]> www.infradead.org Git - mtd-utils.git/commitdiff
UBI: sync ubi-user.h with kernel v3.6-rc1
authorRichard Genoud <richard.genoud@gmail.com>
Wed, 22 Aug 2012 09:27:56 +0000 (11:27 +0200)
committerArtem Bityutskiy <artem.bityutskiy@linux.intel.com>
Wed, 22 Aug 2012 10:20:49 +0000 (13:20 +0300)
Also remove the eraseblock type support, because kernel commit
a65a0eb6d198e058687a9214683bd1c418f20d39 set the dtype
parameter as obsolete.

Also adjust to some renames:
* 'UBI_PROP_DIRECT_WRITE' -> 'UBI_VOL_PROP_DIRECT_WRITE'
* 'struct ubi_set_prop_req' -> 'struct ubi_set_vol_prop_req'.
* 'UBI_IOCSETPROP' -> 'UBI_IOCSETVOLPROP'

Signed-off-by: Richard Genoud <richard.genoud@gmail.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
include/mtd/ubi-user.h
mkfs.ubifs/lpt.c
mkfs.ubifs/mkfs.ubifs.c
mkfs.ubifs/mkfs.ubifs.h
tests/ubi-tests/io_paral.c
ubi-utils/include/libubi.h
ubi-utils/libubi.c

index 296efae3525efe7164a8176035cc55631f5bd59d..19762d09ad74e3c9631e8e10784dda7ab0f9cca8 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) International Business Machines Corp., 2006
+ * Copyright © 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
  * ~~~~~~~~~~~~~~~~~~~~~~~~~
  *
  * To set an UBI volume property the %UBI_IOCSETPROP ioctl command should be
- * used. A pointer to a &struct ubi_set_prop_req object is expected to be
+ * used. A pointer to a &struct ubi_set_vol_prop_req object is expected to be
  * passed. The object describes which property should be set, and to which value
  * it should be set.
  */
 /* Check if LEB is mapped command */
 #define UBI_IOCEBISMAP _IOR(UBI_VOL_IOC_MAGIC, 5, int32_t)
 /* Set an UBI volume property */
-#define UBI_IOCSETPROP _IOW(UBI_VOL_IOC_MAGIC, 6, struct ubi_set_prop_req)
+#define UBI_IOCSETVOLPROP _IOW(UBI_VOL_IOC_MAGIC, 6, \
+                              struct ubi_set_vol_prop_req)
 
 /* Maximum MTD device name length supported by UBI */
 #define MAX_UBI_MTD_NAME_LEN 127
 /* Maximum amount of UBI volumes that can be re-named at one go */
 #define UBI_MAX_RNVOL 32
 
