From: Paulo Alcantara Date: Sun, 12 Feb 2012 00:24:56 +0000 (-0300) Subject: ntfs: remove wrong checks X-Git-Tag: syslinux-4.06-pre2~4 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=83a76e01ba0172202adf0a0ebdac0fd9710ccae5;p=profile%2Fivi%2Fsyslinux.git ntfs: remove wrong checks As an attribute may be stored in a NTFS record rather than the current record being used, these checks wouldn't work anymore for this case. Signed-off-by: Paulo Alcantara --- diff --git a/core/fs/ntfs/ntfs.c b/core/fs/ntfs/ntfs.c index 75690fe..0f6cc44 100644 --- a/core/fs/ntfs/ntfs.c +++ b/core/fs/ntfs/ntfs.c @@ -77,7 +77,7 @@ static void ntfs_fixups_writeback(struct fs_info *fs, struct ntfs_record *nrec) uint16_t usa_count; uint16_t *blk; - dprintf("in %s\n", __func__); + dprintf("in %s()\n", __func__); if (nrec->magic != NTFS_MAGIC_FILE && nrec->magic != NTFS_MAGIC_INDX) return; @@ -114,7 +114,7 @@ static int ntfs_read(struct fs_info *fs, void *buf, size_t len, uint64_t count, uint64_t loffset; uint64_t k; - dprintf("in %s\n", __func__); + dprintf("in %s()\n", __func__); if (count > len) goto out; @@ -192,7 +192,7 @@ static struct ntfs_mft_record *ntfs_mft_record_lookup_3_0(struct fs_info *fs, int err; struct ntfs_mft_record *mrec; - dprintf("in %s\n", __func__); + dprintf("in %s()\n", __func__); buf = (uint8_t *)malloc(mft_record_size); if (!buf) @@ -207,7 +207,7 @@ static struct ntfs_mft_record *ntfs_mft_record_lookup_3_0(struct fs_info *fs, err = ntfs_read(fs, buf, mft_record_size, mft_record_size, &right_blk, &offset, &next_offset, &lcn); if (err) { - printf("Error on reading from cache.\n"); + printf("Error while reading from cache.\n"); break; } @@ -254,7 +254,7 @@ static struct ntfs_mft_record *ntfs_mft_record_lookup_3_1(struct fs_info *fs, int err; struct ntfs_mft_record *mrec; - dprintf("in %s\n", __func__); + dprintf("in %s()\n", __func__); buf = (uint8_t *)malloc(mft_record_size); if (!buf) @@ -268,7 +268,7 @@ static struct ntfs_mft_record *ntfs_mft_record_lookup_3_1(struct fs_info *fs, err = ntfs_read(fs, buf, mft_record_size, mft_record_size, &right_blk, &offset, &next_offset, &lcn); if (err) { - printf("Error on reading from cache.\n"); + printf("Error while reading from cache.\n"); break; } @@ -305,7 +305,7 @@ static bool ntfs_filename_cmp(const char *dname, struct ntfs_idx_entry *ie) uint8_t entry_fn_len; unsigned i; - dprintf("in %s\n", __func__); + dprintf("in %s()\n", __func__); entry_fn = ie->key.file_name.file_name; entry_fn_len = ie->key.file_name.file_name_len; @@ -357,7 +357,7 @@ static int parse_data_run(const void *stream, uint32_t *offset, (void)attr_len; - dprintf("in %s\n", __func__); + dprintf("in %s()\n", __func__); chunk->flags &= ~MAP_MASK; @@ -436,7 +436,7 @@ ntfs_attr_list_lookup(struct fs_info *fs, struct ntfs_attr_record *attr, struct ntfs_mft_record *retval; uint64_t start_blk = 0; - dprintf("in %s\n", __func__); + dprintf("in %s()\n", __func__); if (attr->non_resident) goto handle_non_resident_attr; @@ -482,7 +482,7 @@ handle_non_resident_attr: err = ntfs_read(fs, buf, blk_size, blk_size, &blk, &blk_offset, NULL, (uint64_t *)&lcn); if (err) { - printf("Error on reading from cache.\n"); + printf("Error while reading from cache.\n"); goto out; } @@ -491,8 +491,8 @@ handle_non_resident_attr: for (; (uint8_t *)attr_entry < (uint8_t *)&buf[0] + len; attr_entry = (struct ntfs_attr_list_entry *) ((uint8_t *)attr_entry + attr_entry->length)) { - printf("<$ATTRIBUTE_LIST> Attribute type: 0x%x\n", - attr_entry->type); + dprintf("<$ATTRIBUTE_LIST> Attribute type: 0x%x\n", + attr_entry->type); if (attr_entry->type == type) goto found; /* We got the attribute! :-) */ } @@ -540,7 +540,7 @@ __ntfs_attr_lookup(struct fs_info *fs, uint32_t type, struct ntfs_attr_record *attr; struct ntfs_attr_record *attr_list_attr; - dprintf("in %s\n", __func__); + dprintf("in %s()\n", __func__); if (!_mrec || type == NTFS_AT_END) goto out; @@ -625,15 +625,13 @@ static int index_inode_setup(struct fs_info *fs, unsigned long mft_no, struct ntfs_mft_record *mrec, *lmrec; struct ntfs_attr_record *attr; enum dirent_type d_type; - uint32_t len; - struct ntfs_idx_root *ir; uint8_t *attr_len; struct mapping_chunk chunk; int err; uint8_t *stream; uint32_t offset; - dprintf("in %s\n", __func__); + dprintf("in %s()\n", __func__); mrec = NTFS_SB(fs)->mft_record_lookup(fs, mft_no, &start_blk); if (!mrec) { @@ -658,16 +656,6 @@ static int index_inode_setup(struct fs_info *fs, unsigned long mft_no, goto out; } - /* 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) { - printf("Corrupt index.\n"); - goto out; - } - /* check if we have a previous allocated state structure */ if (readdir_state) { free(readdir_state); @@ -751,7 +739,6 @@ static struct inode *ntfs_index_lookup(const char *dname, struct inode *dir) uint64_t blk_offset; struct ntfs_attr_record *attr; struct ntfs_idx_root *ir; - uint32_t len; struct ntfs_idx_entry *ie; const uint64_t blk_size = UINT64_C(1) << BLOCK_SHIFT(fs); uint8_t buf[blk_size]; @@ -766,7 +753,7 @@ static struct inode *ntfs_index_lookup(const char *dname, struct inode *dir) int64_t last_lcn; struct inode *inode; - dprintf("in %s\n", __func__); + dprintf("in %s()\n", __func__); mrec = NTFS_SB(fs)->mft_record_lookup(fs, NTFS_PVT(dir)->mft_no, NULL); if (!mrec) { @@ -783,10 +770,6 @@ static struct inode *ntfs_index_lookup(const char *dname, struct inode *dir) 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) - goto index_err; - ie = (struct ntfs_idx_entry *)((uint8_t *)&ir->index + ir->index.entries_offset); for (;; ie = (struct ntfs_idx_entry *)((uint8_t *)ie + ie->len)) { @@ -853,7 +836,7 @@ static struct inode *ntfs_index_lookup(const char *dname, struct inode *dir) err = ntfs_read(fs, &buf, blk_size, blk_size, &blk, &blk_offset, NULL, (uint64_t *)&lcn); if (err) { - printf("Error on reading from cache.\n"); + printf("Error while reading from cache.\n"); goto not_found; } @@ -896,8 +879,6 @@ not_found: dprintf("Index not found\n"); out: - dprintf("%s not found!\n", dname); - free(mrec); return NULL; @@ -912,8 +893,6 @@ found: goto out; } - dprintf("%s found!\n", dname); - free(mrec); return inode; @@ -952,7 +931,7 @@ static int ntfs_next_extent(struct inode *inode, uint32_t lstart) const uint32_t sec_size = SECTOR_SIZE(fs); const uint32_t sec_shift = SECTOR_SHIFT(fs); - dprintf("in %s\n", __func__); + dprintf("in %s()\n", __func__); if (!NTFS_PVT(inode)->non_resident) { pstart = (sbi->mft_blk + NTFS_PVT(inode)->here) << BLOCK_SHIFT(fs) >> @@ -1001,7 +980,7 @@ static uint32_t ntfs_getfssec(struct file *file, char *buf, int sectors, struct ntfs_attr_record *attr; char *p; - dprintf("in %s\n", __func__); + dprintf("in %s()\n", __func__); non_resident = NTFS_PVT(inode)->non_resident; @@ -1071,7 +1050,7 @@ static int ntfs_readdir(struct file *file, struct dirent *dirent) int64_t lcn; char filename[NTFS_MAX_FILE_NAME_LEN + 1]; - dprintf("in %s\n", __func__); + dprintf("in %s()\n", __func__); mrec = NTFS_SB(fs)->mft_record_lookup(fs, NTFS_PVT(inode)->mft_no, NULL); if (!mrec) { @@ -1088,9 +1067,6 @@ static int ntfs_readdir(struct file *file, struct dirent *dirent) 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) - goto index_err; if (!file->offset && readdir_state->in_idx_root) { file->offset = (uint32_t)((uint8_t *)&ir->index + @@ -1138,7 +1114,7 @@ next_run: while (count--) { err = parse_data_run(stream, &offset, attr_len, &chunk); if (err) { - printf("Error on parsing data runs.\n"); + printf("Error while parsing data runs.\n"); goto out; } @@ -1169,7 +1145,7 @@ next_vcn: err = ntfs_read(fs, &buf, blk_size, blk_size, &blk, &blk_offset, NULL, (uint64_t *)&lcn); if (err) { - printf("Error on reading from cache.\n"); + printf("Error while reading from cache.\n"); goto not_found; } @@ -1261,7 +1237,7 @@ static struct inode *ntfs_iget_root(struct fs_info *fs) struct inode *inode; int err; - dprintf("in %s\n", __func__); + dprintf("in %s()\n", __func__); /* Fetch the $Volume MFT record */ start_blk = 0; @@ -1325,7 +1301,7 @@ static int ntfs_fs_init(struct fs_info *fs) struct disk *disk = fs->fs_dev->disk; uint8_t mft_record_shift; - dprintf("in %s\n", __func__); + dprintf("in %s()\n", __func__); read_count = disk->rdwr_sectors(disk, &ntfs, 0, 1, 0); if (!read_count) @@ -1374,7 +1350,7 @@ static int ntfs_fs_init(struct fs_info *fs) sbi->clusters = 0xFFFFFFFFFFF4ULL; /* - * Assume NTFS version 3.0 to begin with. If we find that the + * Assume NTFS version 3.0 to begin with. If we find that the * volume is a different version later on, we will adjust at * that time. */