Files
u-boot/include/fs_common.h
Simon Glass 5ab90a9307 virtio: Plumb virtio-fs into the legacy filesystem code
Add compatibility function to support a single virtio-fs via the normal
'ls' and 'load' commands. Other commands are not supported for now.

Add a workaround for the fact that virtiofs does not use a block device.
The existing filesystem layer does not support non-block filesystems -
sandbox's hostfs mostly bypasses this code.

Make sure that sandbox does not try to mount a virtio-fs as this does
not work at present. It will require either a fake driver for virtio-fs
which connects to host files, or possibly something involving FUSE.

Series-to: concept
Cover-letter:
virtio: Support virtio-fs
This series introduces support for virtio-fs, a filesystem which
provides access to host files from within a QEMU guest OS.

A new filesystem driver is created with support for the three uclasses
(FS, DIR, FILE). A compatibility layer is added as well, so that the
existing cmdline work as expected.

Only listing directories and reading files are supported so far.

Since sandbox works by using a NULL blk_desc, a workaround is added for
now. Once we switch commands (and bootstd!) over to the new filesystem
approach, this will go away.

It is possible to test this using something like:

   ./scripts/build-qemu -a x86  -rs -D .

then within U-Boot:

   ls virtio 0
END

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-06-30 11:57:41 -06:00

83 lines
1.9 KiB
C

/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved.
*/
#ifndef _FS_COMMON_H
#define _FS_COMMON_H
#include <rtc.h>
/**
* @FS_TYPE_VIRTIO: virtio-fs for access to the host filesystem from QEMU
*/
enum fs_type_t {
FS_TYPE_ANY = 0,
FS_TYPE_FAT,
FS_TYPE_EXT,
FS_TYPE_SANDBOX,
FS_TYPE_UBIFS,
FS_TYPE_BTRFS,
FS_TYPE_SQUASHFS,
FS_TYPE_EROFS,
FS_TYPE_SEMIHOSTING,
FS_TYPE_EXFAT,
FS_TYPE_VIRTIO,
};
/*
* Directory entry types, matches the subset of DT_x in posix readdir()
* which apply to u-boot.
*/
#define FS_DT_DIR 4 /* directory */
#define FS_DT_REG 8 /* regular file */
#define FS_DT_LNK 10 /* symbolic link */
#define FS_DIRENT_NAME_LEN CONFIG_IS_ENABLED(FS_EXFAT, (1024), (256))
/**
* struct fs_dirent - directory entry
*
* A directory entry, returned by fs_readdir(). Returns information
* about the file/directory at the current directory entry position.
*/
struct fs_dirent {
/** @type: one of FS_DT_x (not a mask) */
unsigned int type;
/** @size: file size */
loff_t size;
/** @attr: attribute flags (FS_ATTR_*) */
u32 attr;
/** @create_time: time of creation */
struct rtc_time create_time;
/** @access_time: time of last access */
struct rtc_time access_time;
/** @change_time: time of last modification */
struct rtc_time change_time;
/** @name: file name */
char name[FS_DIRENT_NAME_LEN];
};
/**
* struct fs_dir_stream - Structure representing an opened directory
*
* 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.
*
* @dev: dir device (UCLASS_DIR)
* @desc: block device descriptor
* @part: partition number
*/
struct fs_dir_stream {
#ifdef CONFIG_FS
struct udevice *dev;
u64 fh;
u64 offset;
#endif
struct blk_desc *desc;
int part;
};
#endif