18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright © International Business Machines Corp., 2006
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * This program is free software; you can redistribute it and/or modify
68c2ecf20Sopenharmony_ci * it under the terms of the GNU General Public License as published by
78c2ecf20Sopenharmony_ci * the Free Software Foundation; either version 2 of the License, or
88c2ecf20Sopenharmony_ci * (at your option) any later version.
98c2ecf20Sopenharmony_ci *
108c2ecf20Sopenharmony_ci * This program is distributed in the hope that it will be useful,
118c2ecf20Sopenharmony_ci * but WITHOUT ANY WARRANTY; without even the implied warranty of
128c2ecf20Sopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
138c2ecf20Sopenharmony_ci * the GNU General Public License for more details.
148c2ecf20Sopenharmony_ci *
158c2ecf20Sopenharmony_ci * You should have received a copy of the GNU General Public License
168c2ecf20Sopenharmony_ci * along with this program; if not, write to the Free Software
178c2ecf20Sopenharmony_ci * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
188c2ecf20Sopenharmony_ci *
198c2ecf20Sopenharmony_ci * Author: Artem Bityutskiy (Битюцкий Артём)
208c2ecf20Sopenharmony_ci */
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ci#ifndef __UBI_USER_H__
238c2ecf20Sopenharmony_ci#define __UBI_USER_H__
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ci#include <linux/types.h>
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ci/*
288c2ecf20Sopenharmony_ci * UBI device creation (the same as MTD device attachment)
298c2ecf20Sopenharmony_ci * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
308c2ecf20Sopenharmony_ci *
318c2ecf20Sopenharmony_ci * MTD devices may be attached using %UBI_IOCATT ioctl command of the UBI
328c2ecf20Sopenharmony_ci * control device. The caller has to properly fill and pass
338c2ecf20Sopenharmony_ci * &struct ubi_attach_req object - UBI will attach the MTD device specified in
348c2ecf20Sopenharmony_ci * the request and return the newly created UBI device number as the ioctl
358c2ecf20Sopenharmony_ci * return value.
368c2ecf20Sopenharmony_ci *
378c2ecf20Sopenharmony_ci * UBI device deletion (the same as MTD device detachment)
388c2ecf20Sopenharmony_ci * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
398c2ecf20Sopenharmony_ci *
408c2ecf20Sopenharmony_ci * An UBI device maybe deleted with %UBI_IOCDET ioctl command of the UBI
418c2ecf20Sopenharmony_ci * control device.
428c2ecf20Sopenharmony_ci *
438c2ecf20Sopenharmony_ci * UBI volume creation
448c2ecf20Sopenharmony_ci * ~~~~~~~~~~~~~~~~~~~
458c2ecf20Sopenharmony_ci *
468c2ecf20Sopenharmony_ci * UBI volumes are created via the %UBI_IOCMKVOL ioctl command of UBI character
478c2ecf20Sopenharmony_ci * device. A &struct ubi_mkvol_req object has to be properly filled and a
488c2ecf20Sopenharmony_ci * pointer to it has to be passed to the ioctl.
498c2ecf20Sopenharmony_ci *
508c2ecf20Sopenharmony_ci * UBI volume deletion
518c2ecf20Sopenharmony_ci * ~~~~~~~~~~~~~~~~~~~
528c2ecf20Sopenharmony_ci *
538c2ecf20Sopenharmony_ci * To delete a volume, the %UBI_IOCRMVOL ioctl command of the UBI character
548c2ecf20Sopenharmony_ci * device should be used. A pointer to the 32-bit volume ID hast to be passed
558c2ecf20Sopenharmony_ci * to the ioctl.
568c2ecf20Sopenharmony_ci *
578c2ecf20Sopenharmony_ci * UBI volume re-size
588c2ecf20Sopenharmony_ci * ~~~~~~~~~~~~~~~~~~
598c2ecf20Sopenharmony_ci *
608c2ecf20Sopenharmony_ci * To re-size a volume, the %UBI_IOCRSVOL ioctl command of the UBI character
618c2ecf20Sopenharmony_ci * device should be used. A &struct ubi_rsvol_req object has to be properly
628c2ecf20Sopenharmony_ci * filled and a pointer to it has to be passed to the ioctl.
638c2ecf20Sopenharmony_ci *
648c2ecf20Sopenharmony_ci * UBI volumes re-name
658c2ecf20Sopenharmony_ci * ~~~~~~~~~~~~~~~~~~~
668c2ecf20Sopenharmony_ci *
678c2ecf20Sopenharmony_ci * To re-name several volumes atomically at one go, the %UBI_IOCRNVOL command
688c2ecf20Sopenharmony_ci * of the UBI character device should be used. A &struct ubi_rnvol_req object
698c2ecf20Sopenharmony_ci * has to be properly filled and a pointer to it has to be passed to the ioctl.
708c2ecf20Sopenharmony_ci *
718c2ecf20Sopenharmony_ci * UBI volume update
728c2ecf20Sopenharmony_ci * ~~~~~~~~~~~~~~~~~
738c2ecf20Sopenharmony_ci *
748c2ecf20Sopenharmony_ci * Volume update should be done via the %UBI_IOCVOLUP ioctl command of the
758c2ecf20Sopenharmony_ci * corresponding UBI volume character device. A pointer to a 64-bit update
768c2ecf20Sopenharmony_ci * size should be passed to the ioctl. After this, UBI expects user to write
778c2ecf20Sopenharmony_ci * this number of bytes to the volume character device. The update is finished
788c2ecf20Sopenharmony_ci * when the claimed number of bytes is passed. So, the volume update sequence
798c2ecf20Sopenharmony_ci * is something like:
808c2ecf20Sopenharmony_ci *
818c2ecf20Sopenharmony_ci * fd = open("/dev/my_volume");
828c2ecf20Sopenharmony_ci * ioctl(fd, UBI_IOCVOLUP, &image_size);
838c2ecf20Sopenharmony_ci * write(fd, buf, image_size);
848c2ecf20Sopenharmony_ci * close(fd);
858c2ecf20Sopenharmony_ci *
868c2ecf20Sopenharmony_ci * Logical eraseblock erase
878c2ecf20Sopenharmony_ci * ~~~~~~~~~~~~~~~~~~~~~~~~
888c2ecf20Sopenharmony_ci *
898c2ecf20Sopenharmony_ci * To erase a logical eraseblock, the %UBI_IOCEBER ioctl command of the
908c2ecf20Sopenharmony_ci * corresponding UBI volume character device should be used. This command
918c2ecf20Sopenharmony_ci * unmaps the requested logical eraseblock, makes sure the corresponding
928c2ecf20Sopenharmony_ci * physical eraseblock is successfully erased, and returns.
938c2ecf20Sopenharmony_ci *
948c2ecf20Sopenharmony_ci * Atomic logical eraseblock change
958c2ecf20Sopenharmony_ci * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
968c2ecf20Sopenharmony_ci *
978c2ecf20Sopenharmony_ci * Atomic logical eraseblock change operation is called using the %UBI_IOCEBCH
988c2ecf20Sopenharmony_ci * ioctl command of the corresponding UBI volume character device. A pointer to
998c2ecf20Sopenharmony_ci * a &struct ubi_leb_change_req object has to be passed to the ioctl. Then the
1008c2ecf20Sopenharmony_ci * user is expected to write the requested amount of bytes (similarly to what
1018c2ecf20Sopenharmony_ci * should be done in case of the "volume update" ioctl).
1028c2ecf20Sopenharmony_ci *
1038c2ecf20Sopenharmony_ci * Logical eraseblock map
1048c2ecf20Sopenharmony_ci * ~~~~~~~~~~~~~~~~~~~~~
1058c2ecf20Sopenharmony_ci *
1068c2ecf20Sopenharmony_ci * To map a logical eraseblock to a physical eraseblock, the %UBI_IOCEBMAP
1078c2ecf20Sopenharmony_ci * ioctl command should be used. A pointer to a &struct ubi_map_req object is
1088c2ecf20Sopenharmony_ci * expected to be passed. The ioctl maps the requested logical eraseblock to
1098c2ecf20Sopenharmony_ci * a physical eraseblock and returns.  Only non-mapped logical eraseblocks can
1108c2ecf20Sopenharmony_ci * be mapped. If the logical eraseblock specified in the request is already
1118c2ecf20Sopenharmony_ci * mapped to a physical eraseblock, the ioctl fails and returns error.
1128c2ecf20Sopenharmony_ci *
1138c2ecf20Sopenharmony_ci * Logical eraseblock unmap
1148c2ecf20Sopenharmony_ci * ~~~~~~~~~~~~~~~~~~~~~~~~
1158c2ecf20Sopenharmony_ci *
1168c2ecf20Sopenharmony_ci * To unmap a logical eraseblock to a physical eraseblock, the %UBI_IOCEBUNMAP
1178c2ecf20Sopenharmony_ci * ioctl command should be used. The ioctl unmaps the logical eraseblocks,
1188c2ecf20Sopenharmony_ci * schedules corresponding physical eraseblock for erasure, and returns. Unlike
1198c2ecf20Sopenharmony_ci * the "LEB erase" command, it does not wait for the physical eraseblock being
1208c2ecf20Sopenharmony_ci * erased. Note, the side effect of this is that if an unclean reboot happens
1218c2ecf20Sopenharmony_ci * after the unmap ioctl returns, you may find the LEB mapped again to the same
1228c2ecf20Sopenharmony_ci * physical eraseblock after the UBI is run again.
1238c2ecf20Sopenharmony_ci *
1248c2ecf20Sopenharmony_ci * Check if logical eraseblock is mapped
1258c2ecf20Sopenharmony_ci * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1268c2ecf20Sopenharmony_ci *
1278c2ecf20Sopenharmony_ci * To check if a logical eraseblock is mapped to a physical eraseblock, the
1288c2ecf20Sopenharmony_ci * %UBI_IOCEBISMAP ioctl command should be used. It returns %0 if the LEB is
1298c2ecf20Sopenharmony_ci * not mapped, and %1 if it is mapped.
1308c2ecf20Sopenharmony_ci *
1318c2ecf20Sopenharmony_ci * Set an UBI volume property
1328c2ecf20Sopenharmony_ci * ~~~~~~~~~~~~~~~~~~~~~~~~~
1338c2ecf20Sopenharmony_ci *
1348c2ecf20Sopenharmony_ci * To set an UBI volume property the %UBI_IOCSETPROP ioctl command should be
1358c2ecf20Sopenharmony_ci * used. A pointer to a &struct ubi_set_vol_prop_req object is expected to be
1368c2ecf20Sopenharmony_ci * passed. The object describes which property should be set, and to which value
1378c2ecf20Sopenharmony_ci * it should be set.
1388c2ecf20Sopenharmony_ci *
1398c2ecf20Sopenharmony_ci * Block devices on UBI volumes
1408c2ecf20Sopenharmony_ci * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1418c2ecf20Sopenharmony_ci *
1428c2ecf20Sopenharmony_ci * To create a R/O block device on top of an UBI volume the %UBI_IOCVOLCRBLK
1438c2ecf20Sopenharmony_ci * should be used. A pointer to a &struct ubi_blkcreate_req object is expected
1448c2ecf20Sopenharmony_ci * to be passed, which is not used and reserved for future usage.
1458c2ecf20Sopenharmony_ci *
1468c2ecf20Sopenharmony_ci * Conversely, to remove a block device the %UBI_IOCVOLRMBLK should be used,
1478c2ecf20Sopenharmony_ci * which takes no arguments.
1488c2ecf20Sopenharmony_ci */
1498c2ecf20Sopenharmony_ci
1508c2ecf20Sopenharmony_ci/*
1518c2ecf20Sopenharmony_ci * When a new UBI volume or UBI device is created, users may either specify the
1528c2ecf20Sopenharmony_ci * volume/device number they want to create or to let UBI automatically assign
1538c2ecf20Sopenharmony_ci * the number using these constants.
1548c2ecf20Sopenharmony_ci */
1558c2ecf20Sopenharmony_ci#define UBI_VOL_NUM_AUTO (-1)
1568c2ecf20Sopenharmony_ci#define UBI_DEV_NUM_AUTO (-1)
1578c2ecf20Sopenharmony_ci
1588c2ecf20Sopenharmony_ci/* Maximum volume name length */
1598c2ecf20Sopenharmony_ci#define UBI_MAX_VOLUME_NAME 127
1608c2ecf20Sopenharmony_ci
1618c2ecf20Sopenharmony_ci/* ioctl commands of UBI character devices */
1628c2ecf20Sopenharmony_ci
1638c2ecf20Sopenharmony_ci#define UBI_IOC_MAGIC 'o'
1648c2ecf20Sopenharmony_ci
1658c2ecf20Sopenharmony_ci/* Create an UBI volume */
1668c2ecf20Sopenharmony_ci#define UBI_IOCMKVOL _IOW(UBI_IOC_MAGIC, 0, struct ubi_mkvol_req)
1678c2ecf20Sopenharmony_ci/* Remove an UBI volume */
1688c2ecf20Sopenharmony_ci#define UBI_IOCRMVOL _IOW(UBI_IOC_MAGIC, 1, __s32)
1698c2ecf20Sopenharmony_ci/* Re-size an UBI volume */
1708c2ecf20Sopenharmony_ci#define UBI_IOCRSVOL _IOW(UBI_IOC_MAGIC, 2, struct ubi_rsvol_req)
1718c2ecf20Sopenharmony_ci/* Re-name volumes */
1728c2ecf20Sopenharmony_ci#define UBI_IOCRNVOL _IOW(UBI_IOC_MAGIC, 3, struct ubi_rnvol_req)
1738c2ecf20Sopenharmony_ci
1748c2ecf20Sopenharmony_ci/* Read the specified PEB and scrub it if there are bitflips */
1758c2ecf20Sopenharmony_ci#define UBI_IOCRPEB _IOW(UBI_IOC_MAGIC, 4, __s32)
1768c2ecf20Sopenharmony_ci/* Force scrubbing on the specified PEB */
1778c2ecf20Sopenharmony_ci#define UBI_IOCSPEB _IOW(UBI_IOC_MAGIC, 5, __s32)
1788c2ecf20Sopenharmony_ci
1798c2ecf20Sopenharmony_ci/* ioctl commands of the UBI control character device */
1808c2ecf20Sopenharmony_ci
1818c2ecf20Sopenharmony_ci#define UBI_CTRL_IOC_MAGIC 'o'
1828c2ecf20Sopenharmony_ci
1838c2ecf20Sopenharmony_ci/* Attach an MTD device */
1848c2ecf20Sopenharmony_ci#define UBI_IOCATT _IOW(UBI_CTRL_IOC_MAGIC, 64, struct ubi_attach_req)
1858c2ecf20Sopenharmony_ci/* Detach an MTD device */
1868c2ecf20Sopenharmony_ci#define UBI_IOCDET _IOW(UBI_CTRL_IOC_MAGIC, 65, __s32)
1878c2ecf20Sopenharmony_ci
1888c2ecf20Sopenharmony_ci/* ioctl commands of UBI volume character devices */
1898c2ecf20Sopenharmony_ci
1908c2ecf20Sopenharmony_ci#define UBI_VOL_IOC_MAGIC 'O'
1918c2ecf20Sopenharmony_ci
1928c2ecf20Sopenharmony_ci/* Start UBI volume update
1938c2ecf20Sopenharmony_ci * Note: This actually takes a pointer (__s64*), but we can't change
1948c2ecf20Sopenharmony_ci *       that without breaking the ABI on 32bit systems
1958c2ecf20Sopenharmony_ci */
1968c2ecf20Sopenharmony_ci#define UBI_IOCVOLUP _IOW(UBI_VOL_IOC_MAGIC, 0, __s64)
1978c2ecf20Sopenharmony_ci/* LEB erasure command, used for debugging, disabled by default */
1988c2ecf20Sopenharmony_ci#define UBI_IOCEBER _IOW(UBI_VOL_IOC_MAGIC, 1, __s32)
1998c2ecf20Sopenharmony_ci/* Atomic LEB change command */
2008c2ecf20Sopenharmony_ci#define UBI_IOCEBCH _IOW(UBI_VOL_IOC_MAGIC, 2, __s32)
2018c2ecf20Sopenharmony_ci/* Map LEB command */
2028c2ecf20Sopenharmony_ci#define UBI_IOCEBMAP _IOW(UBI_VOL_IOC_MAGIC, 3, struct ubi_map_req)
2038c2ecf20Sopenharmony_ci/* Unmap LEB command */
2048c2ecf20Sopenharmony_ci#define UBI_IOCEBUNMAP _IOW(UBI_VOL_IOC_MAGIC, 4, __s32)
2058c2ecf20Sopenharmony_ci/* Check if LEB is mapped command */
2068c2ecf20Sopenharmony_ci#define UBI_IOCEBISMAP _IOR(UBI_VOL_IOC_MAGIC, 5, __s32)
2078c2ecf20Sopenharmony_ci/* Set an UBI volume property */
2088c2ecf20Sopenharmony_ci#define UBI_IOCSETVOLPROP _IOW(UBI_VOL_IOC_MAGIC, 6, \
2098c2ecf20Sopenharmony_ci			       struct ubi_set_vol_prop_req)
2108c2ecf20Sopenharmony_ci/* Create a R/O block device on top of an UBI volume */
2118c2ecf20Sopenharmony_ci#define UBI_IOCVOLCRBLK _IOW(UBI_VOL_IOC_MAGIC, 7, struct ubi_blkcreate_req)
2128c2ecf20Sopenharmony_ci/* Remove the R/O block device */
2138c2ecf20Sopenharmony_ci#define UBI_IOCVOLRMBLK _IO(UBI_VOL_IOC_MAGIC, 8)
2148c2ecf20Sopenharmony_ci
2158c2ecf20Sopenharmony_ci/* Maximum MTD device name length supported by UBI */
2168c2ecf20Sopenharmony_ci#define MAX_UBI_MTD_NAME_LEN 127
2178c2ecf20Sopenharmony_ci
2188c2ecf20Sopenharmony_ci/* Maximum amount of UBI volumes that can be re-named at one go */
2198c2ecf20Sopenharmony_ci#define UBI_MAX_RNVOL 32
2208c2ecf20Sopenharmony_ci
2218c2ecf20Sopenharmony_ci/*
2228c2ecf20Sopenharmony_ci * UBI volume type constants.
2238c2ecf20Sopenharmony_ci *
2248c2ecf20Sopenharmony_ci * @UBI_DYNAMIC_VOLUME: dynamic volume
2258c2ecf20Sopenharmony_ci * @UBI_STATIC_VOLUME:  static volume
2268c2ecf20Sopenharmony_ci */
2278c2ecf20Sopenharmony_cienum {
2288c2ecf20Sopenharmony_ci	UBI_DYNAMIC_VOLUME = 3,
2298c2ecf20Sopenharmony_ci	UBI_STATIC_VOLUME  = 4,
2308c2ecf20Sopenharmony_ci};
2318c2ecf20Sopenharmony_ci
2328c2ecf20Sopenharmony_ci/*
2338c2ecf20Sopenharmony_ci * UBI set volume property ioctl constants.
2348c2ecf20Sopenharmony_ci *
2358c2ecf20Sopenharmony_ci * @UBI_VOL_PROP_DIRECT_WRITE: allow (any non-zero value) or disallow (value 0)
2368c2ecf20Sopenharmony_ci *                             user to directly write and erase individual
2378c2ecf20Sopenharmony_ci *                             eraseblocks on dynamic volumes
2388c2ecf20Sopenharmony_ci */
2398c2ecf20Sopenharmony_cienum {
2408c2ecf20Sopenharmony_ci	UBI_VOL_PROP_DIRECT_WRITE = 1,
2418c2ecf20Sopenharmony_ci};
2428c2ecf20Sopenharmony_ci
2438c2ecf20Sopenharmony_ci/**
2448c2ecf20Sopenharmony_ci * struct ubi_attach_req - attach MTD device request.
2458c2ecf20Sopenharmony_ci * @ubi_num: UBI device number to create
2468c2ecf20Sopenharmony_ci * @mtd_num: MTD device number to attach
2478c2ecf20Sopenharmony_ci * @vid_hdr_offset: VID header offset (use defaults if %0)
2488c2ecf20Sopenharmony_ci * @max_beb_per1024: maximum expected number of bad PEB per 1024 PEBs
2498c2ecf20Sopenharmony_ci * @padding: reserved for future, not used, has to be zeroed
2508c2ecf20Sopenharmony_ci *
2518c2ecf20Sopenharmony_ci * This data structure is used to specify MTD device UBI has to attach and the
2528c2ecf20Sopenharmony_ci * parameters it has to use. The number which should be assigned to the new UBI
2538c2ecf20Sopenharmony_ci * device is passed in @ubi_num. UBI may automatically assign the number if
2548c2ecf20Sopenharmony_ci * @UBI_DEV_NUM_AUTO is passed. In this case, the device number is returned in
2558c2ecf20Sopenharmony_ci * @ubi_num.
2568c2ecf20Sopenharmony_ci *
2578c2ecf20Sopenharmony_ci * Most applications should pass %0 in @vid_hdr_offset to make UBI use default
2588c2ecf20Sopenharmony_ci * offset of the VID header within physical eraseblocks. The default offset is
2598c2ecf20Sopenharmony_ci * the next min. I/O unit after the EC header. For example, it will be offset
2608c2ecf20Sopenharmony_ci * 512 in case of a 512 bytes page NAND flash with no sub-page support. Or
2618c2ecf20Sopenharmony_ci * it will be 512 in case of a 2KiB page NAND flash with 4 512-byte sub-pages.
2628c2ecf20Sopenharmony_ci *
2638c2ecf20Sopenharmony_ci * But in rare cases, if this optimizes things, the VID header may be placed to
2648c2ecf20Sopenharmony_ci * a different offset. For example, the boot-loader might do things faster if
2658c2ecf20Sopenharmony_ci * the VID header sits at the end of the first 2KiB NAND page with 4 sub-pages.
2668c2ecf20Sopenharmony_ci * As the boot-loader would not normally need to read EC headers (unless it
2678c2ecf20Sopenharmony_ci * needs UBI in RW mode), it might be faster to calculate ECC. This is weird
2688c2ecf20Sopenharmony_ci * example, but it real-life example. So, in this example, @vid_hdr_offer would
2698c2ecf20Sopenharmony_ci * be 2KiB-64 bytes = 1984. Note, that this position is not even 512-bytes
2708c2ecf20Sopenharmony_ci * aligned, which is OK, as UBI is clever enough to realize this is 4th
2718c2ecf20Sopenharmony_ci * sub-page of the first page and add needed padding.
2728c2ecf20Sopenharmony_ci *
2738c2ecf20Sopenharmony_ci * The @max_beb_per1024 is the maximum amount of bad PEBs UBI expects on the
2748c2ecf20Sopenharmony_ci * UBI device per 1024 eraseblocks.  This value is often given in an other form
2758c2ecf20Sopenharmony_ci * in the NAND datasheet (min NVB i.e. minimal number of valid blocks). The
2768c2ecf20Sopenharmony_ci * maximum expected bad eraseblocks per 1024 is then:
2778c2ecf20Sopenharmony_ci *    1024 * (1 - MinNVB / MaxNVB)
2788c2ecf20Sopenharmony_ci * Which gives 20 for most NAND devices.  This limit is used in order to derive
2798c2ecf20Sopenharmony_ci * amount of eraseblock UBI reserves for handling new bad blocks. If the device
2808c2ecf20Sopenharmony_ci * has more bad eraseblocks than this limit, UBI does not reserve any physical
2818c2ecf20Sopenharmony_ci * eraseblocks for new bad eraseblocks, but attempts to use available
2828c2ecf20Sopenharmony_ci * eraseblocks (if any). The accepted range is 0-768. If 0 is given, the
2838c2ecf20Sopenharmony_ci * default kernel value of %CONFIG_MTD_UBI_BEB_LIMIT will be used.
2848c2ecf20Sopenharmony_ci */
2858c2ecf20Sopenharmony_cistruct ubi_attach_req {
2868c2ecf20Sopenharmony_ci	__s32 ubi_num;
2878c2ecf20Sopenharmony_ci	__s32 mtd_num;
2888c2ecf20Sopenharmony_ci	__s32 vid_hdr_offset;
2898c2ecf20Sopenharmony_ci	__s16 max_beb_per1024;
2908c2ecf20Sopenharmony_ci	__s8 padding[10];
2918c2ecf20Sopenharmony_ci};
2928c2ecf20Sopenharmony_ci
2938c2ecf20Sopenharmony_ci/*
2948c2ecf20Sopenharmony_ci * UBI volume flags.
2958c2ecf20Sopenharmony_ci *
2968c2ecf20Sopenharmony_ci * @UBI_VOL_SKIP_CRC_CHECK_FLG: skip the CRC check done on a static volume at
2978c2ecf20Sopenharmony_ci *				open time. Only valid for static volumes and
2988c2ecf20Sopenharmony_ci *				should only be used if the volume user has a
2998c2ecf20Sopenharmony_ci *				way to verify data integrity
3008c2ecf20Sopenharmony_ci */
3018c2ecf20Sopenharmony_cienum {
3028c2ecf20Sopenharmony_ci	UBI_VOL_SKIP_CRC_CHECK_FLG = 0x1,
3038c2ecf20Sopenharmony_ci};
3048c2ecf20Sopenharmony_ci
3058c2ecf20Sopenharmony_ci#define UBI_VOL_VALID_FLGS	(UBI_VOL_SKIP_CRC_CHECK_FLG)
3068c2ecf20Sopenharmony_ci
3078c2ecf20Sopenharmony_ci/**
3088c2ecf20Sopenharmony_ci * struct ubi_mkvol_req - volume description data structure used in
3098c2ecf20Sopenharmony_ci *                        volume creation requests.
3108c2ecf20Sopenharmony_ci * @vol_id: volume number
3118c2ecf20Sopenharmony_ci * @alignment: volume alignment
3128c2ecf20Sopenharmony_ci * @bytes: volume size in bytes
3138c2ecf20Sopenharmony_ci * @vol_type: volume type (%UBI_DYNAMIC_VOLUME or %UBI_STATIC_VOLUME)
3148c2ecf20Sopenharmony_ci * @flags: volume flags (%UBI_VOL_SKIP_CRC_CHECK_FLG)
3158c2ecf20Sopenharmony_ci * @name_len: volume name length
3168c2ecf20Sopenharmony_ci * @padding2: reserved for future, not used, has to be zeroed
3178c2ecf20Sopenharmony_ci * @name: volume name
3188c2ecf20Sopenharmony_ci *
3198c2ecf20Sopenharmony_ci * This structure is used by user-space programs when creating new volumes. The
3208c2ecf20Sopenharmony_ci * @used_bytes field is only necessary when creating static volumes.
3218c2ecf20Sopenharmony_ci *
3228c2ecf20Sopenharmony_ci * The @alignment field specifies the required alignment of the volume logical
3238c2ecf20Sopenharmony_ci * eraseblock. This means, that the size of logical eraseblocks will be aligned
3248c2ecf20Sopenharmony_ci * to this number, i.e.,
3258c2ecf20Sopenharmony_ci *	(UBI device logical eraseblock size) mod (@alignment) = 0.
3268c2ecf20Sopenharmony_ci *
3278c2ecf20Sopenharmony_ci * To put it differently, the logical eraseblock of this volume may be slightly
3288c2ecf20Sopenharmony_ci * shortened in order to make it properly aligned. The alignment has to be
3298c2ecf20Sopenharmony_ci * multiple of the flash minimal input/output unit, or %1 to utilize the entire
3308c2ecf20Sopenharmony_ci * available space of logical eraseblocks.
3318c2ecf20Sopenharmony_ci *
3328c2ecf20Sopenharmony_ci * The @alignment field may be useful, for example, when one wants to maintain
3338c2ecf20Sopenharmony_ci * a block device on top of an UBI volume. In this case, it is desirable to fit
3348c2ecf20Sopenharmony_ci * an integer number of blocks in logical eraseblocks of this UBI volume. With
3358c2ecf20Sopenharmony_ci * alignment it is possible to update this volume using plane UBI volume image
3368c2ecf20Sopenharmony_ci * BLOBs, without caring about how to properly align them.
3378c2ecf20Sopenharmony_ci */
3388c2ecf20Sopenharmony_cistruct ubi_mkvol_req {
3398c2ecf20Sopenharmony_ci	__s32 vol_id;
3408c2ecf20Sopenharmony_ci	__s32 alignment;
3418c2ecf20Sopenharmony_ci	__s64 bytes;
3428c2ecf20Sopenharmony_ci	__s8 vol_type;
3438c2ecf20Sopenharmony_ci	__u8 flags;
3448c2ecf20Sopenharmony_ci	__s16 name_len;
3458c2ecf20Sopenharmony_ci	__s8 padding2[4];
3468c2ecf20Sopenharmony_ci	char name[UBI_MAX_VOLUME_NAME + 1];
3478c2ecf20Sopenharmony_ci} __packed;
3488c2ecf20Sopenharmony_ci
3498c2ecf20Sopenharmony_ci/**
3508c2ecf20Sopenharmony_ci * struct ubi_rsvol_req - a data structure used in volume re-size requests.
3518c2ecf20Sopenharmony_ci * @vol_id: ID of the volume to re-size
3528c2ecf20Sopenharmony_ci * @bytes: new size of the volume in bytes
3538c2ecf20Sopenharmony_ci *
3548c2ecf20Sopenharmony_ci * Re-sizing is possible for both dynamic and static volumes. But while dynamic
3558c2ecf20Sopenharmony_ci * volumes may be re-sized arbitrarily, static volumes cannot be made to be
3568c2ecf20Sopenharmony_ci * smaller than the number of bytes they bear. To arbitrarily shrink a static
3578c2ecf20Sopenharmony_ci * volume, it must be wiped out first (by means of volume update operation with
3588c2ecf20Sopenharmony_ci * zero number of bytes).
3598c2ecf20Sopenharmony_ci */
3608c2ecf20Sopenharmony_cistruct ubi_rsvol_req {
3618c2ecf20Sopenharmony_ci	__s64 bytes;
3628c2ecf20Sopenharmony_ci	__s32 vol_id;
3638c2ecf20Sopenharmony_ci} __packed;
3648c2ecf20Sopenharmony_ci
3658c2ecf20Sopenharmony_ci/**
3668c2ecf20Sopenharmony_ci * struct ubi_rnvol_req - volumes re-name request.
3678c2ecf20Sopenharmony_ci * @count: count of volumes to re-name
3688c2ecf20Sopenharmony_ci * @padding1:  reserved for future, not used, has to be zeroed
3698c2ecf20Sopenharmony_ci * @vol_id: ID of the volume to re-name
3708c2ecf20Sopenharmony_ci * @name_len: name length
3718c2ecf20Sopenharmony_ci * @padding2:  reserved for future, not used, has to be zeroed
3728c2ecf20Sopenharmony_ci * @name: new volume name
3738c2ecf20Sopenharmony_ci *
3748c2ecf20Sopenharmony_ci * UBI allows to re-name up to %32 volumes at one go. The count of volumes to
3758c2ecf20Sopenharmony_ci * re-name is specified in the @count field. The ID of the volumes to re-name
3768c2ecf20Sopenharmony_ci * and the new names are specified in the @vol_id and @name fields.
3778c2ecf20Sopenharmony_ci *
3788c2ecf20Sopenharmony_ci * The UBI volume re-name operation is atomic, which means that should power cut
3798c2ecf20Sopenharmony_ci * happen, the volumes will have either old name or new name. So the possible
3808c2ecf20Sopenharmony_ci * use-cases of this command is atomic upgrade. Indeed, to upgrade, say, volumes
3818c2ecf20Sopenharmony_ci * A and B one may create temporary volumes %A1 and %B1 with the new contents,
3828c2ecf20Sopenharmony_ci * then atomically re-name A1->A and B1->B, in which case old %A and %B will
3838c2ecf20Sopenharmony_ci * be removed.
3848c2ecf20Sopenharmony_ci *
3858c2ecf20Sopenharmony_ci * If it is not desirable to remove old A and B, the re-name request has to
3868c2ecf20Sopenharmony_ci * contain 4 entries: A1->A, A->A1, B1->B, B->B1, in which case old A1 and B1
3878c2ecf20Sopenharmony_ci * become A and B, and old A and B will become A1 and B1.
3888c2ecf20Sopenharmony_ci *
3898c2ecf20Sopenharmony_ci * It is also OK to request: A1->A, A1->X, B1->B, B->Y, in which case old A1
3908c2ecf20Sopenharmony_ci * and B1 become A and B, and old A and B become X and Y.
3918c2ecf20Sopenharmony_ci *
3928c2ecf20Sopenharmony_ci * In other words, in case of re-naming into an existing volume name, the
3938c2ecf20Sopenharmony_ci * existing volume is removed, unless it is re-named as well at the same
3948c2ecf20Sopenharmony_ci * re-name request.
3958c2ecf20Sopenharmony_ci */
3968c2ecf20Sopenharmony_cistruct ubi_rnvol_req {
3978c2ecf20Sopenharmony_ci	__s32 count;
3988c2ecf20Sopenharmony_ci	__s8 padding1[12];
3998c2ecf20Sopenharmony_ci	struct {
4008c2ecf20Sopenharmony_ci		__s32 vol_id;
4018c2ecf20Sopenharmony_ci		__s16 name_len;
4028c2ecf20Sopenharmony_ci		__s8  padding2[2];
4038c2ecf20Sopenharmony_ci		char    name[UBI_MAX_VOLUME_NAME + 1];
4048c2ecf20Sopenharmony_ci	} ents[UBI_MAX_RNVOL];
4058c2ecf20Sopenharmony_ci} __packed;
4068c2ecf20Sopenharmony_ci
4078c2ecf20Sopenharmony_ci/**
4088c2ecf20Sopenharmony_ci * struct ubi_leb_change_req - a data structure used in atomic LEB change
4098c2ecf20Sopenharmony_ci *                             requests.
4108c2ecf20Sopenharmony_ci * @lnum: logical eraseblock number to change
4118c2ecf20Sopenharmony_ci * @bytes: how many bytes will be written to the logical eraseblock
4128c2ecf20Sopenharmony_ci * @dtype: pass "3" for better compatibility with old kernels
4138c2ecf20Sopenharmony_ci * @padding: reserved for future, not used, has to be zeroed
4148c2ecf20Sopenharmony_ci *
4158c2ecf20Sopenharmony_ci * The @dtype field used to inform UBI about what kind of data will be written
4168c2ecf20Sopenharmony_ci * to the LEB: long term (value 1), short term (value 2), unknown (value 3).
4178c2ecf20Sopenharmony_ci * UBI tried to pick a PEB with lower erase counter for short term data and a
4188c2ecf20Sopenharmony_ci * PEB with higher erase counter for long term data. But this was not really
4198c2ecf20Sopenharmony_ci * used because users usually do not know this and could easily mislead UBI. We
4208c2ecf20Sopenharmony_ci * removed this feature in May 2012. UBI currently just ignores the @dtype
4218c2ecf20Sopenharmony_ci * field. But for better compatibility with older kernels it is recommended to
4228c2ecf20Sopenharmony_ci * set @dtype to 3 (unknown).
4238c2ecf20Sopenharmony_ci */
4248c2ecf20Sopenharmony_cistruct ubi_leb_change_req {
4258c2ecf20Sopenharmony_ci	__s32 lnum;
4268c2ecf20Sopenharmony_ci	__s32 bytes;
4278c2ecf20Sopenharmony_ci	__s8  dtype; /* obsolete, do not use! */
4288c2ecf20Sopenharmony_ci	__s8  padding[7];
4298c2ecf20Sopenharmony_ci} __packed;
4308c2ecf20Sopenharmony_ci
4318c2ecf20Sopenharmony_ci/**
4328c2ecf20Sopenharmony_ci * struct ubi_map_req - a data structure used in map LEB requests.
4338c2ecf20Sopenharmony_ci * @dtype: pass "3" for better compatibility with old kernels
4348c2ecf20Sopenharmony_ci * @lnum: logical eraseblock number to unmap
4358c2ecf20Sopenharmony_ci * @padding: reserved for future, not used, has to be zeroed
4368c2ecf20Sopenharmony_ci */
4378c2ecf20Sopenharmony_cistruct ubi_map_req {
4388c2ecf20Sopenharmony_ci	__s32 lnum;
4398c2ecf20Sopenharmony_ci	__s8  dtype; /* obsolete, do not use! */
4408c2ecf20Sopenharmony_ci	__s8  padding[3];
4418c2ecf20Sopenharmony_ci} __packed;
4428c2ecf20Sopenharmony_ci
4438c2ecf20Sopenharmony_ci
4448c2ecf20Sopenharmony_ci/**
4458c2ecf20Sopenharmony_ci * struct ubi_set_vol_prop_req - a data structure used to set an UBI volume
4468c2ecf20Sopenharmony_ci *                               property.
4478c2ecf20Sopenharmony_ci * @property: property to set (%UBI_VOL_PROP_DIRECT_WRITE)
4488c2ecf20Sopenharmony_ci * @padding: reserved for future, not used, has to be zeroed
4498c2ecf20Sopenharmony_ci * @value: value to set
4508c2ecf20Sopenharmony_ci */
4518c2ecf20Sopenharmony_cistruct ubi_set_vol_prop_req {
4528c2ecf20Sopenharmony_ci	__u8  property;
4538c2ecf20Sopenharmony_ci	__u8  padding[7];
4548c2ecf20Sopenharmony_ci	__u64 value;
4558c2ecf20Sopenharmony_ci}  __packed;
4568c2ecf20Sopenharmony_ci
4578c2ecf20Sopenharmony_ci/**
4588c2ecf20Sopenharmony_ci * struct ubi_blkcreate_req - a data structure used in block creation requests.
4598c2ecf20Sopenharmony_ci * @padding: reserved for future, not used, has to be zeroed
4608c2ecf20Sopenharmony_ci */
4618c2ecf20Sopenharmony_cistruct ubi_blkcreate_req {
4628c2ecf20Sopenharmony_ci	__s8  padding[128];
4638c2ecf20Sopenharmony_ci}  __packed;
4648c2ecf20Sopenharmony_ci
4658c2ecf20Sopenharmony_ci#endif /* __UBI_USER_H__ */
466