Replace div_up() and round_up() functions with macros.
This commit is contained in:
parent
df5aa263ec
commit
3361e941a6
@ -137,7 +137,7 @@ size_t calc_dir_size(Ecma119Image *t, Ecma119Node *dir, size_t *ce)
|
||||
* the size of the unused space after the last directory record
|
||||
* (ECMA-119, 6.8.1.3)
|
||||
*/
|
||||
len = div_up(len, BLOCK_SIZE) * BLOCK_SIZE;
|
||||
len = ROUND_UP(len, BLOCK_SIZE);
|
||||
|
||||
/* cache the len */
|
||||
dir->info.dir->len = len;
|
||||
@ -153,9 +153,9 @@ void calc_dir_pos(Ecma119Image *t, Ecma119Node *dir)
|
||||
t->ndirs++;
|
||||
dir->info.dir->block = t->curblock;
|
||||
len = calc_dir_size(t, dir, &ce_len);
|
||||
t->curblock += div_up(len, BLOCK_SIZE);
|
||||
t->curblock += DIV_UP(len, BLOCK_SIZE);
|
||||
if (t->rockridge) {
|
||||
t->curblock += div_up(ce_len, BLOCK_SIZE);
|
||||
t->curblock += DIV_UP(ce_len, BLOCK_SIZE);
|
||||
}
|
||||
for (i = 0; i < dir->info.dir->nchildren; i++) {
|
||||
Ecma119Node *child = dir->info.dir->children[i];
|
||||
@ -212,9 +212,9 @@ int ecma119_writer_compute_data_blocks(IsoImageWriter *writer)
|
||||
|
||||
/* compute location for path tables */
|
||||
target->l_path_table_pos = target->curblock;
|
||||
target->curblock += div_up(path_table_size, BLOCK_SIZE);
|
||||
target->curblock += DIV_UP(path_table_size, BLOCK_SIZE);
|
||||
target->m_path_table_pos = target->curblock;
|
||||
target->curblock += div_up(path_table_size, BLOCK_SIZE);
|
||||
target->curblock += DIV_UP(path_table_size, BLOCK_SIZE);
|
||||
target->path_table_size = path_table_size;
|
||||
|
||||
return ISO_SUCCESS;
|
||||
@ -392,7 +392,7 @@ int write_one_dir(Ecma119Image *t, Ecma119Node *dir)
|
||||
memset(&info, 0, sizeof(struct susp_info));
|
||||
if (t->rockridge) {
|
||||
/* initialize the ce_block, it might be needed */
|
||||
info.ce_block = dir->info.dir->block + div_up(dir->info.dir->len,
|
||||
info.ce_block = dir->info.dir->block + DIV_UP(dir->info.dir->len,
|
||||
BLOCK_SIZE);
|
||||
}
|
||||
|
||||
|
@ -176,7 +176,7 @@ int filesrc_writer_compute_data_blocks(IsoImageWriter *writer)
|
||||
for (i = 0; i < size; ++i) {
|
||||
IsoFileSrc *file = filelist[i];
|
||||
file->block = t->curblock;
|
||||
t->curblock += div_up(iso_file_src_get_size(file), BLOCK_SIZE);
|
||||
t->curblock += DIV_UP(iso_file_src_get_size(file), BLOCK_SIZE);
|
||||
}
|
||||
|
||||
/* the list is only needed by this writer, store locally */
|
||||
@ -260,10 +260,10 @@ int filesrc_writer_write_data(IsoImageWriter *writer)
|
||||
|
||||
/*
|
||||
* TODO WARNING
|
||||
* when we allow files greater than 4GB, current div_up implementation
|
||||
* when we allow files greater than 4GB, current DIV_UP implementation
|
||||
* can overflow!!
|
||||
*/
|
||||
uint32_t nblocks = div_up(iso_file_src_get_size(file), BLOCK_SIZE);
|
||||
uint32_t nblocks = DIV_UP(iso_file_src_get_size(file), BLOCK_SIZE);
|
||||
|
||||
res = filesrc_open(file);
|
||||
if (res < 0) {
|
||||
|
@ -1110,7 +1110,7 @@ int iso_file_source_new_ifs(IsoImageFilesystem *fs, IsoFileSource *parent,
|
||||
/* Fill last entries */
|
||||
atts.st_dev = fsdata->id;
|
||||
atts.st_blksize = BLOCK_SIZE;
|
||||
atts.st_blocks = div_up(atts.st_size, BLOCK_SIZE);
|
||||
atts.st_blocks = DIV_UP(atts.st_size, BLOCK_SIZE);
|
||||
|
||||
//TODO more sanity checks!!
|
||||
if (S_ISLNK(atts.st_mode) && (linkdest == NULL)) {
|
||||
@ -2076,7 +2076,7 @@ int create_boot_img_filesrc(IsoImageFilesystem *fs, IsoFileSource **src)
|
||||
/* Fill last entries */
|
||||
atts.st_dev = fsdata->id;
|
||||
atts.st_blksize = BLOCK_SIZE;
|
||||
atts.st_blocks = div_up(atts.st_size, BLOCK_SIZE);
|
||||
atts.st_blocks = DIV_UP(atts.st_size, BLOCK_SIZE);
|
||||
|
||||
/* ok, we can now create the file source */
|
||||
ifsdata = calloc(1, sizeof(ImageFileSourceData));
|
||||
|
@ -347,7 +347,7 @@ size_t calc_dir_size(Ecma119Image *t, Iso1999Node *dir)
|
||||
* the size of the unused space after the last directory record
|
||||
* (ISO 9660:1999, 6.8.1.3)
|
||||
*/
|
||||
len = div_up(len, BLOCK_SIZE) * BLOCK_SIZE;
|
||||
len = ROUND_UP(len, BLOCK_SIZE);
|
||||
|
||||
/* cache the len */
|
||||
dir->info.dir->len = len;
|
||||
@ -362,7 +362,7 @@ void calc_dir_pos(Ecma119Image *t, Iso1999Node *dir)
|
||||
t->iso1999_ndirs++;
|
||||
dir->info.dir->block = t->curblock;
|
||||
len = calc_dir_size(t, dir);
|
||||
t->curblock += div_up(len, BLOCK_SIZE);
|
||||
t->curblock += DIV_UP(len, BLOCK_SIZE);
|
||||
for (i = 0; i < dir->info.dir->nchildren; i++) {
|
||||
Iso1999Node *child = dir->info.dir->children[i];
|
||||
if (child->type == ISO1999_DIR) {
|
||||
@ -419,9 +419,9 @@ int iso1999_writer_compute_data_blocks(IsoImageWriter *writer)
|
||||
|
||||
/* compute location for path tables */
|
||||
t->iso1999_l_path_table_pos = t->curblock;
|
||||
t->curblock += div_up(path_table_size, BLOCK_SIZE);
|
||||
t->curblock += DIV_UP(path_table_size, BLOCK_SIZE);
|
||||
t->iso1999_m_path_table_pos = t->curblock;
|
||||
t->curblock += div_up(path_table_size, BLOCK_SIZE);
|
||||
t->curblock += DIV_UP(path_table_size, BLOCK_SIZE);
|
||||
t->iso1999_path_table_size = path_table_size;
|
||||
|
||||
return ISO_SUCCESS;
|
||||
|
@ -352,7 +352,7 @@ size_t calc_dir_size(Ecma119Image *t, JolietNode *dir)
|
||||
* the size of the unused space after the last directory record
|
||||
* (ECMA-119, 6.8.1.3)
|
||||
*/
|
||||
len = div_up(len, BLOCK_SIZE) * BLOCK_SIZE;
|
||||
len = ROUND_UP(len, BLOCK_SIZE);
|
||||
|
||||
/* cache the len */
|
||||
dir->info.dir->len = len;
|
||||
@ -367,7 +367,7 @@ void calc_dir_pos(Ecma119Image *t, JolietNode *dir)
|
||||
t->joliet_ndirs++;
|
||||
dir->info.dir->block = t->curblock;
|
||||
len = calc_dir_size(t, dir);
|
||||
t->curblock += div_up(len, BLOCK_SIZE);
|
||||
t->curblock += DIV_UP(len, BLOCK_SIZE);
|
||||
for (i = 0; i < dir->info.dir->nchildren; i++) {
|
||||
JolietNode *child = dir->info.dir->children[i];
|
||||
if (child->type == JOLIET_DIR) {
|
||||
@ -422,9 +422,9 @@ int joliet_writer_compute_data_blocks(IsoImageWriter *writer)
|
||||
|
||||
/* compute location for path tables */
|
||||
t->joliet_l_path_table_pos = t->curblock;
|
||||
t->curblock += div_up(path_table_size, BLOCK_SIZE);
|
||||
t->curblock += DIV_UP(path_table_size, BLOCK_SIZE);
|
||||
t->joliet_m_path_table_pos = t->curblock;
|
||||
t->curblock += div_up(path_table_size, BLOCK_SIZE);
|
||||
t->curblock += DIV_UP(path_table_size, BLOCK_SIZE);
|
||||
t->joliet_path_table_size = path_table_size;
|
||||
|
||||
return ISO_SUCCESS;
|
||||
|
@ -80,7 +80,7 @@ int susp_iter_next(SuspIterator *iter, struct susp_sys_user_entry **sue)
|
||||
int nblocks;
|
||||
|
||||
/* A CE has found, there is another continuation area */
|
||||
nblocks = div_up(iter->ce_off + iter->ce_len, BLOCK_SIZE);
|
||||
nblocks = DIV_UP(iter->ce_off + iter->ce_len, BLOCK_SIZE);
|
||||
iter->buffer = realloc(iter->buffer, nblocks * BLOCK_SIZE);
|
||||
|
||||
/* read all blocks needed to cache the full CE */
|
||||
|
10
src/util.c
10
src/util.c
@ -25,16 +25,6 @@
|
||||
#define __USE_GNU
|
||||
#include <unistd.h>
|
||||
|
||||
inline int div_up(unsigned int n, unsigned int div)
|
||||
{
|
||||
return (n + div - 1) / div;
|
||||
}
|
||||
|
||||
inline int round_up(unsigned int n, unsigned int mul)
|
||||
{
|
||||
return div_up(n, mul) * mul;
|
||||
}
|
||||
|
||||
int int_pow(int base, int power)
|
||||
{
|
||||
int result = 1;
|
||||
|
@ -20,8 +20,8 @@
|
||||
# define MIN(a, b) (((a) < (b)) ? (a) : (b))
|
||||
#endif
|
||||
|
||||
int div_up(unsigned int n, unsigned int div);
|
||||
int round_up(unsigned int n, unsigned int mul);
|
||||
#define DIV_UP(n,div) ((n + div - 1) / div)
|
||||
#define ROUND_UP(n,mul) (DIV_UP(n, mul) * mul)
|
||||
|
||||
int int_pow(int base, int power);
|
||||
|
||||
|
@ -55,23 +55,23 @@ static void test_strconv()
|
||||
|
||||
static void test_div_up()
|
||||
{
|
||||
CU_ASSERT_EQUAL( div_up(1, 2), 1 );
|
||||
CU_ASSERT_EQUAL( div_up(2, 2), 1 );
|
||||
CU_ASSERT_EQUAL( div_up(0, 2), 0 );
|
||||
CU_ASSERT_EQUAL( div_up(-1, 2), 0 );
|
||||
CU_ASSERT_EQUAL( div_up(3, 2), 2 );
|
||||
CU_ASSERT_EQUAL( DIV_UP(1, 2), 1 );
|
||||
CU_ASSERT_EQUAL( DIV_UP(2, 2), 1 );
|
||||
CU_ASSERT_EQUAL( DIV_UP(0, 2), 0 );
|
||||
CU_ASSERT_EQUAL( DIV_UP(-1, 2), 0 );
|
||||
CU_ASSERT_EQUAL( DIV_UP(3, 2), 2 );
|
||||
}
|
||||
|
||||
static void test_round_up()
|
||||
{
|
||||
CU_ASSERT_EQUAL( round_up(1, 2), 2 );
|
||||
CU_ASSERT_EQUAL( round_up(2, 2), 2 );
|
||||
CU_ASSERT_EQUAL( round_up(0, 2), 0 );
|
||||
CU_ASSERT_EQUAL( round_up(-1, 2), 0 );
|
||||
CU_ASSERT_EQUAL( round_up(3, 2), 4 );
|
||||
CU_ASSERT_EQUAL( round_up(15, 7), 21 );
|
||||
CU_ASSERT_EQUAL( round_up(13, 7), 14 );
|
||||
CU_ASSERT_EQUAL( round_up(14, 7), 14 );
|
||||
CU_ASSERT_EQUAL( ROUND_UP(1, 2), 2 );
|
||||
CU_ASSERT_EQUAL( ROUND_UP(2, 2), 2 );
|
||||
CU_ASSERT_EQUAL( ROUND_UP(0, 2), 0 );
|
||||
CU_ASSERT_EQUAL( ROUND_UP(-1, 2), 0 );
|
||||
CU_ASSERT_EQUAL( ROUND_UP(3, 2), 4 );
|
||||
CU_ASSERT_EQUAL( ROUND_UP(15, 7), 21 );
|
||||
CU_ASSERT_EQUAL( ROUND_UP(13, 7), 14 );
|
||||
CU_ASSERT_EQUAL( ROUND_UP(14, 7), 14 );
|
||||
}
|
||||
|
||||
static void test_iso_lsb_msb()
|
||||
@ -695,8 +695,8 @@ void add_util_suite()
|
||||
CU_pSuite pSuite = CU_add_suite("UtilSuite", NULL, NULL);
|
||||
|
||||
CU_add_test(pSuite, "strconv()", test_strconv);
|
||||
CU_add_test(pSuite, "div_up()", test_div_up);
|
||||
CU_add_test(pSuite, "round_up()", test_round_up);
|
||||
CU_add_test(pSuite, "DIV_UP()", test_div_up);
|
||||
CU_add_test(pSuite, "ROUND_UP()", test_round_up);
|
||||
CU_add_test(pSuite, "iso_bb()", test_iso_bb);
|
||||
CU_add_test(pSuite, "iso_lsb/msb()", test_iso_lsb_msb);
|
||||
CU_add_test(pSuite, "iso_read_lsb/msb()", test_iso_read_lsb_msb);
|
||||
|
Loading…
Reference in New Issue
Block a user