jfs_extent.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663
  1. /*
  2. * Copyright (C) International Business Machines Corp., 2000-2004
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
  12. * the GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17. */
  18. #include <linux/fs.h>
  19. #include <linux/quotaops.h>
  20. #include "jfs_incore.h"
  21. #include "jfs_inode.h"
  22. #include "jfs_superblock.h"
  23. #include "jfs_dmap.h"
  24. #include "jfs_extent.h"
  25. #include "jfs_debug.h"
  26. /*
  27. * forward references
  28. */
  29. static int extBalloc(struct inode *, s64, s64 *, s64 *);
  30. #ifdef _NOTYET
  31. static int extBrealloc(struct inode *, s64, s64, s64 *, s64 *);
  32. #endif
  33. static s64 extRoundDown(s64 nb);
  34. #define DPD(a) (printk("(a): %d\n",(a)))
  35. #define DPC(a) (printk("(a): %c\n",(a)))
  36. #define DPL1(a) \
  37. { \
  38. if ((a) >> 32) \
  39. printk("(a): %x%08x ",(a)); \
  40. else \
  41. printk("(a): %x ",(a) << 32); \
  42. }
  43. #define DPL(a) \
  44. { \
  45. if ((a) >> 32) \
  46. printk("(a): %x%08x\n",(a)); \
  47. else \
  48. printk("(a): %x\n",(a) << 32); \
  49. }
  50. #define DPD1(a) (printk("(a): %d ",(a)))
  51. #define DPX(a) (printk("(a): %08x\n",(a)))
  52. #define DPX1(a) (printk("(a): %08x ",(a)))
  53. #define DPS(a) (printk("%s\n",(a)))
  54. #define DPE(a) (printk("\nENTERING: %s\n",(a)))
  55. #define DPE1(a) (printk("\nENTERING: %s",(a)))
  56. #define DPS1(a) (printk(" %s ",(a)))
  57. /*
  58. * NAME: extAlloc()
  59. *
  60. * FUNCTION: allocate an extent for a specified page range within a
  61. * file.
  62. *
  63. * PARAMETERS:
  64. * ip - the inode of the file.
  65. * xlen - requested extent length.
  66. * pno - the starting page number with the file.
  67. * xp - pointer to an xad. on entry, xad describes an
  68. * extent that is used as an allocation hint if the
  69. * xaddr of the xad is non-zero. on successful exit,
  70. * the xad describes the newly allocated extent.
  71. * abnr - bool indicating whether the newly allocated extent
  72. * should be marked as allocated but not recorded.
  73. *
  74. * RETURN VALUES:
  75. * 0 - success
  76. * -EIO - i/o error.
  77. * -ENOSPC - insufficient disk resources.
  78. */
  79. int
  80. extAlloc(struct inode *ip, s64 xlen, s64 pno, xad_t * xp, bool abnr)
  81. {
  82. struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb);
  83. s64 nxlen, nxaddr, xoff, hint, xaddr = 0;
  84. int rc;
  85. int xflag;
  86. /* This blocks if we are low on resources */
  87. txBeginAnon(ip->i_sb);
  88. /* Avoid race with jfs_commit_inode() */
  89. mutex_lock(&JFS_IP(ip)->commit_mutex);
  90. /* validate extent length */
  91. if (xlen > MAXXLEN)
  92. xlen = MAXXLEN;
  93. /* get the page's starting extent offset */
  94. xoff = pno << sbi->l2nbperpage;
  95. /* check if an allocation hint was provided */
  96. if ((hint = addressXAD(xp))) {
  97. /* get the size of the extent described by the hint */
  98. nxlen = lengthXAD(xp);
  99. /* check if the hint is for the portion of the file
  100. * immediately previous to the current allocation
  101. * request and if hint extent has the same abnr
  102. * value as the current request. if so, we can
  103. * extend the hint extent to include the current
  104. * extent if we can allocate the blocks immediately
  105. * following the hint extent.
  106. */
  107. if (offsetXAD(xp) + nxlen == xoff &&
  108. abnr == ((xp->flag & XAD_NOTRECORDED) ? true : false))
  109. xaddr = hint + nxlen;
  110. /* adjust the hint to the last block of the extent */
  111. hint += (nxlen - 1);
  112. }
  113. /* allocate the disk blocks for the extent. initially, extBalloc()
  114. * will try to allocate disk blocks for the requested size (xlen).
  115. * if this fails (xlen contiguous free blocks not avaliable), it'll
  116. * try to allocate a smaller number of blocks (producing a smaller
  117. * extent), with this smaller number of blocks consisting of the
  118. * requested number of blocks rounded down to the next smaller
  119. * power of 2 number (i.e. 16 -> 8). it'll continue to round down
  120. * and retry the allocation until the number of blocks to allocate
  121. * is smaller than the number of blocks per page.
  122. */
  123. nxlen = xlen;
  124. if ((rc = extBalloc(ip, hint ? hint : INOHINT(ip), &nxlen, &nxaddr))) {
  125. mutex_unlock(&JFS_IP(ip)->commit_mutex);
  126. return (rc);
  127. }
  128. /* Allocate blocks to quota. */
  129. if (DQUOT_ALLOC_BLOCK(ip, nxlen)) {
  130. dbFree(ip, nxaddr, (s64) nxlen);
  131. mutex_unlock(&JFS_IP(ip)->commit_mutex);
  132. return -EDQUOT;
  133. }
  134. /* determine the value of the extent flag */
  135. xflag = abnr ? XAD_NOTRECORDED : 0;
  136. /* if we can extend the hint extent to cover the current request,
  137. * extend it. otherwise, insert a new extent to
  138. * cover the current request.
  139. */
  140. if (xaddr && xaddr == nxaddr)
  141. rc = xtExtend(0, ip, xoff, (int) nxlen, 0);
  142. else
  143. rc = xtInsert(0, ip, xflag, xoff, (int) nxlen, &nxaddr, 0);
  144. /* if the extend or insert failed,
  145. * free the newly allocated blocks and return the error.
  146. */
  147. if (rc) {
  148. dbFree(ip, nxaddr, nxlen);
  149. DQUOT_FREE_BLOCK(ip, nxlen);
  150. mutex_unlock(&JFS_IP(ip)->commit_mutex);
  151. return (rc);
  152. }
  153. /* set the results of the extent allocation */
  154. XADaddress(xp, nxaddr);
  155. XADlength(xp, nxlen);
  156. XADoffset(xp, xoff);
  157. xp->flag = xflag;
  158. mark_inode_dirty(ip);
  159. mutex_unlock(&JFS_IP(ip)->commit_mutex);
  160. /*
  161. * COMMIT_SyncList flags an anonymous tlock on page that is on
  162. * sync list.
  163. * We need to commit the inode to get the page written disk.
  164. */
  165. if (test_and_clear_cflag(COMMIT_Synclist,ip))
  166. jfs_commit_inode(ip, 0);
  167. return (0);
  168. }
  169. #ifdef _NOTYET
  170. /*
  171. * NAME: extRealloc()
  172. *
  173. * FUNCTION: extend the allocation of a file extent containing a
  174. * partial back last page.
  175. *
  176. * PARAMETERS:
  177. * ip - the inode of the file.
  178. * cp - cbuf for the partial backed last page.
  179. * xlen - request size of the resulting extent.
  180. * xp - pointer to an xad. on successful exit, the xad
  181. * describes the newly allocated extent.
  182. * abnr - bool indicating whether the newly allocated extent
  183. * should be marked as allocated but not recorded.
  184. *
  185. * RETURN VALUES:
  186. * 0 - success
  187. * -EIO - i/o error.
  188. * -ENOSPC - insufficient disk resources.
  189. */
  190. int extRealloc(struct inode *ip, s64 nxlen, xad_t * xp, bool abnr)
  191. {
  192. struct super_block *sb = ip->i_sb;
  193. s64 xaddr, xlen, nxaddr, delta, xoff;
  194. s64 ntail, nextend, ninsert;
  195. int rc, nbperpage = JFS_SBI(sb)->nbperpage;
  196. int xflag;
  197. /* This blocks if we are low on resources */
  198. txBeginAnon(ip->i_sb);
  199. mutex_lock(&JFS_IP(ip)->commit_mutex);
  200. /* validate extent length */
  201. if (nxlen > MAXXLEN)
  202. nxlen = MAXXLEN;
  203. /* get the extend (partial) page's disk block address and
  204. * number of blocks.
  205. */
  206. xaddr = addressXAD(xp);
  207. xlen = lengthXAD(xp);
  208. xoff = offsetXAD(xp);
  209. /* if the extend page is abnr and if the request is for
  210. * the extent to be allocated and recorded,
  211. * make the page allocated and recorded.
  212. */
  213. if ((xp->flag & XAD_NOTRECORDED) && !abnr) {
  214. xp->flag = 0;
  215. if ((rc = xtUpdate(0, ip, xp)))
  216. goto exit;
  217. }
  218. /* try to allocated the request number of blocks for the
  219. * extent. dbRealloc() first tries to satisfy the request
  220. * by extending the allocation in place. otherwise, it will
  221. * try to allocate a new set of blocks large enough for the
  222. * request. in satisfying a request, dbReAlloc() may allocate
  223. * less than what was request but will always allocate enough
  224. * space as to satisfy the extend page.
  225. */
  226. if ((rc = extBrealloc(ip, xaddr, xlen, &nxlen, &nxaddr)))
  227. goto exit;
  228. /* Allocat blocks to quota. */
  229. if (DQUOT_ALLOC_BLOCK(ip, nxlen)) {
  230. dbFree(ip, nxaddr, (s64) nxlen);
  231. mutex_unlock(&JFS_IP(ip)->commit_mutex);
  232. return -EDQUOT;
  233. }
  234. delta = nxlen - xlen;
  235. /* check if the extend page is not abnr but the request is abnr
  236. * and the allocated disk space is for more than one page. if this
  237. * is the case, there is a miss match of abnr between the extend page
  238. * and the one or more pages following the extend page. as a result,
  239. * two extents will have to be manipulated. the first will be that
  240. * of the extent of the extend page and will be manipulated thru
  241. * an xtExtend() or an xtTailgate(), depending upon whether the
  242. * disk allocation occurred as an inplace extension. the second
  243. * extent will be manipulated (created) through an xtInsert() and
  244. * will be for the pages following the extend page.
  245. */
  246. if (abnr && (!(xp->flag & XAD_NOTRECORDED)) && (nxlen > nbperpage)) {
  247. ntail = nbperpage;
  248. nextend = ntail - xlen;
  249. ninsert = nxlen - nbperpage;
  250. xflag = XAD_NOTRECORDED;
  251. } else {
  252. ntail = nxlen;
  253. nextend = delta;
  254. ninsert = 0;
  255. xflag = xp->flag;
  256. }
  257. /* if we were able to extend the disk allocation in place,
  258. * extend the extent. otherwise, move the extent to a
  259. * new disk location.
  260. */
  261. if (xaddr == nxaddr) {
  262. /* extend the extent */
  263. if ((rc = xtExtend(0, ip, xoff + xlen, (int) nextend, 0))) {
  264. dbFree(ip, xaddr + xlen, delta);
  265. DQUOT_FREE_BLOCK(ip, nxlen);
  266. goto exit;
  267. }
  268. } else {
  269. /*
  270. * move the extent to a new location:
  271. *
  272. * xtTailgate() accounts for relocated tail extent;
  273. */
  274. if ((rc = xtTailgate(0, ip, xoff, (int) ntail, nxaddr, 0))) {
  275. dbFree(ip, nxaddr, nxlen);
  276. DQUOT_FREE_BLOCK(ip, nxlen);
  277. goto exit;
  278. }
  279. }
  280. /* check if we need to also insert a new extent */
  281. if (ninsert) {
  282. /* perform the insert. if it fails, free the blocks
  283. * to be inserted and make it appear that we only did
  284. * the xtExtend() or xtTailgate() above.
  285. */
  286. xaddr = nxaddr + ntail;
  287. if (xtInsert (0, ip, xflag, xoff + ntail, (int) ninsert,
  288. &xaddr, 0)) {
  289. dbFree(ip, xaddr, (s64) ninsert);
  290. delta = nextend;
  291. nxlen = ntail;
  292. xflag = 0;
  293. }
  294. }
  295. /* set the return results */
  296. XADaddress(xp, nxaddr);
  297. XADlength(xp, nxlen);
  298. XADoffset(xp, xoff);
  299. xp->flag = xflag;
  300. mark_inode_dirty(ip);
  301. exit:
  302. mutex_unlock(&JFS_IP(ip)->commit_mutex);
  303. return (rc);
  304. }
  305. #endif /* _NOTYET */
  306. /*
  307. * NAME: extHint()
  308. *
  309. * FUNCTION: produce an extent allocation hint for a file offset.
  310. *
  311. * PARAMETERS:
  312. * ip - the inode of the file.
  313. * offset - file offset for which the hint is needed.
  314. * xp - pointer to the xad that is to be filled in with
  315. * the hint.
  316. *
  317. * RETURN VALUES:
  318. * 0 - success
  319. * -EIO - i/o error.
  320. */
  321. int extHint(struct inode *ip, s64 offset, xad_t * xp)
  322. {
  323. struct super_block *sb = ip->i_sb;
  324. struct xadlist xadl;
  325. struct lxdlist lxdl;
  326. lxd_t lxd;
  327. s64 prev;
  328. int rc, nbperpage = JFS_SBI(sb)->nbperpage;
  329. /* init the hint as "no hint provided" */
  330. XADaddress(xp, 0);
  331. /* determine the starting extent offset of the page previous
  332. * to the page containing the offset.
  333. */
  334. prev = ((offset & ~POFFSET) >> JFS_SBI(sb)->l2bsize) - nbperpage;
  335. /* if the offsets in the first page of the file,
  336. * no hint provided.
  337. */
  338. if (prev < 0)
  339. return (0);
  340. /* prepare to lookup the previous page's extent info */
  341. lxdl.maxnlxd = 1;
  342. lxdl.nlxd = 1;
  343. lxdl.lxd = &lxd;
  344. LXDoffset(&lxd, prev)
  345. LXDlength(&lxd, nbperpage);
  346. xadl.maxnxad = 1;
  347. xadl.nxad = 0;
  348. xadl.xad = xp;
  349. /* perform the lookup */
  350. if ((rc = xtLookupList(ip, &lxdl, &xadl, 0)))
  351. return (rc);
  352. /* check if not extent exists for the previous page.
  353. * this is possible for sparse files.
  354. */
  355. if (xadl.nxad == 0) {
  356. // assert(ISSPARSE(ip));
  357. return (0);
  358. }
  359. /* only preserve the abnr flag within the xad flags
  360. * of the returned hint.
  361. */
  362. xp->flag &= XAD_NOTRECORDED;
  363. if(xadl.nxad != 1 || lengthXAD(xp) != nbperpage) {
  364. jfs_error(ip->i_sb, "extHint: corrupt xtree");
  365. return -EIO;
  366. }
  367. return (0);
  368. }
  369. /*
  370. * NAME: extRecord()
  371. *
  372. * FUNCTION: change a page with a file from not recorded to recorded.
  373. *
  374. * PARAMETERS:
  375. * ip - inode of the file.
  376. * cp - cbuf of the file page.
  377. *
  378. * RETURN VALUES:
  379. * 0 - success
  380. * -EIO - i/o error.
  381. * -ENOSPC - insufficient disk resources.
  382. */
  383. int extRecord(struct inode *ip, xad_t * xp)
  384. {
  385. int rc;
  386. txBeginAnon(ip->i_sb);
  387. mutex_lock(&JFS_IP(ip)->commit_mutex);
  388. /* update the extent */
  389. rc = xtUpdate(0, ip, xp);
  390. mutex_unlock(&JFS_IP(ip)->commit_mutex);
  391. return rc;
  392. }
  393. #ifdef _NOTYET
  394. /*
  395. * NAME: extFill()
  396. *
  397. * FUNCTION: allocate disk space for a file page that represents
  398. * a file hole.
  399. *
  400. * PARAMETERS:
  401. * ip - the inode of the file.
  402. * cp - cbuf of the file page represent the hole.
  403. *
  404. * RETURN VALUES:
  405. * 0 - success
  406. * -EIO - i/o error.
  407. * -ENOSPC - insufficient disk resources.
  408. */
  409. int extFill(struct inode *ip, xad_t * xp)
  410. {
  411. int rc, nbperpage = JFS_SBI(ip->i_sb)->nbperpage;
  412. s64 blkno = offsetXAD(xp) >> ip->i_blkbits;
  413. // assert(ISSPARSE(ip));
  414. /* initialize the extent allocation hint */
  415. XADaddress(xp, 0);
  416. /* allocate an extent to fill the hole */
  417. if ((rc = extAlloc(ip, nbperpage, blkno, xp, false)))
  418. return (rc);
  419. assert(lengthPXD(xp) == nbperpage);
  420. return (0);
  421. }
  422. #endif /* _NOTYET */
  423. /*
  424. * NAME: extBalloc()
  425. *
  426. * FUNCTION: allocate disk blocks to form an extent.
  427. *
  428. * initially, we will try to allocate disk blocks for the
  429. * requested size (nblocks). if this fails (nblocks
  430. * contiguous free blocks not avaliable), we'll try to allocate
  431. * a smaller number of blocks (producing a smaller extent), with
  432. * this smaller number of blocks consisting of the requested
  433. * number of blocks rounded down to the next smaller power of 2
  434. * number (i.e. 16 -> 8). we'll continue to round down and
  435. * retry the allocation until the number of blocks to allocate
  436. * is smaller than the number of blocks per page.
  437. *
  438. * PARAMETERS:
  439. * ip - the inode of the file.
  440. * hint - disk block number to be used as an allocation hint.
  441. * *nblocks - pointer to an s64 value. on entry, this value specifies
  442. * the desired number of block to be allocated. on successful
  443. * exit, this value is set to the number of blocks actually
  444. * allocated.
  445. * blkno - pointer to a block address that is filled in on successful
  446. * return with the starting block number of the newly
  447. * allocated block range.
  448. *
  449. * RETURN VALUES:
  450. * 0 - success
  451. * -EIO - i/o error.
  452. * -ENOSPC - insufficient disk resources.
  453. */
  454. static int
  455. extBalloc(struct inode *ip, s64 hint, s64 * nblocks, s64 * blkno)
  456. {
  457. struct jfs_inode_info *ji = JFS_IP(ip);
  458. struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb);
  459. s64 nb, nblks, daddr, max;
  460. int rc, nbperpage = sbi->nbperpage;
  461. struct bmap *bmp = sbi->bmap;
  462. int ag;
  463. /* get the number of blocks to initially attempt to allocate.
  464. * we'll first try the number of blocks requested unless this
  465. * number is greater than the maximum number of contiguous free
  466. * blocks in the map. in that case, we'll start off with the
  467. * maximum free.
  468. */
  469. max = (s64) 1 << bmp->db_maxfreebud;
  470. if (*nblocks >= max && *nblocks > nbperpage)
  471. nb = nblks = (max > nbperpage) ? max : nbperpage;
  472. else
  473. nb = nblks = *nblocks;
  474. /* try to allocate blocks */
  475. while ((rc = dbAlloc(ip, hint, nb, &daddr)) != 0) {
  476. /* if something other than an out of space error,
  477. * stop and return this error.
  478. */
  479. if (rc != -ENOSPC)
  480. return (rc);
  481. /* decrease the allocation request size */
  482. nb = min(nblks, extRoundDown(nb));
  483. /* give up if we cannot cover a page */
  484. if (nb < nbperpage)
  485. return (rc);
  486. }
  487. *nblocks = nb;
  488. *blkno = daddr;
  489. if (S_ISREG(ip->i_mode) && (ji->fileset == FILESYSTEM_I)) {
  490. ag = BLKTOAG(daddr, sbi);
  491. spin_lock_irq(&ji->ag_lock);
  492. if (ji->active_ag == -1) {
  493. atomic_inc(&bmp->db_active[ag]);
  494. ji->active_ag = ag;
  495. } else if (ji->active_ag != ag) {
  496. atomic_dec(&bmp->db_active[ji->active_ag]);
  497. atomic_inc(&bmp->db_active[ag]);
  498. ji->active_ag = ag;
  499. }
  500. spin_unlock_irq(&ji->ag_lock);
  501. }
  502. return (0);
  503. }
  504. #ifdef _NOTYET
  505. /*
  506. * NAME: extBrealloc()
  507. *
  508. * FUNCTION: attempt to extend an extent's allocation.
  509. *
  510. * Initially, we will try to extend the extent's allocation
  511. * in place. If this fails, we'll try to move the extent
  512. * to a new set of blocks. If moving the extent, we initially
  513. * will try to allocate disk blocks for the requested size
  514. * (newnblks). if this fails (new contiguous free blocks not
  515. * avaliable), we'll try to allocate a smaller number of
  516. * blocks (producing a smaller extent), with this smaller
  517. * number of blocks consisting of the requested number of
  518. * blocks rounded down to the next smaller power of 2
  519. * number (i.e. 16 -> 8). We'll continue to round down and
  520. * retry the allocation until the number of blocks to allocate
  521. * is smaller than the number of blocks per page.
  522. *
  523. * PARAMETERS:
  524. * ip - the inode of the file.
  525. * blkno - starting block number of the extents current allocation.
  526. * nblks - number of blocks within the extents current allocation.
  527. * newnblks - pointer to a s64 value. on entry, this value is the
  528. * the new desired extent size (number of blocks). on
  529. * successful exit, this value is set to the extent's actual
  530. * new size (new number of blocks).
  531. * newblkno - the starting block number of the extents new allocation.
  532. *
  533. * RETURN VALUES:
  534. * 0 - success
  535. * -EIO - i/o error.
  536. * -ENOSPC - insufficient disk resources.
  537. */
  538. static int
  539. extBrealloc(struct inode *ip,
  540. s64 blkno, s64 nblks, s64 * newnblks, s64 * newblkno)
  541. {
  542. int rc;
  543. /* try to extend in place */
  544. if ((rc = dbExtend(ip, blkno, nblks, *newnblks - nblks)) == 0) {
  545. *newblkno = blkno;
  546. return (0);
  547. } else {
  548. if (rc != -ENOSPC)
  549. return (rc);
  550. }
  551. /* in place extension not possible.
  552. * try to move the extent to a new set of blocks.
  553. */
  554. return (extBalloc(ip, blkno, newnblks, newblkno));
  555. }
  556. #endif /* _NOTYET */
  557. /*
  558. * NAME: extRoundDown()
  559. *
  560. * FUNCTION: round down a specified number of blocks to the next
  561. * smallest power of 2 number.
  562. *
  563. * PARAMETERS:
  564. * nb - the inode of the file.
  565. *
  566. * RETURN VALUES:
  567. * next smallest power of 2 number.
  568. */
  569. static s64 extRoundDown(s64 nb)
  570. {
  571. int i;
  572. u64 m, k;
  573. for (i = 0, m = (u64) 1 << 63; i < 64; i++, m >>= 1) {
  574. if (m & nb)
  575. break;
  576. }
  577. i = 63 - i;
  578. k = (u64) 1 << i;
  579. k = ((k - 1) & nb) ? k : k >> 1;
  580. return (k);
  581. }