File system API
-
int do_fat_fsload(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
Run the fatload command
Parameters
struct cmd_tbl *cmdtp
Command information for fatload
int flag
Command flags (CMD_FLAG_…)
int argc
Number of arguments
char *const argv[]
List of arguments
Return
result (see enum command_ret_t)
-
int do_ext2load(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
Run the ext2load command
Parameters
struct cmd_tbl *cmdtp
Command information for ext2load
int flag
Command flags (CMD_FLAG_…)
int argc
Number of arguments
char *const argv[]
List of arguments
Return
result (see enum command_ret_t)
-
void fs_set_type(int type)
Tell fs layer which filesystem type is used
Parameters
int type
Filesystem 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
-
void fs_close(void)
Unset current block device and partition
Parameters
void
no 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().
-
int fs_get_type(void)
Get type of current filesystem
Parameters
void
no arguments
Return
filesystem type
Description
Returns filesystem type representing the current filesystem, or FS_TYPE_ANY for any unrecognised filesystem.
-
const char *fs_get_type_name(void)
Get type of current filesystem
Parameters
void
no arguments
Return
Pointer to filesystem name
Description
Returns a string describing the current filesystem, or the sentinel “unsupported” for any unrecognised filesystem.
-
int fs_read(const char *filename, ulong addr, loff_t offset, loff_t len, loff_t *actread)
read file from the partition previously set by fs_set_blk_dev()
Parameters
const char *filename
full path of the file to read from
ulong addr
address of the buffer to write to
loff_t offset
offset in the file from where to start reading
loff_t len
the number of bytes to read. Use 0 to read entire file.
loff_t *actread
returns 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
-
int fs_write(const char *filename, ulong addr, loff_t offset, loff_t len, loff_t *actwrite)
write file to the partition previously set by fs_set_blk_dev()
Parameters
const char *filename
full path of the file to write to
ulong addr
address of the buffer to read from
loff_t offset
offset in the file from where to start writing
loff_t len
the number of bytes to write
loff_t *actwrite
returns 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
-
struct fs_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
type
one of FS_DT_x (not a mask)
size
file size
attr
attribute flags (FS_ATTR_*)
create_time
time of creation
access_time
time of last access
change_time
time of last modification
name
file name
Description
A directory entry, returned by fs_readdir(). Returns information about the file/directory at the current directory entry position.
-
struct fs_dir_stream
Structure representing an opened directory
Definition
struct fs_dir_stream {
struct blk_desc *desc;
int part;
};
Members
desc
block device descriptor
part
partition 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.
-
struct fs_dir_stream *fs_opendir(const char *filename)
Open a directory
Parameters
const char *filename
path 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
-
struct fs_dirent *fs_readdir(struct fs_dir_stream *dirs)
Read the next directory entry in the directory stream.
Parameters
struct fs_dir_stream *dirs
the 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.
-
void fs_closedir(struct fs_dir_stream *dirs)
close a directory stream
Parameters
struct fs_dir_stream *dirs
the directory stream
-
int fs_unlink(const char *filename)
delete a file or directory
Parameters
const char *filename
Name 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
-
int fs_mkdir(const char *filename)
Create a directory
Parameters
const char *filename
Name of directory to create
Return
0 on success, -1 on error conditions
-
int do_fs_types(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
List supported filesystems.
Parameters
struct cmd_tbl *cmdtp
Command information for fstypes
int flag
Command flags (CMD_FLAG_…)
int argc
Number of arguments
char * const argv[]
List of arguments
Return
result (see enum command_ret_t)
-
int fs_read_alloc(const char *fname, ulong size, uint align, void **bufp)
Allocate space for a file and read it
Parameters
const char *fname
Filename to read
ulong size
Size of file to read (must be correct!)
uint align
Alignment to use for memory allocation (0 for default: ARCH_DMA_MINALIGN)
void **bufp
On 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
-
int fs_load_alloc(const char *ifname, const char *dev_part_str, const char *fname, ulong max_size, ulong align, void **bufp, ulong *sizep)
Load a file into allocated space
Parameters
const char *ifname
Interface name to read from (e.g. “mmc”)
const char *dev_part_str
Device and partition string (e.g. “1:2”)
const char *fname
Filename to read
ulong max_size
Maximum allowed size for the file (use 0 for 1GB)
ulong align
Alignment to use for memory allocation (0 for default)
void **bufp
On success, returns the allocated buffer with the nul-terminated file in it
ulong *sizep
On 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