/* One-time init for all ext2 instances */
void ext2_init(void)
{
- ext2_i_kcache = kmem_cache_create("ext2_i_info", sizeof(struct ext2_i_info),
- __alignof__(struct ext2_i_info), 0, 0, 0);
+ ext2_i_kcache = kmem_cache_create("ext2_i_info",
+ sizeof(struct ext2_i_info),
+ __alignof__(struct ext2_i_info), 0,
+ NULL, 0, 0, NULL);
}
/* Block management */
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_i_info *e2ii;
uint32_t dir_block;
unsigned int our_rec_len;
- /* TODO: figure out the real time! (Nanwan's birthday, bitches!) */
- time_t now = 1242129600;
struct ext2_dirent *new_dirent;
/* Set basic inode stuff for files, get a disk inode, etc */
SET_FTYPE(inode->i_mode, __S_IFREG);
inode->i_fop = &ext2_f_op_file;
inode->i_ino = ext2_alloc_diskinode(inode, dir_bg);
- inode->i_atime.tv_sec = now;
- inode->i_atime.tv_nsec = 0;
- inode->i_ctime.tv_sec = now;
- inode->i_ctime.tv_nsec = 0;
- inode->i_mtime.tv_sec = now;
- inode->i_mtime.tv_nsec = 0;
/* Initialize disk inode (this will be different for short symlinks) */
disk_inode = ext2_get_diskinode(inode);
ext2_init_diskinode(disk_inode, inode);
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;
}
return -1;
}
-/* Produces the hash to lookup this dentry from the dcache */
-int ext2_d_hash(struct dentry *dentry, struct qstr *name)
-{
- return -1;
-}
-
/* Compares name1 and name2. name1 should be a member of dir. */
int ext2_d_compare(struct dentry *dir, struct qstr *name1, struct qstr *name2)
{ // default, string comp (case sensitive)
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)
struct dentry_operations ext2_d_op = {
ext2_d_revalidate,
- ext2_d_hash,
+ generic_dentry_hash,
ext2_d_compare,
ext2_d_delete,
ext2_d_release,