2 * Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved.
4 * SPDX-License-Identifier: GPL-2.0
14 #define FS_TYPE_SANDBOX 3
15 #define FS_TYPE_UBIFS 4
16 #define FS_TYPE_BTRFS 5
19 * Tell the fs layer which block device an partition to use for future
20 * commands. This also internally identifies the filesystem that is present
21 * within the partition. The identification process may be limited to a
22 * specific filesystem type by passing FS_* in the fstype parameter.
24 * Returns 0 on success.
25 * Returns non-zero if there is an error accessing the disk or partition, or
26 * no known filesystem type could be recognized on it.
28 int fs_set_blk_dev(const char *ifname, const char *dev_part_str, int fstype);
31 * fs_set_blk_dev_with_part - Set current block device + partition
33 * Similar to fs_set_blk_dev(), but useful for cases where you already
34 * know the blk_desc and part number.
36 * Returns 0 on success.
37 * Returns non-zero if invalid partition or error accessing the disk.
39 int fs_set_blk_dev_with_part(struct blk_desc *desc, int part);
42 * Print the list of files on the partition previously set by fs_set_blk_dev(),
43 * in directory "dirname".
45 * Returns 0 on success. Returns non-zero on error.
47 int fs_ls(const char *dirname);
50 * Determine whether a file exists
52 * Returns 1 if the file exists, 0 if it doesn't exist.
54 int fs_exists(const char *filename);
57 * fs_size - Determine a file's size
59 * @filename: Name of the file
61 * @return 0 if ok with valid *size, negative on error
63 int fs_size(const char *filename, loff_t *size);
66 * fs_read - Read file from the partition previously set by fs_set_blk_dev()
67 * Note that not all filesystem types support either/both offset!=0 or len!=0.
69 * @filename: Name of file to read from
70 * @addr: The address to read into
71 * @offset: The offset in file to read from
72 * @len: The number of bytes to read. Maybe 0 to read entire file
73 * @actread: Returns the actual number of bytes read
74 * @return 0 if ok with valid *actread, -1 on error conditions
76 int fs_read(const char *filename, ulong addr, loff_t offset, loff_t len,
80 * fs_write - Write file to the partition previously set by fs_set_blk_dev()
81 * Note that not all filesystem types support offset!=0.
83 * @filename: Name of file to read from
84 * @addr: The address to read into
85 * @offset: The offset in file to read from. Maybe 0 to write to start of file
86 * @len: The number of bytes to write
87 * @actwrite: Returns the actual number of bytes written
88 * @return 0 if ok with valid *actwrite, -1 on error conditions
90 int fs_write(const char *filename, ulong addr, loff_t offset, loff_t len,
94 * Directory entry types, matches the subset of DT_x in posix readdir()
95 * which apply to u-boot.
97 #define FS_DT_DIR 4 /* directory */
98 #define FS_DT_REG 8 /* regular file */
99 #define FS_DT_LNK 10 /* symbolic link */
102 * A directory entry, returned by fs_readdir(). Returns information
103 * about the file/directory at the current directory entry position.
106 unsigned type; /* one of FS_DT_x (not a mask) */
107 loff_t size; /* size in bytes */
111 /* Note: fs_dir_stream should be treated as opaque to the user of fs layer */
112 struct fs_dir_stream {
113 /* private to fs. layer: */
114 struct blk_desc *desc;
119 * fs_opendir - Open a directory
121 * @filename: the path to directory to open
122 * @return a pointer to the directory stream or NULL on error and errno
125 struct fs_dir_stream *fs_opendir(const char *filename);
128 * fs_readdir - Read the next directory entry in the directory stream.
130 * Works in an analogous way to posix readdir(). The previously returned
131 * directory entry is no longer valid after calling fs_readdir() again.
132 * After fs_closedir() is called, the returned directory entry is no
135 * @dirs: the directory stream
136 * @return the next directory entry (only valid until next fs_readdir() or
137 * fs_closedir() call, do not attempt to free()) or NULL if the end of
138 * the directory is reached.
140 struct fs_dirent *fs_readdir(struct fs_dir_stream *dirs);
143 * fs_closedir - close a directory stream
145 * @dirs: the directory stream
147 void fs_closedir(struct fs_dir_stream *dirs);
150 * Common implementation for various filesystem commands, optionally limited
151 * to a specific filesystem type via the fstype parameter.
153 int do_size(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
155 int do_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
157 int do_ls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
159 int file_exists(const char *dev_type, const char *dev_part, const char *file,
161 int do_save(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
165 * Determine the UUID of the specified filesystem and print it. Optionally it is
166 * possible to store the UUID directly in env.
168 int do_fs_uuid(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
172 * Determine the type of the specified filesystem and print it. Optionally it is
173 * possible to store the type directly in env.
175 int do_fs_type(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);