-/*
- * UBI data type hint constants.
- *
- * UBI_LONGTERM: long-term data
- * UBI_SHORTTERM: short-term data
- * UBI_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_LONGTERM  = 1,
-       UBI_SHORTTERM = 2,
-       UBI_UNKNOWN   = 3,
-};
-
 /*
  * UBI volume type constants.
  *
@@ -221,13 +205,14 @@ enum {
 };
 
 /*
- * UBI set property ioctl constants
+ * UBI set volume property ioctl constants.
  *
- * @UBI_PROP_DIRECT_WRITE: allow / disallow user to directly write and
- *                         erase individual eraseblocks on dynamic volumes
+ * @UBI_VOL_PROP_DIRECT_WRITE: allow (any non-zero value) or disallow (value 0)
+ *                             user to directly write and erase individual
+ *                             eraseblocks on dynamic volumes
  */
 enum {
-       UBI_PROP_DIRECT_WRITE = 1,
+       UBI_VOL_PROP_DIRECT_WRITE = 1,
 };
 
 /**
@@ -306,7 +291,7 @@ struct ubi_mkvol_req {
        int16_t name_len;
        int8_t padding2[4];
        char name[UBI_MAX_VOLUME_NAME + 1];
-} __attribute__ ((packed));
+} __attribute__((packed));
 
 /**
  * struct ubi_rsvol_req - a data structure used in volume re-size requests.
@@ -322,7 +307,7 @@ struct ubi_mkvol_req {
 struct ubi_rsvol_req {
        int64_t bytes;
        int32_t vol_id;
-} __attribute__ ((packed));
+} __attribute__((packed));
 
 /**
  * struct ubi_rnvol_req - volumes re-name request.
@@ -364,47 +349,56 @@ struct ubi_rnvol_req {
                int8_t  padding2[2];
                char    name[UBI_MAX_VOLUME_NAME + 1];
        } ents[UBI_MAX_RNVOL];
-} __attribute__ ((packed));
+} __attribute__((packed));
 
 /**
  * struct ubi_leb_change_req - a data structure used in atomic LEB change
  *                             requests.
  * @lnum: logical eraseblock number to change
  * @bytes: how many bytes will be written to the logical eraseblock
- * @dtype: data type (%UBI_LONGTERM, %UBI_SHORTTERM, %UBI_UNKNOWN)
+ * @dtype: pass "3" for better compatibility with old kernels
  * @padding: reserved for future, not used, has to be zeroed
+ *
+ * The @dtype field used to inform UBI about what kind of data will be written
+ * to the LEB: long term (value 1), short term (value 2), unknown (value 3).
+ * UBI tried to pick a PEB with lower erase counter for short term data and a
+ * PEB with higher erase counter for long term data. But this was not really
+ * used because users usually do not know this and could easily mislead UBI. We
+ * removed this feature in May 2012. UBI currently just ignores the @dtype
+ * field. But for better compatibility with older kernels it is recommended to
+ * set @dtype to 3 (unknown).
  */
 struct ubi_leb_change_req {
        int32_t lnum;
        int32_t bytes;
-       int8_t  dtype;
+       int8_t  dtype; /* obsolete, do not use! */
        int8_t  padding[7];
-} __attribute__ ((packed));
+} __attribute__((packed));
 
 /**
  * struct ubi_map_req - a data structure used in map LEB requests.
+ * @dtype: pass "3" for better compatibility with old kernels
  * @lnum: logical eraseblock number to unmap
- * @dtype: data type (%UBI_LONGTERM, %UBI_SHORTTERM, %UBI_UNKNOWN)
  * @padding: reserved for future, not used, has to be zeroed
  */
 struct ubi_map_req {
        int32_t lnum;
-       int8_t  dtype;
+       int8_t  dtype; /* obsolete, do not use! */
        int8_t  padding[3];
-} __attribute__ ((packed));
+} __attribute__((packed));
 
 
 /**
- * struct ubi_set_prop_req - a data structure used to set an ubi volume
- *                           property.
- * @property: property to set (%UBI_PROP_DIRECT_WRITE)
+ * struct ubi_set_vol_prop_req - a data structure used to set an UBI volume
+ *                               property.
+ * @property: property to set (%UBI_VOL_PROP_DIRECT_WRITE)
  * @padding: reserved for future, not used, has to be zeroed
  * @value: value to set
  */
-struct ubi_set_prop_req {
-       uint8_t  property;
-       uint8_t  padding[7];
-       uint64_t value;
-}  __attribute__ ((packed));
+struct ubi_set_vol_prop_req {
+       uint8_t  property;
+       uint8_t  padding[7];
+       uint64_t value;
+}  __attribute__((packed));
 
 #endif /* __UBI_USER_H__ */
index 60002ff06960537e6df4b630ff7c44fc912253ce..f6d43522eb3632b8e1d763d1ee18187dce8e1dcd 100644 (file)
@@ -410,7 +410,7 @@ int create_lpt(struct ubifs_info *c)
                        alen = ALIGN(len, c->min_io_size);
                        set_ltab(c, lnum, c->leb_size - alen, alen - len);
                        memset(p, 0xff, alen - len);
-                       err = write_leb(lnum++, alen, buf, UBI_SHORTTERM);
+                       err = write_leb(lnum++, alen, buf);
                        if (err)
                                goto out;
                        p = buf;
