Skip to main content

Crate flashkit_ubi_uapi

Crate flashkit_ubi_uapi 

Expand description

Bindings for the Linux UBI userspace API.

use std::fs::File;

use flashkit_ubi_uapi::{UBI_DEV_NUM_AUTO, UbiAttachReq};

let control = File::open("/dev/ubi_ctrl")?;
let mut req = UbiAttachReq {
    ubi_num: UBI_DEV_NUM_AUTO,
    mtd_num: 0,
    ..UbiAttachReq::default()
};
flashkit_ubi_uapi::ubi_att(&control, &mut req)?;
let ubi_num = req.ubi_num;

The crate mirrors the kernel header include/uapi/mtd/ubi-user.h of the latest mainline kernel. Structs and fields keep their kernel names. Each ioctl has a safe function with the name of the ioctl in snake case without IOC, such as ubi_mkvol for UBI_IOCMKVOL.

Each ioctl goes to one kind of file:

Groups of kernel constants are newtypes with associated constants, such as UbiVolType::DYNAMIC for UBI_DYNAMIC_VOLUME. The documentation of each constant states its kernel name. The newtypes keep the layout of the kernel integer and accept values that this crate doesn’t know.

The functions only check what memory safety needs. They pass the arguments to the kernel as they are, without fallbacks for older kernels. Errors are the error numbers of the kernel.

The documentation states the kernel version that added each ioctl, field and constant. Items without a version are in Linux 2.6.22, the first version with UBI. Older kernels return ENOTTY for a newer ioctl and ignore a newer field.

Β§Features

  • std: the functions take file descriptors of the standard library, such as std::fs::File. Without it, they take the file descriptor types of rustix.

ModulesΒ§

attach πŸ”’
block πŸ”’
ec_info πŸ”’
leb πŸ”’
peb πŸ”’
property πŸ”’
rename πŸ”’
update πŸ”’
values πŸ”’
volume πŸ”’

StructsΒ§

Errno
errnoβ€”An error code.
UbiAttachReq
struct ubi_attach_req: an MTD device to attach.
UbiBlkcreateReq
struct ubi_blkcreate_req: options of a new block device.
UbiEcinfoReq
struct ubi_ecinfo_req: a request for the erase counters of a range of physical eraseblocks.
UbiLebChangeReq
struct ubi_leb_change_req: a logical eraseblock to replace.
UbiMapReq
struct ubi_map_req: a logical eraseblock to map.
UbiMkvolReq
struct ubi_mkvol_req: a volume to create.
UbiRnvolEnt
Entry of UbiRnvolReq: a volume and its new name.
UbiRnvolReq
struct ubi_rnvol_req: volumes to rename in one atomic step.
UbiRsvolReq
struct ubi_rsvol_req: a new size for a volume.
UbiSetVolPropReq
struct ubi_set_vol_prop_req: a property of a volume and its new value.
UbiVolFlags
Flags of a new volume.
UbiVolProp
Property of a volume, the UBI_VOL_PROP_* constants.
UbiVolType
Type of a volume, the UBI_*_VOLUME constants.

ConstantsΒ§

