1 /* Copyright 2013-2015 IBM Corp.
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * 	http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12  * implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <stdlib.h>
18 #include <stdio.h>
19 #include <limits.h>
20 #include <unistd.h>
21 #include <dirent.h>
22 #include <sys/types.h>
23 #include <sys/stat.h>
24 #include <fcntl.h>
25 #include <string.h>
26 
27 #include <libflash/file.h>
28 
29 #include "arch_flash.h"
30 
arch_flash_init(struct blocklevel_device ** r_bl,const char * file,bool keep_alive)31 int arch_flash_init(struct blocklevel_device **r_bl, const char *file, bool keep_alive)
32 {
33 	int rc;
34 	struct blocklevel_device *new_bl;
35 
36 	/* Must have passed through a file to operate on */
37 	if (!file) {
38 		fprintf(stderr, "Cannot operate without a file\n");
39 		return -1;
40 	}
41 
42 	rc = file_init_path(file, NULL, keep_alive, &new_bl);
43 	if (rc)
44 		return -1;
45 
46 	*r_bl = new_bl;
47 	return 0;
48 }
49 
arch_flash_close(struct blocklevel_device * bl,const char * file)50 void arch_flash_close(struct blocklevel_device *bl, const char *file)
51 {
52 	(void)file;
53 	file_exit_close(bl);
54 }
55