/*1* Copyright © International Business Machines Corp., 20062*3* This program is free software; you can redistribute it and/or modify4* it under the terms of the GNU General Public License as published by5* the Free Software Foundation; either version 2 of the License, or6* (at your option) any later version.7*8* This program is distributed in the hope that it will be useful,9* but WITHOUT ANY WARRANTY; without even the implied warranty of10* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See11* the GNU General Public License for more details.12*13* You should have received a copy of the GNU General Public License14* along with this program; if not, write to the Free Software15* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA16*17* Author: Artem Bityutskiy (Битюцкий Артём)18*/1920#ifndef __UBI_USER_H__21#define __UBI_USER_H__2223#include <linux/types.h>2425/*26* UBI device creation (the same as MTD device attachment)27* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~28*29* MTD devices may be attached using %UBI_IOCATT ioctl command of the UBI30* control device. The caller has to properly fill and pass31* &struct ubi_attach_req object - UBI will attach the MTD device specified in32* the request and return the newly created UBI device number as the ioctl33* return value.34*35* UBI device deletion (the same as MTD device detachment)36* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~37*38* An UBI device maybe deleted with %UBI_IOCDET ioctl command of the UBI39* control device.40*41* UBI volume creation42* ~~~~~~~~~~~~~~~~~~~43*44* UBI volumes are created via the %UBI_IOCMKVOL ioctl command of UBI character45* device. A &struct ubi_mkvol_req object has to be properly filled and a46* pointer to it has to be passed to the ioctl.47*48* UBI volume deletion49* ~~~~~~~~~~~~~~~~~~~50*51* To delete a volume, the %UBI_IOCRMVOL ioctl command of the UBI character52* device should be used. A pointer to the 32-bit volume ID hast to be passed53* to the ioctl.54*55* UBI volume re-size56* ~~~~~~~~~~~~~~~~~~57*58* To re-size a volume, the %UBI_IOCRSVOL ioctl command of the UBI character59* device should be used. A &struct ubi_rsvol_req object has to be properly60* filled and a pointer to it has to be passed to the ioctl.61*62* UBI volumes re-name63* ~~~~~~~~~~~~~~~~~~~64*65* To re-name several volumes atomically at one go, the %UBI_IOCRNVOL command66* of the UBI character device should be used. A &struct ubi_rnvol_req object67* has to be properly filled and a pointer to it has to be passed to the ioctl.68*69* UBI volume update70* ~~~~~~~~~~~~~~~~~71*72* Volume update should be done via the %UBI_IOCVOLUP ioctl command of the73* corresponding UBI volume character device. A pointer to a 64-bit update74* size should be passed to the ioctl. After this, UBI expects user to write75* this number of bytes to the volume character device. The update is finished76* when the claimed number of bytes is passed. So, the volume update sequence77* is something like:78*79* fd = open("/dev/my_volume");80* ioctl(fd, UBI_IOCVOLUP, &image_size);81* write(fd, buf, image_size);82* close(fd);83*84* Logical eraseblock erase85* ~~~~~~~~~~~~~~~~~~~~~~~~86*87* To erase a logical eraseblock, the %UBI_IOCEBER ioctl command of the88* corresponding UBI volume character device should be used. This command89* unmaps the requested logical eraseblock, makes sure the corresponding90* physical eraseblock is successfully erased, and returns.91*92* Atomic logical eraseblock change93* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~94*95* Atomic logical eraseblock change operation is called using the %UBI_IOCEBCH96* ioctl command of the corresponding UBI volume character device. A pointer to97* a &struct ubi_leb_change_req object has to be passed to the ioctl. Then the98* user is expected to write the requested amount of bytes (similarly to what99* should be done in case of the "volume update" ioctl).100*101* Logical eraseblock map102* ~~~~~~~~~~~~~~~~~~~~~103*104* To map a logical eraseblock to a physical eraseblock, the %UBI_IOCEBMAP105* ioctl command should be used. A pointer to a &struct ubi_map_req object is106* expected to be passed. The ioctl maps the requested logical eraseblock to107* a physical eraseblock and returns. Only non-mapped logical eraseblocks can108* be mapped. If the logical eraseblock specified in the request is already109* mapped to a physical eraseblock, the ioctl fails and returns error.110*111* Logical eraseblock unmap112* ~~~~~~~~~~~~~~~~~~~~~~~~113*114* To unmap a logical eraseblock to a physical eraseblock, the %UBI_IOCEBUNMAP115* ioctl command should be used. The ioctl unmaps the logical eraseblocks,116* schedules corresponding physical eraseblock for erasure, and returns. Unlike117* the "LEB erase" command, it does not wait for the physical eraseblock being118* erased. Note, the side effect of this is that if an unclean reboot happens119* after the unmap ioctl returns, you may find the LEB mapped again to the same120* physical eraseblock after the UBI is run again.121*122* Check if logical eraseblock is mapped123* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~124*125* To check if a logical eraseblock is mapped to a physical eraseblock, the126* %UBI_IOCEBISMAP ioctl command should be used. It returns %0 if the LEB is127* not mapped, and %1 if it is mapped.128*129* Set an UBI volume property130* ~~~~~~~~~~~~~~~~~~~~~~~~~131*132* To set an UBI volume property the %UBI_IOCSETPROP ioctl command should be133* used. A pointer to a &struct ubi_set_vol_prop_req object is expected to be134* passed. The object describes which property should be set, and to which value135* it should be set.136*/137138/*139* When a new UBI volume or UBI device is created, users may either specify the140* volume/device number they want to create or to let UBI automatically assign141* the number using these constants.142*/143#define UBI_VOL_NUM_AUTO (-1)144#define UBI_DEV_NUM_AUTO (-1)145146/* Maximum volume name length */147#define UBI_MAX_VOLUME_NAME 127148149/* ioctl commands of UBI character devices */150151#define UBI_IOC_MAGIC 'o'152153/* Create an UBI volume */154#define UBI_IOCMKVOL _IOW(UBI_IOC_MAGIC, 0, struct ubi_mkvol_req)155/* Remove an UBI volume */156#define UBI_IOCRMVOL _IOW(UBI_IOC_MAGIC, 1, __s32)157/* Re-size an UBI volume */158#define UBI_IOCRSVOL _IOW(UBI_IOC_MAGIC, 2, struct ubi_rsvol_req)159/* Re-name volumes */160#define UBI_IOCRNVOL _IOW(UBI_IOC_MAGIC, 3, struct ubi_rnvol_req)161162/* ioctl commands of the UBI control character device */163164#define UBI_CTRL_IOC_MAGIC 'o'165166/* Attach an MTD device */167#define UBI_IOCATT _IOW(UBI_CTRL_IOC_MAGIC, 64, struct ubi_attach_req)168/* Detach an MTD device */169#define UBI_IOCDET _IOW(UBI_CTRL_IOC_MAGIC, 65, __s32)170171/* ioctl commands of UBI volume character devices */172173#define UBI_VOL_IOC_MAGIC 'O'174175/* Start UBI volume update */176#define UBI_IOCVOLUP _IOW(UBI_VOL_IOC_MAGIC, 0, __s64)177/* LEB erasure command, used for debugging, disabled by default */178#define UBI_IOCEBER _IOW(UBI_VOL_IOC_MAGIC, 1, __s32)179/* Atomic LEB change command */180#define UBI_IOCEBCH _IOW(UBI_VOL_IOC_MAGIC, 2, __s32)181/* Map LEB command */182#define UBI_IOCEBMAP _IOW(UBI_VOL_IOC_MAGIC, 3, struct ubi_map_req)183/* Unmap LEB command */184#define UBI_IOCEBUNMAP _IOW(UBI_VOL_IOC_MAGIC, 4, __s32)185/* Check if LEB is mapped command */186#define UBI_IOCEBISMAP _IOR(UBI_VOL_IOC_MAGIC, 5, __s32)187/* Set an UBI volume property */188#define UBI_IOCSETVOLPROP _IOW(UBI_VOL_IOC_MAGIC, 6, \189struct ubi_set_vol_prop_req)190191/* Maximum MTD device name length supported by UBI */192#define MAX_UBI_MTD_NAME_LEN 127193194/* Maximum amount of UBI volumes that can be re-named at one go */195#define UBI_MAX_RNVOL 32196197/*198* UBI data type hint constants.199*200* UBI_LONGTERM: long-term data201* UBI_SHORTTERM: short-term data202* UBI_UNKNOWN: data persistence is unknown203*204* These constants are used when data is written to UBI volumes in order to205* help the UBI wear-leveling unit to find more appropriate physical206* eraseblocks.207*/208enum {209UBI_LONGTERM = 1,210UBI_SHORTTERM = 2,211UBI_UNKNOWN = 3,212};213214/*215* UBI volume type constants.216*217* @UBI_DYNAMIC_VOLUME: dynamic volume218* @UBI_STATIC_VOLUME: static volume219*/220enum {221UBI_DYNAMIC_VOLUME = 3,222UBI_STATIC_VOLUME = 4,223};224225/*226* UBI set volume property ioctl constants.227*228* @UBI_VOL_PROP_DIRECT_WRITE: allow (any non-zero value) or disallow (value 0)229* user to directly write and erase individual230* eraseblocks on dynamic volumes231*/232enum {233UBI_VOL_PROP_DIRECT_WRITE = 1,234};235236/**237* struct ubi_attach_req - attach MTD device request.238* @ubi_num: UBI device number to create239* @mtd_num: MTD device number to attach240* @vid_hdr_offset: VID header offset (use defaults if %0)241* @padding: reserved for future, not used, has to be zeroed242*243* This data structure is used to specify MTD device UBI has to attach and the244* parameters it has to use. The number which should be assigned to the new UBI245* device is passed in @ubi_num. UBI may automatically assign the number if246* @UBI_DEV_NUM_AUTO is passed. In this case, the device number is returned in247* @ubi_num.248*249* Most applications should pass %0 in @vid_hdr_offset to make UBI use default250* offset of the VID header within physical eraseblocks. The default offset is251* the next min. I/O unit after the EC header. For example, it will be offset252* 512 in case of a 512 bytes page NAND flash with no sub-page support. Or253* it will be 512 in case of a 2KiB page NAND flash with 4 512-byte sub-pages.254*255* But in rare cases, if this optimizes things, the VID header may be placed to256* a different offset. For example, the boot-loader might do things faster if257* the VID header sits at the end of the first 2KiB NAND page with 4 sub-pages.258* As the boot-loader would not normally need to read EC headers (unless it259* needs UBI in RW mode), it might be faster to calculate ECC. This is weird260* example, but it real-life example. So, in this example, @vid_hdr_offer would261* be 2KiB-64 bytes = 1984. Note, that this position is not even 512-bytes262* aligned, which is OK, as UBI is clever enough to realize this is 4th263* sub-page of the first page and add needed padding.264*/265struct ubi_attach_req {266__s32 ubi_num;267__s32 mtd_num;268__s32 vid_hdr_offset;269__s8 padding[12];270};271272/**273* struct ubi_mkvol_req - volume description data structure used in274* volume creation requests.275* @vol_id: volume number276* @alignment: volume alignment277* @bytes: volume size in bytes278* @vol_type: volume type (%UBI_DYNAMIC_VOLUME or %UBI_STATIC_VOLUME)279* @padding1: reserved for future, not used, has to be zeroed280* @name_len: volume name length281* @padding2: reserved for future, not used, has to be zeroed282* @name: volume name283*284* This structure is used by user-space programs when creating new volumes. The285* @used_bytes field is only necessary when creating static volumes.286*287* The @alignment field specifies the required alignment of the volume logical288* eraseblock. This means, that the size of logical eraseblocks will be aligned289* to this number, i.e.,290* (UBI device logical eraseblock size) mod (@alignment) = 0.291*292* To put it differently, the logical eraseblock of this volume may be slightly293* shortened in order to make it properly aligned. The alignment has to be294* multiple of the flash minimal input/output unit, or %1 to utilize the entire295* available space of logical eraseblocks.296*297* The @alignment field may be useful, for example, when one wants to maintain298* a block device on top of an UBI volume. In this case, it is desirable to fit299* an integer number of blocks in logical eraseblocks of this UBI volume. With300* alignment it is possible to update this volume using plane UBI volume image301* BLOBs, without caring about how to properly align them.302*/303struct ubi_mkvol_req {304__s32 vol_id;305__s32 alignment;306__s64 bytes;307__s8 vol_type;308__s8 padding1;309__s16 name_len;310__s8 padding2[4];311char name[UBI_MAX_VOLUME_NAME + 1];312} __packed;313314/**315* struct ubi_rsvol_req - a data structure used in volume re-size requests.316* @vol_id: ID of the volume to re-size317* @bytes: new size of the volume in bytes318*319* Re-sizing is possible for both dynamic and static volumes. But while dynamic320* volumes may be re-sized arbitrarily, static volumes cannot be made to be321* smaller than the number of bytes they bear. To arbitrarily shrink a static322* volume, it must be wiped out first (by means of volume update operation with323* zero number of bytes).324*/325struct ubi_rsvol_req {326__s64 bytes;327__s32 vol_id;328} __packed;329330/**331* struct ubi_rnvol_req - volumes re-name request.332* @count: count of volumes to re-name333* @padding1: reserved for future, not used, has to be zeroed334* @vol_id: ID of the volume to re-name335* @name_len: name length336* @padding2: reserved for future, not used, has to be zeroed337* @name: new volume name338*339* UBI allows to re-name up to %32 volumes at one go. The count of volumes to340* re-name is specified in the @count field. The ID of the volumes to re-name341* and the new names are specified in the @vol_id and @name fields.342*343* The UBI volume re-name operation is atomic, which means that should power cut344* happen, the volumes will have either old name or new name. So the possible345* use-cases of this command is atomic upgrade. Indeed, to upgrade, say, volumes346* A and B one may create temporary volumes %A1 and %B1 with the new contents,347* then atomically re-name A1->A and B1->B, in which case old %A and %B will348* be removed.349*350* If it is not desirable to remove old A and B, the re-name request has to351* contain 4 entries: A1->A, A->A1, B1->B, B->B1, in which case old A1 and B1352* become A and B, and old A and B will become A1 and B1.353*354* It is also OK to request: A1->A, A1->X, B1->B, B->Y, in which case old A1355* and B1 become A and B, and old A and B become X and Y.356*357* In other words, in case of re-naming into an existing volume name, the358* existing volume is removed, unless it is re-named as well at the same359* re-name request.360*/361struct ubi_rnvol_req {362__s32 count;363__s8 padding1[12];364struct {365__s32 vol_id;366__s16 name_len;367__s8 padding2[2];368char name[UBI_MAX_VOLUME_NAME + 1];369} ents[UBI_MAX_RNVOL];370} __packed;371372/**373* struct ubi_leb_change_req - a data structure used in atomic LEB change374* requests.375* @lnum: logical eraseblock number to change376* @bytes: how many bytes will be written to the logical eraseblock377* @dtype: data type (%UBI_LONGTERM, %UBI_SHORTTERM, %UBI_UNKNOWN)378* @padding: reserved for future, not used, has to be zeroed379*/380struct ubi_leb_change_req {381__s32 lnum;382__s32 bytes;383__s8 dtype;384__s8 padding[7];385} __packed;386387/**388* struct ubi_map_req - a data structure used in map LEB requests.389* @lnum: logical eraseblock number to unmap390* @dtype: data type (%UBI_LONGTERM, %UBI_SHORTTERM, %UBI_UNKNOWN)391* @padding: reserved for future, not used, has to be zeroed392*/393struct ubi_map_req {394__s32 lnum;395__s8 dtype;396__s8 padding[3];397} __packed;398399400/**401* struct ubi_set_vol_prop_req - a data structure used to set an UBI volume402* property.403* @property: property to set (%UBI_VOL_PROP_DIRECT_WRITE)404* @padding: reserved for future, not used, has to be zeroed405* @value: value to set406*/407struct ubi_set_vol_prop_req {408__u8 property;409__u8 padding[7];410__u64 value;411} __packed;412413#endif /* __UBI_USER_H__ */414415416