Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved. |
| 3 | * |
Tom Rini | 5b8031c | 2016-01-14 22:05:13 -0500 | [diff] [blame] | 4 | * SPDX-License-Identifier: GPL-2.0 |
Stephen Warren | 045fa1e | 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 | 92ccc96 | 2012-12-26 09:53:35 +0000 | [diff] [blame] | 14 | #define FS_TYPE_SANDBOX 3 |
Hans de Goede | 251cee0 | 2015-09-17 18:46:58 -0400 | [diff] [blame] | 15 | #define FS_TYPE_UBIFS 4 |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 16 | |
| 17 | /* |
| 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. |
| 22 | * |
| 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. |
| 26 | */ |
| 27 | int fs_set_blk_dev(const char *ifname, const char *dev_part_str, int fstype); |
| 28 | |
| 29 | /* |
Rob Clark | 4bbcc96 | 2017-09-09 13:15:55 -0400 | [diff] [blame] | 30 | * fs_set_blk_dev_with_part - Set current block device + partition |
| 31 | * |
| 32 | * Similar to fs_set_blk_dev(), but useful for cases where you already |
| 33 | * know the blk_desc and part number. |
| 34 | * |
| 35 | * Returns 0 on success. |
| 36 | * Returns non-zero if invalid partition or error accessing the disk. |
| 37 | */ |
| 38 | int fs_set_blk_dev_with_part(struct blk_desc *desc, int part); |
| 39 | |
| 40 | /* |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 41 | * Print the list of files on the partition previously set by fs_set_blk_dev(), |
| 42 | * in directory "dirname". |
| 43 | * |
| 44 | * Returns 0 on success. Returns non-zero on error. |
| 45 | */ |
| 46 | int fs_ls(const char *dirname); |
| 47 | |
| 48 | /* |
Stephen Warren | 6152916 | 2014-02-03 13:21:00 -0700 | [diff] [blame] | 49 | * Determine whether a file exists |
| 50 | * |
| 51 | * Returns 1 if the file exists, 0 if it doesn't exist. |
| 52 | */ |
| 53 | int fs_exists(const char *filename); |
| 54 | |
| 55 | /* |
Suriyan Ramasami | d455d87 | 2014-11-17 14:39:38 -0800 | [diff] [blame] | 56 | * fs_size - Determine a file's size |
Stephen Warren | cf65981 | 2014-06-11 12:47:26 -0600 | [diff] [blame] | 57 | * |
Suriyan Ramasami | d455d87 | 2014-11-17 14:39:38 -0800 | [diff] [blame] | 58 | * @filename: Name of the file |
| 59 | * @size: Size of file |
| 60 | * @return 0 if ok with valid *size, negative on error |
Stephen Warren | cf65981 | 2014-06-11 12:47:26 -0600 | [diff] [blame] | 61 | */ |
Suriyan Ramasami | d455d87 | 2014-11-17 14:39:38 -0800 | [diff] [blame] | 62 | int fs_size(const char *filename, loff_t *size); |
Stephen Warren | cf65981 | 2014-06-11 12:47:26 -0600 | [diff] [blame] | 63 | |
| 64 | /* |
Suriyan Ramasami | d455d87 | 2014-11-17 14:39:38 -0800 | [diff] [blame] | 65 | * fs_read - Read file from the partition previously set by fs_set_blk_dev() |
| 66 | * Note that not all filesystem types support either/both offset!=0 or len!=0. |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 67 | * |
Suriyan Ramasami | d455d87 | 2014-11-17 14:39:38 -0800 | [diff] [blame] | 68 | * @filename: Name of file to read from |
| 69 | * @addr: The address to read into |
| 70 | * @offset: The offset in file to read from |
| 71 | * @len: The number of bytes to read. Maybe 0 to read entire file |
| 72 | * @actread: Returns the actual number of bytes read |
| 73 | * @return 0 if ok with valid *actread, -1 on error conditions |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 74 | */ |
Suriyan Ramasami | d455d87 | 2014-11-17 14:39:38 -0800 | [diff] [blame] | 75 | int fs_read(const char *filename, ulong addr, loff_t offset, loff_t len, |
| 76 | loff_t *actread); |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 77 | |
| 78 | /* |
Suriyan Ramasami | d455d87 | 2014-11-17 14:39:38 -0800 | [diff] [blame] | 79 | * fs_write - Write file to the partition previously set by fs_set_blk_dev() |
| 80 | * Note that not all filesystem types support offset!=0. |
Stephen Warren | bd6fb31 | 2014-02-03 13:20:59 -0700 | [diff] [blame] | 81 | * |
Suriyan Ramasami | d455d87 | 2014-11-17 14:39:38 -0800 | [diff] [blame] | 82 | * @filename: Name of file to read from |
| 83 | * @addr: The address to read into |
| 84 | * @offset: The offset in file to read from. Maybe 0 to write to start of file |
| 85 | * @len: The number of bytes to write |
| 86 | * @actwrite: Returns the actual number of bytes written |
| 87 | * @return 0 if ok with valid *actwrite, -1 on error conditions |
Stephen Warren | bd6fb31 | 2014-02-03 13:20:59 -0700 | [diff] [blame] | 88 | */ |
Suriyan Ramasami | d455d87 | 2014-11-17 14:39:38 -0800 | [diff] [blame] | 89 | int fs_write(const char *filename, ulong addr, loff_t offset, loff_t len, |
| 90 | loff_t *actwrite); |
Stephen Warren | bd6fb31 | 2014-02-03 13:20:59 -0700 | [diff] [blame] | 91 | |
| 92 | /* |
Rob Clark | 4bbcc96 | 2017-09-09 13:15:55 -0400 | [diff] [blame] | 93 | * Directory entry types, matches the subset of DT_x in posix readdir() |
| 94 | * which apply to u-boot. |
| 95 | */ |
| 96 | #define FS_DT_DIR 4 /* directory */ |
| 97 | #define FS_DT_REG 8 /* regular file */ |
| 98 | #define FS_DT_LNK 10 /* symbolic link */ |
| 99 | |
| 100 | /* |
| 101 | * A directory entry, returned by fs_readdir(). Returns information |
| 102 | * about the file/directory at the current directory entry position. |
| 103 | */ |
| 104 | struct fs_dirent { |
| 105 | unsigned type; /* one of FS_DT_x (not a mask) */ |
| 106 | loff_t size; /* size in bytes */ |
| 107 | char name[256]; |
| 108 | }; |
| 109 | |
| 110 | /* Note: fs_dir_stream should be treated as opaque to the user of fs layer */ |
| 111 | struct fs_dir_stream { |
| 112 | /* private to fs. layer: */ |
| 113 | struct blk_desc *desc; |
| 114 | int part; |
| 115 | }; |
| 116 | |
| 117 | /* |
| 118 | * fs_opendir - Open a directory |
| 119 | * |
| 120 | * @filename: the path to directory to open |
| 121 | * @return a pointer to the directory stream or NULL on error and errno |
| 122 | * set appropriately |
| 123 | */ |
| 124 | struct fs_dir_stream *fs_opendir(const char *filename); |
| 125 | |
| 126 | /* |
| 127 | * fs_readdir - Read the next directory entry in the directory stream. |
| 128 | * |
| 129 | * Works in an analogous way to posix readdir(). The previously returned |
| 130 | * directory entry is no longer valid after calling fs_readdir() again. |
| 131 | * After fs_closedir() is called, the returned directory entry is no |
| 132 | * longer valid. |
| 133 | * |
| 134 | * @dirs: the directory stream |
| 135 | * @return the next directory entry (only valid until next fs_readdir() or |
| 136 | * fs_closedir() call, do not attempt to free()) or NULL if the end of |
| 137 | * the directory is reached. |
| 138 | */ |
| 139 | struct fs_dirent *fs_readdir(struct fs_dir_stream *dirs); |
| 140 | |
| 141 | /* |
| 142 | * fs_closedir - close a directory stream |
| 143 | * |
| 144 | * @dirs: the directory stream |
| 145 | */ |
| 146 | void fs_closedir(struct fs_dir_stream *dirs); |
| 147 | |
| 148 | /* |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 149 | * Common implementation for various filesystem commands, optionally limited |
| 150 | * to a specific filesystem type via the fstype parameter. |
| 151 | */ |
Stephen Warren | cf65981 | 2014-06-11 12:47:26 -0600 | [diff] [blame] | 152 | int do_size(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[], |
| 153 | int fstype); |
Stephen Warren | f9b55e2 | 2012-10-31 11:05:07 +0000 | [diff] [blame] | 154 | int do_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[], |
Wolfgang Denk | b770e88 | 2013-10-05 21:07:25 +0200 | [diff] [blame] | 155 | int fstype); |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 156 | int do_ls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[], |
| 157 | int fstype); |
Stephen Warren | 6152916 | 2014-02-03 13:21:00 -0700 | [diff] [blame] | 158 | int file_exists(const char *dev_type, const char *dev_part, const char *file, |
| 159 | int fstype); |
Simon Glass | a8f6ab5 | 2013-04-20 08:42:50 +0000 | [diff] [blame] | 160 | int do_save(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[], |
Wolfgang Denk | b770e88 | 2013-10-05 21:07:25 +0200 | [diff] [blame] | 161 | int fstype); |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 162 | |
Christian Gmeiner | 59e890e | 2014-11-12 14:35:04 +0100 | [diff] [blame] | 163 | /* |
| 164 | * Determine the UUID of the specified filesystem and print it. Optionally it is |
| 165 | * possible to store the UUID directly in env. |
| 166 | */ |
| 167 | int do_fs_uuid(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[], |
| 168 | int fstype); |
| 169 | |
Sjoerd Simons | 1a1ad8e | 2015-01-05 18:13:36 +0100 | [diff] [blame] | 170 | /* |
| 171 | * Determine the type of the specified filesystem and print it. Optionally it is |
| 172 | * possible to store the type directly in env. |
| 173 | */ |
| 174 | int do_fs_type(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]); |
| 175 | |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 176 | #endif /* _FS_H */ |