@@ -452,7 +452,7 @@ int create_lpt(struct ubifs_info *c)
                                set_ltab(c, lnum, c->leb_size - alen,
                                            alen - len);
                                memset(p, 0xff, alen - len);
-                               err = write_leb(lnum++, alen, buf, UBI_SHORTTERM);
+                               err = write_leb(lnum++, alen, buf);
                                if (err)
                                        goto out;
                                p = buf;
@@ -499,7 +499,7 @@ int create_lpt(struct ubifs_info *c)
                        alen = ALIGN(len, c->min_io_size);
                        set_ltab(c, lnum, c->leb_size - alen, alen - len);
                        memset(p, 0xff, alen - len);
-                       err = write_leb(lnum++, alen, buf, UBI_SHORTTERM);
+                       err = write_leb(lnum++, alen, buf);
                        if (err)
                                goto out;
                        p = buf;
@@ -522,7 +522,7 @@ int create_lpt(struct ubifs_info *c)
                alen = ALIGN(len, c->min_io_size);
                set_ltab(c, lnum, c->leb_size - alen, alen - len);
                memset(p, 0xff, alen - len);
-               err = write_leb(lnum++, alen, buf, UBI_SHORTTERM);
+               err = write_leb(lnum++, alen, buf);
                if (err)
                        goto out;
                p = buf;
@@ -542,7 +542,7 @@ int create_lpt(struct ubifs_info *c)
 
        /* Write remaining buffer */
        memset(p, 0xff, alen - len);
-       err = write_leb(lnum, alen, buf, UBI_SHORTTERM);
+       err = write_leb(lnum, alen, buf);
        if (err)
                goto out;
 
index bb25dc3a677c2c7019810dc459bda71037901785..149806b197d21e31ad3b280366b578883c2df43d 100644 (file)
@@ -774,16 +774,15 @@ static void prepare_node(void *node, int len)
  * @lnum: LEB number
  * @len: length of data in the buffer
  * @buf: buffer (must be at least c->leb_size bytes)
- * @dtype: expected data type
  */
