xref: /OK3568_Linux_fs/u-boot/include/fs.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * Copyright (c) 2012, NVIDIA CORPORATION.  All rights reserved.
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  * SPDX-License-Identifier:	GPL-2.0
5*4882a593Smuzhiyun  */
6*4882a593Smuzhiyun #ifndef _FS_H
7*4882a593Smuzhiyun #define _FS_H
8*4882a593Smuzhiyun 
9*4882a593Smuzhiyun #include <common.h>
10*4882a593Smuzhiyun 
11*4882a593Smuzhiyun #define FS_TYPE_ANY	0
12*4882a593Smuzhiyun #define FS_TYPE_FAT	1
13*4882a593Smuzhiyun #define FS_TYPE_EXT	2
14*4882a593Smuzhiyun #define FS_TYPE_SANDBOX	3
15*4882a593Smuzhiyun #define FS_TYPE_UBIFS	4
16*4882a593Smuzhiyun 
17*4882a593Smuzhiyun /*
18*4882a593Smuzhiyun  * Tell the fs layer which block device an partition to use for future
19*4882a593Smuzhiyun  * commands. This also internally identifies the filesystem that is present
20*4882a593Smuzhiyun  * within the partition. The identification process may be limited to a
21*4882a593Smuzhiyun  * specific filesystem type by passing FS_* in the fstype parameter.
22*4882a593Smuzhiyun  *
23*4882a593Smuzhiyun  * Returns 0 on success.
24*4882a593Smuzhiyun  * Returns non-zero if there is an error accessing the disk or partition, or
25*4882a593Smuzhiyun  * no known filesystem type could be recognized on it.
26*4882a593Smuzhiyun  */
27*4882a593Smuzhiyun int fs_set_blk_dev(const char *ifname, const char *dev_part_str, int fstype);
28*4882a593Smuzhiyun 
29*4882a593Smuzhiyun /*
30*4882a593Smuzhiyun  * fs_get_fstype - Get filesystem type on the partition previously
31*4882a593Smuzhiyun  * set by fs_set_blk_dev()
32*4882a593Smuzhiyun  *
33*4882a593Smuzhiyun  * @fstype_name: The return the name of filesystem type
34*4882a593Smuzhiyun  * @return 0 if ok with valid *fstype_name, -1 on error conditions
35*4882a593Smuzhiyun  */
36*4882a593Smuzhiyun int fs_get_fstype(const char **fstype_name);
37*4882a593Smuzhiyun 
38*4882a593Smuzhiyun /*
39*4882a593Smuzhiyun  * fs_set_blk_dev_with_part - Set current block device + partition
40*4882a593Smuzhiyun  *
41*4882a593Smuzhiyun  * Similar to fs_set_blk_dev(), but useful for cases where you already
42*4882a593Smuzhiyun  * know the blk_desc and part number.
43*4882a593Smuzhiyun  *
44*4882a593Smuzhiyun  * Returns 0 on success.
45*4882a593Smuzhiyun  * Returns non-zero if invalid partition or error accessing the disk.
46*4882a593Smuzhiyun  */
47*4882a593Smuzhiyun int fs_set_blk_dev_with_part(struct blk_desc *desc, int part);
48*4882a593Smuzhiyun 
49*4882a593Smuzhiyun /*
50*4882a593Smuzhiyun  * Print the list of files on the partition previously set by fs_set_blk_dev(),
51*4882a593Smuzhiyun  * in directory "dirname".
52*4882a593Smuzhiyun  *
53*4882a593Smuzhiyun  * Returns 0 on success. Returns non-zero on error.
54*4882a593Smuzhiyun  */
55*4882a593Smuzhiyun int fs_ls(const char *dirname);
56*4882a593Smuzhiyun 
57*4882a593Smuzhiyun /*
58*4882a593Smuzhiyun  * Determine whether a file exists
59*4882a593Smuzhiyun  *
60*4882a593Smuzhiyun  * Returns 1 if the file exists, 0 if it doesn't exist.
61*4882a593Smuzhiyun  */
62*4882a593Smuzhiyun int fs_exists(const char *filename);
63*4882a593Smuzhiyun 
64*4882a593Smuzhiyun /*
65*4882a593Smuzhiyun  * fs_size - Determine a file's size
66*4882a593Smuzhiyun  *
67*4882a593Smuzhiyun  * @filename: Name of the file
68*4882a593Smuzhiyun  * @size: Size of file
69*4882a593Smuzhiyun  * @return 0 if ok with valid *size, negative on error
70*4882a593Smuzhiyun  */
71*4882a593Smuzhiyun int fs_size(const char *filename, loff_t *size);
72*4882a593Smuzhiyun 
73*4882a593Smuzhiyun /*
74*4882a593Smuzhiyun  * fs_read - Read file from the partition previously set by fs_set_blk_dev()
75*4882a593Smuzhiyun  * Note that not all filesystem types support either/both offset!=0 or len!=0.
76*4882a593Smuzhiyun  *
77*4882a593Smuzhiyun  * @filename: Name of file to read from
78*4882a593Smuzhiyun  * @addr: The address to read into
79*4882a593Smuzhiyun  * @offset: The offset in file to read from
80*4882a593Smuzhiyun  * @len: The number of bytes to read. Maybe 0 to read entire file
81*4882a593Smuzhiyun  * @actread: Returns the actual number of bytes read
82*4882a593Smuzhiyun  * @return 0 if ok with valid *actread, -1 on error conditions
83*4882a593Smuzhiyun  */
84*4882a593Smuzhiyun int fs_read(const char *filename, ulong addr, loff_t offset, loff_t len,
85*4882a593Smuzhiyun 	    loff_t *actread);
86*4882a593Smuzhiyun 
87*4882a593Smuzhiyun /*
88*4882a593Smuzhiyun  * fs_write - Write file to the partition previously set by fs_set_blk_dev()
89*4882a593Smuzhiyun  * Note that not all filesystem types support offset!=0.
90*4882a593Smuzhiyun  *
91*4882a593Smuzhiyun  * @filename: Name of file to read from
92*4882a593Smuzhiyun  * @addr: The address to read into
93*4882a593Smuzhiyun  * @offset: The offset in file to read from. Maybe 0 to write to start of file
94*4882a593Smuzhiyun  * @len: The number of bytes to write
95*4882a593Smuzhiyun  * @actwrite: Returns the actual number of bytes written
96*4882a593Smuzhiyun  * @return 0 if ok with valid *actwrite, -1 on error conditions
97*4882a593Smuzhiyun  */
98*4882a593Smuzhiyun int fs_write(const char *filename, ulong addr, loff_t offset, loff_t len,
99*4882a593Smuzhiyun 	     loff_t *actwrite);
100*4882a593Smuzhiyun 
101*4882a593Smuzhiyun /*
102*4882a593Smuzhiyun  * Directory entry types, matches the subset of DT_x in posix readdir()
103*4882a593Smuzhiyun  * which apply to u-boot.
104*4882a593Smuzhiyun  */
105*4882a593Smuzhiyun #define FS_DT_DIR  4         /* directory */
106*4882a593Smuzhiyun #define FS_DT_REG  8         /* regular file */
107*4882a593Smuzhiyun #define FS_DT_LNK  10        /* symbolic link */
108*4882a593Smuzhiyun 
109*4882a593Smuzhiyun /*
110*4882a593Smuzhiyun  * A directory entry, returned by fs_readdir().  Returns information
111*4882a593Smuzhiyun  * about the file/directory at the current directory entry position.
112*4882a593Smuzhiyun  */
113*4882a593Smuzhiyun struct fs_dirent {
114*4882a593Smuzhiyun 	unsigned type;       /* one of FS_DT_x (not a mask) */
115*4882a593Smuzhiyun 	loff_t size;         /* size in bytes */
116*4882a593Smuzhiyun 	char name[256];
117*4882a593Smuzhiyun };
118*4882a593Smuzhiyun 
119*4882a593Smuzhiyun /* Note: fs_dir_stream should be treated as opaque to the user of fs layer */
120*4882a593Smuzhiyun struct fs_dir_stream {
121*4882a593Smuzhiyun 	/* private to fs. layer: */
122*4882a593Smuzhiyun 	struct blk_desc *desc;
123*4882a593Smuzhiyun 	int part;
124*4882a593Smuzhiyun };
125*4882a593Smuzhiyun 
126*4882a593Smuzhiyun /*
127*4882a593Smuzhiyun  * fs_opendir - Open a directory
128*4882a593Smuzhiyun  *
129*4882a593Smuzhiyun  * @filename: the path to directory to open
130*4882a593Smuzhiyun  * @return a pointer to the directory stream or NULL on error and errno
131*4882a593Smuzhiyun  *    set appropriately
132*4882a593Smuzhiyun  */
133*4882a593Smuzhiyun struct fs_dir_stream *fs_opendir(const char *filename);
134*4882a593Smuzhiyun 
135*4882a593Smuzhiyun /*
136*4882a593Smuzhiyun  * fs_readdir - Read the next directory entry in the directory stream.
137*4882a593Smuzhiyun  *
138*4882a593Smuzhiyun  * Works in an analogous way to posix readdir().  The previously returned
139*4882a593Smuzhiyun  * directory entry is no longer valid after calling fs_readdir() again.
140*4882a593Smuzhiyun  * After fs_closedir() is called, the returned directory entry is no
141*4882a593Smuzhiyun  * longer valid.
142*4882a593Smuzhiyun  *
143*4882a593Smuzhiyun  * @dirs: the directory stream
144*4882a593Smuzhiyun  * @return the next directory entry (only valid until next fs_readdir() or
145*4882a593Smuzhiyun  *    fs_closedir() call, do not attempt to free()) or NULL if the end of
146*4882a593Smuzhiyun  *    the directory is reached.
147*4882a593Smuzhiyun  */
148*4882a593Smuzhiyun struct fs_dirent *fs_readdir(struct fs_dir_stream *dirs);
149*4882a593Smuzhiyun 
150*4882a593Smuzhiyun /*
151*4882a593Smuzhiyun  * fs_closedir - close a directory stream
152*4882a593Smuzhiyun  *
153*4882a593Smuzhiyun  * @dirs: the directory stream
154*4882a593Smuzhiyun  */
155*4882a593Smuzhiyun void fs_closedir(struct fs_dir_stream *dirs);
156*4882a593Smuzhiyun 
157*4882a593Smuzhiyun /*
158*4882a593Smuzhiyun  * Common implementation for various filesystem commands, optionally limited
159*4882a593Smuzhiyun  * to a specific filesystem type via the fstype parameter.
160*4882a593Smuzhiyun  */
161*4882a593Smuzhiyun int do_size(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
162*4882a593Smuzhiyun 		int fstype);
163*4882a593Smuzhiyun int do_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
164*4882a593Smuzhiyun 		int fstype);
165*4882a593Smuzhiyun int do_ls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
166*4882a593Smuzhiyun 		int fstype);
167*4882a593Smuzhiyun int file_exists(const char *dev_type, const char *dev_part, const char *file,
168*4882a593Smuzhiyun 		int fstype);
169*4882a593Smuzhiyun int do_save(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
170*4882a593Smuzhiyun 		int fstype);
171*4882a593Smuzhiyun 
172*4882a593Smuzhiyun /*
173*4882a593Smuzhiyun  * Determine the UUID of the specified filesystem and print it. Optionally it is
174*4882a593Smuzhiyun  * possible to store the UUID directly in env.
175*4882a593Smuzhiyun  */
176*4882a593Smuzhiyun int do_fs_uuid(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
177*4882a593Smuzhiyun 		int fstype);
178*4882a593Smuzhiyun 
179*4882a593Smuzhiyun /*
180*4882a593Smuzhiyun  * Determine the type of the specified filesystem and print it. Optionally it is
181*4882a593Smuzhiyun  * possible to store the type directly in env.
182*4882a593Smuzhiyun  */
183*4882a593Smuzhiyun int do_fs_type(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
184*4882a593Smuzhiyun 
185*4882a593Smuzhiyun #endif /* _FS_H */
186