1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved.
16 #define FS_TYPE_SANDBOX 3
17 #define FS_TYPE_UBIFS 4
18 #define FS_TYPE_BTRFS 5
19 #define FS_TYPE_SQUASHFS 6
20 #define FS_TYPE_EROFS 7
25 * do_fat_fsload - Run the fatload command
27 * @cmdtp: Command information for fatload
28 * @flag: Command flags (CMD_FLAG_...)
29 * @argc: Number of arguments
30 * @argv: List of arguments
31 * Return: result (see enum command_ret_t)
33 int do_fat_fsload(struct cmd_tbl *cmdtp, int flag, int argc,
37 * do_ext2load - Run the ext2load command
39 * @cmdtp: Command information for ext2load
40 * @flag: Command flags (CMD_FLAG_...)
41 * @argc: Number of arguments
42 * @argv: List of arguments
43 * Return: result (see enum command_ret_t)
45 int do_ext2load(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]);
48 * Tell the fs layer which block device an partition to use for future
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.
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.
57 int fs_set_blk_dev(const char *ifname, const char *dev_part_str, int fstype);
60 * fs_set_blk_dev_with_part - Set current block device + partition
62 * Similar to fs_set_blk_dev(), but useful for cases where you already
63 * know the blk_desc and part number.
65 * Returns 0 on success.
66 * Returns non-zero if invalid partition or error accessing the disk.
68 int fs_set_blk_dev_with_part(struct blk_desc *desc, int part);
71 * fs_close() - Unset current block device and partition
73 * fs_close() closes the connection to a file system opened with either
74 * fs_set_blk_dev() or fs_set_dev_with_part().
76 * Many file functions implicitly call fs_close(), e.g. fs_closedir(),
77 * fs_exist(), fs_ln(), fs_ls(), fs_mkdir(), fs_read(), fs_size(), fs_write(),
83 * fs_get_type() - Get type of current filesystem
85 * Return: filesystem type
87 * Returns filesystem type representing the current filesystem, or
88 * FS_TYPE_ANY for any unrecognised filesystem.
90 int fs_get_type(void);
93 * fs_get_type_name() - Get type of current filesystem
95 * Return: Pointer to filesystem name
97 * Returns a string describing the current filesystem, or the sentinel
98 * "unsupported" for any unrecognised filesystem.
100 const char *fs_get_type_name(void);
103 * Print the list of files on the partition previously set by fs_set_blk_dev(),
104 * in directory "dirname".
106 * Returns 0 on success. Returns non-zero on error.
108 int fs_ls(const char *dirname);
111 * Determine whether a file exists
113 * Returns 1 if the file exists, 0 if it doesn't exist.
115 int fs_exists(const char *filename);
118 * fs_size - Determine a file's size
120 * @filename: Name of the file
121 * @size: Size of file
122 * Return: 0 if ok with valid *size, negative on error
124 int fs_size(const char *filename, loff_t *size);
127 * fs_read() - read file from the partition previously set by fs_set_blk_dev()
129 * Note that not all filesystem drivers support either or both of offset != 0
132 * @filename: full path of the file to read from
133 * @addr: address of the buffer to write to
134 * @offset: offset in the file from where to start reading
135 * @len: the number of bytes to read. Use 0 to read entire file.
136 * @actread: returns the actual number of bytes read
137 * Return: 0 if OK with valid *actread, -1 on error conditions
139 int fs_read(const char *filename, ulong addr, loff_t offset, loff_t len,
143 * fs_write() - write file to the partition previously set by fs_set_blk_dev()
145 * Note that not all filesystem drivers support offset != 0.
147 * @filename: full path of the file to write to
148 * @addr: address of the buffer to read from
149 * @offset: offset in the file from where to start writing
150 * @len: the number of bytes to write
151 * @actwrite: returns the actual number of bytes written
152 * Return: 0 if OK with valid *actwrite, -1 on error conditions
154 int fs_write(const char *filename, ulong addr, loff_t offset, loff_t len,
158 * Directory entry types, matches the subset of DT_x in posix readdir()
159 * which apply to u-boot.
161 #define FS_DT_DIR 4 /* directory */
162 #define FS_DT_REG 8 /* regular file */
163 #define FS_DT_LNK 10 /* symbolic link */
166 * struct fs_dirent - directory entry
168 * A directory entry, returned by fs_readdir(). Returns information
169 * about the file/directory at the current directory entry position.
172 /** @type: one of FS_DT_x (not a mask) */
174 /** @size: file size */
176 /** @flags: attribute flags (FS_ATTR_*) */
178 /** create_time: time of creation */
179 struct rtc_time create_time;
180 /** access_time: time of last access */
181 struct rtc_time access_time;
182 /** change_time: time of last modification */
183 struct rtc_time change_time;
184 /** name: file name */
188 /* Note: fs_dir_stream should be treated as opaque to the user of fs layer */
189 struct fs_dir_stream {
190 /* private to fs. layer: */
191 struct blk_desc *desc;
196 * fs_opendir - Open a directory
198 * @filename: the path to directory to open
199 * Return: a pointer to the directory stream or NULL on error and errno
202 struct fs_dir_stream *fs_opendir(const char *filename);
205 * fs_readdir - Read the next directory entry in the directory stream.
207 * Works in an analogous way to posix readdir(). The previously returned
208 * directory entry is no longer valid after calling fs_readdir() again.
209 * After fs_closedir() is called, the returned directory entry is no
212 * @dirs: the directory stream
213 * Return: the next directory entry (only valid until next fs_readdir() or
214 * fs_closedir() call, do not attempt to free()) or NULL if the end of
215 * the directory is reached.
217 struct fs_dirent *fs_readdir(struct fs_dir_stream *dirs);
220 * fs_closedir - close a directory stream
222 * @dirs: the directory stream
224 void fs_closedir(struct fs_dir_stream *dirs);
227 * fs_unlink - delete a file or directory
229 * If a given name is a directory, it will be deleted only if it's empty
231 * @filename: Name of file or directory to delete
232 * Return: 0 on success, -1 on error conditions
234 int fs_unlink(const char *filename);
237 * fs_mkdir - Create a directory
239 * @filename: Name of directory to create
240 * Return: 0 on success, -1 on error conditions
242 int fs_mkdir(const char *filename);
245 * Common implementation for various filesystem commands, optionally limited
246 * to a specific filesystem type via the fstype parameter.
248 int do_size(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[],
250 int do_load(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[],
252 int do_ls(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[],
254 int file_exists(const char *dev_type, const char *dev_part, const char *file,
256 int do_save(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[],
258 int do_rm(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[],
260 int do_mkdir(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[],
262 int do_ln(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[],
266 * Determine the UUID of the specified filesystem and print it. Optionally it is
267 * possible to store the UUID directly in env.
269 int do_fs_uuid(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[],
273 * Determine the type of the specified filesystem and print it. Optionally it is
274 * possible to store the type directly in env.
276 int do_fs_type(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]);
279 * do_fs_types - List supported filesystems.
281 * @cmdtp: Command information for fstypes
282 * @flag: Command flags (CMD_FLAG_...)
283 * @argc: Number of arguments
284 * @argv: List of arguments
285 * Return: result (see enum command_ret_t)
287 int do_fs_types(struct cmd_tbl *cmdtp, int flag, int argc, char * const argv[]);