aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaulo Alcantara <pcacjr@gmail.com>2011-09-07 22:02:56 +0000
committerPaulo Alcantara <pcacjr@gmail.com>2011-09-15 03:32:17 +0000
commit7e6065d5d1d8346683abf2f894d59c703fa60d87 (patch)
treee8173546f8ee620c92397f0b4bcc4602f0d68b2b
parent5b7ccf9012802cbacdf835dd260e510c8fda944b (diff)
downloadsyslinux-7e6065d5d1d8346683abf2f894d59c703fa60d87.tar.gz
syslinux-7e6065d5d1d8346683abf2f894d59c703fa60d87.tar.xz
syslinux-7e6065d5d1d8346683abf2f894d59c703fa60d87.zip
ntfs: cleanups
Signed-off-by: Paulo Alcantara <pcacjr@gmail.com>
-rw-r--r--core/fs/ntfs/ntfs.c170
-rw-r--r--core/fs/ntfs/ntfs.h178
-rw-r--r--core/fs/ntfs/runlist.h8
3 files changed, 116 insertions, 240 deletions
diff --git a/core/fs/ntfs/ntfs.c b/core/fs/ntfs/ntfs.c
index 03dec41d..1dc89e3b 100644
--- a/core/fs/ntfs/ntfs.c
+++ b/core/fs/ntfs/ntfs.c
@@ -68,7 +68,7 @@ static inline struct inode *new_ntfs_inode(struct fs_info *fs)
return inode;
}
-static void ntfs_fixups_writeback(struct fs_info *fs, NTFS_RECORD *nrec)
+static void ntfs_fixups_writeback(struct fs_info *fs, struct ntfs_record *nrec)
{
uint16_t *usa;
uint16_t usa_no;
@@ -170,7 +170,8 @@ out:
return -1;
}
-static MFT_RECORD *ntfs_mft_record_lookup_3_0(struct fs_info *fs, uint32_t file, block_t *blk)
+static struct ntfs_mft_record *ntfs_mft_record_lookup_3_0(struct fs_info *fs,
+ uint32_t file, block_t *blk)
{
const uint64_t mft_record_size = NTFS_SB(fs)->mft_record_size;
uint8_t *buf;
@@ -179,11 +180,11 @@ static MFT_RECORD *ntfs_mft_record_lookup_3_0(struct fs_info *fs, uint32_t file,
block_t right_blk;
uint64_t offset;
uint64_t next_offset;
- const unsigned mft_record_shift = ilog2(mft_record_size);
- const unsigned clust_byte_shift = NTFS_SB(fs)->clust_byte_shift;
- uint64_t lcn = NTFS_SB(fs)->mft_lcn;
+ const uint32_t mft_record_shift = ilog2(mft_record_size);
+ const uint32_t clust_byte_shift = NTFS_SB(fs)->clust_byte_shift;
+ uint64_t lcn;
int err;
- MFT_RECORD *mrec;
+ struct ntfs_mft_record *mrec;
buf = (uint8_t *)malloc(mft_record_size);
if (!buf)
@@ -202,9 +203,9 @@ static MFT_RECORD *ntfs_mft_record_lookup_3_0(struct fs_info *fs, uint32_t file,
break;
}
- ntfs_fixups_writeback(fs, (NTFS_RECORD *)buf);
+ ntfs_fixups_writeback(fs, (struct ntfs_record *)buf);
- mrec = (MFT_RECORD *)buf;
+ mrec = (struct ntfs_mft_record *)buf;
/* check if it has a valid magic number */
if (mrec->magic == NTFS_MAGIC_FILE) {
if (blk)
@@ -229,23 +230,29 @@ static MFT_RECORD *ntfs_mft_record_lookup_3_0(struct fs_info *fs, uint32_t file,
return NULL;
}
-static MFT_RECORD *ntfs_mft_record_lookup_3_1(struct fs_info *fs, uint32_t file, block_t *blk)
+static struct ntfs_mft_record *ntfs_mft_record_lookup_3_1(struct fs_info *fs,
+ uint32_t file, block_t *blk)
{
const uint64_t mft_record_size = NTFS_SB(fs)->mft_record_size;
uint8_t *buf;
+ const block_t mft_blk = NTFS_SB(fs)->mft_blk;
block_t cur_blk;
block_t right_blk;
- uint64_t offset = 0;
+ uint64_t offset;
uint64_t next_offset;
- uint64_t lcn = NTFS_SB(fs)->mft_lcn;
+ const uint32_t mft_record_shift = ilog2(mft_record_size);
+ const uint32_t clust_byte_shift = NTFS_SB(fs)->clust_byte_shift;
+ uint64_t lcn;
int err;
- MFT_RECORD *mrec;
+ struct ntfs_mft_record *mrec;
buf = (uint8_t *)malloc(mft_record_size);
if (!buf)
malloc_error("uint8_t *");
- cur_blk = blk ? *blk : 0;
+ lcn = NTFS_SB(fs)->mft_lcn + (file << mft_record_shift >> clust_byte_shift);
+ cur_blk = (lcn << clust_byte_shift >> BLOCK_SHIFT(fs)) - mft_blk;
+ offset = (file << mft_record_shift) % BLOCK_SIZE(fs);
for (;;) {
right_blk = cur_blk + NTFS_SB(fs)->mft_blk;
err = ntfs_read(fs, buf, mft_record_size, mft_record_size, &right_blk,
@@ -255,9 +262,9 @@ static MFT_RECORD *ntfs_mft_record_lookup_3_1(struct fs_info *fs, uint32_t file,
break;
}
- ntfs_fixups_writeback(fs, (NTFS_RECORD *)buf);
+ ntfs_fixups_writeback(fs, (struct ntfs_record *)buf);
- mrec = (MFT_RECORD *)buf;
+ mrec = (struct ntfs_mft_record *)buf;
/* Check if the NTFS 3.1 MFT record number matches */
if (mrec->magic == NTFS_MAGIC_FILE && mrec->mft_record_no == file) {
if (blk)
@@ -282,17 +289,18 @@ static MFT_RECORD *ntfs_mft_record_lookup_3_1(struct fs_info *fs, uint32_t file,
return NULL;
}
-static ATTR_RECORD *ntfs_attr_lookup(uint32_t type, const MFT_RECORD *mrec)
+static struct ntfs_attr_record *ntfs_attr_lookup(uint32_t type,
+ const struct ntfs_mft_record *mrec)
{
- ATTR_RECORD *attr;
+ struct ntfs_attr_record *attr;
/* sanity check */
if (!mrec || type == NTFS_AT_END)
return NULL;
- attr = (ATTR_RECORD *)((uint8_t *)mrec + mrec->attrs_offset);
+ attr = (struct ntfs_attr_record *)((uint8_t *)mrec + mrec->attrs_offset);
/* walk through the file attribute records */
- for (;; attr = (ATTR_RECORD *)((uint8_t *)attr + attr->len)) {
+ for (;; attr = (struct ntfs_attr_record *)((uint8_t *)attr + attr->len)) {
if (attr->type == NTFS_AT_END)
return NULL;
@@ -303,7 +311,7 @@ static ATTR_RECORD *ntfs_attr_lookup(uint32_t type, const MFT_RECORD *mrec)
return attr;
}
-static bool ntfs_filename_cmp(const char *dname, INDEX_ENTRY *ie)
+static bool ntfs_filename_cmp(const char *dname, struct ntfs_idx_entry *ie)
{
const uint16_t *entry_fn;
uint8_t entry_fn_len;
@@ -329,9 +337,9 @@ static bool ntfs_filename_cmp(const char *dname, INDEX_ENTRY *ie)
return true;
}
-static inline uint8_t *mapping_chunk_init(ATTR_RECORD *attr,
- struct mapping_chunk *chunk,
- uint32_t *offset)
+static inline uint8_t *mapping_chunk_init(struct ntfs_attr_record *attr,
+ struct mapping_chunk *chunk,
+ uint32_t *offset)
{
memset(chunk, 0, sizeof *chunk);
*offset = 0U;
@@ -415,7 +423,7 @@ out:
return -1;
}
-static inline enum dirent_type get_inode_mode(MFT_RECORD *mrec)
+static inline enum dirent_type get_inode_mode(struct ntfs_mft_record *mrec)
{
return mrec->flags & MFT_RECORD_IS_DIRECTORY ? DT_DIR : DT_REG;
}
@@ -424,12 +432,11 @@ static int index_inode_setup(struct fs_info *fs, unsigned long mft_no,
struct inode *inode)
{
uint64_t start_blk = 0;
- MFT_RECORD *mrec;
- ATTR_RECORD *attr;
+ struct ntfs_mft_record *mrec;
+ struct ntfs_attr_record *attr;
enum dirent_type d_type;
uint32_t len;
- INDEX_ROOT *ir;
- uint32_t clust_size;
+ struct ntfs_idx_root *ir;
uint8_t *attr_len;
struct mapping_chunk chunk;
int err;
@@ -457,32 +464,16 @@ static int index_inode_setup(struct fs_info *fs, unsigned long mft_no,
goto out;
}
- /* note: INDEX_ROOT is always resident */
- ir = (INDEX_ROOT *)((uint8_t *)attr +
+ /* note: struct ntfs_idx_root is always resident */
+ ir = (struct ntfs_idx_root *)((uint8_t *)attr +
attr->data.resident.value_offset);
len = attr->data.resident.value_len;
if ((uint8_t *)ir + len > (uint8_t *)mrec +
NTFS_SB(fs)->mft_record_size) {
- dprintf("Corrupt index\n");
+ printf("Corrupt index.\n");
goto out;
}
- NTFS_PVT(inode)->itype.index.collation_rule = ir->collation_rule;
- NTFS_PVT(inode)->itype.index.blk_size = ir->index_block_size;
- NTFS_PVT(inode)->itype.index.blk_size_shift =
- ilog2(NTFS_PVT(inode)->itype.index.blk_size);
-
- /* determine the size of a vcn in the index */
- clust_size = NTFS_PVT(inode)->itype.index.blk_size;
- if (NTFS_SB(fs)->clust_size <= clust_size) {
- NTFS_PVT(inode)->itype.index.vcn_size = NTFS_SB(fs)->clust_size;
- NTFS_PVT(inode)->itype.index.vcn_size_shift =
- NTFS_SB(fs)->clust_shift;
- } else {
- NTFS_PVT(inode)->itype.index.vcn_size = BLOCK_SIZE(fs);
- NTFS_PVT(inode)->itype.index.vcn_size_shift = BLOCK_SHIFT(fs);
- }
-
NTFS_PVT(inode)->in_idx_root = true;
} else if (d_type == DT_REG) { /* file stuff */
dprintf("Got a file.\n");
@@ -548,16 +539,16 @@ out:
static struct inode *ntfs_index_lookup(const char *dname, struct inode *dir)
{
struct fs_info *fs = dir->fs;
- MFT_RECORD *mrec;
+ struct ntfs_mft_record *mrec;
block_t blk;
uint64_t blk_offset;
- ATTR_RECORD *attr;
- INDEX_ROOT *ir;
+ struct ntfs_attr_record *attr;
+ struct ntfs_idx_root *ir;
uint32_t len;
- INDEX_ENTRY *ie;
+ struct ntfs_idx_entry *ie;
const uint64_t blk_size = UINT64_C(1) << BLOCK_SHIFT(fs);
uint8_t buf[blk_size];
- INDEX_BLOCK *iblk;
+ struct ntfs_idx_allocation *iblk;
int err;
uint8_t *stream;
uint8_t *attr_len;
@@ -568,8 +559,6 @@ static struct inode *ntfs_index_lookup(const char *dname, struct inode *dir)
int64_t last_lcn;
struct inode *inode;
- dprintf("ntfs_index_lookup() - mft record number: %d\n",
- NTFS_PVT(dir)->mft_no);
mrec = NTFS_SB(fs)->mft_record_lookup(fs, NTFS_PVT(dir)->mft_no, NULL);
if (!mrec) {
printf("No MFT record found.\n");
@@ -582,19 +571,19 @@ static struct inode *ntfs_index_lookup(const char *dname, struct inode *dir)
goto out;
}
- ir = (INDEX_ROOT *)((uint8_t *)attr +
+ ir = (struct ntfs_idx_root *)((uint8_t *)attr +
attr->data.resident.value_offset);
len = attr->data.resident.value_len;
/* sanity check */
if ((uint8_t *)ir + len > (uint8_t *)mrec + NTFS_SB(fs)->mft_record_size)
goto index_err;
- ie = (INDEX_ENTRY *)((uint8_t *)&ir->index +
+ ie = (struct ntfs_idx_entry *)((uint8_t *)&ir->index +
ir->index.entries_offset);
- for (;; ie = (INDEX_ENTRY *)((uint8_t *)ie + ie->len)) {
+ for (;; ie = (struct ntfs_idx_entry *)((uint8_t *)ie + ie->len)) {
/* bounds checks */
if ((uint8_t *)ie < (uint8_t *)mrec ||
- (uint8_t *)ie + sizeof(INDEX_ENTRY_HEADER) >
+ (uint8_t *)ie + sizeof(struct ntfs_idx_entry_header) >
(uint8_t *)&ir->index + ir->index.index_len ||
(uint8_t *)ie + ie->len >
(uint8_t *)&ir->index + ir->index.index_len)
@@ -603,7 +592,6 @@ static struct inode *ntfs_index_lookup(const char *dname, struct inode *dir)
/* last entry cannot contain a key. it can however contain
* a pointer to a child node in the B+ tree so we just break out
*/
- dprintf("(0) ie->flags: 0x%X\n", ie->flags);
if (ie->flags & INDEX_ENTRY_END)
break;
@@ -660,20 +648,21 @@ static struct inode *ntfs_index_lookup(const char *dname, struct inode *dir)
goto not_found;
}
- ntfs_fixups_writeback(fs, (NTFS_RECORD *)&buf);
+ ntfs_fixups_writeback(fs, (struct ntfs_record *)&buf);
- iblk = (INDEX_BLOCK *)&buf;
+ iblk = (struct ntfs_idx_allocation *)&buf;
if (iblk->magic != NTFS_MAGIC_INDX) {
printf("Not a valid INDX record.\n");
goto not_found;
}
- ie = (INDEX_ENTRY *)((uint8_t *)&iblk->index +
+ ie = (struct ntfs_idx_entry *)((uint8_t *)&iblk->index +
iblk->index.entries_offset);
- for (;; ie = (INDEX_ENTRY *)((uint8_t *)ie + ie->len)) {
+ for (;; ie = (struct ntfs_idx_entry *)((uint8_t *)ie +
+ ie->len)) {
/* bounds checks */
if ((uint8_t *)ie < (uint8_t *)iblk || (uint8_t *)ie +
- sizeof(INDEX_ENTRY_HEADER) >
+ sizeof(struct ntfs_idx_entry_header) >
(uint8_t *)&iblk->index + iblk->index.index_len ||
(uint8_t *)ie + ie->len >
(uint8_t *)&iblk->index + iblk->index.index_len)
@@ -736,7 +725,8 @@ index_err:
}
/* Convert an UTF-16LE LFN to OEM LFN */
-static uint8_t ntfs_cvt_filename(char *filename, INDEX_ENTRY *ie)
+static uint8_t ntfs_cvt_filename(char *filename,
+ const struct ntfs_idx_entry *ie)
{
const uint16_t *entry_fn;
uint8_t entry_fn_len;
@@ -806,8 +796,8 @@ static uint32_t ntfs_getfssec(struct file *file, char *buf, int sectors,
uint32_t ret;
struct fs_info *fs = file->fs;
struct inode *inode = file->inode;
- MFT_RECORD *mrec;
- ATTR_RECORD *attr;
+ struct ntfs_mft_record *mrec;
+ struct ntfs_attr_record *attr;
char *p;
non_resident = NTFS_PVT(inode)->non_resident;
@@ -857,17 +847,17 @@ static int ntfs_readdir(struct file *file, struct dirent *dirent)
{
struct fs_info *fs = file->fs;
struct inode *inode = file->inode;
- MFT_RECORD *mrec;
+ struct ntfs_mft_record *mrec;
block_t blk;
uint64_t blk_offset;
const uint64_t blk_size = UINT64_C(1) << BLOCK_SHIFT(fs);
- ATTR_RECORD *attr;
- INDEX_ROOT *ir;
+ struct ntfs_attr_record *attr;
+ struct ntfs_idx_root *ir;
uint32_t count;
int len;
- INDEX_ENTRY *ie = NULL;
+ struct ntfs_idx_entry *ie = NULL;
uint8_t buf[BLOCK_SIZE(fs)];
- INDEX_BLOCK *iblk;
+ struct ntfs_idx_allocation *iblk;
int err;
uint8_t *stream;
uint8_t *attr_len;
@@ -889,7 +879,7 @@ static int ntfs_readdir(struct file *file, struct dirent *dirent)
goto out;
}
- ir = (INDEX_ROOT *)((uint8_t *)attr +
+ ir = (struct ntfs_idx_root *)((uint8_t *)attr +
attr->data.resident.value_offset);
len = attr->data.resident.value_len;
/* sanity check */
@@ -903,7 +893,7 @@ static int ntfs_readdir(struct file *file, struct dirent *dirent)
idx_root_next_entry:
if (NTFS_PVT(inode)->in_idx_root) {
- ie = (INDEX_ENTRY *)(uint8_t *)file->offset;
+ ie = (struct ntfs_idx_entry *)(uint8_t *)file->offset;
if (ie->flags & INDEX_ENTRY_END) {
file->offset = 0;
NTFS_PVT(inode)->in_idx_root = false;
@@ -977,22 +967,22 @@ next_vcn:
goto not_found;
}
- ntfs_fixups_writeback(fs, (NTFS_RECORD *)&buf);
+ ntfs_fixups_writeback(fs, (struct ntfs_record *)&buf);
- iblk = (INDEX_BLOCK *)&buf;
+ iblk = (struct ntfs_idx_allocation *)&buf;
if (iblk->magic != NTFS_MAGIC_INDX) {
printf("Not a valid INDX record.\n");
goto not_found;
}
idx_block_next_entry:
- ie = (INDEX_ENTRY *)((uint8_t *)&iblk->index +
+ ie = (struct ntfs_idx_entry *)((uint8_t *)&iblk->index +
iblk->index.entries_offset);
count = NTFS_PVT(inode)->entries_count;
- for ( ; count--; ie = (INDEX_ENTRY *)((uint8_t *)ie + ie->len)) {
+ for ( ; count--; ie = (struct ntfs_idx_entry *)((uint8_t *)ie + ie->len)) {
/* bounds checks */
if ((uint8_t *)ie < (uint8_t *)iblk || (uint8_t *)ie +
- sizeof(INDEX_ENTRY_HEADER) >
+ sizeof(struct ntfs_idx_entry_header) >
(uint8_t *)&iblk->index + iblk->index.index_len ||
(uint8_t *)ie + ie->len >
(uint8_t *)&iblk->index + iblk->index.index_len)
@@ -1059,10 +1049,10 @@ static struct inode *ntfs_iget(const char *dname, struct inode *parent)
static struct inode *ntfs_iget_root(struct fs_info *fs)
{
uint64_t start_blk;
- MFT_RECORD * mrec;
- ATTR_RECORD * attr;
- VOLUME_INFORMATION * vol_info;
- struct inode * inode;
+ struct ntfs_mft_record *mrec;
+ struct ntfs_attr_record *attr;
+ struct ntfs_vol_info *vol_info;
+ struct inode *inode;
int err;
/* Fetch the $Volume MFT record */
@@ -1081,13 +1071,13 @@ static struct inode *ntfs_iget_root(struct fs_info *fs)
}
/* Note NTFS version and choose version-dependent functions */
- vol_info = (void *) ((char *) attr + attr->data.resident.value_offset);
+ vol_info = (void *)((char *)attr + attr->data.resident.value_offset);
NTFS_SB(fs)->major_ver = vol_info->major_ver;
NTFS_SB(fs)->minor_ver = vol_info->minor_ver;
if (vol_info->major_ver == 3 && vol_info->minor_ver == 0)
NTFS_SB(fs)->mft_record_lookup = ntfs_mft_record_lookup_3_0;
else if (vol_info->major_ver == 3 && vol_info->minor_ver == 1 &&
- mrec->mft_record_no == FILE_Volume)
+ mrec->mft_record_no == FILE_Volume)
NTFS_SB(fs)->mft_record_lookup = ntfs_mft_record_lookup_3_1;
/* Free MFT record */
@@ -1095,10 +1085,6 @@ static struct inode *ntfs_iget_root(struct fs_info *fs)
mrec = NULL;
inode = new_ntfs_inode(fs);
- if (!inode) {
- printf("Could not allocate root inode!\n");
- goto err_alloc_inode;
- }
inode->fs = fs;
err = index_inode_setup(fs, FILE_root, inode);
@@ -1112,8 +1098,6 @@ static struct inode *ntfs_iget_root(struct fs_info *fs)
err_setup:
free(inode);
-err_alloc_inode:
-
err_attr:
free(mrec);
@@ -1169,8 +1153,8 @@ static int ntfs_fs_init(struct fs_info *fs)
BLOCK_SIZE(fs) = 1 << BLOCK_SHIFT(fs);
sbi->mft_lcn = ntfs.mft_lclust;
- sbi->mft_blk = ntfs.mft_lclust << sbi->clust_shift <<
- SECTOR_SHIFT(fs) >> BLOCK_SHIFT(fs);
+ sbi->mft_blk = ntfs.mft_lclust << sbi->clust_shift << SECTOR_SHIFT(fs) >>
+ BLOCK_SHIFT(fs);
/* 16 MFT entries reserved for metadata files (approximately 16 KiB) */
sbi->mft_size = mft_record_shift << sbi->clust_shift << 4;
diff --git a/core/fs/ntfs/ntfs.h b/core/fs/ntfs/ntfs.h
index 50194dbb..cd8b9984 100644
--- a/core/fs/ntfs/ntfs.h
+++ b/core/fs/ntfs/ntfs.h
@@ -49,9 +49,9 @@ struct ntfs_bpb {
} __attribute__((__packed__));
/* Function type for an NTFS-version-dependent MFT record lookup */
-struct s_mft_record_;
-typedef struct s_mft_record_ * f_mft_record_lookup(struct fs_info *, uint32_t,
- block_t *);
+struct ntfs_mft_record;
+typedef struct ntfs_mft_record *f_mft_record_lookup(struct fs_info *,
+ uint32_t, block_t *);
struct ntfs_sb_info {
block_t mft_blk; /* The first MFT record block */
@@ -72,7 +72,7 @@ struct ntfs_sb_info {
uint8_t minor_ver; /* Minor version from $Volume */
/* NTFS-version-dependent MFT record lookup function to use */
- f_mft_record_lookup * mft_record_lookup;
+ f_mft_record_lookup *mft_record_lookup;
} __attribute__((__packed__));
/* The NTFS in-memory inode structure */
@@ -95,15 +95,6 @@ struct ntfs_inode {
struct runlist *rlist;
} non_resident;
} data;
- union {
- struct { /* It is a directory, $MFT, or an index inode */
- uint32_t blk_size;
- uint32_t vcn_size;
- uint32_t collation_rule;
- uint8_t blk_size_shift; /* log2 of the above */
- uint8_t vcn_size_shift; /* log2 of the above */
- } index;
- } itype;
uint32_t start_cluster; /* Starting cluster address */
sector_t start; /* Starting sector */
sector_t offset; /* Current sector offset */
@@ -173,17 +164,6 @@ enum {
NTFS_FILE_ATTR_DUP_VIEW_INDEX_PRESENT = 0x20000000,
};
-/* The collation rules for sorting views/indexes/etc (32-bit) */
-enum {
- NTFS_COLLATION_BINARY = 0x00,
- NTFS_COLLATION_FILE_NAME = 0x01,
- NTFS_COLLATION_UNICODE_STRING = 0x02,
- NTFS_COLLATION_NTOFS_ULONG = 0x10,
- NTFS_COLLATION_NTOFS_SID = 0x11,
- NTFS_COLLATION_NTOFS_SECURITY_HASH = 0x12,
- NTFS_COLLATION_NTOFS_ULONGS = 0x13,
-};
-
/*
* Magic identifiers present at the beginning of all ntfs record containing
* records (like mft records for example).
@@ -204,14 +184,14 @@ enum {
NTFS_MAGIC_EMPTY = 0xFFFFFFFF, /* Record is empty */
};
-typedef struct {
+struct ntfs_record {
uint32_t magic;
uint16_t usa_ofs;
uint16_t usa_count;
} __attribute__((__packed__)) NTFS_RECORD;
/* The $MFT metadata file types */
-typedef enum {
+enum ntfs_system_file {
FILE_MFT = 0,
FILE_MFTMirr = 1,
FILE_LogFile = 2,
@@ -229,14 +209,14 @@ typedef enum {
FILE_reserved14 = 14,
FILE_reserved15 = 15,
FILE_reserved16 = 16,
-} NTFS_SYSTEM_FILES;
+};
enum {
MFT_RECORD_IN_USE = 0x0001,
MFT_RECORD_IS_DIRECTORY = 0x0002,
} __attribute__((__packed__));
-typedef struct s_mft_record_ {
+struct ntfs_mft_record {
uint32_t magic;
uint16_t usa_ofs;
uint16_t usa_count;
@@ -251,10 +231,10 @@ typedef struct s_mft_record_ {
uint16_t next_attr_instance;
uint16_t reserved;
uint32_t mft_record_no;
-} __attribute__((__packed__)) MFT_RECORD; /* 48 bytes */
+} __attribute__((__packed__)); /* 48 bytes */
/* This is the version without the NTFS 3.1+ specific fields */
-typedef struct {
+struct ntfs_mft_record_old {
uint32_t magic;
uint16_t usa_ofs;
uint16_t usa_count;
@@ -267,7 +247,7 @@ typedef struct {
uint32_t bytes_allocated;
uint64_t base_mft_record;
uint16_t next_attr_instance;
-} __attribute__((__packed__)) MFT_RECORD_OLD; /* 42 bytes */
+} __attribute__((__packed__)); /* 42 bytes */
enum {
ATTR_DEF_INDEXABLE = 0x02,
@@ -279,31 +259,7 @@ enum {
ATTR_DEF_ALWAYS_LOG = 0x80,
};
-typedef struct {
- uint16_t name[0x40];
- uint32_t type;
- uint32_t display_rule;
- uint32_t collation_rule;
- uint32_t flags; /* Attr def flags */
- uint64_t min_size;
- uint64_t max_size;
-} __attribute__((__packed__)) ATTR_DEF;
-
-/* Attribute flags (16-bit) */
-enum {
- ATTR_IS_COMPRESSED = 0x0001,
- ATTR_COMPRESSION_MASK = 0x00FF,
-
- ATTR_IS_ENCRYPTED = 0x4000,
- ATTR_IS_SPARSE = 0x8000,
-} __attribute__((__packed__));
-
-/* Flags of resident attributes (8-bit) */
-enum {
- RESIDENT_ATTR_IS_INDEXED = 0x01,
-} __attribute__((__packed__));
-
-typedef struct {
+struct ntfs_attr_record {
uint32_t type; /* Attr. type code */
uint32_t len;
uint8_t non_resident;
@@ -329,47 +285,7 @@ typedef struct {
int64_t compressed_size;
} __attribute__((__packed__)) non_resident;
} __attribute__((__packed__)) data;
-} __attribute__((__packed__)) ATTR_RECORD;
-
-/* Attribute: Standard Information (0x10)
- * Note: always resident
- */
-typedef struct {
- int64_t ctime;
- int64_t atime;
- int64_t mtime;
- int64_t rtime;
- uint32_t file_attrs;
- union {
- struct { /* NTFS 1.2 (48 bytes) */
- uint8_t reserved12[12];
- } __attribute__((__packed__)) v1;
- struct { /* NTFS 3.x (72 bytes) */
- uint32_t max_version;
- uint32_t version;
- uint32_t class_id;
- uint32_t owner_id;
- uint32_t sec_id;
- uint64_t quota_charged;
- int64_t usn;
- } __attribute__((__packed__)) v3;
- } __attribute__((__packed__)) ver;
-} __attribute__((__packed__)) STANDARD_INFORMATION;
-
-/* Attribute: Attribute List (0x20)
- * Note: can be either resident or non-resident
- */
-typedef struct {
- uint32_t type;
- uint16_t len;
- uint8_t name_len;
- uint8_t name_offset;
- uint64_t lowest_vcn;
- uint64_t mft_ref;
- uint16_t instance;
- uint16_t name[0]; /* Name in Unicode */
- /* sizeof() = 26 + (attribute_name_length * 2) bytes */
-} __attribute__((__packed__)) ATTR_LIST_ENTRY;
+} __attribute__((__packed__));
#define NTFS_MAX_FILE_NAME_LEN 255
@@ -384,7 +300,7 @@ enum {
/* Attribute: Filename (0x30)
* Note: always resident
*/
-typedef struct {
+struct ntfs_filename_attr {
uint64_t parent_directory;
int64_t ctime;
int64_t atime;
@@ -395,7 +311,7 @@ typedef struct {
uint32_t file_attrs;
union {
struct {
- uint16_t __packed___ea_size;
+ uint16_t packed_ea_size;
uint16_t reserved; /* reserved for alignment */
} __attribute__((__packed__)) ea;
struct {
@@ -405,51 +321,33 @@ typedef struct {
uint8_t file_name_len;
uint8_t file_name_type;
uint16_t file_name[0]; /* File name in Unicode */
-} __attribute__((__packed__)) FILE_NAME_ATTR;
+} __attribute__((__packed__));
/* Attribute: Volume Name (0x60)
* Note: always resident
* Note: Present only in FILE_volume
*/
-typedef struct {
+struct ntfs_vol_name {
uint16_t name[0]; /* The name of the volume in Unicode */
-} __attribute__((__packed__)) VOLUME_NAME;
-
-/* Volume flags (16-bit) */
-enum {
- VOLUME_IS_DIRTY = 0x0001,
- VOLUME_RESIZE_LOG_FILE = 0x0002,
- VOLUME_UPGRADE_ON_MOUNT = 0x0004,
- VOLUME_MOUNTED_ON_NT4 = 0x0008,
-
- VOLUME_DELETE_USN_UNDERWAY = 0x0010,
- VOLUME_REPAIR_OBJECT_ID = 0x0020,
-
- VOLUME_CHKDSK_UNDERWAY = 0x4000,
- VOLUME_MODIFIED_BY_CHKDSK = 0x8000,
-
- VOLUME_FLAGS_MASK = 0xC03F,
-
- VOLUME_MUST_MOUNT_RO_MASK = 0xC027,
} __attribute__((__packed__));
/* Attribute: Volume Information (0x70)
* Note: always resident
* Note: present only in FILE_Volume
*/
-typedef struct {
+struct ntfs_vol_info {
uint64_t reserved;
uint8_t major_ver;
uint8_t minor_ver;
uint16_t flags; /* Volume flags */
-} __attribute__((__packed__)) VOLUME_INFORMATION;
+} __attribute__((__packed__));
/* Attribute: Data attribute (0x80)
* Note: can be either resident or non-resident
*/
-typedef struct {
+struct ntfs_data_attr {
uint8_t data[0];
-} __attribute__((__packed__)) DATA_ATTR;
+} __attribute__((__packed__));
/* Index header flags (8-bit) */
enum {
@@ -461,20 +359,20 @@ enum {
} __attribute__((__packed__));
/* Header for the indexes, describing the INDEX_ENTRY records, which
- * follow the INDEX_HEADER.
+ * follow the struct ntfs_idx_header.
*/
-typedef struct {
+struct ntfs_idx_header {
uint32_t entries_offset;
uint32_t index_len;
uint32_t allocated_size;
uint8_t flags; /* Index header flags */
uint8_t reserved[3]; /* Align to 8-byte boundary */
-} __attribute__((__packed__)) INDEX_HEADER;
+} __attribute__((__packed__));
/* Attribute: Index Root (0x90)
* Note: always resident
*/
-typedef struct {
+struct ntfs_idx_root {
uint32_t type; /* It is $FILE_NAME for directories, zero for view indexes.
* No other values allowed.
*/
@@ -482,22 +380,20 @@ typedef struct {
uint32_t index_block_size;
uint8_t clust_per_index_block;
uint8_t reserved[3];
- INDEX_HEADER index;
-} __attribute__((__packed__)) INDEX_ROOT;
+ struct ntfs_idx_header index;
+} __attribute__((__packed__));
/* Attribute: Index allocation (0xA0)
* Note: always non-resident, of course! :-)
*/
-typedef struct {
+struct ntfs_idx_allocation {
uint32_t magic;
uint16_t usa_ofs; /* Update Sequence Array offsets */
uint16_t usa_count; /* Update Sequence Array number in bytes */
int64_t lsn;
int64_t index_block_vcn; /* Virtual cluster number of the index block */
- INDEX_HEADER index;
-} __attribute__((__packed__)) INDEX_BLOCK;
-
-typedef INDEX_BLOCK INDEX_ALLOCATION;
+ struct ntfs_idx_header index;
+} __attribute__((__packed__));
enum {
INDEX_ENTRY_NODE = 1,
@@ -506,7 +402,7 @@ enum {
INDEX_ENTRY_SPACE_FILTER = 0xFFFF,
} __attribute__((__packed__));
-typedef struct {
+struct ntfs_idx_entry_header {
union {
struct { /* Only valid when INDEX_ENTRY_END is not set */
uint64_t indexed_file;
@@ -521,9 +417,9 @@ typedef struct {
uint16_t key_len;
uint16_t flags; /* Index entry flags */
uint16_t reserved; /* Align to 8-byte boundary */
-} __attribute__((__packed__)) INDEX_ENTRY_HEADER;
+} __attribute__((__packed__));
-typedef struct {
+struct ntfs_idx_entry {
union {
struct { /* Only valid when INDEX_ENTRY_END is not set */
uint64_t indexed_file;
@@ -539,7 +435,7 @@ typedef struct {
uint16_t flags; /* Index entry flags */
uint16_t reserved; /* Align to 8-byte boundary */
union {
- FILE_NAME_ATTR file_name;
+ struct ntfs_filename_attr file_name;
//SII_INDEX_KEY sii;
//SDH_INDEX_KEY sdh;
//GUID object_id;
@@ -547,11 +443,7 @@ typedef struct {
//SID sid;
uint32_t owner_id;
} __attribute__((__packed__)) key;
-} __attribute__((__packed__)) INDEX_ENTRY;
-
-typedef struct {
- uint8_t bitmap[0]; /* Array of bits */
-} __attribute__((__packed__)) BITMAP_ATTR;
+} __attribute__((__packed__));
static inline struct ntfs_sb_info *NTFS_SB(struct fs_info *fs)
{
diff --git a/core/fs/ntfs/runlist.h b/core/fs/ntfs/runlist.h
index b74c7d85..c1942338 100644
--- a/core/fs/ntfs/runlist.h
+++ b/core/fs/ntfs/runlist.h
@@ -31,7 +31,7 @@ struct runlist {
struct runlist *next;
};
-static struct runlist **tail;
+static struct runlist *tail;
static inline bool runlist_is_empty(struct runlist *rlist)
{
@@ -60,10 +60,10 @@ static inline void runlist_append(struct runlist **rlist,
if (runlist_is_empty(*rlist)) {
*rlist = n;
- *tail = n;
+ tail = n;
} else {
- (*tail)->next = n;
- *tail = n;
+ tail->next = n;
+ tail = n;
}
}