xref: /rk3399_rockchip-uboot/include/fs.h (revision cf6598193aed5de8855eaf70c1994f2bc437255a)
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*cf659819SStephen Warren  * Determine a file's size
55*cf659819SStephen Warren  *
56*cf659819SStephen Warren  * Returns the file's size in bytes, or a negative value if it doesn't exist.
57*cf659819SStephen Warren  */
58*cf659819SStephen Warren int fs_size(const char *filename);
59*cf659819SStephen Warren 
60*cf659819SStephen Warren /*
61045fa1e1SStephen Warren  * Read file "filename" from the partition previously set by fs_set_blk_dev(),
62045fa1e1SStephen Warren  * to address "addr", starting at byte offset "offset", and reading "len"
63045fa1e1SStephen Warren  * bytes. "offset" may be 0 to read from the start of the file. "len" may be
64045fa1e1SStephen Warren  * 0 to read the entire file. Note that not all filesystem types support
65045fa1e1SStephen Warren  * either/both offset!=0 or len!=0.
66045fa1e1SStephen Warren  *
67045fa1e1SStephen Warren  * Returns number of bytes read on success. Returns <= 0 on error.
68045fa1e1SStephen Warren  */
69045fa1e1SStephen Warren int fs_read(const char *filename, ulong addr, int offset, int len);
70045fa1e1SStephen Warren 
71045fa1e1SStephen Warren /*
72bd6fb31fSStephen Warren  * Write file "filename" to the partition previously set by fs_set_blk_dev(),
73bd6fb31fSStephen Warren  * from address "addr", starting at byte offset "offset", and writing "len"
74bd6fb31fSStephen Warren  * bytes. "offset" may be 0 to write to the start of the file. Note that not
75bd6fb31fSStephen Warren  * all filesystem types support offset!=0.
76bd6fb31fSStephen Warren  *
77bd6fb31fSStephen Warren  * Returns number of bytes read on success. Returns <= 0 on error.
78bd6fb31fSStephen Warren  */
79bd6fb31fSStephen Warren int fs_write(const char *filename, ulong addr, int offset, int len);
80bd6fb31fSStephen Warren 
81bd6fb31fSStephen Warren /*
82045fa1e1SStephen Warren  * Common implementation for various filesystem commands, optionally limited
83045fa1e1SStephen Warren  * to a specific filesystem type via the fstype parameter.
84045fa1e1SStephen Warren  */
85*cf659819SStephen Warren int do_size(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
86*cf659819SStephen Warren 		int fstype);
87f9b55e22SStephen Warren int do_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
88b770e88aSWolfgang Denk 		int fstype);
89045fa1e1SStephen Warren int do_ls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
90045fa1e1SStephen Warren 		int fstype);
916152916aSStephen Warren int file_exists(const char *dev_type, const char *dev_part, const char *file,
926152916aSStephen Warren 		int fstype);
93a8f6ab52SSimon Glass int do_save(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
94b770e88aSWolfgang Denk 		int fstype);
95045fa1e1SStephen Warren 
96045fa1e1SStephen Warren #endif /* _FS_H */
97