-int write_leb(int lnum, int len, void *buf, int dtype)
+int write_leb(int lnum, int len, void *buf)
 {
        off64_t pos = (off64_t)lnum * c->leb_size;
 
        dbg_msg(3, "LEB %d len %d", lnum, len);
        memset(buf + len, 0xff, c->leb_size - len);
        if (out_ubi)
-               if (ubi_leb_change_start(ubi, out_fd, lnum, c->leb_size, dtype))
+               if (ubi_leb_change_start(ubi, out_fd, lnum, c->leb_size))
                        return sys_err_msg("ubi_leb_change_start failed");
 
        if (lseek64(out_fd, pos, SEEK_SET) != pos)
@@ -800,11 +799,10 @@ int write_leb(int lnum, int len, void *buf, int dtype)
 /**
  * write_empty_leb - copy the image of an empty LEB to the output target.
  * @lnum: LEB number
- * @dtype: expected data type
  */
-static int write_empty_leb(int lnum, int dtype)
+static int write_empty_leb(int lnum)
 {
-       return write_leb(lnum, 0, leb_buf, dtype);
+       return write_leb(lnum, 0, leb_buf);
 }
 
 /**
@@ -851,9 +849,8 @@ static int do_pad(void *buf, int len)
  * @node: node
  * @len: node length
  * @lnum: LEB number
- * @dtype: expected data type
  */
-static int write_node(void *node, int len, int lnum, int dtype)
+static int write_node(void *node, int len, int lnum)
 {
        prepare_node(node, len);
 
@@ -861,7 +858,7 @@ static int write_node(void *node, int len, int lnum, int dtype)
 
        len = do_pad(leb_buf, len);
 
-       return write_leb(lnum, len, leb_buf, dtype);
+       return write_leb(lnum, len, leb_buf);
 }
 
 /**
@@ -973,7 +970,7 @@ static int flush_nodes(void)
        if (!head_offs)
                return 0;
        len = do_pad(leb_buf, head_offs);
-       err = write_leb(head_lnum, len, leb_buf, UBI_UNKNOWN);
+       err = write_leb(head_lnum, len, leb_buf);
        if (err)
                return err;
        set_lprops(head_lnum, head_offs, head_flags);
@@ -1901,7 +1898,7 @@ static int set_gc_lnum(void)
        int err;
 
        c->gc_lnum = head_lnum++;
-       err = write_empty_leb(c->gc_lnum, UBI_LONGTERM);
+       err = write_empty_leb(c->gc_lnum);
        if (err)
                return err;
        set_lprops(c->gc_lnum, 0, 0);
@@ -1977,7 +1974,7 @@ static int write_super(void)
        if (c->space_fixup)
                sup.flags |= cpu_to_le32(UBIFS_FLG_SPACE_FIXUP);
 
-       return write_node(&sup, UBIFS_SB_NODE_SZ, UBIFS_SB_LNUM, UBI_LONGTERM);
+       return write_node(&sup, UBIFS_SB_NODE_SZ, UBIFS_SB_LNUM);
 }
 
 /**
@@ -2020,13 +2017,11 @@ static int write_master(void)
        mst.total_dark   = cpu_to_le64(c->lst.total_dark);
        mst.leb_cnt      = cpu_to_le32(c->leb_cnt);
 
-       err = write_node(&mst, UBIFS_MST_NODE_SZ, UBIFS_MST_LNUM,
-                        UBI_SHORTTERM);
+       err = write_node(&mst, UBIFS_MST_NODE_SZ, UBIFS_MST_LNUM);
        if (err)
                return err;
 
-       err = write_node(&mst, UBIFS_MST_NODE_SZ, UBIFS_MST_LNUM + 1,
-                        UBI_SHORTTERM);
+       err = write_node(&mst, UBIFS_MST_NODE_SZ, UBIFS_MST_LNUM + 1);
        if (err)
                return err;
 
@@ -2046,14 +2041,14 @@ static int write_log(void)
        cs.ch.node_type = UBIFS_CS_NODE;
        cs.cmt_no = cpu_to_le64(0);
 
-       err = write_node(&cs, UBIFS_CS_NODE_SZ, lnum, UBI_UNKNOWN);
+       err = write_node(&cs, UBIFS_CS_NODE_SZ, lnum);
        if (err)
                return err;
 
        lnum += 1;
 
        for (i = 1; i < c->log_lebs; i++, lnum++) {
-               err = write_empty_leb(lnum, UBI_UNKNOWN);
+               err = write_empty_leb(lnum);
                if (err)
                        return err;
        }
@@ -2074,7 +2069,7 @@ static int write_lpt(void)
 
        lnum = c->nhead_lnum + 1;
        while (lnum <= c->lpt_last) {
-               err = write_empty_leb(lnum++, UBI_SHORTTERM);
+               err = write_empty_leb(lnum++);
                if (err)
                        return err;
        }
@@ -2091,7 +2086,7 @@ static int write_orphan_area(void)
 
        lnum = UBIFS_LOG_LNUM + c->log_lebs + c->lpt_lebs;
        for (i = 0; i < c->orph_lebs; i++, lnum++) {
-               err = write_empty_leb(lnum, UBI_SHORTTERM);
+               err = write_empty_leb(lnum);
                if (err)
                        return err;
        }
@@ -2137,7 +2132,7 @@ static int open_target(void)
                if (out_fd == -1)
                        return sys_err_msg("cannot open the UBI volume '%s'",
                                           output);
-               if (ubi_set_property(out_fd, UBI_PROP_DIRECT_WRITE, 1))
+               if (ubi_set_property(out_fd, UBI_VOL_PROP_DIRECT_WRITE, 1))
                        return sys_err_msg("ubi_set_property failed");
 
                if (check_volume_empty())
index c00dce038f991e40f4e217d65f586ac7b81a5c92..01161ef2ca9d1188ac098728720e555d6392a502 100644 (file)
@@ -129,7 +129,7 @@ extern struct ubifs_info info_;
 
 struct hashtable_itr;
 
-int write_leb(int lnum, int len, void *buf, int dtype);
+int write_leb(int lnum, int len, void *buf);
 int parse_devtable(const char *tbl_file);
 struct path_htbl_element *devtbl_find_path(const char *path);
 struct name_htbl_element *devtbl_find_name(struct path_htbl_element *ph_elt,
index 1d9a97ce0654cc34e3863ef6d116231a4c8bee82..615c1dd0a292f84ad039a5d79605d1d7ce740bd1 100644 (file)
@@ -179,7 +179,7 @@ static void *write_thread(void *ptr)
                return NULL;
        }
 
-       ret = ubi_set_property(fd, UBI_PROP_DIRECT_WRITE, 1);
+       ret = ubi_set_property(fd, UBI_VOL_PROP_DIRECT_WRITE, 1);
        if (ret) {
                failed("ubi_set_property");
                errmsg("cannot set property for \"%s\"\n", vol_node);
index dc03d0260310c695fda4fd81e08cbee389f76977..11a186b2f7e4706a45abdef8aac2efaad3106e39 100644 (file)
@@ -426,18 +426,17 @@ int ubi_update_start(libubi_t desc, int fd, long long bytes);
  * @fd: volume character device file descriptor
  * @lnum: LEB number to change
  * @bytes: how many bytes of new data will be written to the LEB
- * @dtype: data type (%UBI_LONGTERM, %UBI_SHORTTERM, %UBI_UNKNOWN)
  *
  * This function initiates atomic LEB change operation and returns %0 in case
  * of success and %-1 in case of error. he caller is assumed to write @bytes
  * data to the volume @fd afterward.
  */
-int ubi_leb_change_start(libubi_t desc, int fd, int lnum, int bytes, int dtype);
+int ubi_leb_change_start(libubi_t desc, int fd, int lnum, int bytes);
 
 /**
  * ubi_set_property - set volume propety.
  * @fd: volume character device file descriptor
- * @property: the property to change (%UBI_PROP_DIRECT_WRITE, etc)
+ * @property: the property to change (%UBI_VOL_PROP_DIRECT_WRITE, etc)
  * @value: new value of the changed property
  *
  * This function changes a property of a volume. Returns zero in case of
index c898e363b4017d8a183550831c71741afd327d80..7736dd40e5446a71acb83109f464628099f39c85 100644 (file)
@@ -1106,7 +1106,7 @@ int ubi_update_start(libubi_t desc, int fd, long long bytes)
        return 0;
 }
 
-int ubi_leb_change_start(libubi_t desc, int fd, int lnum, int bytes, int dtype)
+int ubi_leb_change_start(libubi_t desc, int fd, int lnum, int bytes)
 {
        struct ubi_leb_change_req req;
 
@@ -1114,7 +1114,7 @@ int ubi_leb_change_start(libubi_t desc, int fd, int lnum, int bytes, int dtype)
        memset(&req, 0, sizeof(struct ubi_leb_change_req));
        req.lnum = lnum;
        req.bytes = bytes;
-       req.dtype = dtype;
+       req.dtype = 3;
 
        if (ioctl(fd, UBI_IOCEBCH, &req))
                return -1;
@@ -1346,13 +1346,13 @@ int ubi_get_vol_info1_nm(libubi_t desc, int dev_num, const char *name,
 
 int ubi_set_property(int fd, uint8_t property, uint64_t value)
 {
-       struct ubi_set_prop_req r;
+       struct ubi_set_vol_prop_req r;
 
-       memset(&r, 0, sizeof(struct ubi_set_prop_req));
+       memset(&r, 0, sizeof(struct ubi_set_vol_prop_req));
        r.property = property;
        r.value = value;
 
-       return ioctl(fd, UBI_IOCSETPROP, &r);
+       return ioctl(fd, UBI_IOCSETVOLPROP, &r);
 }
 
 int ubi_leb_unmap(int fd, int lnum)