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 * 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.
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.
27 int fs_set_blk_dev(const char *ifname, const char *dev_part_str, int fstype);
30 * fs_set_blk_dev_with_part - Set current block device + partition
32 * Similar to fs_set_blk_dev(), but useful for cases where you already
33 * know the blk_desc and part number.
35 * Returns 0 on success.
36 * Returns non-zero if invalid partition or error accessing the disk.
38 int fs_set_blk_dev_with_part(struct blk_desc *desc, int part);
41 * fs_close() - Unset current block device and partition
43 * fs_close() closes the connection to a file system opened with either
44 * fs_set_blk_dev() or fs_set_dev_with_part().
46 * Many file functions implicitly call fs_close(), e.g. fs_closedir(),
47 * fs_exist(), fs_ln(), fs_ls(), fs_mkdir(), fs_read(), fs_size(), fs_write(),
53 * fs_get_type_name() - Get type of current filesystem
55 * Return: Pointer to filesystem name
57 * Returns a string describing the current filesystem, or the sentinel
58 * "unsupported" for any unrecognised filesystem.
60 const char *fs_get_type_name(void);
63 * Print the list of files on the partition previously set by fs_set_blk_dev(),
64 * in directory "dirname".
66 * Returns 0 on success. Returns non-zero on error.
68 int fs_ls(const char *dirname);
71 * Determine whether a file exists
73 * Returns 1 if the file exists, 0 if it doesn't exist.
75 int fs_exists(const char *filename);
78 * fs_size - Determine a file's size
80 * @filename: Name of the file
82 * @return 0 if ok with valid *size, negative on error
84 int fs_size(const char *filename, loff_t *size);
87 * fs_read() - read file from the partition previously set by fs_set_blk_dev()
89 * Note that not all filesystem drivers support either or both of offset != 0
92 * @filename: full path of the file to read from
93 * @addr: address of the buffer to write to
94 * @offset: offset in the file from where to start reading
95 * @len: the number of bytes to read. Use 0 to read entire file.
96 * @actread: returns the actual number of bytes read
97 * Return: 0 if OK with valid *actread, -1 on error conditions
99 int fs_read(const char *filename, ulong addr, loff_t offset, loff_t len,
103 * fs_write() - write file to the partition previously set by fs_set_blk_dev()
105 * Note that not all filesystem drivers support offset != 0.
107 * @filename: full path of the file to write to
108 * @addr: address of the buffer to read from
109 * @offset: offset in the file from where to start writing
110 * @len: the number of bytes to write
111 * @actwrite: returns the actual number of bytes written
112 * Return: 0 if OK with valid *actwrite, -1 on error conditions
114 int fs_write(const char *filename, ulong addr, loff_t offset, loff_t len,
118 * Directory entry types, matches the subset of DT_x in posix readdir()
119 * which apply to u-boot.
121 #define FS_DT_DIR 4 /* directory */
122 #define FS_DT_REG 8 /* regular file */
123 #define FS_DT_LNK 10 /* symbolic link */
126 * A directory entry, returned by fs_readdir(). Returns information
127 * about the file/directory at the current directory entry position.
130 unsigned type; /* one of FS_DT_x (not a mask) */
131 loff_t size; /* size in bytes */
135 /* Note: fs_dir_stream should be treated as opaque to the user of fs layer */
136 struct fs_dir_stream {
137 /* private to fs. layer: */
138 struct blk_desc *desc;
143 * fs_opendir - Open a directory
145 * @filename: the path to directory to open
146 * @return a pointer to the directory stream or NULL on error and errno
149 struct fs_dir_stream *fs_opendir(const char *filename);
152 * fs_readdir - Read the next directory entry in the directory stream.
154 * Works in an analogous way to posix readdir(). The previously returned
155 * directory entry is no longer valid after calling fs_readdir() again.
156 * After fs_closedir() is called, the returned directory entry is no
159 * @dirs: the directory stream
160 * @return the next directory entry (only valid until next fs_readdir() or
161 * fs_closedir() call, do not attempt to free()) or NULL if the end of
162 * the directory is reached.
164 struct fs_dirent *fs_readdir(struct fs_dir_stream *dirs);
167 * fs_closedir - close a directory stream
169 * @dirs: the directory stream
171 void fs_closedir(struct fs_dir_stream *dirs);
174 * fs_unlink - delete a file or directory
176 * If a given name is a directory, it will be deleted only if it's empty
178 * @filename: Name of file or directory to delete
179 * @return 0 on success, -1 on error conditions
181 int fs_unlink(const char *filename);
184 * fs_mkdir - Create a directory
186 * @filename: Name of directory to create
187 * @return 0 on success, -1 on error conditions
189 int fs_mkdir(const char *filename);
192 * Common implementation for various filesystem commands, optionally limited
193 * to a specific filesystem type via the fstype parameter.
195 int do_size(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
197 int do_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
199 int do_ls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
201 int file_exists(const char *dev_type, const char *dev_part, const char *file,
203 int do_save(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
205 int do_rm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
207 int do_mkdir(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
209 int do_ln(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
213 * Determine the UUID of the specified filesystem and print it. Optionally it is
214 * possible to store the UUID directly in env.
216 int do_fs_uuid(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
220 * Determine the type of the specified filesystem and print it. Optionally it is
221 * possible to store the type directly in env.
223 int do_fs_type(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);