xref: /rk3399_rockchip-uboot/include/fs.h (revision d455d8789d5b35a39a0a179b3af4b423db13bfdd)
1045fa1e1SStephen Warren /*
2045fa1e1SStephen Warren  * Copyright (c) 2012, NVIDIA CORPORATION.  All rights reserved.
3045fa1e1SStephen Warren  *
4045fa1e1SStephen Warren  * This program is free software; you can redistribute it and/or modify it
5045fa1e1SStephen Warren  * under the terms and conditions of the GNU General Public License,
6045fa1e1SStephen Warren  * version 2, as published by the Free Software Foundation.
7045fa1e1SStephen Warren  *
8045fa1e1SStephen Warren  * This program is distributed in the hope it will be useful, but WITHOUT
9045fa1e1SStephen Warren  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10045fa1e1SStephen Warren  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
11045fa1e1SStephen Warren  * more details.
12045fa1e1SStephen Warren  *
13045fa1e1SStephen Warren  * You should have received a copy of the GNU General Public License
14045fa1e1SStephen Warren  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
15045fa1e1SStephen Warren  */
16045fa1e1SStephen Warren #ifndef _FS_H
17045fa1e1SStephen Warren #define _FS_H
18045fa1e1SStephen Warren 
19045fa1e1SStephen Warren #include <common.h>
20045fa1e1SStephen Warren 
21045fa1e1SStephen Warren #define FS_TYPE_ANY	0
22045fa1e1SStephen Warren #define FS_TYPE_FAT	1
23045fa1e1SStephen Warren #define FS_TYPE_EXT	2
2492ccc96bSSimon Glass #define FS_TYPE_SANDBOX	3
25045fa1e1SStephen Warren 
26045fa1e1SStephen Warren /*
27045fa1e1SStephen Warren  * Tell the fs layer which block device an partition to use for future
28045fa1e1SStephen Warren  * commands. This also internally identifies the filesystem that is present
29045fa1e1SStephen Warren  * within the partition. The identification process may be limited to a
30045fa1e1SStephen Warren  * specific filesystem type by passing FS_* in the fstype parameter.
31045fa1e1SStephen Warren  *
32045fa1e1SStephen Warren  * Returns 0 on success.
33045fa1e1SStephen Warren  * Returns non-zero if there is an error accessing the disk or partition, or
34045fa1e1SStephen Warren  * no known filesystem type could be recognized on it.
35045fa1e1SStephen Warren  */
36045fa1e1SStephen Warren int fs_set_blk_dev(const char *ifname, const char *dev_part_str, int fstype);
37045fa1e1SStephen Warren 
38045fa1e1SStephen Warren /*
39045fa1e1SStephen Warren  * Print the list of files on the partition previously set by fs_set_blk_dev(),
40045fa1e1SStephen Warren  * in directory "dirname".
41045fa1e1SStephen Warren  *
42045fa1e1SStephen Warren  * Returns 0 on success. Returns non-zero on error.
43045fa1e1SStephen Warren  */
44045fa1e1SStephen Warren int fs_ls(const char *dirname);
45045fa1e1SStephen Warren 
46045fa1e1SStephen Warren /*
476152916aSStephen Warren  * Determine whether a file exists
486152916aSStephen Warren  *
496152916aSStephen Warren  * Returns 1 if the file exists, 0 if it doesn't exist.
506152916aSStephen Warren  */
516152916aSStephen Warren int fs_exists(const char *filename);
526152916aSStephen Warren 
536152916aSStephen Warren /*
54*d455d878SSuriyan Ramasami  * fs_size - Determine a file's size
55cf659819SStephen Warren  *
56*d455d878SSuriyan Ramasami  * @filename: Name of the file
57*d455d878SSuriyan Ramasami  * @size: Size of file
58*d455d878SSuriyan Ramasami  * @return 0 if ok with valid *size, negative on error
59cf659819SStephen Warren  */
60*d455d878SSuriyan Ramasami int fs_size(const char *filename, loff_t *size);
61cf659819SStephen Warren 
62cf659819SStephen Warren /*
63*d455d878SSuriyan Ramasami  * fs_read - Read file from the partition previously set by fs_set_blk_dev()
64*d455d878SSuriyan Ramasami  * Note that not all filesystem types support either/both offset!=0 or len!=0.
65045fa1e1SStephen Warren  *
66*d455d878SSuriyan Ramasami  * @filename: Name of file to read from
67*d455d878SSuriyan Ramasami  * @addr: The address to read into
68*d455d878SSuriyan Ramasami  * @offset: The offset in file to read from
69*d455d878SSuriyan Ramasami  * @len: The number of bytes to read. Maybe 0 to read entire file
70*d455d878SSuriyan Ramasami  * @actread: Returns the actual number of bytes read
71*d455d878SSuriyan Ramasami  * @return 0 if ok with valid *actread, -1 on error conditions
72045fa1e1SStephen Warren  */
73*d455d878SSuriyan Ramasami int fs_read(const char *filename, ulong addr, loff_t offset, loff_t len,
74*d455d878SSuriyan Ramasami 	    loff_t *actread);
75045fa1e1SStephen Warren 
76045fa1e1SStephen Warren /*
77*d455d878SSuriyan Ramasami  * fs_write - Write file to the partition previously set by fs_set_blk_dev()
78*d455d878SSuriyan Ramasami  * Note that not all filesystem types support offset!=0.
79bd6fb31fSStephen Warren  *
80*d455d878SSuriyan Ramasami  * @filename: Name of file to read from
81*d455d878SSuriyan Ramasami  * @addr: The address to read into
82*d455d878SSuriyan Ramasami  * @offset: The offset in file to read from. Maybe 0 to write to start of file
83*d455d878SSuriyan Ramasami  * @len: The number of bytes to write
84*d455d878SSuriyan Ramasami  * @actwrite: Returns the actual number of bytes written
85*d455d878SSuriyan Ramasami  * @return 0 if ok with valid *actwrite, -1 on error conditions
86bd6fb31fSStephen Warren  */
87*d455d878SSuriyan Ramasami int fs_write(const char *filename, ulong addr, loff_t offset, loff_t len,
88*d455d878SSuriyan Ramasami 	     loff_t *actwrite);
89bd6fb31fSStephen Warren 
90bd6fb31fSStephen Warren /*
91045fa1e1SStephen Warren  * Common implementation for various filesystem commands, optionally limited
92045fa1e1SStephen Warren  * to a specific filesystem type via the fstype parameter.
93045fa1e1SStephen Warren  */
94cf659819SStephen Warren int do_size(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
95cf659819SStephen Warren 		int fstype);
96f9b55e22SStephen Warren int do_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
97b770e88aSWolfgang Denk 		int fstype);
98045fa1e1SStephen Warren int do_ls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
99045fa1e1SStephen Warren 		int fstype);
1006152916aSStephen Warren int file_exists(const char *dev_type, const char *dev_part, const char *file,
1016152916aSStephen Warren 		int fstype);
102a8f6ab52SSimon Glass int do_save(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
103b770e88aSWolfgang Denk 		int fstype);
104045fa1e1SStephen Warren 
10559e890efSChristian Gmeiner /*
10659e890efSChristian Gmeiner  * Determine the UUID of the specified filesystem and print it. Optionally it is
10759e890efSChristian Gmeiner  * possible to store the UUID directly in env.
10859e890efSChristian Gmeiner  */
10959e890efSChristian Gmeiner int do_fs_uuid(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
11059e890efSChristian Gmeiner 		int fstype);
11159e890efSChristian Gmeiner 
112045fa1e1SStephen Warren #endif /* _FS_H */
113