]> git.hungrycats.org Git - linux/commitdiff
NTFS: Get rid of the ugly transparent union in fs/ntfs/dir.c::ntfs_readdir()
authorAnton Altaparmakov <aia21@cantab.net>
Wed, 22 Sep 2004 21:07:55 +0000 (22:07 +0100)
committerAnton Altaparmakov <aia21@cantab.net>
Wed, 22 Sep 2004 21:07:55 +0000 (22:07 +0100)
      and ntfs_filldir() as per suggestion from Al Viro.

Signed-off-by: Anton Altaparmakov <aia21@cantab.net>
fs/ntfs/ChangeLog
fs/ntfs/dir.c

index 028bd144609bfc6d80b83b644cd263a74a25a105..ee4ae5cfd646186430e9042283135c1862b8e5c3 100644 (file)
@@ -28,6 +28,8 @@ ToDo/Notes:
          ACLs yet.
        - Remove BKL use from ntfs_setattr() syncing up with the rest of the
          kernel.
+       - Get rid of the ugly transparent union in fs/ntfs/dir.c::ntfs_readdir()
+         and ntfs_filldir() as per suggestion from Al Viro.
 
 2.1.18 - Fix scheduling latencies at mount time as well as an endianness bug.
 
index d5edebe32a90f2538189d8dd4c90fcddffdcfe52..71ed2f21533148e1b69bbf0d235e9420f1b1ecc6 100644 (file)
@@ -999,23 +999,11 @@ dir_err_out:
 
 #endif
 
-typedef union {
-       INDEX_ROOT *ir;
-       INDEX_ALLOCATION *ia;
-} index_union __attribute__ ((__transparent_union__));
-
-typedef enum {
-       INDEX_TYPE_ROOT,        /* index root */
-       INDEX_TYPE_ALLOCATION,  /* index allocation */
-} INDEX_TYPE;
-
 /**
  * ntfs_filldir - ntfs specific filldir method
  * @vol:       current ntfs volume
  * @fpos:      position in the directory
  * @ndir:      ntfs inode of current directory
- * @index_type:        specifies whether @iu is an index root or an index allocation
- * @iu:                index root or index allocation attribute to which @ie belongs
  * @ia_page:   page in which the index allocation buffer @ie is in resides
  * @ie:                current index entry
  * @name:      buffer to use for the converted name
@@ -1036,8 +1024,7 @@ typedef enum {
  * would need to drop the lock immediately anyway.
  */
 static inline int ntfs_filldir(ntfs_volume *vol, loff_t *fpos,
-               ntfs_inode *ndir, const INDEX_TYPE index_type,
-               index_union iu, struct page *ia_page, INDEX_ENTRY *ie,
+               ntfs_inode *ndir, struct page *ia_page, INDEX_ENTRY *ie,
                u8 *name, void *dirent, filldir_t filldir)
 {
        unsigned long mref;
@@ -1045,14 +1032,6 @@ static inline int ntfs_filldir(ntfs_volume *vol, loff_t *fpos,
        unsigned dt_type;
        FILE_NAME_TYPE_FLAGS name_type;
 
-       /* Advance the position even if going to skip the entry. */
-       if (index_type == INDEX_TYPE_ALLOCATION)
-               *fpos = (u8*)ie - (u8*)iu.ia +
-                               (sle64_to_cpu(iu.ia->index_block_vcn) <<
-                               ndir->itype.index.vcn_size_bits) +
-                               vol->mft_record_size;
-       else /* if (index_type == INDEX_TYPE_ROOT) */
-               *fpos = (u8*)ie - (u8*)iu.ir;
        name_type = ie->key.file_name.file_name_type;
        if (name_type == FILE_NAME_DOS) {
                ntfs_debug("Skipping DOS name space entry.");
@@ -1084,14 +1063,14 @@ static inline int ntfs_filldir(ntfs_volume *vol, loff_t *fpos,
         * Drop the page lock otherwise we deadlock with NFS when it calls
         * ->lookup since ntfs_lookup() will lock the same page.
         */
-       if (index_type == INDEX_TYPE_ALLOCATION)
+       if (ia_page)
                unlock_page(ia_page);
        ntfs_debug("Calling filldir for %s with len %i, fpos 0x%llx, inode "
                        "0x%lx, DT_%s.", name, name_len, *fpos, mref,
                        dt_type == DT_DIR ? "DIR" : "REG");
        rc = filldir(dirent, name, name_len, *fpos, mref, dt_type);
        /* Relock the page but not if we are aborting ->readdir. */
-       if (!rc && index_type == INDEX_TYPE_ALLOCATION)
+       if (!rc && ia_page)
                lock_page(ia_page);
        return rc;
 }
@@ -1244,9 +1223,11 @@ static int ntfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
                /* Skip index root entry if continuing previous readdir. */
                if (ir_pos > (u8*)ie - (u8*)ir)
                        continue;
+               /* Advance the position even if going to skip the entry. */
+               fpos = (u8*)ie - (u8*)ir;
                /* Submit the name to the filldir callback. */
-               rc = ntfs_filldir(vol, &fpos, ndir, INDEX_TYPE_ROOT, ir, NULL,
-                               ie, name, dirent, filldir);
+               rc = ntfs_filldir(vol, &fpos, ndir, NULL, ie, name, dirent,
+                               filldir);
                if (rc) {
                        kfree(ir);
                        goto abort;
@@ -1420,14 +1401,19 @@ find_next_index_buffer:
                /* Skip index block entry if continuing previous readdir. */
                if (ia_pos - ia_start > (u8*)ie - (u8*)ia)
                        continue;
+               /* Advance the position even if going to skip the entry. */
+               fpos = (u8*)ie - (u8*)ia +
+                               (sle64_to_cpu(ia->index_block_vcn) <<
+                               ndir->itype.index.vcn_size_bits) +
+                               vol->mft_record_size;
                /*
                 * Submit the name to the @filldir callback.  Note,
                 * ntfs_filldir() drops the lock on @ia_page but it retakes it
                 * before returning, unless a non-zero value is returned in
                 * which case the page is left unlocked.
                 */
-               rc = ntfs_filldir(vol, &fpos, ndir, INDEX_TYPE_ALLOCATION, ia,
-                               ia_page, ie, name, dirent, filldir);
+               rc = ntfs_filldir(vol, &fpos, ndir, ia_page, ie, name, dirent,
+                               filldir);
                if (rc) {
                        /* @ia_page is already unlocked in this case. */
                        ntfs_unmap_page(ia_page);