Commit ddd7dce9 authored by Brian Gerst's avatar Brian Gerst Committed by Linus Torvalds

[PATCH] struct superblock cleanup - minixfs

Start of cleaning up the union of filesystem-specific structures in
struct super_block.  The goal is to remove dependence on filesystem
headers in fs.h. 

This patch abstracts the access to the minix_sb_info structure through
the function minix_sb(). 
parent d7d3ae66
......@@ -52,6 +52,7 @@ static unsigned long count_free(struct buffer_head *map[], unsigned numblocks, _
void minix_free_block(struct inode * inode, int block)
{
struct super_block * sb = inode->i_sb;
struct minix_sb_info * sbi = minix_sb(sb);
struct buffer_head * bh;
unsigned int bit,zone;
......@@ -59,19 +60,19 @@ void minix_free_block(struct inode * inode, int block)
printk("trying to free block on nonexistent device\n");
return;
}
if (block < sb->u.minix_sb.s_firstdatazone ||
block >= sb->u.minix_sb.s_nzones) {
if (block < sbi->s_firstdatazone ||
block >= sbi->s_nzones) {
printk("trying to free block not in datazone\n");
return;
}
zone = block - sb->u.minix_sb.s_firstdatazone + 1;
zone = block - sbi->s_firstdatazone + 1;
bit = zone & 8191;
zone >>= 13;
if (zone >= sb->u.minix_sb.s_zmap_blocks) {
if (zone >= sbi->s_zmap_blocks) {
printk("minix_free_block: nonexistent bitmap buffer\n");
return;
}
bh = sb->u.minix_sb.s_zmap[zone];
bh = sbi->s_zmap[zone];
if (!minix_test_and_clear_bit(bit,bh->b_data))
printk("free_block (%s:%d): bit already cleared\n",
sb->s_id, block);
......@@ -82,6 +83,7 @@ void minix_free_block(struct inode * inode, int block)
int minix_new_block(struct inode * inode)
{
struct super_block * sb = inode->i_sb;
struct minix_sb_info * sbi = minix_sb(sb);
struct buffer_head * bh;
int i,j;
......@@ -92,8 +94,8 @@ int minix_new_block(struct inode * inode)
repeat:
j = 8192;
bh = NULL;
for (i = 0; i < sb->u.minix_sb.s_zmap_blocks; i++) {
bh = sb->u.minix_sb.s_zmap[i];
for (i = 0; i < sbi->s_zmap_blocks; i++) {
bh = sbi->s_zmap[i];
if ((j = minix_find_first_zero_bit(bh->b_data, 8192)) < 8192)
break;
}
......@@ -104,25 +106,26 @@ int minix_new_block(struct inode * inode)
goto repeat;
}
mark_buffer_dirty(bh);
j += i*8192 + sb->u.minix_sb.s_firstdatazone-1;
if (j < sb->u.minix_sb.s_firstdatazone ||
j >= sb->u.minix_sb.s_nzones)
j += i*8192 + sbi->s_firstdatazone-1;
if (j < sbi->s_firstdatazone ||
j >= sbi->s_nzones)
return 0;
return j;
}
unsigned long minix_count_free_blocks(struct super_block *sb)
{
return (count_free(sb->u.minix_sb.s_zmap, sb->u.minix_sb.s_zmap_blocks,
sb->u.minix_sb.s_nzones - sb->u.minix_sb.s_firstdatazone + 1)
<< sb->u.minix_sb.s_log_zone_size);
struct minix_sb_info *sbi = minix_sb(sb);
return (count_free(sbi->s_zmap, sbi->s_zmap_blocks,
sbi->s_nzones - sbi->s_firstdatazone + 1)
<< sbi->s_log_zone_size);
}
struct minix_inode *
minix_V1_raw_inode(struct super_block *sb, ino_t ino, struct buffer_head **bh)
{
int block;
struct minix_sb_info *sbi = &sb->u.minix_sb;
struct minix_sb_info *sbi = minix_sb(sb);
struct minix_inode *p;
if (!ino || ino > sbi->s_ninodes) {
......@@ -146,7 +149,7 @@ struct minix2_inode *
minix_V2_raw_inode(struct super_block *sb, ino_t ino, struct buffer_head **bh)
{
int block;
struct minix_sb_info *sbi = &sb->u.minix_sb;
struct minix_sb_info *sbi = minix_sb(sb);
struct minix2_inode *p;
*bh = NULL;
......@@ -198,17 +201,17 @@ void minix_free_inode(struct inode * inode)
struct buffer_head * bh;
unsigned long ino;
if (inode->i_ino < 1 || inode->i_ino > inode->i_sb->u.minix_sb.s_ninodes) {
if (inode->i_ino < 1 || inode->i_ino > minix_sb(inode->i_sb)->s_ninodes) {
printk("free_inode: inode 0 or nonexistent inode\n");
return;
}
ino = inode->i_ino;
if ((ino >> 13) >= inode->i_sb->u.minix_sb.s_imap_blocks) {
if ((ino >> 13) >= minix_sb(inode->i_sb)->s_imap_blocks) {
printk("free_inode: nonexistent imap in superblock\n");
return;
}
bh = inode->i_sb->u.minix_sb.s_imap[ino >> 13];
bh = minix_sb(inode->i_sb)->s_imap[ino >> 13];
minix_clear_inode(inode);
clear_inode(inode);
if (!minix_test_and_clear_bit(ino & 8191, bh->b_data))
......@@ -233,8 +236,8 @@ struct inode * minix_new_inode(const struct inode * dir, int * error)
bh = NULL;
*error = -ENOSPC;
lock_super(sb);
for (i = 0; i < sb->u.minix_sb.s_imap_blocks; i++) {
bh = inode->i_sb->u.minix_sb.s_imap[i];
for (i = 0; i < minix_sb(sb)->s_imap_blocks; i++) {
bh = minix_sb(inode->i_sb)->s_imap[i];
if ((j = minix_find_first_zero_bit(bh->b_data, 8192)) < 8192)
break;
}
......@@ -251,7 +254,7 @@ struct inode * minix_new_inode(const struct inode * dir, int * error)
}
mark_buffer_dirty(bh);
j += i*8192;
if (!j || j > inode->i_sb->u.minix_sb.s_ninodes) {
if (!j || j > minix_sb(inode->i_sb)->s_ninodes) {
iput(inode);
unlock_super(sb);
return NULL;
......@@ -272,6 +275,6 @@ struct inode * minix_new_inode(const struct inode * dir, int * error)
unsigned long minix_count_free_inodes(struct super_block *sb)
{
return count_free(sb->u.minix_sb.s_imap, sb->u.minix_sb.s_imap_blocks,
sb->u.minix_sb.s_ninodes + 1);
return count_free(minix_sb(sb)->s_imap, minix_sb(sb)->s_imap_blocks,
minix_sb(sb)->s_ninodes + 1);
}
......@@ -77,7 +77,7 @@ static int minix_readdir(struct file * filp, void * dirent, filldir_t filldir)
unsigned offset = pos & ~PAGE_CACHE_MASK;
unsigned long n = pos >> PAGE_CACHE_SHIFT;
unsigned long npages = dir_pages(inode);
struct minix_sb_info *sbi = &sb->u.minix_sb;
struct minix_sb_info *sbi = minix_sb(sb);
unsigned chunk_size = sbi->s_dirsize;
pos = (pos + chunk_size-1) & ~(chunk_size-1);
......@@ -140,7 +140,7 @@ minix_dirent *minix_find_entry(struct dentry *dentry, struct page **res_page)
int namelen = dentry->d_name.len;
struct inode * dir = dentry->d_parent->d_inode;
struct super_block * sb = dir->i_sb;
struct minix_sb_info * sbi = &sb->u.minix_sb;
struct minix_sb_info * sbi = minix_sb(sb);
unsigned long n;
unsigned long npages = dir_pages(dir);
struct page *page = NULL;
......@@ -178,7 +178,7 @@ int minix_add_link(struct dentry *dentry, struct inode *inode)
const char * name = dentry->d_name.name;
int namelen = dentry->d_name.len;
struct super_block * sb = dir->i_sb;
struct minix_sb_info * sbi = &sb->u.minix_sb;
struct minix_sb_info * sbi = minix_sb(sb);
struct page *page = NULL;
struct minix_dir_entry * de;
unsigned long npages = dir_pages(dir);
......@@ -236,7 +236,7 @@ int minix_delete_entry(struct minix_dir_entry *de, struct page *page)
struct inode *inode = (struct inode*)mapping->host;
char *kaddr = (char*)page_address(page);
unsigned from = (char*)de - kaddr;
unsigned to = from + inode->i_sb->u.minix_sb.s_dirsize;
unsigned to = from + minix_sb(inode->i_sb)->s_dirsize;
int err;
lock_page(page);
......@@ -256,7 +256,7 @@ int minix_make_empty(struct inode *inode, struct inode *dir)
{
struct address_space *mapping = inode->i_mapping;
struct page *page = grab_cache_page(mapping, 0);
struct minix_sb_info * sbi = &inode->i_sb->u.minix_sb;
struct minix_sb_info * sbi = minix_sb(inode->i_sb);
struct minix_dir_entry * de;
char *base;
int err;
......@@ -291,7 +291,7 @@ int minix_empty_dir(struct inode * inode)
{
struct page *page = NULL;
unsigned long i, npages = dir_pages(inode);
struct minix_sb_info *sbi = &inode->i_sb->u.minix_sb;
struct minix_sb_info *sbi = minix_sb(inode->i_sb);
for (i = 0; i < npages; i++) {
char *kaddr;
......@@ -334,7 +334,7 @@ void minix_set_link(struct minix_dir_entry *de, struct page *page,
struct inode *inode)
{
struct inode *dir = (struct inode*)page->mapping->host;
struct minix_sb_info *sbi = &dir->i_sb->u.minix_sb;
struct minix_sb_info *sbi = minix_sb(dir->i_sb);
unsigned from = (char *)de-(char*)page_address(page);
unsigned to = from + sbi->s_dirsize;
int err;
......@@ -354,7 +354,7 @@ void minix_set_link(struct minix_dir_entry *de, struct page *page,
struct minix_dir_entry * minix_dotdot (struct inode *dir, struct page **p)
{
struct page *page = dir_get_page(dir, 0);
struct minix_sb_info *sbi = &dir->i_sb->u.minix_sb;
struct minix_sb_info *sbi = minix_sb(dir->i_sb);
struct minix_dir_entry *de = NULL;
if (!IS_ERR(page)) {
......
......@@ -36,7 +36,7 @@ static void minix_delete_inode(struct inode *inode)
static void minix_commit_super(struct super_block * sb)
{
mark_buffer_dirty(sb->u.minix_sb.s_sbh);
mark_buffer_dirty(minix_sb(sb)->s_sbh);
sb->s_dirt = 0;
}
......@@ -45,7 +45,7 @@ static void minix_write_super(struct super_block * sb)
struct minix_super_block * ms;
if (!(sb->s_flags & MS_RDONLY)) {
ms = sb->u.minix_sb.s_ms;
ms = minix_sb(sb)->s_ms;
if (ms->s_state & MINIX_VALID_FS)
ms->s_state &= ~MINIX_VALID_FS;
......@@ -58,17 +58,18 @@ static void minix_write_super(struct super_block * sb)
static void minix_put_super(struct super_block *sb)
{
int i;
struct minix_sb_info *sbi = minix_sb(sb);
if (!(sb->s_flags & MS_RDONLY)) {
sb->u.minix_sb.s_ms->s_state = sb->u.minix_sb.s_mount_state;
mark_buffer_dirty(sb->u.minix_sb.s_sbh);
sbi->s_ms->s_state = sbi->s_mount_state;
mark_buffer_dirty(sbi->s_sbh);
}
for (i = 0; i < sb->u.minix_sb.s_imap_blocks; i++)
brelse(sb->u.minix_sb.s_imap[i]);
for (i = 0; i < sb->u.minix_sb.s_zmap_blocks; i++)
brelse(sb->u.minix_sb.s_zmap[i]);
brelse (sb->u.minix_sb.s_sbh);
kfree(sb->u.minix_sb.s_imap);
for (i = 0; i < sbi->s_imap_blocks; i++)
brelse(sbi->s_imap[i]);
for (i = 0; i < sbi->s_zmap_blocks; i++)
brelse(sbi->s_zmap[i]);
brelse (sbi->s_sbh);
kfree(sbi->s_imap);
return;
}
......@@ -129,32 +130,33 @@ static struct super_operations minix_sops = {
static int minix_remount (struct super_block * sb, int * flags, char * data)
{
struct minix_sb_info * sbi = minix_sb(sb);
struct minix_super_block * ms;
ms = sb->u.minix_sb.s_ms;
ms = sbi->s_ms;
if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY))
return 0;
if (*flags & MS_RDONLY) {
if (ms->s_state & MINIX_VALID_FS ||
!(sb->u.minix_sb.s_mount_state & MINIX_VALID_FS))
!(sbi->s_mount_state & MINIX_VALID_FS))
return 0;
/* Mounting a rw partition read-only. */
ms->s_state = sb->u.minix_sb.s_mount_state;
mark_buffer_dirty(sb->u.minix_sb.s_sbh);
ms->s_state = sbi->s_mount_state;
mark_buffer_dirty(sbi->s_sbh);
sb->s_dirt = 1;
minix_commit_super(sb);
}
else {
/* Mount a partition which is read-only, read-write. */
sb->u.minix_sb.s_mount_state = ms->s_state;
sbi->s_mount_state = ms->s_state;
ms->s_state &= ~MINIX_VALID_FS;
mark_buffer_dirty(sb->u.minix_sb.s_sbh);
mark_buffer_dirty(sbi->s_sbh);
sb->s_dirt = 1;
if (!(sb->u.minix_sb.s_mount_state & MINIX_VALID_FS))
if (!(sbi->s_mount_state & MINIX_VALID_FS))
printk ("MINIX-fs warning: remounting unchecked fs, "
"running fsck is recommended.\n");
else if ((sb->u.minix_sb.s_mount_state & MINIX_ERROR_FS))
else if ((sbi->s_mount_state & MINIX_ERROR_FS))
printk ("MINIX-fs warning: remounting fs with errors, "
"running fsck is recommended.\n");
}
......@@ -168,7 +170,7 @@ static int minix_fill_super(struct super_block *s, void *data, int silent)
struct minix_super_block *ms;
int i, block;
struct inode *root_inode;
struct minix_sb_info *sbi = &s->u.minix_sb;
struct minix_sb_info *sbi = minix_sb(s);
/* N.B. These should be compile-time tests.
Unfortunately that is impossible. */
......@@ -316,14 +318,15 @@ static int minix_fill_super(struct super_block *s, void *data, int silent)
static int minix_statfs(struct super_block *sb, struct statfs *buf)
{
struct minix_sb_info *sbi = minix_sb(sb);
buf->f_type = sb->s_magic;
buf->f_bsize = sb->s_blocksize;
buf->f_blocks = (sb->u.minix_sb.s_nzones - sb->u.minix_sb.s_firstdatazone) << sb->u.minix_sb.s_log_zone_size;
buf->f_blocks = (sbi->s_nzones - sbi->s_firstdatazone) << sbi->s_log_zone_size;
buf->f_bfree = minix_count_free_blocks(sb);
buf->f_bavail = buf->f_bfree;
buf->f_files = sb->u.minix_sb.s_ninodes;
buf->f_files = sbi->s_ninodes;
buf->f_ffree = minix_count_free_inodes(sb);
buf->f_namelen = sb->u.minix_sb.s_namelen;
buf->f_namelen = sbi->s_namelen;
return 0;
}
......
......@@ -28,7 +28,7 @@ static int block_to_path(struct inode * inode, long block, int offsets[DEPTH])
if (block < 0) {
printk("minix_bmap: block<0");
} else if (block >= (inode->i_sb->u.minix_sb.s_max_size/BLOCK_SIZE)) {
} else if (block >= (minix_sb(inode->i_sb)->s_max_size/BLOCK_SIZE)) {
printk("minix_bmap: block>big");
} else if (block < 7) {
offsets[n++] = block;
......
......@@ -28,7 +28,7 @@ static int block_to_path(struct inode * inode, long block, int offsets[DEPTH])
if (block < 0) {
printk("minix_bmap: block<0");
} else if (block >= (inode->i_sb->u.minix_sb.s_max_size/BLOCK_SIZE)) {
} else if (block >= (minix_sb(inode->i_sb)->s_max_size/BLOCK_SIZE)) {
printk("minix_bmap: block>big");
} else if (block < 7) {
offsets[n++] = block;
......
......@@ -38,7 +38,7 @@ static int minix_hash(struct dentry *dentry, struct qstr *qstr)
int i;
const unsigned char *name;
i = dentry->d_inode->i_sb->u.minix_sb.s_namelen;
i = minix_sb(dentry->d_inode->i_sb)->s_namelen;
if (i >= qstr->len)
return 0;
/* Truncate the name in place, avoids having to define a compare
......@@ -63,7 +63,7 @@ static struct dentry *minix_lookup(struct inode * dir, struct dentry *dentry)
dentry->d_op = dir->i_sb->s_root->d_op;
if (dentry->d_name.len > dir->i_sb->u.minix_sb.s_namelen)
if (dentry->d_name.len > minix_sb(dir->i_sb)->s_namelen)
return ERR_PTR(-ENAMETOOLONG);
ino = minix_inode_by_name(dentry);
......@@ -131,7 +131,7 @@ static int minix_link(struct dentry * old_dentry, struct inode * dir,
{
struct inode *inode = old_dentry->d_inode;
if (inode->i_nlink >= inode->i_sb->u.minix_sb.s_link_max)
if (inode->i_nlink >= minix_sb(inode->i_sb)->s_link_max)
return -EMLINK;
inode->i_ctime = CURRENT_TIME;
......@@ -145,7 +145,7 @@ static int minix_mkdir(struct inode * dir, struct dentry *dentry, int mode)
struct inode * inode;
int err = -EMLINK;
if (dir->i_nlink >= dir->i_sb->u.minix_sb.s_link_max)
if (dir->i_nlink >= minix_sb(dir->i_sb)->s_link_max)
goto out;
inc_count(dir);
......@@ -221,7 +221,7 @@ static int minix_rmdir(struct inode * dir, struct dentry *dentry)
static int minix_rename(struct inode * old_dir, struct dentry *old_dentry,
struct inode * new_dir, struct dentry *new_dentry)
{
struct minix_sb_info * info = &old_dir->i_sb->u.minix_sb;
struct minix_sb_info * info = minix_sb(old_dir->i_sb);
struct inode * old_inode = old_dentry->d_inode;
struct inode * new_inode = new_dentry->d_inode;
struct page * dir_page = NULL;
......
......@@ -32,7 +32,7 @@
#define MINIX_V1 0x0001 /* original minix fs */
#define MINIX_V2 0x0002 /* minix V2 fs */
#define INODE_VERSION(inode) inode->i_sb->u.minix_sb.s_version
#define INODE_VERSION(inode) minix_sb(inode->i_sb)->s_version
/*
* This is the original minix inode layout on disk.
......@@ -90,6 +90,7 @@ struct minix_dir_entry {
#ifdef __KERNEL__
#include <linux/minix_fs_i.h>
#include <linux/minix_fs_sb.h>
/*
* change the define below to 0 if you want names > info->s_namelen chars to be
......@@ -131,6 +132,11 @@ extern struct file_operations minix_file_operations;
extern struct file_operations minix_dir_operations;
extern struct dentry_operations minix_dentry_operations;
static inline struct minix_sb_info *minix_sb(struct super_block *sb)
{
return &sb->u.minix_sb;
}
static inline struct minix_inode_info *minix_i(struct inode *inode)
{
return list_entry(inode, struct minix_inode_info, vfs_inode);
......
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