]>
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 | ||
13c11c66 | 8 | #include <rtc.h> |
045fa1e1 | 9 | |
09140113 SG |
10 | struct cmd_tbl; |
11 | ||
045fa1e1 SW |
12 | #define FS_TYPE_ANY 0 |
13 | #define FS_TYPE_FAT 1 | |
14 | #define FS_TYPE_EXT 2 | |
92ccc96b | 15 | #define FS_TYPE_SANDBOX 3 |
251cee0d | 16 | #define FS_TYPE_UBIFS 4 |
0c936ee3 | 17 | #define FS_TYPE_BTRFS 5 |
c5100613 | 18 | #define FS_TYPE_SQUASHFS 6 |
830613f8 | 19 | #define FS_TYPE_EROFS 7 |
f676b451 | 20 | #define FS_TYPE_SEMIHOSTING 8 |
045fa1e1 | 21 | |
e6f6f9e6 SG |
22 | struct blk_desc; |
23 | ||
14449982 SG |
24 | /** |
25 | * do_fat_fsload - Run the fatload command | |
26 | * | |
27 | * @cmdtp: Command information for fatload | |
aa636678 | 28 | * @flag: Command flags (CMD_FLAG\_...) |
14449982 SG |
29 | * @argc: Number of arguments |
30 | * @argv: List of arguments | |
185f812c | 31 | * Return: result (see enum command_ret_t) |
14449982 | 32 | */ |
09140113 SG |
33 | int do_fat_fsload(struct cmd_tbl *cmdtp, int flag, int argc, |
34 | char *const argv[]); | |
14449982 SG |
35 | |
36 | /** | |
37 | * do_ext2load - Run the ext2load command | |
38 | * | |
39 | * @cmdtp: Command information for ext2load | |
aa636678 | 40 | * @flag: Command flags (CMD_FLAG\_...) |
14449982 SG |
41 | * @argc: Number of arguments |
42 | * @argv: List of arguments | |
185f812c | 43 | * Return: result (see enum command_ret_t) |
14449982 | 44 | */ |
09140113 | 45 | int do_ext2load(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]); |
14449982 | 46 | |
045fa1e1 | 47 | /* |
da223d81 | 48 | * Tell the fs layer which block device and partition to use for future |
045fa1e1 SW |
49 | * commands. This also internally identifies the filesystem that is present |
50 | * within the partition. The identification process may be limited to a | |
51 | * specific filesystem type by passing FS_* in the fstype parameter. | |
52 | * | |
53 | * Returns 0 on success. | |
54 | * Returns non-zero if there is an error accessing the disk or partition, or | |
55 | * no known filesystem type could be recognized on it. | |
56 | */ | |
57 | int fs_set_blk_dev(const char *ifname, const char *dev_part_str, int fstype); | |
58 | ||
c24e58f5 SG |
59 | /** |
60 | * fs_set_type() - Tell fs layer which filesystem type is used | |
61 | * | |
62 | * This is needed when reading from a non-block device such as sandbox. It does | |
63 | * a similar job to fs_set_blk_dev() but just sets the filesystem type instead | |
64 | * of detecting it and loading it on the block device | |
65 | * | |
66 | * @type: Filesystem type to use (FS_TYPE...) | |
67 | */ | |
68 | void fs_set_type(int type); | |
69 | ||
4bbcc965 RC |
70 | /* |
71 | * fs_set_blk_dev_with_part - Set current block device + partition | |
72 | * | |
73 | * Similar to fs_set_blk_dev(), but useful for cases where you already | |
74 | * know the blk_desc and part number. | |
75 | * | |
76 | * Returns 0 on success. | |
77 | * Returns non-zero if invalid partition or error accessing the disk. | |
78 | */ | |
79 | int fs_set_blk_dev_with_part(struct blk_desc *desc, int part); | |
80 | ||
64f49eb7 AT |
81 | /** |
82 | * fs_close() - Unset current block device and partition | |
83 | * | |
e4bad9f9 HS |
84 | * fs_close() closes the connection to a file system opened with either |
85 | * fs_set_blk_dev() or fs_set_dev_with_part(). | |
86 | * | |
87 | * Many file functions implicitly call fs_close(), e.g. fs_closedir(), | |
88 | * fs_exist(), fs_ln(), fs_ls(), fs_mkdir(), fs_read(), fs_size(), fs_write(), | |
89 | * fs_unlink(). | |
64f49eb7 AT |
90 | */ |
91 | void fs_close(void); | |
92 | ||
b7cd9562 AT |
93 | /** |
94 | * fs_get_type() - Get type of current filesystem | |
95 | * | |
96 | * Return: filesystem type | |
97 | * | |
98 | * Returns filesystem type representing the current filesystem, or | |
99 | * FS_TYPE_ANY for any unrecognised filesystem. | |
100 | */ | |
101 | int fs_get_type(void); | |
102 | ||
0d488e8f AK |
103 | /** |
104 | * fs_get_type_name() - Get type of current filesystem | |
105 | * | |
106 | * Return: Pointer to filesystem name | |
107 | * | |
108 | * Returns a string describing the current filesystem, or the sentinel | |
109 | * "unsupported" for any unrecognised filesystem. | |
110 | */ | |
111 | const char *fs_get_type_name(void); | |
112 | ||
045fa1e1 SW |
113 | /* |
114 | * Print the list of files on the partition previously set by fs_set_blk_dev(), | |
115 | * in directory "dirname". | |
116 | * | |
117 | * Returns 0 on success. Returns non-zero on error. | |
118 | */ | |
119 | int fs_ls(const char *dirname); | |
120 | ||
6152916a SW |
121 | /* |
122 | * Determine whether a file exists | |
123 | * | |
124 | * Returns 1 if the file exists, 0 if it doesn't exist. | |
125 | */ | |
126 | int fs_exists(const char *filename); | |
127 | ||
cf659819 | 128 | /* |
d455d878 | 129 | * fs_size - Determine a file's size |
cf659819 | 130 | * |
d455d878 SR |
131 | * @filename: Name of the file |
132 | * @size: Size of file | |
185f812c | 133 | * Return: 0 if ok with valid *size, negative on error |
cf659819 | 134 | */ |
d455d878 | 135 | int fs_size(const char *filename, loff_t *size); |
cf659819 | 136 | |
a0e92cde HS |
137 | /** |
138 | * fs_read() - read file from the partition previously set by fs_set_blk_dev() | |
139 | * | |
140 | * Note that not all filesystem drivers support either or both of offset != 0 | |
141 | * and len != 0. | |
045fa1e1 | 142 | * |
a0e92cde HS |
143 | * @filename: full path of the file to read from |
144 | * @addr: address of the buffer to write to | |
145 | * @offset: offset in the file from where to start reading | |
146 | * @len: the number of bytes to read. Use 0 to read entire file. | |
147 | * @actread: returns the actual number of bytes read | |
aa636678 | 148 | * Return: 0 if OK with valid @actread, -1 on error conditions |
045fa1e1 | 149 | */ |
d455d878 SR |
150 | int fs_read(const char *filename, ulong addr, loff_t offset, loff_t len, |
151 | loff_t *actread); | |
045fa1e1 | 152 | |
a0e92cde HS |
153 | /** |
154 | * fs_write() - write file to the partition previously set by fs_set_blk_dev() | |
155 | * | |
156 | * Note that not all filesystem drivers support offset != 0. | |
bd6fb31f | 157 | * |
a0e92cde HS |
158 | * @filename: full path of the file to write to |
159 | * @addr: address of the buffer to read from | |
160 | * @offset: offset in the file from where to start writing | |
161 | * @len: the number of bytes to write | |
162 | * @actwrite: returns the actual number of bytes written | |
aa636678 | 163 | * Return: 0 if OK with valid @actwrite, -1 on error conditions |
bd6fb31f | 164 | */ |
d455d878 SR |
165 | int fs_write(const char *filename, ulong addr, loff_t offset, loff_t len, |
166 | loff_t *actwrite); | |
bd6fb31f | 167 | |
4bbcc965 RC |
168 | /* |
169 | * Directory entry types, matches the subset of DT_x in posix readdir() | |
170 | * which apply to u-boot. | |
171 | */ | |
172 | #define FS_DT_DIR 4 /* directory */ | |
173 | #define FS_DT_REG 8 /* regular file */ | |
174 | #define FS_DT_LNK 10 /* symbolic link */ | |
175 | ||
2ac0baab MR |
176 | #define FS_DIRENT_NAME_LEN 256 |
177 | ||
13c11c66 HS |
178 | /** |
179 | * struct fs_dirent - directory entry | |
180 | * | |
181 | * A directory entry, returned by fs_readdir(). Returns information | |
4bbcc965 RC |
182 | * about the file/directory at the current directory entry position. |
183 | */ | |
184 | struct fs_dirent { | |
13c11c66 HS |
185 | /** @type: one of FS_DT_x (not a mask) */ |
186 | unsigned int type; | |
187 | /** @size: file size */ | |
188 | loff_t size; | |
aa636678 | 189 | /** @attr: attribute flags (FS_ATTR_*) */ |
13c11c66 | 190 | u32 attr; |
aa636678 | 191 | /** @create_time: time of creation */ |
13c11c66 | 192 | struct rtc_time create_time; |
aa636678 | 193 | /** @access_time: time of last access */ |
13c11c66 | 194 | struct rtc_time access_time; |
aa636678 | 195 | /** @change_time: time of last modification */ |
13c11c66 | 196 | struct rtc_time change_time; |
aa636678 | 197 | /** @name: file name */ |
2ac0baab | 198 | char name[FS_DIRENT_NAME_LEN]; |
4bbcc965 RC |
199 | }; |
200 | ||
aa636678 HS |
201 | /** |
202 | * struct fs_dir_stream - Structure representing an opened directory | |
203 | * | |
204 | * Struct fs_dir_stream should be treated opaque to the user of fs layer. | |
205 | * The fields @desc and @part are used by the fs layer. | |
206 | * File system drivers pass additional private fields with the pointers | |
207 | * to this structure. | |
208 | * | |
209 | * @desc: block device descriptor | |
210 | * @part: partition number | |
211 | */ | |
4bbcc965 | 212 | struct fs_dir_stream { |
4bbcc965 RC |
213 | struct blk_desc *desc; |
214 | int part; | |
215 | }; | |
216 | ||
aa636678 | 217 | /** |
4bbcc965 RC |
218 | * fs_opendir - Open a directory |
219 | * | |
aa636678 HS |
220 | * .. note:: |
221 | * The returned struct fs_dir_stream should be treated opaque to the | |
222 | * user of the fs layer. | |
223 | * | |
224 | * @filename: path to the directory to open | |
225 | * Return: | |
226 | * A pointer to the directory stream or NULL on error and errno set | |
227 | * appropriately | |
4bbcc965 RC |
228 | */ |
229 | struct fs_dir_stream *fs_opendir(const char *filename); | |
230 | ||
aa636678 | 231 | /** |
4bbcc965 RC |
232 | * fs_readdir - Read the next directory entry in the directory stream. |
233 | * | |
aa636678 HS |
234 | * fs_readir works in an analogous way to posix readdir(). |
235 | * The previously returned directory entry is no longer valid after calling | |
236 | * fs_readdir() again. | |
4bbcc965 RC |
237 | * After fs_closedir() is called, the returned directory entry is no |
238 | * longer valid. | |
239 | * | |
240 | * @dirs: the directory stream | |
aa636678 HS |
241 | * Return: |
242 | * the next directory entry (only valid until next fs_readdir() or | |
243 | * fs_closedir() call, do not attempt to free()) or NULL if the end of | |
244 | * the directory is reached. | |
4bbcc965 RC |
245 | */ |
246 | struct fs_dirent *fs_readdir(struct fs_dir_stream *dirs); | |
247 | ||
aa636678 | 248 | /** |
4bbcc965 RC |
249 | * fs_closedir - close a directory stream |
250 | * | |
251 | * @dirs: the directory stream | |
252 | */ | |
253 | void fs_closedir(struct fs_dir_stream *dirs); | |
254 | ||
aa636678 | 255 | /** |
e2519daf AT |
256 | * fs_unlink - delete a file or directory |
257 | * | |
258 | * If a given name is a directory, it will be deleted only if it's empty | |
259 | * | |
260 | * @filename: Name of file or directory to delete | |
185f812c | 261 | * Return: 0 on success, -1 on error conditions |
e2519daf AT |
262 | */ |
263 | int fs_unlink(const char *filename); | |
264 | ||
aa636678 | 265 | /** |
e7074cff AT |
266 | * fs_mkdir - Create a directory |
267 | * | |
268 | * @filename: Name of directory to create | |
185f812c | 269 | * Return: 0 on success, -1 on error conditions |
e7074cff AT |
270 | */ |
271 | int fs_mkdir(const char *filename); | |
272 | ||
045fa1e1 SW |
273 | /* |
274 | * Common implementation for various filesystem commands, optionally limited | |
275 | * to a specific filesystem type via the fstype parameter. | |
276 | */ | |
09140113 SG |
277 | int do_size(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[], |
278 | int fstype); | |
279 | int do_load(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[], | |
280 | int fstype); | |
281 | int do_ls(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[], | |
282 | int fstype); | |
6152916a SW |
283 | int file_exists(const char *dev_type, const char *dev_part, const char *file, |
284 | int fstype); | |
09140113 SG |
285 | int do_save(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[], |
286 | int fstype); | |
287 | int do_rm(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[], | |
288 | int fstype); | |
289 | int do_mkdir(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[], | |
290 | int fstype); | |
291 | int do_ln(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[], | |
aaa12157 | 292 | int fstype); |
045fa1e1 | 293 | |
59e890ef CG |
294 | /* |
295 | * Determine the UUID of the specified filesystem and print it. Optionally it is | |
296 | * possible to store the UUID directly in env. | |
297 | */ | |
09140113 SG |
298 | int do_fs_uuid(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[], |
299 | int fstype); | |
59e890ef | 300 | |
1a1ad8e0 SS |
301 | /* |
302 | * Determine the type of the specified filesystem and print it. Optionally it is | |
303 | * possible to store the type directly in env. | |
304 | */ | |
09140113 | 305 | int do_fs_type(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]); |
1a1ad8e0 | 306 | |
2280fa56 NF |
307 | /** |
308 | * do_fs_types - List supported filesystems. | |
309 | * | |
310 | * @cmdtp: Command information for fstypes | |
aa636678 | 311 | * @flag: Command flags (CMD_FLAG\_...) |
2280fa56 NF |
312 | * @argc: Number of arguments |
313 | * @argv: List of arguments | |
185f812c | 314 | * Return: result (see enum command_ret_t) |
2280fa56 NF |
315 | */ |
316 | int do_fs_types(struct cmd_tbl *cmdtp, int flag, int argc, char * const argv[]); | |
317 | ||
de7b5a8a SG |
318 | /** |
319 | * fs_read_alloc() - Allocate space for a file and read it | |
320 | * | |
321 | * You must call fs_set_blk_dev() or a similar function before calling this, | |
322 | * since that sets up the block device to use. | |
323 | * | |
324 | * The file is terminated with a nul character | |
325 | * | |
326 | * @fname: Filename to read | |
327 | * @size: Size of file to read (must be correct!) | |
6ea8dc66 | 328 | * @align: Alignment to use for memory allocation (0 for default: ARCH_DMA_MINALIGN) |
de7b5a8a SG |
329 | * @bufp: On success, returns the allocated buffer with the nul-terminated file |
330 | * in it | |
331 | * Return: 0 if OK, -ENOMEM if out of memory, -EIO if read failed | |
332 | */ | |
333 | int fs_read_alloc(const char *fname, ulong size, uint align, void **bufp); | |
334 | ||
335 | /** | |
336 | * fs_load_alloc() - Load a file into allocated space | |
337 | * | |
338 | * The file is terminated with a nul character | |
339 | * | |
340 | * @ifname: Interface name to read from (e.g. "mmc") | |
341 | * @dev_part_str: Device and partition string (e.g. "1:2") | |
342 | * @fname: Filename to read | |
343 | * @max_size: Maximum allowed size for the file (use 0 for 1GB) | |
344 | * @align: Alignment to use for memory allocation (0 for default) | |
345 | * @bufp: On success, returns the allocated buffer with the nul-terminated file | |
346 | * in it | |
347 | * @sizep: On success, returns the size of the file | |
348 | * Return: 0 if OK, -ENOMEM if out of memory, -ENOENT if the file does not | |
349 | * exist, -ENOMEDIUM if the device does not exist, -E2BIG if the file is too | |
350 | * large (greater than @max_size), -EIO if read failed | |
351 | */ | |
352 | int fs_load_alloc(const char *ifname, const char *dev_part_str, | |
353 | const char *fname, ulong max_size, ulong align, void **bufp, | |
354 | ulong *sizep); | |
355 | ||
045fa1e1 | 356 | #endif /* _FS_H */ |