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 /* 47*6152916aSStephen Warren * Determine whether a file exists 48*6152916aSStephen Warren * 49*6152916aSStephen Warren * Returns 1 if the file exists, 0 if it doesn't exist. 50*6152916aSStephen Warren */ 51*6152916aSStephen Warren int fs_exists(const char *filename); 52*6152916aSStephen Warren 53*6152916aSStephen Warren /* 54045fa1e1SStephen Warren * Read file "filename" from the partition previously set by fs_set_blk_dev(), 55045fa1e1SStephen Warren * to address "addr", starting at byte offset "offset", and reading "len" 56045fa1e1SStephen Warren * bytes. "offset" may be 0 to read from the start of the file. "len" may be 57045fa1e1SStephen Warren * 0 to read the entire file. Note that not all filesystem types support 58045fa1e1SStephen Warren * either/both offset!=0 or len!=0. 59045fa1e1SStephen Warren * 60045fa1e1SStephen Warren * Returns number of bytes read on success. Returns <= 0 on error. 61045fa1e1SStephen Warren */ 62045fa1e1SStephen Warren int fs_read(const char *filename, ulong addr, int offset, int len); 63045fa1e1SStephen Warren 64045fa1e1SStephen Warren /* 65bd6fb31fSStephen Warren * Write file "filename" to the partition previously set by fs_set_blk_dev(), 66bd6fb31fSStephen Warren * from address "addr", starting at byte offset "offset", and writing "len" 67bd6fb31fSStephen Warren * bytes. "offset" may be 0 to write to the start of the file. Note that not 68bd6fb31fSStephen Warren * all filesystem types support offset!=0. 69bd6fb31fSStephen Warren * 70bd6fb31fSStephen Warren * Returns number of bytes read on success. Returns <= 0 on error. 71bd6fb31fSStephen Warren */ 72bd6fb31fSStephen Warren int fs_write(const char *filename, ulong addr, int offset, int len); 73bd6fb31fSStephen Warren 74bd6fb31fSStephen Warren /* 75045fa1e1SStephen Warren * Common implementation for various filesystem commands, optionally limited 76045fa1e1SStephen Warren * to a specific filesystem type via the fstype parameter. 77045fa1e1SStephen Warren */ 78f9b55e22SStephen Warren int do_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[], 79b770e88aSWolfgang Denk int fstype); 80045fa1e1SStephen Warren int do_ls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[], 81045fa1e1SStephen Warren int fstype); 82*6152916aSStephen Warren int file_exists(const char *dev_type, const char *dev_part, const char *file, 83*6152916aSStephen Warren int fstype); 84a8f6ab52SSimon Glass int do_save(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[], 85b770e88aSWolfgang Denk int fstype); 86045fa1e1SStephen Warren 87045fa1e1SStephen Warren #endif /* _FS_H */ 88