59 #include <linux/module.h>
60 #include <linux/string.h>
62 #include <linux/time.h>
63 #include <linux/slab.h>
71 #include <linux/ctype.h>
79 static const umode_t romfs_modemap[8] = {
90 static const unsigned char romfs_dtype_table[] = {
103 unsigned long fillsize,
pos;
113 size = i_size_read(inode);
120 pos = ROMFS_I(inode)->i_dataoffset +
offset;
133 SetPageUptodate(page);
142 .readpage = romfs_readpage
148 static int romfs_readdir(
struct file *filp,
void *
dirent,
filldir_t filldir)
150 struct inode *
i = filp->f_dentry->d_inode;
152 unsigned long offset, maxoff;
158 maxoff = romfs_maxsize(i->
i_sb);
160 offset = filp->
f_pos;
171 if (!offset || offset >= maxoff) {
197 if (filldir(dirent, fsname, j, offset, ino,
198 romfs_dtype_table[nextfh & ROMFH_TYPE]) < 0)
215 unsigned long offset, maxoff;
228 maxoff = romfs_maxsize(dir->
i_sb);
231 name = dentry->
d_name.name;
235 if (!offset || offset >= maxoff)
258 inode = romfs_iget(dir->
i_sb, offset);
260 ret = PTR_ERR(inode);
276 d_add(dentry, inode);
284 .readdir = romfs_readdir,
289 .lookup = romfs_lookup,
296 static struct inode *romfs_iget(
struct super_block *
sb,
unsigned long pos)
348 switch (nextfh & ROMFH_TYPE) {
350 i->
i_size = ROMFS_I(i)->i_metasize;
351 i->
i_op = &romfs_dir_inode_operations;
352 i->
i_fop = &romfs_dir_operations;
358 i->
i_data.a_ops = &romfs_aops;
360 i->
i_data.backing_dev_info =
361 i->
i_sb->s_mtd->backing_dev_info;
362 if (nextfh & ROMFH_EXEC)
367 i->
i_data.a_ops = &romfs_aops;
393 static struct inode *romfs_alloc_inode(
struct super_block *sb)
409 static void romfs_destroy_inode(
struct inode *inode)
417 static int romfs_statfs(
struct dentry *dentry,
struct kstatfs *buf)
420 u64 id = huge_encode_dev(sb->
s_bdev->bd_dev);
436 static int romfs_remount(
struct super_block *sb,
int *flags,
char *
data)
443 .alloc_inode = romfs_alloc_inode,
444 .destroy_inode = romfs_destroy_inode,
445 .statfs = romfs_statfs,
446 .remount_fs = romfs_remount,
452 static __u32 romfs_checksum(
const void *
data,
int size)
469 static int romfs_fill_super(
struct super_block *sb,
void *data,
int silent)
473 unsigned long pos, img_size;
490 sb->
s_op = &romfs_super_ops;
505 goto error_rsb_inval;
513 " Can't find a romfs filesystem on dev %s.\n",
515 goto error_rsb_inval;
518 if (romfs_checksum(rsb,
min_t(
size_t, img_size, 512))) {
521 goto error_rsb_inval;
524 storage = sb->
s_mtd ?
"MTD" :
"the block layer";
529 (
unsigned) len, (
unsigned) len, rsb->
name, storage);
537 root = romfs_iget(sb, pos);
560 int flags,
const char *dev_name,
563 struct dentry *ret = ERR_PTR(-
EINVAL);
565 #ifdef CONFIG_ROMFS_ON_MTD
566 ret =
mount_mtd(fs_type, flags, dev_name, data, romfs_fill_super);
568 #ifdef CONFIG_ROMFS_ON_BLOCK
569 if (ret == ERR_PTR(-
EINVAL))
570 ret =
mount_bdev(fs_type, flags, dev_name, data,
581 #ifdef CONFIG_ROMFS_ON_MTD
587 #ifdef CONFIG_ROMFS_ON_BLOCK
598 .mount = romfs_mount,
599 .kill_sb = romfs_kill_sb,
606 static void romfs_i_init_once(
void *_inode)
616 static int __init init_romfs_fs(
void)
628 if (!romfs_inode_cachep) {
630 "ROMFS error: Failed to initialise inode cache\n");
648 static void __exit exit_romfs_fs(
void)