@@ -15,14 +15,14 @@ struct superblock {
1515 char padding [4064 ]; /* Padding to match block size */
1616};
1717
18- /* Returns ceil(a/b) */
19- static inline uint32_t idiv_ceil ( uint32_t a , uint32_t b )
20- {
21- uint32_t ret = a / b ;
22- if ( a % b )
23- return ret + 1 ;
24- return ret ;
25- }
18+ /**
19+ * DIV_ROUND_UP - round up a division
20+ * @n: dividend
21+ * @d: divisor
22+ *
23+ * Return the result of n / d, rounded up to the nearest integer.
24+ */
25+ #define DIV_ROUND_UP ( n , d ) (((n) + (d) -1) / (d))
2626
2727static struct superblock * write_superblock (int fd , struct stat * fstats )
2828{
@@ -35,9 +35,10 @@ static struct superblock *write_superblock(int fd, struct stat *fstats)
3535 uint32_t mod = nr_inodes % SIMPLEFS_INODES_PER_BLOCK ;
3636 if (mod )
3737 nr_inodes += SIMPLEFS_INODES_PER_BLOCK - mod ;
38- uint32_t nr_istore_blocks = idiv_ceil (nr_inodes , SIMPLEFS_INODES_PER_BLOCK );
39- uint32_t nr_ifree_blocks = idiv_ceil (nr_inodes , SIMPLEFS_BLOCK_SIZE * 8 );
40- uint32_t nr_bfree_blocks = idiv_ceil (nr_blocks , SIMPLEFS_BLOCK_SIZE * 8 );
38+ uint32_t nr_istore_blocks =
39+ DIV_ROUND_UP (nr_inodes , SIMPLEFS_INODES_PER_BLOCK );
40+ uint32_t nr_ifree_blocks = DIV_ROUND_UP (nr_inodes , SIMPLEFS_BLOCK_SIZE * 8 );
41+ uint32_t nr_bfree_blocks = DIV_ROUND_UP (nr_blocks , SIMPLEFS_BLOCK_SIZE * 8 );
4142 uint32_t nr_data_blocks =
4243 nr_blocks - nr_istore_blocks - nr_ifree_blocks - nr_bfree_blocks ;
4344
0 commit comments