Fix important bug. File sections must be computed before dir size.

This commit is contained in:
Vreixo Formoso 2008-08-19 20:54:27 +02:00
parent ff480b35e9
commit fb3c3e1a6d
2 changed files with 156 additions and 149 deletions

View File

@ -68,13 +68,30 @@ int iso_file_src_create(Ecma119Image *img, IsoFile *file, IsoFileSrc **src)
/* fill key and other atts */
fsrc->prev_img = file->from_old_session;
if (file->from_old_session) {
if (file->from_old_session && img->appendable) {
/*
* On multisession discs we keep file sections from old image.
*/
int ret = iso_file_get_old_image_sections(file, &(fsrc->nsections),
&(fsrc->sections), 0);
if (ret < 0) {
free(fsrc);
return ISO_OUT_OF_MEM;
}
} else {
/*
* For new files, or for image copy, we compute our own file sections.
* Block and size of each section will be filled later.
*/
off_t section_size = iso_stream_get_size(file->stream);
if (section_size > (off_t) MAX_ISO_FILE_SECTION_SIZE) {
fsrc->nsections = DIV_UP(section_size - (off_t) MAX_ISO_FILE_SECTION_SIZE,
(off_t)ISO_EXTENT_SIZE) + 1;
} else {
fsrc->nsections = 1;
}
fsrc->sections = calloc(fsrc->nsections, sizeof(struct iso_file_section));
}
fsrc->sort_weight = file->sort_weight;
fsrc->stream = file->stream;
@ -187,15 +204,6 @@ int filesrc_writer_compute_data_blocks(IsoImageWriter *writer)
IsoFileSrc *file = filelist[i];
off_t section_size = iso_stream_get_size(file->stream);
if (section_size > (off_t) MAX_ISO_FILE_SECTION_SIZE) {
file->nsections = DIV_UP(iso_stream_get_size(file->stream)
- (off_t) MAX_ISO_FILE_SECTION_SIZE,
(off_t)ISO_EXTENT_SIZE) + 1;
} else {
file->nsections = 1;
}
file->sections = realloc(file->sections, file->nsections *
sizeof(struct iso_file_section));
for (extent = 0; extent < file->nsections - 1; ++extent) {
file->sections[extent].block = t->curblock + extent *
(ISO_EXTENT_SIZE / BLOCK_SIZE);
@ -207,8 +215,7 @@ int filesrc_writer_compute_data_blocks(IsoImageWriter *writer)
* final section
*/
file->sections[extent].block = t->curblock + extent * (ISO_EXTENT_SIZE / BLOCK_SIZE);
file->sections[extent].size = section_size;
section_size -= (off_t) ISO_EXTENT_SIZE;
file->sections[extent].size = (uint32_t)section_size;
t->curblock += DIV_UP(iso_file_src_get_size(file), BLOCK_SIZE);
}

View File

@ -1,6 +1,6 @@
/*
* Unit test for util.h
*
*
* This test utiliy functions
*/
#include "test.h"
@ -16,51 +16,51 @@ static void test_rrip_calc_len_file()
Ecma119Node *node;
Ecma119Image t;
size_t sua_len = 0, ce_len = 0;
memset(&t, 0, sizeof(Ecma119Image));
t.input_charset = "UTF-8";
t.output_charset = "UTF-8";
file = malloc(sizeof(IsoFile));
CU_ASSERT_PTR_NOT_NULL_FATAL(file);
file->msblock = 0;
file->from_old_session = 0;
file->sort_weight = 0;
file->stream = NULL; /* it is not needed here */
file->node.type = LIBISO_FILE;
node = malloc(sizeof(Ecma119Node));
CU_ASSERT_PTR_NOT_NULL_FATAL(node);
node->node = (IsoNode*)file;
node->parent = (Ecma119Node*)0x55555555; /* just to make it not NULL */
node->info.file = NULL; /* it is not needed here */
node->info.file = NULL; /* it is not needed here */
node->type = ECMA119_FILE;
/* Case 1. Name fit in System Use field */
file->node.name = "a small name.txt";
node->iso_name = "A_SMALL_.TXT";
sua_len = rrip_calc_len(&t, node, 0, 255 - 46, &ce_len);
CU_ASSERT_EQUAL(ce_len, 0);
CU_ASSERT_EQUAL(sua_len, 44 + (5 + 16) + (5 + 3*7) + 1);
/* Case 2. Name fits exactly */
file->node.name = "a big name, with 133 characters, that it is the max "
"that fits in System Use field of the directory record "
"PADPADPADADPADPADPADPAD.txt";
node->iso_name = "A_BIG_NA.TXT";
sua_len = rrip_calc_len(&t, node, 0, 255 - 46, &ce_len);
CU_ASSERT_EQUAL(ce_len, 0);
/* note that 254 is the max length of a directory record, as it needs to
* be an even number */
CU_ASSERT_EQUAL(sua_len, 254 - 46);
/* case 3. A name just 1 character too big to fit in SUA */
file->node.name = "a big name, with 133 characters, that it is the max "
"that fits in System Use field of the directory record "
"PADPADPADADPADPADPADPAD1.txt";
node->iso_name = "A_BIG_NA.TXT";
sua_len = rrip_calc_len(&t, node, 0, 255 - 46, &ce_len);
/* 28 (the chars moved to include the CE entry) + 5 (header of NM in CE) +
* 1 (the char that originally didn't fit) */
@ -68,21 +68,21 @@ static void test_rrip_calc_len_file()
/* note that 254 is the max length of a directory record, as it needs to
* be an even number */
CU_ASSERT_EQUAL(sua_len, 254 - 46);
/* case 4. A 255 characters name */
file->node.name = "a big name, with 255 characters, that it is the max "
"that a POSIX filename can have. PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP"
"PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP"
"PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP";
node->iso_name = "A_BIG_NA.TXT";
sua_len = rrip_calc_len(&t, node, 0, 255 - 46, &ce_len);
/* 150 + 5 (header + characters that don't fit in sua) */
CU_ASSERT_EQUAL(ce_len, 150 + 5);
/* note that 254 is the max length of a directory record, as it needs to
* be an even number */
CU_ASSERT_EQUAL(sua_len, 254 - 46);
free(node);
free(file);
}
@ -93,31 +93,31 @@ static void test_rrip_calc_len_symlink()
Ecma119Node *node;
Ecma119Image t;
size_t sua_len = 0, ce_len = 0;
memset(&t, 0, sizeof(Ecma119Image));
t.input_charset = "UTF-8";
t.output_charset = "UTF-8";
link = malloc(sizeof(IsoSymlink));
CU_ASSERT_PTR_NOT_NULL_FATAL(link);
link->node.type = LIBISO_SYMLINK;
node = malloc(sizeof(Ecma119Node));
CU_ASSERT_PTR_NOT_NULL_FATAL(node);
node->node = (IsoNode*)link;
node->parent = (Ecma119Node*)0x55555555; /* just to make it not NULL */
node->type = ECMA119_SYMLINK;
/* Case 1. Name and dest fit in System Use field */
link->node.name = "a small name.txt";
link->dest = "/three/components";
node->iso_name = "A_SMALL_.TXT";
sua_len = rrip_calc_len(&t, node, 0, 255 - 46, &ce_len);
CU_ASSERT_EQUAL(ce_len, 0);
CU_ASSERT_EQUAL(sua_len, 44 + (5 + 16) + (5 + 3*7) + 1 +
CU_ASSERT_EQUAL(sua_len, 44 + (5 + 16) + (5 + 3*7) + 1 +
(5 + 2 + (2+5) + (2+10)) );
/* case 2. name + dest fits exactly */
link->node.name = "this name will have 74 characters as it is the max "
"that fits in the SU.txt";
@ -136,7 +136,7 @@ static void test_rrip_calc_len_symlink()
sua_len = rrip_calc_len(&t, node, 0, 255 - 46, &ce_len);
CU_ASSERT_EQUAL(ce_len, 60);
CU_ASSERT_EQUAL(sua_len, 44 + (5 + 74) + (5 + 3*7) + 1 + 28);
/* 3.b extra byte in name */
link->node.name = "this name will have 75 characters as it is the max "
"that fits in the SUx.txt";
@ -145,10 +145,10 @@ static void test_rrip_calc_len_symlink()
sua_len = rrip_calc_len(&t, node, 0, 255 - 46, &ce_len);
CU_ASSERT_EQUAL(ce_len, 59);
CU_ASSERT_EQUAL(sua_len, 44 + (5 + 75) + (5 + 3*7) + 28);
/* case 4. name seems to fit, but SL no, and when CE is added NM
/* case 4. name seems to fit, but SL no, and when CE is added NM
* doesn't fit too */
/* 4.a it just fits */
/* 4.a it just fits */
link->node.name = "this name will have 105 characters as it is just the "
"max that fits in the SU once we add the CE entry.txt";
link->dest = "./and/../a/./big/destination/with/10/components";
@ -156,8 +156,8 @@ static void test_rrip_calc_len_symlink()
sua_len = rrip_calc_len(&t, node, 0, 255 - 46, &ce_len);
CU_ASSERT_EQUAL(ce_len, 59);
CU_ASSERT_EQUAL(sua_len, 254 - 46);
/* 4.b it just fits, the the component ends in '/' */
/* 4.b it just fits, the the component ends in '/' */
link->node.name = "this name will have 105 characters as it is just the "
"max that fits in the SU once we add the CE entry.txt";
link->dest = "./and/../a/./big/destination/with/10/components/";
@ -165,8 +165,8 @@ static void test_rrip_calc_len_symlink()
sua_len = rrip_calc_len(&t, node, 0, 255 - 46, &ce_len);
CU_ASSERT_EQUAL(ce_len, 59);
CU_ASSERT_EQUAL(sua_len, 254 - 46);
/* 4.c extra char in name, that forces it to be divided */
/* 4.c extra char in name, that forces it to be divided */
link->node.name = "this name will have 105 characters as it is just the "
"max that fits in the SU once we add the CE entryc.txt";
link->dest = "./and/../a/./big/destination/with/10/components";
@ -174,7 +174,7 @@ static void test_rrip_calc_len_symlink()
sua_len = rrip_calc_len(&t, node, 0, 255 - 46, &ce_len);
CU_ASSERT_EQUAL(ce_len, 59 + 6);
CU_ASSERT_EQUAL(sua_len, 254 - 46);
/* 5 max destination length to fit in a single SL entry (250) */
link->node.name = "this name will have 74 characters as it is the max "
"that fits in the SU.txt";
@ -186,7 +186,7 @@ static void test_rrip_calc_len_symlink()
sua_len = rrip_calc_len(&t, node, 0, 255 - 46, &ce_len);
CU_ASSERT_EQUAL(ce_len, 255);
CU_ASSERT_EQUAL(sua_len, 44 + (5 + 74) + (5 + 3*7) + 1 + 28);
/* 6 min destination length to need two SL entries (251) */
link->node.name = "this name will have 74 characters as it is the max "
"that fits in the SU.txt";
@ -198,8 +198,8 @@ static void test_rrip_calc_len_symlink()
sua_len = rrip_calc_len(&t, node, 0, 255 - 46, &ce_len);
CU_ASSERT_EQUAL(ce_len, 261);
CU_ASSERT_EQUAL(sua_len, 44 + (5 + 74) + (5 + 3*7) + 1 + 28);
/* 7 destination with big component that need to be splited
/* 7 destination with big component that need to be splited
* in two SL entries */
/* 7.a just fits in one */
link->node.name = "this name will have 74 characters as it is the max "
@ -213,7 +213,7 @@ static void test_rrip_calc_len_symlink()
sua_len = rrip_calc_len(&t, node, 0, 255 - 46, &ce_len);
CU_ASSERT_EQUAL(ce_len, 255);
CU_ASSERT_EQUAL(sua_len, 44 + (5 + 74) + (5 + 3*7) + 1 + 28);
/* 7.b doesn't fits by one character */
link->node.name = "this name will have 74 characters as it is the max "
"that fits in the SU.txt";
@ -226,7 +226,7 @@ static void test_rrip_calc_len_symlink()
sua_len = rrip_calc_len(&t, node, 0, 255 - 46, &ce_len);
CU_ASSERT_EQUAL(ce_len, 255 + (5+2+1));
CU_ASSERT_EQUAL(sua_len, 44 + (5 + 74) + (5 + 3*7) + 1 + 28);
/* 7.c several components before, such as it has just the right len
* to fit in the SL entry plus another one */
link->node.name = "this name will have 74 characters as it is the max "
@ -244,8 +244,8 @@ static void test_rrip_calc_len_symlink()
sua_len = rrip_calc_len(&t, node, 0, 255 - 46, &ce_len);
CU_ASSERT_EQUAL(ce_len, 255 + 255);
CU_ASSERT_EQUAL(sua_len, 44 + (5 + 74) + (5 + 3*7) + 1 + 28);
/*
/*
* 7.d several components before, and then a big component that doesn't
* fit in the 1st SL entry and another one. That case needs a 3rd SL entry,
* but instead of divide the component in 2 entries, we put it in 2,
@ -275,12 +275,12 @@ static
void susp_info_free(struct susp_info *susp)
{
size_t i;
for (i = 0; i < susp->n_susp_fields; ++i) {
free(susp->susp_fields[i]);
}
free(susp->susp_fields);
for (i = 0; i < susp->n_ce_susp_fields; ++i) {
free(susp->ce_susp_fields[i]);
}
@ -296,14 +296,14 @@ void test_rrip_get_susp_fields_file()
struct susp_info susp;
Ecma119Image t;
uint8_t *entry;
memset(&t, 0, sizeof(Ecma119Image));
t.input_charset = "UTF-8";
t.output_charset = "UTF-8";
file = malloc(sizeof(IsoFile));
CU_ASSERT_PTR_NOT_NULL_FATAL(file);
file->msblock = 0;
file->from_old_session = 0;
file->sort_weight = 0;
file->stream = NULL; /* it is not needed here */
file->node.type = LIBISO_FILE;
@ -313,20 +313,20 @@ void test_rrip_get_susp_fields_file()
file->node.mtime = 675757578;
file->node.atime = 546462546;
file->node.ctime = 323245342;
node = malloc(sizeof(Ecma119Node));
CU_ASSERT_PTR_NOT_NULL_FATAL(node);
node->node = (IsoNode*)file;
node->parent = (Ecma119Node*)0x55555555; /* just to make it not NULL */
node->info.file = NULL; /* it is not needed here */
node->info.file = NULL; /* it is not needed here */
node->type = ECMA119_FILE;
node->nlink = 1;
node->ino = 0x03447892;
/* Case 1. Name fit in System Use field */
file->node.name = "a small name.txt";
node->iso_name = "A_SMALL_.TXT";
memset(&susp, 0, sizeof(struct susp_info));
ret = rrip_get_susp_fields(&t, node, 0, 255 - 46, &susp);
CU_ASSERT_EQUAL(ret, 1);
@ -334,7 +334,7 @@ void test_rrip_get_susp_fields_file()
CU_ASSERT_EQUAL(susp.n_ce_susp_fields, 0);
CU_ASSERT_EQUAL(susp.n_susp_fields, 3); /* PX + TF + NM */
CU_ASSERT_EQUAL(susp.suf_len, 44 + (5 + 16) + (5 + 3*7) + 1);
/* PX is the first entry */
entry = susp.susp_fields[0];
CU_ASSERT_PTR_NOT_NULL(entry);
@ -352,7 +352,7 @@ void test_rrip_get_susp_fields_file()
CU_ASSERT_EQUAL(iso_read_msb(entry + 32, 4), 654);
CU_ASSERT_EQUAL(iso_read_lsb(entry + 36, 4), 0x03447892);
CU_ASSERT_EQUAL(iso_read_msb(entry + 40, 4), 0x03447892);
/* TF is the second entry */
entry = susp.susp_fields[1];
CU_ASSERT_PTR_NOT_NULL(entry);
@ -364,7 +364,7 @@ void test_rrip_get_susp_fields_file()
CU_ASSERT_EQUAL(iso_datetime_read_7(entry + 5), 675757578);
CU_ASSERT_EQUAL(iso_datetime_read_7(entry + 12), 546462546);
CU_ASSERT_EQUAL(iso_datetime_read_7(entry + 19), 323245342);
/* NM is the last entry */
entry = susp.susp_fields[2];
CU_ASSERT_PTR_NOT_NULL(entry);
@ -374,24 +374,24 @@ void test_rrip_get_susp_fields_file()
CU_ASSERT_EQUAL(entry[3], 1);
CU_ASSERT_EQUAL(entry[4], 0);
CU_ASSERT_NSTRING_EQUAL(entry + 5, "a small name.txt", 16);
susp_info_free(&susp);
/* Case 2. Name fits exactly */
file->node.name = "a big name, with 133 characters, that it is the max "
"that fits in System Use field of the directory record "
"PADPADPADADPADPADPADPAD.txt";
node->iso_name = "A_BIG_NA.TXT";
memset(&susp, 0, sizeof(struct susp_info));
ret = rrip_get_susp_fields(&t, node, 0, 255 - 46, &susp);
CU_ASSERT_EQUAL(ret, 1);
CU_ASSERT_EQUAL(susp.ce_len, 0);
CU_ASSERT_EQUAL(susp.n_ce_susp_fields, 0);
CU_ASSERT_EQUAL(susp.suf_len, 254 - 46);
CU_ASSERT_EQUAL(susp.n_susp_fields, 3); /* PX + TF + NM */
/* NM is the last entry */
entry = susp.susp_fields[2];
CU_ASSERT_PTR_NOT_NULL(entry);
@ -403,24 +403,24 @@ void test_rrip_get_susp_fields_file()
CU_ASSERT_NSTRING_EQUAL(entry + 5, "a big name, with 133 characters, that "
"it is the max that fits in System Use field of the "
"directory record PADPADPADADPADPADPADPAD.txt", 133);
susp_info_free(&susp);
/* case 3. A name just 1 character too big to fit in SUA */
file->node.name = "a big name, with 133 characters, that it is the max "
"that fits in System Use field of the directory record "
"PADPADPADADPADPADPADPAD1.txt";
node->iso_name = "A_BIG_NA.TXT";
memset(&susp, 0, sizeof(struct susp_info));
ret = rrip_get_susp_fields(&t, node, 0, 255 - 46, &susp);
CU_ASSERT_EQUAL(ret, 1);
CU_ASSERT_EQUAL(susp.ce_len, 28 + 5 + 1);
CU_ASSERT_EQUAL(susp.suf_len, 254 - 46);
CU_ASSERT_EQUAL(susp.n_susp_fields, 4); /* PX + TF + NM + CE */
CU_ASSERT_EQUAL(susp.n_ce_susp_fields, 1); /* NM */
/* test NM entry */
entry = susp.susp_fields[2];
CU_ASSERT_PTR_NOT_NULL(entry);
@ -432,7 +432,7 @@ void test_rrip_get_susp_fields_file()
CU_ASSERT_NSTRING_EQUAL(entry + 5, "a big name, with 133 characters, that "
"it is the max that fits in System Use field of the "
"directory record", 105);
/* and CE entry */
entry = susp.susp_fields[3];
CU_ASSERT_PTR_NOT_NULL(entry);
@ -446,7 +446,7 @@ void test_rrip_get_susp_fields_file()
CU_ASSERT_EQUAL(iso_read_msb(entry + 16, 4), 0);
CU_ASSERT_EQUAL(iso_read_lsb(entry + 20, 4), 34);
CU_ASSERT_EQUAL(iso_read_msb(entry + 24, 4), 34);
/* and check Continuation area */
entry = susp.ce_susp_fields[0];
CU_ASSERT_PTR_NOT_NULL(entry);
@ -456,16 +456,16 @@ void test_rrip_get_susp_fields_file()
CU_ASSERT_EQUAL(entry[3], 1);
CU_ASSERT_EQUAL(entry[4], 0);
CU_ASSERT_NSTRING_EQUAL(entry + 5, " PADPADPADADPADPADPADPAD1.txt", 29);
susp_info_free(&susp);
/* case 4. A 255 characters name */
file->node.name = "a big name, with 255 characters, that it is the max "
"that a POSIX filename can have. PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP"
"PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP"
"PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP";
node->iso_name = "A_BIG_NA.TXT";
memset(&susp, 0, sizeof(struct susp_info));
susp.ce_block = 12;
susp.ce_len = 456;
@ -473,7 +473,7 @@ void test_rrip_get_susp_fields_file()
CU_ASSERT_EQUAL(ret, 1);
CU_ASSERT_EQUAL(susp.ce_len, 150 + 5 + 456);
CU_ASSERT_EQUAL(susp.suf_len, 254 - 46);
CU_ASSERT_EQUAL(susp.n_susp_fields, 4); /* PX + TF + NM + CE */
CU_ASSERT_EQUAL(susp.n_ce_susp_fields, 1); /* NM */
@ -488,7 +488,7 @@ void test_rrip_get_susp_fields_file()
CU_ASSERT_NSTRING_EQUAL(entry + 5, "a big name, with 255 characters, that "
"it is the max that a POSIX filename can have. PPP"
"PPPPPPPPPPPPPPPPPP", 105);
/* and CE entry */
entry = susp.susp_fields[3];
CU_ASSERT_PTR_NOT_NULL(entry);
@ -517,9 +517,9 @@ void test_rrip_get_susp_fields_file()
"PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP"
"PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP"
"PPPPPPPPPPPPPP", 150);
susp_info_free(&susp);
free(node);
free(file);
}
@ -532,11 +532,11 @@ static void test_rrip_get_susp_fields_symlink()
int ret;
struct susp_info susp;
uint8_t *entry;
memset(&t, 0, sizeof(Ecma119Image));
t.input_charset = "UTF-8";
t.output_charset = "UTF-8";
link = malloc(sizeof(IsoSymlink));
CU_ASSERT_PTR_NOT_NULL_FATAL(link);
link->node.type = LIBISO_SYMLINK;
@ -546,7 +546,7 @@ static void test_rrip_get_susp_fields_symlink()
link->node.mtime = 675757578;
link->node.atime = 546462546;
link->node.ctime = 323245342;
node = malloc(sizeof(Ecma119Node));
CU_ASSERT_PTR_NOT_NULL_FATAL(node);
node->node = (IsoNode*)link;
@ -554,21 +554,21 @@ static void test_rrip_get_susp_fields_symlink()
node->type = ECMA119_SYMLINK;
node->nlink = 1;
node->ino = 0x03447892;
/* Case 1. Name and dest fit in System Use field */
link->node.name = "a small name.txt";
link->dest = "/three/components";
node->iso_name = "A_SMALL_.TXT";
memset(&susp, 0, sizeof(struct susp_info));
ret = rrip_get_susp_fields(&t, node, 0, 255 - 46, &susp);
CU_ASSERT_EQUAL(ret, 1);
CU_ASSERT_EQUAL(susp.ce_len, 0);
CU_ASSERT_EQUAL(susp.n_ce_susp_fields, 0);
CU_ASSERT_EQUAL(susp.n_susp_fields, 4); /* PX + TF + NM + SL */
CU_ASSERT_EQUAL(susp.suf_len, 44 + (5 + 16) + (5 + 3*7) + 1
CU_ASSERT_EQUAL(susp.suf_len, 44 + (5 + 16) + (5 + 3*7) + 1
+ (5 + 2 + (2 + 5) + (2 + 10)));
/* PX is the first entry */
entry = susp.susp_fields[0];
CU_ASSERT_PTR_NOT_NULL(entry);
@ -586,7 +586,7 @@ static void test_rrip_get_susp_fields_symlink()
CU_ASSERT_EQUAL(iso_read_msb(entry + 32, 4), 654);
CU_ASSERT_EQUAL(iso_read_lsb(entry + 36, 4), 0x03447892);
CU_ASSERT_EQUAL(iso_read_msb(entry + 40, 4), 0x03447892);
/* TF is the second entry */
entry = susp.susp_fields[1];
CU_ASSERT_PTR_NOT_NULL(entry);
@ -598,7 +598,7 @@ static void test_rrip_get_susp_fields_symlink()
CU_ASSERT_EQUAL(iso_datetime_read_7(entry + 5), 675757578);
CU_ASSERT_EQUAL(iso_datetime_read_7(entry + 12), 546462546);
CU_ASSERT_EQUAL(iso_datetime_read_7(entry + 19), 323245342);
/* NM is the 3rd entry */
entry = susp.susp_fields[2];
CU_ASSERT_PTR_NOT_NULL(entry);
@ -617,7 +617,7 @@ static void test_rrip_get_susp_fields_symlink()
CU_ASSERT_EQUAL(entry[2], 5 + 2 + (2 + 5) + (2 + 10));
CU_ASSERT_EQUAL(entry[3], 1);
CU_ASSERT_EQUAL(entry[4], 0);
/* first component */
CU_ASSERT_EQUAL(entry[5], 0x8); /* root */
CU_ASSERT_EQUAL(entry[6], 0);
@ -626,14 +626,14 @@ static void test_rrip_get_susp_fields_symlink()
CU_ASSERT_EQUAL(entry[7], 0);
CU_ASSERT_EQUAL(entry[8], 5);
CU_ASSERT_NSTRING_EQUAL(entry + 9, "three", 5);
/* 3rd component */
CU_ASSERT_EQUAL(entry[14], 0);
CU_ASSERT_EQUAL(entry[15], 10);
CU_ASSERT_NSTRING_EQUAL(entry + 16, "components", 10);
susp_info_free(&susp);
/* case 2. name + dest fits exactly */
link->node.name = "this name will have 74 characters as it is the max "
"that fits in the SU.txt";
@ -647,7 +647,7 @@ static void test_rrip_get_susp_fields_symlink()
CU_ASSERT_EQUAL(susp.n_ce_susp_fields, 0);
CU_ASSERT_EQUAL(susp.n_susp_fields, 4); /* PX + TF + NM + SL */
CU_ASSERT_EQUAL(susp.suf_len, 254 - 46);
/* NM is the 3rd entry */
entry = susp.susp_fields[2];
CU_ASSERT_PTR_NOT_NULL(entry);
@ -667,7 +667,7 @@ static void test_rrip_get_susp_fields_symlink()
CU_ASSERT_EQUAL(entry[2], 5 + 2 + 5 + 2 + 3 + 2 + 5 + 13 + 6 + 4 + 12);
CU_ASSERT_EQUAL(entry[3], 1);
CU_ASSERT_EQUAL(entry[4], 0);
/* first component */
CU_ASSERT_EQUAL(entry[5], 0x2); /* current */
CU_ASSERT_EQUAL(entry[6], 0);
@ -676,7 +676,7 @@ static void test_rrip_get_susp_fields_symlink()
CU_ASSERT_EQUAL(entry[7], 0);
CU_ASSERT_EQUAL(entry[8], 3);
CU_ASSERT_NSTRING_EQUAL(entry + 9, "and", 3);
/* 3rd component */
CU_ASSERT_EQUAL(entry[12], 0x4); /* parent */
CU_ASSERT_EQUAL(entry[13], 0);
@ -685,7 +685,7 @@ static void test_rrip_get_susp_fields_symlink()
CU_ASSERT_EQUAL(entry[14], 0);
CU_ASSERT_EQUAL(entry[15], 1);
CU_ASSERT_EQUAL(entry[16], 'a');
/* 5th component */
CU_ASSERT_EQUAL(entry[17], 0x2); /* current */
CU_ASSERT_EQUAL(entry[18], 0);
@ -716,7 +716,7 @@ static void test_rrip_get_susp_fields_symlink()
CU_ASSERT_NSTRING_EQUAL(entry + 49, "components", 10);
susp_info_free(&susp);
/* case 3. name fits, dest is one byte larger to fit */
/* 3.a extra byte in dest */
link->node.name = "this name will have 74 characters as it is the max "
@ -738,7 +738,7 @@ static void test_rrip_get_susp_fields_symlink()
CU_ASSERT_EQUAL(entry[0], 'P');
CU_ASSERT_EQUAL(entry[1], 'X');
CU_ASSERT_EQUAL(entry[2], 44);
/* TF is the second entry */
entry = susp.susp_fields[1];
CU_ASSERT_PTR_NOT_NULL(entry);
@ -770,7 +770,7 @@ static void test_rrip_get_susp_fields_symlink()
CU_ASSERT_EQUAL(iso_read_msb(entry + 16, 4), 0);
CU_ASSERT_EQUAL(iso_read_lsb(entry + 20, 4), 60);
CU_ASSERT_EQUAL(iso_read_msb(entry + 24, 4), 60);
/* finally, SL is the single entry in CE */
entry = susp.ce_susp_fields[0];
@ -780,7 +780,7 @@ static void test_rrip_get_susp_fields_symlink()
CU_ASSERT_EQUAL(entry[2], 60);
CU_ASSERT_EQUAL(entry[3], 1);
CU_ASSERT_EQUAL(entry[4], 0);
/* first component */
CU_ASSERT_EQUAL(entry[5], 0x2); /* current */
CU_ASSERT_EQUAL(entry[6], 0);
@ -789,7 +789,7 @@ static void test_rrip_get_susp_fields_symlink()
CU_ASSERT_EQUAL(entry[7], 0);
CU_ASSERT_EQUAL(entry[8], 3);
CU_ASSERT_NSTRING_EQUAL(entry + 9, "and", 3);
/* 3rd component */
CU_ASSERT_EQUAL(entry[12], 0x4); /* parent */
CU_ASSERT_EQUAL(entry[13], 0);
@ -798,7 +798,7 @@ static void test_rrip_get_susp_fields_symlink()
CU_ASSERT_EQUAL(entry[14], 0);
CU_ASSERT_EQUAL(entry[15], 1);
CU_ASSERT_EQUAL(entry[16], 'a');
/* 5th component */
CU_ASSERT_EQUAL(entry[17], 0x2); /* current */
CU_ASSERT_EQUAL(entry[18], 0);
@ -827,7 +827,7 @@ static void test_rrip_get_susp_fields_symlink()
CU_ASSERT_EQUAL(entry[47], 0);
CU_ASSERT_EQUAL(entry[48], 11);
CU_ASSERT_NSTRING_EQUAL(entry + 49, "componentsk", 11);
susp_info_free(&susp);
/* 3.b extra byte in name */
@ -868,7 +868,7 @@ static void test_rrip_get_susp_fields_symlink()
CU_ASSERT_EQUAL(iso_read_msb(entry + 16, 4), 0);
CU_ASSERT_EQUAL(iso_read_lsb(entry + 20, 4), 59);
CU_ASSERT_EQUAL(iso_read_msb(entry + 24, 4), 59);
/* finally, SL is the single entry in CE */
entry = susp.ce_susp_fields[0];
@ -878,7 +878,7 @@ static void test_rrip_get_susp_fields_symlink()
CU_ASSERT_EQUAL(entry[2], 59);
CU_ASSERT_EQUAL(entry[3], 1);
CU_ASSERT_EQUAL(entry[4], 0);
/* first component */
CU_ASSERT_EQUAL(entry[5], 0x2); /* current */
CU_ASSERT_EQUAL(entry[6], 0);
@ -887,7 +887,7 @@ static void test_rrip_get_susp_fields_symlink()
CU_ASSERT_EQUAL(entry[7], 0);
CU_ASSERT_EQUAL(entry[8], 3);
CU_ASSERT_NSTRING_EQUAL(entry + 9, "and", 3);
/* 3rd component */
CU_ASSERT_EQUAL(entry[12], 0x4); /* parent */
CU_ASSERT_EQUAL(entry[13], 0);
@ -896,7 +896,7 @@ static void test_rrip_get_susp_fields_symlink()
CU_ASSERT_EQUAL(entry[14], 0);
CU_ASSERT_EQUAL(entry[15], 1);
CU_ASSERT_EQUAL(entry[16], 'a');
/* 5th component */
CU_ASSERT_EQUAL(entry[17], 0x2); /* current */
CU_ASSERT_EQUAL(entry[18], 0);
@ -925,12 +925,12 @@ static void test_rrip_get_susp_fields_symlink()
CU_ASSERT_EQUAL(entry[47], 0);
CU_ASSERT_EQUAL(entry[48], 10);
CU_ASSERT_NSTRING_EQUAL(entry + 49, "components", 10);
susp_info_free(&susp);
/* case 4. name seems to fit, but SL no, and when CE is added NM
/* case 4. name seems to fit, but SL no, and when CE is added NM
* doesn't fit too */
/* 4.a it just fits */
/* 4.a it just fits */
link->node.name = "this name will have 105 characters as it is just the "
"max that fits in the SU once we add the CE entry.txt";
link->dest = "./and/../a/./big/destination/with/10/components";
@ -978,7 +978,7 @@ static void test_rrip_get_susp_fields_symlink()
CU_ASSERT_EQUAL(entry[2], 59);
CU_ASSERT_EQUAL(entry[3], 1);
CU_ASSERT_EQUAL(entry[4], 0);
/* first component */
CU_ASSERT_EQUAL(entry[5], 0x2); /* current */
CU_ASSERT_EQUAL(entry[6], 0);
@ -987,7 +987,7 @@ static void test_rrip_get_susp_fields_symlink()
CU_ASSERT_EQUAL(entry[7], 0);
CU_ASSERT_EQUAL(entry[8], 3);
CU_ASSERT_NSTRING_EQUAL(entry + 9, "and", 3);
/* 3rd component */
CU_ASSERT_EQUAL(entry[12], 0x4); /* parent */
CU_ASSERT_EQUAL(entry[13], 0);
@ -996,7 +996,7 @@ static void test_rrip_get_susp_fields_symlink()
CU_ASSERT_EQUAL(entry[14], 0);
CU_ASSERT_EQUAL(entry[15], 1);
CU_ASSERT_EQUAL(entry[16], 'a');
/* 5th component */
CU_ASSERT_EQUAL(entry[17], 0x2); /* current */
CU_ASSERT_EQUAL(entry[18], 0);
@ -1025,10 +1025,10 @@ static void test_rrip_get_susp_fields_symlink()
CU_ASSERT_EQUAL(entry[47], 0);
CU_ASSERT_EQUAL(entry[48], 10);
CU_ASSERT_NSTRING_EQUAL(entry + 49, "components", 10);
susp_info_free(&susp);
/* 4.b it just fits, the the component ends in '/' */
/* 4.b it just fits, the the component ends in '/' */
link->node.name = "this name will have 105 characters as it is just the "
"max that fits in the SU once we add the CE entry.txt";
link->dest = "./and/../a/./big/destination/with/10/components/";
@ -1076,7 +1076,7 @@ static void test_rrip_get_susp_fields_symlink()
CU_ASSERT_EQUAL(entry[2], 59);
CU_ASSERT_EQUAL(entry[3], 1);
CU_ASSERT_EQUAL(entry[4], 0);
/* first component */
CU_ASSERT_EQUAL(entry[5], 0x2); /* current */
CU_ASSERT_EQUAL(entry[6], 0);
@ -1085,7 +1085,7 @@ static void test_rrip_get_susp_fields_symlink()
CU_ASSERT_EQUAL(entry[7], 0);
CU_ASSERT_EQUAL(entry[8], 3);
CU_ASSERT_NSTRING_EQUAL(entry + 9, "and", 3);
/* 3rd component */
CU_ASSERT_EQUAL(entry[12], 0x4); /* parent */
CU_ASSERT_EQUAL(entry[13], 0);
@ -1094,7 +1094,7 @@ static void test_rrip_get_susp_fields_symlink()
CU_ASSERT_EQUAL(entry[14], 0);
CU_ASSERT_EQUAL(entry[15], 1);
CU_ASSERT_EQUAL(entry[16], 'a');
/* 5th component */
CU_ASSERT_EQUAL(entry[17], 0x2); /* current */
CU_ASSERT_EQUAL(entry[18], 0);
@ -1123,10 +1123,10 @@ static void test_rrip_get_susp_fields_symlink()
CU_ASSERT_EQUAL(entry[47], 0);
CU_ASSERT_EQUAL(entry[48], 10);
CU_ASSERT_NSTRING_EQUAL(entry + 49, "components", 10);
susp_info_free(&susp);
/* 4.c extra char in name, that forces it to be divided */
/* 4.c extra char in name, that forces it to be divided */
link->node.name = "this name will have 106 characters as it is just the "
"max that fits in the SU once we add the CE entryc.txt";
link->dest = "./and/../a/./big/destination/with/10/components";
@ -1175,7 +1175,7 @@ static void test_rrip_get_susp_fields_symlink()
CU_ASSERT_EQUAL(entry[3], 1);
CU_ASSERT_EQUAL(entry[4], 0);
CU_ASSERT_EQUAL(entry[5], 't');
/* finally, SL is the single entry in CE */
entry = susp.ce_susp_fields[1];
CU_ASSERT_PTR_NOT_NULL(entry);
@ -1184,7 +1184,7 @@ static void test_rrip_get_susp_fields_symlink()
CU_ASSERT_EQUAL(entry[2], 59);
CU_ASSERT_EQUAL(entry[3], 1);
CU_ASSERT_EQUAL(entry[4], 0);
/* first component */
CU_ASSERT_EQUAL(entry[5], 0x2); /* current */
CU_ASSERT_EQUAL(entry[6], 0);
@ -1193,7 +1193,7 @@ static void test_rrip_get_susp_fields_symlink()
CU_ASSERT_EQUAL(entry[7], 0);
CU_ASSERT_EQUAL(entry[8], 3);
CU_ASSERT_NSTRING_EQUAL(entry + 9, "and", 3);
/* 3rd component */
CU_ASSERT_EQUAL(entry[12], 0x4); /* parent */
CU_ASSERT_EQUAL(entry[13], 0);
@ -1202,7 +1202,7 @@ static void test_rrip_get_susp_fields_symlink()
CU_ASSERT_EQUAL(entry[14], 0);
CU_ASSERT_EQUAL(entry[15], 1);
CU_ASSERT_EQUAL(entry[16], 'a');
/* 5th component */
CU_ASSERT_EQUAL(entry[17], 0x2); /* current */
CU_ASSERT_EQUAL(entry[18], 0);
@ -1231,9 +1231,9 @@ static void test_rrip_get_susp_fields_symlink()
CU_ASSERT_EQUAL(entry[47], 0);
CU_ASSERT_EQUAL(entry[48], 10);
CU_ASSERT_NSTRING_EQUAL(entry + 49, "components", 10);
susp_info_free(&susp);
/* 5 max destination length to fit in a single SL entry (250) */
link->node.name = "this name will have 74 characters as it is the max "
"that fits in the SU.txt";
@ -1259,7 +1259,7 @@ static void test_rrip_get_susp_fields_symlink()
CU_ASSERT_EQUAL(entry[2], 255);
CU_ASSERT_EQUAL(entry[3], 1);
CU_ASSERT_EQUAL(entry[4], 0);
/* first component */
CU_ASSERT_EQUAL(entry[5], 0x2); /* current */
CU_ASSERT_EQUAL(entry[6], 0);
@ -1268,7 +1268,7 @@ static void test_rrip_get_susp_fields_symlink()
CU_ASSERT_EQUAL(entry[7], 0);
CU_ASSERT_EQUAL(entry[8], 3);
CU_ASSERT_NSTRING_EQUAL(entry + 9, "and", 3);
/* 3rd component */
CU_ASSERT_EQUAL(entry[12], 0x4); /* parent */
CU_ASSERT_EQUAL(entry[13], 0);
@ -1277,7 +1277,7 @@ static void test_rrip_get_susp_fields_symlink()
CU_ASSERT_EQUAL(entry[14], 0);
CU_ASSERT_EQUAL(entry[15], 1);
CU_ASSERT_EQUAL(entry[16], 'a');
/* 5th component */
CU_ASSERT_EQUAL(entry[17], 0x2); /* current */
CU_ASSERT_EQUAL(entry[18], 0);
@ -1301,7 +1301,7 @@ static void test_rrip_get_susp_fields_symlink()
CU_ASSERT_EQUAL(entry[43], 0);
CU_ASSERT_EQUAL(entry[44], 4);
CU_ASSERT_NSTRING_EQUAL(entry + 45, "with", 4);
/* 10th component */
CU_ASSERT_EQUAL(entry[49], 0);
CU_ASSERT_EQUAL(entry[50], 2);
@ -1316,59 +1316,59 @@ static void test_rrip_get_susp_fields_symlink()
CU_ASSERT_EQUAL(entry[65], 0);
CU_ASSERT_EQUAL(entry[66], 4);
CU_ASSERT_NSTRING_EQUAL(entry + 67, "that", 4);
/* 13th component */
CU_ASSERT_EQUAL(entry[71], 0);
CU_ASSERT_EQUAL(entry[72], 8);
CU_ASSERT_NSTRING_EQUAL(entry + 73, "conforms", 8);
/* 14th component */
CU_ASSERT_EQUAL(entry[81], 0);
CU_ASSERT_EQUAL(entry[82], 3);
CU_ASSERT_NSTRING_EQUAL(entry + 83, "the", 3);
/* 15th component */
CU_ASSERT_EQUAL(entry[86], 0);
CU_ASSERT_EQUAL(entry[87], 3);
CU_ASSERT_NSTRING_EQUAL(entry + 88, "max", 3);
/* 16th component */
CU_ASSERT_EQUAL(entry[91], 0);
CU_ASSERT_EQUAL(entry[92], 4);
CU_ASSERT_NSTRING_EQUAL(entry + 93, "that", 4);
/* 17th component */
CU_ASSERT_EQUAL(entry[97], 0);
CU_ASSERT_EQUAL(entry[98], 4);
CU_ASSERT_NSTRING_EQUAL(entry + 99, "fits", 4);
/* 18th component */
CU_ASSERT_EQUAL(entry[103], 0);
CU_ASSERT_EQUAL(entry[104], 2);
CU_ASSERT_NSTRING_EQUAL(entry + 105, "in", 2);
/* 19th component */
CU_ASSERT_EQUAL(entry[107], 0);
CU_ASSERT_EQUAL(entry[108], 11);
CU_ASSERT_NSTRING_EQUAL(entry + 109, "a single SL", 11);
/* 20th component */
CU_ASSERT_EQUAL(entry[120], 0);
CU_ASSERT_EQUAL(entry[121], 38);
CU_ASSERT_NSTRING_EQUAL(entry + 122, "entry as it takes "
"just two hundred and", 38);
/* 21th component */
CU_ASSERT_EQUAL(entry[160], 0);
CU_ASSERT_EQUAL(entry[161], 29);
CU_ASSERT_NSTRING_EQUAL(entry + 162, "fifty bytes bytes bytes bytes", 29);
/* 22th component */
CU_ASSERT_EQUAL(entry[191], 0);
CU_ASSERT_EQUAL(entry[192], 53);
CU_ASSERT_NSTRING_EQUAL(entry + 193, "bytes bytes bytes bytes bytes bytes"
" bytes bytes bytes", 53);
/* 23th component */
CU_ASSERT_EQUAL(entry[246], 0x4); /* parent */
CU_ASSERT_EQUAL(entry[247], 0);
@ -1379,15 +1379,15 @@ static void test_rrip_get_susp_fields_symlink()
CU_ASSERT_NSTRING_EQUAL(entry + 250, "bytes", 5);
susp_info_free(&susp);
free(node);
free(link);
}
void add_rockridge_suite()
void add_rockridge_suite()
{
CU_pSuite pSuite = CU_add_suite("RockRidge Suite", NULL, NULL);
CU_add_test(pSuite, "rrip_calc_len(file)", test_rrip_calc_len_file);
CU_add_test(pSuite, "rrip_calc_len(symlink)", test_rrip_calc_len_symlink);
CU_add_test(pSuite, "rrip_get_susp_fields(file)", test_rrip_get_susp_fields_file);