diff -urN ext2/fs/ext2/ialloc.c ext2-1/fs/ext2/ialloc.c --- ext2/fs/ext2/ialloc.c Thu Nov 30 11:23:18 2000 +++ ext2-1/fs/ext2/ialloc.c Fri Dec 1 10:35:24 2000 @@ -256,7 +256,7 @@ * For other inodes, search forward from the parent directory\'s block * group to find a free inode. */ -struct inode * ext2_new_inode (const struct inode * dir, int mode, int * err) +struct inode * ext2_new_inode (const struct inode * dir, int mode) { struct super_block * sb; struct buffer_head * bh; @@ -267,26 +267,22 @@ struct ext2_group_desc * gdp; struct ext2_group_desc * tmp; struct ext2_super_block * es; + int err; /* Cannot create files in a deleted directory */ - if (!dir || !dir->i_nlink) { - *err = -EPERM; - return NULL; - } + if (!dir || !dir->i_nlink) + return ERR_PTR(-EPERM); sb = dir->i_sb; inode = new_inode(sb); - if (!inode) { - *err = -ENOMEM; - return NULL; - } + if (!inode) + return ERR_PTR(-ENOMEM); lock_super (sb); es = sb->u.ext2_sb.s_es; repeat: gdp = NULL; i=0; - *err = -ENOSPC; if (S_ISDIR(mode)) { avefreei = le32_to_cpu(es->s_free_inodes_count) / sb->u.ext2_sb.s_groups_count; @@ -365,18 +361,14 @@ } } - if (!gdp) { - unlock_super (sb); - iput(inode); - return NULL; - } + err = -ENOSPC; + if (!gdp) + goto fail; + + err = -EIO; bitmap_nr = load_inode_bitmap (sb, i); - if (bitmap_nr < 0) { - unlock_super (sb); - iput(inode); - *err = -EIO; - return NULL; - } + if (bitmap_nr < 0) + goto fail; bh = sb->u.ext2_sb.s_inode_bitmap[bitmap_nr]; if ((j = ext2_find_first_zero_bit ((unsigned long *) bh->b_data, @@ -397,11 +389,11 @@ ext2_error (sb, "ext2_new_inode", "Free inodes count corrupted in group %d", i); - if (sb->s_flags & MS_RDONLY) { - unlock_super (sb); - iput (inode); - return NULL; - } + /* Is it really ENOSPC? */ + err = -ENOSPC; + if (sb->s_flags & MS_RDONLY) + goto fail; + gdp->bg_free_inodes_count = 0; mark_buffer_dirty(bh2); } @@ -412,10 +404,8 @@ ext2_error (sb, "ext2_new_inode", "reserved inode or inode > inodes count - " "block_group = %d,inode=%d", i, j); - unlock_super (sb); - iput (inode); - *err = -EIO; - return NULL; + err = -EIO; + goto fail; } gdp->bg_free_inodes_count = cpu_to_le16(le16_to_cpu(gdp->bg_free_inodes_count) - 1); @@ -464,13 +454,15 @@ sb->dq_op->drop(inode); inode->i_nlink = 0; iput(inode); - *err = -EDQUOT; - return NULL; + return ERR_PTR(-EDQUOT); } ext2_debug ("allocating inode %lu\n", inode->i_ino); - - *err = 0; return inode; + +fail: + unlock_super(sb); + iput(inode); + return ERR_PTR(err); } unsigned long ext2_count_free_inodes (struct super_block * sb) diff -urN ext2/fs/ext2/namei.c ext2-1/fs/ext2/namei.c --- ext2/fs/ext2/namei.c Thu Nov 30 11:23:18 2000 +++ ext2-1/fs/ext2/namei.c Fri Dec 1 10:35:24 2000 @@ -361,11 +361,9 @@ */ static int ext2_create (struct inode * dir, struct dentry * dentry, int mode) { - struct inode * inode; - int err; - - inode = ext2_new_inode (dir, mode, &err); - if (!inode) + struct inode * inode = ext2_new_inode (dir, mode); + int err = PTR_ERR(inode); + if (IS_ERR(inode)) return err; inode->i_op = &ext2_file_inode_operations; @@ -387,11 +385,10 @@ static int ext2_mknod (struct inode * dir, struct dentry *dentry, int mode, int rdev) { - struct inode * inode; - int err; + struct inode * inode = ext2_new_inode (dir, mode); + int err = PTR_ERR(inode); - inode = ext2_new_inode (dir, mode, &err); - if (!inode) + if (IS_ERR(inode)) return err; inode->i_uid = current->fsuid; @@ -421,8 +418,9 @@ if (dir->i_nlink >= EXT2_LINK_MAX) return -EMLINK; - inode = ext2_new_inode (dir, S_IFDIR, &err); - if (!inode) + inode = ext2_new_inode (dir, S_IFDIR); + err = PTR_ERR(inode); + if (IS_ERR(inode)) return err; inode->i_op = &ext2_dir_inode_operations; @@ -628,7 +626,9 @@ if (l > dir->i_sb->s_blocksize) return -ENAMETOOLONG; - if (!(inode = ext2_new_inode (dir, S_IFLNK, &err))) + inode = ext2_new_inode (dir, S_IFLNK); + err = PTR_ERR(inode); + if (IS_ERR(inode)) return err; inode->i_mode = S_IFLNK | S_IRWXUGO; diff -urN ext2/include/linux/ext2_fs.h ext2-1/include/linux/ext2_fs.h --- ext2/include/linux/ext2_fs.h Thu Nov 30 11:23:18 2000 +++ ext2-1/include/linux/ext2_fs.h Fri Dec 1 10:35:24 2000 @@ -552,7 +552,7 @@ extern int ext2_fsync_inode (struct inode *, int); /* ialloc.c */ -extern struct inode * ext2_new_inode (const struct inode *, int, int *); +extern struct inode * ext2_new_inode (const struct inode *, int); extern void ext2_free_inode (struct inode *); extern unsigned long ext2_count_free_inodes (struct super_block *); extern void ext2_check_inodes_bitmap (struct super_block *);