]> www.infradead.org Git - users/hch/xfsprogs.git/commitdiff
xfs: kill xfs_dir2_inou_t
authorChristoph Hellwig <hch@lst.de>
Wed, 10 Aug 2016 01:29:36 +0000 (11:29 +1000)
committerDave Chinner <david@fromorbit.com>
Wed, 10 Aug 2016 01:29:36 +0000 (11:29 +1000)
Source kernel commit: 266b6969c3dfd3c81d8601754c8b0e25bb52615b

And use an array of unsigned char values directly to avoid problems
with architectures that pad the size of structures.  This also gets
rid of the xfs_dir2_ino4_t and xfs_dir2_ino8_t types, and introduces
new constants for the size of 4 and 8 bytes as well as the size
difference between the two.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
db/dir2.h
db/dir2sf.c
db/faddr.c
db/field.c
libxfs/xfs_da_format.c
libxfs/xfs_da_format.h
libxfs/xfs_dir2_sf.c

index 5054493590b06d6324740ea2ae68757f1e61ddf7..0c2a62ec7f778d1ee293745e8c24504036a8f6ab 100644 (file)
--- a/db/dir2.h
+++ b/db/dir2.h
@@ -53,9 +53,9 @@ extern const field_t  dir3_data_union_flds[];
 extern const field_t   da3_blkinfo_flds[];
 extern const field_t   da3_node_hdr_flds[];
 
-static inline xfs_dir2_inou_t *xfs_dir2_sf_inumberp(xfs_dir2_sf_entry_t *sfep)
+static inline uint8_t *xfs_dir2_sf_inumberp(xfs_dir2_sf_entry_t *sfep)
 {
-       return (xfs_dir2_inou_t *)&(sfep)->name[(sfep)->namelen];
+       return &(sfep)->name[(sfep)->namelen];
 }
 
 extern int     dir2_data_union_size(void *obj, int startoff, int idx);
index d2b02c1c547af60bc6c748567fff6e56c77c3103..c025bc54eccbe40429ed7e38a94ab32c60ca891e 100644 (file)
@@ -41,12 +41,9 @@ const field_t        dir2sf_flds[] = {
        { NULL }
 };
 
-#define UOFF(f)        bitize(offsetof(xfs_dir2_inou_t, f))
 const field_t  dir2_inou_flds[] = {
-       { "i8", FLDT_DIR2_INO8, OI(UOFF(i8)), dir2_inou_i8_count, FLD_COUNT,
-         TYP_INODE },
-       { "i4", FLDT_DIR2_INO4, OI(UOFF(i4)), dir2_inou_i4_count, FLD_COUNT,
-         TYP_INODE },
+       { "i8", FLDT_DIR2_INO8, 0, dir2_inou_i8_count, FLD_COUNT, TYP_INODE },
+       { "i4", FLDT_DIR2_INO4, 0, dir2_inou_i4_count, FLD_COUNT, TYP_INODE },
        { NULL }
 };
 
@@ -110,9 +107,7 @@ dir2_inou_size(
        ASSERT(bitoffs(startoff) == 0);
        ASSERT(idx == 0);
        sf = (struct xfs_dir2_sf_hdr *)XFS_DFORK_DPTR(dip);
-       return bitize(sf->i8count ?
-                     (uint)sizeof(xfs_dir2_ino8_t) :
-                     (uint)sizeof(xfs_dir2_ino4_t));
+       return bitize(sf->i8count ? XFS_INO64_SIZE : XFS_INO32_SIZE);
 }
 
 static int
