📄 super.c
字号:
/* * linux/fs/affs/inode.c * * (c) 1996 Hans-Joachim Widmaier - Rewritten * * (C) 1993 Ray Burr - Modified for Amiga FFS filesystem. * * (C) 1992 Eric Youngdale Modified for ISO 9660 filesystem. * * (C) 1991 Linus Torvalds - minix filesystem */#define DEBUG 0#include <linux/module.h>#include <linux/errno.h>#include <linux/fs.h>#include <linux/malloc.h>#include <linux/stat.h>#include <linux/sched.h>#include <linux/affs_fs.h>#include <linux/kernel.h>#include <linux/mm.h>#include <linux/string.h>#include <linux/locks.h>#include <linux/genhd.h>#include <linux/amigaffs.h>#include <linux/major.h>#include <linux/blkdev.h>#include <linux/init.h>#include <asm/system.h>#include <asm/uaccess.h>extern int *blk_size[];extern struct timezone sys_tz;#define MIN(a,b) (((a)<(b))?(a):(b))static int affs_statfs(struct super_block *sb, struct statfs *buf);static int affs_remount (struct super_block *sb, int *flags, char *data);static voidaffs_put_super(struct super_block *sb){ int i; pr_debug("AFFS: put_super()\n"); for (i = 0; i < sb->u.affs_sb.s_bm_count; i++) affs_brelse(sb->u.affs_sb.s_bitmap[i].bm_bh); if (!(sb->s_flags & MS_RDONLY)) { ROOT_END_S(sb->u.affs_sb.s_root_bh->b_data,sb)->bm_flag = be32_to_cpu(1); secs_to_datestamp(CURRENT_TIME, &ROOT_END_S(sb->u.affs_sb.s_root_bh->b_data,sb)->disk_altered); affs_fix_checksum(sb->s_blocksize,sb->u.affs_sb.s_root_bh->b_data,5); mark_buffer_dirty(sb->u.affs_sb.s_root_bh); } if (sb->u.affs_sb.s_prefix) kfree(sb->u.affs_sb.s_prefix); kfree(sb->u.affs_sb.s_bitmap); affs_brelse(sb->u.affs_sb.s_root_bh); /* * Restore the previous value of this device's blksize_size[][] */ set_blocksize(sb->s_dev, sb->u.affs_sb.s_blksize); return;}static voidaffs_write_super(struct super_block *sb){ int i, clean = 2; if (!(sb->s_flags & MS_RDONLY)) { lock_super(sb); for (i = 0, clean = 1; i < sb->u.affs_sb.s_bm_count; i++) { if (sb->u.affs_sb.s_bitmap[i].bm_bh) { if (buffer_dirty(sb->u.affs_sb.s_bitmap[i].bm_bh)) { clean = 0; break; } } } unlock_super(sb); ROOT_END_S(sb->u.affs_sb.s_root_bh->b_data,sb)->bm_flag = be32_to_cpu(clean); secs_to_datestamp(CURRENT_TIME, &ROOT_END_S(sb->u.affs_sb.s_root_bh->b_data,sb)->disk_altered); affs_fix_checksum(sb->s_blocksize,sb->u.affs_sb.s_root_bh->b_data,5); mark_buffer_dirty(sb->u.affs_sb.s_root_bh); sb->s_dirt = !clean; /* redo until bitmap synced */ } else sb->s_dirt = 0; pr_debug("AFFS: write_super() at %lu, clean=%d\n", CURRENT_TIME, clean);}static struct super_operations affs_sops = { read_inode: affs_read_inode, write_inode: affs_write_inode, put_inode: affs_put_inode, delete_inode: affs_delete_inode, put_super: affs_put_super, write_super: affs_write_super, statfs: affs_statfs, remount_fs: affs_remount,};static intparse_options(char *options, uid_t *uid, gid_t *gid, int *mode, int *reserved, s32 *root, int *blocksize, char **prefix, char *volume, unsigned long *mount_opts){ char *this_char, *value, *optn; int f; /* Fill in defaults */ *uid = current->uid; *gid = current->gid; *reserved = 2; *root = -1; *blocksize = -1; volume[0] = ':'; volume[1] = 0; *mount_opts = 0; if (!options) return 1; for (this_char = strtok(options,","); this_char; this_char = strtok(NULL,",")) { f = 0; if ((value = strchr(this_char,'=')) != NULL) *value++ = 0; if ((optn = "protect") && !strcmp(this_char, optn)) { if (value) goto out_inv_arg; *mount_opts |= SF_IMMUTABLE; } else if ((optn = "verbose") && !strcmp(this_char, optn)) { if (value) goto out_inv_arg; *mount_opts |= SF_VERBOSE; } else if ((optn = "mufs") && !strcmp(this_char, optn)) { if (value) goto out_inv_arg; *mount_opts |= SF_MUFS; } else if ((f = !strcmp(this_char,"setuid")) || !strcmp(this_char,"setgid")) { if (value) { if (!*value) { printk("AFFS: Argument for set[ug]id option missing\n"); return 0; } else { (f ? *uid : *gid) = simple_strtoul(value,&value,0); if (*value) { printk("AFFS: Bad set[ug]id argument\n"); return 0; } *mount_opts |= f ? SF_SETUID : SF_SETGID; } } } else if (!strcmp(this_char,"prefix")) { optn = "prefix"; if (!value || !*value) goto out_no_arg; if (*prefix) { /* Free any previous prefix */ kfree(*prefix); *prefix = NULL; } *prefix = kmalloc(strlen(value) + 1,GFP_KERNEL); if (!*prefix) return 0; strcpy(*prefix,value); *mount_opts |= SF_PREFIX; } else if (!strcmp(this_char,"volume")) { optn = "volume"; if (!value || !*value) goto out_no_arg; if (strlen(value) > 30) value[30] = 0; strncpy(volume,value,30); } else if (!strcmp(this_char,"mode")) { optn = "mode"; if (!value || !*value) goto out_no_arg; *mode = simple_strtoul(value,&value,8) & 0777; if (*value) return 0; *mount_opts |= SF_SETMODE; } else if (!strcmp(this_char,"reserved")) { optn = "reserved"; if (!value || !*value) goto out_no_arg; *reserved = simple_strtoul(value,&value,0); if (*value) return 0; } else if (!strcmp(this_char,"root")) { optn = "root"; if (!value || !*value) goto out_no_arg; *root = simple_strtoul(value,&value,0); if (*value) return 0; } else if (!strcmp(this_char,"bs")) { optn = "bs"; if (!value || !*value) goto out_no_arg; *blocksize = simple_strtoul(value,&value,0); if (*value) return 0; if (*blocksize != 512 && *blocksize != 1024 && *blocksize != 2048 && *blocksize != 4096) { printk ("AFFS: Invalid blocksize (512, 1024, 2048, 4096 allowed)\n"); return 0; } } else if (!strcmp (this_char, "grpquota") || !strcmp (this_char, "noquota") || !strcmp (this_char, "quota") || !strcmp (this_char, "usrquota")) /* Silently ignore the quota options */ ; else { printk("AFFS: Unrecognized mount option %s\n", this_char); return 0; } } return 1;out_no_arg: printk("AFFS: The %s option requires an argument\n", optn); return 0;out_inv_arg: printk("AFFS: Option %s does not take an argument\n", optn); return 0;}/* This function definitely needs to be split up. Some fine day I'll * hopefully have the guts to do so. Until then: sorry for the mess. */static struct super_block *affs_read_super(struct super_block *s, void *data, int silent){ struct buffer_head *bh = NULL; struct buffer_head *bb; struct inode *root_inode; kdev_t dev = s->s_dev; s32 root_block; int blocks, size, blocksize; u32 chksum; u32 *bm; s32 ptype, stype; int mapidx; int num_bm; int i, j; s32 key; uid_t uid; gid_t gid; int reserved; int az_no; int bmalt = 0; unsigned long mount_flags; unsigned long offset; pr_debug("AFFS: read_super(%s)\n",data ? (const char *)data : "no options"); s->s_magic = AFFS_SUPER_MAGIC; s->s_op = &affs_sops; s->u.affs_sb.s_bitmap = NULL; s->u.affs_sb.s_root_bh = NULL; s->u.affs_sb.s_prefix = NULL; s->u.affs_sb.s_hashsize= 0; if (!parse_options(data,&uid,&gid,&i,&reserved,&root_block, &blocksize,&s->u.affs_sb.s_prefix, s->u.affs_sb.s_volume, &mount_flags)) goto out_bad_opts; /* N.B. after this point s_prefix must be released */ s->u.affs_sb.s_flags = mount_flags; s->u.affs_sb.s_mode = i; s->u.affs_sb.s_uid = uid; s->u.affs_sb.s_gid = gid; s->u.affs_sb.s_reserved= reserved; /* Get the size of the device in 512-byte blocks. * If we later see that the partition uses bigger * blocks, we will have to change it. */ blocks = blk_size[MAJOR(dev)][MINOR(dev)]; if (blocks == 0) goto out_bad_size; s->u.affs_sb.s_blksize = blksize_size[MAJOR(dev)][MINOR(dev)]; if (!s->u.affs_sb.s_blksize) s->u.affs_sb.s_blksize = BLOCK_SIZE; size = (s->u.affs_sb.s_blksize / 512) * blocks; pr_debug("AFFS: initial blksize=%d, blocks=%d\n", s->u.affs_sb.s_blksize, blocks); /* Try to find root block. Its location depends on the block size. */ i = 512; j = 4096; if (blocksize > 0) { i = j = blocksize; size = size / (blocksize / 512); } for (blocksize = i, key = 0; blocksize <= j; blocksize <<= 1, size >>= 1) { s->u.affs_sb.s_root_block = root_block; if (root_block < 0) s->u.affs_sb.s_root_block = (reserved + size - 1) / 2; pr_debug("AFFS: setting blocksize to %d\n", blocksize); set_blocksize(dev, blocksize); /* The root block location that was calculated above is not * correct if the partition size is an odd number of 512- * byte blocks, which will be rounded down to a number of * 1024-byte blocks, and if there were an even number of * reserved blocks. Ideally, all partition checkers should * report the real number of blocks of the real blocksize, * but since this just cannot be done, we have to try to * find the root block anyways. In the above case, it is one * block behind the calculated one. So we check this one, too. */ for (num_bm = 0; num_bm < 2; num_bm++) { pr_debug("AFFS: Dev %s, trying root=%u, bs=%d, " "size=%d, reserved=%d\n", kdevname(dev), s->u.affs_sb.s_root_block + num_bm, blocksize, size, reserved); bh = affs_bread(dev, s->u.affs_sb.s_root_block + num_bm, blocksize); if (!bh) continue; if (!affs_checksum_block(blocksize,bh->b_data,&ptype,&stype) && ptype == T_SHORT && stype == ST_ROOT) { s->s_blocksize = blocksize; s->u.affs_sb.s_hashsize = blocksize / 4 - 56; s->u.affs_sb.s_root_block += num_bm; key = 1; goto got_root; } affs_brelse(bh); bh = NULL; } } goto out_no_valid_block;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -