File system API
-
intdo_fat_fsload(structcmd_tbl*cmdtp, intflag, intargc, char*constargv[])
Run the fatload command
Parameters
struct cmd_tbl *cmdtpCommand information for fatload
int flagCommand flags (CMD_FLAG_...)
int argcNumber of arguments
char *const argv[]List of arguments
Return
result (see enum command_ret_t)
-
intdo_ext2load(structcmd_tbl*cmdtp, intflag, intargc, char*constargv[])
Run the ext2load command
Parameters
struct cmd_tbl *cmdtpCommand information for ext2load
int flagCommand flags (CMD_FLAG_...)
int argcNumber of arguments
char *const argv[]List of arguments
Return
result (see enum command_ret_t)
-
voidfs_set_type(inttype)
Tell fs layer which filesystem type is used
Parameters
int typeFilesystem type to use (FS_TYPE...)
Description
This is needed when reading from a non-block device such as sandbox. It does a similar job to fs_set_blk_dev() but just sets the filesystem type instead of detecting it and loading it on the block device
-
voidfs_close(void)
Unset current block device and partition
Parameters
voidno arguments
Description
fs_close() closes the connection to a file system opened with either fs_set_blk_dev() or fs_set_dev_with_part().
Many file functions implicitly call fs_close(), e.g. fs_closedir(), fs_exist(), fs_ln(), fs_ls(), fs_mkdir(), fs_read(), fs_size(), fs_write(), fs_unlink(), fs_rename().
-
intfs_get_type(void)
Get type of current filesystem
Parameters
voidno arguments
Return
filesystem type
Description
Returns filesystem type representing the current filesystem, or FS_TYPE_ANY for any unrecognised filesystem.
-
constchar*fs_get_type_name(void)
Get type of current filesystem
Parameters
voidno arguments
Return
Pointer to filesystem name
Description
Returns a string describing the current filesystem, or the sentinel "unsupported" for any unrecognised filesystem.
-
intfs_read(constchar*filename, ulongaddr, loff_toffset, loff_tlen, loff_t*actread)
read file from the partition previously set by fs_set_blk_dev()
Parameters
const char *filenamefull path of the file to read from
ulong addraddress of the buffer to write to
loff_t offsetoffset in the file from where to start reading
loff_t lenthe number of bytes to read. Use 0 to read entire file.
loff_t *actreadreturns the actual number of bytes read
Description
Note that not all filesystem drivers support either or both of offset != 0 and len != 0.
Return
0 if OK with valid actread, -1 on error conditions
-
intfs_write(constchar*filename, ulongaddr, loff_toffset, loff_tlen, loff_t*actwrite)
write file to the partition previously set by fs_set_blk_dev()
Parameters
const char *filenamefull path of the file to write to
ulong addraddress of the buffer to read from
loff_t offsetoffset in the file from where to start writing
loff_t lenthe number of bytes to write
loff_t *actwritereturns the actual number of bytes written
Description
Note that not all filesystem drivers support offset != 0.
Return
0 if OK with valid actwrite, -1 on error conditions
-
structfs_dirent
directory entry
Definition
struct fs_dirent {
unsigned int type;
loff_t size;
u32 attr;
struct rtc_time create_time;
struct rtc_time access_time;
struct rtc_time change_time;
char name[FS_DIRENT_NAME_LEN];
};
Members
typeone of FS_DT_x (not a mask)
sizefile size
attrattribute flags (FS_ATTR_*)
create_timetime of creation
access_timetime of last access
change_timetime of last modification
namefile name
Description
A directory entry, returned by fs_readdir(). Returns information about the file/directory at the current directory entry position.
-
structfs_dir_stream
Structure representing an opened directory
Definition
struct fs_dir_stream {
struct blk_desc *desc;
int part;
};
Members
descblock device descriptor
partpartition number
Description
Struct fs_dir_stream should be treated opaque to the user of fs layer. The fields desc and part are used by the fs layer. File system drivers pass additional private fields with the pointers to this structure.
-
structfs_dir_stream *fs_opendir(constchar*filename)
Open a directory
Parameters
const char *filenamepath to the directory to open
Description
Note
The returned struct fs_dir_stream should be treated opaque to the user of the fs layer.
Return
A pointer to the directory stream or NULL on error and errno set appropriately
-
structfs_dirent *fs_readdir(structfs_dir_stream *dirs)
Read the next directory entry in the directory stream.
Parameters
struct fs_dir_stream *dirsthe directory stream
Description
fs_readir works in an analogous way to posix readdir(). The previously returned directory entry is no longer valid after calling fs_readdir() again. After fs_closedir() is called, the returned directory entry is no longer valid.
Return
the next directory entry (only valid until next fs_readdir() or fs_closedir() call, do not attempt to free()) or NULL if the end of the directory is reached.
-
voidfs_closedir(structfs_dir_stream *dirs)
close a directory stream
Parameters
struct fs_dir_stream *dirsthe directory stream
-
intfs_unlink(constchar*filename)
delete a file or directory
Parameters
const char *filenameName of file or directory to delete
Description
If a given name is a directory, it will be deleted only if it’s empty
Return
0 on success, -1 on error conditions
-
intfs_mkdir(constchar*filename)
Create a directory
Parameters
const char *filenameName of directory to create
Return
0 on success, -1 on error conditions
-
intfs_rename(constchar*old_path, constchar*new_path)
rename/move a file or directory
Parameters
const char *old_pathexisting path of the file/directory to rename
const char *new_pathnew path of the file/directory. If this points to an existing file or empty directory, the existing file/directory will be unlinked. If this points to a non-empty directory, the rename will fail.
Return
0 on success, -1 on error conditions
-
intdo_fs_types(structcmd_tbl*cmdtp, intflag, intargc, char*constargv[])
List supported filesystems.
Parameters
struct cmd_tbl *cmdtpCommand information for fstypes
int flagCommand flags (CMD_FLAG_...)
int argcNumber of arguments
char * const argv[]List of arguments
Return
result (see enum command_ret_t)
-
intfs_read_alloc(constchar*fname, ulongsize, uintalign, void**bufp)
Allocate space for a file and read it
Parameters
const char *fnameFilename to read
ulong sizeSize of file to read (must be correct!)
uint alignAlignment to use for memory allocation (0 for default: ARCH_DMA_MINALIGN)
void **bufpOn success, returns the allocated buffer with the nul-terminated file in it
Description
You must call fs_set_blk_dev() or a similar function before calling this, since that sets up the block device to use.
The file is terminated with a nul character
Return
0 if OK, -ENOMEM if out of memory, -EIO if read failed
-
intfs_load_alloc(constchar*ifname, constchar*dev_part_str, constchar*fname, ulongmax_size, ulongalign, void**bufp, ulong*sizep)
Load a file into allocated space
Parameters
const char *ifnameInterface name to read from (e.g. "mmc")
const char *dev_part_strDevice and partition string (e.g. "1:2")
const char *fnameFilename to read
ulong max_sizeMaximum allowed size for the file (use 0 for 1GB)
ulong alignAlignment to use for memory allocation (0 for default)
void **bufpOn success, returns the allocated buffer with the nul-terminated file in it
ulong *sizepOn success, returns the size of the file
Description
The file is terminated with a nul character
Return
0 if OK, -ENOMEM if out of memory, -ENOENT if the file does not exist, -ENOMEDIUM if the device does not exist, -E2BIG if the file is too large (greater than max_size), -EIO if read failed