2 * Copyright (c) International Business Machines Corp., 2006
4 * SPDX-License-Identifier: GPL-2.0+
6 * Author: Artem Bityutskiy (Битюцкий Артём)
9 #ifndef __LINUX_UBI_H__
10 #define __LINUX_UBI_H__
12 /* #include <asm/ioctl.h> */
13 #include <linux/types.h>
14 #include <mtd/ubi-user.h>
17 * enum ubi_open_mode - UBI volume open mode constants.
19 * UBI_READONLY: read-only mode
20 * UBI_READWRITE: read-write mode
21 * UBI_EXCLUSIVE: exclusive mode
30 * struct ubi_volume_info - UBI volume description data structure.
32 * @ubi_num: UBI device number this volume belongs to
33 * @size: how many physical eraseblocks are reserved for this volume
34 * @used_bytes: how many bytes of data this volume contains
35 * @used_ebs: how many physical eraseblocks of this volume actually contain any
37 * @vol_type: volume type (%UBI_DYNAMIC_VOLUME or %UBI_STATIC_VOLUME)
38 * @corrupted: non-zero if the volume is corrupted (static volumes only)
39 * @upd_marker: non-zero if the volume has update marker set
40 * @alignment: volume alignment
41 * @usable_leb_size: how many bytes are available in logical eraseblocks of
43 * @name_len: volume name length
45 * @cdev: UBI volume character device major and minor numbers
47 * The @corrupted flag is only relevant to static volumes and is always zero
48 * for dynamic ones. This is because UBI does not care about dynamic volume
49 * data protection and only cares about protecting static volume data.
51 * The @upd_marker flag is set if the volume update operation was interrupted.
52 * Before touching the volume data during the update operation, UBI first sets
53 * the update marker flag for this volume. If the volume update operation was
54 * further interrupted, the update marker indicates this. If the update marker
55 * is set, the contents of the volume is certainly damaged and a new volume
56 * update operation has to be started.
58 * To put it differently, @corrupted and @upd_marker fields have different
60 * o the @corrupted flag means that this static volume is corrupted for some
61 * reasons, but not because an interrupted volume update
62 * o the @upd_marker field means that the volume is damaged because of an
63 * interrupted update operation.
65 * I.e., the @corrupted flag is never set if the @upd_marker flag is set.
67 * The @used_bytes and @used_ebs fields are only really needed for static
68 * volumes and contain the number of bytes stored in this static volume and how
69 * many eraseblock this data occupies. In case of dynamic volumes, the
70 * @used_bytes field is equivalent to @size*@usable_leb_size, and the @used_ebs
71 * field is equivalent to @size.
73 * In general, logical eraseblock size is a property of the UBI device, not
74 * of the UBI volume. Indeed, the logical eraseblock size depends on the
75 * physical eraseblock size and on how much bytes UBI headers consume. But
76 * because of the volume alignment (@alignment), the usable size of logical
77 * eraseblocks if a volume may be less. The following equation is true:
78 * @usable_leb_size = LEB size - (LEB size mod @alignment),
79 * where LEB size is the logical eraseblock size defined by the UBI device.
81 * The alignment is multiple to the minimal flash input/output unit size or %1
82 * if all the available space is used.
84 * To put this differently, alignment may be considered is a way to change
85 * volume logical eraseblock sizes.
87 struct ubi_volume_info {
104 * struct ubi_device_info - UBI device description data structure.
105 * @ubi_num: ubi device number
106 * @leb_size: logical eraseblock size on this UBI device
107 * @min_io_size: minimal I/O unit size
108 * @ro_mode: if this device is in read-only mode
109 * @cdev: UBI character device major and minor numbers
111 * Note, @leb_size is the logical eraseblock size offered by the UBI device.
112 * Volumes of this UBI device may have smaller logical eraseblock size if their
113 * alignment is not equivalent to %1.
115 struct ubi_device_info {
123 /* UBI descriptor given to users when they open UBI volumes */
124 struct ubi_volume_desc;
126 int ubi_get_device_info(int ubi_num, struct ubi_device_info *di);
127 void ubi_get_volume_info(struct ubi_volume_desc *desc,
128 struct ubi_volume_info *vi);
129 struct ubi_volume_desc *ubi_open_volume(int ubi_num, int vol_id, int mode);
130 struct ubi_volume_desc *ubi_open_volume_nm(int ubi_num, const char *name,
132 void ubi_close_volume(struct ubi_volume_desc *desc);
133 int ubi_leb_read(struct ubi_volume_desc *desc, int lnum, char *buf, int offset,
135 int ubi_leb_write(struct ubi_volume_desc *desc, int lnum, const void *buf,
136 int offset, int len, int dtype);
137 int ubi_leb_change(struct ubi_volume_desc *desc, int lnum, const void *buf,
139 int ubi_leb_erase(struct ubi_volume_desc *desc, int lnum);
140 int ubi_leb_unmap(struct ubi_volume_desc *desc, int lnum);
141 int ubi_leb_map(struct ubi_volume_desc *desc, int lnum, int dtype);
142 int ubi_is_mapped(struct ubi_volume_desc *desc, int lnum);
145 * This function is the same as the 'ubi_leb_read()' function, but it does not
146 * provide the checking capability.
148 static inline int ubi_read(struct ubi_volume_desc *desc, int lnum, char *buf,
151 return ubi_leb_read(desc, lnum, buf, offset, len, 0);
155 * This function is the same as the 'ubi_leb_write()' functions, but it does
156 * not have the data type argument.
158 static inline int ubi_write(struct ubi_volume_desc *desc, int lnum,
159 const void *buf, int offset, int len)
161 return ubi_leb_write(desc, lnum, buf, offset, len, UBI_UNKNOWN);
165 * This function is the same as the 'ubi_leb_change()' functions, but it does
166 * not have the data type argument.
168 static inline int ubi_change(struct ubi_volume_desc *desc, int lnum,
169 const void *buf, int len)
171 return ubi_leb_change(desc, lnum, buf, len, UBI_UNKNOWN);
174 #endif /* !__LINUX_UBI_H__ */