Files
u-boot/include/ext4l.h
Simon Glass 8349f9f700 fs: ext4l: Add statfs support
Implement ext4l_statfs() to return filesystem statistics using the
ext4 superblock. The function returns block size, total block count,
and free block count.

Add unit test to verify the statfs implementation returns valid data.

Cover-letter:
fs: ext4l: Complete read-only filesystem support (Part I)
This series completes read-only support for the ext4l filesystem driver,
which is a port of the Linux ext4 driver to U-Boot.

The ext4l driver provides more complete ext4 support than the existing
ext4 driver, including proper handling of extents, directory hashing,
and other ext4 features.

Changes include:

Sandbox infrastructure:
- Fix IRQ macros and buffer_head includes for sandbox builds

Core fixes:
- Fix path lookup by implementing proper dentry operations
- Fix fscrypt_match_name to do actual name comparison

Filesystem operations:
- Add directory listing (opendir/readdir/closedir)
- Add file existence check (exists)
- Add file size query (size)
- Add file read support (read)
- Add UUID query (uuid)
- Add filesystem statistics (statfs)

New command:
- Add fsinfo command to display filesystem statistics

Testing:
- Add comprehensive unit tests for all operations
- Enable fsuuid command for sandbox testing
END

Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-12-27 13:35:43 -07:00

123 lines
3.0 KiB
C

/* SPDX-License-Identifier: GPL-2.0+ */
/*
* ext4l filesystem interface
*
* Copyright 2025 Canonical Ltd
* Written by Simon Glass <simon.glass@canonical.com>
*/
#ifndef __EXT4L_H__
#define __EXT4L_H__
struct blk_desc;
struct disk_partition;
struct fs_dir_stream;
struct fs_dirent;
struct fs_statfs;
/**
* ext4l_probe() - Probe a block device for an ext4 filesystem
*
* @fs_dev_desc: Block device descriptor
* @fs_partition: Partition information
* Return: 0 on success, -EINVAL if no device or invalid magic,
* -ENOMEM on allocation failure, -EIO on read error
*/
int ext4l_probe(struct blk_desc *fs_dev_desc,
struct disk_partition *fs_partition);
/**
* ext4l_close() - Close the ext4 filesystem
*/
void ext4l_close(void);
/**
* ext4l_ls() - List directory contents
*
* @dirname: Directory path to list
* Return: 0 on success, negative on error
*/
int ext4l_ls(const char *dirname);
/**
* ext4l_exists() - Check if a file or directory exists
*
* @filename: Path to check
* Return: 1 if exists, 0 if not
*/
int ext4l_exists(const char *filename);
/**
* ext4l_size() - Get the size of a file
*
* @filename: Path to file
* @sizep: Returns the file size
* Return: 0 on success, negative on error
*/
int ext4l_size(const char *filename, loff_t *sizep);
/**
* ext4l_read() - Read data from a file
*
* @filename: Path to file
* @buf: Buffer to read data into
* @offset: Byte offset to start reading from
* @len: Number of bytes to read (0 = read entire file from offset)
* @actread: Returns actual bytes read
* Return: 0 on success, negative on error
*/
int ext4l_read(const char *filename, void *buf, loff_t offset, loff_t len,
loff_t *actread);
/**
* ext4l_get_uuid() - Get the filesystem UUID
*
* @uuid: Buffer to receive the 16-byte UUID
* Return: 0 on success, -ENODEV if not mounted
*/
int ext4l_get_uuid(u8 *uuid);
/**
* ext4l_uuid() - Get the filesystem UUID as a string
*
* @uuid_str: Buffer to receive the UUID string (must be at least 37 bytes)
* Return: 0 on success, -ENODEV if not mounted
*/
int ext4l_uuid(char *uuid_str);
/**
* ext4l_statfs() - Get filesystem statistics
*
* @stats: Pointer to fs_statfs structure to fill
* Return: 0 on success, -ENODEV if not mounted
*/
int ext4l_statfs(struct fs_statfs *stats);
/**
* ext4l_opendir() - Open a directory for iteration
*
* @filename: Directory path
* @dirsp: Returns directory stream pointer
* Return: 0 on success, -ENODEV if not mounted, -ENOTDIR if not a directory,
* -ENOMEM on allocation failure
*/
int ext4l_opendir(const char *filename, struct fs_dir_stream **dirsp);
/**
* ext4l_readdir() - Read the next directory entry
*
* @dirs: Directory stream from ext4l_opendir
* @dentp: Returns pointer to directory entry
* Return: 0 on success, -ENODEV if not mounted, -ENOENT at end of directory
*/
int ext4l_readdir(struct fs_dir_stream *dirs, struct fs_dirent **dentp);
/**
* ext4l_closedir() - Close a directory stream
*
* @dirs: Directory stream to close
*/
void ext4l_closedir(struct fs_dir_stream *dirs);
#endif /* __EXT4L_H__ */