|
@@ -18,6 +18,9 @@
|
|
* Stephen Tweedie (sct@dcs.ed.ac.uk), 1993
|
|
* Stephen Tweedie (sct@dcs.ed.ac.uk), 1993
|
|
* Big-endian to little-endian byte-swapping/bitmaps by
|
|
* Big-endian to little-endian byte-swapping/bitmaps by
|
|
* David S. Miller (davem@caip.rutgers.edu), 1995
|
|
* David S. Miller (davem@caip.rutgers.edu), 1995
|
|
|
|
+ *
|
|
|
|
+ * UFS2 write support added by
|
|
|
|
+ * Evgeniy Dushistov <dushistov@mail.ru>, 2007
|
|
*/
|
|
*/
|
|
|
|
|
|
#include <linux/fs.h>
|
|
#include <linux/fs.h>
|
|
@@ -125,6 +128,47 @@ void ufs_free_inode (struct inode * inode)
|
|
UFSD("EXIT\n");
|
|
UFSD("EXIT\n");
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+/*
|
|
|
|
+ * Nullify new chunk of inodes,
|
|
|
|
+ * BSD people also set ui_gen field of inode
|
|
|
|
+ * during nullification, but we not care about
|
|
|
|
+ * that because of linux ufs do not support NFS
|
|
|
|
+ */
|
|
|
|
+static void ufs2_init_inodes_chunk(struct super_block *sb,
|
|
|
|
+ struct ufs_cg_private_info *ucpi,
|
|
|
|
+ struct ufs_cylinder_group *ucg)
|
|
|
|
+{
|
|
|
|
+ struct buffer_head *bh;
|
|
|
|
+ struct ufs_sb_private_info *uspi = UFS_SB(sb)->s_uspi;
|
|
|
|
+ sector_t beg = uspi->s_sbbase +
|
|
|
|
+ ufs_inotofsba(ucpi->c_cgx * uspi->s_ipg +
|
|
|
|
+ fs32_to_cpu(sb, ucg->cg_u.cg_u2.cg_initediblk));
|
|
|
|
+ sector_t end = beg + uspi->s_fpb;
|
|
|
|
+
|
|
|
|
+ UFSD("ENTER cgno %d\n", ucpi->c_cgx);
|
|
|
|
+
|
|
|
|
+ for (; beg < end; ++beg) {
|
|
|
|
+ bh = sb_getblk(sb, beg);
|
|
|
|
+ lock_buffer(bh);
|
|
|
|
+ memset(bh->b_data, 0, sb->s_blocksize);
|
|
|
|
+ set_buffer_uptodate(bh);
|
|
|
|
+ mark_buffer_dirty(bh);
|
|
|
|
+ unlock_buffer(bh);
|
|
|
|
+ if (sb->s_flags & MS_SYNCHRONOUS)
|
|
|
|
+ sync_dirty_buffer(bh);
|
|
|
|
+ brelse(bh);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ fs32_add(sb, &ucg->cg_u.cg_u2.cg_initediblk, uspi->s_inopb);
|
|
|
|
+ ubh_mark_buffer_dirty(UCPI_UBH(ucpi));
|
|
|
|
+ if (sb->s_flags & MS_SYNCHRONOUS) {
|
|
|
|
+ ubh_ll_rw_block(SWRITE, UCPI_UBH(ucpi));
|
|
|
|
+ ubh_wait_on_buffer(UCPI_UBH(ucpi));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ UFSD("EXIT\n");
|
|
|
|
+}
|
|
|
|
+
|
|
/*
|
|
/*
|
|
* There are two policies for allocating an inode. If the new inode is
|
|
* There are two policies for allocating an inode. If the new inode is
|
|
* a directory, then a forward search is made for a block group with both
|
|
* a directory, then a forward search is made for a block group with both
|
|
@@ -146,6 +190,7 @@ struct inode * ufs_new_inode(struct inode * dir, int mode)
|
|
struct inode * inode;
|
|
struct inode * inode;
|
|
unsigned cg, bit, i, j, start;
|
|
unsigned cg, bit, i, j, start;
|
|
struct ufs_inode_info *ufsi;
|
|
struct ufs_inode_info *ufsi;
|
|
|
|
+ int err = -ENOSPC;
|
|
|
|
|
|
UFSD("ENTER\n");
|
|
UFSD("ENTER\n");
|
|
|
|
|
|
@@ -198,13 +243,15 @@ struct inode * ufs_new_inode(struct inode * dir, int mode)
|
|
goto cg_found;
|
|
goto cg_found;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
goto failed;
|
|
goto failed;
|
|
|
|
|
|
cg_found:
|
|
cg_found:
|
|
ucpi = ufs_load_cylinder (sb, cg);
|
|
ucpi = ufs_load_cylinder (sb, cg);
|
|
- if (!ucpi)
|
|
|
|
|
|
+ if (!ucpi) {
|
|
|
|
+ err = -EIO;
|
|
goto failed;
|
|
goto failed;
|
|
|
|
+ }
|
|
ucg = ubh_get_ucg(UCPI_UBH(ucpi));
|
|
ucg = ubh_get_ucg(UCPI_UBH(ucpi));
|
|
if (!ufs_cg_chkmagic(sb, ucg))
|
|
if (!ufs_cg_chkmagic(sb, ucg))
|
|
ufs_panic (sb, "ufs_new_inode", "internal error, bad cg magic number");
|
|
ufs_panic (sb, "ufs_new_inode", "internal error, bad cg magic number");
|
|
@@ -216,6 +263,7 @@ cg_found:
|
|
if (!(bit < start)) {
|
|
if (!(bit < start)) {
|
|
ufs_error (sb, "ufs_new_inode",
|
|
ufs_error (sb, "ufs_new_inode",
|
|
"cylinder group %u corrupted - error in inode bitmap\n", cg);
|
|
"cylinder group %u corrupted - error in inode bitmap\n", cg);
|
|
|
|
+ err = -EIO;
|
|
goto failed;
|
|
goto failed;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -224,9 +272,18 @@ cg_found:
|
|
ubh_setbit (UCPI_UBH(ucpi), ucpi->c_iusedoff, bit);
|
|
ubh_setbit (UCPI_UBH(ucpi), ucpi->c_iusedoff, bit);
|
|
else {
|
|
else {
|
|
ufs_panic (sb, "ufs_new_inode", "internal error");
|
|
ufs_panic (sb, "ufs_new_inode", "internal error");
|
|
|
|
+ err = -EIO;
|
|
goto failed;
|
|
goto failed;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+ if (uspi->fs_magic == UFS2_MAGIC) {
|
|
|
|
+ u32 initediblk = fs32_to_cpu(sb, ucg->cg_u.cg_u2.cg_initediblk);
|
|
|
|
+
|
|
|
|
+ if (bit + uspi->s_inopb > initediblk &&
|
|
|
|
+ initediblk < fs32_to_cpu(sb, ucg->cg_u.cg_u2.cg_niblk))
|
|
|
|
+ ufs2_init_inodes_chunk(sb, ucpi, ucg);
|
|
|
|
+ }
|
|
|
|
+
|
|
fs32_sub(sb, &ucg->cg_cs.cs_nifree, 1);
|
|
fs32_sub(sb, &ucg->cg_cs.cs_nifree, 1);
|
|
uspi->cs_total.cs_nifree--;
|
|
uspi->cs_total.cs_nifree--;
|
|
fs32_sub(sb, &sbi->fs_cs(cg).cs_nifree, 1);
|
|
fs32_sub(sb, &sbi->fs_cs(cg).cs_nifree, 1);
|
|
@@ -236,7 +293,6 @@ cg_found:
|
|
uspi->cs_total.cs_ndir++;
|
|
uspi->cs_total.cs_ndir++;
|
|
fs32_add(sb, &sbi->fs_cs(cg).cs_ndir, 1);
|
|
fs32_add(sb, &sbi->fs_cs(cg).cs_ndir, 1);
|
|
}
|
|
}
|
|
-
|
|
|
|
ubh_mark_buffer_dirty (USPI_UBH(uspi));
|
|
ubh_mark_buffer_dirty (USPI_UBH(uspi));
|
|
ubh_mark_buffer_dirty (UCPI_UBH(ucpi));
|
|
ubh_mark_buffer_dirty (UCPI_UBH(ucpi));
|
|
if (sb->s_flags & MS_SYNCHRONOUS) {
|
|
if (sb->s_flags & MS_SYNCHRONOUS) {
|
|
@@ -245,6 +301,7 @@ cg_found:
|
|
}
|
|
}
|
|
sb->s_dirt = 1;
|
|
sb->s_dirt = 1;
|
|
|
|
|
|
|
|
+ inode->i_ino = cg * uspi->s_ipg + bit;
|
|
inode->i_mode = mode;
|
|
inode->i_mode = mode;
|
|
inode->i_uid = current->fsuid;
|
|
inode->i_uid = current->fsuid;
|
|
if (dir->i_mode & S_ISGID) {
|
|
if (dir->i_mode & S_ISGID) {
|
|
@@ -254,39 +311,72 @@ cg_found:
|
|
} else
|
|
} else
|
|
inode->i_gid = current->fsgid;
|
|
inode->i_gid = current->fsgid;
|
|
|
|
|
|
- inode->i_ino = cg * uspi->s_ipg + bit;
|
|
|
|
inode->i_blocks = 0;
|
|
inode->i_blocks = 0;
|
|
|
|
+ inode->i_generation = 0;
|
|
inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME_SEC;
|
|
inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME_SEC;
|
|
ufsi->i_flags = UFS_I(dir)->i_flags;
|
|
ufsi->i_flags = UFS_I(dir)->i_flags;
|
|
ufsi->i_lastfrag = 0;
|
|
ufsi->i_lastfrag = 0;
|
|
- ufsi->i_gen = 0;
|
|
|
|
ufsi->i_shadow = 0;
|
|
ufsi->i_shadow = 0;
|
|
ufsi->i_osync = 0;
|
|
ufsi->i_osync = 0;
|
|
ufsi->i_oeftflag = 0;
|
|
ufsi->i_oeftflag = 0;
|
|
ufsi->i_dir_start_lookup = 0;
|
|
ufsi->i_dir_start_lookup = 0;
|
|
memset(&ufsi->i_u1, 0, sizeof(ufsi->i_u1));
|
|
memset(&ufsi->i_u1, 0, sizeof(ufsi->i_u1));
|
|
-
|
|
|
|
insert_inode_hash(inode);
|
|
insert_inode_hash(inode);
|
|
mark_inode_dirty(inode);
|
|
mark_inode_dirty(inode);
|
|
|
|
|
|
|
|
+ if (uspi->fs_magic == UFS2_MAGIC) {
|
|
|
|
+ struct buffer_head *bh;
|
|
|
|
+ struct ufs2_inode *ufs2_inode;
|
|
|
|
+
|
|
|
|
+ /*
|
|
|
|
+ * setup birth date, we do it here because of there is no sense
|
|
|
|
+ * to hold it in struct ufs_inode_info, and lose 64 bit
|
|
|
|
+ */
|
|
|
|
+ bh = sb_bread(sb, uspi->s_sbbase + ufs_inotofsba(inode->i_ino));
|
|
|
|
+ if (!bh) {
|
|
|
|
+ ufs_warning(sb, "ufs_read_inode",
|
|
|
|
+ "unable to read inode %lu\n",
|
|
|
|
+ inode->i_ino);
|
|
|
|
+ err = -EIO;
|
|
|
|
+ goto fail_remove_inode;
|
|
|
|
+ }
|
|
|
|
+ lock_buffer(bh);
|
|
|
|
+ ufs2_inode = (struct ufs2_inode *)bh->b_data;
|
|
|
|
+ ufs2_inode += ufs_inotofsbo(inode->i_ino);
|
|
|
|
+ ufs2_inode->ui_birthtime.tv_sec =
|
|
|
|
+ cpu_to_fs32(sb, CURRENT_TIME_SEC.tv_sec);
|
|
|
|
+ ufs2_inode->ui_birthtime.tv_usec = 0;
|
|
|
|
+ mark_buffer_dirty(bh);
|
|
|
|
+ unlock_buffer(bh);
|
|
|
|
+ if (sb->s_flags & MS_SYNCHRONOUS)
|
|
|
|
+ sync_dirty_buffer(bh);
|
|
|
|
+ brelse(bh);
|
|
|
|
+ }
|
|
|
|
+
|
|
unlock_super (sb);
|
|
unlock_super (sb);
|
|
|
|
|
|
if (DQUOT_ALLOC_INODE(inode)) {
|
|
if (DQUOT_ALLOC_INODE(inode)) {
|
|
DQUOT_DROP(inode);
|
|
DQUOT_DROP(inode);
|
|
- inode->i_flags |= S_NOQUOTA;
|
|
|
|
- inode->i_nlink = 0;
|
|
|
|
- iput(inode);
|
|
|
|
- return ERR_PTR(-EDQUOT);
|
|
|
|
|
|
+ err = -EDQUOT;
|
|
|
|
+ goto fail_without_unlock;
|
|
}
|
|
}
|
|
|
|
|
|
UFSD("allocating inode %lu\n", inode->i_ino);
|
|
UFSD("allocating inode %lu\n", inode->i_ino);
|
|
UFSD("EXIT\n");
|
|
UFSD("EXIT\n");
|
|
return inode;
|
|
return inode;
|
|
|
|
|
|
|
|
+fail_remove_inode:
|
|
|
|
+ unlock_super(sb);
|
|
|
|
+fail_without_unlock:
|
|
|
|
+ inode->i_flags |= S_NOQUOTA;
|
|
|
|
+ inode->i_nlink = 0;
|
|
|
|
+ iput(inode);
|
|
|
|
+ UFSD("EXIT (FAILED): err %d\n", err);
|
|
|
|
+ return ERR_PTR(err);
|
|
failed:
|
|
failed:
|
|
unlock_super (sb);
|
|
unlock_super (sb);
|
|
make_bad_inode(inode);
|
|
make_bad_inode(inode);
|
|
iput (inode);
|
|
iput (inode);
|
|
- UFSD("EXIT (FAILED)\n");
|
|
|
|
- return ERR_PTR(-ENOSPC);
|
|
|
|
|
|
+ UFSD("EXIT (FAILED): err %d\n", err);
|
|
|
|
+ return ERR_PTR(err);
|
|
}
|
|
}
|