super.c
/*
* super.c
*
* Copyright (c) 1999 Al Smith
*
* Portions derived from work (c) 1995,1996 Christian Vogelgsang.
*/
#include
#include «efs.h» static int efs_statfs(struct dentry *dentry, struct kstatfs *buf); static int efs_get_sb(struct file_system_type *fs_type, static struct file_system_type efs_fs_type = { static struct pt_types sgi_pt_types[] = { static struct kmem_cache * efs_inode_cachep; static struct inode *efs_alloc_inode(struct super_block *sb) static void efs_destroy_inode(struct inode *inode) static void init_once(void *foo) inode_init_once(&ei->vfs_inode); static int init_inodecache(void) static void destroy_inodecache(void) static void efs_put_super(struct super_block *s) static int efs_remount(struct super_block *sb, int *flags, char *data) static const struct super_operations efs_superblock_operations = { static const struct export_operations efs_export_ops = { static int __init init_efs_fs(void) { static void __exit exit_efs_fs(void) { module_init(init_efs_fs) static efs_block_t efs_validate_vh(struct volume_header *vh) { if (be32_to_cpu(vh->vh_magic) != VHMAGIC) { ui = ((__be32 *) (vh + 1)) – 1; #ifdef DEBUG for(i = 0; i < NVDIR; i++) { for(j = 0; j < VDNAMESIZE; j++) { if (name[0]) { for(i = 0; i < NPARTAB; i++) { if (slice == -1) { static int efs_validate_super(struct efs_sb_info *sb, struct efs_super *super) { if (!IS_EFS_MAGIC(be32_to_cpu(super->fs_magic))) sb->fs_magic = be32_to_cpu(super->fs_magic); return 0; static int efs_fill_super(struct super_block *s, void *d, int silent) sb = kzalloc(sizeof(struct efs_sb_info), GFP_KERNEL); s->s_magic = EFS_SUPER_MAGIC; /* read the vh (volume header) block */ if (!bh) { /* if (sb->fs_start == -1) { bh = sb_bread(s, sb->fs_start + EFS_SUPER); if (efs_validate_super(sb, (struct efs_super *) bh->b_data)) { if (!(s->s_flags & MS_RDONLY)) { s->s_root = d_alloc_root(root); return 0; out_no_fs_ul: static int efs_statfs(struct dentry *dentry, struct kstatfs *buf) { buf->f_type = EFS_SUPER_MAGIC; /* efs magic number */ return 0;
#include
static int efs_fill_super(struct super_block *s, void *d, int silent);
int flags, const char *dev_name, void *data, struct vfsmount *mnt)
{
return get_sb_bdev(fs_type, flags, dev_name, data, efs_fill_super, mnt);
}
.owner = THIS_MODULE,
.name = «efs»,
.get_sb = efs_get_sb,
.kill_sb = kill_block_super,
.fs_flags = FS_REQUIRES_DEV,
};
{0×00, «SGI vh»},
{0×01, «SGI trkrepl»},
{0×02, «SGI secrepl»},
{0×03, «SGI raw»},
{0×04, «SGI bsd»},
{SGI_SYSV, «SGI sysv»},
{0×06, «SGI vol»},
{SGI_EFS, «SGI efs»},
{0×08, «SGI lv»},
{0×09, «SGI rlv»},
{0×0A, «SGI xfs»},
{0×0B, «SGI xfslog»},
{0×0C, «SGI xlv»},
{0×82, «Linux swap»},
{0×83, «Linux native»},
{0, NULL}
};
{
struct efs_inode_info *ei;
ei = (struct efs_inode_info *)kmem_cache_alloc(efs_inode_cachep, GFP_KERNEL);
if (!ei)
return NULL;
return &ei->vfs_inode;
}
{
kmem_cache_free(efs_inode_cachep, INODE_INFO(inode));
}
{
struct efs_inode_info *ei = (struct efs_inode_info *) foo;
}
{
efs_inode_cachep = kmem_cache_create(»efs_inode_cache»,
sizeof(struct efs_inode_info),
0, SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
init_once);
if (efs_inode_cachep == NULL)
return -ENOMEM;
return 0;
}
{
kmem_cache_destroy(efs_inode_cachep);
}
{
kfree(s->s_fs_info);
s->s_fs_info = NULL;
}
{
*flags |= MS_RDONLY;
return 0;
}
.alloc_inode = efs_alloc_inode,
.destroy_inode = efs_destroy_inode,
.put_super = efs_put_super,
.statfs = efs_statfs,
.remount_fs = efs_remount,
};
.fh_to_dentry = efs_fh_to_dentry,
.fh_to_parent = efs_fh_to_parent,
.get_parent = efs_get_parent,
};
int err;
printk(»EFS: «EFS_VERSION» – http://aeschi.ch.eu.org/efs/\n»);
err = init_inodecache();
if (err)
goto out1;
err = register_filesystem(&efs_fs_type);
if (err)
goto out;
return 0;
out:
destroy_inodecache();
out1:
return err;
}
unregister_filesystem(&efs_fs_type);
destroy_inodecache();
}
module_exit(exit_efs_fs)
int i;
__be32 cs, *ui;
int csum;
efs_block_t sblock = 0; /* shuts up gcc */
struct pt_types *pt_entry;
int pt_type, slice = -1;
/*
* assume that we’re dealing with a partition and allow
* read_super() to try and detect a valid superblock
* on the next block.
*/
return 0;
}
for(csum = 0; ui >= ((__be32 *) vh);) {
cs = *ui–;
csum += be32_to_cpu(cs);
}
if (csum) {
printk(KERN_INFO «EFS: SGI disklabel: checksum bad, label corrupted\n»);
return 0;
}
printk(KERN_DEBUG «EFS: bf: \»%16s\»\n», vh->vh_bootfile);
int j;
char name[VDNAMESIZE+1];
name[j] = vh->vh_vd[i].vd_name[j];
}
name[j] = (char) 0;
printk(KERN_DEBUG «EFS: vh: %8s block: 0x%08x size: 0x%08x\n»,
name,
(int) be32_to_cpu(vh->vh_vd[i].vd_lbn),
(int) be32_to_cpu(vh->vh_vd[i].vd_nbytes));
}
}
#endif
pt_type = (int) be32_to_cpu(vh->vh_pt[i].pt_type);
for(pt_entry = sgi_pt_types; pt_entry->pt_name; pt_entry++) {
if (pt_type == pt_entry->pt_type) break;
}
#ifdef DEBUG
if (be32_to_cpu(vh->vh_pt[i].pt_nblks)) {
printk(KERN_DEBUG «EFS: pt %2d: start: %08d size: %08d type: 0x%02x (%s)\n»,
i,
(int) be32_to_cpu(vh->vh_pt[i].pt_firstlbn),
(int) be32_to_cpu(vh->vh_pt[i].pt_nblks),
pt_type,
(pt_entry->pt_name) ? pt_entry->pt_name : «unknown»);
}
#endif
if (IS_EFS(pt_type)) {
sblock = be32_to_cpu(vh->vh_pt[i].pt_firstlbn);
slice = i;
}
}
printk(KERN_NOTICE «EFS: partition table contained no EFS partitions\n»);
#ifdef DEBUG
} else {
printk(KERN_INFO «EFS: using slice %d (type %s, offset 0x%x)\n»,
slice,
(pt_entry->pt_name) ? pt_entry->pt_name : «unknown»,
sblock);
#endif
}
return sblock;
}
return -1;
sb->total_blocks = be32_to_cpu(super->fs_size);
sb->first_block = be32_to_cpu(super->fs_firstcg);
sb->group_size = be32_to_cpu(super->fs_cgfsize);
sb->data_free = be32_to_cpu(super->fs_tfree);
sb->inode_free = be32_to_cpu(super->fs_tinode);
sb->inode_blocks = be16_to_cpu(super->fs_cgisize);
sb->total_groups = be16_to_cpu(super->fs_ncg);
}
{
struct efs_sb_info *sb;
struct buffer_head *bh;
struct inode *root;
int ret = -EINVAL;
if (!sb)
return -ENOMEM;
s->s_fs_info = sb;
if (!sb_set_blocksize(s, EFS_BLOCKSIZE)) {
printk(KERN_ERR «EFS: device does not support %d byte blocks\n»,
EFS_BLOCKSIZE);
goto out_no_fs_ul;
}
bh = sb_bread(s, 0);
printk(KERN_ERR «EFS: cannot read volume header\n»);
goto out_no_fs_ul;
}
* if this returns zero then we didn’t find any partition table.
* this isn’t (yet) an error – just assume for the moment that
* the device is valid and go on to search for a superblock.
*/
sb->fs_start = efs_validate_vh((struct volume_header *) bh->b_data);
brelse(bh);
goto out_no_fs_ul;
}
if (!bh) {
printk(KERN_ERR «EFS: cannot read superblock\n»);
goto out_no_fs_ul;
}
#ifdef DEBUG
printk(KERN_WARNING «EFS: invalid superblock at block %u\n», sb->fs_start + EFS_SUPER);
#endif
brelse(bh);
goto out_no_fs_ul;
}
brelse(bh);
#ifdef DEBUG
printk(KERN_INFO «EFS: forcing read-only mode\n»);
#endif
s->s_flags |= MS_RDONLY;
}
s->s_op = &efs_superblock_operations;
s->s_export_op = &efs_export_ops;
root = efs_iget(s, EFS_ROOTINODE);
if (IS_ERR(root)) {
printk(KERN_ERR «EFS: get root inode failed\n»);
ret = PTR_ERR(root);
goto out_no_fs;
}
if (!(s->s_root)) {
printk(KERN_ERR «EFS: get root dentry failed\n»);
iput(root);
ret = -ENOMEM;
goto out_no_fs;
}
out_no_fs:
s->s_fs_info = NULL;
kfree(sb);
return ret;
}
struct super_block *sb = dentry->d_sb;
struct efs_sb_info *sbi = SUPER_INFO(sb);
u64 id = huge_encode_dev(sb->s_bdev->bd_dev);
buf->f_bsize = EFS_BLOCKSIZE; /* blocksize */
buf->f_blocks = sbi->total_groups * /* total data blocks */
(sbi->group_size – sbi->inode_blocks);
buf->f_bfree = sbi->data_free; /* free data blocks */
buf->f_bavail = sbi->data_free; /* free blocks for non-root */
buf->f_files = sbi->total_groups * /* total inodes */
sbi->inode_blocks *
(EFS_BLOCKSIZE / sizeof(struct efs_dinode));
buf->f_ffree = sbi->inode_free; /* free inodes */
buf->f_fsid.val[0] = (u32)id;
buf->f_fsid.val[1] = (u32)(id >> 32);
buf->f_namelen = EFS_MAXNAMELEN; /* max filename length */
}