[Libburn] libisofs patch
Todd Kulesza
todd@dropline.net
Thu, 05 Feb 2004 13:55:16 -0500
--=-kzgRgKXwtT6jC8qDGeIt
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
The attached patch gets libisofs a nip closer to creating actual ISO
images. It fixes a couple of bugs in the current code when converting
between big and little-endian byte orders and sets up the code for
keeping track of the current logical block. If there are no objections,
I'll press ahead and try to get code written to calculate the disc Path
Tables.
Todd
--=-kzgRgKXwtT6jC8qDGeIt
Content-Disposition: attachment; filename=burn.diff
Content-Type: text/x-patch; name=burn.diff; charset=
Content-Transfer-Encoding: 7bit
? libburn/null.lo
Index: libburn/libburn.h
===================================================================
RCS file: /cvs/burn/burn/libburn/libburn.h,v
retrieving revision 1.190
diff -p -u -r1.190 libburn.h
--- libburn/libburn.h 1 Feb 2004 06:11:00 -0000 1.190
+++ libburn/libburn.h 5 Feb 2004 18:36:03 -0000
@@ -263,7 +263,7 @@ struct burn_source {
/** Read data from the source */
int (*read)(struct burn_source *,
unsigned char *buffer,
- int size);
+ int size);
/** Read subchannel data from the source (NULL if lib generated) */
int (*read_sub)(struct burn_source *,
Index: libisofs/util.c
===================================================================
RCS file: /cvs/burn/burn/libisofs/util.c,v
retrieving revision 1.2
diff -p -u -r1.2 util.c
--- libisofs/util.c 3 Dec 2003 20:01:58 -0000 1.2
+++ libisofs/util.c 5 Feb 2004 18:36:03 -0000
@@ -131,7 +131,7 @@ iso_lsb(unsigned char *buf, int num, int
assert (bytes <= sizeof (int));
for (i = 0; i < bytes; ++i)
- buf[i] = num << (sizeof (int)-1-i) >> (sizeof (int) - 1) << i;
+ buf[i] = (num >> (8 * i)) & 0xff;
}
void
@@ -142,20 +142,18 @@ iso_msb(unsigned char *buf, int num, int
assert (bytes <= sizeof (int));
for (i = 0; i < bytes; ++i)
- buf[bytes - 1 - i] =
- num << (sizeof (int)-1-i) >> (sizeof (int) - 1) << i;
+ buf[bytes - 1 - i] = (num >> (8 * i)) & 0xff;
}
void
iso_bb(unsigned char *buf, int num, int bytes)
{
int i;
-
+
assert (bytes <= sizeof (int));
-
+
for (i = 0; i < bytes; ++i)
- buf[i] = buf[2 * bytes - 1 - i] =
- num << (sizeof (int)-1-i) >> (sizeof (int) - 1) << i;
+ buf[i] = buf[2 * bytes - 1 - i] = (num >> (8 * i)) & 0xff;
}
void
Index: libisofs/writer.c
===================================================================
RCS file: /cvs/burn/burn/libisofs/writer.c,v
retrieving revision 1.14
diff -p -u -r1.14 writer.c
--- libisofs/writer.c 12 Dec 2003 23:01:06 -0000 1.14
+++ libisofs/writer.c 5 Feb 2004 18:36:03 -0000
@@ -35,6 +35,29 @@ static int iso_write_dir_record (struct
static void iso_write_file_id (unsigned char *buf, int size,
struct iso_tree_file **f);
+static int
+get_path_table_size (struct iso_tree_dir **ddir)
+{
+ int i, size = 0;
+ struct iso_tree_dir *dir = *ddir;
+
+ assert (dir);
+
+ if (dir->isoname1)
+ size += strlen (dir->isoname1);
+ else
+ {
+ /* if dir->isoname1 is NULL, this is the root dir and will have
+ * a path record of 10 bytes */
+ size += 10;
+ }
+
+ for (i = 0; i < dir->nchildren; i++)
+ size += get_path_table_size (dir->children[i].me);
+
+ return size;
+}
+
struct burn_source*
iso_source_new (struct iso_volumeset *volumeset,
int volume)
@@ -62,7 +85,9 @@ iso_source_new (struct iso_volumeset *vo
src = malloc (sizeof (struct burn_source));
src->refcount = 1;
src->free_data = iso_source_free;
- src->read = iso_source_generate;
+ src->read = (int (*)(struct burn_source *,
+ unsigned char *buffer,
+ int size)) iso_source_generate;
src->read_sub = NULL;
src->get_size = iso_source_get_size;
src->data = t;
@@ -76,7 +101,7 @@ iso_source_free (struct burn_source *src
assert (src->read == iso_source_generate &&
src->read_sub == NULL &&
- src->get_size == iso_source_get_size);
+ src->get_size == iso_source_get_size);
iso_volumeset_free (target->volset);
free (target);
@@ -89,8 +114,9 @@ iso_dir_layout (struct iso_write_target
int i;
struct iso_tree_dir *dir = *ddir;
- dir->logical_block = 0;
- dir->size = 0;
+ dir->logical_block = target->logical_block;
+ target->logical_block++;
+ dir->size = 0; /* FIXME: wtf goes here? */
for (i = 0; i < dir->nfiles; ++i) {
dir->files[i].logical_block = 0;
@@ -104,20 +130,36 @@ iso_dir_layout (struct iso_write_target
void
iso_target_layout (struct iso_write_target *target)
{
+ /* logical block numbering starts at 1, not 0 */
+ target->logical_block = 1;
target->total_size = 0;
/* system area */
+ target->logical_block += 16;
target->total_size += 16 * target->phys_sector_size;
/* primary volume descriptor */
+ target->logical_block++;
target->total_size += target->phys_sector_size;
/* volume descriptor terminator */
+ target->logical_block++;
target->total_size += target->phys_sector_size;
- target->volume_space_size = 0;
+ /* 16 logical blocks for the System Area plus at least 2 for
+ * the Data Area (primary volume and volume terminator) */
+ target->volume_space_size = 18;
target->logical_block_size = 2048;
- target->path_table_size = 0;
- target->l_path_table_pos = 0;
- target->m_path_table_pos = 0;
-
+ target->path_table_size = get_path_table_size (target->volset->root);
+ /* leave a 1-block buffer between the volume descriptor and the start
+ * of the path tables */
+ target->l_path_table_pos = 19;
+ target->volume_space_size += 2;
+ target->logical_block += 2;
+ target->total_size += 2 * target->phys_sector_size;
+ /* leave a 1-block buffer after each path table */
+ target->m_path_table_pos = 21;
+ target->volume_space_size += 2;
+ target->logical_block += 2;
+ target->total_size += 2 * target->phys_sector_size;
+
iso_dir_layout (target, target->volset->root);
}
@@ -150,8 +192,10 @@ iso_next_state (struct iso_write_target
case ISO_WRITE_VOL_DESC_TERMINATOR:
break;
case ISO_WRITE_L_PATH_TABLE:
+ target->state_data.path_tables.sectors = 0;
break;
case ISO_WRITE_M_PATH_TABLE:
+ target->state_data.path_tables.sectors = 0;
break;
case ISO_WRITE_DONE:
break;
@@ -388,6 +432,6 @@ int iso_write_path_table (struct iso_wri
{
struct iso_state_path_tables *state = &t->state_data.path_tables;
-
- return 1;
+ memset (buffer, 0, t->phys_sector_size);
+ return (++state->sectors == 2);
}
Index: libisofs/writer.h
===================================================================
RCS file: /cvs/burn/burn/libisofs/writer.h,v
retrieving revision 1.9
diff -p -u -r1.9 writer.h
--- libisofs/writer.h 10 Dec 2003 05:45:26 -0000 1.9
+++ libisofs/writer.h 5 Feb 2004 18:36:03 -0000
@@ -45,6 +45,8 @@ struct iso_write_target
/* size of the total output */
int total_size;
+ /* the next available logical block */
+ int logical_block;
/* The number of Logical Blocks for the Volume Space */
int volume_space_size;
/* The Logical Block size */
@@ -65,6 +67,9 @@ struct iso_write_target
int sectors;
} system_area;
struct iso_state_path_tables {
+ /* how many sectors in the path table area have been
+ written */
+ int sectors;
} path_tables;
} state_data;
};
--=-kzgRgKXwtT6jC8qDGeIt--