Stephen Warren | eefbc3f | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved. |
| 3 | * |
Tom Rini | e237880 | 2016-01-14 22:05:13 -0500 | [diff] [blame] | 4 | * SPDX-License-Identifier: GPL-2.0 |
Stephen Warren | eefbc3f | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 5 | */ |
| 6 | #ifndef _FS_H |
| 7 | #define _FS_H |
| 8 | |
| 9 | #include <common.h> |
| 10 | |
| 11 | #define FS_TYPE_ANY 0 |
| 12 | #define FS_TYPE_FAT 1 |
| 13 | #define FS_TYPE_EXT 2 |
Simon Glass | 1184287 | 2012-12-26 09:53:35 +0000 | [diff] [blame] | 14 | #define FS_TYPE_SANDBOX 3 |
Hans de Goede | 690c796 | 2015-09-17 18:46:58 -0400 | [diff] [blame] | 15 | #define FS_TYPE_UBIFS 4 |
Marek BehĂșn | 98ec1d1 | 2017-09-03 17:00:29 +0200 | [diff] [blame] | 16 | #define FS_TYPE_BTRFS 5 |
Stephen Warren | eefbc3f | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 17 | |
| 18 | /* |
| 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. |
| 23 | * |
| 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. |
| 27 | */ |
| 28 | int fs_set_blk_dev(const char *ifname, const char *dev_part_str, int fstype); |
| 29 | |
| 30 | /* |
Rob Clark | 2b7bfd9 | 2017-09-09 13:15:55 -0400 | [diff] [blame] | 31 | * fs_set_blk_dev_with_part - Set current block device + partition |
| 32 | * |
| 33 | * Similar to fs_set_blk_dev(), but useful for cases where you already |
| 34 | * know the blk_desc and part number. |
| 35 | * |
| 36 | * Returns 0 on success. |
| 37 | * Returns non-zero if invalid partition or error accessing the disk. |
| 38 | */ |
| 39 | int fs_set_blk_dev_with_part(struct blk_desc *desc, int part); |
| 40 | |
| 41 | /* |
Stephen Warren | eefbc3f | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 42 | * Print the list of files on the partition previously set by fs_set_blk_dev(), |
| 43 | * in directory "dirname". |
| 44 | * |
| 45 | * Returns 0 on success. Returns non-zero on error. |
| 46 | */ |
| 47 | int fs_ls(const char *dirname); |
| 48 | |
| 49 | /* |
Stephen Warren | d008fbb | 2014-02-03 13:21:00 -0700 | [diff] [blame] | 50 | * Determine whether a file exists |
| 51 | * |
| 52 | * Returns 1 if the file exists, 0 if it doesn't exist. |
| 53 | */ |
| 54 | int fs_exists(const char *filename); |
| 55 | |
| 56 | /* |
Suriyan Ramasami | 96171fb | 2014-11-17 14:39:38 -0800 | [diff] [blame] | 57 | * fs_size - Determine a file's size |
Stephen Warren | 3eb58f5 | 2014-06-11 12:47:26 -0600 | [diff] [blame] | 58 | * |
Suriyan Ramasami | 96171fb | 2014-11-17 14:39:38 -0800 | [diff] [blame] | 59 | * @filename: Name of the file |
| 60 | * @size: Size of file |
| 61 | * @return 0 if ok with valid *size, negative on error |
Stephen Warren | 3eb58f5 | 2014-06-11 12:47:26 -0600 | [diff] [blame] | 62 | */ |
Suriyan Ramasami | 96171fb | 2014-11-17 14:39:38 -0800 | [diff] [blame] | 63 | int fs_size(const char *filename, loff_t *size); |
Stephen Warren | 3eb58f5 | 2014-06-11 12:47:26 -0600 | [diff] [blame] | 64 | |
| 65 | /* |
Suriyan Ramasami | 96171fb | 2014-11-17 14:39:38 -0800 | [diff] [blame] | 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. |
Stephen Warren | eefbc3f | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 68 | * |
Suriyan Ramasami | 96171fb | 2014-11-17 14:39:38 -0800 | [diff] [blame] | 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 |
Stephen Warren | eefbc3f | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 75 | */ |
Suriyan Ramasami | 96171fb | 2014-11-17 14:39:38 -0800 | [diff] [blame] | 76 | int fs_read(const char *filename, ulong addr, loff_t offset, loff_t len, |
| 77 | loff_t *actread); |
Stephen Warren | eefbc3f | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 78 | |
| 79 | /* |
Suriyan Ramasami | 96171fb | 2014-11-17 14:39:38 -0800 | [diff] [blame] | 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. |
Stephen Warren | 9df2580 | 2014-02-03 13:20:59 -0700 | [diff] [blame] | 82 | * |
Suriyan Ramasami | 96171fb | 2014-11-17 14:39:38 -0800 | [diff] [blame] | 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 |
Stephen Warren | 9df2580 | 2014-02-03 13:20:59 -0700 | [diff] [blame] | 89 | */ |
Suriyan Ramasami | 96171fb | 2014-11-17 14:39:38 -0800 | [diff] [blame] | 90 | int fs_write(const char *filename, ulong addr, loff_t offset, loff_t len, |
| 91 | loff_t *actwrite); |
Stephen Warren | 9df2580 | 2014-02-03 13:20:59 -0700 | [diff] [blame] | 92 | |
| 93 | /* |
Rob Clark | 2b7bfd9 | 2017-09-09 13:15:55 -0400 | [diff] [blame] | 94 | * Directory entry types, matches the subset of DT_x in posix readdir() |
| 95 | * which apply to u-boot. |
| 96 | */ |
| 97 | #define FS_DT_DIR 4 /* directory */ |
| 98 | #define FS_DT_REG 8 /* regular file */ |
| 99 | #define FS_DT_LNK 10 /* symbolic link */ |
| 100 | |
| 101 | /* |
| 102 | * A directory entry, returned by fs_readdir(). Returns information |
| 103 | * about the file/directory at the current directory entry position. |
| 104 | */ |
| 105 | struct fs_dirent { |
| 106 | unsigned type; /* one of FS_DT_x (not a mask) */ |
| 107 | loff_t size; /* size in bytes */ |
| 108 | char name[256]; |
| 109 | }; |
| 110 | |
| 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; |
| 115 | int part; |
| 116 | }; |
| 117 | |
| 118 | /* |
| 119 | * fs_opendir - Open a directory |
| 120 | * |
| 121 | * @filename: the path to directory to open |
| 122 | * @return a pointer to the directory stream or NULL on error and errno |
| 123 | * set appropriately |
| 124 | */ |
| 125 | struct fs_dir_stream *fs_opendir(const char *filename); |
| 126 | |
| 127 | /* |
| 128 | * fs_readdir - Read the next directory entry in the directory stream. |
| 129 | * |
| 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 |
| 133 | * longer valid. |
| 134 | * |
| 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. |
| 139 | */ |
| 140 | struct fs_dirent *fs_readdir(struct fs_dir_stream *dirs); |
| 141 | |
| 142 | /* |
| 143 | * fs_closedir - close a directory stream |
| 144 | * |
| 145 | * @dirs: the directory stream |
| 146 | */ |
| 147 | void fs_closedir(struct fs_dir_stream *dirs); |
| 148 | |
| 149 | /* |
Stephen Warren | eefbc3f | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 150 | * Common implementation for various filesystem commands, optionally limited |
| 151 | * to a specific filesystem type via the fstype parameter. |
| 152 | */ |
Stephen Warren | 3eb58f5 | 2014-06-11 12:47:26 -0600 | [diff] [blame] | 153 | int do_size(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[], |
| 154 | int fstype); |
Stephen Warren | 128d3d9 | 2012-10-31 11:05:07 +0000 | [diff] [blame] | 155 | int do_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[], |
Wolfgang Denk | a10c7a5 | 2013-10-05 21:07:25 +0200 | [diff] [blame] | 156 | int fstype); |
Stephen Warren | eefbc3f | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 157 | int do_ls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[], |
| 158 | int fstype); |
Stephen Warren | d008fbb | 2014-02-03 13:21:00 -0700 | [diff] [blame] | 159 | int file_exists(const char *dev_type, const char *dev_part, const char *file, |
| 160 | int fstype); |
Simon Glass | eda14ea | 2013-04-20 08:42:50 +0000 | [diff] [blame] | 161 | int do_save(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[], |
Wolfgang Denk | a10c7a5 | 2013-10-05 21:07:25 +0200 | [diff] [blame] | 162 | int fstype); |
Stephen Warren | eefbc3f | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 163 | |
Christian Gmeiner | 9f9eec3 | 2014-11-12 14:35:04 +0100 | [diff] [blame] | 164 | /* |
| 165 | * Determine the UUID of the specified filesystem and print it. Optionally it is |
| 166 | * possible to store the UUID directly in env. |
| 167 | */ |
| 168 | int do_fs_uuid(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[], |
| 169 | int fstype); |
| 170 | |
Sjoerd Simons | 7d9faf6 | 2015-01-05 18:13:36 +0100 | [diff] [blame] | 171 | /* |
| 172 | * Determine the type of the specified filesystem and print it. Optionally it is |
| 173 | * possible to store the type directly in env. |
| 174 | */ |
| 175 | int do_fs_type(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]); |
| 176 | |
Stephen Warren | eefbc3f | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 177 | #endif /* _FS_H */ |