11da177e4SLinus Torvalds /* 21da177e4SLinus Torvalds * linux/fs/affs/inode.c 31da177e4SLinus Torvalds * 41da177e4SLinus Torvalds * (c) 1996 Hans-Joachim Widmaier - Rewritten 51da177e4SLinus Torvalds * 61da177e4SLinus Torvalds * (C) 1993 Ray Burr - Modified for Amiga FFS filesystem. 71da177e4SLinus Torvalds * 81da177e4SLinus Torvalds * (C) 1992 Eric Youngdale Modified for ISO 9660 filesystem. 91da177e4SLinus Torvalds * 101da177e4SLinus Torvalds * (C) 1991 Linus Torvalds - minix filesystem 111da177e4SLinus Torvalds */ 121da177e4SLinus Torvalds 131da177e4SLinus Torvalds #include <linux/module.h> 141da177e4SLinus Torvalds #include <linux/init.h> 151da177e4SLinus Torvalds #include <linux/statfs.h> 161da177e4SLinus Torvalds #include <linux/parser.h> 17e18fa700SJeff Garzik #include <linux/magic.h> 18e8edc6e0SAlexey Dobriyan #include <linux/sched.h> 191da177e4SLinus Torvalds #include "affs.h" 201da177e4SLinus Torvalds 211da177e4SLinus Torvalds extern struct timezone sys_tz; 221da177e4SLinus Torvalds 23726c3342SDavid Howells static int affs_statfs(struct dentry *dentry, struct kstatfs *buf); 241da177e4SLinus Torvalds static int affs_remount (struct super_block *sb, int *flags, char *data); 251da177e4SLinus Torvalds 261da177e4SLinus Torvalds static void 271da177e4SLinus Torvalds affs_put_super(struct super_block *sb) 281da177e4SLinus Torvalds { 291da177e4SLinus Torvalds struct affs_sb_info *sbi = AFFS_SB(sb); 301da177e4SLinus Torvalds pr_debug("AFFS: put_super()\n"); 311da177e4SLinus Torvalds 326cfd0148SChristoph Hellwig lock_kernel(); 336cfd0148SChristoph Hellwig 341da177e4SLinus Torvalds if (!(sb->s_flags & MS_RDONLY)) { 351da177e4SLinus Torvalds AFFS_ROOT_TAIL(sb, sbi->s_root_bh)->bm_flag = cpu_to_be32(1); 361da177e4SLinus Torvalds secs_to_datestamp(get_seconds(), 371da177e4SLinus Torvalds &AFFS_ROOT_TAIL(sb, sbi->s_root_bh)->disk_change); 381da177e4SLinus Torvalds affs_fix_checksum(sb, sbi->s_root_bh); 391da177e4SLinus Torvalds mark_buffer_dirty(sbi->s_root_bh); 401da177e4SLinus Torvalds } 411da177e4SLinus Torvalds 421da177e4SLinus Torvalds kfree(sbi->s_prefix); 431da177e4SLinus Torvalds affs_free_bitmap(sb); 441da177e4SLinus Torvalds affs_brelse(sbi->s_root_bh); 451da177e4SLinus Torvalds kfree(sbi); 461da177e4SLinus Torvalds sb->s_fs_info = NULL; 476cfd0148SChristoph Hellwig 486cfd0148SChristoph Hellwig unlock_kernel(); 491da177e4SLinus Torvalds } 501da177e4SLinus Torvalds 511da177e4SLinus Torvalds static void 521da177e4SLinus Torvalds affs_write_super(struct super_block *sb) 531da177e4SLinus Torvalds { 541da177e4SLinus Torvalds int clean = 2; 551da177e4SLinus Torvalds struct affs_sb_info *sbi = AFFS_SB(sb); 561da177e4SLinus Torvalds 57*ebc1ac16SChristoph Hellwig lock_super(sb); 581da177e4SLinus Torvalds if (!(sb->s_flags & MS_RDONLY)) { 591da177e4SLinus Torvalds // if (sbi->s_bitmap[i].bm_bh) { 601da177e4SLinus Torvalds // if (buffer_dirty(sbi->s_bitmap[i].bm_bh)) { 611da177e4SLinus Torvalds // clean = 0; 621da177e4SLinus Torvalds AFFS_ROOT_TAIL(sb, sbi->s_root_bh)->bm_flag = cpu_to_be32(clean); 631da177e4SLinus Torvalds secs_to_datestamp(get_seconds(), 641da177e4SLinus Torvalds &AFFS_ROOT_TAIL(sb, sbi->s_root_bh)->disk_change); 651da177e4SLinus Torvalds affs_fix_checksum(sb, sbi->s_root_bh); 661da177e4SLinus Torvalds mark_buffer_dirty(sbi->s_root_bh); 671da177e4SLinus Torvalds sb->s_dirt = !clean; /* redo until bitmap synced */ 681da177e4SLinus Torvalds } else 691da177e4SLinus Torvalds sb->s_dirt = 0; 70*ebc1ac16SChristoph Hellwig unlock_super(sb); 711da177e4SLinus Torvalds 721da177e4SLinus Torvalds pr_debug("AFFS: write_super() at %lu, clean=%d\n", get_seconds(), clean); 731da177e4SLinus Torvalds } 741da177e4SLinus Torvalds 75e18b890bSChristoph Lameter static struct kmem_cache * affs_inode_cachep; 761da177e4SLinus Torvalds 771da177e4SLinus Torvalds static struct inode *affs_alloc_inode(struct super_block *sb) 781da177e4SLinus Torvalds { 79dca3c336SRoman Zippel struct affs_inode_info *i; 80dca3c336SRoman Zippel 81dca3c336SRoman Zippel i = kmem_cache_alloc(affs_inode_cachep, GFP_KERNEL); 82dca3c336SRoman Zippel if (!i) 831da177e4SLinus Torvalds return NULL; 84dca3c336SRoman Zippel 85dca3c336SRoman Zippel i->vfs_inode.i_version = 1; 86dca3c336SRoman Zippel i->i_lc = NULL; 87dca3c336SRoman Zippel i->i_ext_bh = NULL; 88dca3c336SRoman Zippel i->i_pa_cnt = 0; 89dca3c336SRoman Zippel 90dca3c336SRoman Zippel return &i->vfs_inode; 911da177e4SLinus Torvalds } 921da177e4SLinus Torvalds 931da177e4SLinus Torvalds static void affs_destroy_inode(struct inode *inode) 941da177e4SLinus Torvalds { 951da177e4SLinus Torvalds kmem_cache_free(affs_inode_cachep, AFFS_I(inode)); 961da177e4SLinus Torvalds } 971da177e4SLinus Torvalds 9851cc5068SAlexey Dobriyan static void init_once(void *foo) 991da177e4SLinus Torvalds { 1001da177e4SLinus Torvalds struct affs_inode_info *ei = (struct affs_inode_info *) foo; 1011da177e4SLinus Torvalds 1021da177e4SLinus Torvalds init_MUTEX(&ei->i_link_lock); 1031da177e4SLinus Torvalds init_MUTEX(&ei->i_ext_lock); 1041da177e4SLinus Torvalds inode_init_once(&ei->vfs_inode); 1051da177e4SLinus Torvalds } 1061da177e4SLinus Torvalds 1071da177e4SLinus Torvalds static int init_inodecache(void) 1081da177e4SLinus Torvalds { 1091da177e4SLinus Torvalds affs_inode_cachep = kmem_cache_create("affs_inode_cache", 1101da177e4SLinus Torvalds sizeof(struct affs_inode_info), 111fffb60f9SPaul Jackson 0, (SLAB_RECLAIM_ACCOUNT| 112fffb60f9SPaul Jackson SLAB_MEM_SPREAD), 11320c2df83SPaul Mundt init_once); 1141da177e4SLinus Torvalds if (affs_inode_cachep == NULL) 1151da177e4SLinus Torvalds return -ENOMEM; 1161da177e4SLinus Torvalds return 0; 1171da177e4SLinus Torvalds } 1181da177e4SLinus Torvalds 1191da177e4SLinus Torvalds static void destroy_inodecache(void) 1201da177e4SLinus Torvalds { 1211a1d92c1SAlexey Dobriyan kmem_cache_destroy(affs_inode_cachep); 1221da177e4SLinus Torvalds } 1231da177e4SLinus Torvalds 124ee9b6d61SJosef 'Jeff' Sipek static const struct super_operations affs_sops = { 1251da177e4SLinus Torvalds .alloc_inode = affs_alloc_inode, 1261da177e4SLinus Torvalds .destroy_inode = affs_destroy_inode, 1271da177e4SLinus Torvalds .write_inode = affs_write_inode, 1281da177e4SLinus Torvalds .delete_inode = affs_delete_inode, 1291da177e4SLinus Torvalds .clear_inode = affs_clear_inode, 1301da177e4SLinus Torvalds .put_super = affs_put_super, 1311da177e4SLinus Torvalds .write_super = affs_write_super, 1321da177e4SLinus Torvalds .statfs = affs_statfs, 1331da177e4SLinus Torvalds .remount_fs = affs_remount, 134e9b3961bSMiklos Szeredi .show_options = generic_show_options, 1351da177e4SLinus Torvalds }; 1361da177e4SLinus Torvalds 1371da177e4SLinus Torvalds enum { 1381da177e4SLinus Torvalds Opt_bs, Opt_mode, Opt_mufs, Opt_prefix, Opt_protect, 1391da177e4SLinus Torvalds Opt_reserved, Opt_root, Opt_setgid, Opt_setuid, 1401da177e4SLinus Torvalds Opt_verbose, Opt_volume, Opt_ignore, Opt_err, 1411da177e4SLinus Torvalds }; 1421da177e4SLinus Torvalds 143a447c093SSteven Whitehouse static const match_table_t tokens = { 1441da177e4SLinus Torvalds {Opt_bs, "bs=%u"}, 1451da177e4SLinus Torvalds {Opt_mode, "mode=%o"}, 1461da177e4SLinus Torvalds {Opt_mufs, "mufs"}, 1471da177e4SLinus Torvalds {Opt_prefix, "prefix=%s"}, 1481da177e4SLinus Torvalds {Opt_protect, "protect"}, 1491da177e4SLinus Torvalds {Opt_reserved, "reserved=%u"}, 1501da177e4SLinus Torvalds {Opt_root, "root=%u"}, 1511da177e4SLinus Torvalds {Opt_setgid, "setgid=%u"}, 1521da177e4SLinus Torvalds {Opt_setuid, "setuid=%u"}, 1531da177e4SLinus Torvalds {Opt_verbose, "verbose"}, 1541da177e4SLinus Torvalds {Opt_volume, "volume=%s"}, 1551da177e4SLinus Torvalds {Opt_ignore, "grpquota"}, 1561da177e4SLinus Torvalds {Opt_ignore, "noquota"}, 1571da177e4SLinus Torvalds {Opt_ignore, "quota"}, 1581da177e4SLinus Torvalds {Opt_ignore, "usrquota"}, 1591da177e4SLinus Torvalds {Opt_err, NULL}, 1601da177e4SLinus Torvalds }; 1611da177e4SLinus Torvalds 1621da177e4SLinus Torvalds static int 1631da177e4SLinus Torvalds parse_options(char *options, uid_t *uid, gid_t *gid, int *mode, int *reserved, s32 *root, 1641da177e4SLinus Torvalds int *blocksize, char **prefix, char *volume, unsigned long *mount_opts) 1651da177e4SLinus Torvalds { 1661da177e4SLinus Torvalds char *p; 1671da177e4SLinus Torvalds substring_t args[MAX_OPT_ARGS]; 1681da177e4SLinus Torvalds 1691da177e4SLinus Torvalds /* Fill in defaults */ 1701da177e4SLinus Torvalds 17121559981SDavid Howells *uid = current_uid(); 17221559981SDavid Howells *gid = current_gid(); 1731da177e4SLinus Torvalds *reserved = 2; 1741da177e4SLinus Torvalds *root = -1; 1751da177e4SLinus Torvalds *blocksize = -1; 1761da177e4SLinus Torvalds volume[0] = ':'; 1771da177e4SLinus Torvalds volume[1] = 0; 1781da177e4SLinus Torvalds *mount_opts = 0; 1791da177e4SLinus Torvalds if (!options) 1801da177e4SLinus Torvalds return 1; 1811da177e4SLinus Torvalds 1821da177e4SLinus Torvalds while ((p = strsep(&options, ",")) != NULL) { 1831da177e4SLinus Torvalds int token, n, option; 1841da177e4SLinus Torvalds if (!*p) 1851da177e4SLinus Torvalds continue; 1861da177e4SLinus Torvalds 1871da177e4SLinus Torvalds token = match_token(p, tokens, args); 1881da177e4SLinus Torvalds switch (token) { 1891da177e4SLinus Torvalds case Opt_bs: 1901da177e4SLinus Torvalds if (match_int(&args[0], &n)) 1911da177e4SLinus Torvalds return -EINVAL; 1921da177e4SLinus Torvalds if (n != 512 && n != 1024 && n != 2048 1931da177e4SLinus Torvalds && n != 4096) { 1941da177e4SLinus Torvalds printk ("AFFS: Invalid blocksize (512, 1024, 2048, 4096 allowed)\n"); 1951da177e4SLinus Torvalds return 0; 1961da177e4SLinus Torvalds } 1971da177e4SLinus Torvalds *blocksize = n; 1981da177e4SLinus Torvalds break; 1991da177e4SLinus Torvalds case Opt_mode: 2001da177e4SLinus Torvalds if (match_octal(&args[0], &option)) 2011da177e4SLinus Torvalds return 1; 2021da177e4SLinus Torvalds *mode = option & 0777; 2031da177e4SLinus Torvalds *mount_opts |= SF_SETMODE; 2041da177e4SLinus Torvalds break; 2051da177e4SLinus Torvalds case Opt_mufs: 2061da177e4SLinus Torvalds *mount_opts |= SF_MUFS; 2071da177e4SLinus Torvalds break; 2081da177e4SLinus Torvalds case Opt_prefix: 209f99d49adSJesper Juhl /* Free any previous prefix */ 2101da177e4SLinus Torvalds kfree(*prefix); 2111da177e4SLinus Torvalds *prefix = match_strdup(&args[0]); 2121da177e4SLinus Torvalds if (!*prefix) 2131da177e4SLinus Torvalds return 0; 2141da177e4SLinus Torvalds *mount_opts |= SF_PREFIX; 2151da177e4SLinus Torvalds break; 2161da177e4SLinus Torvalds case Opt_protect: 2171da177e4SLinus Torvalds *mount_opts |= SF_IMMUTABLE; 2181da177e4SLinus Torvalds break; 2191da177e4SLinus Torvalds case Opt_reserved: 2201da177e4SLinus Torvalds if (match_int(&args[0], reserved)) 2211da177e4SLinus Torvalds return 1; 2221da177e4SLinus Torvalds break; 2231da177e4SLinus Torvalds case Opt_root: 2241da177e4SLinus Torvalds if (match_int(&args[0], root)) 2251da177e4SLinus Torvalds return 1; 2261da177e4SLinus Torvalds break; 2271da177e4SLinus Torvalds case Opt_setgid: 2281da177e4SLinus Torvalds if (match_int(&args[0], &option)) 2291da177e4SLinus Torvalds return 1; 2301da177e4SLinus Torvalds *gid = option; 2311da177e4SLinus Torvalds *mount_opts |= SF_SETGID; 2321da177e4SLinus Torvalds break; 2331da177e4SLinus Torvalds case Opt_setuid: 2341da177e4SLinus Torvalds if (match_int(&args[0], &option)) 2351da177e4SLinus Torvalds return -EINVAL; 2361da177e4SLinus Torvalds *uid = option; 2371da177e4SLinus Torvalds *mount_opts |= SF_SETUID; 2381da177e4SLinus Torvalds break; 2391da177e4SLinus Torvalds case Opt_verbose: 2401da177e4SLinus Torvalds *mount_opts |= SF_VERBOSE; 2411da177e4SLinus Torvalds break; 2421da177e4SLinus Torvalds case Opt_volume: { 2431da177e4SLinus Torvalds char *vol = match_strdup(&args[0]); 2446db27dd9SJim Meyering if (!vol) 2456db27dd9SJim Meyering return 0; 2461da177e4SLinus Torvalds strlcpy(volume, vol, 32); 2471da177e4SLinus Torvalds kfree(vol); 2481da177e4SLinus Torvalds break; 2491da177e4SLinus Torvalds } 2501da177e4SLinus Torvalds case Opt_ignore: 2511da177e4SLinus Torvalds /* Silently ignore the quota options */ 2521da177e4SLinus Torvalds break; 2531da177e4SLinus Torvalds default: 2541da177e4SLinus Torvalds printk("AFFS: Unrecognized mount option \"%s\" " 2551da177e4SLinus Torvalds "or missing value\n", p); 2561da177e4SLinus Torvalds return 0; 2571da177e4SLinus Torvalds } 2581da177e4SLinus Torvalds } 2591da177e4SLinus Torvalds return 1; 2601da177e4SLinus Torvalds } 2611da177e4SLinus Torvalds 2621da177e4SLinus Torvalds /* This function definitely needs to be split up. Some fine day I'll 2631da177e4SLinus Torvalds * hopefully have the guts to do so. Until then: sorry for the mess. 2641da177e4SLinus Torvalds */ 2651da177e4SLinus Torvalds 2661da177e4SLinus Torvalds static int affs_fill_super(struct super_block *sb, void *data, int silent) 2671da177e4SLinus Torvalds { 2681da177e4SLinus Torvalds struct affs_sb_info *sbi; 2691da177e4SLinus Torvalds struct buffer_head *root_bh = NULL; 2701da177e4SLinus Torvalds struct buffer_head *boot_bh; 2711da177e4SLinus Torvalds struct inode *root_inode = NULL; 2721da177e4SLinus Torvalds s32 root_block; 2731da177e4SLinus Torvalds int size, blocksize; 2741da177e4SLinus Torvalds u32 chksum; 2751da177e4SLinus Torvalds int num_bm; 2761da177e4SLinus Torvalds int i, j; 2771da177e4SLinus Torvalds s32 key; 2781da177e4SLinus Torvalds uid_t uid; 2791da177e4SLinus Torvalds gid_t gid; 2801da177e4SLinus Torvalds int reserved; 2811da177e4SLinus Torvalds unsigned long mount_flags; 2821da177e4SLinus Torvalds int tmp_flags; /* fix remount prototype... */ 2832b943cf0SAl Viro u8 sig[4]; 284210f8559SDavid Howells int ret = -EINVAL; 2851da177e4SLinus Torvalds 286e9b3961bSMiklos Szeredi save_mount_options(sb, data); 287e9b3961bSMiklos Szeredi 2881da177e4SLinus Torvalds pr_debug("AFFS: read_super(%s)\n",data ? (const char *)data : "no options"); 2891da177e4SLinus Torvalds 2901da177e4SLinus Torvalds sb->s_magic = AFFS_SUPER_MAGIC; 2911da177e4SLinus Torvalds sb->s_op = &affs_sops; 2921da177e4SLinus Torvalds sb->s_flags |= MS_NODIRATIME; 2931da177e4SLinus Torvalds 294f8314dc6SPanagiotis Issaris sbi = kzalloc(sizeof(struct affs_sb_info), GFP_KERNEL); 2951da177e4SLinus Torvalds if (!sbi) 2961da177e4SLinus Torvalds return -ENOMEM; 2971da177e4SLinus Torvalds sb->s_fs_info = sbi; 2987d135a5dSMatthias Kaehlcke mutex_init(&sbi->s_bmlock); 2991da177e4SLinus Torvalds 3001da177e4SLinus Torvalds if (!parse_options(data,&uid,&gid,&i,&reserved,&root_block, 3011da177e4SLinus Torvalds &blocksize,&sbi->s_prefix, 3021da177e4SLinus Torvalds sbi->s_volume, &mount_flags)) { 3031da177e4SLinus Torvalds printk(KERN_ERR "AFFS: Error parsing options\n"); 3041da177e4SLinus Torvalds return -EINVAL; 3051da177e4SLinus Torvalds } 3061da177e4SLinus Torvalds /* N.B. after this point s_prefix must be released */ 3071da177e4SLinus Torvalds 3081da177e4SLinus Torvalds sbi->s_flags = mount_flags; 3091da177e4SLinus Torvalds sbi->s_mode = i; 3101da177e4SLinus Torvalds sbi->s_uid = uid; 3111da177e4SLinus Torvalds sbi->s_gid = gid; 3121da177e4SLinus Torvalds sbi->s_reserved= reserved; 3131da177e4SLinus Torvalds 3141da177e4SLinus Torvalds /* Get the size of the device in 512-byte blocks. 3151da177e4SLinus Torvalds * If we later see that the partition uses bigger 3161da177e4SLinus Torvalds * blocks, we will have to change it. 3171da177e4SLinus Torvalds */ 3181da177e4SLinus Torvalds 3191da177e4SLinus Torvalds size = sb->s_bdev->bd_inode->i_size >> 9; 3201da177e4SLinus Torvalds pr_debug("AFFS: initial blocksize=%d, #blocks=%d\n", 512, size); 3211da177e4SLinus Torvalds 3221da177e4SLinus Torvalds affs_set_blocksize(sb, PAGE_SIZE); 3231da177e4SLinus Torvalds /* Try to find root block. Its location depends on the block size. */ 3241da177e4SLinus Torvalds 3251da177e4SLinus Torvalds i = 512; 3261da177e4SLinus Torvalds j = 4096; 3271da177e4SLinus Torvalds if (blocksize > 0) { 3281da177e4SLinus Torvalds i = j = blocksize; 3291da177e4SLinus Torvalds size = size / (blocksize / 512); 3301da177e4SLinus Torvalds } 3311da177e4SLinus Torvalds for (blocksize = i, key = 0; blocksize <= j; blocksize <<= 1, size >>= 1) { 3321da177e4SLinus Torvalds sbi->s_root_block = root_block; 3331da177e4SLinus Torvalds if (root_block < 0) 3341da177e4SLinus Torvalds sbi->s_root_block = (reserved + size - 1) / 2; 3351da177e4SLinus Torvalds pr_debug("AFFS: setting blocksize to %d\n", blocksize); 3361da177e4SLinus Torvalds affs_set_blocksize(sb, blocksize); 3371da177e4SLinus Torvalds sbi->s_partition_size = size; 3381da177e4SLinus Torvalds 3391da177e4SLinus Torvalds /* The root block location that was calculated above is not 3401da177e4SLinus Torvalds * correct if the partition size is an odd number of 512- 3411da177e4SLinus Torvalds * byte blocks, which will be rounded down to a number of 3421da177e4SLinus Torvalds * 1024-byte blocks, and if there were an even number of 3431da177e4SLinus Torvalds * reserved blocks. Ideally, all partition checkers should 3441da177e4SLinus Torvalds * report the real number of blocks of the real blocksize, 3451da177e4SLinus Torvalds * but since this just cannot be done, we have to try to 3461da177e4SLinus Torvalds * find the root block anyways. In the above case, it is one 3471da177e4SLinus Torvalds * block behind the calculated one. So we check this one, too. 3481da177e4SLinus Torvalds */ 3491da177e4SLinus Torvalds for (num_bm = 0; num_bm < 2; num_bm++) { 3501da177e4SLinus Torvalds pr_debug("AFFS: Dev %s, trying root=%u, bs=%d, " 3511da177e4SLinus Torvalds "size=%d, reserved=%d\n", 3521da177e4SLinus Torvalds sb->s_id, 3531da177e4SLinus Torvalds sbi->s_root_block + num_bm, 3541da177e4SLinus Torvalds blocksize, size, reserved); 3551da177e4SLinus Torvalds root_bh = affs_bread(sb, sbi->s_root_block + num_bm); 3561da177e4SLinus Torvalds if (!root_bh) 3571da177e4SLinus Torvalds continue; 3581da177e4SLinus Torvalds if (!affs_checksum_block(sb, root_bh) && 3591da177e4SLinus Torvalds be32_to_cpu(AFFS_ROOT_HEAD(root_bh)->ptype) == T_SHORT && 3601da177e4SLinus Torvalds be32_to_cpu(AFFS_ROOT_TAIL(sb, root_bh)->stype) == ST_ROOT) { 3611da177e4SLinus Torvalds sbi->s_hashsize = blocksize / 4 - 56; 3621da177e4SLinus Torvalds sbi->s_root_block += num_bm; 3631da177e4SLinus Torvalds key = 1; 3641da177e4SLinus Torvalds goto got_root; 3651da177e4SLinus Torvalds } 3661da177e4SLinus Torvalds affs_brelse(root_bh); 3671da177e4SLinus Torvalds root_bh = NULL; 3681da177e4SLinus Torvalds } 3691da177e4SLinus Torvalds } 3701da177e4SLinus Torvalds if (!silent) 3711da177e4SLinus Torvalds printk(KERN_ERR "AFFS: No valid root block on device %s\n", 3721da177e4SLinus Torvalds sb->s_id); 3731da177e4SLinus Torvalds goto out_error; 3741da177e4SLinus Torvalds 3751da177e4SLinus Torvalds /* N.B. after this point bh must be released */ 3761da177e4SLinus Torvalds got_root: 3771da177e4SLinus Torvalds root_block = sbi->s_root_block; 3781da177e4SLinus Torvalds 3791da177e4SLinus Torvalds /* Find out which kind of FS we have */ 3801da177e4SLinus Torvalds boot_bh = sb_bread(sb, 0); 3811da177e4SLinus Torvalds if (!boot_bh) { 3821da177e4SLinus Torvalds printk(KERN_ERR "AFFS: Cannot read boot block\n"); 3831da177e4SLinus Torvalds goto out_error; 3841da177e4SLinus Torvalds } 3852b943cf0SAl Viro memcpy(sig, boot_bh->b_data, 4); 3861da177e4SLinus Torvalds brelse(boot_bh); 3872b943cf0SAl Viro chksum = be32_to_cpu(*(__be32 *)sig); 3881da177e4SLinus Torvalds 3891da177e4SLinus Torvalds /* Dircache filesystems are compatible with non-dircache ones 3901da177e4SLinus Torvalds * when reading. As long as they aren't supported, writing is 3911da177e4SLinus Torvalds * not recommended. 3921da177e4SLinus Torvalds */ 3931da177e4SLinus Torvalds if ((chksum == FS_DCFFS || chksum == MUFS_DCFFS || chksum == FS_DCOFS 3941da177e4SLinus Torvalds || chksum == MUFS_DCOFS) && !(sb->s_flags & MS_RDONLY)) { 3951da177e4SLinus Torvalds printk(KERN_NOTICE "AFFS: Dircache FS - mounting %s read only\n", 3961da177e4SLinus Torvalds sb->s_id); 3971da177e4SLinus Torvalds sb->s_flags |= MS_RDONLY; 3981da177e4SLinus Torvalds } 3991da177e4SLinus Torvalds switch (chksum) { 4001da177e4SLinus Torvalds case MUFS_FS: 4011da177e4SLinus Torvalds case MUFS_INTLFFS: 4021da177e4SLinus Torvalds case MUFS_DCFFS: 4031da177e4SLinus Torvalds sbi->s_flags |= SF_MUFS; 4041da177e4SLinus Torvalds /* fall thru */ 4051da177e4SLinus Torvalds case FS_INTLFFS: 4061da177e4SLinus Torvalds case FS_DCFFS: 4071da177e4SLinus Torvalds sbi->s_flags |= SF_INTL; 4081da177e4SLinus Torvalds break; 4091da177e4SLinus Torvalds case MUFS_FFS: 4101da177e4SLinus Torvalds sbi->s_flags |= SF_MUFS; 4111da177e4SLinus Torvalds break; 4121da177e4SLinus Torvalds case FS_FFS: 4131da177e4SLinus Torvalds break; 4141da177e4SLinus Torvalds case MUFS_OFS: 4151da177e4SLinus Torvalds sbi->s_flags |= SF_MUFS; 4161da177e4SLinus Torvalds /* fall thru */ 4171da177e4SLinus Torvalds case FS_OFS: 4181da177e4SLinus Torvalds sbi->s_flags |= SF_OFS; 4191da177e4SLinus Torvalds sb->s_flags |= MS_NOEXEC; 4201da177e4SLinus Torvalds break; 4211da177e4SLinus Torvalds case MUFS_DCOFS: 4221da177e4SLinus Torvalds case MUFS_INTLOFS: 4231da177e4SLinus Torvalds sbi->s_flags |= SF_MUFS; 4241da177e4SLinus Torvalds case FS_DCOFS: 4251da177e4SLinus Torvalds case FS_INTLOFS: 4261da177e4SLinus Torvalds sbi->s_flags |= SF_INTL | SF_OFS; 4271da177e4SLinus Torvalds sb->s_flags |= MS_NOEXEC; 4281da177e4SLinus Torvalds break; 4291da177e4SLinus Torvalds default: 4301da177e4SLinus Torvalds printk(KERN_ERR "AFFS: Unknown filesystem on device %s: %08X\n", 4311da177e4SLinus Torvalds sb->s_id, chksum); 4321da177e4SLinus Torvalds goto out_error; 4331da177e4SLinus Torvalds } 4341da177e4SLinus Torvalds 4351da177e4SLinus Torvalds if (mount_flags & SF_VERBOSE) { 4362b943cf0SAl Viro u8 len = AFFS_ROOT_TAIL(sb, root_bh)->disk_name[0]; 4372b943cf0SAl Viro printk(KERN_NOTICE "AFFS: Mounting volume \"%.*s\": Type=%.3s\\%c, Blocksize=%d\n", 4382b943cf0SAl Viro len > 31 ? 31 : len, 4391da177e4SLinus Torvalds AFFS_ROOT_TAIL(sb, root_bh)->disk_name + 1, 4402b943cf0SAl Viro sig, sig[3] + '0', blocksize); 4411da177e4SLinus Torvalds } 4421da177e4SLinus Torvalds 4431da177e4SLinus Torvalds sb->s_flags |= MS_NODEV | MS_NOSUID; 4441da177e4SLinus Torvalds 4451da177e4SLinus Torvalds sbi->s_data_blksize = sb->s_blocksize; 4461da177e4SLinus Torvalds if (sbi->s_flags & SF_OFS) 4471da177e4SLinus Torvalds sbi->s_data_blksize -= 24; 4481da177e4SLinus Torvalds 4491da177e4SLinus Torvalds /* Keep super block in cache */ 4501da177e4SLinus Torvalds sbi->s_root_bh = root_bh; 4511da177e4SLinus Torvalds /* N.B. after this point s_root_bh must be released */ 4521da177e4SLinus Torvalds 4531da177e4SLinus Torvalds tmp_flags = sb->s_flags; 4541da177e4SLinus Torvalds if (affs_init_bitmap(sb, &tmp_flags)) 4551da177e4SLinus Torvalds goto out_error; 4561da177e4SLinus Torvalds sb->s_flags = tmp_flags; 4571da177e4SLinus Torvalds 4581da177e4SLinus Torvalds /* set up enough so that it can read an inode */ 4591da177e4SLinus Torvalds 460210f8559SDavid Howells root_inode = affs_iget(sb, root_block); 461210f8559SDavid Howells if (IS_ERR(root_inode)) { 462210f8559SDavid Howells ret = PTR_ERR(root_inode); 463210f8559SDavid Howells goto out_error_noinode; 464210f8559SDavid Howells } 465210f8559SDavid Howells 4661da177e4SLinus Torvalds sb->s_root = d_alloc_root(root_inode); 4671da177e4SLinus Torvalds if (!sb->s_root) { 4681da177e4SLinus Torvalds printk(KERN_ERR "AFFS: Get root inode failed\n"); 4691da177e4SLinus Torvalds goto out_error; 4701da177e4SLinus Torvalds } 4711da177e4SLinus Torvalds sb->s_root->d_op = &affs_dentry_operations; 4721da177e4SLinus Torvalds 4731da177e4SLinus Torvalds pr_debug("AFFS: s_flags=%lX\n",sb->s_flags); 4741da177e4SLinus Torvalds return 0; 4751da177e4SLinus Torvalds 4761da177e4SLinus Torvalds /* 4771da177e4SLinus Torvalds * Begin the cascaded cleanup ... 4781da177e4SLinus Torvalds */ 4791da177e4SLinus Torvalds out_error: 4801da177e4SLinus Torvalds if (root_inode) 4811da177e4SLinus Torvalds iput(root_inode); 482210f8559SDavid Howells out_error_noinode: 4831da177e4SLinus Torvalds kfree(sbi->s_bitmap); 4841da177e4SLinus Torvalds affs_brelse(root_bh); 4851da177e4SLinus Torvalds kfree(sbi->s_prefix); 4861da177e4SLinus Torvalds kfree(sbi); 4871da177e4SLinus Torvalds sb->s_fs_info = NULL; 488210f8559SDavid Howells return ret; 4891da177e4SLinus Torvalds } 4901da177e4SLinus Torvalds 4911da177e4SLinus Torvalds static int 4921da177e4SLinus Torvalds affs_remount(struct super_block *sb, int *flags, char *data) 4931da177e4SLinus Torvalds { 4941da177e4SLinus Torvalds struct affs_sb_info *sbi = AFFS_SB(sb); 4951da177e4SLinus Torvalds int blocksize; 4961da177e4SLinus Torvalds uid_t uid; 4971da177e4SLinus Torvalds gid_t gid; 4981da177e4SLinus Torvalds int mode; 4991da177e4SLinus Torvalds int reserved; 5001da177e4SLinus Torvalds int root_block; 5011da177e4SLinus Torvalds unsigned long mount_flags; 5021da177e4SLinus Torvalds int res = 0; 503e9b3961bSMiklos Szeredi char *new_opts = kstrdup(data, GFP_KERNEL); 5041da177e4SLinus Torvalds 5051da177e4SLinus Torvalds pr_debug("AFFS: remount(flags=0x%x,opts=\"%s\")\n",*flags,data); 5061da177e4SLinus Torvalds 5071da177e4SLinus Torvalds *flags |= MS_NODIRATIME; 5081da177e4SLinus Torvalds 5091da177e4SLinus Torvalds if (!parse_options(data, &uid, &gid, &mode, &reserved, &root_block, 510e9b3961bSMiklos Szeredi &blocksize, &sbi->s_prefix, sbi->s_volume, 511e9b3961bSMiklos Szeredi &mount_flags)) { 512e9b3961bSMiklos Szeredi kfree(new_opts); 5131da177e4SLinus Torvalds return -EINVAL; 514e9b3961bSMiklos Szeredi } 5152a32cebdSAl Viro replace_mount_options(sb, new_opts); 516e9b3961bSMiklos Szeredi 5171da177e4SLinus Torvalds sbi->s_flags = mount_flags; 5181da177e4SLinus Torvalds sbi->s_mode = mode; 5191da177e4SLinus Torvalds sbi->s_uid = uid; 5201da177e4SLinus Torvalds sbi->s_gid = gid; 5211da177e4SLinus Torvalds 5221da177e4SLinus Torvalds if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY)) 5231da177e4SLinus Torvalds return 0; 5241da177e4SLinus Torvalds if (*flags & MS_RDONLY) { 5251da177e4SLinus Torvalds sb->s_dirt = 1; 5261da177e4SLinus Torvalds while (sb->s_dirt) 5271da177e4SLinus Torvalds affs_write_super(sb); 5281da177e4SLinus Torvalds affs_free_bitmap(sb); 5291da177e4SLinus Torvalds } else 5301da177e4SLinus Torvalds res = affs_init_bitmap(sb, flags); 5311da177e4SLinus Torvalds 5321da177e4SLinus Torvalds return res; 5331da177e4SLinus Torvalds } 5341da177e4SLinus Torvalds 5351da177e4SLinus Torvalds static int 536726c3342SDavid Howells affs_statfs(struct dentry *dentry, struct kstatfs *buf) 5371da177e4SLinus Torvalds { 538726c3342SDavid Howells struct super_block *sb = dentry->d_sb; 5391da177e4SLinus Torvalds int free; 540a6a2a73cSColy Li u64 id = huge_encode_dev(sb->s_bdev->bd_dev); 5411da177e4SLinus Torvalds 5421da177e4SLinus Torvalds pr_debug("AFFS: statfs() partsize=%d, reserved=%d\n",AFFS_SB(sb)->s_partition_size, 5431da177e4SLinus Torvalds AFFS_SB(sb)->s_reserved); 5441da177e4SLinus Torvalds 5451da177e4SLinus Torvalds free = affs_count_free_blocks(sb); 5461da177e4SLinus Torvalds buf->f_type = AFFS_SUPER_MAGIC; 5471da177e4SLinus Torvalds buf->f_bsize = sb->s_blocksize; 5481da177e4SLinus Torvalds buf->f_blocks = AFFS_SB(sb)->s_partition_size - AFFS_SB(sb)->s_reserved; 5491da177e4SLinus Torvalds buf->f_bfree = free; 5501da177e4SLinus Torvalds buf->f_bavail = free; 551a6a2a73cSColy Li buf->f_fsid.val[0] = (u32)id; 552a6a2a73cSColy Li buf->f_fsid.val[1] = (u32)(id >> 32); 553a6a2a73cSColy Li buf->f_namelen = 30; 5541da177e4SLinus Torvalds return 0; 5551da177e4SLinus Torvalds } 5561da177e4SLinus Torvalds 557454e2398SDavid Howells static int affs_get_sb(struct file_system_type *fs_type, 558454e2398SDavid Howells int flags, const char *dev_name, void *data, struct vfsmount *mnt) 5591da177e4SLinus Torvalds { 560454e2398SDavid Howells return get_sb_bdev(fs_type, flags, dev_name, data, affs_fill_super, 561454e2398SDavid Howells mnt); 5621da177e4SLinus Torvalds } 5631da177e4SLinus Torvalds 5641da177e4SLinus Torvalds static struct file_system_type affs_fs_type = { 5651da177e4SLinus Torvalds .owner = THIS_MODULE, 5661da177e4SLinus Torvalds .name = "affs", 5671da177e4SLinus Torvalds .get_sb = affs_get_sb, 5681da177e4SLinus Torvalds .kill_sb = kill_block_super, 5691da177e4SLinus Torvalds .fs_flags = FS_REQUIRES_DEV, 5701da177e4SLinus Torvalds }; 5711da177e4SLinus Torvalds 5721da177e4SLinus Torvalds static int __init init_affs_fs(void) 5731da177e4SLinus Torvalds { 5741da177e4SLinus Torvalds int err = init_inodecache(); 5751da177e4SLinus Torvalds if (err) 5761da177e4SLinus Torvalds goto out1; 5771da177e4SLinus Torvalds err = register_filesystem(&affs_fs_type); 5781da177e4SLinus Torvalds if (err) 5791da177e4SLinus Torvalds goto out; 5801da177e4SLinus Torvalds return 0; 5811da177e4SLinus Torvalds out: 5821da177e4SLinus Torvalds destroy_inodecache(); 5831da177e4SLinus Torvalds out1: 5841da177e4SLinus Torvalds return err; 5851da177e4SLinus Torvalds } 5861da177e4SLinus Torvalds 5871da177e4SLinus Torvalds static void __exit exit_affs_fs(void) 5881da177e4SLinus Torvalds { 5891da177e4SLinus Torvalds unregister_filesystem(&affs_fs_type); 5901da177e4SLinus Torvalds destroy_inodecache(); 5911da177e4SLinus Torvalds } 5921da177e4SLinus Torvalds 5931da177e4SLinus Torvalds MODULE_DESCRIPTION("Amiga filesystem support for Linux"); 5941da177e4SLinus Torvalds MODULE_LICENSE("GPL"); 5951da177e4SLinus Torvalds 5961da177e4SLinus Torvalds module_init(init_affs_fs) 5971da177e4SLinus Torvalds module_exit(exit_affs_fs) 598