blob: 247e9540536ca67b416ef831be6bf36f53da4c4b [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>
9
10#define FS_TYPE_ANY 0
11#define FS_TYPE_FAT 1
12#define FS_TYPE_EXT 2
Simon Glass92ccc962012-12-26 09:53:35 +000013#define FS_TYPE_SANDBOX 3
Hans de Goede251cee02015-09-17 18:46:58 -040014#define FS_TYPE_UBIFS 4
Marek BehĂșn0c936ee2017-09-03 17:00:29 +020015#define FS_TYPE_BTRFS 5
Stephen Warren045fa1e2012-10-22 06:43:51 +000016
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 */
27int fs_set_blk_dev(const char *ifname, const char *dev_part_str, int fstype);
28
29/*
Rob Clark4bbcc962017-09-09 13:15:55 -040030 * 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 */
38int fs_set_blk_dev_with_part(struct blk_desc *desc, int part);
39
Alex Kiernan0d488e82018-05-29 15:30:50 +000040/**
AKASHI Takahiro64f49eb2019-10-07 14:59:35 +090041 * fs_close() - Unset current block device and partition
42 *
Heinrich Schuchardte4bad9f2019-10-13 10:26:26 +020043 * fs_close() closes the connection to a file system opened with either
44 * fs_set_blk_dev() or fs_set_dev_with_part().
45 *
46 * Many file functions implicitly call fs_close(), e.g. fs_closedir(),
47 * fs_exist(), fs_ln(), fs_ls(), fs_mkdir(), fs_read(), fs_size(), fs_write(),
48 * fs_unlink().
AKASHI Takahiro64f49eb2019-10-07 14:59:35 +090049 */
50void fs_close(void);
51
52/**
Alex Kiernan0d488e82018-05-29 15:30:50 +000053 * fs_get_type_name() - Get type of current filesystem
54 *
55 * Return: Pointer to filesystem name
56 *
57 * Returns a string describing the current filesystem, or the sentinel
58 * "unsupported" for any unrecognised filesystem.
59 */
60const char *fs_get_type_name(void);
61
Rob Clark4bbcc962017-09-09 13:15:55 -040062/*
Stephen Warren045fa1e2012-10-22 06:43:51 +000063 * Print the list of files on the partition previously set by fs_set_blk_dev(),
64 * in directory "dirname".
65 *
66 * Returns 0 on success. Returns non-zero on error.
67 */
68int fs_ls(const char *dirname);
69
70/*
Stephen Warren61529162014-02-03 13:21:00 -070071 * Determine whether a file exists
72 *
73 * Returns 1 if the file exists, 0 if it doesn't exist.
74 */
75int fs_exists(const char *filename);
76
77/*
Suriyan Ramasamid455d872014-11-17 14:39:38 -080078 * fs_size - Determine a file's size
Stephen Warrencf659812014-06-11 12:47:26 -060079 *
Suriyan Ramasamid455d872014-11-17 14:39:38 -080080 * @filename: Name of the file
81 * @size: Size of file
82 * @return 0 if ok with valid *size, negative on error
Stephen Warrencf659812014-06-11 12:47:26 -060083 */
Suriyan Ramasamid455d872014-11-17 14:39:38 -080084int fs_size(const char *filename, loff_t *size);
Stephen Warrencf659812014-06-11 12:47:26 -060085
Heinrich Schuchardta0e92cd2019-04-25 20:36:39 +020086/**
87 * fs_read() - read file from the partition previously set by fs_set_blk_dev()
Stephen Warren045fa1e2012-10-22 06:43:51 +000088 *
Heinrich Schuchardta0e92cd2019-04-25 20:36:39 +020089 * Note that not all filesystem drivers support either or both of offset != 0
90 * and len != 0.
91 *
92 * @filename: full path of the file to read from
93 * @addr: address of the buffer to write to
94 * @offset: offset in the file from where to start reading
95 * @len: the number of bytes to read. Use 0 to read entire file.
96 * @actread: returns the actual number of bytes read
97 * Return: 0 if OK with valid *actread, -1 on error conditions
Stephen Warren045fa1e2012-10-22 06:43:51 +000098 */
Suriyan Ramasamid455d872014-11-17 14:39:38 -080099int fs_read(const char *filename, ulong addr, loff_t offset, loff_t len,
100 loff_t *actread);
Stephen Warren045fa1e2012-10-22 06:43:51 +0000101
Heinrich Schuchardta0e92cd2019-04-25 20:36:39 +0200102/**
103 * fs_write() - write file to the partition previously set by fs_set_blk_dev()
Stephen Warrenbd6fb312014-02-03 13:20:59 -0700104 *
Heinrich Schuchardta0e92cd2019-04-25 20:36:39 +0200105 * Note that not all filesystem drivers support offset != 0.
106 *
107 * @filename: full path of the file to write to
108 * @addr: address of the buffer to read from
109 * @offset: offset in the file from where to start writing
110 * @len: the number of bytes to write
111 * @actwrite: returns the actual number of bytes written
112 * Return: 0 if OK with valid *actwrite, -1 on error conditions
Stephen Warrenbd6fb312014-02-03 13:20:59 -0700113 */
Suriyan Ramasamid455d872014-11-17 14:39:38 -0800114int fs_write(const char *filename, ulong addr, loff_t offset, loff_t len,
115 loff_t *actwrite);
Stephen Warrenbd6fb312014-02-03 13:20:59 -0700116
117/*
Rob Clark4bbcc962017-09-09 13:15:55 -0400118 * Directory entry types, matches the subset of DT_x in posix readdir()
119 * which apply to u-boot.
120 */
121#define FS_DT_DIR 4 /* directory */
122#define FS_DT_REG 8 /* regular file */
123#define FS_DT_LNK 10 /* symbolic link */
124
125/*
126 * A directory entry, returned by fs_readdir(). Returns information
127 * about the file/directory at the current directory entry position.
128 */
129struct fs_dirent {
130 unsigned type; /* one of FS_DT_x (not a mask) */
131 loff_t size; /* size in bytes */
132 char name[256];
133};
134
135/* Note: fs_dir_stream should be treated as opaque to the user of fs layer */
136struct fs_dir_stream {
137 /* private to fs. layer: */
138 struct blk_desc *desc;
139 int part;
140};
141
142/*
143 * fs_opendir - Open a directory
144 *
145 * @filename: the path to directory to open
146 * @return a pointer to the directory stream or NULL on error and errno
147 * set appropriately
148 */
149struct fs_dir_stream *fs_opendir(const char *filename);
150
151/*
152 * fs_readdir - Read the next directory entry in the directory stream.
153 *
154 * Works in an analogous way to posix readdir(). The previously returned
155 * directory entry is no longer valid after calling fs_readdir() again.
156 * After fs_closedir() is called, the returned directory entry is no
157 * longer valid.
158 *
159 * @dirs: the directory stream
160 * @return the next directory entry (only valid until next fs_readdir() or
161 * fs_closedir() call, do not attempt to free()) or NULL if the end of
162 * the directory is reached.
163 */
164struct fs_dirent *fs_readdir(struct fs_dir_stream *dirs);
165
166/*
167 * fs_closedir - close a directory stream
168 *
169 * @dirs: the directory stream
170 */
171void fs_closedir(struct fs_dir_stream *dirs);
172
173/*
AKASHI Takahiroe2519da2018-09-11 15:59:13 +0900174 * fs_unlink - delete a file or directory
175 *
176 * If a given name is a directory, it will be deleted only if it's empty
177 *
178 * @filename: Name of file or directory to delete
179 * @return 0 on success, -1 on error conditions
180 */
181int fs_unlink(const char *filename);
182
183/*
AKASHI Takahiroe7074cf2018-09-11 15:59:08 +0900184 * fs_mkdir - Create a directory
185 *
186 * @filename: Name of directory to create
187 * @return 0 on success, -1 on error conditions
188 */
189int fs_mkdir(const char *filename);
190
191/*
Stephen Warren045fa1e2012-10-22 06:43:51 +0000192 * Common implementation for various filesystem commands, optionally limited
193 * to a specific filesystem type via the fstype parameter.
194 */
Stephen Warrencf659812014-06-11 12:47:26 -0600195int do_size(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
196 int fstype);
Stephen Warrenf9b55e22012-10-31 11:05:07 +0000197int do_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
Wolfgang Denkb770e882013-10-05 21:07:25 +0200198 int fstype);
Stephen Warren045fa1e2012-10-22 06:43:51 +0000199int do_ls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
200 int fstype);
Stephen Warren61529162014-02-03 13:21:00 -0700201int file_exists(const char *dev_type, const char *dev_part, const char *file,
202 int fstype);
Simon Glassa8f6ab52013-04-20 08:42:50 +0000203int do_save(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
Wolfgang Denkb770e882013-10-05 21:07:25 +0200204 int fstype);
AKASHI Takahiroe2519da2018-09-11 15:59:13 +0900205int do_rm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
206 int fstype);
AKASHI Takahiroe7074cf2018-09-11 15:59:08 +0900207int do_mkdir(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
208 int fstype);
Jean-Jacques Hiblotaaa12152019-02-13 12:15:26 +0100209int do_ln(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
210 int fstype);
Stephen Warren045fa1e2012-10-22 06:43:51 +0000211
Christian Gmeiner59e890e2014-11-12 14:35:04 +0100212/*
213 * Determine the UUID of the specified filesystem and print it. Optionally it is
214 * possible to store the UUID directly in env.
215 */
216int do_fs_uuid(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
217 int fstype);
218
Sjoerd Simons1a1ad8e2015-01-05 18:13:36 +0100219/*
220 * Determine the type of the specified filesystem and print it. Optionally it is
221 * possible to store the type directly in env.
222 */
223int do_fs_type(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
224
Stephen Warren045fa1e2012-10-22 06:43:51 +0000225#endif /* _FS_H */