1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved.
13 #define FS_TYPE_SANDBOX 3
14 #define FS_TYPE_UBIFS 4
15 #define FS_TYPE_BTRFS 5
18 * do_fat_fsload - Run the fatload command
20 * @cmdtp: Command information for fatload
21 * @flag: Command flags (CMD_FLAG_...)
22 * @argc: Number of arguments
23 * @argv: List of arguments
24 * @return result (see enum command_ret_t)
26 int do_fat_fsload(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]);
29 * do_ext2load - Run the ext2load command
31 * @cmdtp: Command information for ext2load
32 * @flag: Command flags (CMD_FLAG_...)
33 * @argc: Number of arguments
34 * @argv: List of arguments
35 * @return result (see enum command_ret_t)
37 int do_ext2load(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]);
40 * Tell the fs layer which block device an partition to use for future
41 * commands. This also internally identifies the filesystem that is present
42 * within the partition. The identification process may be limited to a
43 * specific filesystem type by passing FS_* in the fstype parameter.
45 * Returns 0 on success.
46 * Returns non-zero if there is an error accessing the disk or partition, or
47 * no known filesystem type could be recognized on it.
49 int fs_set_blk_dev(const char *ifname, const char *dev_part_str, int fstype);
52 * fs_set_blk_dev_with_part - Set current block device + partition
54 * Similar to fs_set_blk_dev(), but useful for cases where you already
55 * know the blk_desc and part number.
57 * Returns 0 on success.
58 * Returns non-zero if invalid partition or error accessing the disk.
60 int fs_set_blk_dev_with_part(struct blk_desc *desc, int part);
63 * fs_close() - Unset current block device and partition
65 * fs_close() closes the connection to a file system opened with either
66 * fs_set_blk_dev() or fs_set_dev_with_part().
68 * Many file functions implicitly call fs_close(), e.g. fs_closedir(),
69 * fs_exist(), fs_ln(), fs_ls(), fs_mkdir(), fs_read(), fs_size(), fs_write(),
75 * fs_get_type() - Get type of current filesystem
77 * Return: filesystem type
79 * Returns filesystem type representing the current filesystem, or
80 * FS_TYPE_ANY for any unrecognised filesystem.
82 int fs_get_type(void);
85 * fs_get_type_name() - Get type of current filesystem
87 * Return: Pointer to filesystem name
89 * Returns a string describing the current filesystem, or the sentinel
90 * "unsupported" for any unrecognised filesystem.
92 const char *fs_get_type_name(void);
95 * Print the list of files on the partition previously set by fs_set_blk_dev(),
96 * in directory "dirname".
98 * Returns 0 on success. Returns non-zero on error.
100 int fs_ls(const char *dirname);
103 * Determine whether a file exists
105 * Returns 1 if the file exists, 0 if it doesn't exist.
107 int fs_exists(const char *filename);
110 * fs_size - Determine a file's size
112 * @filename: Name of the file
113 * @size: Size of file
114 * @return 0 if ok with valid *size, negative on error
116 int fs_size(const char *filename, loff_t *size);
119 * fs_read() - read file from the partition previously set by fs_set_blk_dev()
121 * Note that not all filesystem drivers support either or both of offset != 0
124 * @filename: full path of the file to read from
125 * @addr: address of the buffer to write to
126 * @offset: offset in the file from where to start reading
127 * @len: the number of bytes to read. Use 0 to read entire file.
128 * @actread: returns the actual number of bytes read
129 * Return: 0 if OK with valid *actread, -1 on error conditions
131 int fs_read(const char *filename, ulong addr, loff_t offset, loff_t len,
135 * fs_write() - write file to the partition previously set by fs_set_blk_dev()
137 * Note that not all filesystem drivers support offset != 0.
139 * @filename: full path of the file to write to
140 * @addr: address of the buffer to read from
141 * @offset: offset in the file from where to start writing
142 * @len: the number of bytes to write
143 * @actwrite: returns the actual number of bytes written
144 * Return: 0 if OK with valid *actwrite, -1 on error conditions
146 int fs_write(const char *filename, ulong addr, loff_t offset, loff_t len,
150 * Directory entry types, matches the subset of DT_x in posix readdir()
151 * which apply to u-boot.
153 #define FS_DT_DIR 4 /* directory */
154 #define FS_DT_REG 8 /* regular file */
155 #define FS_DT_LNK 10 /* symbolic link */
158 * A directory entry, returned by fs_readdir(). Returns information
159 * about the file/directory at the current directory entry position.
162 unsigned type; /* one of FS_DT_x (not a mask) */
163 loff_t size; /* size in bytes */
167 /* Note: fs_dir_stream should be treated as opaque to the user of fs layer */
168 struct fs_dir_stream {
169 /* private to fs. layer: */
170 struct blk_desc *desc;
175 * fs_opendir - Open a directory
177 * @filename: the path to directory to open
178 * @return a pointer to the directory stream or NULL on error and errno
181 struct fs_dir_stream *fs_opendir(const char *filename);
184 * fs_readdir - Read the next directory entry in the directory stream.
186 * Works in an analogous way to posix readdir(). The previously returned
187 * directory entry is no longer valid after calling fs_readdir() again.
188 * After fs_closedir() is called, the returned directory entry is no
191 * @dirs: the directory stream
192 * @return the next directory entry (only valid until next fs_readdir() or
193 * fs_closedir() call, do not attempt to free()) or NULL if the end of
194 * the directory is reached.
196 struct fs_dirent *fs_readdir(struct fs_dir_stream *dirs);
199 * fs_closedir - close a directory stream
201 * @dirs: the directory stream
203 void fs_closedir(struct fs_dir_stream *dirs);
206 * fs_unlink - delete a file or directory
208 * If a given name is a directory, it will be deleted only if it's empty
210 * @filename: Name of file or directory to delete
211 * @return 0 on success, -1 on error conditions
213 int fs_unlink(const char *filename);
216 * fs_mkdir - Create a directory
218 * @filename: Name of directory to create
219 * @return 0 on success, -1 on error conditions
221 int fs_mkdir(const char *filename);
224 * Common implementation for various filesystem commands, optionally limited
225 * to a specific filesystem type via the fstype parameter.
227 int do_size(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
229 int do_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
231 int do_ls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
233 int file_exists(const char *dev_type, const char *dev_part, const char *file,
235 int do_save(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
237 int do_rm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
239 int do_mkdir(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
241 int do_ln(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
245 * Determine the UUID of the specified filesystem and print it. Optionally it is
246 * possible to store the UUID directly in env.
248 int do_fs_uuid(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
252 * Determine the type of the specified filesystem and print it. Optionally it is
253 * possible to store the type directly in env.
255 int do_fs_type(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);