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 25*251cee0dSHans de Goede #define FS_TYPE_UBIFS 4 26045fa1e1SStephen Warren 27045fa1e1SStephen Warren /* 28045fa1e1SStephen Warren * Tell the fs layer which block device an partition to use for future 29045fa1e1SStephen Warren * commands. This also internally identifies the filesystem that is present 30045fa1e1SStephen Warren * within the partition. The identification process may be limited to a 31045fa1e1SStephen Warren * specific filesystem type by passing FS_* in the fstype parameter. 32045fa1e1SStephen Warren * 33045fa1e1SStephen Warren * Returns 0 on success. 34045fa1e1SStephen Warren * Returns non-zero if there is an error accessing the disk or partition, or 35045fa1e1SStephen Warren * no known filesystem type could be recognized on it. 36045fa1e1SStephen Warren */ 37045fa1e1SStephen Warren int fs_set_blk_dev(const char *ifname, const char *dev_part_str, int fstype); 38045fa1e1SStephen Warren 39045fa1e1SStephen Warren /* 40045fa1e1SStephen Warren * Print the list of files on the partition previously set by fs_set_blk_dev(), 41045fa1e1SStephen Warren * in directory "dirname". 42045fa1e1SStephen Warren * 43045fa1e1SStephen Warren * Returns 0 on success. Returns non-zero on error. 44045fa1e1SStephen Warren */ 45045fa1e1SStephen Warren int fs_ls(const char *dirname); 46045fa1e1SStephen Warren 47045fa1e1SStephen Warren /* 486152916aSStephen Warren * Determine whether a file exists 496152916aSStephen Warren * 506152916aSStephen Warren * Returns 1 if the file exists, 0 if it doesn't exist. 516152916aSStephen Warren */ 526152916aSStephen Warren int fs_exists(const char *filename); 536152916aSStephen Warren 546152916aSStephen Warren /* 55d455d878SSuriyan Ramasami * fs_size - Determine a file's size 56cf659819SStephen Warren * 57d455d878SSuriyan Ramasami * @filename: Name of the file 58d455d878SSuriyan Ramasami * @size: Size of file 59d455d878SSuriyan Ramasami * @return 0 if ok with valid *size, negative on error 60cf659819SStephen Warren */ 61d455d878SSuriyan Ramasami int fs_size(const char *filename, loff_t *size); 62cf659819SStephen Warren 63cf659819SStephen Warren /* 64d455d878SSuriyan Ramasami * fs_read - Read file from the partition previously set by fs_set_blk_dev() 65d455d878SSuriyan Ramasami * Note that not all filesystem types support either/both offset!=0 or len!=0. 66045fa1e1SStephen Warren * 67d455d878SSuriyan Ramasami * @filename: Name of file to read from 68d455d878SSuriyan Ramasami * @addr: The address to read into 69d455d878SSuriyan Ramasami * @offset: The offset in file to read from 70d455d878SSuriyan Ramasami * @len: The number of bytes to read. Maybe 0 to read entire file 71d455d878SSuriyan Ramasami * @actread: Returns the actual number of bytes read 72d455d878SSuriyan Ramasami * @return 0 if ok with valid *actread, -1 on error conditions 73045fa1e1SStephen Warren */ 74d455d878SSuriyan Ramasami int fs_read(const char *filename, ulong addr, loff_t offset, loff_t len, 75d455d878SSuriyan Ramasami loff_t *actread); 76045fa1e1SStephen Warren 77045fa1e1SStephen Warren /* 78d455d878SSuriyan Ramasami * fs_write - Write file to the partition previously set by fs_set_blk_dev() 79d455d878SSuriyan Ramasami * Note that not all filesystem types support offset!=0. 80bd6fb31fSStephen Warren * 81d455d878SSuriyan Ramasami * @filename: Name of file to read from 82d455d878SSuriyan Ramasami * @addr: The address to read into 83d455d878SSuriyan Ramasami * @offset: The offset in file to read from. Maybe 0 to write to start of file 84d455d878SSuriyan Ramasami * @len: The number of bytes to write 85d455d878SSuriyan Ramasami * @actwrite: Returns the actual number of bytes written 86d455d878SSuriyan Ramasami * @return 0 if ok with valid *actwrite, -1 on error conditions 87bd6fb31fSStephen Warren */ 88d455d878SSuriyan Ramasami int fs_write(const char *filename, ulong addr, loff_t offset, loff_t len, 89d455d878SSuriyan Ramasami loff_t *actwrite); 90bd6fb31fSStephen Warren 91bd6fb31fSStephen Warren /* 92045fa1e1SStephen Warren * Common implementation for various filesystem commands, optionally limited 93045fa1e1SStephen Warren * to a specific filesystem type via the fstype parameter. 94045fa1e1SStephen Warren */ 95cf659819SStephen Warren int do_size(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[], 96cf659819SStephen Warren int fstype); 97f9b55e22SStephen Warren int do_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[], 98b770e88aSWolfgang Denk int fstype); 99045fa1e1SStephen Warren int do_ls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[], 100045fa1e1SStephen Warren int fstype); 1016152916aSStephen Warren int file_exists(const char *dev_type, const char *dev_part, const char *file, 1026152916aSStephen Warren int fstype); 103a8f6ab52SSimon Glass int do_save(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[], 104b770e88aSWolfgang Denk int fstype); 105045fa1e1SStephen Warren 10659e890efSChristian Gmeiner /* 10759e890efSChristian Gmeiner * Determine the UUID of the specified filesystem and print it. Optionally it is 10859e890efSChristian Gmeiner * possible to store the UUID directly in env. 10959e890efSChristian Gmeiner */ 11059e890efSChristian Gmeiner int do_fs_uuid(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[], 11159e890efSChristian Gmeiner int fstype); 11259e890efSChristian Gmeiner 1131a1ad8e0SSjoerd Simons /* 1141a1ad8e0SSjoerd Simons * Determine the type of the specified filesystem and print it. Optionally it is 1151a1ad8e0SSjoerd Simons * possible to store the type directly in env. 1161a1ad8e0SSjoerd Simons */ 1171a1ad8e0SSjoerd Simons int do_fs_type(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]); 1181a1ad8e0SSjoerd Simons 119045fa1e1SStephen Warren #endif /* _FS_H */ 120