[PATCH 03/22 take 3] UBI: kernel-space API header

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Artem Bityutskiy
Date: Wednesday, March 14, 2007 - 8:19 am

diff -auNrp tmp-from/include/linux/mtd/ubi.h tmp-to/include/linux/mtd/ubi.h
--- tmp-from/include/linux/mtd/ubi.h	1970-01-01 02:00:00.000000000 +0200
+++ tmp-to/include/linux/mtd/ubi.h	2007-03-14 17:15:49.000000000 +0200
@@ -0,0 +1,196 @@
+/*
+ * Copyright (c) International Business Machines Corp., 2006
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Artem B. Bityutskiy
+ */
+
+#ifndef __LINUX_UBI_H__
+#define __LINUX_UBI_H__
+
+#include <asm/ioctl.h>
+#include <linux/types.h>
+#include <mtd/ubi-user.h>
+
+/**
+ * enum ubi_data_type - UBI data type hint constants.
+ *
+ * @UBI_DATA_LONGTERM: long-term data
+ * @UBI_DATA_SHORTTERM: short-term data
+ * @UBI_DATA_UNKNOWN: data persistence is unknown
+ *
+ * These constants are used when data is written to UBI volumes in order to
+ * help the UBI wear-leveling unit to find more appropriate physical
+ * eraseblocks.
+ */
+enum ubi_data_type {
+	UBI_DATA_LONGTERM = 1,
+	UBI_DATA_SHORTTERM,
+	UBI_DATA_UNKNOWN
+};
+
+/**
+ * enum ubi_open_mode - UBI volume open mode constants.
+ *
+ * @UBI_READONLY: read-only mode
+ * @UBI_READWRITE: read-write mode
+ * @UBI_EXCLUSIVE: exclusive mode
+ */
+enum ubi_open_mode {
+	UBI_READONLY = 1,
+	UBI_READWRITE,
+	UBI_EXCLUSIVE
+};
+
+/**
+ * struct ubi_vol_info - UBI volume description data structure.
+ *
+ * @vol_id: volume ID
+ * @ubi_num: UBI device number this volume belongs to
+ * @size: how many physical eraseblocks are reserved for this volume
+ * @used_bytes: how many bytes of data this volume contains
+ * @used_ebs: how many physical eraseblocks of this volume actually contain any
+ * data
+ * @vol_type: volume type (%UBI_DYNAMIC_VOLUME or %UBI_STATIC_VOLUME)
+ * @corrupted: non-zero if the volume is corrupted (static volumes only)
+ * @upd_marker: non-zero if the volume has update marker set
+ * @alignment: volume alignment
+ * @usable_leb_size: how many bytes are available in logical eraseblocks of
+ * this volume
+ * @name_len: volume name length
+ * @name: volume name
+ * @cdev: UBI volume character device major and minor numbers
+ *
+ * The @corrupted flag is only relevant to static volumes and is always zero
+ * for dynamic ones. This is because UBI does not care about dynamic volume
+ * data protection and only cares about protecting static volume data.
+ *
+ * The @upd_marker flag is set if the volume update operation was interrupted.
+ * Before touching the volume data during the update operation, UBI first sets
+ * the update marker flag for this volume. If the volume update operation was
+ * further interrupted, the update marker indicates this. If the update marker
+ * is set, the contents of the volume is certainly damaged and a new volume
+ * update operation has to be started.
+ *
+ * To put it differently, @corrupted and @upd_marker fields have different
+ * semantics:
+ *     o the @corrupted flag means that this static volume is corrupted for some
+ *       reasons, but not because an interrupted volume update
+ *     o the @upd_marker field means that the volume is damaged because of an
+ *       interrupted update operation.
+ *
+ * I.e., the @corrupted flag is never set if the @upd_marker flag is set.
+ *
+ * The @used_bytes and @used_ebs fields are only really needed for static
+ * volumes and contain the number of bytes stored in this static volume and how
+ * many eraseblock this data occupies. In case of dynamic volumes, the
+ * @used_bytes field is equivalent to @size*@usable_leb_size, and the @used_ebs
+ * field is equivalent to @size.
+ *
+ * In general, logical eraseblock size is a property of the UBI device, not
+ * of the UBI volume. Indeed, the logical eraseblock size depends on the
+ * physical eraseblock size and on how much bytes UBI headers consume. But
+ * because of the volume alignment (@alignment), the usable size of logical
+ * eraseblocks if a volume may be less. The following equation is true:
+ * 	@usable_leb_size = LEB size - (LEB size mod @alignment),
+ * where LEB size is the logical eraseblock size defined by the UBI device.
+ *
+ * The alignment is multiple to the minimal flash input/output unit size or %1
+ * if all the available space is used.
+ *
+ * To put this differently, alignment may be considered is a way to change
+ * volume logical eraseblock sizes.
+ */
+struct ubi_vol_info {
+	int ubi_num;
+	int vol_id;
+	int size;
+	long long used_bytes;
+	int used_ebs;
+	int vol_type;
+	int corrupted;
+	int upd_marker;
+	int alignment;
+	int usable_leb_size;
+	int name_len;
+	const char *name;
+	dev_t cdev;
+};
+
+/**
+ * struct ubi_dev_info - UBI device description data structure.
+ *
+ * @ubi_num: ubi device number
+ * @leb_size: logical eraseblock size on this UBI device
+ * @min_io_size: minimal I/O unit size
+ * @ro_mode: if this device is in read-only mode
+ * @cdev: UBI character device major and minor numbers
+ *
+ * Note, @leb_size is the logical eraseblock size offered by the UBI device.
+ * Volumes of this UBI device may have smaller logical eraseblock size if their
+ * alignment is not equivalent to %1.
+ */
+struct ubi_dev_info {
+	int ubi_num;
+	int leb_size;
+	int min_io_size;
+	int ro_mode;
+	dev_t cdev;
+};
+
+/* UBI descriptor given to users when they open UBI volumes */
+struct ubi_vol_desc;
+
+int ubi_get_device_info(int ubi_num, struct ubi_dev_info *di);
+void ubi_get_volume_info(struct ubi_vol_desc *desc, struct ubi_vol_info *vi);
+struct ubi_vol_desc *ubi_open_volume(int ubi_num, int vol_id, int mode);
+struct ubi_vol_desc *ubi_open_volume_nm(int ubi_num, const char *name,
+					int mode);
+void ubi_close_volume(struct ubi_vol_desc *desc);
+int ubi_eraseblock_read(struct ubi_vol_desc *desc, int lnum, char *buf,
+			int offset, int len, int check);
+int ubi_eraseblock_write(struct ubi_vol_desc *desc, int lnum, const void *buf,
+			 int offset, int len, int dtype);
+int ubi_eraseblock_erase(struct ubi_vol_desc *desc, int lnum);
+int ubi_eraseblock_unmap(struct ubi_vol_desc *desc, int lnum);
+int ubi_eraseblock_is_mapped(struct ubi_vol_desc *desc, int lnum);
+
+/*
+ * ubi_read - read data from an logical eraseblock (simplified).
+ *
+ * This function is the same as the 'ubi_eraseblock_read()' function, but it
+ * does not provide the checking capability.
+ */
+static inline int ubi_read(struct ubi_vol_desc *desc, int lnum, char *buf,
+			   int offset, int len)
+{
+	return ubi_eraseblock_read(desc, lnum, buf, offset, len, 0);
+}
+
+/*
+ * ubi_write - write data to a logical eraseblock (simplified).
+ *
+ * This function is the same as the 'ubi_eraseblock_write()' functions, but it
+ * does not have the data type argument.
+ */
+static inline int ubi_write(struct ubi_vol_desc *desc, int lnum,
+			    const void *buf, int offset, int len)
+{
+	return ubi_eraseblock_write(desc, lnum, buf, offset, len,
+				    UBI_DATA_UNKNOWN);
+}
+
+#endif /* !__LINUX_UBI_H__ */
-
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH 00/22 take 3] UBI: Unsorted Block Images, Artem Bityutskiy, (Wed Mar 14, 8:19 am)
[PATCH 01/22 take 3] UBI: on-flash data structures header, Artem Bityutskiy, (Wed Mar 14, 8:19 am)
[PATCH 02/22 take 3] UBI: user-space API header, Artem Bityutskiy, (Wed Mar 14, 8:19 am)
[PATCH 03/22 take 3] UBI: kernel-space API header, Artem Bityutskiy, (Wed Mar 14, 8:19 am)
[PATCH 04/22 take 3] UBI: internal header, Artem Bityutskiy, (Wed Mar 14, 8:19 am)
[PATCH 05/22 take 3] UBI: startup code, Artem Bityutskiy, (Wed Mar 14, 8:19 am)
[PATCH 06/22 take 3] UBI: scanning unit, Artem Bityutskiy, (Wed Mar 14, 8:20 am)
[PATCH 07/22 take 3] UBI: I/O unit, Artem Bityutskiy, (Wed Mar 14, 8:20 am)
[PATCH 08/22 take 3] UBI: volume table unit, Artem Bityutskiy, (Wed Mar 14, 8:20 am)
[PATCH 09/22 take 3] UBI: wear-leveling unit, Artem Bityutskiy, (Wed Mar 14, 8:20 am)
[PATCH 10/22 take 3] UBI: EBA unit, Artem Bityutskiy, (Wed Mar 14, 8:20 am)
[PATCH 11/22 take 3] UBI: user-interfaces unit, Artem Bityutskiy, (Wed Mar 14, 8:20 am)
[PATCH 12/22 take 3] UBI: update functionality, Artem Bityutskiy, (Wed Mar 14, 8:20 am)
[PATCH 13/22 take 3] UBI: accounting unit, Artem Bityutskiy, (Wed Mar 14, 8:20 am)
[PATCH 14/22 take 3] UBI: volume management functionality, Artem Bityutskiy, (Wed Mar 14, 8:20 am)
[PATCH 15/22 take 3] UBI: sysfs functionality, Artem Bityutskiy, (Wed Mar 14, 8:20 am)
[PATCH 16/22 take 3] UBI: character devices functionality, Artem Bityutskiy, (Wed Mar 14, 8:20 am)
[PATCH 17/22 take 3] UBI: gluebi functionality, Artem Bityutskiy, (Wed Mar 14, 8:21 am)
[PATCH 18/22 take 3] UBI: misc stuff, Artem Bityutskiy, (Wed Mar 14, 8:21 am)
[PATCH 19/22 take 3] UBI: debugging stuff, Artem Bityutskiy, (Wed Mar 14, 8:21 am)
[PATCH 20/22 take 3] UBI: JFFS2 UBI support, Artem Bityutskiy, (Wed Mar 14, 8:21 am)
[PATCH 21/22 take 3] UBI: update MAINTAINERS, Artem Bityutskiy, (Wed Mar 14, 8:21 am)
[PATCH 22/22 take 3] UBI: Linux build integration, Artem Bityutskiy, (Wed Mar 14, 8:21 am)
Re: [PATCH 10/22 take 3] UBI: EBA unit, Andrew Morton, (Thu Mar 15, 12:07 pm)
Re: [PATCH 10/22 take 3] UBI: EBA unit, Randy Dunlap, (Thu Mar 15, 2:24 pm)
Re: [PATCH 10/22 take 3] UBI: EBA unit, Josh Boyer, (Thu Mar 15, 4:29 pm)
Re: [PATCH 10/22 take 3] UBI: EBA unit, Randy Dunlap, (Thu Mar 15, 6:49 pm)
Re: [PATCH 10/22 take 3] UBI: EBA unit, Artem Bityutskiy, (Fri Mar 16, 3:14 am)
Re: [PATCH 10/22 take 3] UBI: EBA unit, Artem Bityutskiy, (Fri Mar 16, 3:21 am)
Re: [PATCH 10/22 take 3] UBI: EBA unit, Artem Bityutskiy, (Fri Mar 16, 3:23 am)
Re: [PATCH 10/22 take 3] UBI: EBA unit, Randy Dunlap, (Fri Mar 16, 7:55 am)
Re: [PATCH 00/22 take 3] UBI: Unsorted Block Images, Matt Mackall, (Sun Mar 18, 9:27 am)
Re: [PATCH 00/22 take 3] UBI: Unsorted Block Images, Artem Bityutskiy, (Sun Mar 18, 9:49 am)
Re: [PATCH 00/22 take 3] UBI: Unsorted Block Images, Matt Mackall, (Sun Mar 18, 12:18 pm)
Re: [PATCH 00/22 take 3] UBI: Unsorted Block Images, Josh Boyer, (Sun Mar 18, 1:31 pm)
Re: [PATCH 00/22 take 3] UBI: Unsorted Block Images, Matt Mackall, (Mon Mar 19, 10:08 am)
Re: [PATCH 00/22 take 3] UBI: Unsorted Block Images, Josh Boyer, (Mon Mar 19, 11:16 am)
Re: [PATCH 00/22 take 3] UBI: Unsorted Block Images, Thomas Gleixner, (Mon Mar 19, 12:03 pm)
Re: [PATCH 00/22 take 3] UBI: Unsorted Block Images, Matt Mackall, (Mon Mar 19, 12:54 pm)
Re: [PATCH 00/22 take 3] UBI: Unsorted Block Images, Matt Mackall, (Mon Mar 19, 1:12 pm)
Re: [PATCH 00/22 take 3] UBI: Unsorted Block Images, Artem Bityutskiy, (Mon Mar 19, 1:18 pm)
Re: [PATCH 00/22 take 3] UBI: Unsorted Block Images, Thomas Gleixner, (Mon Mar 19, 2:04 pm)
Re: [PATCH 00/22 take 3] UBI: Unsorted Block Images, Thomas Gleixner, (Mon Mar 19, 2:05 pm)
Re: [PATCH 00/22 take 3] UBI: Unsorted Block Images, Artem Bityutskiy, (Mon Mar 19, 2:06 pm)
Re: [PATCH 00/22 take 3] UBI: Unsorted Block Images, Matt Mackall, (Mon Mar 19, 2:36 pm)
Re: [PATCH 00/22 take 3] UBI: Unsorted Block Images, Matt Mackall, (Mon Mar 19, 3:32 pm)
Re: [PATCH 00/22 take 3] UBI: Unsorted Block Images, Thomas Gleixner, (Mon Mar 19, 5:42 pm)
Re: [PATCH 00/22 take 3] UBI: Unsorted Block Images, Thomas Gleixner, (Mon Mar 19, 5:43 pm)
Re: [PATCH 00/22 take 3] UBI: Unsorted Block Images, Matt Mackall, (Mon Mar 19, 6:05 pm)
Re: [PATCH 00/22 take 3] UBI: Unsorted Block Images, Thomas Gleixner, (Mon Mar 19, 11:28 pm)
Re: [PATCH 00/22 take 3] UBI: Unsorted Block Images, Josh Boyer, (Tue Mar 20, 5:13 am)
Re: [PATCH 00/22 take 3] UBI: Unsorted Block Images, Artem Bityutskiy, (Tue Mar 20, 5:25 am)
Re: [PATCH 00/22 take 3] UBI: Unsorted Block Images, Theodore Tso, (Tue Mar 20, 6:52 am)
Re: [PATCH 00/22 take 3] UBI: Unsorted Block Images, Artem Bityutskiy, (Tue Mar 20, 8:14 am)
Re: [PATCH 00/22 take 3] UBI: Unsorted Block Images, Josh Boyer, (Tue Mar 20, 8:59 am)
Re: [PATCH 00/22 take 3] UBI: Unsorted Block Images, David Lang, (Tue Mar 20, 11:58 am)
Re: [PATCH 00/22 take 3] UBI: Unsorted Block Images, Artem Bityutskiy, (Tue Mar 20, 1:05 pm)
Re: [PATCH 00/22 take 3] UBI: Unsorted Block Images, David Woodhouse, (Tue Mar 20, 2:32 pm)
Re: [PATCH 00/22 take 3] UBI: Unsorted Block Images, David Woodhouse, (Tue Mar 20, 2:36 pm)
Re: [PATCH 00/22 take 3] UBI: Unsorted Block Images, Theodore Tso, (Tue Mar 20, 3:03 pm)
Re: [PATCH 00/22 take 3] UBI: Unsorted Block Images, Artem Bityutskiy, (Wed Mar 21, 1:44 am)
Re: [PATCH 00/22 take 3] UBI: Unsorted Block Images, Artem Bityutskiy, (Wed Mar 21, 1:54 am)
Re: [PATCH 00/22 take 3] UBI: Unsorted Block Images, Thomas Gleixner, (Wed Mar 21, 4:25 am)
Re: [PATCH 00/22 take 3] UBI: Unsorted Block Images, Artem Bityutskiy, (Wed Mar 21, 4:36 am)
Re: [PATCH 00/22 take 3] UBI: Unsorted Block Images, Thomas Gleixner, (Wed Mar 21, 4:57 am)
Re: [PATCH 00/22 take 3] UBI: Unsorted Block Images, Artem Bityutskiy, (Wed Mar 21, 5:39 am)
Re: [PATCH 00/22 take 3] UBI: Unsorted Block Images, Theodore Tso, (Wed Mar 21, 6:50 am)
Re: [PATCH 00/22 take 3] UBI: Unsorted Block Images, Josh Boyer, (Wed Mar 21, 6:59 am)
Re: [PATCH 00/22 take 3] UBI: Unsorted Block Images, Artem Bityutskiy, (Wed Mar 21, 7:02 am)
Re: [PATCH 00/22 take 3] UBI: Unsorted Block Images, Frank Haverkamp, (Wed Mar 21, 8:38 am)
Re: [PATCH 00/22 take 3] UBI: Unsorted Block Images, David Lang, (Wed Mar 21, 1:26 pm)
Re: [PATCH 00/22 take 3] UBI: Unsorted Block Images, David Lang, (Sun Mar 25, 2:49 pm)
Re: [PATCH 00/22 take 3] UBI: Unsorted Block Images, David Woodhouse, (Sun Mar 25, 4:46 pm)
Re: [PATCH 00/22 take 3] UBI: Unsorted Block Images, David Woodhouse, (Sun Mar 25, 5:21 pm)
Re: [PATCH 00/22 take 3] UBI: Unsorted Block Images, David Woodhouse, (Mon Mar 26, 2:45 am)
Re: [PATCH 00/22 take 3] UBI: Unsorted Block Images, Thomas Gleixner, (Mon Mar 26, 3:02 am)
Re: [PATCH 00/22 take 3] UBI: Unsorted Block Images, David Woodhouse, (Mon Mar 26, 3:07 am)
Re: [PATCH 00/22 take 3] UBI: Unsorted Block Images, Artem Bityutskiy, (Mon Mar 26, 3:49 am)