return (offset < fs->blocksize - csum_size);
}
+#define NEXT_DIRENT(d) ((void *)((char *)(d) + (d)->rec_len))
static errcode_t insert_dirent_tail(ext2_filsys fs, void *dirbuf)
{
struct ext2_dir_entry *d;
d = dirbuf;
top = EXT2_DIRENT_TAIL(dirbuf, fs->blocksize);
- rec_len = d->rec_len;
- while (rec_len && !(rec_len & 0x3)) {
- d = (struct ext2_dir_entry *)(((char *)d) + rec_len);
- if (((void *)d) + d->rec_len >= top)
- break;
- rec_len = d->rec_len;
- }
+ while (d->rec_len && !(d->rec_len & 0x3) && NEXT_DIRENT(d) <= top)
+ d = NEXT_DIRENT(d);
if (d != top) {
size_t min_size = EXT2_DIR_REC_LEN(
ext2fs_dirent_name_len(dirbuf));
- if (min_size > d->rec_len - sizeof(struct ext2_dir_entry_tail))
+ if (min_size > top - (void *)d)
return EXT2_ET_DIR_NO_SPACE_FOR_CSUM;
- d->rec_len -= sizeof(struct ext2_dir_entry_tail);
+ d->rec_len = top - (void *)d;
}
t = (struct ext2_dir_entry_tail *)top;
return 0;
}
+#undef NEXT_DIRENT
static int check_dir_block(ext2_filsys fs,
struct ext2_db_entry2 *db,
--- /dev/null
+Pass 1: Checking inodes, blocks, and sizes
+Pass 2: Checking directory structure
+Directory inode 2, block #0, offset 0: directory has no checksum.
+Fix? yes
+
+Directory inode 2, block #0, offset 1012: directory corrupted
+Salvage? yes
+
+Pass 3: Checking directory connectivity
+Pass 3A: Optimizing directories
+Pass 4: Checking reference counts
+Pass 5: Checking group summary information
+
+test_filesys: ***** FILE SYSTEM WAS MODIFIED *****
+test_filesys: 11/128 files (9.1% non-contiguous), 1090/2048 blocks
+Exit status is 1
--- /dev/null
+Pass 1: Checking inodes, blocks, and sizes
+Pass 2: Checking directory structure
+Pass 3: Checking directory connectivity
+Pass 4: Checking reference counts
+Pass 5: Checking group summary information
+test_filesys: 11/128 files (9.1% non-contiguous), 1090/2048 blocks
+Exit status is 0