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> 19337eb00aSAlessio Igor Bogani #include <linux/smp_lock.h> 201da177e4SLinus Torvalds #include "affs.h" 211da177e4SLinus Torvalds 221da177e4SLinus Torvalds extern struct timezone sys_tz; 231da177e4SLinus Torvalds 24726c3342SDavid Howells static int affs_statfs(struct dentry *dentry, struct kstatfs *buf); 251da177e4SLinus Torvalds static int affs_remount (struct super_block *sb, int *flags, char *data); 261da177e4SLinus Torvalds 271da177e4SLinus Torvalds static void 28e2896436SChristoph Hellwig affs_commit_super(struct super_block *sb, int clean) 29e2896436SChristoph Hellwig { 30e2896436SChristoph Hellwig struct affs_sb_info *sbi = AFFS_SB(sb); 31e2896436SChristoph Hellwig struct buffer_head *bh = sbi->s_root_bh; 32e2896436SChristoph Hellwig struct affs_root_tail *tail = AFFS_ROOT_TAIL(sb, bh); 33e2896436SChristoph Hellwig 34e2896436SChristoph Hellwig tail->bm_flag = cpu_to_be32(clean); 35e2896436SChristoph Hellwig secs_to_datestamp(get_seconds(), &tail->disk_change); 36e2896436SChristoph Hellwig affs_fix_checksum(sb, bh); 37e2896436SChristoph Hellwig mark_buffer_dirty(bh); 38e2896436SChristoph Hellwig } 39e2896436SChristoph Hellwig 40e2896436SChristoph Hellwig static void 411da177e4SLinus Torvalds affs_put_super(struct super_block *sb) 421da177e4SLinus Torvalds { 431da177e4SLinus Torvalds struct affs_sb_info *sbi = AFFS_SB(sb); 441da177e4SLinus Torvalds pr_debug("AFFS: put_super()\n"); 451da177e4SLinus Torvalds 466cfd0148SChristoph Hellwig lock_kernel(); 476cfd0148SChristoph Hellwig 48e2896436SChristoph Hellwig if (!(sb->s_flags & MS_RDONLY)) 49e2896436SChristoph Hellwig affs_commit_super(sb, 1); 501da177e4SLinus Torvalds 511da177e4SLinus Torvalds kfree(sbi->s_prefix); 521da177e4SLinus Torvalds affs_free_bitmap(sb); 531da177e4SLinus Torvalds affs_brelse(sbi->s_root_bh); 541da177e4SLinus Torvalds kfree(sbi); 551da177e4SLinus Torvalds sb->s_fs_info = NULL; 566cfd0148SChristoph Hellwig 576cfd0148SChristoph Hellwig unlock_kernel(); 581da177e4SLinus Torvalds } 591da177e4SLinus Torvalds 601da177e4SLinus Torvalds static void 611da177e4SLinus Torvalds affs_write_super(struct super_block *sb) 621da177e4SLinus Torvalds { 631da177e4SLinus Torvalds int clean = 2; 641da177e4SLinus Torvalds 65ebc1ac16SChristoph Hellwig lock_super(sb); 661da177e4SLinus Torvalds if (!(sb->s_flags & MS_RDONLY)) { 671da177e4SLinus Torvalds // if (sbi->s_bitmap[i].bm_bh) { 681da177e4SLinus Torvalds // if (buffer_dirty(sbi->s_bitmap[i].bm_bh)) { 691da177e4SLinus Torvalds // clean = 0; 70e2896436SChristoph Hellwig affs_commit_super(sb, clean); 711da177e4SLinus Torvalds sb->s_dirt = !clean; /* redo until bitmap synced */ 721da177e4SLinus Torvalds } else 731da177e4SLinus Torvalds sb->s_dirt = 0; 74ebc1ac16SChristoph Hellwig unlock_super(sb); 751da177e4SLinus Torvalds 761da177e4SLinus Torvalds pr_debug("AFFS: write_super() at %lu, clean=%d\n", get_seconds(), clean); 771da177e4SLinus Torvalds } 781da177e4SLinus Torvalds 79e2896436SChristoph Hellwig static int 80e2896436SChristoph Hellwig affs_sync_fs(struct super_block *sb, int wait) 81e2896436SChristoph Hellwig { 82e2896436SChristoph Hellwig lock_super(sb); 83e2896436SChristoph Hellwig affs_commit_super(sb, 2); 84e2896436SChristoph Hellwig sb->s_dirt = 0; 85e2896436SChristoph Hellwig unlock_super(sb); 86e2896436SChristoph Hellwig return 0; 87e2896436SChristoph Hellwig } 88e2896436SChristoph Hellwig 89e18b890bSChristoph Lameter static struct kmem_cache * affs_inode_cachep; 901da177e4SLinus Torvalds 911da177e4SLinus Torvalds static struct inode *affs_alloc_inode(struct super_block *sb) 921da177e4SLinus Torvalds { 93dca3c336SRoman Zippel struct affs_inode_info *i; 94dca3c336SRoman Zippel 95dca3c336SRoman Zippel i = kmem_cache_alloc(affs_inode_cachep, GFP_KERNEL); 96dca3c336SRoman Zippel if (!i) 971da177e4SLinus Torvalds return NULL; 98dca3c336SRoman Zippel 99dca3c336SRoman Zippel i->vfs_inode.i_version = 1; 100dca3c336SRoman Zippel i->i_lc = NULL; 101dca3c336SRoman Zippel i->i_ext_bh = NULL; 102dca3c336SRoman Zippel i->i_pa_cnt = 0; 103dca3c336SRoman Zippel 104dca3c336SRoman Zippel return &i->vfs_inode; 1051da177e4SLinus Torvalds } 1061da177e4SLinus Torvalds 1071da177e4SLinus Torvalds static void affs_destroy_inode(struct inode *inode) 1081da177e4SLinus Torvalds { 1091da177e4SLinus Torvalds kmem_cache_free(affs_inode_cachep, AFFS_I(inode)); 1101da177e4SLinus Torvalds } 1111da177e4SLinus Torvalds 11251cc5068SAlexey Dobriyan static void init_once(void *foo) 1131da177e4SLinus Torvalds { 1141da177e4SLinus Torvalds struct affs_inode_info *ei = (struct affs_inode_info *) foo; 1151da177e4SLinus Torvalds 1161da177e4SLinus Torvalds init_MUTEX(&ei->i_link_lock); 1171da177e4SLinus Torvalds init_MUTEX(&ei->i_ext_lock); 1181da177e4SLinus Torvalds inode_init_once(&ei->vfs_inode); 1191da177e4SLinus Torvalds } 1201da177e4SLinus Torvalds 1211da177e4SLinus Torvalds static int init_inodecache(void) 1221da177e4SLinus Torvalds { 1231da177e4SLinus Torvalds affs_inode_cachep = kmem_cache_create("affs_inode_cache", 1241da177e4SLinus Torvalds sizeof(struct affs_inode_info), 125fffb60f9SPaul Jackson 0, (SLAB_RECLAIM_ACCOUNT| 126fffb60f9SPaul Jackson SLAB_MEM_SPREAD), 12720c2df83SPaul Mundt init_once); 1281da177e4SLinus Torvalds if (affs_inode_cachep == NULL) 1291da177e4SLinus Torvalds return -ENOMEM; 1301da177e4SLinus Torvalds return 0; 1311da177e4SLinus Torvalds } 1321da177e4SLinus Torvalds 1331da177e4SLinus Torvalds static void destroy_inodecache(void) 1341da177e4SLinus Torvalds { 1351a1d92c1SAlexey Dobriyan kmem_cache_destroy(affs_inode_cachep); 1361da177e4SLinus Torvalds } 1371da177e4SLinus Torvalds 138ee9b6d61SJosef 'Jeff' Sipek static const struct super_operations affs_sops = { 1391da177e4SLinus Torvalds .alloc_inode = affs_alloc_inode, 1401da177e4SLinus Torvalds .destroy_inode = affs_destroy_inode, 1411da177e4SLinus Torvalds .write_inode = affs_write_inode, 1421da177e4SLinus Torvalds .delete_inode = affs_delete_inode, 1431da177e4SLinus Torvalds .clear_inode = affs_clear_inode, 1441da177e4SLinus Torvalds .put_super = affs_put_super, 1451da177e4SLinus Torvalds .write_super = affs_write_super, 146e2896436SChristoph Hellwig .sync_fs = affs_sync_fs, 1471da177e4SLinus Torvalds .statfs = affs_statfs, 1481da177e4SLinus Torvalds .remount_fs = affs_remount, 149e9b3961bSMiklos Szeredi .show_options = generic_show_options, 1501da177e4SLinus Torvalds }; 1511da177e4SLinus Torvalds 1521da177e4SLinus Torvalds enum { 1531da177e4SLinus Torvalds Opt_bs, Opt_mode, Opt_mufs, Opt_prefix, Opt_protect, 1541da177e4SLinus Torvalds Opt_reserved, Opt_root, Opt_setgid, Opt_setuid, 1551da177e4SLinus Torvalds Opt_verbose, Opt_volume, Opt_ignore, Opt_err, 1561da177e4SLinus Torvalds }; 1571da177e4SLinus Torvalds 158a447c093SSteven Whitehouse static const match_table_t tokens = { 1591da177e4SLinus Torvalds {Opt_bs, "bs=%u"}, 1601da177e4SLinus Torvalds {Opt_mode, "mode=%o"}, 1611da177e4SLinus Torvalds {Opt_mufs, "mufs"}, 1621da177e4SLinus Torvalds {Opt_prefix, "prefix=%s"}, 1631da177e4SLinus Torvalds {Opt_protect, "protect"}, 1641da177e4SLinus Torvalds {Opt_reserved, "reserved=%u"}, 1651da177e4SLinus Torvalds {Opt_root, "root=%u"}, 1661da177e4SLinus Torvalds {Opt_setgid, "setgid=%u"}, 1671da177e4SLinus Torvalds {Opt_setuid, "setuid=%u"}, 1681da177e4SLinus Torvalds {Opt_verbose, "verbose"}, 1691da177e4SLinus Torvalds {Opt_volume, "volume=%s"}, 1701da177e4SLinus Torvalds {Opt_ignore, "grpquota"}, 1711da177e4SLinus Torvalds {Opt_ignore, "noquota"}, 1721da177e4SLinus Torvalds {Opt_ignore, "quota"}, 1731da177e4SLinus Torvalds {Opt_ignore, "usrquota"}, 1741da177e4SLinus Torvalds {Opt_err, NULL}, 1751da177e4SLinus Torvalds }; 1761da177e4SLinus Torvalds 1771da177e4SLinus Torvalds static int 1781da177e4SLinus Torvalds parse_options(char *options, uid_t *uid, gid_t *gid, int *mode, int *reserved, s32 *root, 1791da177e4SLinus Torvalds int *blocksize, char **prefix, char *volume, unsigned long *mount_opts) 1801da177e4SLinus Torvalds { 1811da177e4SLinus Torvalds char *p; 1821da177e4SLinus Torvalds substring_t args[MAX_OPT_ARGS]; 1831da177e4SLinus Torvalds 1841da177e4SLinus Torvalds /* Fill in defaults */ 1851da177e4SLinus Torvalds 18621559981SDavid Howells *uid = current_uid(); 18721559981SDavid Howells *gid = current_gid(); 1881da177e4SLinus Torvalds *reserved = 2; 1891da177e4SLinus Torvalds *root = -1; 1901da177e4SLinus Torvalds *blocksize = -1; 1911da177e4SLinus Torvalds volume[0] = ':'; 1921da177e4SLinus Torvalds volume[1] = 0; 1931da177e4SLinus Torvalds *mount_opts = 0; 1941da177e4SLinus Torvalds if (!options) 1951da177e4SLinus Torvalds return 1; 1961da177e4SLinus Torvalds 1971da177e4SLinus Torvalds while ((p = strsep(&options, ",")) != NULL) { 1981da177e4SLinus Torvalds int token, n, option; 1991da177e4SLinus Torvalds if (!*p) 2001da177e4SLinus Torvalds continue; 2011da177e4SLinus Torvalds 2021da177e4SLinus Torvalds token = match_token(p, tokens, args); 2031da177e4SLinus Torvalds switch (token) { 2041da177e4SLinus Torvalds case Opt_bs: 2051da177e4SLinus Torvalds if (match_int(&args[0], &n)) 206*217686e9SAl Viro return 0; 2071da177e4SLinus Torvalds if (n != 512 && n != 1024 && n != 2048 2081da177e4SLinus Torvalds && n != 4096) { 2091da177e4SLinus Torvalds printk ("AFFS: Invalid blocksize (512, 1024, 2048, 4096 allowed)\n"); 2101da177e4SLinus Torvalds return 0; 2111da177e4SLinus Torvalds } 2121da177e4SLinus Torvalds *blocksize = n; 2131da177e4SLinus Torvalds break; 2141da177e4SLinus Torvalds case Opt_mode: 2151da177e4SLinus Torvalds if (match_octal(&args[0], &option)) 216*217686e9SAl Viro return 0; 2171da177e4SLinus Torvalds *mode = option & 0777; 2181da177e4SLinus Torvalds *mount_opts |= SF_SETMODE; 2191da177e4SLinus Torvalds break; 2201da177e4SLinus Torvalds case Opt_mufs: 2211da177e4SLinus Torvalds *mount_opts |= SF_MUFS; 2221da177e4SLinus Torvalds break; 2231da177e4SLinus Torvalds case Opt_prefix: 2241da177e4SLinus Torvalds *prefix = match_strdup(&args[0]); 2251da177e4SLinus Torvalds if (!*prefix) 2261da177e4SLinus Torvalds return 0; 2271da177e4SLinus Torvalds *mount_opts |= SF_PREFIX; 2281da177e4SLinus Torvalds break; 2291da177e4SLinus Torvalds case Opt_protect: 2301da177e4SLinus Torvalds *mount_opts |= SF_IMMUTABLE; 2311da177e4SLinus Torvalds break; 2321da177e4SLinus Torvalds case Opt_reserved: 2331da177e4SLinus Torvalds if (match_int(&args[0], reserved)) 234*217686e9SAl Viro return 0; 2351da177e4SLinus Torvalds break; 2361da177e4SLinus Torvalds case Opt_root: 2371da177e4SLinus Torvalds if (match_int(&args[0], root)) 238*217686e9SAl Viro return 0; 2391da177e4SLinus Torvalds break; 2401da177e4SLinus Torvalds case Opt_setgid: 2411da177e4SLinus Torvalds if (match_int(&args[0], &option)) 242*217686e9SAl Viro return 0; 2431da177e4SLinus Torvalds *gid = option; 2441da177e4SLinus Torvalds *mount_opts |= SF_SETGID; 2451da177e4SLinus Torvalds break; 2461da177e4SLinus Torvalds case Opt_setuid: 2471da177e4SLinus Torvalds if (match_int(&args[0], &option)) 248*217686e9SAl Viro return 0; 2491da177e4SLinus Torvalds *uid = option; 2501da177e4SLinus Torvalds *mount_opts |= SF_SETUID; 2511da177e4SLinus Torvalds break; 2521da177e4SLinus Torvalds case Opt_verbose: 2531da177e4SLinus Torvalds *mount_opts |= SF_VERBOSE; 2541da177e4SLinus Torvalds break; 2551da177e4SLinus Torvalds case Opt_volume: { 2561da177e4SLinus Torvalds char *vol = match_strdup(&args[0]); 2576db27dd9SJim Meyering if (!vol) 2586db27dd9SJim Meyering return 0; 2591da177e4SLinus Torvalds strlcpy(volume, vol, 32); 2601da177e4SLinus Torvalds kfree(vol); 2611da177e4SLinus Torvalds break; 2621da177e4SLinus Torvalds } 2631da177e4SLinus Torvalds case Opt_ignore: 2641da177e4SLinus Torvalds /* Silently ignore the quota options */ 2651da177e4SLinus Torvalds break; 2661da177e4SLinus Torvalds default: 2671da177e4SLinus Torvalds printk("AFFS: Unrecognized mount option \"%s\" " 2681da177e4SLinus Torvalds "or missing value\n", p); 2691da177e4SLinus Torvalds return 0; 2701da177e4SLinus Torvalds } 2711da177e4SLinus Torvalds } 2721da177e4SLinus Torvalds return 1; 2731da177e4SLinus Torvalds } 2741da177e4SLinus Torvalds 2751da177e4SLinus Torvalds /* This function definitely needs to be split up. Some fine day I'll 2761da177e4SLinus Torvalds * hopefully have the guts to do so. Until then: sorry for the mess. 2771da177e4SLinus Torvalds */ 2781da177e4SLinus Torvalds 2791da177e4SLinus Torvalds static int affs_fill_super(struct super_block *sb, void *data, int silent) 2801da177e4SLinus Torvalds { 2811da177e4SLinus Torvalds struct affs_sb_info *sbi; 2821da177e4SLinus Torvalds struct buffer_head *root_bh = NULL; 2831da177e4SLinus Torvalds struct buffer_head *boot_bh; 2841da177e4SLinus Torvalds struct inode *root_inode = NULL; 2851da177e4SLinus Torvalds s32 root_block; 2861da177e4SLinus Torvalds int size, blocksize; 2871da177e4SLinus Torvalds u32 chksum; 2881da177e4SLinus Torvalds int num_bm; 2891da177e4SLinus Torvalds int i, j; 2901da177e4SLinus Torvalds s32 key; 2911da177e4SLinus Torvalds uid_t uid; 2921da177e4SLinus Torvalds gid_t gid; 2931da177e4SLinus Torvalds int reserved; 2941da177e4SLinus Torvalds unsigned long mount_flags; 2951da177e4SLinus Torvalds int tmp_flags; /* fix remount prototype... */ 2962b943cf0SAl Viro u8 sig[4]; 297210f8559SDavid Howells int ret = -EINVAL; 2981da177e4SLinus Torvalds 299e9b3961bSMiklos Szeredi save_mount_options(sb, data); 300e9b3961bSMiklos Szeredi 3011da177e4SLinus Torvalds pr_debug("AFFS: read_super(%s)\n",data ? (const char *)data : "no options"); 3021da177e4SLinus Torvalds 3031da177e4SLinus Torvalds sb->s_magic = AFFS_SUPER_MAGIC; 3041da177e4SLinus Torvalds sb->s_op = &affs_sops; 3051da177e4SLinus Torvalds sb->s_flags |= MS_NODIRATIME; 3061da177e4SLinus Torvalds 307f8314dc6SPanagiotis Issaris sbi = kzalloc(sizeof(struct affs_sb_info), GFP_KERNEL); 3081da177e4SLinus Torvalds if (!sbi) 3091da177e4SLinus Torvalds return -ENOMEM; 3101da177e4SLinus Torvalds sb->s_fs_info = sbi; 3117d135a5dSMatthias Kaehlcke mutex_init(&sbi->s_bmlock); 31229333920SAl Viro spin_lock_init(&sbi->symlink_lock); 3131da177e4SLinus Torvalds 3141da177e4SLinus Torvalds if (!parse_options(data,&uid,&gid,&i,&reserved,&root_block, 3151da177e4SLinus Torvalds &blocksize,&sbi->s_prefix, 3161da177e4SLinus Torvalds sbi->s_volume, &mount_flags)) { 3171da177e4SLinus Torvalds printk(KERN_ERR "AFFS: Error parsing options\n"); 318afc70ed0SAl Viro kfree(sbi->s_prefix); 319afc70ed0SAl Viro kfree(sbi); 3201da177e4SLinus Torvalds return -EINVAL; 3211da177e4SLinus Torvalds } 3221da177e4SLinus Torvalds /* N.B. after this point s_prefix must be released */ 3231da177e4SLinus Torvalds 3241da177e4SLinus Torvalds sbi->s_flags = mount_flags; 3251da177e4SLinus Torvalds sbi->s_mode = i; 3261da177e4SLinus Torvalds sbi->s_uid = uid; 3271da177e4SLinus Torvalds sbi->s_gid = gid; 3281da177e4SLinus Torvalds sbi->s_reserved= reserved; 3291da177e4SLinus Torvalds 3301da177e4SLinus Torvalds /* Get the size of the device in 512-byte blocks. 3311da177e4SLinus Torvalds * If we later see that the partition uses bigger 3321da177e4SLinus Torvalds * blocks, we will have to change it. 3331da177e4SLinus Torvalds */ 3341da177e4SLinus Torvalds 3351da177e4SLinus Torvalds size = sb->s_bdev->bd_inode->i_size >> 9; 3361da177e4SLinus Torvalds pr_debug("AFFS: initial blocksize=%d, #blocks=%d\n", 512, size); 3371da177e4SLinus Torvalds 3381da177e4SLinus Torvalds affs_set_blocksize(sb, PAGE_SIZE); 3391da177e4SLinus Torvalds /* Try to find root block. Its location depends on the block size. */ 3401da177e4SLinus Torvalds 3411da177e4SLinus Torvalds i = 512; 3421da177e4SLinus Torvalds j = 4096; 3431da177e4SLinus Torvalds if (blocksize > 0) { 3441da177e4SLinus Torvalds i = j = blocksize; 3451da177e4SLinus Torvalds size = size / (blocksize / 512); 3461da177e4SLinus Torvalds } 3471da177e4SLinus Torvalds for (blocksize = i, key = 0; blocksize <= j; blocksize <<= 1, size >>= 1) { 3481da177e4SLinus Torvalds sbi->s_root_block = root_block; 3491da177e4SLinus Torvalds if (root_block < 0) 3501da177e4SLinus Torvalds sbi->s_root_block = (reserved + size - 1) / 2; 3511da177e4SLinus Torvalds pr_debug("AFFS: setting blocksize to %d\n", blocksize); 3521da177e4SLinus Torvalds affs_set_blocksize(sb, blocksize); 3531da177e4SLinus Torvalds sbi->s_partition_size = size; 3541da177e4SLinus Torvalds 3551da177e4SLinus Torvalds /* The root block location that was calculated above is not 3561da177e4SLinus Torvalds * correct if the partition size is an odd number of 512- 3571da177e4SLinus Torvalds * byte blocks, which will be rounded down to a number of 3581da177e4SLinus Torvalds * 1024-byte blocks, and if there were an even number of 3591da177e4SLinus Torvalds * reserved blocks. Ideally, all partition checkers should 3601da177e4SLinus Torvalds * report the real number of blocks of the real blocksize, 3611da177e4SLinus Torvalds * but since this just cannot be done, we have to try to 3621da177e4SLinus Torvalds * find the root block anyways. In the above case, it is one 3631da177e4SLinus Torvalds * block behind the calculated one. So we check this one, too. 3641da177e4SLinus Torvalds */ 3651da177e4SLinus Torvalds for (num_bm = 0; num_bm < 2; num_bm++) { 3661da177e4SLinus Torvalds pr_debug("AFFS: Dev %s, trying root=%u, bs=%d, " 3671da177e4SLinus Torvalds "size=%d, reserved=%d\n", 3681da177e4SLinus Torvalds sb->s_id, 3691da177e4SLinus Torvalds sbi->s_root_block + num_bm, 3701da177e4SLinus Torvalds blocksize, size, reserved); 3711da177e4SLinus Torvalds root_bh = affs_bread(sb, sbi->s_root_block + num_bm); 3721da177e4SLinus Torvalds if (!root_bh) 3731da177e4SLinus Torvalds continue; 3741da177e4SLinus Torvalds if (!affs_checksum_block(sb, root_bh) && 3751da177e4SLinus Torvalds be32_to_cpu(AFFS_ROOT_HEAD(root_bh)->ptype) == T_SHORT && 3761da177e4SLinus Torvalds be32_to_cpu(AFFS_ROOT_TAIL(sb, root_bh)->stype) == ST_ROOT) { 3771da177e4SLinus Torvalds sbi->s_hashsize = blocksize / 4 - 56; 3781da177e4SLinus Torvalds sbi->s_root_block += num_bm; 3791da177e4SLinus Torvalds key = 1; 3801da177e4SLinus Torvalds goto got_root; 3811da177e4SLinus Torvalds } 3821da177e4SLinus Torvalds affs_brelse(root_bh); 3831da177e4SLinus Torvalds root_bh = NULL; 3841da177e4SLinus Torvalds } 3851da177e4SLinus Torvalds } 3861da177e4SLinus Torvalds if (!silent) 3871da177e4SLinus Torvalds printk(KERN_ERR "AFFS: No valid root block on device %s\n", 3881da177e4SLinus Torvalds sb->s_id); 3891da177e4SLinus Torvalds goto out_error; 3901da177e4SLinus Torvalds 3911da177e4SLinus Torvalds /* N.B. after this point bh must be released */ 3921da177e4SLinus Torvalds got_root: 3931da177e4SLinus Torvalds root_block = sbi->s_root_block; 3941da177e4SLinus Torvalds 3951da177e4SLinus Torvalds /* Find out which kind of FS we have */ 3961da177e4SLinus Torvalds boot_bh = sb_bread(sb, 0); 3971da177e4SLinus Torvalds if (!boot_bh) { 3981da177e4SLinus Torvalds printk(KERN_ERR "AFFS: Cannot read boot block\n"); 3991da177e4SLinus Torvalds goto out_error; 4001da177e4SLinus Torvalds } 4012b943cf0SAl Viro memcpy(sig, boot_bh->b_data, 4); 4021da177e4SLinus Torvalds brelse(boot_bh); 4032b943cf0SAl Viro chksum = be32_to_cpu(*(__be32 *)sig); 4041da177e4SLinus Torvalds 4051da177e4SLinus Torvalds /* Dircache filesystems are compatible with non-dircache ones 4061da177e4SLinus Torvalds * when reading. As long as they aren't supported, writing is 4071da177e4SLinus Torvalds * not recommended. 4081da177e4SLinus Torvalds */ 4091da177e4SLinus Torvalds if ((chksum == FS_DCFFS || chksum == MUFS_DCFFS || chksum == FS_DCOFS 4101da177e4SLinus Torvalds || chksum == MUFS_DCOFS) && !(sb->s_flags & MS_RDONLY)) { 4111da177e4SLinus Torvalds printk(KERN_NOTICE "AFFS: Dircache FS - mounting %s read only\n", 4121da177e4SLinus Torvalds sb->s_id); 4131da177e4SLinus Torvalds sb->s_flags |= MS_RDONLY; 4141da177e4SLinus Torvalds } 4151da177e4SLinus Torvalds switch (chksum) { 4161da177e4SLinus Torvalds case MUFS_FS: 4171da177e4SLinus Torvalds case MUFS_INTLFFS: 4181da177e4SLinus Torvalds case MUFS_DCFFS: 4191da177e4SLinus Torvalds sbi->s_flags |= SF_MUFS; 4201da177e4SLinus Torvalds /* fall thru */ 4211da177e4SLinus Torvalds case FS_INTLFFS: 4221da177e4SLinus Torvalds case FS_DCFFS: 4231da177e4SLinus Torvalds sbi->s_flags |= SF_INTL; 4241da177e4SLinus Torvalds break; 4251da177e4SLinus Torvalds case MUFS_FFS: 4261da177e4SLinus Torvalds sbi->s_flags |= SF_MUFS; 4271da177e4SLinus Torvalds break; 4281da177e4SLinus Torvalds case FS_FFS: 4291da177e4SLinus Torvalds break; 4301da177e4SLinus Torvalds case MUFS_OFS: 4311da177e4SLinus Torvalds sbi->s_flags |= SF_MUFS; 4321da177e4SLinus Torvalds /* fall thru */ 4331da177e4SLinus Torvalds case FS_OFS: 4341da177e4SLinus Torvalds sbi->s_flags |= SF_OFS; 4351da177e4SLinus Torvalds sb->s_flags |= MS_NOEXEC; 4361da177e4SLinus Torvalds break; 4371da177e4SLinus Torvalds case MUFS_DCOFS: 4381da177e4SLinus Torvalds case MUFS_INTLOFS: 4391da177e4SLinus Torvalds sbi->s_flags |= SF_MUFS; 4401da177e4SLinus Torvalds case FS_DCOFS: 4411da177e4SLinus Torvalds case FS_INTLOFS: 4421da177e4SLinus Torvalds sbi->s_flags |= SF_INTL | SF_OFS; 4431da177e4SLinus Torvalds sb->s_flags |= MS_NOEXEC; 4441da177e4SLinus Torvalds break; 4451da177e4SLinus Torvalds default: 4461da177e4SLinus Torvalds printk(KERN_ERR "AFFS: Unknown filesystem on device %s: %08X\n", 4471da177e4SLinus Torvalds sb->s_id, chksum); 4481da177e4SLinus Torvalds goto out_error; 4491da177e4SLinus Torvalds } 4501da177e4SLinus Torvalds 4511da177e4SLinus Torvalds if (mount_flags & SF_VERBOSE) { 4522b943cf0SAl Viro u8 len = AFFS_ROOT_TAIL(sb, root_bh)->disk_name[0]; 4532b943cf0SAl Viro printk(KERN_NOTICE "AFFS: Mounting volume \"%.*s\": Type=%.3s\\%c, Blocksize=%d\n", 4542b943cf0SAl Viro len > 31 ? 31 : len, 4551da177e4SLinus Torvalds AFFS_ROOT_TAIL(sb, root_bh)->disk_name + 1, 4562b943cf0SAl Viro sig, sig[3] + '0', blocksize); 4571da177e4SLinus Torvalds } 4581da177e4SLinus Torvalds 4591da177e4SLinus Torvalds sb->s_flags |= MS_NODEV | MS_NOSUID; 4601da177e4SLinus Torvalds 4611da177e4SLinus Torvalds sbi->s_data_blksize = sb->s_blocksize; 4621da177e4SLinus Torvalds if (sbi->s_flags & SF_OFS) 4631da177e4SLinus Torvalds sbi->s_data_blksize -= 24; 4641da177e4SLinus Torvalds 4651da177e4SLinus Torvalds /* Keep super block in cache */ 4661da177e4SLinus Torvalds sbi->s_root_bh = root_bh; 4671da177e4SLinus Torvalds /* N.B. after this point s_root_bh must be released */ 4681da177e4SLinus Torvalds 4691da177e4SLinus Torvalds tmp_flags = sb->s_flags; 4701da177e4SLinus Torvalds if (affs_init_bitmap(sb, &tmp_flags)) 4711da177e4SLinus Torvalds goto out_error; 4721da177e4SLinus Torvalds sb->s_flags = tmp_flags; 4731da177e4SLinus Torvalds 4741da177e4SLinus Torvalds /* set up enough so that it can read an inode */ 4751da177e4SLinus Torvalds 476210f8559SDavid Howells root_inode = affs_iget(sb, root_block); 477210f8559SDavid Howells if (IS_ERR(root_inode)) { 478210f8559SDavid Howells ret = PTR_ERR(root_inode); 479210f8559SDavid Howells goto out_error_noinode; 480210f8559SDavid Howells } 481210f8559SDavid Howells 4821da177e4SLinus Torvalds sb->s_root = d_alloc_root(root_inode); 4831da177e4SLinus Torvalds if (!sb->s_root) { 4841da177e4SLinus Torvalds printk(KERN_ERR "AFFS: Get root inode failed\n"); 4851da177e4SLinus Torvalds goto out_error; 4861da177e4SLinus Torvalds } 4871da177e4SLinus Torvalds sb->s_root->d_op = &affs_dentry_operations; 4881da177e4SLinus Torvalds 4891da177e4SLinus Torvalds pr_debug("AFFS: s_flags=%lX\n",sb->s_flags); 4901da177e4SLinus Torvalds return 0; 4911da177e4SLinus Torvalds 4921da177e4SLinus Torvalds /* 4931da177e4SLinus Torvalds * Begin the cascaded cleanup ... 4941da177e4SLinus Torvalds */ 4951da177e4SLinus Torvalds out_error: 4961da177e4SLinus Torvalds if (root_inode) 4971da177e4SLinus Torvalds iput(root_inode); 498210f8559SDavid Howells out_error_noinode: 4991da177e4SLinus Torvalds kfree(sbi->s_bitmap); 5001da177e4SLinus Torvalds affs_brelse(root_bh); 5011da177e4SLinus Torvalds kfree(sbi->s_prefix); 5021da177e4SLinus Torvalds kfree(sbi); 5031da177e4SLinus Torvalds sb->s_fs_info = NULL; 504210f8559SDavid Howells return ret; 5051da177e4SLinus Torvalds } 5061da177e4SLinus Torvalds 5071da177e4SLinus Torvalds static int 5081da177e4SLinus Torvalds affs_remount(struct super_block *sb, int *flags, char *data) 5091da177e4SLinus Torvalds { 5101da177e4SLinus Torvalds struct affs_sb_info *sbi = AFFS_SB(sb); 5111da177e4SLinus Torvalds int blocksize; 5121da177e4SLinus Torvalds uid_t uid; 5131da177e4SLinus Torvalds gid_t gid; 5141da177e4SLinus Torvalds int mode; 5151da177e4SLinus Torvalds int reserved; 5161da177e4SLinus Torvalds int root_block; 5171da177e4SLinus Torvalds unsigned long mount_flags; 5181da177e4SLinus Torvalds int res = 0; 519e9b3961bSMiklos Szeredi char *new_opts = kstrdup(data, GFP_KERNEL); 52029333920SAl Viro char volume[32]; 52129333920SAl Viro char *prefix = NULL; 5221da177e4SLinus Torvalds 5231da177e4SLinus Torvalds pr_debug("AFFS: remount(flags=0x%x,opts=\"%s\")\n",*flags,data); 5241da177e4SLinus Torvalds 5251da177e4SLinus Torvalds *flags |= MS_NODIRATIME; 5261da177e4SLinus Torvalds 52729333920SAl Viro memcpy(volume, sbi->s_volume, 32); 5281da177e4SLinus Torvalds if (!parse_options(data, &uid, &gid, &mode, &reserved, &root_block, 52929333920SAl Viro &blocksize, &prefix, volume, 530e9b3961bSMiklos Szeredi &mount_flags)) { 53129333920SAl Viro kfree(prefix); 532e9b3961bSMiklos Szeredi kfree(new_opts); 5331da177e4SLinus Torvalds return -EINVAL; 534e9b3961bSMiklos Szeredi } 535337eb00aSAlessio Igor Bogani lock_kernel(); 5362a32cebdSAl Viro replace_mount_options(sb, new_opts); 537e9b3961bSMiklos Szeredi 5381da177e4SLinus Torvalds sbi->s_flags = mount_flags; 5391da177e4SLinus Torvalds sbi->s_mode = mode; 5401da177e4SLinus Torvalds sbi->s_uid = uid; 5411da177e4SLinus Torvalds sbi->s_gid = gid; 54229333920SAl Viro /* protect against readers */ 54329333920SAl Viro spin_lock(&sbi->symlink_lock); 54429333920SAl Viro if (prefix) { 54529333920SAl Viro kfree(sbi->s_prefix); 54629333920SAl Viro sbi->s_prefix = prefix; 54729333920SAl Viro } 54829333920SAl Viro memcpy(sbi->s_volume, volume, 32); 54929333920SAl Viro spin_unlock(&sbi->symlink_lock); 5501da177e4SLinus Torvalds 551337eb00aSAlessio Igor Bogani if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY)) { 552337eb00aSAlessio Igor Bogani unlock_kernel(); 5531da177e4SLinus Torvalds return 0; 554337eb00aSAlessio Igor Bogani } 5551da177e4SLinus Torvalds if (*flags & MS_RDONLY) { 5561da177e4SLinus Torvalds sb->s_dirt = 1; 5571da177e4SLinus Torvalds while (sb->s_dirt) 5581da177e4SLinus Torvalds affs_write_super(sb); 5591da177e4SLinus Torvalds affs_free_bitmap(sb); 5601da177e4SLinus Torvalds } else 5611da177e4SLinus Torvalds res = affs_init_bitmap(sb, flags); 5621da177e4SLinus Torvalds 563337eb00aSAlessio Igor Bogani unlock_kernel(); 5641da177e4SLinus Torvalds return res; 5651da177e4SLinus Torvalds } 5661da177e4SLinus Torvalds 5671da177e4SLinus Torvalds static int 568726c3342SDavid Howells affs_statfs(struct dentry *dentry, struct kstatfs *buf) 5691da177e4SLinus Torvalds { 570726c3342SDavid Howells struct super_block *sb = dentry->d_sb; 5711da177e4SLinus Torvalds int free; 572a6a2a73cSColy Li u64 id = huge_encode_dev(sb->s_bdev->bd_dev); 5731da177e4SLinus Torvalds 5741da177e4SLinus Torvalds pr_debug("AFFS: statfs() partsize=%d, reserved=%d\n",AFFS_SB(sb)->s_partition_size, 5751da177e4SLinus Torvalds AFFS_SB(sb)->s_reserved); 5761da177e4SLinus Torvalds 5771da177e4SLinus Torvalds free = affs_count_free_blocks(sb); 5781da177e4SLinus Torvalds buf->f_type = AFFS_SUPER_MAGIC; 5791da177e4SLinus Torvalds buf->f_bsize = sb->s_blocksize; 5801da177e4SLinus Torvalds buf->f_blocks = AFFS_SB(sb)->s_partition_size - AFFS_SB(sb)->s_reserved; 5811da177e4SLinus Torvalds buf->f_bfree = free; 5821da177e4SLinus Torvalds buf->f_bavail = free; 583a6a2a73cSColy Li buf->f_fsid.val[0] = (u32)id; 584a6a2a73cSColy Li buf->f_fsid.val[1] = (u32)(id >> 32); 585a6a2a73cSColy Li buf->f_namelen = 30; 5861da177e4SLinus Torvalds return 0; 5871da177e4SLinus Torvalds } 5881da177e4SLinus Torvalds 589454e2398SDavid Howells static int affs_get_sb(struct file_system_type *fs_type, 590454e2398SDavid Howells int flags, const char *dev_name, void *data, struct vfsmount *mnt) 5911da177e4SLinus Torvalds { 592454e2398SDavid Howells return get_sb_bdev(fs_type, flags, dev_name, data, affs_fill_super, 593454e2398SDavid Howells mnt); 5941da177e4SLinus Torvalds } 5951da177e4SLinus Torvalds 5961da177e4SLinus Torvalds static struct file_system_type affs_fs_type = { 5971da177e4SLinus Torvalds .owner = THIS_MODULE, 5981da177e4SLinus Torvalds .name = "affs", 5991da177e4SLinus Torvalds .get_sb = affs_get_sb, 6001da177e4SLinus Torvalds .kill_sb = kill_block_super, 6011da177e4SLinus Torvalds .fs_flags = FS_REQUIRES_DEV, 6021da177e4SLinus Torvalds }; 6031da177e4SLinus Torvalds 6041da177e4SLinus Torvalds static int __init init_affs_fs(void) 6051da177e4SLinus Torvalds { 6061da177e4SLinus Torvalds int err = init_inodecache(); 6071da177e4SLinus Torvalds if (err) 6081da177e4SLinus Torvalds goto out1; 6091da177e4SLinus Torvalds err = register_filesystem(&affs_fs_type); 6101da177e4SLinus Torvalds if (err) 6111da177e4SLinus Torvalds goto out; 6121da177e4SLinus Torvalds return 0; 6131da177e4SLinus Torvalds out: 6141da177e4SLinus Torvalds destroy_inodecache(); 6151da177e4SLinus Torvalds out1: 6161da177e4SLinus Torvalds return err; 6171da177e4SLinus Torvalds } 6181da177e4SLinus Torvalds 6191da177e4SLinus Torvalds static void __exit exit_affs_fs(void) 6201da177e4SLinus Torvalds { 6211da177e4SLinus Torvalds unregister_filesystem(&affs_fs_type); 6221da177e4SLinus Torvalds destroy_inodecache(); 6231da177e4SLinus Torvalds } 6241da177e4SLinus Torvalds 6251da177e4SLinus Torvalds MODULE_DESCRIPTION("Amiga filesystem support for Linux"); 6261da177e4SLinus Torvalds MODULE_LICENSE("GPL"); 6271da177e4SLinus Torvalds 6281da177e4SLinus Torvalds module_init(init_affs_fs) 6291da177e4SLinus Torvalds module_exit(exit_affs_fs) 630