blksize = 1024 << le32_to_cpu(e2sb->s_log_block_size);
blks_per_group = le32_to_cpu(e2sb->s_blocks_per_group);
num_blk_group = num_blks / blks_per_group + (num_blks % blks_per_group ? 1 : 0);
-
+
if (print) {
printk("EXT2 info:\n-------------------------\n");
printk("Total Inodes: %8d\n", le32_to_cpu(e2sb->s_inodes_cnt));
printk("Volume name: %s\n", e2sb->s_volume_name);
printk("\nBlock Group Info:\n----------------------\n");
}
-
+
for (int i = 0; i < num_blk_group; i++) {
sum_blks += le16_to_cpu(bg[i].bg_free_blocks_cnt);
sum_inodes += le16_to_cpu(bg[i].bg_free_inodes_cnt);
printk("Used Dirs: %8d\n", le16_to_cpu(bg[i].bg_used_dirs_cnt));
}
}
-
+
/* Sanity Assertions. A good ext2 will always pass these. */
inodes_per_grp = le32_to_cpu(e2sb->s_inodes_per_group);
blks_per_group = le32_to_cpu(e2sb->s_blocks_per_group);
return 0;
}
-/* Helper for writing the contents of a dentry to a disk dirent */
+/* Helper for writing the contents of a dentry to a disk dirent. Zeroes the
+ * contents of the dirent so that we don't write random data to disk. */
static void ext2_write_dirent(struct ext2_dirent *e2dir, struct dentry *dentry,
unsigned int rec_len)
{
+ memset(e2dir, 0, sizeof(*e2dir));
e2dir->dir_inode = cpu_to_le32(dentry->d_inode->i_ino);
e2dir->dir_reclen = cpu_to_le16(rec_len);
e2dir->dir_namelen = dentry->d_name.len;
e2dir->dir_filetype = EXT2_FT_UNKNOWN;
}
assert(dentry->d_name.len <= 255);
- strncpy((char*)e2dir->dir_name, dentry->d_name.name, dentry->d_name.len);
+ strlcpy((char*)e2dir->dir_name, dentry->d_name.name,
+ sizeof(e2dir->dir_name));
}
/* Helper for ext2_create(). This tries to squeeze a dirent in the slack space
struct ext2_dirent *dir_buf, *dir_i;
if (!ext2_foreach_dirent(dir, lookup_each_func, (long)dentry, 0, 0))
return dentry;
- printd("EXT2: Not Found, %s\n", dentry->d_name.name);
+ printd("EXT2: Not Found, %s\n", dentry->d_name.name);
return 0;
}
struct inode *inode = dentry->d_inode;
SET_FTYPE(inode->i_mode, __S_IFLNK);
inode->i_fop = &ext2_f_op_sym;
- strncpy(string, symname, len);
- string[len] = '\0'; /* symname should be \0d anyway, but just in case */
+ strlcpy(string, symname, len + 1);
#endif
return 0;
}
panic("Something is jacked with the dirent going beyond the dir/file");
/* note, dir_namelen doesn't include the \0 */
dirent->d_reclen = e2dir->dir_namelen;
- strncpy(dirent->d_name, (char*)e2dir->dir_name, e2dir->dir_namelen);
assert(e2dir->dir_namelen <= MAX_FILENAME_SZ);
- dirent->d_name[e2dir->dir_namelen] = '\0';
+ strlcpy(dirent->d_name, (char*)e2dir->dir_name, e2dir->dir_namelen + 1);
ext2_put_metablock(dir->f_dentry->d_sb, blk_buf);
-
+
/* At the end of the directory, sort of. ext2 often preallocates blocks, so
* this will cause us to walk along til the end, which isn't quite right. */
if (dir->f_dentry->d_inode->i_size == dirent->d_off)