blob: 32fc480135841333015b8628b4cfc889ba5f2ab8 [file] [log] [blame]
Stephen Warren045fa1e2012-10-22 06:43:51 +00001/*
2 * Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved.
3 *
Tom Rini5b8031c2016-01-14 22:05:13 -05004 * SPDX-License-Identifier: GPL-2.0
Stephen Warren045fa1e2012-10-22 06:43:51 +00005 */
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
Simon Glass92ccc962012-12-26 09:53:35 +000014#define FS_TYPE_SANDBOX 3
Hans de Goede251cee02015-09-17 18:46:58 -040015#define FS_TYPE_UBIFS 4
Marek BehĂșn0c936ee2017-09-03 17:00:29 +020016#define FS_TYPE_BTRFS 5
Stephen Warren045fa1e2012-10-22 06:43:51 +000017
18/*
19 * Tell the fs layer which block device an partition to use for future
20 * commands. This also internally identifies the filesystem that is present
21 * within the partition. The identification process may be limited to a
22 * specific filesystem type by passing FS_* in the fstype parameter.
23 *
24 * Returns 0 on success.
25 * Returns non-zero if there is an error accessing the disk or partition, or
26 * no known filesystem type could be recognized on it.
27 */
28int fs_set_blk_dev(const char *ifname, const char *dev_part_str, int fstype);
29
30/*
Rob Clark4bbcc962017-09-09 13:15:55 -040031 * fs_set_blk_dev_with_part - Set current block device + partition
32 *
33 * Similar to fs_set_blk_dev(), but useful for cases where you already
34 * know the blk_desc and part number.
35 *
36 * Returns 0 on success.
37 * Returns non-zero if invalid partition or error accessing the disk.
38 */
39int fs_set_blk_dev_with_part(struct blk_desc *desc, int part);
40
41/*
Stephen Warren045fa1e2012-10-22 06:43:51 +000042 * Print the list of files on the partition previously set by fs_set_blk_dev(),
43 * in directory "dirname".
44 *
45 * Returns 0 on success. Returns non-zero on error.
46 */
47int fs_ls(const char *dirname);
48
49/*
Stephen Warren61529162014-02-03 13:21:00 -070050 * Determine whether a file exists
51 *
52 * Returns 1 if the file exists, 0 if it doesn't exist.
53 */
54int fs_exists(const char *filename);
55
56/*
Suriyan Ramasamid455d872014-11-17 14:39:38 -080057 * fs_size - Determine a file's size
Stephen Warrencf659812014-06-11 12:47:26 -060058 *
Suriyan Ramasamid455d872014-11-17 14:39:38 -080059 * @filename: Name of the file
60 * @size: Size of file
61 * @return 0 if ok with valid *size, negative on error
Stephen Warrencf659812014-06-11 12:47:26 -060062 */
Suriyan Ramasamid455d872014-11-17 14:39:38 -080063int fs_size(const char *filename, loff_t *size);
Stephen Warrencf659812014-06-11 12:47:26 -060064
65/*
Suriyan Ramasamid455d872014-11-17 14:39:38 -080066 * fs_read - Read file from the partition previously set by fs_set_blk_dev()
67 * Note that not all filesystem types support either/both offset!=0 or len!=0.
Stephen Warren045fa1e2012-10-22 06:43:51 +000068 *
Suriyan Ramasamid455d872014-11-17 14:39:38 -080069 * @filename: Name of file to read from
70 * @addr: The address to read into
71 * @offset: The offset in file to read from
72 * @len: The number of bytes to read. Maybe 0 to read entire file
73 * @actread: Returns the actual number of bytes read
74 * @return 0 if ok with valid *actread, -1 on error conditions
Stephen Warren045fa1e2012-10-22 06:43:51 +000075 */
Suriyan Ramasamid455d872014-11-17 14:39:38 -080076int fs_read(const char *filename, ulong addr, loff_t offset, loff_t len,
77 loff_t *actread);
Stephen Warren045fa1e2012-10-22 06:43:51 +000078
79/*
Suriyan Ramasamid455d872014-11-17 14:39:38 -080080 * fs_write - Write file to the partition previously set by fs_set_blk_dev()
81 * Note that not all filesystem types support offset!=0.
Stephen Warrenbd6fb312014-02-03 13:20:59 -070082 *
Suriyan Ramasamid455d872014-11-17 14:39:38 -080083 * @filename: Name of file to read from
84 * @addr: The address to read into
85 * @offset: The offset in file to read from. Maybe 0 to write to start of file
86 * @len: The number of bytes to write
87 * @actwrite: Returns the actual number of bytes written
88 * @return 0 if ok with valid *actwrite, -1 on error conditions
Stephen Warrenbd6fb312014-02-03 13:20:59 -070089 */
Suriyan Ramasamid455d872014-11-17 14:39:38 -080090int fs_write(const char *filename, ulong addr, loff_t offset, loff_t len,
91 loff_t *actwrite);
Stephen Warrenbd6fb312014-02-03 13:20:59 -070092
93/*
Rob Clark4bbcc962017-09-09 13:15:55 -040094 * Directory entry types, matches the subset of DT_x in posix readdir()
95 * which apply to u-boot.
96 */
97#define FS_DT_DIR 4 /* directory */
98#define FS_DT_REG 8 /* regular file */
99#define FS_DT_LNK 10 /* symbolic link */
100
101/*
102 * A directory entry, returned by fs_readdir(). Returns information
103 * about the file/directory at the current directory entry position.
104 */
105struct fs_dirent {
106 unsigned type; /* one of FS_DT_x (not a mask) */
107 loff_t size; /* size in bytes */
108 char name[256];
109};
110
111/* Note: fs_dir_stream should be treated as opaque to the user of fs layer */
112struct fs_dir_stream {
113 /* private to fs. layer: */
114 struct blk_desc *desc;
115 int part;
116};
117
118/*
119 * fs_opendir - Open a directory
120 *
121 * @filename: the path to directory to open
122 * @return a pointer to the directory stream or NULL on error and errno
123 * set appropriately
124 */
125struct fs_dir_stream *fs_opendir(const char *filename);
126
127/*
128 * fs_readdir - Read the next directory entry in the directory stream.
129 *
130 * Works in an analogous way to posix readdir(). The previously returned
131 * directory entry is no longer valid after calling fs_readdir() again.
132 * After fs_closedir() is called, the returned directory entry is no
133 * longer valid.
134 *
135 * @dirs: the directory stream
136 * @return the next directory entry (only valid until next fs_readdir() or
137 * fs_closedir() call, do not attempt to free()) or NULL if the end of
138 * the directory is reached.
139 */
140struct fs_dirent *fs_readdir(struct fs_dir_stream *dirs);
141
142/*
143 * fs_closedir - close a directory stream
144 *
145 * @dirs: the directory stream
146 */
147void fs_closedir(struct fs_dir_stream *dirs);
148
149/*
Stephen Warren045fa1e2012-10-22 06:43:51 +0000150 * Common implementation for various filesystem commands, optionally limited
151 * to a specific filesystem type via the fstype parameter.
152 */
Stephen Warrencf659812014-06-11 12:47:26 -0600153int do_size(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
154 int fstype);
Stephen Warrenf9b55e22012-10-31 11:05:07 +0000155int do_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
Wolfgang Denkb770e882013-10-05 21:07:25 +0200156 int fstype);
Stephen Warren045fa1e2012-10-22 06:43:51 +0000157int do_ls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
158 int fstype);
Stephen Warren61529162014-02-03 13:21:00 -0700159int file_exists(const char *dev_type, const char *dev_part, const char *file,
160 int fstype);
Simon Glassa8f6ab52013-04-20 08:42:50 +0000161int do_save(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
Wolfgang Denkb770e882013-10-05 21:07:25 +0200162 int fstype);
Stephen Warren045fa1e2012-10-22 06:43:51 +0000163
Christian Gmeiner59e890e2014-11-12 14:35:04 +0100164/*
165 * Determine the UUID of the specified filesystem and print it. Optionally it is
166 * possible to store the UUID directly in env.
167 */
168int do_fs_uuid(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
169 int fstype);
170
Sjoerd Simons1a1ad8e2015-01-05 18:13:36 +0100171/*
172 * Determine the type of the specified filesystem and print it. Optionally it is
173 * possible to store the type directly in env.
174 */
175int do_fs_type(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
176
Stephen Warren045fa1e2012-10-22 06:43:51 +0000177#endif /* _FS_H */