Commit 928098c9 authored by Dave Jones's avatar Dave Jones Committed by Linus Torvalds

[PATCH] struct super_block cleanup - adfs

Another one from Brian Gerst. Still applies to 2.5.18

Seperates adfs_sb_info from struct super_block.
parent 812c0374
...@@ -132,7 +132,7 @@ __adfs_block_map(struct super_block *sb, unsigned int object_id, ...@@ -132,7 +132,7 @@ __adfs_block_map(struct super_block *sb, unsigned int object_id,
unsigned int off; unsigned int off;
off = (object_id & 255) - 1; off = (object_id & 255) - 1;
block += off << sb->u.adfs_sb.s_log2sharesize; block += off << ADFS_SB(sb)->s_log2sharesize;
} }
return adfs_map_lookup(sb, object_id >> 8, block); return adfs_map_lookup(sb, object_id >> 8, block);
......
...@@ -32,7 +32,7 @@ adfs_readdir(struct file *filp, void *dirent, filldir_t filldir) ...@@ -32,7 +32,7 @@ adfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
{ {
struct inode *inode = filp->f_dentry->d_inode; struct inode *inode = filp->f_dentry->d_inode;
struct super_block *sb = inode->i_sb; struct super_block *sb = inode->i_sb;
struct adfs_dir_ops *ops = sb->u.adfs_sb.s_dir; struct adfs_dir_ops *ops = ADFS_SB(sb)->s_dir;
struct object_info obj; struct object_info obj;
struct adfs_dir dir; struct adfs_dir dir;
int ret = 0; int ret = 0;
...@@ -89,7 +89,7 @@ adfs_dir_update(struct super_block *sb, struct object_info *obj) ...@@ -89,7 +89,7 @@ adfs_dir_update(struct super_block *sb, struct object_info *obj)
{ {
int ret = -EINVAL; int ret = -EINVAL;
#ifdef CONFIG_ADFS_FS_RW #ifdef CONFIG_ADFS_FS_RW
struct adfs_dir_ops *ops = sb->u.adfs_sb.s_dir; struct adfs_dir_ops *ops = ADFS_SB(sb)->s_dir;
struct adfs_dir dir; struct adfs_dir dir;
printk(KERN_INFO "adfs_dir_update: object %06X in dir %06X\n", printk(KERN_INFO "adfs_dir_update: object %06X in dir %06X\n",
...@@ -143,7 +143,7 @@ static int ...@@ -143,7 +143,7 @@ static int
adfs_dir_lookup_byname(struct inode *inode, struct qstr *name, struct object_info *obj) adfs_dir_lookup_byname(struct inode *inode, struct qstr *name, struct object_info *obj)
{ {
struct super_block *sb = inode->i_sb; struct super_block *sb = inode->i_sb;
struct adfs_dir_ops *ops = sb->u.adfs_sb.s_dir; struct adfs_dir_ops *ops = ADFS_SB(sb)->s_dir;
struct adfs_dir dir; struct adfs_dir dir;
int ret; int ret;
...@@ -206,7 +206,7 @@ struct file_operations adfs_dir_operations = { ...@@ -206,7 +206,7 @@ struct file_operations adfs_dir_operations = {
static int static int
adfs_hash(struct dentry *parent, struct qstr *qstr) adfs_hash(struct dentry *parent, struct qstr *qstr)
{ {
const unsigned int name_len = parent->d_sb->u.adfs_sb.s_namelen; const unsigned int name_len = ADFS_SB(parent->d_sb)->s_namelen;
const unsigned char *name; const unsigned char *name;
unsigned long hash; unsigned long hash;
int i; int i;
......
...@@ -25,7 +25,8 @@ ...@@ -25,7 +25,8 @@
#include <linux/fcntl.h> #include <linux/fcntl.h>
#include <linux/time.h> #include <linux/time.h>
#include <linux/stat.h> #include <linux/stat.h>
#include <linux/buffer_head.h> /* for file_fsync() */ #include <linux/buffer_head.h> /* for file_fsync() */
#include <linux/adfs_fs.h>
#include "adfs.h" #include "adfs.h"
......
...@@ -102,9 +102,10 @@ adfs_atts2mode(struct super_block *sb, struct inode *inode) ...@@ -102,9 +102,10 @@ adfs_atts2mode(struct super_block *sb, struct inode *inode)
{ {
unsigned int filetype, attr = ADFS_I(inode)->attr; unsigned int filetype, attr = ADFS_I(inode)->attr;
umode_t mode, rmask; umode_t mode, rmask;
struct adfs_sb_info *asb = ADFS_SB(sb);
if (attr & ADFS_NDA_DIRECTORY) { if (attr & ADFS_NDA_DIRECTORY) {
mode = S_IRUGO & sb->u.adfs_sb.s_owner_mask; mode = S_IRUGO & asb->s_owner_mask;
return S_IFDIR | S_IXUGO | mode; return S_IFDIR | S_IXUGO | mode;
} }
...@@ -125,16 +126,16 @@ adfs_atts2mode(struct super_block *sb, struct inode *inode) ...@@ -125,16 +126,16 @@ adfs_atts2mode(struct super_block *sb, struct inode *inode)
mode = S_IFREG; mode = S_IFREG;
if (attr & ADFS_NDA_OWNER_READ) if (attr & ADFS_NDA_OWNER_READ)
mode |= rmask & sb->u.adfs_sb.s_owner_mask; mode |= rmask & asb->s_owner_mask;
if (attr & ADFS_NDA_OWNER_WRITE) if (attr & ADFS_NDA_OWNER_WRITE)
mode |= S_IWUGO & sb->u.adfs_sb.s_owner_mask; mode |= S_IWUGO & asb->s_owner_mask;
if (attr & ADFS_NDA_PUBLIC_READ) if (attr & ADFS_NDA_PUBLIC_READ)
mode |= rmask & sb->u.adfs_sb.s_other_mask; mode |= rmask & asb->s_other_mask;
if (attr & ADFS_NDA_PUBLIC_WRITE) if (attr & ADFS_NDA_PUBLIC_WRITE)
mode |= S_IWUGO & sb->u.adfs_sb.s_other_mask; mode |= S_IWUGO & asb->s_other_mask;
return mode; return mode;
} }
...@@ -147,6 +148,7 @@ adfs_mode2atts(struct super_block *sb, struct inode *inode) ...@@ -147,6 +148,7 @@ adfs_mode2atts(struct super_block *sb, struct inode *inode)
{ {
umode_t mode; umode_t mode;
int attr; int attr;
struct adfs_sb_info *asb = ADFS_SB(sb);
/* FIXME: should we be able to alter a link? */ /* FIXME: should we be able to alter a link? */
if (S_ISLNK(inode->i_mode)) if (S_ISLNK(inode->i_mode))
...@@ -157,14 +159,14 @@ adfs_mode2atts(struct super_block *sb, struct inode *inode) ...@@ -157,14 +159,14 @@ adfs_mode2atts(struct super_block *sb, struct inode *inode)
else else
attr = 0; attr = 0;
mode = inode->i_mode & sb->u.adfs_sb.s_owner_mask; mode = inode->i_mode & asb->s_owner_mask;
if (mode & S_IRUGO) if (mode & S_IRUGO)
attr |= ADFS_NDA_OWNER_READ; attr |= ADFS_NDA_OWNER_READ;
if (mode & S_IWUGO) if (mode & S_IWUGO)
attr |= ADFS_NDA_OWNER_WRITE; attr |= ADFS_NDA_OWNER_WRITE;
mode = inode->i_mode & sb->u.adfs_sb.s_other_mask; mode = inode->i_mode & asb->s_other_mask;
mode &= ~sb->u.adfs_sb.s_owner_mask; mode &= ~asb->s_owner_mask;
if (mode & S_IRUGO) if (mode & S_IRUGO)
attr |= ADFS_NDA_PUBLIC_READ; attr |= ADFS_NDA_PUBLIC_READ;
if (mode & S_IWUGO) if (mode & S_IWUGO)
...@@ -247,8 +249,8 @@ adfs_iget(struct super_block *sb, struct object_info *obj) ...@@ -247,8 +249,8 @@ adfs_iget(struct super_block *sb, struct object_info *obj)
if (!inode) if (!inode)
goto out; goto out;
inode->i_uid = sb->u.adfs_sb.s_uid; inode->i_uid = ADFS_SB(sb)->s_uid;
inode->i_gid = sb->u.adfs_sb.s_gid; inode->i_gid = ADFS_SB(sb)->s_gid;
inode->i_ino = obj->file_id; inode->i_ino = obj->file_id;
inode->i_size = obj->size; inode->i_size = obj->size;
inode->i_nlink = 2; inode->i_nlink = 2;
...@@ -310,8 +312,8 @@ adfs_notify_change(struct dentry *dentry, struct iattr *attr) ...@@ -310,8 +312,8 @@ adfs_notify_change(struct dentry *dentry, struct iattr *attr)
* we can't change the UID or GID of any file - * we can't change the UID or GID of any file -
* we have a global UID/GID in the superblock * we have a global UID/GID in the superblock
*/ */
if ((ia_valid & ATTR_UID && attr->ia_uid != sb->u.adfs_sb.s_uid) || if ((ia_valid & ATTR_UID && attr->ia_uid != ADFS_SB(sb)->s_uid) ||
(ia_valid & ATTR_GID && attr->ia_gid != sb->u.adfs_sb.s_gid)) (ia_valid & ATTR_GID && attr->ia_gid != ADFS_SB(sb)->s_gid))
error = -EPERM; error = -EPERM;
if (error) if (error)
......
...@@ -238,7 +238,7 @@ scan_map(struct adfs_sb_info *asb, unsigned int zone, ...@@ -238,7 +238,7 @@ scan_map(struct adfs_sb_info *asb, unsigned int zone,
unsigned int unsigned int
adfs_map_free(struct super_block *sb) adfs_map_free(struct super_block *sb)
{ {
struct adfs_sb_info *asb = &sb->u.adfs_sb; struct adfs_sb_info *asb = ADFS_SB(sb);
struct adfs_discmap *dm; struct adfs_discmap *dm;
unsigned int total = 0; unsigned int total = 0;
unsigned int zone; unsigned int zone;
......
...@@ -105,7 +105,7 @@ static int adfs_checkmap(struct super_block *sb, struct adfs_discmap *dm) ...@@ -105,7 +105,7 @@ static int adfs_checkmap(struct super_block *sb, struct adfs_discmap *dm)
unsigned char crosscheck = 0, zonecheck = 1; unsigned char crosscheck = 0, zonecheck = 1;
int i; int i;
for (i = 0; i < sb->u.adfs_sb.s_map_size; i++) { for (i = 0; i < ADFS_SB(sb)->s_map_size; i++) {
unsigned char *map; unsigned char *map;
map = dm[i].dm_bh->b_data; map = dm[i].dm_bh->b_data;
...@@ -124,15 +124,19 @@ static int adfs_checkmap(struct super_block *sb, struct adfs_discmap *dm) ...@@ -124,15 +124,19 @@ static int adfs_checkmap(struct super_block *sb, struct adfs_discmap *dm)
static void adfs_put_super(struct super_block *sb) static void adfs_put_super(struct super_block *sb)
{ {
int i; int i;
struct adfs_sb_info *asb = ADFS_SB(sb);
for (i = 0; i < sb->u.adfs_sb.s_map_size; i++) for (i = 0; i < asb->s_map_size; i++)
brelse(sb->u.adfs_sb.s_map[i].dm_bh); brelse(asb->s_map[i].dm_bh);
kfree(sb->u.adfs_sb.s_map); kfree(asb->s_map);
kfree(asb);
sb->u.generic_sbp = NULL;
} }
static int parse_options(struct super_block *sb, char *options) static int parse_options(struct super_block *sb, char *options)
{ {
char *value, *opt; char *value, *opt;
struct adfs_sb_info *asb = ADFS_SB(sb);
if (!options) if (!options)
return 0; return 0;
...@@ -147,28 +151,28 @@ static int parse_options(struct super_block *sb, char *options) ...@@ -147,28 +151,28 @@ static int parse_options(struct super_block *sb, char *options)
if (!strcmp(opt, "uid")) { /* owner of all files */ if (!strcmp(opt, "uid")) { /* owner of all files */
if (!value || !*value) if (!value || !*value)
return -EINVAL; return -EINVAL;
sb->u.adfs_sb.s_uid = simple_strtoul(value, &value, 0); asb->s_uid = simple_strtoul(value, &value, 0);
if (*value) if (*value)
return -EINVAL; return -EINVAL;
} else } else
if (!strcmp(opt, "gid")) { /* group owner of all files */ if (!strcmp(opt, "gid")) { /* group owner of all files */
if (!value || !*value) if (!value || !*value)
return -EINVAL; return -EINVAL;
sb->u.adfs_sb.s_gid = simple_strtoul(value, &value, 0); asb->s_gid = simple_strtoul(value, &value, 0);
if (*value) if (*value)
return -EINVAL; return -EINVAL;
} else } else
if (!strcmp(opt, "ownmask")) { /* owner permission mask */ if (!strcmp(opt, "ownmask")) { /* owner permission mask */
if (!value || !*value) if (!value || !*value)
return -EINVAL; return -EINVAL;
sb->u.adfs_sb.s_owner_mask = simple_strtoul(value, &value, 8); asb->s_owner_mask = simple_strtoul(value, &value, 8);
if (*value) if (*value)
return -EINVAL; return -EINVAL;
} else } else
if (!strcmp(opt, "othmask")) { /* others permission mask */ if (!strcmp(opt, "othmask")) { /* others permission mask */
if (!value || !*value) if (!value || !*value)
return -EINVAL; return -EINVAL;
sb->u.adfs_sb.s_other_mask = simple_strtoul(value, &value, 8); asb->s_other_mask = simple_strtoul(value, &value, 8);
if (*value) if (*value)
return -EINVAL; return -EINVAL;
} else { /* eh? say again. */ } else { /* eh? say again. */
...@@ -186,7 +190,7 @@ static int adfs_remount(struct super_block *sb, int *flags, char *data) ...@@ -186,7 +190,7 @@ static int adfs_remount(struct super_block *sb, int *flags, char *data)
static int adfs_statfs(struct super_block *sb, struct statfs *buf) static int adfs_statfs(struct super_block *sb, struct statfs *buf)
{ {
struct adfs_sb_info *asb = &sb->u.adfs_sb; struct adfs_sb_info *asb = ADFS_SB(sb);
buf->f_type = ADFS_SUPER_MAGIC; buf->f_type = ADFS_SUPER_MAGIC;
buf->f_namelen = asb->s_namelen; buf->f_namelen = asb->s_namelen;
...@@ -256,14 +260,15 @@ static struct adfs_discmap *adfs_read_map(struct super_block *sb, struct adfs_di ...@@ -256,14 +260,15 @@ static struct adfs_discmap *adfs_read_map(struct super_block *sb, struct adfs_di
struct adfs_discmap *dm; struct adfs_discmap *dm;
unsigned int map_addr, zone_size, nzones; unsigned int map_addr, zone_size, nzones;
int i, zone; int i, zone;
struct adfs_sb_info *asb = ADFS_SB(sb);
nzones = sb->u.adfs_sb.s_map_size; nzones = asb->s_map_size;
zone_size = (8 << dr->log2secsize) - le16_to_cpu(dr->zone_spare); zone_size = (8 << dr->log2secsize) - le16_to_cpu(dr->zone_spare);
map_addr = (nzones >> 1) * zone_size - map_addr = (nzones >> 1) * zone_size -
((nzones > 1) ? ADFS_DR_SIZE_BITS : 0); ((nzones > 1) ? ADFS_DR_SIZE_BITS : 0);
map_addr = signed_asl(map_addr, sb->u.adfs_sb.s_map2blk); map_addr = signed_asl(map_addr, asb->s_map2blk);
sb->u.adfs_sb.s_ids_per_zone = zone_size / (sb->u.adfs_sb.s_idlen + 1); asb->s_ids_per_zone = zone_size / (asb->s_idlen + 1);
dm = kmalloc(nzones * sizeof(*dm), GFP_KERNEL); dm = kmalloc(nzones * sizeof(*dm), GFP_KERNEL);
if (dm == NULL) { if (dm == NULL) {
...@@ -320,12 +325,19 @@ static int adfs_fill_super(struct super_block *sb, void *data, int silent) ...@@ -320,12 +325,19 @@ static int adfs_fill_super(struct super_block *sb, void *data, int silent)
struct buffer_head *bh; struct buffer_head *bh;
struct object_info root_obj; struct object_info root_obj;
unsigned char *b_data; unsigned char *b_data;
struct adfs_sb_info *asb;
asb = kmalloc(sizeof(*asb), GFP_KERNEL);
if (!asb)
return -ENOMEM;
sb->u.generic_sbp = asb;
memset(asb, 0, sizeof(*asb));
/* set default options */ /* set default options */
sb->u.adfs_sb.s_uid = 0; asb->s_uid = 0;
sb->u.adfs_sb.s_gid = 0; asb->s_gid = 0;
sb->u.adfs_sb.s_owner_mask = S_IRWXU; asb->s_owner_mask = S_IRWXU;
sb->u.adfs_sb.s_other_mask = S_IRWXG | S_IRWXO; asb->s_other_mask = S_IRWXG | S_IRWXO;
if (parse_options(sb, data)) if (parse_options(sb, data))
goto error; goto error;
...@@ -382,16 +394,16 @@ static int adfs_fill_super(struct super_block *sb, void *data, int silent) ...@@ -382,16 +394,16 @@ static int adfs_fill_super(struct super_block *sb, void *data, int silent)
* blocksize on this device should now be set to the ADFS log2secsize * blocksize on this device should now be set to the ADFS log2secsize
*/ */
sb->s_magic = ADFS_SUPER_MAGIC; sb->s_magic = ADFS_SUPER_MAGIC;
sb->u.adfs_sb.s_idlen = dr->idlen; asb->s_idlen = dr->idlen;
sb->u.adfs_sb.s_map_size = dr->nzones | (dr->nzones_high << 8); asb->s_map_size = dr->nzones | (dr->nzones_high << 8);
sb->u.adfs_sb.s_map2blk = dr->log2bpmb - dr->log2secsize; asb->s_map2blk = dr->log2bpmb - dr->log2secsize;
sb->u.adfs_sb.s_size = adfs_discsize(dr, sb->s_blocksize_bits); asb->s_size = adfs_discsize(dr, sb->s_blocksize_bits);
sb->u.adfs_sb.s_version = dr->format_version; asb->s_version = dr->format_version;
sb->u.adfs_sb.s_log2sharesize = dr->log2sharesize; asb->s_log2sharesize = dr->log2sharesize;
sb->u.adfs_sb.s_map = adfs_read_map(sb, dr); asb->s_map = adfs_read_map(sb, dr);
if (!sb->u.adfs_sb.s_map) if (!asb->s_map)
goto error_free_bh; goto error_free_bh;
brelse(bh); brelse(bh);
...@@ -401,7 +413,7 @@ static int adfs_fill_super(struct super_block *sb, void *data, int silent) ...@@ -401,7 +413,7 @@ static int adfs_fill_super(struct super_block *sb, void *data, int silent)
*/ */
sb->s_op = &adfs_sops; sb->s_op = &adfs_sops;
dr = (struct adfs_discrecord *)(sb->u.adfs_sb.s_map[0].dm_bh->b_data + 4); dr = (struct adfs_discrecord *)(asb->s_map[0].dm_bh->b_data + 4);
root_obj.parent_id = root_obj.file_id = le32_to_cpu(dr->root); root_obj.parent_id = root_obj.file_id = le32_to_cpu(dr->root);
root_obj.name_len = 0; root_obj.name_len = 0;
...@@ -415,22 +427,22 @@ static int adfs_fill_super(struct super_block *sb, void *data, int silent) ...@@ -415,22 +427,22 @@ static int adfs_fill_super(struct super_block *sb, void *data, int silent)
* If this is a F+ disk with variable length directories, * If this is a F+ disk with variable length directories,
* get the root_size from the disc record. * get the root_size from the disc record.
*/ */
if (sb->u.adfs_sb.s_version) { if (asb->s_version) {
root_obj.size = dr->root_size; root_obj.size = dr->root_size;
sb->u.adfs_sb.s_dir = &adfs_fplus_dir_ops; asb->s_dir = &adfs_fplus_dir_ops;
sb->u.adfs_sb.s_namelen = ADFS_FPLUS_NAME_LEN; asb->s_namelen = ADFS_FPLUS_NAME_LEN;
} else { } else {
sb->u.adfs_sb.s_dir = &adfs_f_dir_ops; asb->s_dir = &adfs_f_dir_ops;
sb->u.adfs_sb.s_namelen = ADFS_F_NAME_LEN; asb->s_namelen = ADFS_F_NAME_LEN;
} }
sb->s_root = d_alloc_root(adfs_iget(sb, &root_obj)); sb->s_root = d_alloc_root(adfs_iget(sb, &root_obj));
if (!sb->s_root) { if (!sb->s_root) {
int i; int i;
for (i = 0; i < sb->u.adfs_sb.s_map_size; i++) for (i = 0; i < asb->s_map_size; i++)
brelse(sb->u.adfs_sb.s_map[i].dm_bh); brelse(asb->s_map[i].dm_bh);
kfree(sb->u.adfs_sb.s_map); kfree(asb->s_map);
adfs_error(sb, "get root inode failed\n"); adfs_error(sb, "get root inode failed\n");
goto error; goto error;
} else } else
...@@ -440,6 +452,8 @@ static int adfs_fill_super(struct super_block *sb, void *data, int silent) ...@@ -440,6 +452,8 @@ static int adfs_fill_super(struct super_block *sb, void *data, int silent)
error_free_bh: error_free_bh:
brelse(bh); brelse(bh);
error: error:
sb->u.generic_sbp = NULL;
kfree(asb);
return -EINVAL; return -EINVAL;
} }
......
...@@ -42,6 +42,7 @@ struct adfs_discrecord { ...@@ -42,6 +42,7 @@ struct adfs_discrecord {
#ifdef __KERNEL__ #ifdef __KERNEL__
#include <linux/adfs_fs_i.h> #include <linux/adfs_fs_i.h>
#include <linux/adfs_fs_sb.h>
/* /*
* Calculate the boot block checksum on an ADFS drive. Note that this will * Calculate the boot block checksum on an ADFS drive. Note that this will
* appear to be correct if the sector contains all zeros, so also check that * appear to be correct if the sector contains all zeros, so also check that
...@@ -60,6 +61,11 @@ static inline int adfs_checkbblk(unsigned char *ptr) ...@@ -60,6 +61,11 @@ static inline int adfs_checkbblk(unsigned char *ptr)
return (result & 0xff) != ptr[511]; return (result & 0xff) != ptr[511];
} }
static inline struct adfs_sb_info *ADFS_SB(struct super_block *sb)
{
return sb->u.generic_sbp;
}
static inline struct adfs_inode_info *ADFS_I(struct inode *inode) static inline struct adfs_inode_info *ADFS_I(struct inode *inode)
{ {
return list_entry(inode, struct adfs_inode_info, vfs_inode); return list_entry(inode, struct adfs_inode_info, vfs_inode);
......
...@@ -625,7 +625,6 @@ extern void __kill_fasync(struct fasync_struct *, int, int); ...@@ -625,7 +625,6 @@ extern void __kill_fasync(struct fasync_struct *, int, int);
#include <linux/hpfs_fs_sb.h> #include <linux/hpfs_fs_sb.h>
#include <linux/ufs_fs_sb.h> #include <linux/ufs_fs_sb.h>
#include <linux/romfs_fs_sb.h> #include <linux/romfs_fs_sb.h>
#include <linux/adfs_fs_sb.h>
extern struct list_head super_blocks; extern struct list_head super_blocks;
extern spinlock_t sb_lock; extern spinlock_t sb_lock;
...@@ -671,7 +670,6 @@ struct super_block { ...@@ -671,7 +670,6 @@ struct super_block {
struct hpfs_sb_info hpfs_sb; struct hpfs_sb_info hpfs_sb;
struct ufs_sb_info ufs_sb; struct ufs_sb_info ufs_sb;
struct romfs_sb_info romfs_sb; struct romfs_sb_info romfs_sb;
struct adfs_sb_info adfs_sb;
void *generic_sbp; void *generic_sbp;
} u; } u;
/* /*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment