string: factorize skip_spaces and export it to be generally available
[safe/jmp/linux-2.6] / fs / sysv / inode.c
index 0530077..9824743 100644 (file)
  *  the superblock.
  */
 
-#include <linux/smp_lock.h>
 #include <linux/highuid.h>
 #include <linux/slab.h>
 #include <linux/init.h>
 #include <linux/buffer_head.h>
 #include <linux/vfs.h>
+#include <linux/namei.h>
 #include <asm/byteorder.h>
 #include "sysv.h"
 
-/* This is only called on sync() and umount(), when s_dirt=1. */
-static void sysv_write_super(struct super_block *sb)
+static int sysv_sync_fs(struct super_block *sb, int wait)
 {
        struct sysv_sb_info *sbi = SYSV_SB(sb);
        unsigned long time = get_seconds(), old_time;
 
-       lock_kernel();
-       if (sb->s_flags & MS_RDONLY)
-               goto clean;
+       lock_super(sb);
 
        /*
         * If we are going to write out the super block,
@@ -52,18 +49,29 @@ static void sysv_write_super(struct super_block *sb)
                *sbi->s_sb_time = cpu_to_fs32(sbi, time);
                mark_buffer_dirty(sbi->s_bh2);
        }
-clean:
-       sb->s_dirt = 0;
-       unlock_kernel();
+
+       unlock_super(sb);
+
+       return 0;
+}
+
+static void sysv_write_super(struct super_block *sb)
+{
+       if (!(sb->s_flags & MS_RDONLY))
+               sysv_sync_fs(sb, 1);
+       else
+               sb->s_dirt = 0;
 }
 
 static int sysv_remount(struct super_block *sb, int *flags, char *data)
 {
        struct sysv_sb_info *sbi = SYSV_SB(sb);
+       lock_super(sb);
        if (sbi->s_forced_ro)
                *flags |= MS_RDONLY;
        if (!(*flags & MS_RDONLY))
                sb->s_dirt = 1;
+       unlock_super(sb);
        return 0;
 }
 
@@ -71,6 +79,9 @@ static void sysv_put_super(struct super_block *sb)
 {
        struct sysv_sb_info *sbi = SYSV_SB(sb);
 
+       if (sb->s_dirt)
+               sysv_write_super(sb);
+
        if (!(sb->s_flags & MS_RDONLY)) {
                /* XXX ext2 also updates the state here */
                mark_buffer_dirty(sbi->s_bh1);
@@ -85,9 +96,11 @@ static void sysv_put_super(struct super_block *sb)
        kfree(sbi);
 }
 
-static int sysv_statfs(struct super_block *sb, struct kstatfs *buf)
+static int sysv_statfs(struct dentry *dentry, struct kstatfs *buf)
 {
+       struct super_block *sb = dentry->d_sb;
        struct sysv_sb_info *sbi = SYSV_SB(sb);
+       u64 id = huge_encode_dev(sb->s_bdev->bd_dev);
 
        buf->f_type = sb->s_magic;
        buf->f_bsize = sb->s_blocksize;
@@ -96,6 +109,8 @@ static int sysv_statfs(struct super_block *sb, struct kstatfs *buf)
        buf->f_files = sbi->s_ninodes;
        buf->f_ffree = sysv_count_free_inodes(sb);
        buf->f_namelen = SYSV_NAMELEN;
+       buf->f_fsid.val[0] = (u32)id;
+       buf->f_fsid.val[1] = (u32)(id >> 32);
        return 0;
 }
 
@@ -141,7 +156,7 @@ static inline void write3byte(struct sysv_sb_info *sbi,
        }
 }
 
-static struct inode_operations sysv_symlink_inode_operations = {
+static const struct inode_operations sysv_symlink_inode_operations = {
        .readlink       = generic_readlink,
        .follow_link    = page_follow_link_light,
        .put_link       = page_put_link,
@@ -162,26 +177,36 @@ void sysv_set_inode(struct inode *inode, dev_t rdev)
                if (inode->i_blocks) {
                        inode->i_op = &sysv_symlink_inode_operations;
                        inode->i_mapping->a_ops = &sysv_aops;
-               } else
+               } else {
                        inode->i_op = &sysv_fast_symlink_inode_operations;
+                       nd_terminate_link(SYSV_I(inode)->i_data, inode->i_size,
+                               sizeof(SYSV_I(inode)->i_data) - 1);
+               }
        } else
                init_special_inode(inode, inode->i_mode, rdev);
 }
 
-static void sysv_read_inode(struct inode *inode)
+struct inode *sysv_iget(struct super_block *sb, unsigned int ino)
 {
-       struct super_block * sb = inode->i_sb;
        struct sysv_sb_info * sbi = SYSV_SB(sb);
        struct buffer_head * bh;
        struct sysv_inode * raw_inode;
        struct sysv_inode_info * si;
-       unsigned int block, ino = inode->i_ino;
+       struct inode *inode;
+       unsigned int block;
 
        if (!ino || ino > sbi->s_ninodes) {
                printk("Bad inode number on dev %s: %d is out of range\n",
-                      inode->i_sb->s_id, ino);
-               goto bad_inode;
+                      sb->s_id, ino);
+               return ERR_PTR(-EIO);
        }
