blob: 37e35c21206e96a1dac5320f28295cc92a595e15 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0 */
Stephen Warreneefbc3f2012-10-22 06:43:51 +00002/*
3 * Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved.
Stephen Warreneefbc3f2012-10-22 06:43:51 +00004 */
5#ifndef _FS_H
6#define _FS_H
7
8#include <common.h>
9
10#define FS_TYPE_ANY 0
11#define FS_TYPE_FAT 1
12#define FS_TYPE_EXT 2
Simon Glass11842872012-12-26 09:53:35 +000013#define FS_TYPE_SANDBOX 3
Hans de Goede690c7962015-09-17 18:46:58 -040014#define FS_TYPE_UBIFS 4
Marek BehĂșn98ec1d12017-09-03 17:00:29 +020015#define FS_TYPE_BTRFS 5
Stephen Warreneefbc3f2012-10-22 06:43:51 +000016
Simon Glass1b3f75f2019-12-28 10:44:44 -070017/**
18 * do_fat_fsload - Run the fatload command
19 *
20 * @cmdtp: Command information for fatload
21 * @flag: Command flags (CMD_FLAG_...)
22 * @argc: Number of arguments
23 * @argv: List of arguments
24 * @return result (see enum command_ret_t)
25 */
26int do_fat_fsload(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]);
27
28/**
29 * do_ext2load - Run the ext2load command
30 *
31 * @cmdtp: Command information for ext2load
32 * @flag: Command flags (CMD_FLAG_...)
33 * @argc: Number of arguments
34 * @argv: List of arguments
35 * @return result (see enum command_ret_t)
36 */
37int do_ext2load(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]);
38
Stephen Warreneefbc3f2012-10-22 06:43:51 +000039/*
40 * Tell the fs layer which block device an partition to use for future
41 * commands. This also internally identifies the filesystem that is present
42 * within the partition. The identification process may be limited to a
43 * specific filesystem type by passing FS_* in the fstype parameter.
44 *
45 * Returns 0 on success.
46 * Returns non-zero if there is an error accessing the disk or partition, or
47 * no known filesystem type could be recognized on it.
48 */
49int fs_set_blk_dev(const char *ifname, const char *dev_part_str, int fstype);
50
51/*
Rob Clark2b7bfd92017-09-09 13:15:55 -040052 * fs_set_blk_dev_with_part - Set current block device + partition
53 *
54 * Similar to fs_set_blk_dev(), but useful for cases where you already
55 * know the blk_desc and part number.
56 *
57 * Returns 0 on success.
58 * Returns non-zero if invalid partition or error accessing the disk.
59 */
60int fs_set_blk_dev_with_part(struct blk_desc *desc, int part);
61
Alex Kiernan3a6163a2018-05-29 15:30:50 +000062/**
AKASHI Takahiroca8e3772019-10-07 14:59:35 +090063 * fs_close() - Unset current block device and partition
64 *
Heinrich Schuchardt63a57522019-10-13 10:26:26 +020065 * fs_close() closes the connection to a file system opened with either
66 * fs_set_blk_dev() or fs_set_dev_with_part().
67 *
68 * Many file functions implicitly call fs_close(), e.g. fs_closedir(),
69 * fs_exist(), fs_ln(), fs_ls(), fs_mkdir(), fs_read(), fs_size(), fs_write(),
70 * fs_unlink().
AKASHI Takahiroca8e3772019-10-07 14:59:35 +090071 */
72void fs_close(void);
73
74/**
AKASHI Takahiro80ac7342019-10-07 14:59:37 +090075 * fs_get_type() - Get type of current filesystem
76 *
77 * Return: filesystem type
78 *
79 * Returns filesystem type representing the current filesystem, or
80 * FS_TYPE_ANY for any unrecognised filesystem.
81 */
82int fs_get_type(void);
83
84/**
Alex Kiernan3a6163a2018-05-29 15:30:50 +000085 * fs_get_type_name() - Get type of current filesystem
86 *
87 * Return: Pointer to filesystem name
88 *
89 * Returns a string describing the current filesystem, or the sentinel
90 * "unsupported" for any unrecognised filesystem.
91 */
92const char *fs_get_type_name(void);
93
Rob Clark2b7bfd92017-09-09 13:15:55 -040094/*
Stephen Warreneefbc3f2012-10-22 06:43:51 +000095 * Print the list of files on the partition previously set by fs_set_blk_dev(),
96 * in directory "dirname".
97 *
98 * Returns 0 on success. Returns non-zero on error.
99 */
100int fs_ls(const char *dirname);
101
102/*
Stephen Warrend008fbb2014-02-03 13:21:00 -0700103 * Determine whether a file exists
104 *
105 * Returns 1 if the file exists, 0 if it doesn't exist.
106 */
107int fs_exists(const char *filename);
108
109/*
Suriyan Ramasami96171fb2014-11-17 14:39:38 -0800110 * fs_size - Determine a file's size
Stephen Warren3eb58f52014-06-11 12:47:26 -0600111 *
Suriyan Ramasami96171fb2014-11-17 14:39:38 -0800112 * @filename: Name of the file
113 * @size: Size of file
114 * @return 0 if ok with valid *size, negative on error
Stephen Warren3eb58f52014-06-11 12:47:26 -0600115 */
Suriyan Ramasami96171fb2014-11-17 14:39:38 -0800116int fs_size(const char *filename, loff_t *size);
Stephen Warren3eb58f52014-06-11 12:47:26 -0600117
Heinrich Schuchardt5f1d6952019-04-25 20:36:39 +0200118/**
119 * fs_read() - read file from the partition previously set by fs_set_blk_dev()
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000120 *
Heinrich Schuchardt5f1d6952019-04-25 20:36:39 +0200121 * Note that not all filesystem drivers support either or both of offset != 0
122 * and len != 0.
123 *
124 * @filename: full path of the file to read from
125 * @addr: address of the buffer to write to
126 * @offset: offset in the file from where to start reading
127 * @len: the number of bytes to read. Use 0 to read entire file.
128 * @actread: returns the actual number of bytes read
129 * Return: 0 if OK with valid *actread, -1 on error conditions
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000130 */
Suriyan Ramasami96171fb2014-11-17 14:39:38 -0800131int fs_read(const char *filename, ulong addr, loff_t offset, loff_t len,
132 loff_t *actread);
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000133
Heinrich Schuchardt5f1d6952019-04-25 20:36:39 +0200134/**
135 * fs_write() - write file to the partition previously set by fs_set_blk_dev()
136 *
137 * Note that not all filesystem drivers support offset != 0.
Stephen Warren9df25802014-02-03 13:20:59 -0700138 *
Heinrich Schuchardt5f1d6952019-04-25 20:36:39 +0200139 * @filename: full path of the file to write to
140 * @addr: address of the buffer to read from
141 * @offset: offset in the file from where to start writing
142 * @len: the number of bytes to write
143 * @actwrite: returns the actual number of bytes written
144 * Return: 0 if OK with valid *actwrite, -1 on error conditions
Stephen Warren9df25802014-02-03 13:20:59 -0700145 */
Suriyan Ramasami96171fb2014-11-17 14:39:38 -0800146int fs_write(const char *filename, ulong addr, loff_t offset, loff_t len,
147 loff_t *actwrite);
Stephen Warren9df25802014-02-03 13:20:59 -0700148
149/*
Rob Clark2b7bfd92017-09-09 13:15:55 -0400150 * Directory entry types, matches the subset of DT_x in posix readdir()
151 * which apply to u-boot.
152 */
153#define FS_DT_DIR 4 /* directory */
154#define FS_DT_REG 8 /* regular file */
155#define FS_DT_LNK 10 /* symbolic link */
156
157/*
158 * A directory entry, returned by fs_readdir(). Returns information
159 * about the file/directory at the current directory entry position.
160 */
161struct fs_dirent {
162 unsigned type; /* one of FS_DT_x (not a mask) */
163 loff_t size; /* size in bytes */
164 char name[256];
165};
166
167/* Note: fs_dir_stream should be treated as opaque to the user of fs layer */
168struct fs_dir_stream {
169 /* private to fs. layer: */
170 struct blk_desc *desc;
171 int part;
172};
173
174/*
175 * fs_opendir - Open a directory
176 *
177 * @filename: the path to directory to open
178 * @return a pointer to the directory stream or NULL on error and errno
179 * set appropriately
180 */
181struct fs_dir_stream *fs_opendir(const char *filename);
182
183/*
184 * fs_readdir - Read the next directory entry in the directory stream.
185 *
186 * Works in an analogous way to posix readdir(). The previously returned
187 * directory entry is no longer valid after calling fs_readdir() again.
188 * After fs_closedir() is called, the returned directory entry is no
189 * longer valid.
190 *
191 * @dirs: the directory stream
192 * @return the next directory entry (only valid until next fs_readdir() or
193 * fs_closedir() call, do not attempt to free()) or NULL if the end of
194 * the directory is reached.
195 */
196struct fs_dirent *fs_readdir(struct fs_dir_stream *dirs);
197
198/*
199 * fs_closedir - close a directory stream
200 *
201 * @dirs: the directory stream
202 */
203void fs_closedir(struct fs_dir_stream *dirs);
204
205/*
AKASHI Takahiro1ba42532018-09-11 15:59:13 +0900206 * fs_unlink - delete a file or directory
207 *
208 * If a given name is a directory, it will be deleted only if it's empty
209 *
210 * @filename: Name of file or directory to delete
211 * @return 0 on success, -1 on error conditions
212 */
213int fs_unlink(const char *filename);
214
215/*
AKASHI Takahiroadc8c9f2018-09-11 15:59:08 +0900216 * fs_mkdir - Create a directory
217 *
218 * @filename: Name of directory to create
219 * @return 0 on success, -1 on error conditions
220 */
221int fs_mkdir(const char *filename);
222
223/*
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000224 * Common implementation for various filesystem commands, optionally limited
225 * to a specific filesystem type via the fstype parameter.
226 */
Stephen Warren3eb58f52014-06-11 12:47:26 -0600227int do_size(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
228 int fstype);
Stephen Warren128d3d92012-10-31 11:05:07 +0000229int do_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
Wolfgang Denka10c7a52013-10-05 21:07:25 +0200230 int fstype);
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000231int do_ls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
232 int fstype);
Stephen Warrend008fbb2014-02-03 13:21:00 -0700233int file_exists(const char *dev_type, const char *dev_part, const char *file,
234 int fstype);
Simon Glasseda14ea2013-04-20 08:42:50 +0000235int do_save(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
Wolfgang Denka10c7a52013-10-05 21:07:25 +0200236 int fstype);
AKASHI Takahiro1ba42532018-09-11 15:59:13 +0900237int do_rm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
238 int fstype);
AKASHI Takahiroadc8c9f2018-09-11 15:59:08 +0900239int do_mkdir(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
240 int fstype);
Jean-Jacques Hiblotbc237482019-02-13 12:15:26 +0100241int do_ln(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
242 int fstype);
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000243
Christian Gmeiner9f9eec32014-11-12 14:35:04 +0100244/*
245 * Determine the UUID of the specified filesystem and print it. Optionally it is
246 * possible to store the UUID directly in env.
247 */
248int do_fs_uuid(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
249 int fstype);
250
Sjoerd Simons7d9faf62015-01-05 18:13:36 +0100251/*
252 * Determine the type of the specified filesystem and print it. Optionally it is
253 * possible to store the type directly in env.
254 */
255int do_fs_type(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
256
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000257#endif /* _FS_H */