]> www.infradead.org Git - mtd-utils.git/commitdiff
ubi-tools: fix compilation problems
authorArtem Bityutskiy <Artem.Bityutskiy@nokia.com>
Fri, 25 Jan 2008 09:22:00 +0000 (11:22 +0200)
committerArtem Bityutskiy <Artem.Bityutskiy@nokia.com>
Fri, 25 Jan 2008 09:22:00 +0000 (11:22 +0200)
It appears that older system do not expose __be32 and friends
to userspace, so use uint32_t and friends.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
include/mtd/ubi-header.h
include/mtd/ubi-user.h
ubi-utils/include/libubi.h
ubi-utils/include/libubigen.h
ubi-utils/old-tools/src/pfi2bin.c
ubi-utils/old-tools/src/unubi.c
ubi-utils/src/libubigen.c

index 69d5d7e22899133b8a6a59687e0b8508cbec2bdf..5dacbf7cdb2fe08d351d5bc3935e3f1be80ff3eb 100644 (file)
@@ -30,6 +30,7 @@
 #ifndef __UBI_HEADER_H__
 #define __UBI_HEADER_H__
 
+#include <stdint.h>
 #include <asm/byteorder.h>
 
 /* The version of UBI images supported by this implementation */
@@ -116,8 +117,8 @@ enum {
 #define UBI_VID_HDR_SIZE sizeof(struct ubi_vid_hdr)
 
 /* Sizes of UBI headers without the ending CRC */
-#define UBI_EC_HDR_SIZE_CRC  (UBI_EC_HDR_SIZE  - sizeof(__be32))
-#define UBI_VID_HDR_SIZE_CRC (UBI_VID_HDR_SIZE - sizeof(__be32))
+#define UBI_EC_HDR_SIZE_CRC  (UBI_EC_HDR_SIZE  - sizeof(uint32_t))
+#define UBI_VID_HDR_SIZE_CRC (UBI_VID_HDR_SIZE - sizeof(uint32_t))
 
 /**
  * struct ubi_ec_hdr - UBI erase counter header.
@@ -145,14 +146,14 @@ enum {
  * eraseblocks.
  */
 struct ubi_ec_hdr {
-       __be32  magic;
-       __u8    version;
-       __u8    padding1[3];
-       __be64  ec; /* Warning: the current limit is 31-bit anyway! */
-       __be32  vid_hdr_offset;
-       __be32  data_offset;
-       __u8    padding2[36];
-       __be32  hdr_crc;
+       uint32_t magic;
+       uint8_t  version;
+       uint8_t  padding1[3];
+       uint64_t ec; /* Warning: the current limit is 31-bit anyway! */
+       uint32_t vid_hdr_offset;
+       uint32_t data_offset;
+       uint8_t  padding2[36];
+       uint32_t hdr_crc;
 } __attribute__ ((packed));
 
 /**
@@ -270,22 +271,22 @@ struct ubi_ec_hdr {
  * software (say, cramfs) on top of the UBI volume.
  */
 struct ubi_vid_hdr {
-       __be32  magic;
-       __u8    version;
-       __u8    vol_type;
-       __u8    copy_flag;
-       __u8    compat;
-       __be32  vol_id;
-       __be32  lnum;
-       __be32  leb_ver; /* obsolete, to be removed, don't use */
-       __be32  data_size;
-       __be32  used_ebs;
-       __be32  data_pad;
-       __be32  data_crc;
-       __u8    padding1[4];
-       __be64  sqnum;
-       __u8    padding2[12];
-       __be32  hdr_crc;
+       uint32_t magic;
+       uint8_t  version;
+       uint8_t  vol_type;
+       uint8_t  copy_flag;
+       uint8_t  compat;
+       uint32_t vol_id;
+       uint32_t lnum;
+       uint32_t leb_ver; /* obsolete, to be removed, don't use */
+       uint32_t data_size;
+       uint32_t used_ebs;
+       uint32_t data_pad;
+       uint32_t data_crc;
+       uint8_t  padding1[4];
+       uint64_t sqnum;
+       uint8_t  padding2[12];
+       uint32_t hdr_crc;
 } __attribute__ ((packed));
 
 /* Internal UBI volumes count */
@@ -299,7 +300,9 @@ struct ubi_vid_hdr {
 
 /* The layout volume contains the volume table */
 
-#define UBI_LAYOUT_VOL_ID        UBI_INTERNAL_VOL_START
+#define UBI_LAYOUT_VOLUME_ID     UBI_INTERNAL_VOL_START
+#define UBI_LAYOUT_VOLUME_TYPE   UBI_VID_DYNAMIC
+#define UBI_LAYOUT_VOLUME_ALIGN  1
 #define UBI_LAYOUT_VOLUME_EBS    2
 #define UBI_LAYOUT_VOLUME_NAME   "layout volume"
 #define UBI_LAYOUT_VOLUME_COMPAT UBI_COMPAT_REJECT
@@ -314,7 +317,7 @@ struct ubi_vid_hdr {
 #define UBI_VTBL_RECORD_SIZE sizeof(struct ubi_vtbl_record)
 
 /* Size of the volume table record without the ending CRC */
-#define UBI_VTBL_RECORD_SIZE_CRC (UBI_VTBL_RECORD_SIZE - sizeof(__be32))
+#define UBI_VTBL_RECORD_SIZE_CRC (UBI_VTBL_RECORD_SIZE - sizeof(uint32_t))
 
 /**
  * struct ubi_vtbl_record - a record in the volume table.
@@ -355,16 +358,16 @@ struct ubi_vid_hdr {
  * Empty records contain all zeroes and the CRC checksum of those zeroes.
  */
 struct ubi_vtbl_record {
-       __be32  reserved_pebs;
-       __be32  alignment;
-       __be32  data_pad;
-       __u8    vol_type;
-       __u8    upd_marker;
-       __be16  name_len;
-       __u8    name[UBI_VOL_NAME_MAX+1];
-       __u8    flags;
-       __u8    padding[23];
-       __be32  crc;
+       uint32_t reserved_pebs;
+       uint32_t alignment;
+       uint32_t data_pad;
+       uint8_t  vol_type;
+       uint8_t  upd_marker;
+       uint16_t name_len;
+       uint8_t  name[UBI_VOL_NAME_MAX+1];
+       uint8_t  flags;
+       uint8_t  padding[23];
+       uint32_t crc;
 } __attribute__ ((packed));
 
 #endif /* !__UBI_HEADER_H__ */
index 4d184a7f80a847bc4c0ba49069198897662b2dd0..a7421f130cc019a3e4144090a3848bf338f3be4b 100644 (file)
@@ -63,7 +63,7 @@
  *
  * Volume update should be done via the %UBI_IOCVOLUP IOCTL command of the
  * corresponding UBI volume character device. A pointer to a 64-bit update
- * size should be passed to the IOCTL. After then, UBI expects user to write
+ * size should be passed to the IOCTL. After this, UBI expects user to write
  * this number of bytes to the volume character device. The update is finished
  * when the claimed number of bytes is passed. So, the volume update sequence
  * is something like:
  * ioctl(fd, UBI_IOCVOLUP, &image_size);
  * write(fd, buf, image_size);
  * close(fd);
+ *
+ * Atomic eraseblock change
+ * ~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ * Atomic eraseblock change operation is done via the %UBI_IOCEBCH IOCTL
+ * command of the corresponding UBI volume character device. A pointer to
+ * &struct ubi_leb_change_req has to be passed to the IOCTL. Then the user is
+ * expected to write the requested amount of bytes. This is similar to the
+ * "volume update" IOCTL.
  */
 
 /*
 #define UBI_IOCVOLUP _IOW(UBI_VOL_IOC_MAGIC, 0, int64_t)
 /* An eraseblock erasure command, used for debugging, disabled by default */
 #define UBI_IOCEBER _IOW(UBI_VOL_IOC_MAGIC, 1, int32_t)
+/* An atomic eraseblock change command */
+#define UBI_IOCEBCH _IOW(UBI_VOL_IOC_MAGIC, 2, int32_t)
 
 /* Maximum MTD device name length supported by UBI */
 #define MAX_UBI_MTD_NAME_LEN 127
 
+/*
+ * 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.
  *
  */
 enum {
        UBI_DYNAMIC_VOLUME = 3,
-       UBI_STATIC_VOLUME = 4,
+       UBI_STATIC_VOLUME  = 4,
 };
 
 /**
@@ -137,7 +165,7 @@ enum {
  *
  * This data structure is used to specify MTD device UBI has to attach and the
  * parameters it has to use. The number which should be assigned to the new UBI
- * device is passed in @ubi_num. UBI may automatically assing the number if
+ * device is passed in @ubi_num. UBI may automatically assign the number if
  * @UBI_DEV_NUM_AUTO is passed. In this case, the device number is returned in
  * @ubi_num.
  *
@@ -176,7 +204,7 @@ struct ubi_attach_req {
  * @padding2: reserved for future, not used, has to be zeroed
  * @name: volume name
  *
- * This structure is used by userspace programs when creating new volumes. The
+ * This structure is used by user-space programs when creating new volumes. The
  * @used_bytes field is only necessary when creating static volumes.
  *
  * The @alignment field specifies the required alignment of the volume logical
@@ -222,4 +250,19 @@ struct ubi_rsvol_req {
        int32_t vol_id;
 } __attribute__ ((packed));
 
+/**
+ * struct ubi_leb_change_req - a data structure used in atomic logical
+ *                             eraseblock 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)
+ * @padding: reserved for future, not used, has to be zeroed
+ */
+struct ubi_leb_change_req {
+       int32_t lnum;
+       int32_t bytes;
+       uint8_t dtype;
+       uint8_t padding[7];
+} __attribute__ ((packed));
+
 #endif /* __UBI_USER_H__ */
index 0cdb67c06eaf70a4bb6b6a27855bb1fdae2dba38..61d886f846753cee5e3be5821b36a8bd639e2a9e 100644 (file)
@@ -23,9 +23,9 @@
 #ifndef __LIBUBI_H__
 #define __LIBUBI_H__
 
+#include <ctype.h>
 #include <stdint.h>
 #include <mtd/ubi-user.h>
-#include <ctype.h>
 #include <mtd/ubi-header.h>
 
 #ifdef __cplusplus
index f5c76161e5bdcd009b164dac3e8decfb432ddc13..1b659b5d89c75dfd85d2972dd841128fad437ceb 100644 (file)
@@ -27,7 +27,7 @@
 
 #include <stdint.h>
 #include <stdio.h>
-#include <asm/byteorder.h>
+#include <endian.h>
 
 #ifdef __cplusplus
 extern "C" {
index 7f31938d6cd48829b4fab19cdd62eb0b133acb04..fc1676047f26b620303afad37e794aadccf1670f 100644 (file)
@@ -359,7 +359,7 @@ write_ubi_volume_table(pdd_data_t pdd, list_t raw_pebs,
         * introduce this stupid mechanism. Until no final
         * decision of the VTAB structure is made... Good enough.
         */
-       rc = ubigen_create(&u, UBI_LAYOUT_VOL_ID, UBI_VID_DYNAMIC,
+       rc = ubigen_create(&u, UBI_LAYOUT_VOLUME_ID, UBI_VID_DYNAMIC,
                           pdd->eb_size, DEFAULT_ERASE_COUNT,
                           1, UBI_VERSION,
                           pdd->vid_hdr_offset, UBI_COMPAT_REJECT,
@@ -389,7 +389,7 @@ write_ubi_volume_table(pdd_data_t pdd, list_t raw_pebs,
        memcpy(ptr, vol_tab, vol_tab_size_limit);
        fp_leb = my_fmemopen(ptr, leb_size, "r");
 
-       rc = ubigen_create(&u, UBI_LAYOUT_VOL_ID, UBI_VID_DYNAMIC,
+       rc = ubigen_create(&u, UBI_LAYOUT_VOLUME_ID, UBI_VID_DYNAMIC,
                           pdd->eb_size, DEFAULT_ERASE_COUNT,
                           1, UBI_VERSION, pdd->vid_hdr_offset,
                           UBI_COMPAT_REJECT, leb_size * UBI_LAYOUT_VOLUME_EBS,
index 5c1d3249b234e8ae2ca856a99878ab3dfb5a75dd..8d16192e5cb71ecbe18bdb9484f075ee501f6479 100644 (file)
@@ -431,7 +431,7 @@ extract_itable(FILE *fpin, struct eb_info *cur, size_t bsize, size_t num,
        fseek(fpin, __be32_to_cpu(cur->ec.data_offset), SEEK_CUR);
 
        /* prepare output file */
-       if (__be32_to_cpu(cur->vid.vol_id) != UBI_LAYOUT_VOL_ID)
+       if (__be32_to_cpu(cur->vid.vol_id) != UBI_LAYOUT_VOLUME_ID)
                return -2;
        memset(filename, 0, MAXPATH + 1);
        snprintf(filename, MAXPATH, FN_VITBL, path, num);
@@ -771,7 +771,7 @@ unubi_volumes(FILE* fpin, uint32_t *vols, size_t vc, struct args *a)
 
                /* extract info-table */
                if (a->itable &&
-                   (__be32_to_cpu(cur->vid.vol_id) == UBI_LAYOUT_VOL_ID)) {
+                   (__be32_to_cpu(cur->vid.vol_id) == UBI_LAYOUT_VOLUME_ID)) {
                        extract_itable(fpin, cur, a->bsize,
                                       itable_num, a->odir_path);
                        itable_num++;
index 83cea91f64c9f0d09c9d70afbbd9f37fd7642745..ff7602e8eccbed2f530a8b56ec219bd4148423bc 100644 (file)
@@ -302,7 +302,7 @@ int ubigen_write_layout_vol(const struct ubigen_info *ui,
                size = UBI_MAX_VOLUMES * UBI_VTBL_RECORD_SIZE;
 
        vi.bytes = ui->leb_size * UBI_LAYOUT_VOLUME_EBS;
-       vi.id = UBI_LAYOUT_VOL_ID;
+       vi.id = UBI_LAYOUT_VOLUME_ID;
        vi.alignment = 1;
        vi.data_pad = 0;
        vi.usable_leb_size = ui->leb_size;