]> git.ipfire.org Git - people/ms/u-boot.git/blame - include/fs.h
Convert CONFIG_BOOTCOUNT_ENV to Kconfig
[people/ms/u-boot.git] / include / fs.h
CommitLineData
045fa1e1
SW
1/*
2 * Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved.
3 *
5b8031cc 4 * SPDX-License-Identifier: GPL-2.0
045fa1e1
SW
5 */
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
92ccc96b 14#define FS_TYPE_SANDBOX 3
251cee0d 15#define FS_TYPE_UBIFS 4
0c936ee3 16#define FS_TYPE_BTRFS 5
045fa1e1
SW
17
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
4bbcc965
RC
30/*
31 * 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
045fa1e1
SW
41/*
42 * 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
6152916a
SW
49/*
50 * 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
cf659819 56/*
d455d878 57 * fs_size - Determine a file's size
cf659819 58 *
d455d878
SR
59 * @filename: Name of the file
60 * @size: Size of file
61 * @return 0 if ok with valid *size, negative on error
cf659819 62 */
d455d878 63int fs_size(const char *filename, loff_t *size);
cf659819 64
045fa1e1 65/*
d455d878
SR
66 * 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.
045fa1e1 68 *
d455d878
SR
69 * @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
045fa1e1 75 */
d455d878
SR
76int fs_read(const char *filename, ulong addr, loff_t offset, loff_t len,
77 loff_t *actread);
045fa1e1 78
bd6fb31f 79/*
d455d878
SR
80 * fs_write - Write file to the partition previously set by fs_set_blk_dev()
81 * Note that not all filesystem types support offset!=0.
bd6fb31f 82 *
d455d878
SR
83 * @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
bd6fb31f 89 */
d455d878
SR
90int fs_write(const char *filename, ulong addr, loff_t offset, loff_t len,
91 loff_t *actwrite);
bd6fb31f 92
4bbcc965
RC
93/*
94 * 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
045fa1e1
SW
149/*
150 * Common implementation for various filesystem commands, optionally limited
151 * to a specific filesystem type via the fstype parameter.
152 */
cf659819
SW
153int do_size(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
154 int fstype);
f9b55e22 155int do_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
b770e88a 156 int fstype);
045fa1e1
SW
157int do_ls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
158 int fstype);
6152916a
SW
159int file_exists(const char *dev_type, const char *dev_part, const char *file,
160 int fstype);
a8f6ab52 161int do_save(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
b770e88a 162 int fstype);
045fa1e1 163
59e890ef
CG
164/*
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
1a1ad8e0
SS
171/*
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
045fa1e1 177#endif /* _FS_H */