aboutsummaryrefslogtreecommitdiffstats
path: root/fs/xfs/xfs_inode.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/xfs/xfs_inode.c')
-rw-r--r--fs/xfs/xfs_inode.c85
1 files changed, 42 insertions, 43 deletions
diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c
index 46b0526acd4e..1d2912dc5226 100644
--- a/fs/xfs/xfs_inode.c
+++ b/fs/xfs/xfs_inode.c
@@ -174,8 +174,8 @@ xfs_imap_to_bp(
174 174
175 dip = (xfs_dinode_t *)xfs_buf_offset(bp, 175 dip = (xfs_dinode_t *)xfs_buf_offset(bp,
176 (i << mp->m_sb.sb_inodelog)); 176 (i << mp->m_sb.sb_inodelog));
177 di_ok = be16_to_cpu(dip->di_core.di_magic) == XFS_DINODE_MAGIC && 177 di_ok = be16_to_cpu(dip->di_magic) == XFS_DINODE_MAGIC &&
178 XFS_DINODE_GOOD_VERSION(dip->di_core.di_version); 178 XFS_DINODE_GOOD_VERSION(dip->di_version);
179 if (unlikely(XFS_TEST_ERROR(!di_ok, mp, 179 if (unlikely(XFS_TEST_ERROR(!di_ok, mp,
180 XFS_ERRTAG_ITOBP_INOTOBP, 180 XFS_ERRTAG_ITOBP_INOTOBP,
181 XFS_RANDOM_ITOBP_INOTOBP))) { 181 XFS_RANDOM_ITOBP_INOTOBP))) {
@@ -191,7 +191,7 @@ xfs_imap_to_bp(
191 "daddr %lld #%d (magic=%x)", 191 "daddr %lld #%d (magic=%x)",
192 XFS_BUFTARG_NAME(mp->m_ddev_targp), 192 XFS_BUFTARG_NAME(mp->m_ddev_targp),
193 (unsigned long long)imap->im_blkno, i, 193 (unsigned long long)imap->im_blkno, i,
194 be16_to_cpu(dip->di_core.di_magic)); 194 be16_to_cpu(dip->di_magic));
195#endif 195#endif
196 xfs_trans_brelse(tp, bp); 196 xfs_trans_brelse(tp, bp);
197 return XFS_ERROR(EFSCORRUPTED); 197 return XFS_ERROR(EFSCORRUPTED);
@@ -350,26 +350,26 @@ xfs_iformat(
350 XFS_IFORK_DSIZE(ip) / (uint)sizeof(xfs_bmbt_rec_t); 350 XFS_IFORK_DSIZE(ip) / (uint)sizeof(xfs_bmbt_rec_t);
351 error = 0; 351 error = 0;
352 352
353 if (unlikely(be32_to_cpu(dip->di_core.di_nextents) + 353 if (unlikely(be32_to_cpu(dip->di_nextents) +
354 be16_to_cpu(dip->di_core.di_anextents) > 354 be16_to_cpu(dip->di_anextents) >
355 be64_to_cpu(dip->di_core.di_nblocks))) { 355 be64_to_cpu(dip->di_nblocks))) {
356 xfs_fs_repair_cmn_err(CE_WARN, ip->i_mount, 356 xfs_fs_repair_cmn_err(CE_WARN, ip->i_mount,
357 "corrupt dinode %Lu, extent total = %d, nblocks = %Lu.", 357 "corrupt dinode %Lu, extent total = %d, nblocks = %Lu.",
358 (unsigned long long)ip->i_ino, 358 (unsigned long long)ip->i_ino,
359 (int)(be32_to_cpu(dip->di_core.di_nextents) + 359 (int)(be32_to_cpu(dip->di_nextents) +
360 be16_to_cpu(dip->di_core.di_anextents)), 360 be16_to_cpu(dip->di_anextents)),
361 (unsigned long long) 361 (unsigned long long)
362 be64_to_cpu(dip->di_core.di_nblocks)); 362 be64_to_cpu(dip->di_nblocks));
363 XFS_CORRUPTION_ERROR("xfs_iformat(1)", XFS_ERRLEVEL_LOW, 363 XFS_CORRUPTION_ERROR("xfs_iformat(1)", XFS_ERRLEVEL_LOW,
364 ip->i_mount, dip); 364 ip->i_mount, dip);
365 return XFS_ERROR(EFSCORRUPTED); 365 return XFS_ERROR(EFSCORRUPTED);
366 } 366 }
367 367
368 if (unlikely(dip->di_core.di_forkoff > ip->i_mount->m_sb.sb_inodesize)) { 368 if (unlikely(dip->di_forkoff > ip->i_mount->m_sb.sb_inodesize)) {
369 xfs_fs_repair_cmn_err(CE_WARN, ip->i_mount, 369 xfs_fs_repair_cmn_err(CE_WARN, ip->i_mount,
370 "corrupt dinode %Lu, forkoff = 0x%x.", 370 "corrupt dinode %Lu, forkoff = 0x%x.",
371 (unsigned long long)ip->i_ino, 371 (unsigned long long)ip->i_ino,
372 dip->di_core.di_forkoff); 372 dip->di_forkoff);
373 XFS_CORRUPTION_ERROR("xfs_iformat(2)", XFS_ERRLEVEL_LOW, 373 XFS_CORRUPTION_ERROR("xfs_iformat(2)", XFS_ERRLEVEL_LOW,
374 ip->i_mount, dip); 374 ip->i_mount, dip);
375 return XFS_ERROR(EFSCORRUPTED); 375 return XFS_ERROR(EFSCORRUPTED);
@@ -380,25 +380,25 @@ xfs_iformat(
380 case S_IFCHR: 380 case S_IFCHR:
381 case S_IFBLK: 381 case S_IFBLK:
382 case S_IFSOCK: 382 case S_IFSOCK:
383 if (unlikely(dip->di_core.di_format != XFS_DINODE_FMT_DEV)) { 383 if (unlikely(dip->di_format != XFS_DINODE_FMT_DEV)) {
384 XFS_CORRUPTION_ERROR("xfs_iformat(3)", XFS_ERRLEVEL_LOW, 384 XFS_CORRUPTION_ERROR("xfs_iformat(3)", XFS_ERRLEVEL_LOW,
385 ip->i_mount, dip); 385 ip->i_mount, dip);
386 return XFS_ERROR(EFSCORRUPTED); 386 return XFS_ERROR(EFSCORRUPTED);
387 } 387 }
388 ip->i_d.di_size = 0; 388 ip->i_d.di_size = 0;
389 ip->i_size = 0; 389 ip->i_size = 0;
390 ip->i_df.if_u2.if_rdev = be32_to_cpu(dip->di_u.di_dev); 390 ip->i_df.if_u2.if_rdev = xfs_dinode_get_rdev(dip);
391 break; 391 break;
392 392
393 case S_IFREG: 393 case S_IFREG:
394 case S_IFLNK: 394 case S_IFLNK:
395 case S_IFDIR: 395 case S_IFDIR:
396 switch (dip->di_core.di_format) { 396 switch (dip->di_format) {
397 case XFS_DINODE_FMT_LOCAL: 397 case XFS_DINODE_FMT_LOCAL:
398 /* 398 /*
399 * no local regular files yet 399 * no local regular files yet
400 */ 400 */
401 if (unlikely((be16_to_cpu(dip->di_core.di_mode) & S_IFMT) == S_IFREG)) { 401 if (unlikely((be16_to_cpu(dip->di_mode) & S_IFMT) == S_IFREG)) {
402 xfs_fs_repair_cmn_err(CE_WARN, ip->i_mount, 402 xfs_fs_repair_cmn_err(CE_WARN, ip->i_mount,
403 "corrupt inode %Lu " 403 "corrupt inode %Lu "
404 "(local format for regular file).", 404 "(local format for regular file).",
@@ -409,7 +409,7 @@ xfs_iformat(
409 return XFS_ERROR(EFSCORRUPTED); 409 return XFS_ERROR(EFSCORRUPTED);
410 } 410 }
411 411
412 di_size = be64_to_cpu(dip->di_core.di_size); 412 di_size = be64_to_cpu(dip->di_size);
413 if (unlikely(di_size > XFS_DFORK_DSIZE(dip, ip->i_mount))) { 413 if (unlikely(di_size > XFS_DFORK_DSIZE(dip, ip->i_mount))) {
414 xfs_fs_repair_cmn_err(CE_WARN, ip->i_mount, 414 xfs_fs_repair_cmn_err(CE_WARN, ip->i_mount,
415 "corrupt inode %Lu " 415 "corrupt inode %Lu "
@@ -451,7 +451,7 @@ xfs_iformat(
451 ip->i_afp = kmem_zone_zalloc(xfs_ifork_zone, KM_SLEEP); 451 ip->i_afp = kmem_zone_zalloc(xfs_ifork_zone, KM_SLEEP);
452 ip->i_afp->if_ext_max = 452 ip->i_afp->if_ext_max =
453 XFS_IFORK_ASIZE(ip) / (uint)sizeof(xfs_bmbt_rec_t); 453 XFS_IFORK_ASIZE(ip) / (uint)sizeof(xfs_bmbt_rec_t);
454 switch (dip->di_core.di_aformat) { 454 switch (dip->di_aformat) {
455 case XFS_DINODE_FMT_LOCAL: 455 case XFS_DINODE_FMT_LOCAL:
456 atp = (xfs_attr_shortform_t *)XFS_DFORK_APTR(dip); 456 atp = (xfs_attr_shortform_t *)XFS_DFORK_APTR(dip);
457 size = be16_to_cpu(atp->hdr.totsize); 457 size = be16_to_cpu(atp->hdr.totsize);
@@ -663,7 +663,7 @@ xfs_iformat_btree(
663void 663void
664xfs_dinode_from_disk( 664xfs_dinode_from_disk(
665 xfs_icdinode_t *to, 665 xfs_icdinode_t *to,
666 xfs_dinode_core_t *from) 666 xfs_dinode_t *from)
667{ 667{
668 to->di_magic = be16_to_cpu(from->di_magic); 668 to->di_magic = be16_to_cpu(from->di_magic);
669 to->di_mode = be16_to_cpu(from->di_mode); 669 to->di_mode = be16_to_cpu(from->di_mode);
@@ -697,7 +697,7 @@ xfs_dinode_from_disk(
697 697
698void 698void
699xfs_dinode_to_disk( 699xfs_dinode_to_disk(
700 xfs_dinode_core_t *to, 700 xfs_dinode_t *to,
701 xfs_icdinode_t *from) 701 xfs_icdinode_t *from)
702{ 702{
703 to->di_magic = cpu_to_be16(from->di_magic); 703 to->di_magic = cpu_to_be16(from->di_magic);
@@ -784,9 +784,7 @@ uint
784xfs_dic2xflags( 784xfs_dic2xflags(
785 xfs_dinode_t *dip) 785 xfs_dinode_t *dip)
786{ 786{
787 xfs_dinode_core_t *dic = &dip->di_core; 787 return _xfs_dic2xflags(be16_to_cpu(dip->di_flags)) |
788
789 return _xfs_dic2xflags(be16_to_cpu(dic->di_flags)) |
790 (XFS_DFORK_Q(dip) ? XFS_XFLAG_HASATTR : 0); 788 (XFS_DFORK_Q(dip) ? XFS_XFLAG_HASATTR : 0);
791} 789}
792 790
@@ -905,12 +903,12 @@ xfs_iread(
905 * If we got something that isn't an inode it means someone 903 * If we got something that isn't an inode it means someone
906 * (nfs or dmi) has a stale handle. 904 * (nfs or dmi) has a stale handle.
907 */ 905 */
908 if (be16_to_cpu(dip->di_core.di_magic) != XFS_DINODE_MAGIC) { 906 if (be16_to_cpu(dip->di_magic) != XFS_DINODE_MAGIC) {
909#ifdef DEBUG 907#ifdef DEBUG
910 xfs_fs_cmn_err(CE_ALERT, mp, "xfs_iread: " 908 xfs_fs_cmn_err(CE_ALERT, mp, "xfs_iread: "
911 "dip->di_core.di_magic (0x%x) != " 909 "dip->di_magic (0x%x) != "
912 "XFS_DINODE_MAGIC (0x%x)", 910 "XFS_DINODE_MAGIC (0x%x)",
913 be16_to_cpu(dip->di_core.di_magic), 911 be16_to_cpu(dip->di_magic),
914 XFS_DINODE_MAGIC); 912 XFS_DINODE_MAGIC);
915#endif /* DEBUG */ 913#endif /* DEBUG */
916 error = XFS_ERROR(EINVAL); 914 error = XFS_ERROR(EINVAL);
@@ -924,8 +922,8 @@ xfs_iread(
924 * specific information. 922 * specific information.
925 * Otherwise, just get the truly permanent information. 923 * Otherwise, just get the truly permanent information.
926 */ 924 */
927 if (dip->di_core.di_mode) { 925 if (dip->di_mode) {
928 xfs_dinode_from_disk(&ip->i_d, &dip->di_core); 926 xfs_dinode_from_disk(&ip->i_d, dip);
929 error = xfs_iformat(ip, dip); 927 error = xfs_iformat(ip, dip);
930 if (error) { 928 if (error) {
931#ifdef DEBUG 929#ifdef DEBUG
@@ -936,10 +934,10 @@ xfs_iread(
936 goto out_brelse; 934 goto out_brelse;
937 } 935 }
938 } else { 936 } else {
939 ip->i_d.di_magic = be16_to_cpu(dip->di_core.di_magic); 937 ip->i_d.di_magic = be16_to_cpu(dip->di_magic);
940 ip->i_d.di_version = dip->di_core.di_version; 938 ip->i_d.di_version = dip->di_version;
941 ip->i_d.di_gen = be32_to_cpu(dip->di_core.di_gen); 939 ip->i_d.di_gen = be32_to_cpu(dip->di_gen);
942 ip->i_d.di_flushiter = be16_to_cpu(dip->di_core.di_flushiter); 940 ip->i_d.di_flushiter = be16_to_cpu(dip->di_flushiter);
943 /* 941 /*
944 * Make sure to pull in the mode here as well in 942 * Make sure to pull in the mode here as well in
945 * case the inode is released without being used. 943 * case the inode is released without being used.
@@ -2295,7 +2293,7 @@ xfs_ifree(
2295 * This is a temporary hack that would require a proper fix 2293 * This is a temporary hack that would require a proper fix
2296 * in the future. 2294 * in the future.
2297 */ 2295 */
2298 dip->di_core.di_mode = 0; 2296 dip->di_mode = 0;
2299 2297
2300 if (delete) { 2298 if (delete) {
2301 xfs_ifree_cluster(ip, tp, first_ino); 2299 xfs_ifree_cluster(ip, tp, first_ino);
@@ -2909,15 +2907,16 @@ xfs_iflush_fork(
2909 case XFS_DINODE_FMT_DEV: 2907 case XFS_DINODE_FMT_DEV:
2910 if (iip->ili_format.ilf_fields & XFS_ILOG_DEV) { 2908 if (iip->ili_format.ilf_fields & XFS_ILOG_DEV) {
2911 ASSERT(whichfork == XFS_DATA_FORK); 2909 ASSERT(whichfork == XFS_DATA_FORK);
2912 dip->di_u.di_dev = cpu_to_be32(ip->i_df.if_u2.if_rdev); 2910 xfs_dinode_put_rdev(dip, ip->i_df.if_u2.if_rdev);
2913 } 2911 }
2914 break; 2912 break;
2915 2913
2916 case XFS_DINODE_FMT_UUID: 2914 case XFS_DINODE_FMT_UUID:
2917 if (iip->ili_format.ilf_fields & XFS_ILOG_UUID) { 2915 if (iip->ili_format.ilf_fields & XFS_ILOG_UUID) {
2918 ASSERT(whichfork == XFS_DATA_FORK); 2916 ASSERT(whichfork == XFS_DATA_FORK);
2919 memcpy(&dip->di_u.di_muuid, &ip->i_df.if_u2.if_uuid, 2917 memcpy(XFS_DFORK_DPTR(dip),
2920 sizeof(uuid_t)); 2918 &ip->i_df.if_u2.if_uuid,
2919 sizeof(uuid_t));
2921 } 2920 }
2922 break; 2921 break;
2923 2922
@@ -3295,11 +3294,11 @@ xfs_iflush_int(
3295 */ 3294 */
3296 xfs_synchronize_atime(ip); 3295 xfs_synchronize_atime(ip);
3297 3296
3298 if (XFS_TEST_ERROR(be16_to_cpu(dip->di_core.di_magic) != XFS_DINODE_MAGIC, 3297 if (XFS_TEST_ERROR(be16_to_cpu(dip->di_magic) != XFS_DINODE_MAGIC,
3299 mp, XFS_ERRTAG_IFLUSH_1, XFS_RANDOM_IFLUSH_1)) { 3298 mp, XFS_ERRTAG_IFLUSH_1, XFS_RANDOM_IFLUSH_1)) {
3300 xfs_cmn_err(XFS_PTAG_IFLUSH, CE_ALERT, mp, 3299 xfs_cmn_err(XFS_PTAG_IFLUSH, CE_ALERT, mp,
3301 "xfs_iflush: Bad inode %Lu magic number 0x%x, ptr 0x%p", 3300 "xfs_iflush: Bad inode %Lu magic number 0x%x, ptr 0x%p",
3302 ip->i_ino, be16_to_cpu(dip->di_core.di_magic), dip); 3301 ip->i_ino, be16_to_cpu(dip->di_magic), dip);
3303 goto corrupt_out; 3302 goto corrupt_out;
3304 } 3303 }
3305 if (XFS_TEST_ERROR(ip->i_d.di_magic != XFS_DINODE_MAGIC, 3304 if (XFS_TEST_ERROR(ip->i_d.di_magic != XFS_DINODE_MAGIC,
@@ -3362,7 +3361,7 @@ xfs_iflush_int(
3362 * because if the inode is dirty at all the core must 3361 * because if the inode is dirty at all the core must
3363 * be. 3362 * be.
3364 */ 3363 */
3365 xfs_dinode_to_disk(&dip->di_core, &ip->i_d); 3364 xfs_dinode_to_disk(dip, &ip->i_d);
3366 3365
3367 /* Wrap, we never let the log put out DI_MAX_FLUSH */ 3366 /* Wrap, we never let the log put out DI_MAX_FLUSH */
3368 if (ip->i_d.di_flushiter == DI_MAX_FLUSH) 3367 if (ip->i_d.di_flushiter == DI_MAX_FLUSH)
@@ -3382,7 +3381,7 @@ xfs_iflush_int(
3382 * Convert it back. 3381 * Convert it back.
3383 */ 3382 */
3384 ASSERT(ip->i_d.di_nlink <= XFS_MAXLINK_1); 3383 ASSERT(ip->i_d.di_nlink <= XFS_MAXLINK_1);
3385 dip->di_core.di_onlink = cpu_to_be16(ip->i_d.di_nlink); 3384 dip->di_onlink = cpu_to_be16(ip->i_d.di_nlink);
3386 } else { 3385 } else {
3387 /* 3386 /*
3388 * The superblock version has already been bumped, 3387 * The superblock version has already been bumped,
@@ -3390,12 +3389,12 @@ xfs_iflush_int(
3390 * format permanent. 3389 * format permanent.
3391 */ 3390 */
3392 ip->i_d.di_version = XFS_DINODE_VERSION_2; 3391 ip->i_d.di_version = XFS_DINODE_VERSION_2;
3393 dip->di_core.di_version = XFS_DINODE_VERSION_2; 3392 dip->di_version = XFS_DINODE_VERSION_2;
3394 ip->i_d.di_onlink = 0; 3393 ip->i_d.di_onlink = 0;
3395 dip->di_core.di_onlink = 0; 3394 dip->di_onlink = 0;
3396 memset(&(ip->i_d.di_pad[0]), 0, sizeof(ip->i_d.di_pad)); 3395 memset(&(ip->i_d.di_pad[0]), 0, sizeof(ip->i_d.di_pad));
3397 memset(&(dip->di_core.di_pad[0]), 0, 3396 memset(&(dip->di_pad[0]), 0,
3398 sizeof(dip->di_core.di_pad)); 3397 sizeof(dip->di_pad));
3399 ASSERT(ip->i_d.di_projid == 0); 3398 ASSERT(ip->i_d.di_projid == 0);
3400 } 3399 }
3401 } 3400 }