virtiofs filesystem

Browse source code on GitHub

Overview

This sample app demonstrates the use of Zephyr’s file system API over virtiofs by reading, creating and listing files and directories. In the case of virtiofs the mounted filesystem is a directory on the host.

Requirements

This sample requires virtiofsd to run.

Building

west build -b qemu_x86_64 samples/subsys/fs/virtiofs

Running

Before launching QEMU virtiofsd has to be running. QEMU’s arguments are embedded using CONFIG_QEMU_EXTRA_FLAGS and socket path is set to /tmp/vhostqemu, so virtiofsd has to be launched using

virtiofsd --socket-path=/tmp/vhostqemu -o source=shared_dir_path

where shared_dir_path is a directory that will be mounted on Zephyr side. Then you can launch QEMU using:

west build -t run

This sample will list the files and directories in the mounted filesystem and print the contents of the file file in the mounted directory. This sample will also create some files and directories. You can create the sample directory using prepare_sample_directory.sh.

Example output:

*** Booting Zephyr OS build v4.1.0-rc1-28-gc6816316fc50 ***
/virtiofs directory tree:
- dir2 (type=dir)
  - b (type=file, size=3)
  - a (type=file, size=2)
  - c (type=file, size=4)
- dir (type=dir)
  - some_file (type=file, size=0)
  - nested_dir (type=dir)
     - some_other_file (type=file, size=0)
- file (type=file, size=27)

/virtiofs/file content:
this is a file on the host

After running the sample you can check the created files:

shared_dir_path$ cat file_created_by_zephyr
hello world
shared_dir_path$ cat second_file_created_by_zephyr
lorem ipsum

See also

File System APIs