blob: aa3604db8dc4c5ae77a23b059a7edb027e48e43a [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/**
41 * fs_get_type_name() - Get type of current filesystem
42 *
43 * Return: Pointer to filesystem name
44 *
45 * Returns a string describing the current filesystem, or the sentinel
46 * "unsupported" for any unrecognised filesystem.
47 */
48const char *fs_get_type_name(void);
49
Rob Clark4bbcc962017-09-09 13:15:55 -040050/*
Stephen Warren045fa1e2012-10-22 06:43:51 +000051 * Print the list of files on the partition previously set by fs_set_blk_dev(),
52 * in directory "dirname".
53 *
54 * Returns 0 on success. Returns non-zero on error.
55 */
56int fs_ls(const char *dirname);
57
58/*
Stephen Warren61529162014-02-03 13:21:00 -070059 * Determine whether a file exists
60 *
61 * Returns 1 if the file exists, 0 if it doesn't exist.
62 */
63int fs_exists(const char *filename);
64
65/*
Suriyan Ramasamid455d872014-11-17 14:39:38 -080066 * fs_size - Determine a file's size
Stephen Warrencf659812014-06-11 12:47:26 -060067 *
Suriyan Ramasamid455d872014-11-17 14:39:38 -080068 * @filename: Name of the file
69 * @size: Size of file
70 * @return 0 if ok with valid *size, negative on error
Stephen Warrencf659812014-06-11 12:47:26 -060071 */
Suriyan Ramasamid455d872014-11-17 14:39:38 -080072int fs_size(const char *filename, loff_t *size);
Stephen Warrencf659812014-06-11 12:47:26 -060073
74/*
Suriyan Ramasamid455d872014-11-17 14:39:38 -080075 * fs_read - Read file from the partition previously set by fs_set_blk_dev()
76 * Note that not all filesystem types support either/both offset!=0 or len!=0.
Stephen Warren045fa1e2012-10-22 06:43:51 +000077 *
Suriyan Ramasamid455d872014-11-17 14:39:38 -080078 * @filename: Name of file to read from
79 * @addr: The address to read into
80 * @offset: The offset in file to read from
81 * @len: The number of bytes to read. Maybe 0 to read entire file
82 * @actread: Returns the actual number of bytes read
83 * @return 0 if ok with valid *actread, -1 on error conditions
Stephen Warren045fa1e2012-10-22 06:43:51 +000084 */
Suriyan Ramasamid455d872014-11-17 14:39:38 -080085int fs_read(const char *filename, ulong addr, loff_t offset, loff_t len,
86 loff_t *actread);
Stephen Warren045fa1e2012-10-22 06:43:51 +000087
88/*
Suriyan Ramasamid455d872014-11-17 14:39:38 -080089 * fs_write - Write file to the partition previously set by fs_set_blk_dev()
90 * Note that not all filesystem types support offset!=0.
Stephen Warrenbd6fb312014-02-03 13:20:59 -070091 *
Suriyan Ramasamid455d872014-11-17 14:39:38 -080092 * @filename: Name of file to read from
93 * @addr: The address to read into
94 * @offset: The offset in file to read from. Maybe 0 to write to start of file
95 * @len: The number of bytes to write
96 * @actwrite: Returns the actual number of bytes written
97 * @return 0 if ok with valid *actwrite, -1 on error conditions
Stephen Warrenbd6fb312014-02-03 13:20:59 -070098 */
Suriyan Ramasamid455d872014-11-17 14:39:38 -080099int fs_write(const char *filename, ulong addr, loff_t offset, loff_t len,
100 loff_t *actwrite);
Stephen Warrenbd6fb312014-02-03 13:20:59 -0700101
102/*
Rob Clark4bbcc962017-09-09 13:15:55 -0400103 * Directory entry types, matches the subset of DT_x in posix readdir()
104 * which apply to u-boot.
105 */
106#define FS_DT_DIR 4 /* directory */
107#define FS_DT_REG 8 /* regular file */
108#define FS_DT_LNK 10 /* symbolic link */
109
110/*
111 * A directory entry, returned by fs_readdir(). Returns information
112 * about the file/directory at the current directory entry position.
113 */
114struct fs_dirent {
115 unsigned type; /* one of FS_DT_x (not a mask) */
116 loff_t size; /* size in bytes */
117 char name[256];
118};
119
120/* Note: fs_dir_stream should be treated as opaque to the user of fs layer */
121struct fs_dir_stream {
122 /* private to fs. layer: */
123 struct blk_desc *desc;
124 int part;
125};
126
127/*
128 * fs_opendir - Open a directory
129 *
130 * @filename: the path to directory to open
131 * @return a pointer to the directory stream or NULL on error and errno
132 * set appropriately
133 */
134struct fs_dir_stream *fs_opendir(const char *filename);
135
136/*
137 * fs_readdir - Read the next directory entry in the directory stream.
138 *
139 * Works in an analogous way to posix readdir(). The previously returned
140 * directory entry is no longer valid after calling fs_readdir() again.
141 * After fs_closedir() is called, the returned directory entry is no
142 * longer valid.
143 *
144 * @dirs: the directory stream
145 * @return the next directory entry (only valid until next fs_readdir() or
146 * fs_closedir() call, do not attempt to free()) or NULL if the end of
147 * the directory is reached.
148 */
149struct fs_dirent *fs_readdir(struct fs_dir_stream *dirs);
150
151/*
152 * fs_closedir - close a directory stream
153 *
154 * @dirs: the directory stream
155 */
156void fs_closedir(struct fs_dir_stream *dirs);
157
158/*
AKASHI Takahiroe2519da2018-09-11 15:59:13 +0900159 * fs_unlink - delete a file or directory
160 *
161 * If a given name is a directory, it will be deleted only if it's empty
162 *
163 * @filename: Name of file or directory to delete
164 * @return 0 on success, -1 on error conditions
165 */
166int fs_unlink(const char *filename);
167
168/*
AKASHI Takahiroe7074cf2018-09-11 15:59:08 +0900169 * fs_mkdir - Create a directory
170 *
171 * @filename: Name of directory to create
172 * @return 0 on success, -1 on error conditions
173 */
174int fs_mkdir(const char *filename);
175
176/*
Stephen Warren045fa1e2012-10-22 06:43:51 +0000177 * Common implementation for various filesystem commands, optionally limited
178 * to a specific filesystem type via the fstype parameter.
179 */
Stephen Warrencf659812014-06-11 12:47:26 -0600180int do_size(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
181 int fstype);
Stephen Warrenf9b55e22012-10-31 11:05:07 +0000182int do_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
Wolfgang Denkb770e882013-10-05 21:07:25 +0200183 int fstype);
Stephen Warren045fa1e2012-10-22 06:43:51 +0000184int do_ls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
185 int fstype);
Stephen Warren61529162014-02-03 13:21:00 -0700186int file_exists(const char *dev_type, const char *dev_part, const char *file,
187 int fstype);
Simon Glassa8f6ab52013-04-20 08:42:50 +0000188int do_save(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
Wolfgang Denkb770e882013-10-05 21:07:25 +0200189 int fstype);
AKASHI Takahiroe2519da2018-09-11 15:59:13 +0900190int do_rm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
191 int fstype);
AKASHI Takahiroe7074cf2018-09-11 15:59:08 +0900192int do_mkdir(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
193 int fstype);
Stephen Warren045fa1e2012-10-22 06:43:51 +0000194
Christian Gmeiner59e890e2014-11-12 14:35:04 +0100195/*
196 * Determine the UUID of the specified filesystem and print it. Optionally it is
197 * possible to store the UUID directly in env.
198 */
199int do_fs_uuid(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
200 int fstype);
201
Sjoerd Simons1a1ad8e2015-01-05 18:13:36 +0100202/*
203 * Determine the type of the specified filesystem and print it. Optionally it is
204 * possible to store the type directly in env.
205 */
206int do_fs_type(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
207
Stephen Warren045fa1e2012-10-22 06:43:51 +0000208#endif /* _FS_H */