vfs – virtual filesystem control

The vfs module contains functions for creating filesystem objects and mounting/unmounting them in the Virtual Filesystem.

Filesystem mounting

Some ports provide a Virtual Filesystem (VFS) and the ability to mount multiple “real” filesystems within this VFS. Filesystem objects can be mounted at either the root of the VFS, or at a subdirectory that lives in the root. This allows dynamic and flexible configuration of the filesystem that is seen by Python programs. Ports that have this functionality provide the mount() and umount() functions, and possibly various filesystem implementations represented by VFS classes.

vfs.mount(fsobj, mount_point, *, readonly)

Mount the filesystem object fsobj at the location in the VFS given by the mount_point string. fsobj can be a a VFS object that has a mount() method, or a block device. If it’s a block device then the filesystem type is automatically detected (an exception is raised if no filesystem was recognised). mount_point may be '/' to mount fsobj at the root, or '/<name>' to mount it at a subdirectory under the root.

If readonly is True then the filesystem is mounted read-only.

During the mount process the method mount() is called on the filesystem object.

Will raise OSError(EPERM) if mount_point is already mounted.

vfs.mount()

With no arguments to mount(), return a list of tuples representing all active mountpoints.

The returned list has the form [(fsobj, mount_point), …].

vfs.umount(mount_point)

Unmount a filesystem. mount_point can be a string naming the mount location, or a previously-mounted filesystem object. During the unmount process the method umount() is called on the filesystem object.

Will raise OSError(EINVAL) if mount_point is not found.

class vfs.VfsFat(block_dev)

Create a filesystem object that uses the FAT filesystem format. Storage of the FAT filesystem is provided by block_dev. Objects created by this constructor can be mounted using mount().

static mkfs(block_dev)

Build a FAT filesystem on block_dev.

Block devices

A block device is an object which implements the block protocol. This enables a device to support MicroPython filesystems. The physical hardware is represented by a user defined class. The AbstractBlockDev class is a template for the design of such a class: MicroPython does not actually provide that class, but an actual block device class must implement the methods described below.

A concrete implementation of this class will usually allow access to the memory-like functionality of a piece of hardware (like flash memory). A block device can be formatted to any supported filesystem and mounted using os methods.

See filesystem for example implementations of block devices using the two variants of the block protocol described below.