aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ufs
diff options
context:
space:
mode:
authorEvgeniy <dushistov@mail.ru>2006-01-14 03:42:06 -0500
committerLinus Torvalds <torvalds@g5.osdl.org>2006-01-14 13:27:32 -0500
commit7b4ee73e28052e53aac2fef1c91029666d8b2d70 (patch)
treea82714e4b9c2e1157695872b66bf180dc12b27a2 /fs/ufs
parent59af70385fb125f819d953801b6c45629836e916 (diff)
[PATCH] ufs cleanup
Here is update of ufs cleanup patch, brought on by the recently fixed ubh_get_usb_second() bug that made some ugly code rather painfully obvious. It also includes - fix compilation warnings which appears if debug mode turn on - remove unnecessary duplication of code to support UFS2 I tested it on ufs1 and ufs2 file-systems. Signed-off-by: Evgeniy Dushistov <dushistov@mail.ru> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'fs/ufs')
-rw-r--r--fs/ufs/balloc.c19
-rw-r--r--fs/ufs/ialloc.c4
-rw-r--r--fs/ufs/inode.c11
-rw-r--r--fs/ufs/super.c57
-rw-r--r--fs/ufs/util.h28
5 files changed, 64 insertions, 55 deletions
diff --git a/fs/ufs/balloc.c b/fs/ufs/balloc.c
index a9f4421ddb6f..3ada9dcf55b8 100644
--- a/fs/ufs/balloc.c
+++ b/fs/ufs/balloc.c
@@ -49,7 +49,7 @@ void ufs_free_fragments (struct inode * inode, unsigned fragment, unsigned count
49 49
50 sb = inode->i_sb; 50 sb = inode->i_sb;
51 uspi = UFS_SB(sb)->s_uspi; 51 uspi = UFS_SB(sb)->s_uspi;
52 usb1 = ubh_get_usb_first(USPI_UBH); 52 usb1 = ubh_get_usb_first(uspi);
53 53
54 UFSD(("ENTER, fragment %u, count %u\n", fragment, count)) 54 UFSD(("ENTER, fragment %u, count %u\n", fragment, count))
55 55
@@ -81,8 +81,9 @@ void ufs_free_fragments (struct inode * inode, unsigned fragment, unsigned count
81 for (i = bit; i < end_bit; i++) { 81 for (i = bit; i < end_bit; i++) {
82 if (ubh_isclr (UCPI_UBH, ucpi->c_freeoff, i)) 82 if (ubh_isclr (UCPI_UBH, ucpi->c_freeoff, i))
83 ubh_setbit (UCPI_UBH, ucpi->c_freeoff, i); 83 ubh_setbit (UCPI_UBH, ucpi->c_freeoff, i);
84 else ufs_error (sb, "ufs_free_fragments", 84 else
85 "bit already cleared for fragment %u", i); 85 ufs_error (sb, "ufs_free_fragments",
86 "bit already cleared for fragment %u", i);
86 } 87 }
87 88
88 DQUOT_FREE_BLOCK (inode, count); 89 DQUOT_FREE_BLOCK (inode, count);
@@ -143,7 +144,7 @@ void ufs_free_blocks (struct inode * inode, unsigned fragment, unsigned count) {
143 144
144 sb = inode->i_sb; 145 sb = inode->i_sb;
145 uspi = UFS_SB(sb)->s_uspi; 146 uspi = UFS_SB(sb)->s_uspi;
146 usb1 = ubh_get_usb_first(USPI_UBH); 147 usb1 = ubh_get_usb_first(uspi);
147 148
148 UFSD(("ENTER, fragment %u, count %u\n", fragment, count)) 149 UFSD(("ENTER, fragment %u, count %u\n", fragment, count))
149 150
@@ -247,7 +248,7 @@ unsigned ufs_new_fragments (struct inode * inode, __fs32 * p, unsigned fragment,
247 248
248 sb = inode->i_sb; 249 sb = inode->i_sb;
249 uspi = UFS_SB(sb)->s_uspi; 250 uspi = UFS_SB(sb)->s_uspi;
250 usb1 = ubh_get_usb_first(USPI_UBH); 251 usb1 = ubh_get_usb_first(uspi);
251 *err = -ENOSPC; 252 *err = -ENOSPC;
252 253
253 lock_super (sb); 254 lock_super (sb);
@@ -407,7 +408,7 @@ ufs_add_fragments (struct inode * inode, unsigned fragment,
407 408
408 sb = inode->i_sb; 409 sb = inode->i_sb;
409 uspi = UFS_SB(sb)->s_uspi; 410 uspi = UFS_SB(sb)->s_uspi;
410 usb1 = ubh_get_usb_first (USPI_UBH); 411 usb1 = ubh_get_usb_first (uspi);
411 count = newcount - oldcount; 412 count = newcount - oldcount;
412 413
413 cgno = ufs_dtog(fragment); 414 cgno = ufs_dtog(fragment);
@@ -490,7 +491,7 @@ static unsigned ufs_alloc_fragments (struct inode * inode, unsigned cgno,
490 491
491 sb = inode->i_sb; 492 sb = inode->i_sb;
492 uspi = UFS_SB(sb)->s_uspi; 493 uspi = UFS_SB(sb)->s_uspi;
493 usb1 = ubh_get_usb_first(USPI_UBH); 494 usb1 = ubh_get_usb_first(uspi);
494 oldcg = cgno; 495 oldcg = cgno;
495 496
496 /* 497 /*
@@ -606,7 +607,7 @@ static unsigned ufs_alloccg_block (struct inode * inode,
606 607
607 sb = inode->i_sb; 608 sb = inode->i_sb;
608 uspi = UFS_SB(sb)->s_uspi; 609 uspi = UFS_SB(sb)->s_uspi;
609 usb1 = ubh_get_usb_first(USPI_UBH); 610 usb1 = ubh_get_usb_first(uspi);
610 ucg = ubh_get_ucg(UCPI_UBH); 611 ucg = ubh_get_ucg(UCPI_UBH);
611 612
612 if (goal == 0) { 613 if (goal == 0) {
@@ -663,7 +664,7 @@ static unsigned ufs_bitmap_search (struct super_block * sb,
663 UFSD(("ENTER, cg %u, goal %u, count %u\n", ucpi->c_cgx, goal, count)) 664 UFSD(("ENTER, cg %u, goal %u, count %u\n", ucpi->c_cgx, goal, count))
664 665
665 uspi = UFS_SB(sb)->s_uspi; 666 uspi = UFS_SB(sb)->s_uspi;
666 usb1 = ubh_get_usb_first (USPI_UBH); 667 usb1 = ubh_get_usb_first (uspi);
667 ucg = ubh_get_ucg(UCPI_UBH); 668 ucg = ubh_get_ucg(UCPI_UBH);
668 669
669 if (goal) 670 if (goal)
diff --git a/fs/ufs/ialloc.c b/fs/ufs/ialloc.c
index 0938945b9cbc..c7a47ed4f430 100644
--- a/fs/ufs/ialloc.c
+++ b/fs/ufs/ialloc.c
@@ -72,7 +72,7 @@ void ufs_free_inode (struct inode * inode)
72 72
73 sb = inode->i_sb; 73 sb = inode->i_sb;
74 uspi = UFS_SB(sb)->s_uspi; 74 uspi = UFS_SB(sb)->s_uspi;
75 usb1 = ubh_get_usb_first(USPI_UBH); 75 usb1 = ubh_get_usb_first(uspi);
76 76
77 ino = inode->i_ino; 77 ino = inode->i_ino;
78 78
@@ -167,7 +167,7 @@ struct inode * ufs_new_inode(struct inode * dir, int mode)
167 ufsi = UFS_I(inode); 167 ufsi = UFS_I(inode);
168 sbi = UFS_SB(sb); 168 sbi = UFS_SB(sb);
169 uspi = sbi->s_uspi; 169 uspi = sbi->s_uspi;
170 usb1 = ubh_get_usb_first(USPI_UBH); 170 usb1 = ubh_get_usb_first(uspi);
171 171
172 lock_super (sb); 172 lock_super (sb);
173 173
diff --git a/fs/ufs/inode.c b/fs/ufs/inode.c
index 55f4aa16e3fc..e0c04e36a051 100644
--- a/fs/ufs/inode.c
+++ b/fs/ufs/inode.c
@@ -61,7 +61,7 @@ static int ufs_block_to_path(struct inode *inode, sector_t i_block, sector_t off
61 int n = 0; 61 int n = 0;
62 62
63 63
64 UFSD(("ptrs=uspi->s_apb = %d,double_blocks=%d \n",ptrs,double_blocks)); 64 UFSD(("ptrs=uspi->s_apb = %d,double_blocks=%ld \n",ptrs,double_blocks));
65 if (i_block < 0) { 65 if (i_block < 0) {
66 ufs_warning(inode->i_sb, "ufs_block_to_path", "block < 0"); 66 ufs_warning(inode->i_sb, "ufs_block_to_path", "block < 0");
67 } else if (i_block < direct_blocks) { 67 } else if (i_block < direct_blocks) {
@@ -104,7 +104,7 @@ u64 ufs_frag_map(struct inode *inode, sector_t frag)
104 unsigned flags = UFS_SB(sb)->s_flags; 104 unsigned flags = UFS_SB(sb)->s_flags;
105 u64 temp = 0L; 105 u64 temp = 0L;
106 106
107 UFSD((": frag = %lu depth = %d\n",frag,depth)); 107 UFSD((": frag = %llu depth = %d\n", (unsigned long long)frag, depth));
108 UFSD((": uspi->s_fpbshift = %d ,uspi->s_apbmask = %x, mask=%llx\n",uspi->s_fpbshift,uspi->s_apbmask,mask)); 108 UFSD((": uspi->s_fpbshift = %d ,uspi->s_apbmask = %x, mask=%llx\n",uspi->s_fpbshift,uspi->s_apbmask,mask));
109 109
110 if (depth == 0) 110 if (depth == 0)
@@ -365,9 +365,10 @@ repeat:
365 sync_dirty_buffer(bh); 365 sync_dirty_buffer(bh);
366 inode->i_ctime = CURRENT_TIME_SEC; 366 inode->i_ctime = CURRENT_TIME_SEC;
367 mark_inode_dirty(inode); 367 mark_inode_dirty(inode);
368 UFSD(("result %u\n", tmp + blockoff));
368out: 369out:
369 brelse (bh); 370 brelse (bh);
370 UFSD(("EXIT, result %u\n", tmp + blockoff)) 371 UFSD(("EXIT\n"));
371 return result; 372 return result;
372} 373}
373 374
@@ -386,7 +387,7 @@ static int ufs_getfrag_block (struct inode *inode, sector_t fragment, struct buf
386 387
387 if (!create) { 388 if (!create) {
388 phys64 = ufs_frag_map(inode, fragment); 389 phys64 = ufs_frag_map(inode, fragment);
389 UFSD(("phys64 = %lu \n",phys64)); 390 UFSD(("phys64 = %llu \n",phys64));
390 if (phys64) 391 if (phys64)
391 map_bh(bh_result, sb, phys64); 392 map_bh(bh_result, sb, phys64);
392 return 0; 393 return 0;
@@ -401,7 +402,7 @@ static int ufs_getfrag_block (struct inode *inode, sector_t fragment, struct buf
401 402
402 lock_kernel(); 403 lock_kernel();
403 404
404 UFSD(("ENTER, ino %lu, fragment %u\n", inode->i_ino, fragment)) 405 UFSD(("ENTER, ino %lu, fragment %llu\n", inode->i_ino, (unsigned long long)fragment))
405 if (fragment < 0) 406 if (fragment < 0)
406 goto abort_negative; 407 goto abort_negative;
407 if (fragment > 408 if (fragment >
diff --git a/fs/ufs/super.c b/fs/ufs/super.c
index e9a42c711a9e..d4aacee593ff 100644
--- a/fs/ufs/super.c
+++ b/fs/ufs/super.c
@@ -221,7 +221,7 @@ void ufs_error (struct super_block * sb, const char * function,
221 va_list args; 221 va_list args;
222 222
223 uspi = UFS_SB(sb)->s_uspi; 223 uspi = UFS_SB(sb)->s_uspi;
224 usb1 = ubh_get_usb_first(USPI_UBH); 224 usb1 = ubh_get_usb_first(uspi);
225 225
226 if (!(sb->s_flags & MS_RDONLY)) { 226 if (!(sb->s_flags & MS_RDONLY)) {
227 usb1->fs_clean = UFS_FSBAD; 227 usb1->fs_clean = UFS_FSBAD;
@@ -253,7 +253,7 @@ void ufs_panic (struct super_block * sb, const char * function,
253 va_list args; 253 va_list args;
254 254
255 uspi = UFS_SB(sb)->s_uspi; 255 uspi = UFS_SB(sb)->s_uspi;
256 usb1 = ubh_get_usb_first(USPI_UBH); 256 usb1 = ubh_get_usb_first(uspi);
257 257
258 if (!(sb->s_flags & MS_RDONLY)) { 258 if (!(sb->s_flags & MS_RDONLY)) {
259 usb1->fs_clean = UFS_FSBAD; 259 usb1->fs_clean = UFS_FSBAD;
@@ -420,21 +420,18 @@ static int ufs_read_cylinder_structures (struct super_block *sb) {
420 if (i + uspi->s_fpb > blks) 420 if (i + uspi->s_fpb > blks)
421 size = (blks - i) * uspi->s_fsize; 421 size = (blks - i) * uspi->s_fsize;
422 422
423 if ((flags & UFS_TYPE_MASK) == UFS_TYPE_UFS2) { 423 if ((flags & UFS_TYPE_MASK) == UFS_TYPE_UFS2)
424 ubh = ubh_bread(sb, 424 ubh = ubh_bread(sb,
425 fs64_to_cpu(sb, usb->fs_u11.fs_u2.fs_csaddr) + i, size); 425 fs64_to_cpu(sb, usb->fs_u11.fs_u2.fs_csaddr) + i, size);
426 if (!ubh) 426 else
427 goto failed;
428 ubh_ubhcpymem (space, ubh, size);
429 sbi->s_csp[ufs_fragstoblks(i)]=(struct ufs_csum *)space;
430 }
431 else {
432 ubh = ubh_bread(sb, uspi->s_csaddr + i, size); 427 ubh = ubh_bread(sb, uspi->s_csaddr + i, size);
433 if (!ubh) 428
434 goto failed; 429 if (!ubh)
435 ubh_ubhcpymem(space, ubh, size); 430 goto failed;
436 sbi->s_csp[ufs_fragstoblks(i)]=(struct ufs_csum *)space; 431
437 } 432 ubh_ubhcpymem (space, ubh, size);
433 sbi->s_csp[ufs_fragstoblks(i)]=(struct ufs_csum *)space;
434
438 space += size; 435 space += size;
439 ubh_brelse (ubh); 436 ubh_brelse (ubh);
440 ubh = NULL; 437 ubh = NULL;
@@ -539,6 +536,7 @@ static int ufs_fill_super(struct super_block *sb, void *data, int silent)
539 struct inode *inode; 536 struct inode *inode;
540 unsigned block_size, super_block_size; 537 unsigned block_size, super_block_size;
541 unsigned flags; 538 unsigned flags;
539 unsigned super_block_offset;
542 540
543 uspi = NULL; 541 uspi = NULL;
544 ubh = NULL; 542 ubh = NULL;
@@ -586,10 +584,11 @@ static int ufs_fill_super(struct super_block *sb, void *data, int silent)
586 if (!uspi) 584 if (!uspi)
587 goto failed; 585 goto failed;
588 586
587 super_block_offset=UFS_SBLOCK;
588
589 /* Keep 2Gig file limit. Some UFS variants need to override 589 /* Keep 2Gig file limit. Some UFS variants need to override
590 this but as I don't know which I'll let those in the know loosen 590 this but as I don't know which I'll let those in the know loosen
591 the rules */ 591 the rules */
592
593 switch (sbi->s_mount_opt & UFS_MOUNT_UFSTYPE) { 592 switch (sbi->s_mount_opt & UFS_MOUNT_UFSTYPE) {
594 case UFS_MOUNT_UFSTYPE_44BSD: 593 case UFS_MOUNT_UFSTYPE_44BSD:
595 UFSD(("ufstype=44bsd\n")) 594 UFSD(("ufstype=44bsd\n"))
@@ -601,7 +600,8 @@ static int ufs_fill_super(struct super_block *sb, void *data, int silent)
601 flags |= UFS_DE_44BSD | UFS_UID_44BSD | UFS_ST_44BSD | UFS_CG_44BSD; 600 flags |= UFS_DE_44BSD | UFS_UID_44BSD | UFS_ST_44BSD | UFS_CG_44BSD;
602 break; 601 break;
603 case UFS_MOUNT_UFSTYPE_UFS2: 602 case UFS_MOUNT_UFSTYPE_UFS2:
604 UFSD(("ufstype=ufs2\n")) 603 UFSD(("ufstype=ufs2\n"));
604 super_block_offset=SBLOCK_UFS2;
605 uspi->s_fsize = block_size = 512; 605 uspi->s_fsize = block_size = 512;
606 uspi->s_fmask = ~(512 - 1); 606 uspi->s_fmask = ~(512 - 1);
607 uspi->s_fshift = 9; 607 uspi->s_fshift = 9;
@@ -725,19 +725,16 @@ again:
725 /* 725 /*
726 * read ufs super block from device 726 * read ufs super block from device
727 */ 727 */
728 if ( (flags & UFS_TYPE_MASK) == UFS_TYPE_UFS2) { 728
729 ubh = ubh_bread_uspi(uspi, sb, uspi->s_sbbase + SBLOCK_UFS2/block_size, super_block_size); 729 ubh = ubh_bread_uspi(uspi, sb, uspi->s_sbbase + super_block_offset/block_size, super_block_size);
730 } 730
731 else {
732 ubh = ubh_bread_uspi(uspi, sb, uspi->s_sbbase + UFS_SBLOCK/block_size, super_block_size);
733 }
734 if (!ubh) 731 if (!ubh)
735 goto failed; 732 goto failed;
736 733
737 734
738 usb1 = ubh_get_usb_first(USPI_UBH); 735 usb1 = ubh_get_usb_first(uspi);
739 usb2 = ubh_get_usb_second(USPI_UBH); 736 usb2 = ubh_get_usb_second(uspi);
740 usb3 = ubh_get_usb_third(USPI_UBH); 737 usb3 = ubh_get_usb_third(uspi);
741 usb = (struct ufs_super_block *) 738 usb = (struct ufs_super_block *)
742 ((struct ufs_buffer_head *)uspi)->bh[0]->b_data ; 739 ((struct ufs_buffer_head *)uspi)->bh[0]->b_data ;
743 740
@@ -1006,8 +1003,8 @@ static void ufs_write_super (struct super_block *sb) {
1006 UFSD(("ENTER\n")) 1003 UFSD(("ENTER\n"))
1007 flags = UFS_SB(sb)->s_flags; 1004 flags = UFS_SB(sb)->s_flags;
1008 uspi = UFS_SB(sb)->s_uspi; 1005 uspi = UFS_SB(sb)->s_uspi;
1009 usb1 = ubh_get_usb_first(USPI_UBH); 1006 usb1 = ubh_get_usb_first(uspi);
1010 usb3 = ubh_get_usb_third(USPI_UBH); 1007 usb3 = ubh_get_usb_third(uspi);
1011 1008
1012 if (!(sb->s_flags & MS_RDONLY)) { 1009 if (!(sb->s_flags & MS_RDONLY)) {
1013 usb1->fs_time = cpu_to_fs32(sb, get_seconds()); 1010 usb1->fs_time = cpu_to_fs32(sb, get_seconds());
@@ -1049,8 +1046,8 @@ static int ufs_remount (struct super_block *sb, int *mount_flags, char *data)
1049 1046
1050 uspi = UFS_SB(sb)->s_uspi; 1047 uspi = UFS_SB(sb)->s_uspi;
1051 flags = UFS_SB(sb)->s_flags; 1048 flags = UFS_SB(sb)->s_flags;
1052 usb1 = ubh_get_usb_first(USPI_UBH); 1049 usb1 = ubh_get_usb_first(uspi);
1053 usb3 = ubh_get_usb_third(USPI_UBH); 1050 usb3 = ubh_get_usb_third(uspi);
1054 1051
1055 /* 1052 /*
1056 * Allow the "check" option to be passed as a remount option. 1053 * Allow the "check" option to be passed as a remount option.
@@ -1124,7 +1121,7 @@ static int ufs_statfs (struct super_block *sb, struct kstatfs *buf)
1124 lock_kernel(); 1121 lock_kernel();
1125 1122
1126 uspi = UFS_SB(sb)->s_uspi; 1123 uspi = UFS_SB(sb)->s_uspi;
1127 usb1 = ubh_get_usb_first (USPI_UBH); 1124 usb1 = ubh_get_usb_first (uspi);
1128 usb = (struct ufs_super_block *) 1125 usb = (struct ufs_super_block *)
1129 ((struct ufs_buffer_head *)uspi)->bh[0]->b_data ; 1126 ((struct ufs_buffer_head *)uspi)->bh[0]->b_data ;
1130 1127
diff --git a/fs/ufs/util.h b/fs/ufs/util.h
index e45ad5379872..48d6d9bcc157 100644
--- a/fs/ufs/util.h
+++ b/fs/ufs/util.h
@@ -249,18 +249,28 @@ extern void _ubh_memcpyubh_(struct ufs_sb_private_info *, struct ufs_buffer_head
249 249
250 250
251/* 251/*
252 * macros to get important structures from ufs_buffer_head 252 * macros and inline function to get important structures from ufs_sb_private_info
253 */ 253 */
254#define ubh_get_usb_first(ubh) \
255 ((struct ufs_super_block_first *)((ubh)->bh[0]->b_data))
256 254
257#define ubh_get_usb_second(ubh) \ 255static inline void *get_usb_offset(struct ufs_sb_private_info *uspi,
258 ((struct ufs_super_block_second *)((ubh)->\ 256 unsigned int offset)
259 bh[UFS_SECTOR_SIZE >> uspi->s_fshift]->b_data + (UFS_SECTOR_SIZE & ~uspi->s_fmask))) 257{
258 unsigned int index;
259
260 index = offset >> uspi->s_fshift;
261 offset &= ~uspi->s_fmask;
262 return uspi->s_ubh.bh[index]->b_data + offset;
263}
264
265#define ubh_get_usb_first(uspi) \
266 ((struct ufs_super_block_first *)get_usb_offset((uspi), 0))
267
268#define ubh_get_usb_second(uspi) \
269 ((struct ufs_super_block_second *)get_usb_offset((uspi), UFS_SECTOR_SIZE))
270
271#define ubh_get_usb_third(uspi) \
272 ((struct ufs_super_block_third *)get_usb_offset((uspi), 2*UFS_SECTOR_SIZE))
260 273
261#define ubh_get_usb_third(ubh) \
262 ((struct ufs_super_block_third *)((ubh)-> \
263 bh[UFS_SECTOR_SIZE*2 >> uspi->s_fshift]->b_data + (UFS_SECTOR_SIZE*2 & ~uspi->s_fmask)))
264 274
265#define ubh_get_ucg(ubh) \ 275#define ubh_get_ucg(ubh) \
266 ((struct ufs_cylinder_group *)((ubh)->bh[0]->b_data)) 276 ((struct ufs_cylinder_group *)((ubh)->bh[0]->b_data))