162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * Copyright © International Business Machines Corp., 2006 462306a36Sopenharmony_ci * 562306a36Sopenharmony_ci * This program is free software; you can redistribute it and/or modify 662306a36Sopenharmony_ci * it under the terms of the GNU General Public License as published by 762306a36Sopenharmony_ci * the Free Software Foundation; either version 2 of the License, or 862306a36Sopenharmony_ci * (at your option) any later version. 962306a36Sopenharmony_ci * 1062306a36Sopenharmony_ci * This program is distributed in the hope that it will be useful, 1162306a36Sopenharmony_ci * but WITHOUT ANY WARRANTY; without even the implied warranty of 1262306a36Sopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 1362306a36Sopenharmony_ci * the GNU General Public License for more details. 1462306a36Sopenharmony_ci * 1562306a36Sopenharmony_ci * You should have received a copy of the GNU General Public License 1662306a36Sopenharmony_ci * along with this program; if not, write to the Free Software 1762306a36Sopenharmony_ci * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 1862306a36Sopenharmony_ci * 1962306a36Sopenharmony_ci * Author: Artem Bityutskiy (Битюцкий Артём) 2062306a36Sopenharmony_ci */ 2162306a36Sopenharmony_ci 2262306a36Sopenharmony_ci#ifndef __UBI_USER_H__ 2362306a36Sopenharmony_ci#define __UBI_USER_H__ 2462306a36Sopenharmony_ci 2562306a36Sopenharmony_ci#include <linux/types.h> 2662306a36Sopenharmony_ci 2762306a36Sopenharmony_ci/* 2862306a36Sopenharmony_ci * UBI device creation (the same as MTD device attachment) 2962306a36Sopenharmony_ci * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 3062306a36Sopenharmony_ci * 3162306a36Sopenharmony_ci * MTD devices may be attached using %UBI_IOCATT ioctl command of the UBI 3262306a36Sopenharmony_ci * control device. The caller has to properly fill and pass 3362306a36Sopenharmony_ci * &struct ubi_attach_req object - UBI will attach the MTD device specified in 3462306a36Sopenharmony_ci * the request and return the newly created UBI device number as the ioctl 3562306a36Sopenharmony_ci * return value. 3662306a36Sopenharmony_ci * 3762306a36Sopenharmony_ci * UBI device deletion (the same as MTD device detachment) 3862306a36Sopenharmony_ci * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 3962306a36Sopenharmony_ci * 4062306a36Sopenharmony_ci * An UBI device maybe deleted with %UBI_IOCDET ioctl command of the UBI 4162306a36Sopenharmony_ci * control device. 4262306a36Sopenharmony_ci * 4362306a36Sopenharmony_ci * UBI volume creation 4462306a36Sopenharmony_ci * ~~~~~~~~~~~~~~~~~~~ 4562306a36Sopenharmony_ci * 4662306a36Sopenharmony_ci * UBI volumes are created via the %UBI_IOCMKVOL ioctl command of UBI character 4762306a36Sopenharmony_ci * device. A &struct ubi_mkvol_req object has to be properly filled and a 4862306a36Sopenharmony_ci * pointer to it has to be passed to the ioctl. 4962306a36Sopenharmony_ci * 5062306a36Sopenharmony_ci * UBI volume deletion 5162306a36Sopenharmony_ci * ~~~~~~~~~~~~~~~~~~~ 5262306a36Sopenharmony_ci * 5362306a36Sopenharmony_ci * To delete a volume, the %UBI_IOCRMVOL ioctl command of the UBI character 5462306a36Sopenharmony_ci * device should be used. A pointer to the 32-bit volume ID hast to be passed 5562306a36Sopenharmony_ci * to the ioctl. 5662306a36Sopenharmony_ci * 5762306a36Sopenharmony_ci * UBI volume re-size 5862306a36Sopenharmony_ci * ~~~~~~~~~~~~~~~~~~ 5962306a36Sopenharmony_ci * 6062306a36Sopenharmony_ci * To re-size a volume, the %UBI_IOCRSVOL ioctl command of the UBI character 6162306a36Sopenharmony_ci * device should be used. A &struct ubi_rsvol_req object has to be properly 6262306a36Sopenharmony_ci * filled and a pointer to it has to be passed to the ioctl. 6362306a36Sopenharmony_ci * 6462306a36Sopenharmony_ci * UBI volumes re-name 6562306a36Sopenharmony_ci * ~~~~~~~~~~~~~~~~~~~ 6662306a36Sopenharmony_ci * 6762306a36Sopenharmony_ci * To re-name several volumes atomically at one go, the %UBI_IOCRNVOL command 6862306a36Sopenharmony_ci * of the UBI character device should be used. A &struct ubi_rnvol_req object 6962306a36Sopenharmony_ci * has to be properly filled and a pointer to it has to be passed to the ioctl. 7062306a36Sopenharmony_ci * 7162306a36Sopenharmony_ci * UBI volume update 7262306a36Sopenharmony_ci * ~~~~~~~~~~~~~~~~~ 7362306a36Sopenharmony_ci * 7462306a36Sopenharmony_ci * Volume update should be done via the %UBI_IOCVOLUP ioctl command of the 7562306a36Sopenharmony_ci * corresponding UBI volume character device. A pointer to a 64-bit update 7662306a36Sopenharmony_ci * size should be passed to the ioctl. After this, UBI expects user to write 7762306a36Sopenharmony_ci * this number of bytes to the volume character device. The update is finished 7862306a36Sopenharmony_ci * when the claimed number of bytes is passed. So, the volume update sequence 7962306a36Sopenharmony_ci * is something like: 8062306a36Sopenharmony_ci * 8162306a36Sopenharmony_ci * fd = open("/dev/my_volume"); 8262306a36Sopenharmony_ci * ioctl(fd, UBI_IOCVOLUP, &image_size); 8362306a36Sopenharmony_ci * write(fd, buf, image_size); 8462306a36Sopenharmony_ci * close(fd); 8562306a36Sopenharmony_ci * 8662306a36Sopenharmony_ci * Logical eraseblock erase 8762306a36Sopenharmony_ci * ~~~~~~~~~~~~~~~~~~~~~~~~ 8862306a36Sopenharmony_ci * 8962306a36Sopenharmony_ci * To erase a logical eraseblock, the %UBI_IOCEBER ioctl command of the 9062306a36Sopenharmony_ci * corresponding UBI volume character device should be used. This command 9162306a36Sopenharmony_ci * unmaps the requested logical eraseblock, makes sure the corresponding 9262306a36Sopenharmony_ci * physical eraseblock is successfully erased, and returns. 9362306a36Sopenharmony_ci * 9462306a36Sopenharmony_ci * Atomic logical eraseblock change 9562306a36Sopenharmony_ci * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 9662306a36Sopenharmony_ci * 9762306a36Sopenharmony_ci * Atomic logical eraseblock change operation is called using the %UBI_IOCEBCH 9862306a36Sopenharmony_ci * ioctl command of the corresponding UBI volume character device. A pointer to 9962306a36Sopenharmony_ci * a &struct ubi_leb_change_req object has to be passed to the ioctl. Then the 10062306a36Sopenharmony_ci * user is expected to write the requested amount of bytes (similarly to what 10162306a36Sopenharmony_ci * should be done in case of the "volume update" ioctl). 10262306a36Sopenharmony_ci * 10362306a36Sopenharmony_ci * Logical eraseblock map 10462306a36Sopenharmony_ci * ~~~~~~~~~~~~~~~~~~~~~ 10562306a36Sopenharmony_ci * 10662306a36Sopenharmony_ci * To map a logical eraseblock to a physical eraseblock, the %UBI_IOCEBMAP 10762306a36Sopenharmony_ci * ioctl command should be used. A pointer to a &struct ubi_map_req object is 10862306a36Sopenharmony_ci * expected to be passed. The ioctl maps the requested logical eraseblock to 10962306a36Sopenharmony_ci * a physical eraseblock and returns. Only non-mapped logical eraseblocks can 11062306a36Sopenharmony_ci * be mapped. If the logical eraseblock specified in the request is already 11162306a36Sopenharmony_ci * mapped to a physical eraseblock, the ioctl fails and returns error. 11262306a36Sopenharmony_ci * 11362306a36Sopenharmony_ci * Logical eraseblock unmap 11462306a36Sopenharmony_ci * ~~~~~~~~~~~~~~~~~~~~~~~~ 11562306a36Sopenharmony_ci * 11662306a36Sopenharmony_ci * To unmap a logical eraseblock to a physical eraseblock, the %UBI_IOCEBUNMAP 11762306a36Sopenharmony_ci * ioctl command should be used. The ioctl unmaps the logical eraseblocks, 11862306a36Sopenharmony_ci * schedules corresponding physical eraseblock for erasure, and returns. Unlike 11962306a36Sopenharmony_ci * the "LEB erase" command, it does not wait for the physical eraseblock being 12062306a36Sopenharmony_ci * erased. Note, the side effect of this is that if an unclean reboot happens 12162306a36Sopenharmony_ci * after the unmap ioctl returns, you may find the LEB mapped again to the same 12262306a36Sopenharmony_ci * physical eraseblock after the UBI is run again. 12362306a36Sopenharmony_ci * 12462306a36Sopenharmony_ci * Check if logical eraseblock is mapped 12562306a36Sopenharmony_ci * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 12662306a36Sopenharmony_ci * 12762306a36Sopenharmony_ci * To check if a logical eraseblock is mapped to a physical eraseblock, the 12862306a36Sopenharmony_ci * %UBI_IOCEBISMAP ioctl command should be used. It returns %0 if the LEB is 12962306a36Sopenharmony_ci * not mapped, and %1 if it is mapped. 13062306a36Sopenharmony_ci * 13162306a36Sopenharmony_ci * Set an UBI volume property 13262306a36Sopenharmony_ci * ~~~~~~~~~~~~~~~~~~~~~~~~~ 13362306a36Sopenharmony_ci * 13462306a36Sopenharmony_ci * To set an UBI volume property the %UBI_IOCSETPROP ioctl command should be 13562306a36Sopenharmony_ci * used. A pointer to a &struct ubi_set_vol_prop_req object is expected to be 13662306a36Sopenharmony_ci * passed. The object describes which property should be set, and to which value 13762306a36Sopenharmony_ci * it should be set. 13862306a36Sopenharmony_ci * 13962306a36Sopenharmony_ci * Block devices on UBI volumes 14062306a36Sopenharmony_ci * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 14162306a36Sopenharmony_ci * 14262306a36Sopenharmony_ci * To create a R/O block device on top of an UBI volume the %UBI_IOCVOLCRBLK 14362306a36Sopenharmony_ci * should be used. A pointer to a &struct ubi_blkcreate_req object is expected 14462306a36Sopenharmony_ci * to be passed, which is not used and reserved for future usage. 14562306a36Sopenharmony_ci * 14662306a36Sopenharmony_ci * Conversely, to remove a block device the %UBI_IOCVOLRMBLK should be used, 14762306a36Sopenharmony_ci * which takes no arguments. 14862306a36Sopenharmony_ci */ 14962306a36Sopenharmony_ci 15062306a36Sopenharmony_ci/* 15162306a36Sopenharmony_ci * When a new UBI volume or UBI device is created, users may either specify the 15262306a36Sopenharmony_ci * volume/device number they want to create or to let UBI automatically assign 15362306a36Sopenharmony_ci * the number using these constants. 15462306a36Sopenharmony_ci */ 15562306a36Sopenharmony_ci#define UBI_VOL_NUM_AUTO (-1) 15662306a36Sopenharmony_ci#define UBI_DEV_NUM_AUTO (-1) 15762306a36Sopenharmony_ci 15862306a36Sopenharmony_ci/* Maximum volume name length */ 15962306a36Sopenharmony_ci#define UBI_MAX_VOLUME_NAME 127 16062306a36Sopenharmony_ci 16162306a36Sopenharmony_ci/* ioctl commands of UBI character devices */ 16262306a36Sopenharmony_ci 16362306a36Sopenharmony_ci#define UBI_IOC_MAGIC 'o' 16462306a36Sopenharmony_ci 16562306a36Sopenharmony_ci/* Create an UBI volume */ 16662306a36Sopenharmony_ci#define UBI_IOCMKVOL _IOW(UBI_IOC_MAGIC, 0, struct ubi_mkvol_req) 16762306a36Sopenharmony_ci/* Remove an UBI volume */ 16862306a36Sopenharmony_ci#define UBI_IOCRMVOL _IOW(UBI_IOC_MAGIC, 1, __s32) 16962306a36Sopenharmony_ci/* Re-size an UBI volume */ 17062306a36Sopenharmony_ci#define UBI_IOCRSVOL _IOW(UBI_IOC_MAGIC, 2, struct ubi_rsvol_req) 17162306a36Sopenharmony_ci/* Re-name volumes */ 17262306a36Sopenharmony_ci#define UBI_IOCRNVOL _IOW(UBI_IOC_MAGIC, 3, struct ubi_rnvol_req) 17362306a36Sopenharmony_ci 17462306a36Sopenharmony_ci/* Read the specified PEB and scrub it if there are bitflips */ 17562306a36Sopenharmony_ci#define UBI_IOCRPEB _IOW(UBI_IOC_MAGIC, 4, __s32) 17662306a36Sopenharmony_ci/* Force scrubbing on the specified PEB */ 17762306a36Sopenharmony_ci#define UBI_IOCSPEB _IOW(UBI_IOC_MAGIC, 5, __s32) 17862306a36Sopenharmony_ci 17962306a36Sopenharmony_ci/* ioctl commands of the UBI control character device */ 18062306a36Sopenharmony_ci 18162306a36Sopenharmony_ci#define UBI_CTRL_IOC_MAGIC 'o' 18262306a36Sopenharmony_ci 18362306a36Sopenharmony_ci/* Attach an MTD device */ 18462306a36Sopenharmony_ci#define UBI_IOCATT _IOW(UBI_CTRL_IOC_MAGIC, 64, struct ubi_attach_req) 18562306a36Sopenharmony_ci/* Detach an MTD device */ 18662306a36Sopenharmony_ci#define UBI_IOCDET _IOW(UBI_CTRL_IOC_MAGIC, 65, __s32) 18762306a36Sopenharmony_ci 18862306a36Sopenharmony_ci/* ioctl commands of UBI volume character devices */ 18962306a36Sopenharmony_ci 19062306a36Sopenharmony_ci#define UBI_VOL_IOC_MAGIC 'O' 19162306a36Sopenharmony_ci 19262306a36Sopenharmony_ci/* Start UBI volume update 19362306a36Sopenharmony_ci * Note: This actually takes a pointer (__s64*), but we can't change 19462306a36Sopenharmony_ci * that without breaking the ABI on 32bit systems 19562306a36Sopenharmony_ci */ 19662306a36Sopenharmony_ci#define UBI_IOCVOLUP _IOW(UBI_VOL_IOC_MAGIC, 0, __s64) 19762306a36Sopenharmony_ci/* LEB erasure command, used for debugging, disabled by default */ 19862306a36Sopenharmony_ci#define UBI_IOCEBER _IOW(UBI_VOL_IOC_MAGIC, 1, __s32) 19962306a36Sopenharmony_ci/* Atomic LEB change command */ 20062306a36Sopenharmony_ci#define UBI_IOCEBCH _IOW(UBI_VOL_IOC_MAGIC, 2, __s32) 20162306a36Sopenharmony_ci/* Map LEB command */ 20262306a36Sopenharmony_ci#define UBI_IOCEBMAP _IOW(UBI_VOL_IOC_MAGIC, 3, struct ubi_map_req) 20362306a36Sopenharmony_ci/* Unmap LEB command */ 20462306a36Sopenharmony_ci#define UBI_IOCEBUNMAP _IOW(UBI_VOL_IOC_MAGIC, 4, __s32) 20562306a36Sopenharmony_ci/* Check if LEB is mapped command */ 20662306a36Sopenharmony_ci#define UBI_IOCEBISMAP _IOR(UBI_VOL_IOC_MAGIC, 5, __s32) 20762306a36Sopenharmony_ci/* Set an UBI volume property */ 20862306a36Sopenharmony_ci#define UBI_IOCSETVOLPROP _IOW(UBI_VOL_IOC_MAGIC, 6, \ 20962306a36Sopenharmony_ci struct ubi_set_vol_prop_req) 21062306a36Sopenharmony_ci/* Create a R/O block device on top of an UBI volume */ 21162306a36Sopenharmony_ci#define UBI_IOCVOLCRBLK _IOW(UBI_VOL_IOC_MAGIC, 7, struct ubi_blkcreate_req) 21262306a36Sopenharmony_ci/* Remove the R/O block device */ 21362306a36Sopenharmony_ci#define UBI_IOCVOLRMBLK _IO(UBI_VOL_IOC_MAGIC, 8) 21462306a36Sopenharmony_ci 21562306a36Sopenharmony_ci/* Maximum MTD device name length supported by UBI */ 21662306a36Sopenharmony_ci#define MAX_UBI_MTD_NAME_LEN 127 21762306a36Sopenharmony_ci 21862306a36Sopenharmony_ci/* Maximum amount of UBI volumes that can be re-named at one go */ 21962306a36Sopenharmony_ci#define UBI_MAX_RNVOL 32 22062306a36Sopenharmony_ci 22162306a36Sopenharmony_ci/* 22262306a36Sopenharmony_ci * UBI volume type constants. 22362306a36Sopenharmony_ci * 22462306a36Sopenharmony_ci * @UBI_DYNAMIC_VOLUME: dynamic volume 22562306a36Sopenharmony_ci * @UBI_STATIC_VOLUME: static volume 22662306a36Sopenharmony_ci */ 22762306a36Sopenharmony_cienum { 22862306a36Sopenharmony_ci UBI_DYNAMIC_VOLUME = 3, 22962306a36Sopenharmony_ci UBI_STATIC_VOLUME = 4, 23062306a36Sopenharmony_ci}; 23162306a36Sopenharmony_ci 23262306a36Sopenharmony_ci/* 23362306a36Sopenharmony_ci * UBI set volume property ioctl constants. 23462306a36Sopenharmony_ci * 23562306a36Sopenharmony_ci * @UBI_VOL_PROP_DIRECT_WRITE: allow (any non-zero value) or disallow (value 0) 23662306a36Sopenharmony_ci * user to directly write and erase individual 23762306a36Sopenharmony_ci * eraseblocks on dynamic volumes 23862306a36Sopenharmony_ci */ 23962306a36Sopenharmony_cienum { 24062306a36Sopenharmony_ci UBI_VOL_PROP_DIRECT_WRITE = 1, 24162306a36Sopenharmony_ci}; 24262306a36Sopenharmony_ci 24362306a36Sopenharmony_ci/** 24462306a36Sopenharmony_ci * struct ubi_attach_req - attach MTD device request. 24562306a36Sopenharmony_ci * @ubi_num: UBI device number to create 24662306a36Sopenharmony_ci * @mtd_num: MTD device number to attach 24762306a36Sopenharmony_ci * @vid_hdr_offset: VID header offset (use defaults if %0) 24862306a36Sopenharmony_ci * @max_beb_per1024: maximum expected number of bad PEB per 1024 PEBs 24962306a36Sopenharmony_ci * @padding: reserved for future, not used, has to be zeroed 25062306a36Sopenharmony_ci * @disable_fm: whether disable fastmap 25162306a36Sopenharmony_ci * 25262306a36Sopenharmony_ci * This data structure is used to specify MTD device UBI has to attach and the 25362306a36Sopenharmony_ci * parameters it has to use. The number which should be assigned to the new UBI 25462306a36Sopenharmony_ci * device is passed in @ubi_num. UBI may automatically assign the number if 25562306a36Sopenharmony_ci * @UBI_DEV_NUM_AUTO is passed. In this case, the device number is returned in 25662306a36Sopenharmony_ci * @ubi_num. 25762306a36Sopenharmony_ci * 25862306a36Sopenharmony_ci * Most applications should pass %0 in @vid_hdr_offset to make UBI use default 25962306a36Sopenharmony_ci * offset of the VID header within physical eraseblocks. The default offset is 26062306a36Sopenharmony_ci * the next min. I/O unit after the EC header. For example, it will be offset 26162306a36Sopenharmony_ci * 512 in case of a 512 bytes page NAND flash with no sub-page support. Or 26262306a36Sopenharmony_ci * it will be 512 in case of a 2KiB page NAND flash with 4 512-byte sub-pages. 26362306a36Sopenharmony_ci * 26462306a36Sopenharmony_ci * But in rare cases, if this optimizes things, the VID header may be placed to 26562306a36Sopenharmony_ci * a different offset. For example, the boot-loader might do things faster if 26662306a36Sopenharmony_ci * the VID header sits at the end of the first 2KiB NAND page with 4 sub-pages. 26762306a36Sopenharmony_ci * As the boot-loader would not normally need to read EC headers (unless it 26862306a36Sopenharmony_ci * needs UBI in RW mode), it might be faster to calculate ECC. This is weird 26962306a36Sopenharmony_ci * example, but it real-life example. So, in this example, @vid_hdr_offer would 27062306a36Sopenharmony_ci * be 2KiB-64 bytes = 1984. Note, that this position is not even 512-bytes 27162306a36Sopenharmony_ci * aligned, which is OK, as UBI is clever enough to realize this is 4th 27262306a36Sopenharmony_ci * sub-page of the first page and add needed padding. 27362306a36Sopenharmony_ci * 27462306a36Sopenharmony_ci * The @max_beb_per1024 is the maximum amount of bad PEBs UBI expects on the 27562306a36Sopenharmony_ci * UBI device per 1024 eraseblocks. This value is often given in an other form 27662306a36Sopenharmony_ci * in the NAND datasheet (min NVB i.e. minimal number of valid blocks). The 27762306a36Sopenharmony_ci * maximum expected bad eraseblocks per 1024 is then: 27862306a36Sopenharmony_ci * 1024 * (1 - MinNVB / MaxNVB) 27962306a36Sopenharmony_ci * Which gives 20 for most NAND devices. This limit is used in order to derive 28062306a36Sopenharmony_ci * amount of eraseblock UBI reserves for handling new bad blocks. If the device 28162306a36Sopenharmony_ci * has more bad eraseblocks than this limit, UBI does not reserve any physical 28262306a36Sopenharmony_ci * eraseblocks for new bad eraseblocks, but attempts to use available 28362306a36Sopenharmony_ci * eraseblocks (if any). The accepted range is 0-768. If 0 is given, the 28462306a36Sopenharmony_ci * default kernel value of %CONFIG_MTD_UBI_BEB_LIMIT will be used. 28562306a36Sopenharmony_ci * 28662306a36Sopenharmony_ci * If @disable_fm is not zero, ubi doesn't create new fastmap even the module 28762306a36Sopenharmony_ci * param 'fm_autoconvert' is set, and existed old fastmap will be destroyed 28862306a36Sopenharmony_ci * after doing full scanning. 28962306a36Sopenharmony_ci */ 29062306a36Sopenharmony_cistruct ubi_attach_req { 29162306a36Sopenharmony_ci __s32 ubi_num; 29262306a36Sopenharmony_ci __s32 mtd_num; 29362306a36Sopenharmony_ci __s32 vid_hdr_offset; 29462306a36Sopenharmony_ci __s16 max_beb_per1024; 29562306a36Sopenharmony_ci __s8 disable_fm; 29662306a36Sopenharmony_ci __s8 padding[9]; 29762306a36Sopenharmony_ci}; 29862306a36Sopenharmony_ci 29962306a36Sopenharmony_ci/* 30062306a36Sopenharmony_ci * UBI volume flags. 30162306a36Sopenharmony_ci * 30262306a36Sopenharmony_ci * @UBI_VOL_SKIP_CRC_CHECK_FLG: skip the CRC check done on a static volume at 30362306a36Sopenharmony_ci * open time. Only valid for static volumes and 30462306a36Sopenharmony_ci * should only be used if the volume user has a 30562306a36Sopenharmony_ci * way to verify data integrity 30662306a36Sopenharmony_ci */ 30762306a36Sopenharmony_cienum { 30862306a36Sopenharmony_ci UBI_VOL_SKIP_CRC_CHECK_FLG = 0x1, 30962306a36Sopenharmony_ci}; 31062306a36Sopenharmony_ci 31162306a36Sopenharmony_ci#define UBI_VOL_VALID_FLGS (UBI_VOL_SKIP_CRC_CHECK_FLG) 31262306a36Sopenharmony_ci 31362306a36Sopenharmony_ci/** 31462306a36Sopenharmony_ci * struct ubi_mkvol_req - volume description data structure used in 31562306a36Sopenharmony_ci * volume creation requests. 31662306a36Sopenharmony_ci * @vol_id: volume number 31762306a36Sopenharmony_ci * @alignment: volume alignment 31862306a36Sopenharmony_ci * @bytes: volume size in bytes 31962306a36Sopenharmony_ci * @vol_type: volume type (%UBI_DYNAMIC_VOLUME or %UBI_STATIC_VOLUME) 32062306a36Sopenharmony_ci * @flags: volume flags (%UBI_VOL_SKIP_CRC_CHECK_FLG) 32162306a36Sopenharmony_ci * @name_len: volume name length 32262306a36Sopenharmony_ci * @padding2: reserved for future, not used, has to be zeroed 32362306a36Sopenharmony_ci * @name: volume name 32462306a36Sopenharmony_ci * 32562306a36Sopenharmony_ci * This structure is used by user-space programs when creating new volumes. The 32662306a36Sopenharmony_ci * @used_bytes field is only necessary when creating static volumes. 32762306a36Sopenharmony_ci * 32862306a36Sopenharmony_ci * The @alignment field specifies the required alignment of the volume logical 32962306a36Sopenharmony_ci * eraseblock. This means, that the size of logical eraseblocks will be aligned 33062306a36Sopenharmony_ci * to this number, i.e., 33162306a36Sopenharmony_ci * (UBI device logical eraseblock size) mod (@alignment) = 0. 33262306a36Sopenharmony_ci * 33362306a36Sopenharmony_ci * To put it differently, the logical eraseblock of this volume may be slightly 33462306a36Sopenharmony_ci * shortened in order to make it properly aligned. The alignment has to be 33562306a36Sopenharmony_ci * multiple of the flash minimal input/output unit, or %1 to utilize the entire 33662306a36Sopenharmony_ci * available space of logical eraseblocks. 33762306a36Sopenharmony_ci * 33862306a36Sopenharmony_ci * The @alignment field may be useful, for example, when one wants to maintain 33962306a36Sopenharmony_ci * a block device on top of an UBI volume. In this case, it is desirable to fit 34062306a36Sopenharmony_ci * an integer number of blocks in logical eraseblocks of this UBI volume. With 34162306a36Sopenharmony_ci * alignment it is possible to update this volume using plane UBI volume image 34262306a36Sopenharmony_ci * BLOBs, without caring about how to properly align them. 34362306a36Sopenharmony_ci */ 34462306a36Sopenharmony_cistruct ubi_mkvol_req { 34562306a36Sopenharmony_ci __s32 vol_id; 34662306a36Sopenharmony_ci __s32 alignment; 34762306a36Sopenharmony_ci __s64 bytes; 34862306a36Sopenharmony_ci __s8 vol_type; 34962306a36Sopenharmony_ci __u8 flags; 35062306a36Sopenharmony_ci __s16 name_len; 35162306a36Sopenharmony_ci __s8 padding2[4]; 35262306a36Sopenharmony_ci char name[UBI_MAX_VOLUME_NAME + 1]; 35362306a36Sopenharmony_ci} __packed; 35462306a36Sopenharmony_ci 35562306a36Sopenharmony_ci/** 35662306a36Sopenharmony_ci * struct ubi_rsvol_req - a data structure used in volume re-size requests. 35762306a36Sopenharmony_ci * @vol_id: ID of the volume to re-size 35862306a36Sopenharmony_ci * @bytes: new size of the volume in bytes 35962306a36Sopenharmony_ci * 36062306a36Sopenharmony_ci * Re-sizing is possible for both dynamic and static volumes. But while dynamic 36162306a36Sopenharmony_ci * volumes may be re-sized arbitrarily, static volumes cannot be made to be 36262306a36Sopenharmony_ci * smaller than the number of bytes they bear. To arbitrarily shrink a static 36362306a36Sopenharmony_ci * volume, it must be wiped out first (by means of volume update operation with 36462306a36Sopenharmony_ci * zero number of bytes). 36562306a36Sopenharmony_ci */ 36662306a36Sopenharmony_cistruct ubi_rsvol_req { 36762306a36Sopenharmony_ci __s64 bytes; 36862306a36Sopenharmony_ci __s32 vol_id; 36962306a36Sopenharmony_ci} __packed; 37062306a36Sopenharmony_ci 37162306a36Sopenharmony_ci/** 37262306a36Sopenharmony_ci * struct ubi_rnvol_req - volumes re-name request. 37362306a36Sopenharmony_ci * @count: count of volumes to re-name 37462306a36Sopenharmony_ci * @padding1: reserved for future, not used, has to be zeroed 37562306a36Sopenharmony_ci * @vol_id: ID of the volume to re-name 37662306a36Sopenharmony_ci * @name_len: name length 37762306a36Sopenharmony_ci * @padding2: reserved for future, not used, has to be zeroed 37862306a36Sopenharmony_ci * @name: new volume name 37962306a36Sopenharmony_ci * 38062306a36Sopenharmony_ci * UBI allows to re-name up to %32 volumes at one go. The count of volumes to 38162306a36Sopenharmony_ci * re-name is specified in the @count field. The ID of the volumes to re-name 38262306a36Sopenharmony_ci * and the new names are specified in the @vol_id and @name fields. 38362306a36Sopenharmony_ci * 38462306a36Sopenharmony_ci * The UBI volume re-name operation is atomic, which means that should power cut 38562306a36Sopenharmony_ci * happen, the volumes will have either old name or new name. So the possible 38662306a36Sopenharmony_ci * use-cases of this command is atomic upgrade. Indeed, to upgrade, say, volumes 38762306a36Sopenharmony_ci * A and B one may create temporary volumes %A1 and %B1 with the new contents, 38862306a36Sopenharmony_ci * then atomically re-name A1->A and B1->B, in which case old %A and %B will 38962306a36Sopenharmony_ci * be removed. 39062306a36Sopenharmony_ci * 39162306a36Sopenharmony_ci * If it is not desirable to remove old A and B, the re-name request has to 39262306a36Sopenharmony_ci * contain 4 entries: A1->A, A->A1, B1->B, B->B1, in which case old A1 and B1 39362306a36Sopenharmony_ci * become A and B, and old A and B will become A1 and B1. 39462306a36Sopenharmony_ci * 39562306a36Sopenharmony_ci * It is also OK to request: A1->A, A1->X, B1->B, B->Y, in which case old A1 39662306a36Sopenharmony_ci * and B1 become A and B, and old A and B become X and Y. 39762306a36Sopenharmony_ci * 39862306a36Sopenharmony_ci * In other words, in case of re-naming into an existing volume name, the 39962306a36Sopenharmony_ci * existing volume is removed, unless it is re-named as well at the same 40062306a36Sopenharmony_ci * re-name request. 40162306a36Sopenharmony_ci */ 40262306a36Sopenharmony_cistruct ubi_rnvol_req { 40362306a36Sopenharmony_ci __s32 count; 40462306a36Sopenharmony_ci __s8 padding1[12]; 40562306a36Sopenharmony_ci struct { 40662306a36Sopenharmony_ci __s32 vol_id; 40762306a36Sopenharmony_ci __s16 name_len; 40862306a36Sopenharmony_ci __s8 padding2[2]; 40962306a36Sopenharmony_ci char name[UBI_MAX_VOLUME_NAME + 1]; 41062306a36Sopenharmony_ci } ents[UBI_MAX_RNVOL]; 41162306a36Sopenharmony_ci} __packed; 41262306a36Sopenharmony_ci 41362306a36Sopenharmony_ci/** 41462306a36Sopenharmony_ci * struct ubi_leb_change_req - a data structure used in atomic LEB change 41562306a36Sopenharmony_ci * requests. 41662306a36Sopenharmony_ci * @lnum: logical eraseblock number to change 41762306a36Sopenharmony_ci * @bytes: how many bytes will be written to the logical eraseblock 41862306a36Sopenharmony_ci * @dtype: pass "3" for better compatibility with old kernels 41962306a36Sopenharmony_ci * @padding: reserved for future, not used, has to be zeroed 42062306a36Sopenharmony_ci * 42162306a36Sopenharmony_ci * The @dtype field used to inform UBI about what kind of data will be written 42262306a36Sopenharmony_ci * to the LEB: long term (value 1), short term (value 2), unknown (value 3). 42362306a36Sopenharmony_ci * UBI tried to pick a PEB with lower erase counter for short term data and a 42462306a36Sopenharmony_ci * PEB with higher erase counter for long term data. But this was not really 42562306a36Sopenharmony_ci * used because users usually do not know this and could easily mislead UBI. We 42662306a36Sopenharmony_ci * removed this feature in May 2012. UBI currently just ignores the @dtype 42762306a36Sopenharmony_ci * field. But for better compatibility with older kernels it is recommended to 42862306a36Sopenharmony_ci * set @dtype to 3 (unknown). 42962306a36Sopenharmony_ci */ 43062306a36Sopenharmony_cistruct ubi_leb_change_req { 43162306a36Sopenharmony_ci __s32 lnum; 43262306a36Sopenharmony_ci __s32 bytes; 43362306a36Sopenharmony_ci __s8 dtype; /* obsolete, do not use! */ 43462306a36Sopenharmony_ci __s8 padding[7]; 43562306a36Sopenharmony_ci} __packed; 43662306a36Sopenharmony_ci 43762306a36Sopenharmony_ci/** 43862306a36Sopenharmony_ci * struct ubi_map_req - a data structure used in map LEB requests. 43962306a36Sopenharmony_ci * @dtype: pass "3" for better compatibility with old kernels 44062306a36Sopenharmony_ci * @lnum: logical eraseblock number to unmap 44162306a36Sopenharmony_ci * @padding: reserved for future, not used, has to be zeroed 44262306a36Sopenharmony_ci */ 44362306a36Sopenharmony_cistruct ubi_map_req { 44462306a36Sopenharmony_ci __s32 lnum; 44562306a36Sopenharmony_ci __s8 dtype; /* obsolete, do not use! */ 44662306a36Sopenharmony_ci __s8 padding[3]; 44762306a36Sopenharmony_ci} __packed; 44862306a36Sopenharmony_ci 44962306a36Sopenharmony_ci 45062306a36Sopenharmony_ci/** 45162306a36Sopenharmony_ci * struct ubi_set_vol_prop_req - a data structure used to set an UBI volume 45262306a36Sopenharmony_ci * property. 45362306a36Sopenharmony_ci * @property: property to set (%UBI_VOL_PROP_DIRECT_WRITE) 45462306a36Sopenharmony_ci * @padding: reserved for future, not used, has to be zeroed 45562306a36Sopenharmony_ci * @value: value to set 45662306a36Sopenharmony_ci */ 45762306a36Sopenharmony_cistruct ubi_set_vol_prop_req { 45862306a36Sopenharmony_ci __u8 property; 45962306a36Sopenharmony_ci __u8 padding[7]; 46062306a36Sopenharmony_ci __u64 value; 46162306a36Sopenharmony_ci} __packed; 46262306a36Sopenharmony_ci 46362306a36Sopenharmony_ci/** 46462306a36Sopenharmony_ci * struct ubi_blkcreate_req - a data structure used in block creation requests. 46562306a36Sopenharmony_ci * @padding: reserved for future, not used, has to be zeroed 46662306a36Sopenharmony_ci */ 46762306a36Sopenharmony_cistruct ubi_blkcreate_req { 46862306a36Sopenharmony_ci __s8 padding[128]; 46962306a36Sopenharmony_ci} __packed; 47062306a36Sopenharmony_ci 47162306a36Sopenharmony_ci#endif /* __UBI_USER_H__ */ 472