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:
- The UBI control device,
/dev/ubi_ctrl:ubi_attandubi_det. - A UBI device,
/dev/ubi<n>:ubi_mkvol,ubi_rmvol,ubi_rsvol,ubi_rnvol,ubi_rpeb,ubi_spebandubi_ecnfo. - A volume,
/dev/ubi<n>_<m>: all other functions.
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 asstd::fs::File. Without it, they take the file descriptor types ofrustix.
ModulesΒ§
- attach π
- block π
- ec_info π
- leb π
- peb π
- property π
- rename π
- update π
- values π
- volume π
StructsΒ§
- Errno
errnoβAn error code.- UbiAttach
Req struct ubi_attach_req: an MTD device to attach.- UbiBlkcreate
Req struct ubi_blkcreate_req: options of a new block device.- UbiEcinfo
Req struct ubi_ecinfo_req: a request for the erase counters of a range of physical eraseblocks.- UbiLeb
Change Req struct ubi_leb_change_req: a logical eraseblock to replace.- UbiMap
Req struct ubi_map_req: a logical eraseblock to map.- UbiMkvol
Req struct ubi_mkvol_req: a volume to create.- UbiRnvol
Ent - Entry of
UbiRnvolReq: a volume and its new name. - UbiRnvol
Req struct ubi_rnvol_req: volumes to rename in one atomic step.- UbiRsvol
Req struct ubi_rsvol_req: a new size for a volume.- UbiSet
VolProp Req struct ubi_set_vol_prop_req: a property of a volume and its new value.- UbiVol
Flags - Flags of a new volume.
- UbiVol
Prop - Property of a volume, the
UBI_VOL_PROP_*constants. - UbiVol
Type - Type of a volume, the
UBI_*_VOLUMEconstants.
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 anint32_t, but the kernel reads aUbiLebChangeReq. - 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 beforeerase_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_rnvolrenames. - 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 deviceubi_numthrough 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 eraseblocklnumof the volume of the file,/dev/ubi<n>_<m>, and waits until its physical eraseblock is erased.- ubi_
ebismap UBI_IOCEBISMAP: returns whether logical eraseblocklnumof 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 eraseblocklnumof the volume of the file,/dev/ubi<n>_<m>.- ubi_
ecnfo UBI_IOCECNFO: reads the erase counters ofreq.lengthphysical eraseblocks fromreq.startof 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 volumevol_idfrom 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 eraseblockpnumof 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 eraseblockpnumof 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>, withbytesbytes.
Type AliasesΒ§
- Opcode
- The type used by the
ioctlto signify the command.