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