index e368d0da8f66b96c90d7d37138ee6c21353a3991..877200bf808de13535a626ca0a399a5aff297c10 100644 (file)
@@ -363,10 +363,9 @@ fa_ino4(
        typnm_t         next)
 {
        xfs_ino_t       ino;
-       xfs_dir2_ino4_t ino4;
 
        ASSERT(next == TYP_INODE);
-       ino = (xfs_ino_t)getbitval(obj, bit, bitsz(ino4), BVUNSIGNED);
+       ino = (xfs_ino_t)getbitval(obj, bit, bitsz(XFS_INO32_SIZE), BVUNSIGNED);
        if (ino == NULLFSINO) {
                dbprintf(_("null inode number, cannot set new addr\n"));
                return;
@@ -381,10 +380,9 @@ fa_ino8(
        typnm_t         next)
 {
        xfs_ino_t       ino;
-       xfs_dir2_ino8_t ino8;
 
        ASSERT(next == TYP_INODE);
-       ino = (xfs_ino_t)getbitval(obj, bit, bitsz(ino8), BVUNSIGNED);
+       ino = (xfs_ino_t)getbitval(obj, bit, bitsz(XFS_INO64_SIZE), BVUNSIGNED);
        if (ino == NULLFSINO) {
                dbprintf(_("null inode number, cannot set new addr\n"));
                return;
index a9d4a3a7a2359ca3ab09e8ff3a0837db1371d15a..26f521a5482d07706c84c72c435f95688507a802 100644 (file)
@@ -206,10 +206,10 @@ const ftattr_t    ftattrtab[] = {
          dir2_data_union_flds },
        { FLDT_DIR2_FREE_HDR, "dir2_free_hdr", NULL, (char *)dir2_free_hdr_flds,
          SI(bitsz(xfs_dir2_free_hdr_t)), 0, NULL, dir2_free_hdr_flds },
-       { FLDT_DIR2_INO4, "dir2_ino4", fp_num, "%u", SI(bitsz(xfs_dir2_ino4_t)),
-         0, fa_ino4, NULL },
+       { FLDT_DIR2_INO4, "dir2_ino4", fp_num, "%u",
+         SI(bitize(XFS_INO32_SIZE)), 0, fa_ino4, NULL },
        { FLDT_DIR2_INO8, "dir2_ino8", fp_num, "%llu",
-         SI(bitsz(xfs_dir2_ino8_t)), 0, fa_ino8, NULL },
+         SI(bitize(XFS_INO64_SIZE)), 0, fa_ino8, NULL },
        { FLDT_DIR2_INOU, "dir2_inou", NULL, (char *)dir2_inou_flds,
          dir2_inou_size, FTARG_SIZE, NULL, dir2_inou_flds },
        { FLDT_DIR2_LEAF_ENTRY, "dir2_leaf_entry", NULL,
index e4c37f94866efffd977a3e30c1194378f89ec498..2b732b3c07d6e6b4eb1fa75308528feb2d1721f2 100644 (file)
@@ -40,8 +40,7 @@ xfs_dir2_sf_entsize(
        int count = sizeof(struct xfs_dir2_sf_entry);   /* namelen + offset */
 
        count += len;                                   /* name */
-       count += hdr->i8count ? sizeof(xfs_dir2_ino8_t) :
-                               sizeof(xfs_dir2_ino4_t); /* ino # */
+       count += hdr->i8count ? XFS_INO64_SIZE : XFS_INO32_SIZE; /* ino # */
        return count;
 }
 
@@ -125,33 +124,33 @@ xfs_dir3_sfe_put_ftype(
 static xfs_ino_t
 xfs_dir2_sf_get_ino(
        struct xfs_dir2_sf_hdr  *hdr,
-       xfs_dir2_inou_t         *from)
+       __uint8_t               *from)
 {
        if (hdr->i8count)
-               return get_unaligned_be64(&from->i8.i) & 0x00ffffffffffffffULL;
+               return get_unaligned_be64(from) & 0x00ffffffffffffffULL;
        else
-               return get_unaligned_be32(&from->i4.i);
+               return get_unaligned_be32(from);
 }
 
 static void
 xfs_dir2_sf_put_ino(
        struct xfs_dir2_sf_hdr  *hdr,
-       xfs_dir2_inou_t         *to,
+       __uint8_t               *to,
        xfs_ino_t               ino)
 {
        ASSERT((ino & 0xff00000000000000ULL) == 0);
 
        if (hdr->i8count)
-               put_unaligned_be64(ino, &to->i8.i);
+               put_unaligned_be64(ino, to);
        else
-               put_unaligned_be32(ino, &to->i4.i);
+               put_unaligned_be32(ino, to);
 }
 
 static xfs_ino_t
 xfs_dir2_sf_get_parent_ino(
        struct xfs_dir2_sf_hdr  *hdr)
 {
-       return xfs_dir2_sf_get_ino(hdr, &hdr->parent);
+       return xfs_dir2_sf_get_ino(hdr, hdr->parent);
 }
 
 static void
@@ -159,7 +158,7 @@ xfs_dir2_sf_put_parent_ino(
        struct xfs_dir2_sf_hdr  *hdr,
        xfs_ino_t               ino)
 {
-       xfs_dir2_sf_put_ino(hdr, &hdr->parent, ino);
+       xfs_dir2_sf_put_ino(hdr, hdr->parent, ino);
 }
 
 /*
@@ -173,8 +172,7 @@ xfs_dir2_sfe_get_ino(
        struct xfs_dir2_sf_hdr  *hdr,
        struct xfs_dir2_sf_entry *sfep)
 {
-       return xfs_dir2_sf_get_ino(hdr,
-                               (xfs_dir2_inou_t *)&sfep->name[sfep->namelen]);
+       return xfs_dir2_sf_get_ino(hdr, &sfep->name[sfep->namelen]);
 }
 
 static void
@@ -183,8 +181,7 @@ xfs_dir2_sfe_put_ino(
        struct xfs_dir2_sf_entry *sfep,
        xfs_ino_t               ino)
 {
-       xfs_dir2_sf_put_ino(hdr,
-                           (xfs_dir2_inou_t *)&sfep->name[sfep->namelen], ino);
+       xfs_dir2_sf_put_ino(hdr, &sfep->name[sfep->namelen], ino);
 }
 
 static xfs_ino_t
@@ -192,8 +189,7 @@ xfs_dir3_sfe_get_ino(
        struct xfs_dir2_sf_hdr  *hdr,
        struct xfs_dir2_sf_entry *sfep)
 {
-       return xfs_dir2_sf_get_ino(hdr,
-                       (xfs_dir2_inou_t *)&sfep->name[sfep->namelen + 1]);
+       return xfs_dir2_sf_get_ino(hdr, &sfep->name[sfep->namelen + 1]);
 }
 
 static void
@@ -202,8 +198,7 @@ xfs_dir3_sfe_put_ino(
        struct xfs_dir2_sf_entry *sfep,
        xfs_ino_t               ino)
 {
-       xfs_dir2_sf_put_ino(hdr,
-                       (xfs_dir2_inou_t *)&sfep->name[sfep->namelen + 1], ino);
+       xfs_dir2_sf_put_ino(hdr, &sfep->name[sfep->namelen + 1], ino);
 }
 
 
index a5f4d6ee2bb3f01aa51201d687d732f2a46793ae..f877bb17c6c349e1ad2a47a79991921834a6adaf 100644 (file)
@@ -208,22 +208,10 @@ typedef   xfs_off_t       xfs_dir2_off_t;
  */
 typedef        __uint32_t      xfs_dir2_db_t;
 
-/*
- * Inode number stored as 8 8-bit values.
- */
-typedef        struct { __uint8_t i[8]; } xfs_dir2_ino8_t;
-
-/*
- * Inode number stored as 4 8-bit values.
- * Works a lot of the time, when all the inode numbers in a directory
- * fit in 32 bits.
- */
-typedef struct { __uint8_t i[4]; } xfs_dir2_ino4_t;
+#define XFS_INO32_SIZE 4
+#define XFS_INO64_SIZE 8
+#define XFS_INO64_DIFF (XFS_INO64_SIZE - XFS_INO32_SIZE)
 
-typedef union {
-       xfs_dir2_ino8_t i8;
-       xfs_dir2_ino4_t i4;
-} xfs_dir2_inou_t;
 #define        XFS_DIR2_MAX_SHORT_INUM ((xfs_ino_t)0xffffffffULL)
 
 /*
@@ -240,7 +228,7 @@ typedef union {
 typedef struct xfs_dir2_sf_hdr {
        __uint8_t               count;          /* count of entries */
        __uint8_t               i8count;        /* count of 8-byte inode #s */
-       xfs_dir2_inou_t         parent;         /* parent dir inode number */
+       __uint8_t               parent[8];      /* parent dir inode number */
 } __arch_pack xfs_dir2_sf_hdr_t;
 
 typedef struct xfs_dir2_sf_entry {
@@ -251,16 +239,15 @@ typedef struct xfs_dir2_sf_entry {
         * A single byte containing the file type field follows the inode
         * number for version 3 directory entries.
         *
-        * A xfs_dir2_ino8_t or xfs_dir2_ino4_t follows here, at a
-        * variable offset after the name.
+        * A 64-bit or 32-bit inode number follows here, at a variable offset
+        * after the name.
         */
 } xfs_dir2_sf_entry_t;
 
 static inline int xfs_dir2_sf_hdr_size(int i8count)
 {
        return sizeof(struct xfs_dir2_sf_hdr) -
-               (i8count == 0) *
-               (sizeof(xfs_dir2_ino8_t) - sizeof(xfs_dir2_ino4_t));
+               (i8count == 0) * XFS_INO64_DIFF;
 }
 
 static inline xfs_dir2_data_aoff_t
index b4482aa7097dbf16629e4506fce7dfa429ebf115..0b1f17505404f5c84398f05d7abc21b9343cfc3d 100644 (file)
@@ -128,8 +128,8 @@ xfs_dir2_block_sfsize(
                       count * 3 * sizeof(__u8) +       /* namelen + offset */
                       namelen +                        /* name */
                       (i8count ?                       /* inumber */
-                               (uint)sizeof(xfs_dir2_ino8_t) * count :
-                               (uint)sizeof(xfs_dir2_ino4_t) * count);
+                               count * XFS_INO64_SIZE :
+                               count * XFS_INO32_SIZE);
                if (size > XFS_IFORK_DSIZE(dp))
                        return size;            /* size value is a failure */
        }
@@ -316,10 +316,7 @@ xfs_dir2_sf_addname(
                /*
                 * Yes, adjust the inode size.  old count + (parent + new)
                 */
-               incr_isize +=
-                       (sfp->count + 2) *
-                       ((uint)sizeof(xfs_dir2_ino8_t) -
-                        (uint)sizeof(xfs_dir2_ino4_t));
+               incr_isize += (sfp->count + 2) * XFS_INO64_DIFF;
                objchange = 1;
        }
 
@@ -894,11 +891,7 @@ xfs_dir2_sf_replace(
                int     error;                  /* error return value */
                int     newsize;                /* new inode size */
 
-               newsize =
-                       dp->i_df.if_bytes +
-                       (sfp->count + 1) *
-                       ((uint)sizeof(xfs_dir2_ino8_t) -
-                        (uint)sizeof(xfs_dir2_ino4_t));
+               newsize = dp->i_df.if_bytes + (sfp->count + 1) * XFS_INO64_DIFF;
                /*
                 * Won't fit as shortform, convert to block then do replace.
                 */
@@ -1019,10 +1012,7 @@ xfs_dir2_sf_toino4(
        /*
         * Compute the new inode size.
         */
-       newsize =
-               oldsize -
-               (oldsfp->count + 1) *
-               ((uint)sizeof(xfs_dir2_ino8_t) - (uint)sizeof(xfs_dir2_ino4_t));
+       newsize = oldsize - (oldsfp->count + 1) * XFS_INO64_DIFF;
        xfs_idata_realloc(dp, -oldsize, XFS_DATA_FORK);
        xfs_idata_realloc(dp, newsize, XFS_DATA_FORK);
        /*
@@ -1095,10 +1085,7 @@ xfs_dir2_sf_toino8(
        /*
         * Compute the new inode size (nb: entry count + 1 for parent)
         */
-       newsize =
-               oldsize +
-               (oldsfp->count + 1) *
-               ((uint)sizeof(xfs_dir2_ino8_t) - (uint)sizeof(xfs_dir2_ino4_t));
+       newsize = oldsize + (oldsfp->count + 1) * XFS_INO64_DIFF;
        xfs_idata_realloc(dp, -oldsize, XFS_DATA_FORK);
        xfs_idata_realloc(dp, newsize, XFS_DATA_FORK);
        /*