Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved. |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 4 | */ |
| 5 | #ifndef _FS_H |
| 6 | #define _FS_H |
| 7 | |
| 8 | #include <common.h> |
| 9 | |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 10 | struct cmd_tbl; |
| 11 | |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 12 | #define FS_TYPE_ANY 0 |
| 13 | #define FS_TYPE_FAT 1 |
| 14 | #define FS_TYPE_EXT 2 |
Simon Glass | 92ccc96 | 2012-12-26 09:53:35 +0000 | [diff] [blame] | 15 | #define FS_TYPE_SANDBOX 3 |
Hans de Goede | 251cee0 | 2015-09-17 18:46:58 -0400 | [diff] [blame] | 16 | #define FS_TYPE_UBIFS 4 |
Marek BehĂșn | 0c936ee | 2017-09-03 17:00:29 +0200 | [diff] [blame] | 17 | #define FS_TYPE_BTRFS 5 |
Joao Marcos Costa | c510061 | 2020-07-30 15:33:47 +0200 | [diff] [blame] | 18 | #define FS_TYPE_SQUASHFS 6 |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 19 | |
Simon Glass | e6f6f9e | 2020-05-10 11:39:58 -0600 | [diff] [blame] | 20 | struct blk_desc; |
| 21 | |
Simon Glass | 1444998 | 2019-12-28 10:44:44 -0700 | [diff] [blame] | 22 | /** |
| 23 | * do_fat_fsload - Run the fatload command |
| 24 | * |
| 25 | * @cmdtp: Command information for fatload |
| 26 | * @flag: Command flags (CMD_FLAG_...) |
| 27 | * @argc: Number of arguments |
| 28 | * @argv: List of arguments |
| 29 | * @return result (see enum command_ret_t) |
| 30 | */ |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 31 | int do_fat_fsload(struct cmd_tbl *cmdtp, int flag, int argc, |
| 32 | char *const argv[]); |
Simon Glass | 1444998 | 2019-12-28 10:44:44 -0700 | [diff] [blame] | 33 | |
| 34 | /** |
| 35 | * do_ext2load - Run the ext2load command |
| 36 | * |
| 37 | * @cmdtp: Command information for ext2load |
| 38 | * @flag: Command flags (CMD_FLAG_...) |
| 39 | * @argc: Number of arguments |
| 40 | * @argv: List of arguments |
| 41 | * @return result (see enum command_ret_t) |
| 42 | */ |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 43 | int do_ext2load(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]); |
Simon Glass | 1444998 | 2019-12-28 10:44:44 -0700 | [diff] [blame] | 44 | |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 45 | /* |
| 46 | * Tell the fs layer which block device an partition to use for future |
| 47 | * commands. This also internally identifies the filesystem that is present |
| 48 | * within the partition. The identification process may be limited to a |
| 49 | * specific filesystem type by passing FS_* in the fstype parameter. |
| 50 | * |
| 51 | * Returns 0 on success. |
| 52 | * Returns non-zero if there is an error accessing the disk or partition, or |
| 53 | * no known filesystem type could be recognized on it. |
| 54 | */ |
| 55 | int fs_set_blk_dev(const char *ifname, const char *dev_part_str, int fstype); |
| 56 | |
| 57 | /* |
Rob Clark | 4bbcc96 | 2017-09-09 13:15:55 -0400 | [diff] [blame] | 58 | * fs_set_blk_dev_with_part - Set current block device + partition |
| 59 | * |
| 60 | * Similar to fs_set_blk_dev(), but useful for cases where you already |
| 61 | * know the blk_desc and part number. |
| 62 | * |
| 63 | * Returns 0 on success. |
| 64 | * Returns non-zero if invalid partition or error accessing the disk. |
| 65 | */ |
| 66 | int fs_set_blk_dev_with_part(struct blk_desc *desc, int part); |
| 67 | |
Alex Kiernan | 0d488e8 | 2018-05-29 15:30:50 +0000 | [diff] [blame] | 68 | /** |
AKASHI Takahiro | 64f49eb | 2019-10-07 14:59:35 +0900 | [diff] [blame] | 69 | * fs_close() - Unset current block device and partition |
| 70 | * |
Heinrich Schuchardt | e4bad9f | 2019-10-13 10:26:26 +0200 | [diff] [blame] | 71 | * fs_close() closes the connection to a file system opened with either |
| 72 | * fs_set_blk_dev() or fs_set_dev_with_part(). |
| 73 | * |
| 74 | * Many file functions implicitly call fs_close(), e.g. fs_closedir(), |
| 75 | * fs_exist(), fs_ln(), fs_ls(), fs_mkdir(), fs_read(), fs_size(), fs_write(), |
| 76 | * fs_unlink(). |
AKASHI Takahiro | 64f49eb | 2019-10-07 14:59:35 +0900 | [diff] [blame] | 77 | */ |
| 78 | void fs_close(void); |
| 79 | |
| 80 | /** |
AKASHI Takahiro | b7cd956 | 2019-10-07 14:59:37 +0900 | [diff] [blame] | 81 | * fs_get_type() - Get type of current filesystem |
| 82 | * |
| 83 | * Return: filesystem type |
| 84 | * |
| 85 | * Returns filesystem type representing the current filesystem, or |
| 86 | * FS_TYPE_ANY for any unrecognised filesystem. |
| 87 | */ |
| 88 | int fs_get_type(void); |
| 89 | |
| 90 | /** |
Alex Kiernan | 0d488e8 | 2018-05-29 15:30:50 +0000 | [diff] [blame] | 91 | * fs_get_type_name() - Get type of current filesystem |
| 92 | * |
| 93 | * Return: Pointer to filesystem name |
| 94 | * |
| 95 | * Returns a string describing the current filesystem, or the sentinel |
| 96 | * "unsupported" for any unrecognised filesystem. |
| 97 | */ |
| 98 | const char *fs_get_type_name(void); |
| 99 | |
Rob Clark | 4bbcc96 | 2017-09-09 13:15:55 -0400 | [diff] [blame] | 100 | /* |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 101 | * Print the list of files on the partition previously set by fs_set_blk_dev(), |
| 102 | * in directory "dirname". |
| 103 | * |
| 104 | * Returns 0 on success. Returns non-zero on error. |
| 105 | */ |
| 106 | int fs_ls(const char *dirname); |
| 107 | |
| 108 | /* |
Stephen Warren | 6152916 | 2014-02-03 13:21:00 -0700 | [diff] [blame] | 109 | * Determine whether a file exists |
| 110 | * |
| 111 | * Returns 1 if the file exists, 0 if it doesn't exist. |
| 112 | */ |
| 113 | int fs_exists(const char *filename); |
| 114 | |
| 115 | /* |
Suriyan Ramasami | d455d87 | 2014-11-17 14:39:38 -0800 | [diff] [blame] | 116 | * fs_size - Determine a file's size |
Stephen Warren | cf65981 | 2014-06-11 12:47:26 -0600 | [diff] [blame] | 117 | * |
Suriyan Ramasami | d455d87 | 2014-11-17 14:39:38 -0800 | [diff] [blame] | 118 | * @filename: Name of the file |
| 119 | * @size: Size of file |
| 120 | * @return 0 if ok with valid *size, negative on error |
Stephen Warren | cf65981 | 2014-06-11 12:47:26 -0600 | [diff] [blame] | 121 | */ |
Suriyan Ramasami | d455d87 | 2014-11-17 14:39:38 -0800 | [diff] [blame] | 122 | int fs_size(const char *filename, loff_t *size); |
Stephen Warren | cf65981 | 2014-06-11 12:47:26 -0600 | [diff] [blame] | 123 | |
Heinrich Schuchardt | a0e92cd | 2019-04-25 20:36:39 +0200 | [diff] [blame] | 124 | /** |
| 125 | * fs_read() - read file from the partition previously set by fs_set_blk_dev() |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 126 | * |
Heinrich Schuchardt | a0e92cd | 2019-04-25 20:36:39 +0200 | [diff] [blame] | 127 | * Note that not all filesystem drivers support either or both of offset != 0 |
| 128 | * and len != 0. |
| 129 | * |
| 130 | * @filename: full path of the file to read from |
| 131 | * @addr: address of the buffer to write to |
| 132 | * @offset: offset in the file from where to start reading |
| 133 | * @len: the number of bytes to read. Use 0 to read entire file. |
| 134 | * @actread: returns the actual number of bytes read |
| 135 | * Return: 0 if OK with valid *actread, -1 on error conditions |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 136 | */ |
Suriyan Ramasami | d455d87 | 2014-11-17 14:39:38 -0800 | [diff] [blame] | 137 | int fs_read(const char *filename, ulong addr, loff_t offset, loff_t len, |
| 138 | loff_t *actread); |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 139 | |
Heinrich Schuchardt | a0e92cd | 2019-04-25 20:36:39 +0200 | [diff] [blame] | 140 | /** |
| 141 | * fs_write() - write file to the partition previously set by fs_set_blk_dev() |
Stephen Warren | bd6fb31 | 2014-02-03 13:20:59 -0700 | [diff] [blame] | 142 | * |
Heinrich Schuchardt | a0e92cd | 2019-04-25 20:36:39 +0200 | [diff] [blame] | 143 | * Note that not all filesystem drivers support offset != 0. |
| 144 | * |
| 145 | * @filename: full path of the file to write to |
| 146 | * @addr: address of the buffer to read from |
| 147 | * @offset: offset in the file from where to start writing |
| 148 | * @len: the number of bytes to write |
| 149 | * @actwrite: returns the actual number of bytes written |
| 150 | * Return: 0 if OK with valid *actwrite, -1 on error conditions |
Stephen Warren | bd6fb31 | 2014-02-03 13:20:59 -0700 | [diff] [blame] | 151 | */ |
Suriyan Ramasami | d455d87 | 2014-11-17 14:39:38 -0800 | [diff] [blame] | 152 | int fs_write(const char *filename, ulong addr, loff_t offset, loff_t len, |
| 153 | loff_t *actwrite); |
Stephen Warren | bd6fb31 | 2014-02-03 13:20:59 -0700 | [diff] [blame] | 154 | |
| 155 | /* |
Rob Clark | 4bbcc96 | 2017-09-09 13:15:55 -0400 | [diff] [blame] | 156 | * Directory entry types, matches the subset of DT_x in posix readdir() |
| 157 | * which apply to u-boot. |
| 158 | */ |
| 159 | #define FS_DT_DIR 4 /* directory */ |
| 160 | #define FS_DT_REG 8 /* regular file */ |
| 161 | #define FS_DT_LNK 10 /* symbolic link */ |
| 162 | |
| 163 | /* |
| 164 | * A directory entry, returned by fs_readdir(). Returns information |
| 165 | * about the file/directory at the current directory entry position. |
| 166 | */ |
| 167 | struct fs_dirent { |
| 168 | unsigned type; /* one of FS_DT_x (not a mask) */ |
| 169 | loff_t size; /* size in bytes */ |
| 170 | char name[256]; |
| 171 | }; |
| 172 | |
| 173 | /* Note: fs_dir_stream should be treated as opaque to the user of fs layer */ |
| 174 | struct fs_dir_stream { |
| 175 | /* private to fs. layer: */ |
| 176 | struct blk_desc *desc; |
| 177 | int part; |
| 178 | }; |
| 179 | |
| 180 | /* |
| 181 | * fs_opendir - Open a directory |
| 182 | * |
| 183 | * @filename: the path to directory to open |
| 184 | * @return a pointer to the directory stream or NULL on error and errno |
| 185 | * set appropriately |
| 186 | */ |
| 187 | struct fs_dir_stream *fs_opendir(const char *filename); |
| 188 | |
| 189 | /* |
| 190 | * fs_readdir - Read the next directory entry in the directory stream. |
| 191 | * |
| 192 | * Works in an analogous way to posix readdir(). The previously returned |
| 193 | * directory entry is no longer valid after calling fs_readdir() again. |
| 194 | * After fs_closedir() is called, the returned directory entry is no |
| 195 | * longer valid. |
| 196 | * |
| 197 | * @dirs: the directory stream |
| 198 | * @return the next directory entry (only valid until next fs_readdir() or |
| 199 | * fs_closedir() call, do not attempt to free()) or NULL if the end of |
| 200 | * the directory is reached. |
| 201 | */ |
| 202 | struct fs_dirent *fs_readdir(struct fs_dir_stream *dirs); |
| 203 | |
| 204 | /* |
| 205 | * fs_closedir - close a directory stream |
| 206 | * |
| 207 | * @dirs: the directory stream |
| 208 | */ |
| 209 | void fs_closedir(struct fs_dir_stream *dirs); |
| 210 | |
| 211 | /* |
AKASHI Takahiro | e2519da | 2018-09-11 15:59:13 +0900 | [diff] [blame] | 212 | * fs_unlink - delete a file or directory |
| 213 | * |
| 214 | * If a given name is a directory, it will be deleted only if it's empty |
| 215 | * |
| 216 | * @filename: Name of file or directory to delete |
| 217 | * @return 0 on success, -1 on error conditions |
| 218 | */ |
| 219 | int fs_unlink(const char *filename); |
| 220 | |
| 221 | /* |
AKASHI Takahiro | e7074cf | 2018-09-11 15:59:08 +0900 | [diff] [blame] | 222 | * fs_mkdir - Create a directory |
| 223 | * |
| 224 | * @filename: Name of directory to create |
| 225 | * @return 0 on success, -1 on error conditions |
| 226 | */ |
| 227 | int fs_mkdir(const char *filename); |
| 228 | |
| 229 | /* |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 230 | * Common implementation for various filesystem commands, optionally limited |
| 231 | * to a specific filesystem type via the fstype parameter. |
| 232 | */ |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 233 | int do_size(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[], |
| 234 | int fstype); |
| 235 | int do_load(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[], |
| 236 | int fstype); |
| 237 | int do_ls(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[], |
| 238 | int fstype); |
Stephen Warren | 6152916 | 2014-02-03 13:21:00 -0700 | [diff] [blame] | 239 | int file_exists(const char *dev_type, const char *dev_part, const char *file, |
| 240 | int fstype); |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 241 | int do_save(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[], |
| 242 | int fstype); |
| 243 | int do_rm(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[], |
| 244 | int fstype); |
| 245 | int do_mkdir(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[], |
| 246 | int fstype); |
| 247 | int do_ln(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[], |
Jean-Jacques Hiblot | aaa1215 | 2019-02-13 12:15:26 +0100 | [diff] [blame] | 248 | int fstype); |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 249 | |
Christian Gmeiner | 59e890e | 2014-11-12 14:35:04 +0100 | [diff] [blame] | 250 | /* |
| 251 | * Determine the UUID of the specified filesystem and print it. Optionally it is |
| 252 | * possible to store the UUID directly in env. |
| 253 | */ |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 254 | int do_fs_uuid(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[], |
| 255 | int fstype); |
Christian Gmeiner | 59e890e | 2014-11-12 14:35:04 +0100 | [diff] [blame] | 256 | |
Sjoerd Simons | 1a1ad8e | 2015-01-05 18:13:36 +0100 | [diff] [blame] | 257 | /* |
| 258 | * Determine the type of the specified filesystem and print it. Optionally it is |
| 259 | * possible to store the type directly in env. |
| 260 | */ |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 261 | int do_fs_type(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]); |
Sjoerd Simons | 1a1ad8e | 2015-01-05 18:13:36 +0100 | [diff] [blame] | 262 | |
Niel Fourie | 2280fa5 | 2020-03-24 16:17:04 +0100 | [diff] [blame] | 263 | /** |
| 264 | * do_fs_types - List supported filesystems. |
| 265 | * |
| 266 | * @cmdtp: Command information for fstypes |
| 267 | * @flag: Command flags (CMD_FLAG_...) |
| 268 | * @argc: Number of arguments |
| 269 | * @argv: List of arguments |
| 270 | * @return result (see enum command_ret_t) |
| 271 | */ |
| 272 | int do_fs_types(struct cmd_tbl *cmdtp, int flag, int argc, char * const argv[]); |
| 273 | |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 274 | #endif /* _FS_H */ |