Commit 07a9abc8 authored by Alexander Viro's avatar Alexander Viro Committed by Linus Torvalds

[PATCH] minixfs cleanups (4/4)

Clean up minix/bitmap.c
parent ae99fb7c
...@@ -12,9 +12,7 @@ ...@@ -12,9 +12,7 @@
/* bitmap.c contains the code that handles the inode and block bitmaps */ /* bitmap.c contains the code that handles the inode and block bitmaps */
#include "minix.h" #include "minix.h"
#include <linux/locks.h>
#include <linux/smp_lock.h> #include <linux/smp_lock.h>
#include <asm/bitops.h> #include <asm/bitops.h>
static int nibblemap[] = { 4,3,3,2,3,2,2,1,3,2,2,1,2,1,1,0 }; static int nibblemap[] = { 4,3,3,2,3,2,2,1,3,2,2,1,2,1,1,0 };
...@@ -56,12 +54,7 @@ void minix_free_block(struct inode * inode, int block) ...@@ -56,12 +54,7 @@ void minix_free_block(struct inode * inode, int block)
struct buffer_head * bh; struct buffer_head * bh;
unsigned int bit,zone; unsigned int bit,zone;
if (!sb) { if (block < sbi->s_firstdatazone || block >= sbi->s_nzones) {
printk("trying to free block on nonexistent device\n");
return;
}
if (block < sbi->s_firstdatazone ||
block >= sbi->s_nzones) {
printk("trying to free block not in datazone\n"); printk("trying to free block not in datazone\n");
return; return;
} }
...@@ -84,44 +77,30 @@ void minix_free_block(struct inode * inode, int block) ...@@ -84,44 +77,30 @@ void minix_free_block(struct inode * inode, int block)
int minix_new_block(struct inode * inode) int minix_new_block(struct inode * inode)
{ {
struct super_block * sb = inode->i_sb; struct minix_sb_info *sbi = minix_sb(inode->i_sb);
struct minix_sb_info * sbi = minix_sb(sb); int i;
struct buffer_head * bh;
int i,j;
if (!sb) {
printk("trying to get new block from nonexistent device\n");
return 0;
}
lock_kernel();
repeat:
j = 8192;
bh = NULL;
for (i = 0; i < sbi->s_zmap_blocks; i++) { for (i = 0; i < sbi->s_zmap_blocks; i++) {
bh = sbi->s_zmap[i]; struct buffer_head *bh = sbi->s_zmap[i];
if ((j = minix_find_first_zero_bit(bh->b_data, 8192)) < 8192) int j;
break;
} lock_kernel();
if (!bh || j >= 8192) { if ((j = minix_find_first_zero_bit(bh->b_data, 8192)) < 8192) {
minix_set_bit(j,bh->b_data);
unlock_kernel();
mark_buffer_dirty(bh);
j += i*8192 + sbi->s_firstdatazone-1;
if (j < sbi->s_firstdatazone || j >= sbi->s_nzones)
break;
return j;
}
unlock_kernel(); unlock_kernel();
return 0;
}
if (minix_test_and_set_bit(j,bh->b_data)) {
printk("new_block: bit already set");
goto repeat;
} }
unlock_kernel(); return 0;
mark_buffer_dirty(bh);
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) unsigned long minix_count_free_blocks(struct minix_sb_info *sbi)
{ {
struct minix_sb_info *sbi = minix_sb(sb);
return (count_free(sbi->s_zmap, sbi->s_zmap_blocks, return (count_free(sbi->s_zmap, sbi->s_zmap_blocks,
sbi->s_nzones - sbi->s_firstdatazone + 1) sbi->s_nzones - sbi->s_firstdatazone + 1)
<< sbi->s_log_zone_size); << sbi->s_log_zone_size);
...@@ -204,36 +183,38 @@ static void minix_clear_inode(struct inode *inode) ...@@ -204,36 +183,38 @@ static void minix_clear_inode(struct inode *inode)
void minix_free_inode(struct inode * inode) void minix_free_inode(struct inode * inode)
{ {
struct minix_sb_info *sbi = minix_sb(inode->i_sb);
struct buffer_head * bh; struct buffer_head * bh;
unsigned long ino; unsigned long ino;
if (inode->i_ino < 1 || inode->i_ino > minix_sb(inode->i_sb)->s_ninodes) { if (inode->i_ino < 1 || inode->i_ino > sbi->s_ninodes) {
printk("free_inode: inode 0 or nonexistent inode\n"); printk("free_inode: inode 0 or nonexistent inode\n");
return; return;
} }
ino = inode->i_ino; ino = inode->i_ino;
if ((ino >> 13) >= minix_sb(inode->i_sb)->s_imap_blocks) { if ((ino >> 13) >= sbi->s_imap_blocks) {
printk("free_inode: nonexistent imap in superblock\n"); printk("free_inode: nonexistent imap in superblock\n");
return; return;
} }
bh = minix_sb(inode->i_sb)->s_imap[ino >> 13]; bh = sbi->s_imap[ino >> 13];
minix_clear_inode(inode); minix_clear_inode(inode);
clear_inode(inode); clear_inode(inode);
lock_kernel();
if (!minix_test_and_clear_bit(ino & 8191, bh->b_data)) if (!minix_test_and_clear_bit(ino & 8191, bh->b_data))
printk("free_inode: bit %lu already cleared.\n",ino); printk("free_inode: bit %lu already cleared.\n",ino);
unlock_kernel();
mark_buffer_dirty(bh); mark_buffer_dirty(bh);
} }
struct inode * minix_new_inode(const struct inode * dir, int * error) struct inode * minix_new_inode(const struct inode * dir, int * error)
{ {
struct super_block * sb; struct super_block *sb = dir->i_sb;
struct inode * inode; struct minix_sb_info *sbi = minix_sb(sb);
struct inode *inode = new_inode(sb);
struct buffer_head * bh; struct buffer_head * bh;
int i,j; int i,j;
sb = dir->i_sb;
inode = new_inode(sb);
if (!inode) { if (!inode) {
*error = -ENOMEM; *error = -ENOMEM;
return NULL; return NULL;
...@@ -241,28 +222,28 @@ struct inode * minix_new_inode(const struct inode * dir, int * error) ...@@ -241,28 +222,28 @@ struct inode * minix_new_inode(const struct inode * dir, int * error)
j = 8192; j = 8192;
bh = NULL; bh = NULL;
*error = -ENOSPC; *error = -ENOSPC;
lock_super(sb); lock_kernel();
for (i = 0; i < minix_sb(sb)->s_imap_blocks; i++) { for (i = 0; i < sbi->s_imap_blocks; i++) {
bh = minix_sb(inode->i_sb)->s_imap[i]; bh = sbi->s_imap[i];
if ((j = minix_find_first_zero_bit(bh->b_data, 8192)) < 8192) if ((j = minix_find_first_zero_bit(bh->b_data, 8192)) < 8192)
break; break;
} }
if (!bh || j >= 8192) { if (!bh || j >= 8192) {
unlock_kernel();
iput(inode); iput(inode);
unlock_super(sb);
return NULL; return NULL;
} }
if (minix_test_and_set_bit(j,bh->b_data)) { /* shouldn't happen */ if (minix_test_and_set_bit(j,bh->b_data)) { /* shouldn't happen */
printk("new_inode: bit already set"); printk("new_inode: bit already set");
unlock_kernel();
iput(inode); iput(inode);
unlock_super(sb);
return NULL; return NULL;
} }
unlock_kernel();
mark_buffer_dirty(bh); mark_buffer_dirty(bh);
j += i*8192; j += i*8192;
if (!j || j > minix_sb(inode->i_sb)->s_ninodes) { if (!j || j > sbi->s_ninodes) {
iput(inode); iput(inode);
unlock_super(sb);
return NULL; return NULL;
} }
inode->i_uid = current->fsuid; inode->i_uid = current->fsuid;
...@@ -274,13 +255,11 @@ struct inode * minix_new_inode(const struct inode * dir, int * error) ...@@ -274,13 +255,11 @@ struct inode * minix_new_inode(const struct inode * dir, int * error)
insert_inode_hash(inode); insert_inode_hash(inode);
mark_inode_dirty(inode); mark_inode_dirty(inode);
unlock_super(sb);
*error = 0; *error = 0;
return inode; return inode;
} }
unsigned long minix_count_free_inodes(struct super_block *sb) unsigned long minix_count_free_inodes(struct minix_sb_info *sbi)
{ {
return count_free(minix_sb(sb)->s_imap, minix_sb(sb)->s_imap_blocks, return count_free(sbi->s_imap, sbi->s_imap_blocks, sbi->s_ninodes + 1);
minix_sb(sb)->s_ninodes + 1);
} }
...@@ -10,14 +10,11 @@ ...@@ -10,14 +10,11 @@
*/ */
#include <linux/module.h> #include <linux/module.h>
#include "minix.h" #include "minix.h"
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/locks.h> #include <linux/locks.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/smp_lock.h>
#include <linux/highuid.h> #include <linux/highuid.h>
#include <linux/blkdev.h>
static void minix_read_inode(struct inode * inode); static void minix_read_inode(struct inode * inode);
static void minix_write_inode(struct inode * inode, int wait); static void minix_write_inode(struct inode * inode, int wait);
...@@ -28,9 +25,7 @@ static void minix_delete_inode(struct inode *inode) ...@@ -28,9 +25,7 @@ static void minix_delete_inode(struct inode *inode)
{ {
inode->i_size = 0; inode->i_size = 0;
minix_truncate(inode); minix_truncate(inode);
lock_kernel();
minix_free_inode(inode); minix_free_inode(inode);
unlock_kernel();
} }
static void minix_put_super(struct super_block *sb) static void minix_put_super(struct super_block *sb)
...@@ -304,10 +299,10 @@ static int minix_statfs(struct super_block *sb, struct statfs *buf) ...@@ -304,10 +299,10 @@ static int minix_statfs(struct super_block *sb, struct statfs *buf)
buf->f_type = sb->s_magic; buf->f_type = sb->s_magic;
buf->f_bsize = sb->s_blocksize; buf->f_bsize = sb->s_blocksize;
buf->f_blocks = (sbi->s_nzones - sbi->s_firstdatazone) << sbi->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_bfree = minix_count_free_blocks(sbi);
buf->f_bavail = buf->f_bfree; buf->f_bavail = buf->f_bfree;
buf->f_files = sbi->s_ninodes; buf->f_files = sbi->s_ninodes;
buf->f_ffree = minix_count_free_inodes(sb); buf->f_ffree = minix_count_free_inodes(sbi);
buf->f_namelen = sbi->s_namelen; buf->f_namelen = sbi->s_namelen;
return 0; return 0;
} }
...@@ -498,12 +493,7 @@ static struct buffer_head *minix_update_inode(struct inode *inode) ...@@ -498,12 +493,7 @@ static struct buffer_head *minix_update_inode(struct inode *inode)
static void minix_write_inode(struct inode * inode, int wait) static void minix_write_inode(struct inode * inode, int wait)
{ {
struct buffer_head *bh; brelse(minix_update_inode(inode));
lock_kernel();
bh = minix_update_inode(inode);
unlock_kernel();
brelse(bh);
} }
int minix_sync_inode(struct inode * inode) int minix_sync_inode(struct inode * inode)
......
...@@ -50,10 +50,10 @@ extern struct minix_inode * minix_V1_raw_inode(struct super_block *, ino_t, stru ...@@ -50,10 +50,10 @@ extern struct minix_inode * minix_V1_raw_inode(struct super_block *, ino_t, stru
extern struct minix2_inode * minix_V2_raw_inode(struct super_block *, ino_t, struct buffer_head **); extern struct minix2_inode * minix_V2_raw_inode(struct super_block *, ino_t, struct buffer_head **);
extern struct inode * minix_new_inode(const struct inode * dir, int * error); extern struct inode * minix_new_inode(const struct inode * dir, int * error);
extern void minix_free_inode(struct inode * inode); extern void minix_free_inode(struct inode * inode);
extern unsigned long minix_count_free_inodes(struct super_block *sb); extern unsigned long minix_count_free_inodes(struct minix_sb_info *sbi);
extern int minix_new_block(struct inode * inode); extern int minix_new_block(struct inode * inode);
extern void minix_free_block(struct inode * inode, int block); extern void minix_free_block(struct inode * inode, int block);
extern unsigned long minix_count_free_blocks(struct super_block *sb); extern unsigned long minix_count_free_blocks(struct minix_sb_info *sbi);
extern void V1_minix_truncate(struct inode *); extern void V1_minix_truncate(struct inode *);
extern void V2_minix_truncate(struct inode *); extern void V2_minix_truncate(struct 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