]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs: shortform directory offsets change for dir3 format
authorDave Chinner <dchinner@redhat.com>
Fri, 7 Jun 2013 00:25:36 +0000 (10:25 +1000)
committerBen Myers <bpm@sgi.com>
Tue, 6 Aug 2013 18:21:45 +0000 (13:21 -0500)
Because the header size for the CRC enabled directory blocks is
larger, the offset of the first entry into a directory block is
different to the dir2 format. The shortform directory stores the
dirent's offset so that it doesn't change when moving from shortform
to block form and back again, and hence it needs to take into
account the different header sizes to maintain the correct offsets.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Ben Myers <bpm@sgi.com>
Signed-off-by: Ben Myers <bpm@sgi.com>
db/check.c
include/xfs_dir2_format.h
libxfs/xfs_dir2_sf.c
repair/dir2.c

index b7855c0fa1e13401588ff20daf3a67716ad21baa..27107a07b6ba061fca6f93cf82b8615bc3789045 100644 (file)
@@ -3418,7 +3418,7 @@ process_sf_dir_v2(
                dbprintf(_("dir %lld entry . %lld\n"), id->ino, id->ino);
        (*dot)++;
        sfe = xfs_dir2_sf_firstentry(&sf->hdr);
-       offset = XFS_DIR2_DATA_FIRST_OFFSET;
+       offset = XFS_DIR3_DATA_FIRST_OFFSET(mp);
        for (i = sf->hdr.count - 1, i8 = 0; i >= 0; i--) {
                if ((__psint_t)sfe + xfs_dir2_sf_entsize(&sf->hdr,sfe->namelen) -
                    (__psint_t)sf > be64_to_cpu(dip->di_size)) {
index ce3626bb7794f463c56457deeee642762efe8c18..6dc884abe2c393f03970df35e29e760495cabb25 100644 (file)
@@ -221,16 +221,6 @@ xfs_dir2_sf_nextentry(struct xfs_dir2_sf_hdr *hdr,
 #define        XFS_DIR2_DATA_FIRSTDB(mp)       \
        xfs_dir2_byte_to_db(mp, XFS_DIR2_DATA_OFFSET)
 
-/*
- * Offsets of . and .. in data space (always block 0)
- */
-#define        XFS_DIR2_DATA_DOT_OFFSET        \
-       ((xfs_dir2_data_aoff_t)sizeof(struct xfs_dir2_data_hdr))
-#define        XFS_DIR2_DATA_DOTDOT_OFFSET     \
-       (XFS_DIR2_DATA_DOT_OFFSET + xfs_dir2_data_entsize(1))
-#define        XFS_DIR2_DATA_FIRST_OFFSET              \
-       (XFS_DIR2_DATA_DOTDOT_OFFSET + xfs_dir2_data_entsize(2))
-
 /*
  * Describe a free area in the data block.
  *
@@ -372,7 +362,20 @@ xfs_dir3_data_unused_p(struct xfs_dir2_data_hdr *hdr)
 
 /*
  * Offsets of . and .. in data space (always block 0)
- */
+ *
+ * The macros are used for shortform directories as they have no headers to read
+ * the magic number out of. Shortform directories need to know the size of the
+ * data block header because the sfe embeds the block offset of the entry into
+ * it so that it doesn't change when format conversion occurs. Bad Things Happen
+ * if we don't follow this rule.
+ */
+#define        XFS_DIR3_DATA_DOT_OFFSET(mp)    \
+       xfs_dir3_data_hdr_size(xfs_sb_version_hascrc(&(mp)->m_sb))
+#define        XFS_DIR3_DATA_DOTDOT_OFFSET(mp) \
+       (XFS_DIR3_DATA_DOT_OFFSET(mp) + xfs_dir2_data_entsize(1))
+#define        XFS_DIR3_DATA_FIRST_OFFSET(mp)          \
+       (XFS_DIR3_DATA_DOTDOT_OFFSET(mp) + xfs_dir2_data_entsize(2))
+
 static inline xfs_dir2_data_aoff_t
 xfs_dir3_data_dot_offset(struct xfs_dir2_data_hdr *hdr)
 {
index 6848d059d546b9240e2700a87c2bee62462f4409..cb2336862486607962a167079a4e2bf6d9a9807b 100644 (file)
@@ -519,7 +519,7 @@ xfs_dir2_sf_addname_hard(
         * to insert the new entry.
         * If it's going to end up at the end then oldsfep will point there.
         */
-       for (offset = XFS_DIR2_DATA_FIRST_OFFSET,
+       for (offset = XFS_DIR3_DATA_FIRST_OFFSET(dp->i_mount),
              oldsfep = xfs_dir2_sf_firstentry(oldsfp),
              add_datasize = xfs_dir2_data_entsize(args->namelen),
              eof = (char *)oldsfep == &buf[old_isize];
@@ -601,7 +601,7 @@ xfs_dir2_sf_addname_pick(
 
        sfp = (xfs_dir2_sf_hdr_t *)dp->i_df.if_u1.if_data;
        size = xfs_dir2_data_entsize(args->namelen);
-       offset = XFS_DIR2_DATA_FIRST_OFFSET;
+       offset = XFS_DIR3_DATA_FIRST_OFFSET(mp);
        sfep = xfs_dir2_sf_firstentry(sfp);
        holefit = 0;
        /*
@@ -672,7 +672,7 @@ xfs_dir2_sf_check(
        dp = args->dp;
 
        sfp = (xfs_dir2_sf_hdr_t *)dp->i_df.if_u1.if_data;
-       offset = XFS_DIR2_DATA_FIRST_OFFSET;
+       offset = XFS_DIR3_DATA_FIRST_OFFSET(dp->i_mount);
        ino = xfs_dir2_sf_get_parent_ino(sfp);
        i8count = ino > XFS_DIR2_MAX_SHORT_INUM;
 
index 9f1d50beaceb459d400db33b6bdc1fff77634ca4..2f13864ad685d2db3a5ed8ef0b2745a6363a50ef 100644 (file)
@@ -682,6 +682,7 @@ process_sf_dir2_fixi8(
  */
 static void
 process_sf_dir2_fixoff(
+       xfs_mount_t     *mp,
        xfs_dinode_t    *dip)
 {
        int                     i;
@@ -691,7 +692,7 @@ process_sf_dir2_fixoff(
 
        sfp = (xfs_dir2_sf_t *)XFS_DFORK_DPTR(dip);
        sfep = xfs_dir2_sf_firstentry(&sfp->hdr);
-       offset = XFS_DIR2_DATA_FIRST_OFFSET;
+       offset = XFS_DIR3_DATA_FIRST_OFFSET(mp);
 
        for (i = 0; i < sfp->hdr.count; i++) {
                xfs_dir2_sf_put_offset(sfep, offset);
@@ -745,7 +746,7 @@ process_sf_dir2(
        max_size = XFS_DFORK_DSIZE(dip, mp);
        num_entries = sfp->hdr.count;
        ino_dir_size = be64_to_cpu(dip->di_size);
-       offset = XFS_DIR2_DATA_FIRST_OFFSET;
+       offset = XFS_DIR3_DATA_FIRST_OFFSET(mp);
        bad_offset = *repair = 0;
 
        ASSERT(ino_dir_size <= max_size);
@@ -1102,7 +1103,7 @@ _("would have corrected entry offsets in directory %" PRIu64 "\n"),
                        do_warn(
 _("corrected entry offsets in directory %" PRIu64 "\n"),
                                ino);
-                       process_sf_dir2_fixoff(dip);
+                       process_sf_dir2_fixoff(mp, dip);
                        *dino_dirty = 1;
                        *repair = 1;
                }