[syslinux:master] ntfs: better way to check whether a MFT record is file or directory

syslinux-bot for Paulo Alcantara pcacjr at gmail.com
Sat Dec 17 21:19:26 PST 2011


Commit-ID:  5bcdd9254ec5c06d45bd5c56401115a067a5678b
Gitweb:     http://www.syslinux.org/commit/5bcdd9254ec5c06d45bd5c56401115a067a5678b
Author:     Paulo Alcantara <pcacjr at gmail.com>
AuthorDate: Fri, 29 Jul 2011 04:16:18 +0000
Committer:  Paulo Alcantara <pcacjr at gmail.com>
CommitDate: Sun, 11 Sep 2011 04:09:58 +0000

ntfs: better way to check whether a MFT record is file or directory

Signed-off-by: Paulo Alcantara <pcacjr at gmail.com>

---
 core/fs/ntfs/ntfs.c |   42 ++----------------------------------------
 core/fs/ntfs/ntfs.h |    5 +++++
 2 files changed, 7 insertions(+), 40 deletions(-)

diff --git a/core/fs/ntfs/ntfs.c b/core/fs/ntfs/ntfs.c
index 6ac48a2..a555f43 100644
--- a/core/fs/ntfs/ntfs.c
+++ b/core/fs/ntfs/ntfs.c
@@ -275,42 +275,9 @@ out:
     return -1;
 }
 
-static enum dirent_type get_inode_mode(MFT_RECORD *mrec)
+static inline enum dirent_type get_inode_mode(MFT_RECORD *mrec)
 {
-    ATTR_RECORD *attr;
-    FILE_NAME_ATTR *fn;
-    bool infile = false;
-    uint32_t dir_mask, root_mask, file_mask;
-    uint32_t dir, root, file;
-
-    attr = attr_lookup(NTFS_AT_FILENAME, mrec);
-    if (!attr) {
-        printf("No attribute found.\n");
-        return DT_UNKNOWN;
-    }
-
-    fn = (FILE_NAME_ATTR *)((uint8_t *)attr +
-                                attr->data.resident.value_offset);
-    dprintf("File attributes:        0x%X\n", fn->file_attrs);
-
-    dir_mask = NTFS_FILE_ATTR_ARCHIVE |
-                NTFS_FILE_ATTR_DUP_FILE_NAME_INDEX_PRESENT;
-    root_mask = NTFS_FILE_ATTR_READONLY | NTFS_FILE_ATTR_HIDDEN |
-                NTFS_FILE_ATTR_SYSTEM |
-                NTFS_FILE_ATTR_DUP_FILE_NAME_INDEX_PRESENT;
-    file_mask = NTFS_FILE_ATTR_ARCHIVE;
-
-    dir = fn->file_attrs & ~dir_mask;
-    root = fn->file_attrs & ~root_mask;
-    file = fn->file_attrs & ~file_mask;
-
-    dprintf("dir = 0x%X\n", dir);
-    dprintf("root= 0x%X\n", root);
-    dprintf("file = 0x%X\n", file);
-    if (((!dir && root) || (!dir && !root)) && !file)
-        infile = true;
-
-    return infile ? DT_REG : DT_DIR;
+    return mrec->flags & MFT_RECORD_IS_DIRECTORY ? DT_DIR : DT_REG;
 }
 
 static int index_inode_setup(struct fs_info *fs, block_t start_block,
@@ -341,11 +308,6 @@ static int index_inode_setup(struct fs_info *fs, block_t start_block,
     NTFS_PVT(inode)->here = start_block;
 
     d_type = get_inode_mode(mrec);
-    if (d_type == DT_UNKNOWN) {
-        dprintf("Failed on determining inode's mode\n");
-        goto out;
-    }
-
     if (d_type == DT_DIR) {    /* directory stuff */
         dprintf("Got a directory.\n");
         attr = attr_lookup(NTFS_AT_INDEX_ROOT, mrec);
diff --git a/core/fs/ntfs/ntfs.h b/core/fs/ntfs/ntfs.h
index eb5e3b6..1da93b2 100644
--- a/core/fs/ntfs/ntfs.h
+++ b/core/fs/ntfs/ntfs.h
@@ -215,6 +215,11 @@ typedef enum {
     FILE_reserved16     = 16,
 } NTFS_SYSTEM_FILES;
 
+enum {
+    MFT_RECORD_IN_USE       = 0x0001,
+    MFT_RECORD_IS_DIRECTORY = 0x0002,
+} __attribute__((__packed__));
+
 typedef struct {
     uint32_t magic;
     uint16_t usa_ofs;


More information about the Syslinux-commits mailing list