+
+       inode = iget_locked(sb, ino);
+       if (!inode)
+               return ERR_PTR(-ENOMEM);
+       if (!(inode->i_state & I_NEW))
+               return inode;
+
        raw_inode = sysv_raw_inode(sb, ino, &bh);
        if (!raw_inode) {
                printk("Major problem: unable to read inode from dev %s\n",
@@ -200,7 +225,7 @@ static void sysv_read_inode(struct inode *inode)
        inode->i_ctime.tv_nsec = 0;
        inode->i_atime.tv_nsec = 0;
        inode->i_mtime.tv_nsec = 0;
-       inode->i_blocks = inode->i_blksize = 0;
+       inode->i_blocks = 0;
 
        si = SYSV_I(inode);
        for (block = 0; block < 10+1+1+1; block++)
@@ -213,14 +238,15 @@ static void sysv_read_inode(struct inode *inode)
                               old_decode_dev(fs32_to_cpu(sbi, si->i_data[0])));
        else
                sysv_set_inode(inode, 0);
-       return;
+       unlock_new_inode(inode);
+       return inode;
 
 bad_inode:
-       make_bad_inode(inode);
-       return;
+       iget_failed(inode);
+       return ERR_PTR(-EIO);
 }
 
-static struct buffer_head * sysv_update_inode(struct inode * inode)
+int sysv_write_inode(struct inode *inode, int wait)
 {
        struct super_block * sb = inode->i_sb;
        struct sysv_sb_info * sbi = SYSV_SB(sb);
@@ -228,17 +254,18 @@ static struct buffer_head * sysv_update_inode(struct inode * inode)
        struct sysv_inode * raw_inode;
        struct sysv_inode_info * si;
        unsigned int ino, block;
+       int err = 0;
 
        ino = inode->i_ino;
        if (!ino || ino > sbi->s_ninodes) {
                printk("Bad inode number on dev %s: %d is out of range\n",
                       inode->i_sb->s_id, ino);
-               return NULL;
+               return -EIO;
        }
        raw_inode = sysv_raw_inode(sb, ino, &bh);
        if (!raw_inode) {
                printk("unable to read i-node block\n");
-               return NULL;
+               return -EIO;
        }
 
        raw_inode->i_mode = cpu_to_fs16(sbi, inode->i_mode);
@@ -257,55 +284,38 @@ static struct buffer_head * sysv_update_inode(struct inode * inode)
                write3byte(sbi, (u8 *)&si->i_data[block],
                        &raw_inode->i_data[3*block]);
        mark_buffer_dirty(bh);
-       return bh;
-}
-
-int sysv_write_inode(struct inode * inode, int wait)
-{
-       struct buffer_head *bh;
-       lock_kernel();
-       bh = sysv_update_inode(inode);
+       if (wait) {
+                sync_dirty_buffer(bh);
+                if (buffer_req(bh) && !buffer_uptodate(bh)) {
+                        printk ("IO error syncing sysv inode [%s:%08x]\n",
+                                sb->s_id, ino);
+                        err = -EIO;
+                }
+        }
        brelse(bh);
-       unlock_kernel();
        return 0;
 }
 
-int sysv_sync_inode(struct inode * inode)
+int sysv_sync_inode(struct inode *inode)
 {
-        int err = 0;
-        struct buffer_head *bh;
-
-        bh = sysv_update_inode(inode);
-        if (bh && buffer_dirty(bh)) {
-                sync_dirty_buffer(bh);
-                if (buffer_req(bh) && !buffer_uptodate(bh)) {
-                        printk ("IO error syncing sysv inode [%s:%08lx]\n",
-                                inode->i_sb->s_id, inode->i_ino);
-                        err = -1;
-                }
-        }
-        else if (!bh)
-                err = -1;
-        brelse (bh);
-        return err;
+       return sysv_write_inode(inode, 1);
 }
 
 static void sysv_delete_inode(struct inode *inode)
 {
+       truncate_inode_pages(&inode->i_data, 0);
        inode->i_size = 0;
        sysv_truncate(inode);
-       lock_kernel();
        sysv_free_inode(inode);
-       unlock_kernel();
 }
 
-static kmem_cache_t *sysv_inode_cachep;
+static struct kmem_cache *sysv_inode_cachep;
 
 static struct inode *sysv_alloc_inode(struct super_block *sb)
 {
        struct sysv_inode_info *si;
 
-       si = kmem_cache_alloc(sysv_inode_cachep, SLAB_KERNEL);
+       si = kmem_cache_alloc(sysv_inode_cachep, GFP_KERNEL);
        if (!si)
                return NULL;
        return &si->vfs_inode;
@@ -316,23 +326,21 @@ static void sysv_destroy_inode(struct inode *inode)
        kmem_cache_free(sysv_inode_cachep, SYSV_I(inode));
 }
 
-static void init_once(void *p, kmem_cache_t *cachep, unsigned long flags)
+static void init_once(void *p)
 {
        struct sysv_inode_info *si = (struct sysv_inode_info *)p;
 
-       if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) ==
-                       SLAB_CTOR_CONSTRUCTOR)
-               inode_init_once(&si->vfs_inode);
+       inode_init_once(&si->vfs_inode);
 }
 
-struct super_operations sysv_sops = {
+const struct super_operations sysv_sops = {
        .alloc_inode    = sysv_alloc_inode,
        .destroy_inode  = sysv_destroy_inode,
-       .read_inode     = sysv_read_inode,
        .write_inode    = sysv_write_inode,
        .delete_inode   = sysv_delete_inode,
        .put_super      = sysv_put_super,
        .write_super    = sysv_write_super,
+       .sync_fs        = sysv_sync_fs,
        .remount_fs     = sysv_remount,
        .statfs         = sysv_statfs,
 };
@@ -341,8 +349,8 @@ int __init sysv_init_icache(void)
 {
        sysv_inode_cachep = kmem_cache_create("sysv_inode_cache",
                        sizeof(struct sysv_inode_info), 0,
-                       SLAB_RECLAIM_ACCOUNT,
-                       init_once, NULL);
+                       SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
+                       init_once);
        if (!sysv_inode_cachep)
                return -ENOMEM;
        return 0;