MAX_UBI_MTD_NAME_LEN
Longest MTD device name that UBI accepts.
UBI_DEV_NUM_AUTO
Lets the kernel pick the number of a new UBI device.
UBI_IOCATT
Opcode of ubi_att. The header declares it as a write, but the kernel also writes the device number back to userspace.
UBI_IOCDET
Opcode of ubi_det.
UBI_IOCEBCH
Opcode of ubi_ebch. The header declares it as a write of an int32_t, but the kernel reads a UbiLebChangeReq.
UBI_IOCEBER
Opcode of ubi_eber.
UBI_IOCEBISMAP
Opcode of ubi_ebismap. The header declares it as a read, but the kernel reads the logical eraseblock number from userspace.
UBI_IOCEBMAP
Opcode of ubi_ebmap.
UBI_IOCEBUNMAP
Opcode of ubi_ebunmap.
UBI_IOCECNFO
Opcode of ubi_ecnfo. Its size covers the fields before erase_counters.
UBI_IOCMKVOL
Opcode of ubi_mkvol. The header declares it as a write, but the kernel also writes the volume ID back to userspace.
UBI_IOCRMVOL
Opcode of ubi_rmvol.
UBI_IOCRNVOL
Opcode of ubi_rnvol.
UBI_IOCRPEB
Opcode of ubi_rpeb.
UBI_IOCRSVOL
Opcode of ubi_rsvol.
UBI_IOCSETVOLPROP
Opcode of ubi_setvolprop.
UBI_IOCSPEB
Opcode of ubi_speb.
UBI_IOCVOLCRBLK
Opcode of ubi_volcrblk.
UBI_IOCVOLRMBLK
Opcode of ubi_volrmblk.
UBI_IOCVOLUP
Opcode of ubi_volup.
UBI_MAX_RNVOL
Most volumes that one ubi_rnvol renames.
UBI_MAX_VOLUME_NAME
Longest volume name, without the zero byte at the end.
UBI_VOL_NUM_AUTO
Lets the kernel pick the ID of a new volume.

FunctionsΒ§

ubi_att
UBI_IOCATT: attaches an MTD device to UBI through the UBI control device, /dev/ubi_ctrl.
ubi_det
UBI_IOCDET: detaches UBI device ubi_num through the UBI control device, /dev/ubi_ctrl.
ubi_ebch
UBI_IOCEBCH: starts an atomic change of a logical eraseblock of the volume of the file, /dev/ubi<n>_<m>.
ubi_eber
UBI_IOCEBER: unmaps logical eraseblock lnum of the volume of the file, /dev/ubi<n>_<m>, and waits until its physical eraseblock is erased.
ubi_ebismap
UBI_IOCEBISMAP: returns whether logical eraseblock lnum of the volume of the file, /dev/ubi<n>_<m>, is mapped.
ubi_ebmap
UBI_IOCEBMAP: maps an unmapped logical eraseblock of the volume of the file, /dev/ubi<n>_<m>, to an erased physical eraseblock.
ubi_ebunmap
UBI_IOCEBUNMAP: unmaps logical eraseblock lnum of the volume of the file, /dev/ubi<n>_<m>.
ubi_ecnfo
UBI_IOCECNFO: reads the erase counters of req.length physical eraseblocks from req.start of the UBI device of the file, /dev/ubi<n>.
ubi_mkvol
UBI_IOCMKVOL: creates a volume on the UBI device of the file, /dev/ubi<n>.
ubi_rmvol
UBI_IOCRMVOL: removes volume vol_id from the UBI device of the file, /dev/ubi<n>.
ubi_rnvol
UBI_IOCRNVOL: renames volumes of the UBI device of the file, /dev/ubi<n>, in one atomic step.
ubi_rpeb
UBI_IOCRPEB: reads physical eraseblock pnum of the UBI device of the file, /dev/ubi<n>, and scrubs it if it has bit flips.
ubi_rsvol
UBI_IOCRSVOL: resizes a volume of the UBI device of the file, /dev/ubi<n>.
ubi_setvolprop
UBI_IOCSETVOLPROP: sets a property of the volume of the file, /dev/ubi<n>_<m>.
ubi_speb
UBI_IOCSPEB: scrubs physical eraseblock pnum of the UBI device of the file, /dev/ubi<n>.
ubi_volcrblk
UBI_IOCVOLCRBLK: creates a read-only block device on the volume of the file, /dev/ubi<n>_<m>.
ubi_volrmblk
UBI_IOCVOLRMBLK: removes the block device of the volume of the file, /dev/ubi<n>_<m>.
ubi_volup
UBI_IOCVOLUP: starts an update of the volume of the file, /dev/ubi<n>_<m>, with bytes bytes.

Type AliasesΒ§

Opcode
The type used by the ioctl to signify the command.