aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ufs/balloc.c
diff options
context:
space:
mode:
authorEvgeniy Dushistov <dushistov@mail.ru>2007-02-12 03:54:32 -0500
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2007-02-12 12:48:40 -0500
commit54fb996ac15c4014fa4d6b0ec8e42da134204897 (patch)
treeee7a98270cabefc996a13691a7c9d63141a8d3a9 /fs/ufs/balloc.c
parent3313e29267414e4e3bf0d3de1caf9cb439b64aaf (diff)
[PATCH] ufs2 write: block allocation update
Patch adds ability to work with 64bit metadata, this made by replacing work with 32bit pointers by inline functions. Signed-off-by: Evgeniy Dushistov <dushistov@mail.ru> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs/ufs/balloc.c')
-rw-r--r--fs/ufs/balloc.c197
1 files changed, 117 insertions, 80 deletions
diff --git a/fs/ufs/balloc.c b/fs/ufs/balloc.c
index 638f4c585e89..0e97a4f79c31 100644
--- a/fs/ufs/balloc.c
+++ b/fs/ufs/balloc.c
@@ -4,6 +4,8 @@
4 * Copyright (C) 1998 4 * Copyright (C) 1998
5 * Daniel Pirkl <daniel.pirkl@email.cz> 5 * Daniel Pirkl <daniel.pirkl@email.cz>
6 * Charles University, Faculty of Mathematics and Physics 6 * Charles University, Faculty of Mathematics and Physics
7 *
8 * UFS2 write support Evgeniy Dushistov <dushistov@mail.ru>, 2007
7 */ 9 */
8 10
9#include <linux/fs.h> 11#include <linux/fs.h>
@@ -21,38 +23,42 @@
21#include "swab.h" 23#include "swab.h"
22#include "util.h" 24#include "util.h"
23 25
24static unsigned ufs_add_fragments (struct inode *, unsigned, unsigned, unsigned, int *); 26#define INVBLOCK ((u64)-1L)
25static unsigned ufs_alloc_fragments (struct inode *, unsigned, unsigned, unsigned, int *); 27
26static unsigned ufs_alloccg_block (struct inode *, struct ufs_cg_private_info *, unsigned, int *); 28static u64 ufs_add_fragments(struct inode *, u64, unsigned, unsigned, int *);
27static unsigned ufs_bitmap_search (struct super_block *, struct ufs_cg_private_info *, unsigned, unsigned); 29static u64 ufs_alloc_fragments(struct inode *, unsigned, u64, unsigned, int *);
30static u64 ufs_alloccg_block(struct inode *, struct ufs_cg_private_info *, u64, int *);
31static u64 ufs_bitmap_search (struct super_block *, struct ufs_cg_private_info *, u64, unsigned);
28static unsigned char ufs_fragtable_8fpb[], ufs_fragtable_other[]; 32static unsigned char ufs_fragtable_8fpb[], ufs_fragtable_other[];
29static void ufs_clusteracct(struct super_block *, struct ufs_cg_private_info *, unsigned, int); 33static void ufs_clusteracct(struct super_block *, struct ufs_cg_private_info *, unsigned, int);
30 34
31/* 35/*
32 * Free 'count' fragments from fragment number 'fragment' 36 * Free 'count' fragments from fragment number 'fragment'
33 */ 37 */
34void ufs_free_fragments(struct inode *inode, unsigned fragment, unsigned count) 38void ufs_free_fragments(struct inode *inode, u64 fragment, unsigned count)
35{ 39{
36 struct super_block * sb; 40 struct super_block * sb;
37 struct ufs_sb_private_info * uspi; 41 struct ufs_sb_private_info * uspi;
38 struct ufs_super_block_first * usb1; 42 struct ufs_super_block_first * usb1;
39 struct ufs_cg_private_info * ucpi; 43 struct ufs_cg_private_info * ucpi;
40 struct ufs_cylinder_group * ucg; 44 struct ufs_cylinder_group * ucg;
41 unsigned cgno, bit, end_bit, bbase, blkmap, i, blkno, cylno; 45 unsigned cgno, bit, end_bit, bbase, blkmap, i;
46 u64 blkno;
42 47
43 sb = inode->i_sb; 48 sb = inode->i_sb;
44 uspi = UFS_SB(sb)->s_uspi; 49 uspi = UFS_SB(sb)->s_uspi;
45 usb1 = ubh_get_usb_first(uspi); 50 usb1 = ubh_get_usb_first(uspi);
46 51
47 UFSD("ENTER, fragment %u, count %u\n", fragment, count); 52 UFSD("ENTER, fragment %llu, count %u\n",
53 (unsigned long long)fragment, count);
48 54
49 if (ufs_fragnum(fragment) + count > uspi->s_fpg) 55 if (ufs_fragnum(fragment) + count > uspi->s_fpg)
50 ufs_error (sb, "ufs_free_fragments", "internal error"); 56 ufs_error (sb, "ufs_free_fragments", "internal error");
51 57
52 lock_super(sb); 58 lock_super(sb);
53 59
54 cgno = ufs_dtog(fragment); 60 cgno = ufs_dtog(uspi, fragment);
55 bit = ufs_dtogd(fragment); 61 bit = ufs_dtogd(uspi, fragment);
56 if (cgno >= uspi->s_ncg) { 62 if (cgno >= uspi->s_ncg) {
57 ufs_panic (sb, "ufs_free_fragments", "freeing blocks are outside device"); 63 ufs_panic (sb, "ufs_free_fragments", "freeing blocks are outside device");
58 goto failed; 64 goto failed;
@@ -101,9 +107,13 @@ void ufs_free_fragments(struct inode *inode, unsigned fragment, unsigned count)
101 fs32_add(sb, &ucg->cg_cs.cs_nbfree, 1); 107 fs32_add(sb, &ucg->cg_cs.cs_nbfree, 1);
102 uspi->cs_total.cs_nbfree++; 108 uspi->cs_total.cs_nbfree++;
103 fs32_add(sb, &UFS_SB(sb)->fs_cs(cgno).cs_nbfree, 1); 109 fs32_add(sb, &UFS_SB(sb)->fs_cs(cgno).cs_nbfree, 1);
104 cylno = ufs_cbtocylno (bbase); 110 if (uspi->fs_magic != UFS2_MAGIC) {
105 fs16_add(sb, &ubh_cg_blks(ucpi, cylno, ufs_cbtorpos(bbase)), 1); 111 unsigned cylno = ufs_cbtocylno (bbase);
106 fs32_add(sb, &ubh_cg_blktot(ucpi, cylno), 1); 112
113 fs16_add(sb, &ubh_cg_blks(ucpi, cylno,
114 ufs_cbtorpos(bbase)), 1);
115 fs32_add(sb, &ubh_cg_blktot(ucpi, cylno), 1);
116 }
107 } 117 }
108 118
109 ubh_mark_buffer_dirty (USPI_UBH(uspi)); 119 ubh_mark_buffer_dirty (USPI_UBH(uspi));
@@ -127,24 +137,27 @@ failed:
127/* 137/*
128 * Free 'count' fragments from fragment number 'fragment' (free whole blocks) 138 * Free 'count' fragments from fragment number 'fragment' (free whole blocks)
129 */ 139 */
130void ufs_free_blocks(struct inode *inode, unsigned fragment, unsigned count) 140void ufs_free_blocks(struct inode *inode, u64 fragment, unsigned count)
131{ 141{
132 struct super_block * sb; 142 struct super_block * sb;
133 struct ufs_sb_private_info * uspi; 143 struct ufs_sb_private_info * uspi;
134 struct ufs_super_block_first * usb1; 144 struct ufs_super_block_first * usb1;
135 struct ufs_cg_private_info * ucpi; 145 struct ufs_cg_private_info * ucpi;
136 struct ufs_cylinder_group * ucg; 146 struct ufs_cylinder_group * ucg;
137 unsigned overflow, cgno, bit, end_bit, blkno, i, cylno; 147 unsigned overflow, cgno, bit, end_bit, i;
148 u64 blkno;
138 149
139 sb = inode->i_sb; 150 sb = inode->i_sb;
140 uspi = UFS_SB(sb)->s_uspi; 151 uspi = UFS_SB(sb)->s_uspi;
141 usb1 = ubh_get_usb_first(uspi); 152 usb1 = ubh_get_usb_first(uspi);
142 153
143 UFSD("ENTER, fragment %u, count %u\n", fragment, count); 154 UFSD("ENTER, fragment %llu, count %u\n",
155 (unsigned long long)fragment, count);
144 156
145 if ((fragment & uspi->s_fpbmask) || (count & uspi->s_fpbmask)) { 157 if ((fragment & uspi->s_fpbmask) || (count & uspi->s_fpbmask)) {
146 ufs_error (sb, "ufs_free_blocks", "internal error, " 158 ufs_error (sb, "ufs_free_blocks", "internal error, "
147 "fragment %u, count %u\n", fragment, count); 159 "fragment %llu, count %u\n",
160 (unsigned long long)fragment, count);
148 goto failed; 161 goto failed;
149 } 162 }
150 163
@@ -152,8 +165,8 @@ void ufs_free_blocks(struct inode *inode, unsigned fragment, unsigned count)
152 165
153do_more: 166do_more:
154 overflow = 0; 167 overflow = 0;
155 cgno = ufs_dtog (fragment); 168 cgno = ufs_dtog(uspi, fragment);
156 bit = ufs_dtogd (fragment); 169 bit = ufs_dtogd(uspi, fragment);
157 if (cgno >= uspi->s_ncg) { 170 if (cgno >= uspi->s_ncg) {
158 ufs_panic (sb, "ufs_free_blocks", "freeing blocks are outside device"); 171 ufs_panic (sb, "ufs_free_blocks", "freeing blocks are outside device");
159 goto failed_unlock; 172 goto failed_unlock;
@@ -187,9 +200,14 @@ do_more:
187 fs32_add(sb, &ucg->cg_cs.cs_nbfree, 1); 200 fs32_add(sb, &ucg->cg_cs.cs_nbfree, 1);
188 uspi->cs_total.cs_nbfree++; 201 uspi->cs_total.cs_nbfree++;
189 fs32_add(sb, &UFS_SB(sb)->fs_cs(cgno).cs_nbfree, 1); 202 fs32_add(sb, &UFS_SB(sb)->fs_cs(cgno).cs_nbfree, 1);
190 cylno = ufs_cbtocylno(i); 203
191 fs16_add(sb, &ubh_cg_blks(ucpi, cylno, ufs_cbtorpos(i)), 1); 204 if (uspi->fs_magic != UFS2_MAGIC) {
192 fs32_add(sb, &ubh_cg_blktot(ucpi, cylno), 1); 205 unsigned cylno = ufs_cbtocylno(i);
206
207 fs16_add(sb, &ubh_cg_blks(ucpi, cylno,
208 ufs_cbtorpos(i)), 1);
209 fs32_add(sb, &ubh_cg_blktot(ucpi, cylno), 1);
210 }
193 } 211 }
194 212
195 ubh_mark_buffer_dirty (USPI_UBH(uspi)); 213 ubh_mark_buffer_dirty (USPI_UBH(uspi));
@@ -308,15 +326,19 @@ static void ufs_clear_frags(struct inode *inode, sector_t beg, unsigned int n,
308 } 326 }
309} 327}
310 328
311unsigned ufs_new_fragments(struct inode * inode, __fs32 * p, unsigned fragment, 329u64 ufs_new_fragments(struct inode *inode, void *p, u64 fragment,
312 unsigned goal, unsigned count, int * err, struct page *locked_page) 330 u64 goal, unsigned count, int *err,
331 struct page *locked_page)
313{ 332{
314 struct super_block * sb; 333 struct super_block * sb;
315 struct ufs_sb_private_info * uspi; 334 struct ufs_sb_private_info * uspi;
316 struct ufs_super_block_first * usb1; 335 struct ufs_super_block_first * usb1;
317 unsigned cgno, oldcount, newcount, tmp, request, result; 336 unsigned cgno, oldcount, newcount;
337 u64 tmp, request, result;
318 338
319 UFSD("ENTER, ino %lu, fragment %u, goal %u, count %u\n", inode->i_ino, fragment, goal, count); 339 UFSD("ENTER, ino %lu, fragment %llu, goal %llu, count %u\n",
340 inode->i_ino, (unsigned long long)fragment,
341 (unsigned long long)goal, count);
320 342
321 sb = inode->i_sb; 343 sb = inode->i_sb;
322 uspi = UFS_SB(sb)->s_uspi; 344 uspi = UFS_SB(sb)->s_uspi;
@@ -324,11 +346,12 @@ unsigned ufs_new_fragments(struct inode * inode, __fs32 * p, unsigned fragment,
324 *err = -ENOSPC; 346 *err = -ENOSPC;
325 347
326 lock_super (sb); 348 lock_super (sb);
327 349 tmp = ufs_data_ptr_to_cpu(sb, p);
328 tmp = fs32_to_cpu(sb, *p); 350
329 if (count + ufs_fragnum(fragment) > uspi->s_fpb) { 351 if (count + ufs_fragnum(fragment) > uspi->s_fpb) {
330 ufs_warning (sb, "ufs_new_fragments", "internal warning" 352 ufs_warning(sb, "ufs_new_fragments", "internal warning"
331 " fragment %u, count %u", fragment, count); 353 " fragment %llu, count %u",
354 (unsigned long long)fragment, count);
332 count = uspi->s_fpb - ufs_fragnum(fragment); 355 count = uspi->s_fpb - ufs_fragnum(fragment);
333 } 356 }
334 oldcount = ufs_fragnum (fragment); 357 oldcount = ufs_fragnum (fragment);
@@ -339,10 +362,12 @@ unsigned ufs_new_fragments(struct inode * inode, __fs32 * p, unsigned fragment,
339 */ 362 */
340 if (oldcount) { 363 if (oldcount) {
341 if (!tmp) { 364 if (!tmp) {
342 ufs_error (sb, "ufs_new_fragments", "internal error, " 365 ufs_error(sb, "ufs_new_fragments", "internal error, "
343 "fragment %u, tmp %u\n", fragment, tmp); 366 "fragment %llu, tmp %llu\n",
344 unlock_super (sb); 367 (unsigned long long)fragment,
345 return (unsigned)-1; 368 (unsigned long long)tmp);
369 unlock_super(sb);
370 return INVBLOCK;
346 } 371 }
347 if (fragment < UFS_I(inode)->i_lastfrag) { 372 if (fragment < UFS_I(inode)->i_lastfrag) {
348 UFSD("EXIT (ALREADY ALLOCATED)\n"); 373 UFSD("EXIT (ALREADY ALLOCATED)\n");
@@ -372,7 +397,7 @@ unsigned ufs_new_fragments(struct inode * inode, __fs32 * p, unsigned fragment,
372 if (goal == 0) 397 if (goal == 0)
373 cgno = ufs_inotocg (inode->i_ino); 398 cgno = ufs_inotocg (inode->i_ino);
374 else 399 else
375 cgno = ufs_dtog (goal); 400 cgno = ufs_dtog(uspi, goal);
376 401
377 /* 402 /*
378 * allocate new fragment 403 * allocate new fragment
@@ -380,14 +405,16 @@ unsigned ufs_new_fragments(struct inode * inode, __fs32 * p, unsigned fragment,
380 if (oldcount == 0) { 405 if (oldcount == 0) {
381 result = ufs_alloc_fragments (inode, cgno, goal, count, err); 406 result = ufs_alloc_fragments (inode, cgno, goal, count, err);
382 if (result) { 407 if (result) {
383 *p = cpu_to_fs32(sb, result); 408 ufs_cpu_to_data_ptr(sb, p, result);
384 *err = 0; 409 *err = 0;
385 UFS_I(inode)->i_lastfrag = max_t(u32, UFS_I(inode)->i_lastfrag, fragment + count); 410 UFS_I(inode)->i_lastfrag =
386 ufs_clear_frags(inode, result + oldcount, newcount - oldcount, 411 max_t(u32, UFS_I(inode)->i_lastfrag,
387 locked_page != NULL); 412 fragment + count);
413 ufs_clear_frags(inode, result + oldcount,
414 newcount - oldcount, locked_page != NULL);
388 } 415 }
389 unlock_super(sb); 416 unlock_super(sb);
390 UFSD("EXIT, result %u\n", result); 417 UFSD("EXIT, result %llu\n", (unsigned long long)result);
391 return result; 418 return result;
392 } 419 }
393 420
@@ -401,7 +428,7 @@ unsigned ufs_new_fragments(struct inode * inode, __fs32 * p, unsigned fragment,
401 ufs_clear_frags(inode, result + oldcount, newcount - oldcount, 428 ufs_clear_frags(inode, result + oldcount, newcount - oldcount,
402 locked_page != NULL); 429 locked_page != NULL);
403 unlock_super(sb); 430 unlock_super(sb);
404 UFSD("EXIT, result %u\n", result); 431 UFSD("EXIT, result %llu\n", (unsigned long long)result);
405 return result; 432 return result;
406 } 433 }
407 434
@@ -433,15 +460,14 @@ unsigned ufs_new_fragments(struct inode * inode, __fs32 * p, unsigned fragment,
433 locked_page != NULL); 460 locked_page != NULL);
434 ufs_change_blocknr(inode, fragment - oldcount, oldcount, tmp, 461 ufs_change_blocknr(inode, fragment - oldcount, oldcount, tmp,
435 result, locked_page); 462 result, locked_page);
436 463 ufs_cpu_to_data_ptr(sb, p, result);
437 *p = cpu_to_fs32(sb, result);
438 *err = 0; 464 *err = 0;
439 UFS_I(inode)->i_lastfrag = max_t(u32, UFS_I(inode)->i_lastfrag, fragment + count); 465 UFS_I(inode)->i_lastfrag = max_t(u32, UFS_I(inode)->i_lastfrag, fragment + count);
440 unlock_super(sb); 466 unlock_super(sb);
441 if (newcount < request) 467 if (newcount < request)
442 ufs_free_fragments (inode, result + newcount, request - newcount); 468 ufs_free_fragments (inode, result + newcount, request - newcount);
443 ufs_free_fragments (inode, tmp, oldcount); 469 ufs_free_fragments (inode, tmp, oldcount);
444 UFSD("EXIT, result %u\n", result); 470 UFSD("EXIT, result %llu\n", (unsigned long long)result);
445 return result; 471 return result;
446 } 472 }
447 473
@@ -450,9 +476,8 @@ unsigned ufs_new_fragments(struct inode * inode, __fs32 * p, unsigned fragment,
450 return 0; 476 return 0;
451} 477}
452 478
453static unsigned 479static u64 ufs_add_fragments(struct inode *inode, u64 fragment,
454ufs_add_fragments (struct inode * inode, unsigned fragment, 480 unsigned oldcount, unsigned newcount, int *err)
455 unsigned oldcount, unsigned newcount, int * err)
456{ 481{
457 struct super_block * sb; 482 struct super_block * sb;
458 struct ufs_sb_private_info * uspi; 483 struct ufs_sb_private_info * uspi;
@@ -461,14 +486,15 @@ ufs_add_fragments (struct inode * inode, unsigned fragment,
461 struct ufs_cylinder_group * ucg; 486 struct ufs_cylinder_group * ucg;
462 unsigned cgno, fragno, fragoff, count, fragsize, i; 487 unsigned cgno, fragno, fragoff, count, fragsize, i;
463 488
464 UFSD("ENTER, fragment %u, oldcount %u, newcount %u\n", fragment, oldcount, newcount); 489 UFSD("ENTER, fragment %llu, oldcount %u, newcount %u\n",
490 (unsigned long long)fragment, oldcount, newcount);
465 491
466 sb = inode->i_sb; 492 sb = inode->i_sb;
467 uspi = UFS_SB(sb)->s_uspi; 493 uspi = UFS_SB(sb)->s_uspi;
468 usb1 = ubh_get_usb_first (uspi); 494 usb1 = ubh_get_usb_first (uspi);
469 count = newcount - oldcount; 495 count = newcount - oldcount;
470 496
471 cgno = ufs_dtog(fragment); 497 cgno = ufs_dtog(uspi, fragment);
472 if (fs32_to_cpu(sb, UFS_SB(sb)->fs_cs(cgno).cs_nffree) < count) 498 if (fs32_to_cpu(sb, UFS_SB(sb)->fs_cs(cgno).cs_nffree) < count)
473 return 0; 499 return 0;
474 if ((ufs_fragnum (fragment) + newcount) > uspi->s_fpb) 500 if ((ufs_fragnum (fragment) + newcount) > uspi->s_fpb)
@@ -483,7 +509,7 @@ ufs_add_fragments (struct inode * inode, unsigned fragment,
483 return 0; 509 return 0;
484 } 510 }
485 511
486 fragno = ufs_dtogd (fragment); 512 fragno = ufs_dtogd(uspi, fragment);
487 fragoff = ufs_fragnum (fragno); 513 fragoff = ufs_fragnum (fragno);
488 for (i = oldcount; i < newcount; i++) 514 for (i = oldcount; i < newcount; i++)
489 if (ubh_isclr (UCPI_UBH(ucpi), ucpi->c_freeoff, fragno + i)) 515 if (ubh_isclr (UCPI_UBH(ucpi), ucpi->c_freeoff, fragno + i))
@@ -521,7 +547,7 @@ ufs_add_fragments (struct inode * inode, unsigned fragment,
521 } 547 }
522 sb->s_dirt = 1; 548 sb->s_dirt = 1;
523 549
524 UFSD("EXIT, fragment %u\n", fragment); 550 UFSD("EXIT, fragment %llu\n", (unsigned long long)fragment);
525 551
526 return fragment; 552 return fragment;
527} 553}
@@ -534,17 +560,19 @@ ufs_add_fragments (struct inode * inode, unsigned fragment,
534 if (fs32_to_cpu(sb, ucg->cg_frsum[k])) \ 560 if (fs32_to_cpu(sb, ucg->cg_frsum[k])) \
535 goto cg_found; 561 goto cg_found;
536 562
537static unsigned ufs_alloc_fragments (struct inode * inode, unsigned cgno, 563static u64 ufs_alloc_fragments(struct inode *inode, unsigned cgno,
538 unsigned goal, unsigned count, int * err) 564 u64 goal, unsigned count, int *err)
539{ 565{
540 struct super_block * sb; 566 struct super_block * sb;
541 struct ufs_sb_private_info * uspi; 567 struct ufs_sb_private_info * uspi;
542 struct ufs_super_block_first * usb1; 568 struct ufs_super_block_first * usb1;
543 struct ufs_cg_private_info * ucpi; 569 struct ufs_cg_private_info * ucpi;
544 struct ufs_cylinder_group * ucg; 570 struct ufs_cylinder_group * ucg;
545 unsigned oldcg, i, j, k, result, allocsize; 571 unsigned oldcg, i, j, k, allocsize;
572 u64 result;
546 573
547 UFSD("ENTER, ino %lu, cgno %u, goal %u, count %u\n", inode->i_ino, cgno, goal, count); 574 UFSD("ENTER, ino %lu, cgno %u, goal %llu, count %u\n",
575 inode->i_ino, cgno, (unsigned long long)goal, count);
548 576
549 sb = inode->i_sb; 577 sb = inode->i_sb;
550 uspi = UFS_SB(sb)->s_uspi; 578 uspi = UFS_SB(sb)->s_uspi;
@@ -593,7 +621,7 @@ cg_found:
593 621
594 if (count == uspi->s_fpb) { 622 if (count == uspi->s_fpb) {
595 result = ufs_alloccg_block (inode, ucpi, goal, err); 623 result = ufs_alloccg_block (inode, ucpi, goal, err);
596 if (result == (unsigned)-1) 624 if (result == INVBLOCK)
597 return 0; 625 return 0;
598 goto succed; 626 goto succed;
599 } 627 }
@@ -604,9 +632,9 @@ cg_found:
604 632
605 if (allocsize == uspi->s_fpb) { 633 if (allocsize == uspi->s_fpb) {
606 result = ufs_alloccg_block (inode, ucpi, goal, err); 634 result = ufs_alloccg_block (inode, ucpi, goal, err);
607 if (result == (unsigned)-1) 635 if (result == INVBLOCK)
608 return 0; 636 return 0;
609 goal = ufs_dtogd (result); 637 goal = ufs_dtogd(uspi, result);
610 for (i = count; i < uspi->s_fpb; i++) 638 for (i = count; i < uspi->s_fpb; i++)
611 ubh_setbit (UCPI_UBH(ucpi), ucpi->c_freeoff, goal + i); 639 ubh_setbit (UCPI_UBH(ucpi), ucpi->c_freeoff, goal + i);
612 i = uspi->s_fpb - count; 640 i = uspi->s_fpb - count;
@@ -620,7 +648,7 @@ cg_found:
620 } 648 }
621 649
622 result = ufs_bitmap_search (sb, ucpi, goal, allocsize); 650 result = ufs_bitmap_search (sb, ucpi, goal, allocsize);
623 if (result == (unsigned)-1) 651 if (result == INVBLOCK)
624 return 0; 652 return 0;
625 if(DQUOT_ALLOC_BLOCK(inode, count)) { 653 if(DQUOT_ALLOC_BLOCK(inode, count)) {
626 *err = -EDQUOT; 654 *err = -EDQUOT;
@@ -647,20 +675,21 @@ succed:
647 sb->s_dirt = 1; 675 sb->s_dirt = 1;
648 676
649 result += cgno * uspi->s_fpg; 677 result += cgno * uspi->s_fpg;
650 UFSD("EXIT3, result %u\n", result); 678 UFSD("EXIT3, result %llu\n", (unsigned long long)result);
651 return result; 679 return result;
652} 680}
653 681
654static unsigned ufs_alloccg_block (struct inode * inode, 682static u64 ufs_alloccg_block(struct inode *inode,
655 struct ufs_cg_private_info * ucpi, unsigned goal, int * err) 683 struct ufs_cg_private_info *ucpi,
684 u64 goal, int *err)
656{ 685{
657 struct super_block * sb; 686 struct super_block * sb;
658 struct ufs_sb_private_info * uspi; 687 struct ufs_sb_private_info * uspi;
659 struct ufs_super_block_first * usb1; 688 struct ufs_super_block_first * usb1;
660 struct ufs_cylinder_group * ucg; 689 struct ufs_cylinder_group * ucg;
661 unsigned result, cylno, blkno; 690 u64 result, blkno;
662 691
663 UFSD("ENTER, goal %u\n", goal); 692 UFSD("ENTER, goal %llu\n", (unsigned long long)goal);
664 693
665 sb = inode->i_sb; 694 sb = inode->i_sb;
666 uspi = UFS_SB(sb)->s_uspi; 695 uspi = UFS_SB(sb)->s_uspi;
@@ -672,7 +701,7 @@ static unsigned ufs_alloccg_block (struct inode * inode,
672 goto norot; 701 goto norot;
673 } 702 }
674 goal = ufs_blknum (goal); 703 goal = ufs_blknum (goal);
675 goal = ufs_dtogd (goal); 704 goal = ufs_dtogd(uspi, goal);
676 705
677 /* 706 /*
678 * If the requested block is available, use it. 707 * If the requested block is available, use it.
@@ -684,8 +713,8 @@ static unsigned ufs_alloccg_block (struct inode * inode,
684 713
685norot: 714norot:
686 result = ufs_bitmap_search (sb, ucpi, goal, uspi->s_fpb); 715 result = ufs_bitmap_search (sb, ucpi, goal, uspi->s_fpb);
687 if (result == (unsigned)-1) 716 if (result == INVBLOCK)
688 return (unsigned)-1; 717 return INVBLOCK;
689 ucpi->c_rotor = result; 718 ucpi->c_rotor = result;
690gotit: 719gotit:
691 blkno = ufs_fragstoblks(result); 720 blkno = ufs_fragstoblks(result);
@@ -694,17 +723,22 @@ gotit:
694 ufs_clusteracct (sb, ucpi, blkno, -1); 723 ufs_clusteracct (sb, ucpi, blkno, -1);
695 if(DQUOT_ALLOC_BLOCK(inode, uspi->s_fpb)) { 724 if(DQUOT_ALLOC_BLOCK(inode, uspi->s_fpb)) {
696 *err = -EDQUOT; 725 *err = -EDQUOT;
697 return (unsigned)-1; 726 return INVBLOCK;
698 } 727 }
699 728
700 fs32_sub(sb, &ucg->cg_cs.cs_nbfree, 1); 729 fs32_sub(sb, &ucg->cg_cs.cs_nbfree, 1);
701 uspi->cs_total.cs_nbfree--; 730 uspi->cs_total.cs_nbfree--;
702 fs32_sub(sb, &UFS_SB(sb)->fs_cs(ucpi->c_cgx).cs_nbfree, 1); 731 fs32_sub(sb, &UFS_SB(sb)->fs_cs(ucpi->c_cgx).cs_nbfree, 1);
703 cylno = ufs_cbtocylno(result); 732
704 fs16_sub(sb, &ubh_cg_blks(ucpi, cylno, ufs_cbtorpos(result)), 1); 733 if (uspi->fs_magic != UFS2_MAGIC) {
705 fs32_sub(sb, &ubh_cg_blktot(ucpi, cylno), 1); 734 unsigned cylno = ufs_cbtocylno((unsigned)result);
735
736 fs16_sub(sb, &ubh_cg_blks(ucpi, cylno,
737 ufs_cbtorpos((unsigned)result)), 1);
738 fs32_sub(sb, &ubh_cg_blktot(ucpi, cylno), 1);
739 }
706 740
707 UFSD("EXIT, result %u\n", result); 741 UFSD("EXIT, result %llu\n", (unsigned long long)result);
708 742
709 return result; 743 return result;
710} 744}
@@ -744,9 +778,9 @@ static unsigned ubh_scanc(struct ufs_sb_private_info *uspi,
744 * @goal: near which block we want find new one 778 * @goal: near which block we want find new one
745 * @count: specified size 779 * @count: specified size
746 */ 780 */
747static unsigned ufs_bitmap_search(struct super_block *sb, 781static u64 ufs_bitmap_search(struct super_block *sb,
748 struct ufs_cg_private_info *ucpi, 782 struct ufs_cg_private_info *ucpi,
749 unsigned goal, unsigned count) 783 u64 goal, unsigned count)
750{ 784{
751 /* 785 /*
752 * Bit patterns for identifying fragments in the block map 786 * Bit patterns for identifying fragments in the block map
@@ -761,16 +795,18 @@ static unsigned ufs_bitmap_search(struct super_block *sb,
761 struct ufs_sb_private_info *uspi = UFS_SB(sb)->s_uspi; 795 struct ufs_sb_private_info *uspi = UFS_SB(sb)->s_uspi;
762 struct ufs_super_block_first *usb1; 796 struct ufs_super_block_first *usb1;
763 struct ufs_cylinder_group *ucg; 797 struct ufs_cylinder_group *ucg;
764 unsigned start, length, loc, result; 798 unsigned start, length, loc;
765 unsigned pos, want, blockmap, mask, end; 799 unsigned pos, want, blockmap, mask, end;
800 u64 result;
766 801
767 UFSD("ENTER, cg %u, goal %u, count %u\n", ucpi->c_cgx, goal, count); 802 UFSD("ENTER, cg %u, goal %llu, count %u\n", ucpi->c_cgx,
803 (unsigned long long)goal, count);
768 804
769 usb1 = ubh_get_usb_first (uspi); 805 usb1 = ubh_get_usb_first (uspi);
770 ucg = ubh_get_ucg(UCPI_UBH(ucpi)); 806 ucg = ubh_get_ucg(UCPI_UBH(ucpi));
771 807
772 if (goal) 808 if (goal)
773 start = ufs_dtogd(goal) >> 3; 809 start = ufs_dtogd(uspi, goal) >> 3;
774 else 810 else
775 start = ucpi->c_frotor >> 3; 811 start = ucpi->c_frotor >> 3;
776 812
@@ -790,7 +826,7 @@ static unsigned ufs_bitmap_search(struct super_block *sb,
790 " length %u, count %u, freeoff %u\n", 826 " length %u, count %u, freeoff %u\n",
791 ucpi->c_cgx, start, length, count, 827 ucpi->c_cgx, start, length, count,
792 ucpi->c_freeoff); 828 ucpi->c_freeoff);
793 return (unsigned)-1; 829 return INVBLOCK;
794 } 830 }
795 start = 0; 831 start = 0;
796 } 832 }
@@ -808,7 +844,8 @@ static unsigned ufs_bitmap_search(struct super_block *sb,
808 want = want_arr[count]; 844 want = want_arr[count];
809 for (pos = 0; pos <= uspi->s_fpb - count; pos++) { 845 for (pos = 0; pos <= uspi->s_fpb - count; pos++) {
810 if ((blockmap & mask) == want) { 846 if ((blockmap & mask) == want) {
811 UFSD("EXIT, result %u\n", result); 847 UFSD("EXIT, result %llu\n",
848 (unsigned long long)result);
812 return result + pos; 849 return result + pos;
813 } 850 }
814 mask <<= 1; 851 mask <<= 1;
@@ -819,7 +856,7 @@ static unsigned ufs_bitmap_search(struct super_block *sb,
819 ufs_error(sb, "ufs_bitmap_search", "block not in map on cg %u\n", 856 ufs_error(sb, "ufs_bitmap_search", "block not in map on cg %u\n",
820 ucpi->c_cgx); 857 ucpi->c_cgx);
821 UFSD("EXIT (FAILED)\n"); 858 UFSD("EXIT (FAILED)\n");
822 return (unsigned)-1; 859 return INVBLOCK;
823} 860}
824 861
825static void ufs_clusteracct(struct super_block * sb, 862static void ufs_clusteracct(struct super_block * sb,