blob: b607b0028dce8a98d368a73e0a5efb92bb2698dd [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0 */
Stephen Warren045fa1e2012-10-22 06:43:51 +00002/*
3 * Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved.
Stephen Warren045fa1e2012-10-22 06:43:51 +00004 */
5#ifndef _FS_H
6#define _FS_H
7
8#include <common.h>
Heinrich Schuchardt13c11c62021-05-15 22:06:16 +02009#include <rtc.h>
Stephen Warren045fa1e2012-10-22 06:43:51 +000010
Simon Glass09140112020-05-10 11:40:03 -060011struct cmd_tbl;
12
Stephen Warren045fa1e2012-10-22 06:43:51 +000013#define FS_TYPE_ANY 0
14#define FS_TYPE_FAT 1
15#define FS_TYPE_EXT 2
Simon Glass92ccc962012-12-26 09:53:35 +000016#define FS_TYPE_SANDBOX 3
Hans de Goede251cee02015-09-17 18:46:58 -040017#define FS_TYPE_UBIFS 4
Marek BehĂșn0c936ee2017-09-03 17:00:29 +020018#define FS_TYPE_BTRFS 5
Joao Marcos Costac5100612020-07-30 15:33:47 +020019#define FS_TYPE_SQUASHFS 6
Huang Jianan830613f2022-02-26 15:05:47 +080020#define FS_TYPE_EROFS 7
Stephen Warren045fa1e2012-10-22 06:43:51 +000021
Simon Glasse6f6f9e2020-05-10 11:39:58 -060022struct blk_desc;
23
Simon Glass14449982019-12-28 10:44:44 -070024/**
25 * do_fat_fsload - Run the fatload command
26 *
27 * @cmdtp: Command information for fatload
28 * @flag: Command flags (CMD_FLAG_...)
29 * @argc: Number of arguments
30 * @argv: List of arguments
Heinrich Schuchardt185f8122022-01-19 18:05:50 +010031 * Return: result (see enum command_ret_t)
Simon Glass14449982019-12-28 10:44:44 -070032 */
Simon Glass09140112020-05-10 11:40:03 -060033int do_fat_fsload(struct cmd_tbl *cmdtp, int flag, int argc,
34 char *const argv[]);
Simon Glass14449982019-12-28 10:44:44 -070035
36/**
37 * do_ext2load - Run the ext2load command
38 *
39 * @cmdtp: Command information for ext2load
40 * @flag: Command flags (CMD_FLAG_...)
41 * @argc: Number of arguments
42 * @argv: List of arguments
Heinrich Schuchardt185f8122022-01-19 18:05:50 +010043 * Return: result (see enum command_ret_t)
Simon Glass14449982019-12-28 10:44:44 -070044 */
Simon Glass09140112020-05-10 11:40:03 -060045int do_ext2load(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]);
Simon Glass14449982019-12-28 10:44:44 -070046
Stephen Warren045fa1e2012-10-22 06:43:51 +000047/*
48 * Tell the fs layer which block device an partition to use for future
49 * commands. This also internally identifies the filesystem that is present
50 * within the partition. The identification process may be limited to a
51 * specific filesystem type by passing FS_* in the fstype parameter.
52 *
53 * Returns 0 on success.
54 * Returns non-zero if there is an error accessing the disk or partition, or
55 * no known filesystem type could be recognized on it.
56 */
57int fs_set_blk_dev(const char *ifname, const char *dev_part_str, int fstype);
58
59/*
Rob Clark4bbcc962017-09-09 13:15:55 -040060 * fs_set_blk_dev_with_part - Set current block device + partition
61 *
62 * Similar to fs_set_blk_dev(), but useful for cases where you already
63 * know the blk_desc and part number.
64 *
65 * Returns 0 on success.
66 * Returns non-zero if invalid partition or error accessing the disk.
67 */
68int fs_set_blk_dev_with_part(struct blk_desc *desc, int part);
69
Alex Kiernan0d488e82018-05-29 15:30:50 +000070/**
AKASHI Takahiro64f49eb2019-10-07 14:59:35 +090071 * fs_close() - Unset current block device and partition
72 *
Heinrich Schuchardte4bad9f2019-10-13 10:26:26 +020073 * fs_close() closes the connection to a file system opened with either
74 * fs_set_blk_dev() or fs_set_dev_with_part().
75 *
76 * Many file functions implicitly call fs_close(), e.g. fs_closedir(),
77 * fs_exist(), fs_ln(), fs_ls(), fs_mkdir(), fs_read(), fs_size(), fs_write(),
78 * fs_unlink().
AKASHI Takahiro64f49eb2019-10-07 14:59:35 +090079 */
80void fs_close(void);
81
82/**
AKASHI Takahirob7cd9562019-10-07 14:59:37 +090083 * fs_get_type() - Get type of current filesystem
84 *
85 * Return: filesystem type
86 *
87 * Returns filesystem type representing the current filesystem, or
88 * FS_TYPE_ANY for any unrecognised filesystem.
89 */
90int fs_get_type(void);
91
92/**
Alex Kiernan0d488e82018-05-29 15:30:50 +000093 * fs_get_type_name() - Get type of current filesystem
94 *
95 * Return: Pointer to filesystem name
96 *
97 * Returns a string describing the current filesystem, or the sentinel
98 * "unsupported" for any unrecognised filesystem.
99 */
100const char *fs_get_type_name(void);
101
Rob Clark4bbcc962017-09-09 13:15:55 -0400102/*
Stephen Warren045fa1e2012-10-22 06:43:51 +0000103 * Print the list of files on the partition previously set by fs_set_blk_dev(),
104 * in directory "dirname".
105 *
106 * Returns 0 on success. Returns non-zero on error.
107 */
108int fs_ls(const char *dirname);
109
110/*
Stephen Warren61529162014-02-03 13:21:00 -0700111 * Determine whether a file exists
112 *
113 * Returns 1 if the file exists, 0 if it doesn't exist.
114 */
115int fs_exists(const char *filename);
116
117/*
Suriyan Ramasamid455d872014-11-17 14:39:38 -0800118 * fs_size - Determine a file's size
Stephen Warrencf659812014-06-11 12:47:26 -0600119 *
Suriyan Ramasamid455d872014-11-17 14:39:38 -0800120 * @filename: Name of the file
121 * @size: Size of file
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100122 * Return: 0 if ok with valid *size, negative on error
Stephen Warrencf659812014-06-11 12:47:26 -0600123 */
Suriyan Ramasamid455d872014-11-17 14:39:38 -0800124int fs_size(const char *filename, loff_t *size);
Stephen Warrencf659812014-06-11 12:47:26 -0600125
Heinrich Schuchardta0e92cd2019-04-25 20:36:39 +0200126/**
127 * fs_read() - read file from the partition previously set by fs_set_blk_dev()
Stephen Warren045fa1e2012-10-22 06:43:51 +0000128 *
Heinrich Schuchardta0e92cd2019-04-25 20:36:39 +0200129 * Note that not all filesystem drivers support either or both of offset != 0
130 * and len != 0.
131 *
132 * @filename: full path of the file to read from
133 * @addr: address of the buffer to write to
134 * @offset: offset in the file from where to start reading
135 * @len: the number of bytes to read. Use 0 to read entire file.
136 * @actread: returns the actual number of bytes read
137 * Return: 0 if OK with valid *actread, -1 on error conditions
Stephen Warren045fa1e2012-10-22 06:43:51 +0000138 */
Suriyan Ramasamid455d872014-11-17 14:39:38 -0800139int fs_read(const char *filename, ulong addr, loff_t offset, loff_t len,
140 loff_t *actread);
Stephen Warren045fa1e2012-10-22 06:43:51 +0000141
Heinrich Schuchardta0e92cd2019-04-25 20:36:39 +0200142/**
143 * fs_write() - write file to the partition previously set by fs_set_blk_dev()
Stephen Warrenbd6fb312014-02-03 13:20:59 -0700144 *
Heinrich Schuchardta0e92cd2019-04-25 20:36:39 +0200145 * Note that not all filesystem drivers support offset != 0.
146 *
147 * @filename: full path of the file to write to
148 * @addr: address of the buffer to read from
149 * @offset: offset in the file from where to start writing
150 * @len: the number of bytes to write
151 * @actwrite: returns the actual number of bytes written
152 * Return: 0 if OK with valid *actwrite, -1 on error conditions
Stephen Warrenbd6fb312014-02-03 13:20:59 -0700153 */
Suriyan Ramasamid455d872014-11-17 14:39:38 -0800154int fs_write(const char *filename, ulong addr, loff_t offset, loff_t len,
155 loff_t *actwrite);
Stephen Warrenbd6fb312014-02-03 13:20:59 -0700156
157/*
Rob Clark4bbcc962017-09-09 13:15:55 -0400158 * Directory entry types, matches the subset of DT_x in posix readdir()
159 * which apply to u-boot.
160 */
161#define FS_DT_DIR 4 /* directory */
162#define FS_DT_REG 8 /* regular file */
163#define FS_DT_LNK 10 /* symbolic link */
164
Heinrich Schuchardt13c11c62021-05-15 22:06:16 +0200165/**
166 * struct fs_dirent - directory entry
167 *
168 * A directory entry, returned by fs_readdir(). Returns information
Rob Clark4bbcc962017-09-09 13:15:55 -0400169 * about the file/directory at the current directory entry position.
170 */
171struct fs_dirent {
Heinrich Schuchardt13c11c62021-05-15 22:06:16 +0200172 /** @type: one of FS_DT_x (not a mask) */
173 unsigned int type;
174 /** @size: file size */
175 loff_t size;
176 /** @flags: attribute flags (FS_ATTR_*) */
177 u32 attr;
178 /** create_time: time of creation */
179 struct rtc_time create_time;
180 /** access_time: time of last access */
181 struct rtc_time access_time;
182 /** change_time: time of last modification */
183 struct rtc_time change_time;
184 /** name: file name */
Rob Clark4bbcc962017-09-09 13:15:55 -0400185 char name[256];
186};
187
188/* Note: fs_dir_stream should be treated as opaque to the user of fs layer */
189struct fs_dir_stream {
190 /* private to fs. layer: */
191 struct blk_desc *desc;
192 int part;
193};
194
195/*
196 * fs_opendir - Open a directory
197 *
198 * @filename: the path to directory to open
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100199 * Return: a pointer to the directory stream or NULL on error and errno
Rob Clark4bbcc962017-09-09 13:15:55 -0400200 * set appropriately
201 */
202struct fs_dir_stream *fs_opendir(const char *filename);
203
204/*
205 * fs_readdir - Read the next directory entry in the directory stream.
206 *
207 * Works in an analogous way to posix readdir(). The previously returned
208 * directory entry is no longer valid after calling fs_readdir() again.
209 * After fs_closedir() is called, the returned directory entry is no
210 * longer valid.
211 *
212 * @dirs: the directory stream
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100213 * Return: the next directory entry (only valid until next fs_readdir() or
Rob Clark4bbcc962017-09-09 13:15:55 -0400214 * fs_closedir() call, do not attempt to free()) or NULL if the end of
215 * the directory is reached.
216 */
217struct fs_dirent *fs_readdir(struct fs_dir_stream *dirs);
218
219/*
220 * fs_closedir - close a directory stream
221 *
222 * @dirs: the directory stream
223 */
224void fs_closedir(struct fs_dir_stream *dirs);
225
226/*
AKASHI Takahiroe2519da2018-09-11 15:59:13 +0900227 * fs_unlink - delete a file or directory
228 *
229 * If a given name is a directory, it will be deleted only if it's empty
230 *
231 * @filename: Name of file or directory to delete
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100232 * Return: 0 on success, -1 on error conditions
AKASHI Takahiroe2519da2018-09-11 15:59:13 +0900233 */
234int fs_unlink(const char *filename);
235
236/*
AKASHI Takahiroe7074cf2018-09-11 15:59:08 +0900237 * fs_mkdir - Create a directory
238 *
239 * @filename: Name of directory to create
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100240 * Return: 0 on success, -1 on error conditions
AKASHI Takahiroe7074cf2018-09-11 15:59:08 +0900241 */
242int fs_mkdir(const char *filename);
243
244/*
Stephen Warren045fa1e2012-10-22 06:43:51 +0000245 * Common implementation for various filesystem commands, optionally limited
246 * to a specific filesystem type via the fstype parameter.
247 */
Simon Glass09140112020-05-10 11:40:03 -0600248int do_size(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[],
249 int fstype);
250int do_load(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[],
251 int fstype);
252int do_ls(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[],
253 int fstype);
Stephen Warren61529162014-02-03 13:21:00 -0700254int file_exists(const char *dev_type, const char *dev_part, const char *file,
255 int fstype);
Simon Glass09140112020-05-10 11:40:03 -0600256int do_save(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[],
257 int fstype);
258int do_rm(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[],
259 int fstype);
260int do_mkdir(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[],
261 int fstype);
262int do_ln(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[],
Jean-Jacques Hiblotaaa12152019-02-13 12:15:26 +0100263 int fstype);
Stephen Warren045fa1e2012-10-22 06:43:51 +0000264
Christian Gmeiner59e890e2014-11-12 14:35:04 +0100265/*
266 * Determine the UUID of the specified filesystem and print it. Optionally it is
267 * possible to store the UUID directly in env.
268 */
Simon Glass09140112020-05-10 11:40:03 -0600269int do_fs_uuid(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[],
270 int fstype);
Christian Gmeiner59e890e2014-11-12 14:35:04 +0100271
Sjoerd Simons1a1ad8e2015-01-05 18:13:36 +0100272/*
273 * Determine the type of the specified filesystem and print it. Optionally it is
274 * possible to store the type directly in env.
275 */
Simon Glass09140112020-05-10 11:40:03 -0600276int do_fs_type(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]);
Sjoerd Simons1a1ad8e2015-01-05 18:13:36 +0100277
Niel Fourie2280fa52020-03-24 16:17:04 +0100278/**
279 * do_fs_types - List supported filesystems.
280 *
281 * @cmdtp: Command information for fstypes
282 * @flag: Command flags (CMD_FLAG_...)
283 * @argc: Number of arguments
284 * @argv: List of arguments
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100285 * Return: result (see enum command_ret_t)
Niel Fourie2280fa52020-03-24 16:17:04 +0100286 */
287int do_fs_types(struct cmd_tbl *cmdtp, int flag, int argc, char * const argv[]);
288
Stephen Warren045fa1e2012-10-22 06:43:51 +0000289#endif /* _FS_H */