File system API

struct fs_plat

Filesystem information

Definition

struct fs_plat {
  char name[FS_MAX_NAME_LEN];
  struct blk_desc *desc;
  int part_num;
  struct disk_partition part;
};

Members

name

Name of the filesystem, or empty if not available

desc

Block device descriptor, or NULL if not block-backed

part_num

Partition number (valid only when desc is non-NULL)

part

Partition information (valid only when desc is non-NULL)

Description

For block-device-backed filesystems, desc and part identify the underlying storage. Non-block filesystems (hostfs, rootfs) leave desc as NULL.

struct fs_priv

Private information for the FS devices

Definition

struct fs_priv {
  bool mounted;
};

Members

mounted

true if mounted

int fs_mount(struct udevice *dev)

Mount the filesystem

Parameters

struct udevice *dev

Filesystem device Return 0 if OK, -EISCONN if already mounted, other -ve on error

int fs_unmount(struct udevice *dev)

Unmount the filesystem

Parameters

struct udevice *dev

Filesystem device Return 0 if OK, -ENOTCONN if not mounted, other -ve on error

int fs_lookup_dir(struct udevice *dev, const char *path, struct udevice **dirp)

Look up a directory on a filesystem

Parameters

struct udevice *dev

Filesystem device

const char *path

Path to look up, “” or “/” for the root

struct udevice **dirp

Returns associated directory device, creating if necessary Return 0 if OK, -ENOENT, other -ve on error

Description

If a new directory-device is created, its uclass data is set up also

int fs_do_ln(struct udevice *dev, const char *path, const char *target)

Create a symbolic link on a filesystem

Parameters

struct udevice *dev

Filesystem device

const char *path

Path of symlink to create (within the filesystem)

const char *target

Target the symlink points to

Return

0 if OK, -ENOSYS if not supported, other -ve on error

int fs_do_rename(struct udevice *dev, const char *old_path, const char *new_path)

Rename or move a file on a filesystem

Parameters

struct udevice *dev

Filesystem device

const char *old_path

Current path (within the filesystem)

const char *new_path

New path (within the filesystem)

Description

Both paths must be within the same filesystem.

Return

0 if OK, -ENOSYS if not supported, other -ve on error

Read a symbolic link target on a filesystem

Parameters

struct udevice *dev

Filesystem device

const char *path

Path to the symbolic link (within the filesystem)

char *buf

Buffer to receive the target path

int size

Size of buffer

Return

length of target, -ENOSYS if not supported, other -ve on error

int fs_do_statfs(struct udevice *dev, struct fs_statfs *stats)

Get filesystem statistics

Parameters

struct udevice *dev

Filesystem device

struct fs_statfs *stats

Returns filesystem statistics

Return

0 if OK, -ENOSYS if not supported, other -ve on error

Delete a file on a filesystem

Parameters

struct udevice *dev

Filesystem device

const char *path

Path of the file to delete (within the filesystem)

Return

0 if OK, -ENOSYS if not supported, other -ve on error

int fs_do_mkdir(struct udevice *dev, const char *path)

Create a directory on a filesystem

Parameters

struct udevice *dev

Filesystem device

const char *path

Path of the directory to create (within the filesystem)

Return

0 if OK, -ENOSYS if not supported, other -ve on error

int fs_split_path(const char *fname, char **subdirp, const char **leafp)

Get a list of subdirs in a filename

Parameters

const char *fname

Filename to parse

char **subdirp

Returns an allocating string containing the subdirs, or “/” if none

const char **leafp

Returns a pointer to the leaf filename, within fname

Description

For example, ‘/path/to/fred’ returns an alist containing allocated strings ‘path’ and ‘to’, with *leafp pointing to the ‘f’

void fs_split_path_inplace(char *fname, const char **dirp, const char **leafp)

Split a path into directory and leaf in place

Parameters

char *fname

Path to split (modified in place when it contains ‘/’)

const char **dirp

Returns pointer to the directory part

const char **leafp

Returns pointer to the leaf filename

Description

Modifies fname by null-terminating at the last ‘/’. Sets dirp to point to the directory part and leafp to the leaf. If there is no ‘/’, dirp is set to “” and leafp points to fname unchanged.