1801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy/*
2a1452a3771c4eb85bd779790b040efdc36f4274eDavid Woodhouse * Copyright © International Business Machines Corp., 2006
3801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy *
4801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy * This program is free software; you can redistribute it and/or modify
5801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy * it under the terms of the GNU General Public License as published by
6801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy * the Free Software Foundation; either version 2 of the License, or
7801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy * (at your option) any later version.
8801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy *
9801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy * This program is distributed in the hope that it will be useful,
10801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy * but WITHOUT ANY WARRANTY; without even the implied warranty of
11801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
12801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy * the GNU General Public License for more details.
13801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy *
14801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy * You should have received a copy of the GNU General Public License
15801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy * along with this program; if not, write to the Free Software
16801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy *
18801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy * Author: Artem Bityutskiy (Битюцкий Артём)
19801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy */
20801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy
21801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy#ifndef __UBI_USER_H__
22801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy#define __UBI_USER_H__
23801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy
24ccef7ab534347e2e1e1ef398d2ec987d37e519f3Arnd Bergmann#include <linux/types.h>
25ccef7ab534347e2e1e1ef398d2ec987d37e519f3Arnd Bergmann
26801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy/*
279b79cc0f84edecceb04b806b9014fcec1306c34dArtem Bityutskiy * UBI device creation (the same as MTD device attachment)
289b79cc0f84edecceb04b806b9014fcec1306c34dArtem Bityutskiy * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
299b79cc0f84edecceb04b806b9014fcec1306c34dArtem Bityutskiy *
309b79cc0f84edecceb04b806b9014fcec1306c34dArtem Bityutskiy * MTD devices may be attached using %UBI_IOCATT ioctl command of the UBI
319b79cc0f84edecceb04b806b9014fcec1306c34dArtem Bityutskiy * control device. The caller has to properly fill and pass
329b79cc0f84edecceb04b806b9014fcec1306c34dArtem Bityutskiy * &struct ubi_attach_req object - UBI will attach the MTD device specified in
339b79cc0f84edecceb04b806b9014fcec1306c34dArtem Bityutskiy * the request and return the newly created UBI device number as the ioctl
349b79cc0f84edecceb04b806b9014fcec1306c34dArtem Bityutskiy * return value.
359b79cc0f84edecceb04b806b9014fcec1306c34dArtem Bityutskiy *
369b79cc0f84edecceb04b806b9014fcec1306c34dArtem Bityutskiy * UBI device deletion (the same as MTD device detachment)
379b79cc0f84edecceb04b806b9014fcec1306c34dArtem Bityutskiy * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
389b79cc0f84edecceb04b806b9014fcec1306c34dArtem Bityutskiy *
399b79cc0f84edecceb04b806b9014fcec1306c34dArtem Bityutskiy * An UBI device maybe deleted with %UBI_IOCDET ioctl command of the UBI
409b79cc0f84edecceb04b806b9014fcec1306c34dArtem Bityutskiy * control device.
419b79cc0f84edecceb04b806b9014fcec1306c34dArtem Bityutskiy *
42801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy * UBI volume creation
43801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy * ~~~~~~~~~~~~~~~~~~~
44801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy *
45f7fc6f3f33703e3365c0ef9d4bf322b88cc9dae7Artem Bityutskiy * UBI volumes are created via the %UBI_IOCMKVOL ioctl command of UBI character
46801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy * device. A &struct ubi_mkvol_req object has to be properly filled and a
47f7fc6f3f33703e3365c0ef9d4bf322b88cc9dae7Artem Bityutskiy * pointer to it has to be passed to the ioctl.
48801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy *
49801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy * UBI volume deletion
50801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy * ~~~~~~~~~~~~~~~~~~~
51801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy *
52f7fc6f3f33703e3365c0ef9d4bf322b88cc9dae7Artem Bityutskiy * To delete a volume, the %UBI_IOCRMVOL ioctl command of the UBI character
53801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy * device should be used. A pointer to the 32-bit volume ID hast to be passed
54f7fc6f3f33703e3365c0ef9d4bf322b88cc9dae7Artem Bityutskiy * to the ioctl.
55801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy *
56801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy * UBI volume re-size
57801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy * ~~~~~~~~~~~~~~~~~~
58801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy *
59f7fc6f3f33703e3365c0ef9d4bf322b88cc9dae7Artem Bityutskiy * To re-size a volume, the %UBI_IOCRSVOL ioctl command of the UBI character
60801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy * device should be used. A &struct ubi_rsvol_req object has to be properly
61f7fc6f3f33703e3365c0ef9d4bf322b88cc9dae7Artem Bityutskiy * filled and a pointer to it has to be passed to the ioctl.
62801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy *
63f40ac9cdf6991287f19bdafe9b0752ee40137908Artem Bityutskiy * UBI volumes re-name
64f40ac9cdf6991287f19bdafe9b0752ee40137908Artem Bityutskiy * ~~~~~~~~~~~~~~~~~~~
65f40ac9cdf6991287f19bdafe9b0752ee40137908Artem Bityutskiy *
66f40ac9cdf6991287f19bdafe9b0752ee40137908Artem Bityutskiy * To re-name several volumes atomically at one go, the %UBI_IOCRNVOL command
67f40ac9cdf6991287f19bdafe9b0752ee40137908Artem Bityutskiy * of the UBI character device should be used. A &struct ubi_rnvol_req object
68f7fc6f3f33703e3365c0ef9d4bf322b88cc9dae7Artem Bityutskiy * has to be properly filled and a pointer to it has to be passed to the ioctl.
69f40ac9cdf6991287f19bdafe9b0752ee40137908Artem Bityutskiy *
70801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy * UBI volume update
71801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy * ~~~~~~~~~~~~~~~~~
72801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy *
73f7fc6f3f33703e3365c0ef9d4bf322b88cc9dae7Artem Bityutskiy * Volume update should be done via the %UBI_IOCVOLUP ioctl command of the
74801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy * corresponding UBI volume character device. A pointer to a 64-bit update
75f7fc6f3f33703e3365c0ef9d4bf322b88cc9dae7Artem Bityutskiy * size should be passed to the ioctl. After this, UBI expects user to write
76801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy * this number of bytes to the volume character device. The update is finished
77801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy * when the claimed number of bytes is passed. So, the volume update sequence
78801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy * is something like:
79801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy *
80801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy * fd = open("/dev/my_volume");
81801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy * ioctl(fd, UBI_IOCVOLUP, &image_size);
82801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy * write(fd, buf, image_size);
83801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy * close(fd);
84866136827b9a71c39dcb06d23ce523f719eab74bArtem Bityutskiy *
85f7fc6f3f33703e3365c0ef9d4bf322b88cc9dae7Artem Bityutskiy * Logical eraseblock erase
86866136827b9a71c39dcb06d23ce523f719eab74bArtem Bityutskiy * ~~~~~~~~~~~~~~~~~~~~~~~~
87866136827b9a71c39dcb06d23ce523f719eab74bArtem Bityutskiy *
88f7fc6f3f33703e3365c0ef9d4bf322b88cc9dae7Artem Bityutskiy * To erase a logical eraseblock, the %UBI_IOCEBER ioctl command of the
89f7fc6f3f33703e3365c0ef9d4bf322b88cc9dae7Artem Bityutskiy * corresponding UBI volume character device should be used. This command
90f7fc6f3f33703e3365c0ef9d4bf322b88cc9dae7Artem Bityutskiy * unmaps the requested logical eraseblock, makes sure the corresponding
91f7fc6f3f33703e3365c0ef9d4bf322b88cc9dae7Artem Bityutskiy * physical eraseblock is successfully erased, and returns.
92f7fc6f3f33703e3365c0ef9d4bf322b88cc9dae7Artem Bityutskiy *
93f7fc6f3f33703e3365c0ef9d4bf322b88cc9dae7Artem Bityutskiy * Atomic logical eraseblock change
94f7fc6f3f33703e3365c0ef9d4bf322b88cc9dae7Artem Bityutskiy * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
95f7fc6f3f33703e3365c0ef9d4bf322b88cc9dae7Artem Bityutskiy *
96f7fc6f3f33703e3365c0ef9d4bf322b88cc9dae7Artem Bityutskiy * Atomic logical eraseblock change operation is called using the %UBI_IOCEBCH
97f7fc6f3f33703e3365c0ef9d4bf322b88cc9dae7Artem Bityutskiy * ioctl command of the corresponding UBI volume character device. A pointer to
98f7fc6f3f33703e3365c0ef9d4bf322b88cc9dae7Artem Bityutskiy * a &struct ubi_leb_change_req object has to be passed to the ioctl. Then the
99f7fc6f3f33703e3365c0ef9d4bf322b88cc9dae7Artem Bityutskiy * user is expected to write the requested amount of bytes (similarly to what
100f7fc6f3f33703e3365c0ef9d4bf322b88cc9dae7Artem Bityutskiy * should be done in case of the "volume update" ioctl).
101f7fc6f3f33703e3365c0ef9d4bf322b88cc9dae7Artem Bityutskiy *
102f7fc6f3f33703e3365c0ef9d4bf322b88cc9dae7Artem Bityutskiy * Logical eraseblock map
103f7fc6f3f33703e3365c0ef9d4bf322b88cc9dae7Artem Bityutskiy * ~~~~~~~~~~~~~~~~~~~~~
104f7fc6f3f33703e3365c0ef9d4bf322b88cc9dae7Artem Bityutskiy *
105f7fc6f3f33703e3365c0ef9d4bf322b88cc9dae7Artem Bityutskiy * To map a logical eraseblock to a physical eraseblock, the %UBI_IOCEBMAP
106f7fc6f3f33703e3365c0ef9d4bf322b88cc9dae7Artem Bityutskiy * ioctl command should be used. A pointer to a &struct ubi_map_req object is
107f7fc6f3f33703e3365c0ef9d4bf322b88cc9dae7Artem Bityutskiy * expected to be passed. The ioctl maps the requested logical eraseblock to
108f7fc6f3f33703e3365c0ef9d4bf322b88cc9dae7Artem Bityutskiy * a physical eraseblock and returns.  Only non-mapped logical eraseblocks can
109f7fc6f3f33703e3365c0ef9d4bf322b88cc9dae7Artem Bityutskiy * be mapped. If the logical eraseblock specified in the request is already
110f7fc6f3f33703e3365c0ef9d4bf322b88cc9dae7Artem Bityutskiy * mapped to a physical eraseblock, the ioctl fails and returns error.
111f7fc6f3f33703e3365c0ef9d4bf322b88cc9dae7Artem Bityutskiy *
112f7fc6f3f33703e3365c0ef9d4bf322b88cc9dae7Artem Bityutskiy * Logical eraseblock unmap
113f7fc6f3f33703e3365c0ef9d4bf322b88cc9dae7Artem Bityutskiy * ~~~~~~~~~~~~~~~~~~~~~~~~
114f7fc6f3f33703e3365c0ef9d4bf322b88cc9dae7Artem Bityutskiy *
115f7fc6f3f33703e3365c0ef9d4bf322b88cc9dae7Artem Bityutskiy * To unmap a logical eraseblock to a physical eraseblock, the %UBI_IOCEBUNMAP
116f7fc6f3f33703e3365c0ef9d4bf322b88cc9dae7Artem Bityutskiy * ioctl command should be used. The ioctl unmaps the logical eraseblocks,
117f7fc6f3f33703e3365c0ef9d4bf322b88cc9dae7Artem Bityutskiy * schedules corresponding physical eraseblock for erasure, and returns. Unlike
118f7fc6f3f33703e3365c0ef9d4bf322b88cc9dae7Artem Bityutskiy * the "LEB erase" command, it does not wait for the physical eraseblock being
119f7fc6f3f33703e3365c0ef9d4bf322b88cc9dae7Artem Bityutskiy * erased. Note, the side effect of this is that if an unclean reboot happens
120f7fc6f3f33703e3365c0ef9d4bf322b88cc9dae7Artem Bityutskiy * after the unmap ioctl returns, you may find the LEB mapped again to the same
121f7fc6f3f33703e3365c0ef9d4bf322b88cc9dae7Artem Bityutskiy * physical eraseblock after the UBI is run again.
122f7fc6f3f33703e3365c0ef9d4bf322b88cc9dae7Artem Bityutskiy *
123f7fc6f3f33703e3365c0ef9d4bf322b88cc9dae7Artem Bityutskiy * Check if logical eraseblock is mapped
124f7fc6f3f33703e3365c0ef9d4bf322b88cc9dae7Artem Bityutskiy * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
125f7fc6f3f33703e3365c0ef9d4bf322b88cc9dae7Artem Bityutskiy *
126f7fc6f3f33703e3365c0ef9d4bf322b88cc9dae7Artem Bityutskiy * To check if a logical eraseblock is mapped to a physical eraseblock, the
127f7fc6f3f33703e3365c0ef9d4bf322b88cc9dae7Artem Bityutskiy * %UBI_IOCEBISMAP ioctl command should be used. It returns %0 if the LEB is
128f7fc6f3f33703e3365c0ef9d4bf322b88cc9dae7Artem Bityutskiy * not mapped, and %1 if it is mapped.
129766fb95ba06e1bbf531d30dc05e21b2d4a0e8dd2Sidney Amani *
130766fb95ba06e1bbf531d30dc05e21b2d4a0e8dd2Sidney Amani * Set an UBI volume property
131766fb95ba06e1bbf531d30dc05e21b2d4a0e8dd2Sidney Amani * ~~~~~~~~~~~~~~~~~~~~~~~~~
132766fb95ba06e1bbf531d30dc05e21b2d4a0e8dd2Sidney Amani *
133766fb95ba06e1bbf531d30dc05e21b2d4a0e8dd2Sidney Amani * To set an UBI volume property the %UBI_IOCSETPROP ioctl command should be
1346748482f4153fc0e095aa3dc831d5edac5656a80Artem Bityutskiy * used. A pointer to a &struct ubi_set_vol_prop_req object is expected to be
135766fb95ba06e1bbf531d30dc05e21b2d4a0e8dd2Sidney Amani * passed. The object describes which property should be set, and to which value
136766fb95ba06e1bbf531d30dc05e21b2d4a0e8dd2Sidney Amani * it should be set.
1379d54c8a33eec78289b1b3f6e10874719c27ce0a7Ezequiel Garcia *
1389d54c8a33eec78289b1b3f6e10874719c27ce0a7Ezequiel Garcia * Block devices on UBI volumes
1399d54c8a33eec78289b1b3f6e10874719c27ce0a7Ezequiel Garcia * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1409d54c8a33eec78289b1b3f6e10874719c27ce0a7Ezequiel Garcia *
141463c5eedb4a13b9aa91f05498a0f2c20bd03f8c4Ezequiel Garcia * To create a R/O block device on top of an UBI volume the %UBI_IOCVOLCRBLK
142463c5eedb4a13b9aa91f05498a0f2c20bd03f8c4Ezequiel Garcia * should be used. A pointer to a &struct ubi_blkcreate_req object is expected
143463c5eedb4a13b9aa91f05498a0f2c20bd03f8c4Ezequiel Garcia * to be passed, which is not used and reserved for future usage.
144463c5eedb4a13b9aa91f05498a0f2c20bd03f8c4Ezequiel Garcia *
145463c5eedb4a13b9aa91f05498a0f2c20bd03f8c4Ezequiel Garcia * Conversely, to remove a block device the %UBI_IOCVOLRMBLK should be used,
146463c5eedb4a13b9aa91f05498a0f2c20bd03f8c4Ezequiel Garcia * which takes no arguments.
147801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy */
148801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy
149801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy/*
1509b79cc0f84edecceb04b806b9014fcec1306c34dArtem Bityutskiy * When a new UBI volume or UBI device is created, users may either specify the
1519b79cc0f84edecceb04b806b9014fcec1306c34dArtem Bityutskiy * volume/device number they want to create or to let UBI automatically assign
1529b79cc0f84edecceb04b806b9014fcec1306c34dArtem Bityutskiy * the number using these constants.
153801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy */
154801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy#define UBI_VOL_NUM_AUTO (-1)
1559b79cc0f84edecceb04b806b9014fcec1306c34dArtem Bityutskiy#define UBI_DEV_NUM_AUTO (-1)
156801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy
157801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy/* Maximum volume name length */
158801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy#define UBI_MAX_VOLUME_NAME 127
159801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy
160f7fc6f3f33703e3365c0ef9d4bf322b88cc9dae7Artem Bityutskiy/* ioctl commands of UBI character devices */
161801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy
162801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy#define UBI_IOC_MAGIC 'o'
163801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy
164801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy/* Create an UBI volume */
165801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy#define UBI_IOCMKVOL _IOW(UBI_IOC_MAGIC, 0, struct ubi_mkvol_req)
166801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy/* Remove an UBI volume */
167ccef7ab534347e2e1e1ef398d2ec987d37e519f3Arnd Bergmann#define UBI_IOCRMVOL _IOW(UBI_IOC_MAGIC, 1, __s32)
168801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy/* Re-size an UBI volume */
169801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy#define UBI_IOCRSVOL _IOW(UBI_IOC_MAGIC, 2, struct ubi_rsvol_req)
170f40ac9cdf6991287f19bdafe9b0752ee40137908Artem Bityutskiy/* Re-name volumes */
171f40ac9cdf6991287f19bdafe9b0752ee40137908Artem Bityutskiy#define UBI_IOCRNVOL _IOW(UBI_IOC_MAGIC, 3, struct ubi_rnvol_req)
172801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy
173f7fc6f3f33703e3365c0ef9d4bf322b88cc9dae7Artem Bityutskiy/* ioctl commands of the UBI control character device */
1749b79cc0f84edecceb04b806b9014fcec1306c34dArtem Bityutskiy
1759b79cc0f84edecceb04b806b9014fcec1306c34dArtem Bityutskiy#define UBI_CTRL_IOC_MAGIC 'o'
1769b79cc0f84edecceb04b806b9014fcec1306c34dArtem Bityutskiy
1779b79cc0f84edecceb04b806b9014fcec1306c34dArtem Bityutskiy/* Attach an MTD device */
1789b79cc0f84edecceb04b806b9014fcec1306c34dArtem Bityutskiy#define UBI_IOCATT _IOW(UBI_CTRL_IOC_MAGIC, 64, struct ubi_attach_req)
1799b79cc0f84edecceb04b806b9014fcec1306c34dArtem Bityutskiy/* Detach an MTD device */
180ccef7ab534347e2e1e1ef398d2ec987d37e519f3Arnd Bergmann#define UBI_IOCDET _IOW(UBI_CTRL_IOC_MAGIC, 65, __s32)
1819b79cc0f84edecceb04b806b9014fcec1306c34dArtem Bityutskiy
182f7fc6f3f33703e3365c0ef9d4bf322b88cc9dae7Artem Bityutskiy/* ioctl commands of UBI volume character devices */
183801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy
184801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy#define UBI_VOL_IOC_MAGIC 'O'
185801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy
18695f9a4d27eadcc1e76c9196e9d90cf41e9bba6baMike Frysinger/* Start UBI volume update
18795f9a4d27eadcc1e76c9196e9d90cf41e9bba6baMike Frysinger * Note: This actually takes a pointer (__s64*), but we can't change
18895f9a4d27eadcc1e76c9196e9d90cf41e9bba6baMike Frysinger *       that without breaking the ABI on 32bit systems
18995f9a4d27eadcc1e76c9196e9d90cf41e9bba6baMike Frysinger */
190ccef7ab534347e2e1e1ef398d2ec987d37e519f3Arnd Bergmann#define UBI_IOCVOLUP _IOW(UBI_VOL_IOC_MAGIC, 0, __s64)
191f7fc6f3f33703e3365c0ef9d4bf322b88cc9dae7Artem Bityutskiy/* LEB erasure command, used for debugging, disabled by default */
192ccef7ab534347e2e1e1ef398d2ec987d37e519f3Arnd Bergmann#define UBI_IOCEBER _IOW(UBI_VOL_IOC_MAGIC, 1, __s32)
193f7fc6f3f33703e3365c0ef9d4bf322b88cc9dae7Artem Bityutskiy/* Atomic LEB change command */
194ccef7ab534347e2e1e1ef398d2ec987d37e519f3Arnd Bergmann#define UBI_IOCEBCH _IOW(UBI_VOL_IOC_MAGIC, 2, __s32)
195f7fc6f3f33703e3365c0ef9d4bf322b88cc9dae7Artem Bityutskiy/* Map LEB command */
196141e6ebd1b1759bd5cebf092b7216b6f1c7b4c4fCorentin Chary#define UBI_IOCEBMAP _IOW(UBI_VOL_IOC_MAGIC, 3, struct ubi_map_req)
197f7fc6f3f33703e3365c0ef9d4bf322b88cc9dae7Artem Bityutskiy/* Unmap LEB command */
198ccef7ab534347e2e1e1ef398d2ec987d37e519f3Arnd Bergmann#define UBI_IOCEBUNMAP _IOW(UBI_VOL_IOC_MAGIC, 4, __s32)
199f7fc6f3f33703e3365c0ef9d4bf322b88cc9dae7Artem Bityutskiy/* Check if LEB is mapped command */
200ccef7ab534347e2e1e1ef398d2ec987d37e519f3Arnd Bergmann#define UBI_IOCEBISMAP _IOR(UBI_VOL_IOC_MAGIC, 5, __s32)
201766fb95ba06e1bbf531d30dc05e21b2d4a0e8dd2Sidney Amani/* Set an UBI volume property */
2026748482f4153fc0e095aa3dc831d5edac5656a80Artem Bityutskiy#define UBI_IOCSETVOLPROP _IOW(UBI_VOL_IOC_MAGIC, 6, \
2036748482f4153fc0e095aa3dc831d5edac5656a80Artem Bityutskiy			       struct ubi_set_vol_prop_req)
2048af871887fcba470ff9265c65cff7d14d9e0e3f9Artem Bityutskiy/* Create a R/O block device on top of an UBI volume */
205463c5eedb4a13b9aa91f05498a0f2c20bd03f8c4Ezequiel Garcia#define UBI_IOCVOLCRBLK _IOW(UBI_VOL_IOC_MAGIC, 7, struct ubi_blkcreate_req)
2068af871887fcba470ff9265c65cff7d14d9e0e3f9Artem Bityutskiy/* Remove the R/O block device */
2078af871887fcba470ff9265c65cff7d14d9e0e3f9Artem Bityutskiy#define UBI_IOCVOLRMBLK _IO(UBI_VOL_IOC_MAGIC, 8)
208801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy
2099b79cc0f84edecceb04b806b9014fcec1306c34dArtem Bityutskiy/* Maximum MTD device name length supported by UBI */
2109b79cc0f84edecceb04b806b9014fcec1306c34dArtem Bityutskiy#define MAX_UBI_MTD_NAME_LEN 127
2119b79cc0f84edecceb04b806b9014fcec1306c34dArtem Bityutskiy
212f40ac9cdf6991287f19bdafe9b0752ee40137908Artem Bityutskiy/* Maximum amount of UBI volumes that can be re-named at one go */
213f40ac9cdf6991287f19bdafe9b0752ee40137908Artem Bityutskiy#define UBI_MAX_RNVOL 32
214f40ac9cdf6991287f19bdafe9b0752ee40137908Artem Bityutskiy
215801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy/*
216801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy * UBI volume type constants.
217801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy *
218801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy * @UBI_DYNAMIC_VOLUME: dynamic volume
219801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy * @UBI_STATIC_VOLUME:  static volume
220801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy */
221801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiyenum {
222801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy	UBI_DYNAMIC_VOLUME = 3,
223866136827b9a71c39dcb06d23ce523f719eab74bArtem Bityutskiy	UBI_STATIC_VOLUME  = 4,
2249b79cc0f84edecceb04b806b9014fcec1306c34dArtem Bityutskiy};
2259b79cc0f84edecceb04b806b9014fcec1306c34dArtem Bityutskiy
226766fb95ba06e1bbf531d30dc05e21b2d4a0e8dd2Sidney Amani/*
227e8e088de305d7cc00b2c8b2a857ceb62d5fa68d3Artem Bityutskiy * UBI set volume property ioctl constants.
228766fb95ba06e1bbf531d30dc05e21b2d4a0e8dd2Sidney Amani *
229e8e088de305d7cc00b2c8b2a857ceb62d5fa68d3Artem Bityutskiy * @UBI_VOL_PROP_DIRECT_WRITE: allow (any non-zero value) or disallow (value 0)
230e8e088de305d7cc00b2c8b2a857ceb62d5fa68d3Artem Bityutskiy *                             user to directly write and erase individual
231e8e088de305d7cc00b2c8b2a857ceb62d5fa68d3Artem Bityutskiy *                             eraseblocks on dynamic volumes
232766fb95ba06e1bbf531d30dc05e21b2d4a0e8dd2Sidney Amani */
233766fb95ba06e1bbf531d30dc05e21b2d4a0e8dd2Sidney Amanienum {
234e8e088de305d7cc00b2c8b2a857ceb62d5fa68d3Artem Bityutskiy	UBI_VOL_PROP_DIRECT_WRITE = 1,
235766fb95ba06e1bbf531d30dc05e21b2d4a0e8dd2Sidney Amani};
236766fb95ba06e1bbf531d30dc05e21b2d4a0e8dd2Sidney Amani
2379b79cc0f84edecceb04b806b9014fcec1306c34dArtem Bityutskiy/**
2389b79cc0f84edecceb04b806b9014fcec1306c34dArtem Bityutskiy * struct ubi_attach_req - attach MTD device request.
2399b79cc0f84edecceb04b806b9014fcec1306c34dArtem Bityutskiy * @ubi_num: UBI device number to create
2409b79cc0f84edecceb04b806b9014fcec1306c34dArtem Bityutskiy * @mtd_num: MTD device number to attach
2419b79cc0f84edecceb04b806b9014fcec1306c34dArtem Bityutskiy * @vid_hdr_offset: VID header offset (use defaults if %0)
242db7e21c21f293d52f5363fe8d9ee91d6bd0a503aRichard Genoud * @max_beb_per1024: maximum expected number of bad PEB per 1024 PEBs
2439b79cc0f84edecceb04b806b9014fcec1306c34dArtem Bityutskiy * @padding: reserved for future, not used, has to be zeroed
2449b79cc0f84edecceb04b806b9014fcec1306c34dArtem Bityutskiy *
2459b79cc0f84edecceb04b806b9014fcec1306c34dArtem Bityutskiy * This data structure is used to specify MTD device UBI has to attach and the
2469b79cc0f84edecceb04b806b9014fcec1306c34dArtem Bityutskiy * parameters it has to use. The number which should be assigned to the new UBI
247866136827b9a71c39dcb06d23ce523f719eab74bArtem Bityutskiy * device is passed in @ubi_num. UBI may automatically assign the number if
2489b79cc0f84edecceb04b806b9014fcec1306c34dArtem Bityutskiy * @UBI_DEV_NUM_AUTO is passed. In this case, the device number is returned in
2499b79cc0f84edecceb04b806b9014fcec1306c34dArtem Bityutskiy * @ubi_num.
2509b79cc0f84edecceb04b806b9014fcec1306c34dArtem Bityutskiy *
2519b79cc0f84edecceb04b806b9014fcec1306c34dArtem Bityutskiy * Most applications should pass %0 in @vid_hdr_offset to make UBI use default
2529b79cc0f84edecceb04b806b9014fcec1306c34dArtem Bityutskiy * offset of the VID header within physical eraseblocks. The default offset is
2539b79cc0f84edecceb04b806b9014fcec1306c34dArtem Bityutskiy * the next min. I/O unit after the EC header. For example, it will be offset
2549b79cc0f84edecceb04b806b9014fcec1306c34dArtem Bityutskiy * 512 in case of a 512 bytes page NAND flash with no sub-page support. Or
2559b79cc0f84edecceb04b806b9014fcec1306c34dArtem Bityutskiy * it will be 512 in case of a 2KiB page NAND flash with 4 512-byte sub-pages.
2569b79cc0f84edecceb04b806b9014fcec1306c34dArtem Bityutskiy *
2579b79cc0f84edecceb04b806b9014fcec1306c34dArtem Bityutskiy * But in rare cases, if this optimizes things, the VID header may be placed to
2589c9ec147709e63e4e8ac6a037c6bb50688ff8e9cArtem Bityutskiy * a different offset. For example, the boot-loader might do things faster if
2599c9ec147709e63e4e8ac6a037c6bb50688ff8e9cArtem Bityutskiy * the VID header sits at the end of the first 2KiB NAND page with 4 sub-pages.
2609c9ec147709e63e4e8ac6a037c6bb50688ff8e9cArtem Bityutskiy * As the boot-loader would not normally need to read EC headers (unless it
2619c9ec147709e63e4e8ac6a037c6bb50688ff8e9cArtem Bityutskiy * needs UBI in RW mode), it might be faster to calculate ECC. This is weird
2629c9ec147709e63e4e8ac6a037c6bb50688ff8e9cArtem Bityutskiy * example, but it real-life example. So, in this example, @vid_hdr_offer would
2639c9ec147709e63e4e8ac6a037c6bb50688ff8e9cArtem Bityutskiy * be 2KiB-64 bytes = 1984. Note, that this position is not even 512-bytes
2649c9ec147709e63e4e8ac6a037c6bb50688ff8e9cArtem Bityutskiy * aligned, which is OK, as UBI is clever enough to realize this is 4th
2659c9ec147709e63e4e8ac6a037c6bb50688ff8e9cArtem Bityutskiy * sub-page of the first page and add needed padding.
266db7e21c21f293d52f5363fe8d9ee91d6bd0a503aRichard Genoud *
267db7e21c21f293d52f5363fe8d9ee91d6bd0a503aRichard Genoud * The @max_beb_per1024 is the maximum amount of bad PEBs UBI expects on the
268db7e21c21f293d52f5363fe8d9ee91d6bd0a503aRichard Genoud * UBI device per 1024 eraseblocks.  This value is often given in an other form
269db7e21c21f293d52f5363fe8d9ee91d6bd0a503aRichard Genoud * in the NAND datasheet (min NVB i.e. minimal number of valid blocks). The
270db7e21c21f293d52f5363fe8d9ee91d6bd0a503aRichard Genoud * maximum expected bad eraseblocks per 1024 is then:
271db7e21c21f293d52f5363fe8d9ee91d6bd0a503aRichard Genoud *    1024 * (1 - MinNVB / MaxNVB)
272db7e21c21f293d52f5363fe8d9ee91d6bd0a503aRichard Genoud * Which gives 20 for most NAND devices.  This limit is used in order to derive
273db7e21c21f293d52f5363fe8d9ee91d6bd0a503aRichard Genoud * amount of eraseblock UBI reserves for handling new bad blocks. If the device
274db7e21c21f293d52f5363fe8d9ee91d6bd0a503aRichard Genoud * has more bad eraseblocks than this limit, UBI does not reserve any physical
275db7e21c21f293d52f5363fe8d9ee91d6bd0a503aRichard Genoud * eraseblocks for new bad eraseblocks, but attempts to use available
276db7e21c21f293d52f5363fe8d9ee91d6bd0a503aRichard Genoud * eraseblocks (if any). The accepted range is 0-768. If 0 is given, the
277db7e21c21f293d52f5363fe8d9ee91d6bd0a503aRichard Genoud * default kernel value of %CONFIG_MTD_UBI_BEB_LIMIT will be used.
2789b79cc0f84edecceb04b806b9014fcec1306c34dArtem Bityutskiy */
2799b79cc0f84edecceb04b806b9014fcec1306c34dArtem Bityutskiystruct ubi_attach_req {
280ccef7ab534347e2e1e1ef398d2ec987d37e519f3Arnd Bergmann	__s32 ubi_num;
281ccef7ab534347e2e1e1ef398d2ec987d37e519f3Arnd Bergmann	__s32 mtd_num;
282ccef7ab534347e2e1e1ef398d2ec987d37e519f3Arnd Bergmann	__s32 vid_hdr_offset;
283db7e21c21f293d52f5363fe8d9ee91d6bd0a503aRichard Genoud	__s16 max_beb_per1024;
284db7e21c21f293d52f5363fe8d9ee91d6bd0a503aRichard Genoud	__s8 padding[10];
285801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy};
286801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy
287801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy/**
288801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy * struct ubi_mkvol_req - volume description data structure used in
2899b79cc0f84edecceb04b806b9014fcec1306c34dArtem Bityutskiy *                        volume creation requests.
290801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy * @vol_id: volume number
291801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy * @alignment: volume alignment
292801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy * @bytes: volume size in bytes
293801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy * @vol_type: volume type (%UBI_DYNAMIC_VOLUME or %UBI_STATIC_VOLUME)
2949b79cc0f84edecceb04b806b9014fcec1306c34dArtem Bityutskiy * @padding1: reserved for future, not used, has to be zeroed
295801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy * @name_len: volume name length
2969b79cc0f84edecceb04b806b9014fcec1306c34dArtem Bityutskiy * @padding2: reserved for future, not used, has to be zeroed
297801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy * @name: volume name
298801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy *
299866136827b9a71c39dcb06d23ce523f719eab74bArtem Bityutskiy * This structure is used by user-space programs when creating new volumes. The
300801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy * @used_bytes field is only necessary when creating static volumes.
301801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy *
302801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy * The @alignment field specifies the required alignment of the volume logical
303801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy * eraseblock. This means, that the size of logical eraseblocks will be aligned
304801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy * to this number, i.e.,
305801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy *	(UBI device logical eraseblock size) mod (@alignment) = 0.
306801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy *
307801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy * To put it differently, the logical eraseblock of this volume may be slightly
308801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy * shortened in order to make it properly aligned. The alignment has to be
309801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy * multiple of the flash minimal input/output unit, or %1 to utilize the entire
310801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy * available space of logical eraseblocks.
311801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy *
312801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy * The @alignment field may be useful, for example, when one wants to maintain
313801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy * a block device on top of an UBI volume. In this case, it is desirable to fit
314801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy * an integer number of blocks in logical eraseblocks of this UBI volume. With
315801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy * alignment it is possible to update this volume using plane UBI volume image
316801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy * BLOBs, without caring about how to properly align them.
317801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy */
318801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiystruct ubi_mkvol_req {
319ccef7ab534347e2e1e1ef398d2ec987d37e519f3Arnd Bergmann	__s32 vol_id;
320ccef7ab534347e2e1e1ef398d2ec987d37e519f3Arnd Bergmann	__s32 alignment;
321ccef7ab534347e2e1e1ef398d2ec987d37e519f3Arnd Bergmann	__s64 bytes;
322ccef7ab534347e2e1e1ef398d2ec987d37e519f3Arnd Bergmann	__s8 vol_type;
323ccef7ab534347e2e1e1ef398d2ec987d37e519f3Arnd Bergmann	__s8 padding1;
324ccef7ab534347e2e1e1ef398d2ec987d37e519f3Arnd Bergmann	__s16 name_len;
325ccef7ab534347e2e1e1ef398d2ec987d37e519f3Arnd Bergmann	__s8 padding2[4];
3269b79cc0f84edecceb04b806b9014fcec1306c34dArtem Bityutskiy	char name[UBI_MAX_VOLUME_NAME + 1];
3273627924acf70a9a26587712e4888ee7144489678Artem Bityutskiy} __packed;
328801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy
329801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy/**
330801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy * struct ubi_rsvol_req - a data structure used in volume re-size requests.
331801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy * @vol_id: ID of the volume to re-size
332801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy * @bytes: new size of the volume in bytes
333801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy *
334801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy * Re-sizing is possible for both dynamic and static volumes. But while dynamic
335801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy * volumes may be re-sized arbitrarily, static volumes cannot be made to be
336025dfdafe77f20b3890981a394774baab7b9c827Frederik Schwarzer * smaller than the number of bytes they bear. To arbitrarily shrink a static
337801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy * volume, it must be wiped out first (by means of volume update operation with
338801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy * zero number of bytes).
339801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy */
340801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiystruct ubi_rsvol_req {
341ccef7ab534347e2e1e1ef398d2ec987d37e519f3Arnd Bergmann	__s64 bytes;
342ccef7ab534347e2e1e1ef398d2ec987d37e519f3Arnd Bergmann	__s32 vol_id;
3433627924acf70a9a26587712e4888ee7144489678Artem Bityutskiy} __packed;
344801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy
345866136827b9a71c39dcb06d23ce523f719eab74bArtem Bityutskiy/**
346f40ac9cdf6991287f19bdafe9b0752ee40137908Artem Bityutskiy * struct ubi_rnvol_req - volumes re-name request.
347f40ac9cdf6991287f19bdafe9b0752ee40137908Artem Bityutskiy * @count: count of volumes to re-name
348f40ac9cdf6991287f19bdafe9b0752ee40137908Artem Bityutskiy * @padding1:  reserved for future, not used, has to be zeroed
349f40ac9cdf6991287f19bdafe9b0752ee40137908Artem Bityutskiy * @vol_id: ID of the volume to re-name
350f40ac9cdf6991287f19bdafe9b0752ee40137908Artem Bityutskiy * @name_len: name length
351f40ac9cdf6991287f19bdafe9b0752ee40137908Artem Bityutskiy * @padding2:  reserved for future, not used, has to be zeroed
352f40ac9cdf6991287f19bdafe9b0752ee40137908Artem Bityutskiy * @name: new volume name
353f40ac9cdf6991287f19bdafe9b0752ee40137908Artem Bityutskiy *
354f40ac9cdf6991287f19bdafe9b0752ee40137908Artem Bityutskiy * UBI allows to re-name up to %32 volumes at one go. The count of volumes to
355f40ac9cdf6991287f19bdafe9b0752ee40137908Artem Bityutskiy * re-name is specified in the @count field. The ID of the volumes to re-name
356f40ac9cdf6991287f19bdafe9b0752ee40137908Artem Bityutskiy * and the new names are specified in the @vol_id and @name fields.
357f40ac9cdf6991287f19bdafe9b0752ee40137908Artem Bityutskiy *
358f40ac9cdf6991287f19bdafe9b0752ee40137908Artem Bityutskiy * The UBI volume re-name operation is atomic, which means that should power cut
359f40ac9cdf6991287f19bdafe9b0752ee40137908Artem Bityutskiy * happen, the volumes will have either old name or new name. So the possible
360f40ac9cdf6991287f19bdafe9b0752ee40137908Artem Bityutskiy * use-cases of this command is atomic upgrade. Indeed, to upgrade, say, volumes
361f40ac9cdf6991287f19bdafe9b0752ee40137908Artem Bityutskiy * A and B one may create temporary volumes %A1 and %B1 with the new contents,
362f40ac9cdf6991287f19bdafe9b0752ee40137908Artem Bityutskiy * then atomically re-name A1->A and B1->B, in which case old %A and %B will
363f40ac9cdf6991287f19bdafe9b0752ee40137908Artem Bityutskiy * be removed.
364f40ac9cdf6991287f19bdafe9b0752ee40137908Artem Bityutskiy *
365f40ac9cdf6991287f19bdafe9b0752ee40137908Artem Bityutskiy * If it is not desirable to remove old A and B, the re-name request has to
366f40ac9cdf6991287f19bdafe9b0752ee40137908Artem Bityutskiy * contain 4 entries: A1->A, A->A1, B1->B, B->B1, in which case old A1 and B1
367f40ac9cdf6991287f19bdafe9b0752ee40137908Artem Bityutskiy * become A and B, and old A and B will become A1 and B1.
368f40ac9cdf6991287f19bdafe9b0752ee40137908Artem Bityutskiy *
369f40ac9cdf6991287f19bdafe9b0752ee40137908Artem Bityutskiy * It is also OK to request: A1->A, A1->X, B1->B, B->Y, in which case old A1
370f40ac9cdf6991287f19bdafe9b0752ee40137908Artem Bityutskiy * and B1 become A and B, and old A and B become X and Y.
371f40ac9cdf6991287f19bdafe9b0752ee40137908Artem Bityutskiy *
372f40ac9cdf6991287f19bdafe9b0752ee40137908Artem Bityutskiy * In other words, in case of re-naming into an existing volume name, the
373f40ac9cdf6991287f19bdafe9b0752ee40137908Artem Bityutskiy * existing volume is removed, unless it is re-named as well at the same
374f40ac9cdf6991287f19bdafe9b0752ee40137908Artem Bityutskiy * re-name request.
375f40ac9cdf6991287f19bdafe9b0752ee40137908Artem Bityutskiy */
376f40ac9cdf6991287f19bdafe9b0752ee40137908Artem Bityutskiystruct ubi_rnvol_req {
377ccef7ab534347e2e1e1ef398d2ec987d37e519f3Arnd Bergmann	__s32 count;
378ccef7ab534347e2e1e1ef398d2ec987d37e519f3Arnd Bergmann	__s8 padding1[12];
379f40ac9cdf6991287f19bdafe9b0752ee40137908Artem Bityutskiy	struct {
380ccef7ab534347e2e1e1ef398d2ec987d37e519f3Arnd Bergmann		__s32 vol_id;
381ccef7ab534347e2e1e1ef398d2ec987d37e519f3Arnd Bergmann		__s16 name_len;
382ccef7ab534347e2e1e1ef398d2ec987d37e519f3Arnd Bergmann		__s8  padding2[2];
383f40ac9cdf6991287f19bdafe9b0752ee40137908Artem Bityutskiy		char    name[UBI_MAX_VOLUME_NAME + 1];
384f40ac9cdf6991287f19bdafe9b0752ee40137908Artem Bityutskiy	} ents[UBI_MAX_RNVOL];
3853627924acf70a9a26587712e4888ee7144489678Artem Bityutskiy} __packed;
386f40ac9cdf6991287f19bdafe9b0752ee40137908Artem Bityutskiy
387f40ac9cdf6991287f19bdafe9b0752ee40137908Artem Bityutskiy/**
388f7fc6f3f33703e3365c0ef9d4bf322b88cc9dae7Artem Bityutskiy * struct ubi_leb_change_req - a data structure used in atomic LEB change
389f7fc6f3f33703e3365c0ef9d4bf322b88cc9dae7Artem Bityutskiy *                             requests.
390866136827b9a71c39dcb06d23ce523f719eab74bArtem Bityutskiy * @lnum: logical eraseblock number to change
391866136827b9a71c39dcb06d23ce523f719eab74bArtem Bityutskiy * @bytes: how many bytes will be written to the logical eraseblock
3924415626732defb5a4567a0a757c7c5baae7ca846Artem Bityutskiy * @dtype: pass "3" for better compatibility with old kernels
393866136827b9a71c39dcb06d23ce523f719eab74bArtem Bityutskiy * @padding: reserved for future, not used, has to be zeroed
3944415626732defb5a4567a0a757c7c5baae7ca846Artem Bityutskiy *
3954415626732defb5a4567a0a757c7c5baae7ca846Artem Bityutskiy * The @dtype field used to inform UBI about what kind of data will be written
3964415626732defb5a4567a0a757c7c5baae7ca846Artem Bityutskiy * to the LEB: long term (value 1), short term (value 2), unknown (value 3).
3974415626732defb5a4567a0a757c7c5baae7ca846Artem Bityutskiy * UBI tried to pick a PEB with lower erase counter for short term data and a
3984415626732defb5a4567a0a757c7c5baae7ca846Artem Bityutskiy * PEB with higher erase counter for long term data. But this was not really
3994415626732defb5a4567a0a757c7c5baae7ca846Artem Bityutskiy * used because users usually do not know this and could easily mislead UBI. We
4004415626732defb5a4567a0a757c7c5baae7ca846Artem Bityutskiy * removed this feature in May 2012. UBI currently just ignores the @dtype
4014415626732defb5a4567a0a757c7c5baae7ca846Artem Bityutskiy * field. But for better compatibility with older kernels it is recommended to
4024415626732defb5a4567a0a757c7c5baae7ca846Artem Bityutskiy * set @dtype to 3 (unknown).
403866136827b9a71c39dcb06d23ce523f719eab74bArtem Bityutskiy */
404866136827b9a71c39dcb06d23ce523f719eab74bArtem Bityutskiystruct ubi_leb_change_req {
405ccef7ab534347e2e1e1ef398d2ec987d37e519f3Arnd Bergmann	__s32 lnum;
406ccef7ab534347e2e1e1ef398d2ec987d37e519f3Arnd Bergmann	__s32 bytes;
407a65a0eb6d198e058687a9214683bd1c418f20d39Richard Weinberger	__s8  dtype; /* obsolete, do not use! */
408ccef7ab534347e2e1e1ef398d2ec987d37e519f3Arnd Bergmann	__s8  padding[7];
4093627924acf70a9a26587712e4888ee7144489678Artem Bityutskiy} __packed;
410866136827b9a71c39dcb06d23ce523f719eab74bArtem Bityutskiy
411141e6ebd1b1759bd5cebf092b7216b6f1c7b4c4fCorentin Chary/**
412f7fc6f3f33703e3365c0ef9d4bf322b88cc9dae7Artem Bityutskiy * struct ubi_map_req - a data structure used in map LEB requests.
4134415626732defb5a4567a0a757c7c5baae7ca846Artem Bityutskiy * @dtype: pass "3" for better compatibility with old kernels
414141e6ebd1b1759bd5cebf092b7216b6f1c7b4c4fCorentin Chary * @lnum: logical eraseblock number to unmap
415141e6ebd1b1759bd5cebf092b7216b6f1c7b4c4fCorentin Chary * @padding: reserved for future, not used, has to be zeroed
416141e6ebd1b1759bd5cebf092b7216b6f1c7b4c4fCorentin Chary */
417141e6ebd1b1759bd5cebf092b7216b6f1c7b4c4fCorentin Charystruct ubi_map_req {
418ccef7ab534347e2e1e1ef398d2ec987d37e519f3Arnd Bergmann	__s32 lnum;
419a65a0eb6d198e058687a9214683bd1c418f20d39Richard Weinberger	__s8  dtype; /* obsolete, do not use! */
420ccef7ab534347e2e1e1ef398d2ec987d37e519f3Arnd Bergmann	__s8  padding[3];
4213627924acf70a9a26587712e4888ee7144489678Artem Bityutskiy} __packed;
422141e6ebd1b1759bd5cebf092b7216b6f1c7b4c4fCorentin Chary
423766fb95ba06e1bbf531d30dc05e21b2d4a0e8dd2Sidney Amani
424766fb95ba06e1bbf531d30dc05e21b2d4a0e8dd2Sidney Amani/**
425e8e088de305d7cc00b2c8b2a857ceb62d5fa68d3Artem Bityutskiy * struct ubi_set_vol_prop_req - a data structure used to set an UBI volume
4266748482f4153fc0e095aa3dc831d5edac5656a80Artem Bityutskiy *                               property.
4276748482f4153fc0e095aa3dc831d5edac5656a80Artem Bityutskiy * @property: property to set (%UBI_VOL_PROP_DIRECT_WRITE)
428766fb95ba06e1bbf531d30dc05e21b2d4a0e8dd2Sidney Amani * @padding: reserved for future, not used, has to be zeroed
429766fb95ba06e1bbf531d30dc05e21b2d4a0e8dd2Sidney Amani * @value: value to set
430766fb95ba06e1bbf531d30dc05e21b2d4a0e8dd2Sidney Amani */
4316748482f4153fc0e095aa3dc831d5edac5656a80Artem Bityutskiystruct ubi_set_vol_prop_req {
432feddbb34ebd75e9b6bf573b852079e327a88c07aArtem Bityutskiy	__u8  property;
433feddbb34ebd75e9b6bf573b852079e327a88c07aArtem Bityutskiy	__u8  padding[7];
434feddbb34ebd75e9b6bf573b852079e327a88c07aArtem Bityutskiy	__u64 value;
4353627924acf70a9a26587712e4888ee7144489678Artem Bityutskiy}  __packed;
436766fb95ba06e1bbf531d30dc05e21b2d4a0e8dd2Sidney Amani
437463c5eedb4a13b9aa91f05498a0f2c20bd03f8c4Ezequiel Garcia/**
438463c5eedb4a13b9aa91f05498a0f2c20bd03f8c4Ezequiel Garcia * struct ubi_blkcreate_req - a data structure used in block creation requests.
439463c5eedb4a13b9aa91f05498a0f2c20bd03f8c4Ezequiel Garcia * @padding: reserved for future, not used, has to be zeroed
440463c5eedb4a13b9aa91f05498a0f2c20bd03f8c4Ezequiel Garcia */
441463c5eedb4a13b9aa91f05498a0f2c20bd03f8c4Ezequiel Garciastruct ubi_blkcreate_req {
442463c5eedb4a13b9aa91f05498a0f2c20bd03f8c4Ezequiel Garcia	__s8  padding[128];
443463c5eedb4a13b9aa91f05498a0f2c20bd03f8c4Ezequiel Garcia}  __packed;
444463c5eedb4a13b9aa91f05498a0f2c20bd03f8c4Ezequiel Garcia
445801c135ce73d5df1caf3eca35b66a10824ae0707Artem B. Bityutskiy#endif /* __UBI_USER_H__ */
446