2 * Copyright (c) International Business Machines Corp., 2006
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
12 * the GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 * Author: Artem Bityutskiy (Битюцкий Артём)
21 #ifndef __LINUX_UBI_H__
22 #define __LINUX_UBI_H__
24 #include <asm/ioctl.h>
25 #include <linux/types.h>
26 #include <mtd/ubi-user.h>
29 * enum ubi_open_mode - UBI volume open mode constants.
31 * UBI_READONLY: read-only mode
32 * UBI_READWRITE: read-write mode
33 * UBI_EXCLUSIVE: exclusive mode
42 * struct ubi_volume_info - UBI volume description data structure.
44 * @ubi_num: UBI device number this volume belongs to
45 * @size: how many physical eraseblocks are reserved for this volume
46 * @used_bytes: how many bytes of data this volume contains
47 * @used_ebs: how many physical eraseblocks of this volume actually contain any
49 * @vol_type: volume type (%UBI_DYNAMIC_VOLUME or %UBI_STATIC_VOLUME)
50 * @corrupted: non-zero if the volume is corrupted (static volumes only)
51 * @upd_marker: non-zero if the volume has update marker set
52 * @alignment: volume alignment
53 * @usable_leb_size: how many bytes are available in logical eraseblocks of
55 * @name_len: volume name length
57 * @cdev: UBI volume character device major and minor numbers
59 * The @corrupted flag is only relevant to static volumes and is always zero
60 * for dynamic ones. This is because UBI does not care about dynamic volume
61 * data protection and only cares about protecting static volume data.
63 * The @upd_marker flag is set if the volume update operation was interrupted.
64 * Before touching the volume data during the update operation, UBI first sets
65 * the update marker flag for this volume. If the volume update operation was
66 * further interrupted, the update marker indicates this. If the update marker
67 * is set, the contents of the volume is certainly damaged and a new volume
68 * update operation has to be started.
70 * To put it differently, @corrupted and @upd_marker fields have different
72 * o the @corrupted flag means that this static volume is corrupted for some
73 * reasons, but not because an interrupted volume update
74 * o the @upd_marker field means that the volume is damaged because of an
75 * interrupted update operation.
77 * I.e., the @corrupted flag is never set if the @upd_marker flag is set.
79 * The @used_bytes and @used_ebs fields are only really needed for static
80 * volumes and contain the number of bytes stored in this static volume and how
81 * many eraseblock this data occupies. In case of dynamic volumes, the
82 * @used_bytes field is equivalent to @size*@usable_leb_size, and the @used_ebs
83 * field is equivalent to @size.
85 * In general, logical eraseblock size is a property of the UBI device, not
86 * of the UBI volume. Indeed, the logical eraseblock size depends on the
87 * physical eraseblock size and on how much bytes UBI headers consume. But
88 * because of the volume alignment (@alignment), the usable size of logical
89 * eraseblocks if a volume may be less. The following equation is true:
90 * @usable_leb_size = LEB size - (LEB size mod @alignment),
91 * where LEB size is the logical eraseblock size defined by the UBI device.
93 * The alignment is multiple to the minimal flash input/output unit size or %1
94 * if all the available space is used.
96 * To put this differently, alignment may be considered is a way to change
97 * volume logical eraseblock sizes.
99 struct ubi_volume_info
{
103 long long used_bytes
;
116 * struct ubi_device_info - UBI device description data structure.
117 * @ubi_num: ubi device number
118 * @leb_size: logical eraseblock size on this UBI device
119 * @min_io_size: minimal I/O unit size
120 * @ro_mode: if this device is in read-only mode
121 * @cdev: UBI character device major and minor numbers
123 * Note, @leb_size is the logical eraseblock size offered by the UBI device.
124 * Volumes of this UBI device may have smaller logical eraseblock size if their
125 * alignment is not equivalent to %1.
127 struct ubi_device_info
{
136 * enum - volume notification types.
137 * @UBI_VOLUME_ADDED: volume has been added
138 * @UBI_VOLUME_REMOVED: start volume volume
139 * @UBI_VOLUME_RESIZED: volume size has been re-sized
140 * @UBI_VOLUME_RENAMED: volume name has been re-named
141 * @UBI_VOLUME_UPDATED: volume name has been updated
143 * These constants define which type of event has happened when a volume
144 * notification function is invoked.
155 * struct ubi_notification - UBI notification description structure.
156 * @di: UBI device description object
157 * @vi: UBI volume description object
159 * UBI notifiers are called with a pointer to an object of this type. The
160 * object describes the notification. Namely, it provides a description of the
161 * UBI device and UBI volume the notification informs about.
163 struct ubi_notification
{
164 struct ubi_device_info di
;
165 struct ubi_volume_info vi
;
168 /* UBI descriptor given to users when they open UBI volumes */
169 struct ubi_volume_desc
;
171 int ubi_get_device_info(int ubi_num
, struct ubi_device_info
*di
);
172 void ubi_get_volume_info(struct ubi_volume_desc
*desc
,
173 struct ubi_volume_info
*vi
);
174 struct ubi_volume_desc
*ubi_open_volume(int ubi_num
, int vol_id
, int mode
);
175 struct ubi_volume_desc
*ubi_open_volume_nm(int ubi_num
, const char *name
,
177 struct ubi_volume_desc
*ubi_open_volume_path(const char *pathname
, int mode
);
179 int ubi_register_volume_notifier(struct notifier_block
*nb
,
180 int ignore_existing
);
181 int ubi_unregister_volume_notifier(struct notifier_block
*nb
);
183 void ubi_close_volume(struct ubi_volume_desc
*desc
);
184 int ubi_leb_read(struct ubi_volume_desc
*desc
, int lnum
, char *buf
, int offset
,
186 int ubi_leb_write(struct ubi_volume_desc
*desc
, int lnum
, const void *buf
,
187 int offset
, int len
, int dtype
);
188 int ubi_leb_change(struct ubi_volume_desc
*desc
, int lnum
, const void *buf
,
190 int ubi_leb_erase(struct ubi_volume_desc
*desc
, int lnum
);
191 int ubi_leb_unmap(struct ubi_volume_desc
*desc
, int lnum
);
192 int ubi_leb_map(struct ubi_volume_desc
*desc
, int lnum
, int dtype
);
193 int ubi_is_mapped(struct ubi_volume_desc
*desc
, int lnum
);
194 int ubi_sync(int ubi_num
);
197 * This function is the same as the 'ubi_leb_read()' function, but it does not
198 * provide the checking capability.
200 static inline int ubi_read(struct ubi_volume_desc
*desc
, int lnum
, char *buf
,
203 return ubi_leb_read(desc
, lnum
, buf
, offset
, len
, 0);
207 * This function is the same as the 'ubi_leb_write()' functions, but it does
208 * not have the data type argument.
210 static inline int ubi_write(struct ubi_volume_desc
*desc
, int lnum
,
211 const void *buf
, int offset
, int len
)
213 return ubi_leb_write(desc
, lnum
, buf
, offset
, len
, UBI_UNKNOWN
);
217 * This function is the same as the 'ubi_leb_change()' functions, but it does
218 * not have the data type argument.
220 static inline int ubi_change(struct ubi_volume_desc
*desc
, int lnum
,
221 const void *buf
, int len
)
223 return ubi_leb_change(desc
, lnum
, buf
, len
, UBI_UNKNOWN
);
226 #endif /* !__LINUX_UBI_H__ */