]>
Commit | Line | Data |
---|---|---|
83d290c5 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
045fa1e1 SW |
2 | /* |
3 | * Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved. | |
045fa1e1 SW |
4 | */ |
5 | #ifndef _FS_H | |
6 | #define _FS_H | |
7 | ||
8 | #include <common.h> | |
9 | ||
10 | #define FS_TYPE_ANY 0 | |
11 | #define FS_TYPE_FAT 1 | |
12 | #define FS_TYPE_EXT 2 | |
92ccc96b | 13 | #define FS_TYPE_SANDBOX 3 |
251cee0d | 14 | #define FS_TYPE_UBIFS 4 |
0c936ee3 | 15 | #define FS_TYPE_BTRFS 5 |
045fa1e1 SW |
16 | |
17 | /* | |
18 | * Tell the fs layer which block device an partition to use for future | |
19 | * commands. This also internally identifies the filesystem that is present | |
20 | * within the partition. The identification process may be limited to a | |
21 | * specific filesystem type by passing FS_* in the fstype parameter. | |
22 | * | |
23 | * Returns 0 on success. | |
24 | * Returns non-zero if there is an error accessing the disk or partition, or | |
25 | * no known filesystem type could be recognized on it. | |
26 | */ | |
27 | int fs_set_blk_dev(const char *ifname, const char *dev_part_str, int fstype); | |
28 | ||
4bbcc965 RC |
29 | /* |
30 | * fs_set_blk_dev_with_part - Set current block device + partition | |
31 | * | |
32 | * Similar to fs_set_blk_dev(), but useful for cases where you already | |
33 | * know the blk_desc and part number. | |
34 | * | |
35 | * Returns 0 on success. | |
36 | * Returns non-zero if invalid partition or error accessing the disk. | |
37 | */ | |
38 | int fs_set_blk_dev_with_part(struct blk_desc *desc, int part); | |
39 | ||
0d488e8f AK |
40 | /** |
41 | * fs_get_type_name() - Get type of current filesystem | |
42 | * | |
43 | * Return: Pointer to filesystem name | |
44 | * | |
45 | * Returns a string describing the current filesystem, or the sentinel | |
46 | * "unsupported" for any unrecognised filesystem. | |
47 | */ | |
48 | const char *fs_get_type_name(void); | |
49 | ||
045fa1e1 SW |
50 | /* |
51 | * Print the list of files on the partition previously set by fs_set_blk_dev(), | |
52 | * in directory "dirname". | |
53 | * | |
54 | * Returns 0 on success. Returns non-zero on error. | |
55 | */ | |
56 | int fs_ls(const char *dirname); | |
57 | ||
6152916a SW |
58 | /* |
59 | * Determine whether a file exists | |
60 | * | |
61 | * Returns 1 if the file exists, 0 if it doesn't exist. | |
62 | */ | |
63 | int fs_exists(const char *filename); | |
64 | ||
cf659819 | 65 | /* |
d455d878 | 66 | * fs_size - Determine a file's size |
cf659819 | 67 | * |
d455d878 SR |
68 | * @filename: Name of the file |
69 | * @size: Size of file | |
70 | * @return 0 if ok with valid *size, negative on error | |
cf659819 | 71 | */ |
d455d878 | 72 | int fs_size(const char *filename, loff_t *size); |
cf659819 | 73 | |
a0e92cde HS |
74 | /** |
75 | * fs_read() - read file from the partition previously set by fs_set_blk_dev() | |
76 | * | |
77 | * Note that not all filesystem drivers support either or both of offset != 0 | |
78 | * and len != 0. | |
045fa1e1 | 79 | * |
a0e92cde HS |
80 | * @filename: full path of the file to read from |
81 | * @addr: address of the buffer to write to | |
82 | * @offset: offset in the file from where to start reading | |
83 | * @len: the number of bytes to read. Use 0 to read entire file. | |
84 | * @actread: returns the actual number of bytes read | |
85 | * Return: 0 if OK with valid *actread, -1 on error conditions | |
045fa1e1 | 86 | */ |
d455d878 SR |
87 | int fs_read(const char *filename, ulong addr, loff_t offset, loff_t len, |
88 | loff_t *actread); | |
045fa1e1 | 89 | |
a0e92cde HS |
90 | /** |
91 | * fs_write() - write file to the partition previously set by fs_set_blk_dev() | |
92 | * | |
93 | * Note that not all filesystem drivers support offset != 0. | |
bd6fb31f | 94 | * |
a0e92cde HS |
95 | * @filename: full path of the file to write to |
96 | * @addr: address of the buffer to read from | |
97 | * @offset: offset in the file from where to start writing | |
98 | * @len: the number of bytes to write | |
99 | * @actwrite: returns the actual number of bytes written | |
100 | * Return: 0 if OK with valid *actwrite, -1 on error conditions | |
bd6fb31f | 101 | */ |
d455d878 SR |
102 | int fs_write(const char *filename, ulong addr, loff_t offset, loff_t len, |
103 | loff_t *actwrite); | |
bd6fb31f | 104 | |
4bbcc965 RC |
105 | /* |
106 | * Directory entry types, matches the subset of DT_x in posix readdir() | |
107 | * which apply to u-boot. | |
108 | */ | |
109 | #define FS_DT_DIR 4 /* directory */ | |
110 | #define FS_DT_REG 8 /* regular file */ | |
111 | #define FS_DT_LNK 10 /* symbolic link */ | |
112 | ||
113 | /* | |
114 | * A directory entry, returned by fs_readdir(). Returns information | |
115 | * about the file/directory at the current directory entry position. | |
116 | */ | |
117 | struct fs_dirent { | |
118 | unsigned type; /* one of FS_DT_x (not a mask) */ | |
119 | loff_t size; /* size in bytes */ | |
120 | char name[256]; | |
121 | }; | |
122 | ||
123 | /* Note: fs_dir_stream should be treated as opaque to the user of fs layer */ | |
124 | struct fs_dir_stream { | |
125 | /* private to fs. layer: */ | |
126 | struct blk_desc *desc; | |
127 | int part; | |
128 | }; | |
129 | ||
130 | /* | |
131 | * fs_opendir - Open a directory | |
132 | * | |
133 | * @filename: the path to directory to open | |
134 | * @return a pointer to the directory stream or NULL on error and errno | |
135 | * set appropriately | |
136 | */ | |
137 | struct fs_dir_stream *fs_opendir(const char *filename); | |
138 | ||
139 | /* | |
140 | * fs_readdir - Read the next directory entry in the directory stream. | |
141 | * | |
142 | * Works in an analogous way to posix readdir(). The previously returned | |
143 | * directory entry is no longer valid after calling fs_readdir() again. | |
144 | * After fs_closedir() is called, the returned directory entry is no | |
145 | * longer valid. | |
146 | * | |
147 | * @dirs: the directory stream | |
148 | * @return the next directory entry (only valid until next fs_readdir() or | |
149 | * fs_closedir() call, do not attempt to free()) or NULL if the end of | |
150 | * the directory is reached. | |
151 | */ | |
152 | struct fs_dirent *fs_readdir(struct fs_dir_stream *dirs); | |
153 | ||
154 | /* | |
155 | * fs_closedir - close a directory stream | |
156 | * | |
157 | * @dirs: the directory stream | |
158 | */ | |
159 | void fs_closedir(struct fs_dir_stream *dirs); | |
160 | ||
e2519daf AT |
161 | /* |
162 | * fs_unlink - delete a file or directory | |
163 | * | |
164 | * If a given name is a directory, it will be deleted only if it's empty | |
165 | * | |
166 | * @filename: Name of file or directory to delete | |
167 | * @return 0 on success, -1 on error conditions | |
168 | */ | |
169 | int fs_unlink(const char *filename); | |
170 | ||
e7074cff AT |
171 | /* |
172 | * fs_mkdir - Create a directory | |
173 | * | |
174 | * @filename: Name of directory to create | |
175 | * @return 0 on success, -1 on error conditions | |
176 | */ | |
177 | int fs_mkdir(const char *filename); | |
178 | ||
045fa1e1 SW |
179 | /* |
180 | * Common implementation for various filesystem commands, optionally limited | |
181 | * to a specific filesystem type via the fstype parameter. | |
182 | */ | |
cf659819 SW |
183 | int do_size(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[], |
184 | int fstype); | |
f9b55e22 | 185 | int do_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[], |
b770e88a | 186 | int fstype); |
045fa1e1 SW |
187 | int do_ls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[], |
188 | int fstype); | |
6152916a SW |
189 | int file_exists(const char *dev_type, const char *dev_part, const char *file, |
190 | int fstype); | |
a8f6ab52 | 191 | int do_save(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[], |
b770e88a | 192 | int fstype); |
e2519daf AT |
193 | int do_rm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[], |
194 | int fstype); | |
e7074cff AT |
195 | int do_mkdir(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[], |
196 | int fstype); | |
aaa12157 JJH |
197 | int do_ln(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[], |
198 | int fstype); | |
045fa1e1 | 199 | |
59e890ef CG |
200 | /* |
201 | * Determine the UUID of the specified filesystem and print it. Optionally it is | |
202 | * possible to store the UUID directly in env. | |
203 | */ | |
204 | int do_fs_uuid(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[], | |
205 | int fstype); | |
206 | ||
1a1ad8e0 SS |
207 | /* |
208 | * Determine the type of the specified filesystem and print it. Optionally it is | |
209 | * possible to store the type directly in env. | |
210 | */ | |
211 | int do_fs_type(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]); | |
212 | ||
045fa1e1 | 213 | #endif /* _FS_H */ |