Module Name:    src
Committed By:   christos
Date:           Fri Oct 22 00:49:16 UTC 2010

Modified Files:
        src/usr.sbin/makefs: cd9660.h
        src/usr.sbin/makefs/cd9660: cd9660_debug.c cd9660_eltorito.c
            cd9660_write.c

Log Message:
- simple fseek->fseeko conversion. probably needs more work.
- use a constant instead of sprinkling 2048 everywhere.


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/usr.sbin/makefs/cd9660.h
cvs rdiff -u -r1.9 -r1.10 src/usr.sbin/makefs/cd9660/cd9660_debug.c
cvs rdiff -u -r1.12 -r1.13 src/usr.sbin/makefs/cd9660/cd9660_eltorito.c \
    src/usr.sbin/makefs/cd9660/cd9660_write.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.sbin/makefs/cd9660.h
diff -u src/usr.sbin/makefs/cd9660.h:1.13 src/usr.sbin/makefs/cd9660.h:1.14
--- src/usr.sbin/makefs/cd9660.h:1.13	Sat Jan 10 17:06:29 2009
+++ src/usr.sbin/makefs/cd9660.h	Thu Oct 21 20:49:15 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: cd9660.h,v 1.13 2009/01/10 22:06:29 bjh21 Exp $	*/
+/*	$NetBSD: cd9660.h,v 1.14 2010/10/22 00:49:15 christos Exp $	*/
 
 /*
  * Copyright (c) 2005 Daniel Watt, Walter Deignan, Ryan Gabrys, Alan
@@ -130,11 +130,12 @@
 #define CD9660_TYPE_DIR		0x02
 #define CD9660_TYPE_DOT		0x04
 #define CD9660_TYPE_DOTDOT	0x08
-#define CD9660_TYPE_VIRTUAL 0x80
+#define CD9660_TYPE_VIRTUAL	0x80
 
-#define CD9660_INODE_HASH_SIZE 1024
+#define CD9660_INODE_HASH_SIZE	1024
+#define CD9660_SECTOR_SIZE	2048
 
-#define CD9660_END_PADDING 150
+#define CD9660_END_PADDING	150
 
 /* Slight modification of the ISO structure in iso.h */
 typedef struct _iso_directory_record_cd9660 {
@@ -344,7 +345,7 @@
 
 /*** Write Functions ***/
 int	cd9660_write_image(const char *image);
-int	cd9660_copy_file(FILE *, int, const char *);
+int	cd9660_copy_file(FILE *, off_t, const char *);
 
 void	cd9660_compute_full_filename(cd9660node *, char *, int);
 int	cd9660_compute_record_size(cd9660node *);
@@ -354,7 +355,7 @@
 void	debug_print_path_tree(cd9660node *);
 void	debug_print_volume_descriptor_information(void);
 void	debug_dump_to_xml_ptentry(path_table_entry *,int, int);
-void	debug_dump_to_xml_path_table(FILE *, int, int, int);
+void	debug_dump_to_xml_path_table(FILE *, off_t, int, int);
 void	debug_dump_to_xml(FILE *);
 int	debug_get_encoded_number(unsigned char *, int);
 void	debug_dump_integer(const char *, char *,int);

Index: src/usr.sbin/makefs/cd9660/cd9660_debug.c
diff -u src/usr.sbin/makefs/cd9660/cd9660_debug.c:1.9 src/usr.sbin/makefs/cd9660/cd9660_debug.c:1.10
--- src/usr.sbin/makefs/cd9660/cd9660_debug.c:1.9	Thu Jan  8 17:28:45 2009
+++ src/usr.sbin/makefs/cd9660/cd9660_debug.c	Thu Oct 21 20:49:15 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: cd9660_debug.c,v 1.9 2009/01/08 22:28:45 bjh21 Exp $	*/
+/*	$NetBSD: cd9660_debug.c,v 1.10 2010/10/22 00:49:15 christos Exp $	*/
 
 /*
  * Copyright (c) 2005 Daniel Watt, Walter Deignan, Ryan Gabrys, Alan
@@ -40,7 +40,7 @@
 #include <sys/param.h>
 
 #if defined(__RCSID) && !defined(__lint)
-__RCSID("$NetBSD: cd9660_debug.c,v 1.9 2009/01/08 22:28:45 bjh21 Exp $");
+__RCSID("$NetBSD: cd9660_debug.c,v 1.10 2010/10/22 00:49:15 christos Exp $");
 #endif  /* !__lint */
 
 #if !HAVE_NBTOOL_CONFIG_H
@@ -153,12 +153,12 @@
 debug_print_volume_descriptor_information(void)
 {
 	volume_descriptor *tmp = diskStructure.firstVolumeDescriptor;
-	char temp[2048];
+	char temp[CD9660_SECTOR_SIZE];
 
 	printf("==Listing Volume Descriptors==\n");
 
 	while (tmp != NULL) {
-		memset(temp, 0, 2048);
+		memset(temp, 0, CD9660_SECTOR_SIZE);
 		memcpy(temp, tmp->volumeDescriptorData + 1, 5);
 		printf("Volume descriptor in sector %i: type %i, ID %s\n",
 		    tmp->sector, tmp->volumeDescriptorData[0], temp);
@@ -199,13 +199,14 @@
 }
 
 void
-debug_dump_to_xml_path_table(FILE *fd, int sector, int size, int mode)
+debug_dump_to_xml_path_table(FILE *fd, off_t sector, int size, int mode)
 {
 	path_table_entry pttemp;
 	int t = 0;
 	int n = 0;
 
-	fseek(fd, 2048 * sector, SEEK_SET);
+	if (fseeko(fd, CD9660_SECTOR_SIZE * sector, SEEK_SET) == -1)
+		err(1, "fseeko");
 
 	while (t < size) {
 		/* Read fixed data first */
@@ -229,8 +230,8 @@
 void
 debug_dump_to_xml(FILE *fd)
 {
-	unsigned char buf[2048];
-	int sector;
+	unsigned char buf[CD9660_SECTOR_SIZE];
+	off_t sector;
 	int t, t2;
 	struct iso_primary_descriptor primaryVD;
 	struct _boot_volume_descriptor bootVD;
@@ -240,15 +241,16 @@
 	/* Display Volume Descriptors */
 	sector = 16;
 	do {
-		fseek(fd, 2048*sector, SEEK_SET);
-		fread(buf, 1, 2048, fd);
+		if (fseeko(fd, CD9660_SECTOR_SIZE * sector, SEEK_SET) == -1)
+			err(1, "fseeko");
+		fread(buf, 1, CD9660_SECTOR_SIZE, fd);
 		t = (int)((unsigned char)buf[0]);
 		switch (t) {
 		case 0:
-			memcpy(&bootVD, buf, 2048);
+			memcpy(&bootVD, buf, CD9660_SECTOR_SIZE);
 			break;
 		case 1:
-			memcpy(&primaryVD, buf, 2048);
+			memcpy(&primaryVD, buf, CD9660_SECTOR_SIZE);
 			break;
 		}
 		debug_dump_to_xml_volume_descriptor(buf, sector);

Index: src/usr.sbin/makefs/cd9660/cd9660_eltorito.c
diff -u src/usr.sbin/makefs/cd9660/cd9660_eltorito.c:1.12 src/usr.sbin/makefs/cd9660/cd9660_eltorito.c:1.13
--- src/usr.sbin/makefs/cd9660/cd9660_eltorito.c:1.12	Sun Jul 27 06:29:32 2008
+++ src/usr.sbin/makefs/cd9660/cd9660_eltorito.c	Thu Oct 21 20:49:15 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: cd9660_eltorito.c,v 1.12 2008/07/27 10:29:32 reinoud Exp $	*/
+/*	$NetBSD: cd9660_eltorito.c,v 1.13 2010/10/22 00:49:15 christos Exp $	*/
 
 /*
  * Copyright (c) 2005 Daniel Watt, Walter Deignan, Ryan Gabrys, Alan
@@ -36,7 +36,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(__lint)
-__RCSID("$NetBSD: cd9660_eltorito.c,v 1.12 2008/07/27 10:29:32 reinoud Exp $");
+__RCSID("$NetBSD: cd9660_eltorito.c,v 1.13 2010/10/22 00:49:15 christos Exp $");
 #endif  /* !__lint */
 
 #ifdef DEBUG
@@ -506,8 +506,9 @@
 	struct cd9660_boot_image *t;
 
 	/* write boot catalog */
-	fseek(fd, diskStructure.boot_catalog_sector * diskStructure.sectorSize,
-	    SEEK_SET);
+	if (fseeko(fd, (off_t)diskStructure.boot_catalog_sector *
+	    diskStructure.sectorSize, SEEK_SET) == -1)
+		err(1, "fseeko");
 
 	if (diskStructure.verbose_level > 0) {
 		printf("Writing boot catalog to sector %d\n",
Index: src/usr.sbin/makefs/cd9660/cd9660_write.c
diff -u src/usr.sbin/makefs/cd9660/cd9660_write.c:1.12 src/usr.sbin/makefs/cd9660/cd9660_write.c:1.13
--- src/usr.sbin/makefs/cd9660/cd9660_write.c:1.12	Sun Nov 22 13:43:27 2009
+++ src/usr.sbin/makefs/cd9660/cd9660_write.c	Thu Oct 21 20:49:15 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: cd9660_write.c,v 1.12 2009/11/22 18:43:27 mbalmer Exp $	*/
+/*	$NetBSD: cd9660_write.c,v 1.13 2010/10/22 00:49:15 christos Exp $	*/
 
 /*
  * Copyright (c) 2005 Daniel Watt, Walter Deignan, Ryan Gabrys, Alan
@@ -37,18 +37,18 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(__lint)
-__RCSID("$NetBSD: cd9660_write.c,v 1.12 2009/11/22 18:43:27 mbalmer Exp $");
+__RCSID("$NetBSD: cd9660_write.c,v 1.13 2010/10/22 00:49:15 christos Exp $");
 #endif  /* !__lint */
 
 static int cd9660_write_volume_descriptors(FILE *);
-static int cd9660_write_path_table(FILE *, int, int);
+static int cd9660_write_path_table(FILE *, off_t, int);
 static int cd9660_write_path_tables(FILE *);
 static int cd9660_write_file(FILE *, cd9660node *);
-static int cd9660_write_filedata(FILE *, int, const unsigned char *, int);
+static int cd9660_write_filedata(FILE *, off_t, const unsigned char *, int);
 #if 0
-static int cd9660_write_buffered(FILE *, int, int, const unsigned char*);
+static int cd9660_write_buffered(FILE *, off_t, int, const unsigned char *);
 #endif
-static void cd9660_write_rr(FILE *, cd9660node *, int, int);
+static void cd9660_write_rr(FILE *, cd9660node *, off_t, off_t);
 
 /*
  * Write the image
@@ -61,7 +61,7 @@
 {
 	FILE *fd;
 	int status;
-	char buf[2048];
+	char buf[CD9660_SECTOR_SIZE];
 
 	if ((fd = fopen(image, "w+")) == NULL) {
 		err(EXIT_FAILURE, "%s: Can't open `%s' for writing", __func__,
@@ -117,7 +117,7 @@
 	}
 
 	/* Write padding bits. This is temporary */
-	memset(buf, 0, 2048);
+	memset(buf, 0, CD9660_SECTOR_SIZE);
 	cd9660_write_filedata(fd, diskStructure.totalSectors - 1, buf, 1);
 
 	if (diskStructure.verbose_level > 0)
@@ -144,7 +144,7 @@
 	int pos;
 
 	while (vd_temp != NULL) {
-		pos = vd_temp->sector*diskStructure.sectorSize;
+		pos = vd_temp->sector * diskStructure.sectorSize;
 		cd9660_write_filedata(fd, vd_temp->sector,
 		    vd_temp->volumeDescriptorData, 1);
 		vd_temp = vd_temp->next;
@@ -161,7 +161,7 @@
  * @returns int 1 on success, 0 on failure
  */
 static int
-cd9660_write_path_table(FILE *fd, int sector, int mode)
+cd9660_write_path_table(FILE *fd, off_t sector, int mode)
 {
 	int path_table_sectors = CD9660_BLOCKS(diskStructure.sectorSize,
 	    diskStructure.pathTableLength);
@@ -266,7 +266,7 @@
 	char *buf;
 	char *temp_file_name;
 	int ret;
-	int working_sector;
+	off_t working_sector;
 	int cur_sector_offset;
 	int written;
 	iso_directory_record_cd9660 temp_record;
@@ -316,7 +316,9 @@
 		 */
 		cur_sector_offset = 0;
 		working_sector = writenode->fileDataSector;
-		fseek(fd, working_sector * diskStructure.sectorSize, SEEK_SET);
+		if (fseeko(fd, working_sector * diskStructure.sectorSize,
+		    SEEK_SET) == -1)
+			err(1, "fseeko");
 
 		/*
 		 * Now loop over children, writing out their directory
@@ -339,9 +341,9 @@
 				working_sector++;
 
 				/* Seek to the next sector. */
-				fseek(fd,
-				    working_sector * diskStructure.sectorSize,
-				    SEEK_SET);
+				if (fseeko(fd, working_sector *
+				    diskStructure.sectorSize, SEEK_SET) == -1)
+					err(1, "fseeko");
 			}
 			/* Write out the basic ISO directory record */
 			written = fwrite(&temp_record, 1,
@@ -350,11 +352,11 @@
 				cd9660_write_rr(fd, temp,
 				    cur_sector_offset, working_sector);
 			}
-			fseek(fd,
-			    working_sector * diskStructure.sectorSize +
-			    cur_sector_offset + temp_record.length[0] -
-			    temp->su_tail_size,
-			    SEEK_SET);
+			if (fseeko(fd, working_sector *
+			    diskStructure.sectorSize + cur_sector_offset +
+			    temp_record.length[0] - temp->su_tail_size,
+			    SEEK_SET) == -1)
+				err(1, "fseeko");
 			if (temp->su_tail_size > 0)
 				fwrite(temp->su_tail_data, 1,
 				    temp->su_tail_size, fd);
@@ -395,7 +397,7 @@
  *                             is written, the rest should be set to 0.
  */
 static int
-cd9660_write_filedata(FILE *fd, int sector, const unsigned char *buf,
+cd9660_write_filedata(FILE *fd, off_t sector, const unsigned char *buf,
 		      int numsecs)
 {
 	off_t curpos;
@@ -403,11 +405,13 @@
 
 	curpos = ftello(fd);
 
-	fseek(fd, sector * diskStructure.sectorSize, SEEK_SET);
+	if (fseeko(fd, sector * diskStructure.sectorSize, SEEK_SET) == -1)
+		err(1, "fseeko");
 
 	success = fwrite(buf, diskStructure.sectorSize * numsecs, 1, fd);
 
-	fseek(fd, curpos, SEEK_SET);
+	if (fseeko(fd, curpos, SEEK_SET) == -1)
+		err(1, "fseeko");
 
 	if (success == 1)
 		success = diskStructure.sectorSize * numsecs;
@@ -416,22 +420,22 @@
 
 #if 0
 static int
-cd9660_write_buffered(FILE *fd, int offset, int buff_len,
+cd9660_write_buffered(FILE *fd, off_t offset, int buff_len,
 		      const unsigned char* buffer)
 {
 	static int working_sector = -1;
-	static char buf[2048];
+	static char buf[CD9660_SECTOR_SIZE];
 
 	return 0;
 }
 #endif
 
 int
-cd9660_copy_file(FILE *fd, int start_sector, const char *filename)
+cd9660_copy_file(FILE *fd, off_t start_sector, const char *filename)
 {
 	FILE *rf;
 	int bytes_read;
-	int sector = start_sector;
+	off_t sector = start_sector;
 	int buf_size = diskStructure.sectorSize;
 	char *buf;
 
@@ -448,7 +452,8 @@
 	if (diskStructure.verbose_level > 1)
 		printf("Writing file: %s\n",filename);
 
-	fseek(fd, start_sector * diskStructure.sectorSize, SEEK_SET);
+	if (fseeko(fd, start_sector * diskStructure.sectorSize, SEEK_SET) == -1)
+		err(1, "fseeko");
 
 	while (!feof(rf)) {
 		bytes_read = fread(buf,1,buf_size,rf);
@@ -473,13 +478,15 @@
 }
 
 static void
-cd9660_write_rr(FILE *fd, cd9660node *writenode, int offset, int sector)
+cd9660_write_rr(FILE *fd, cd9660node *writenode, off_t offset, off_t sector)
 {
 	int in_ca = 0;
 	struct ISO_SUSP_ATTRIBUTES *myattr;
 
 	offset += writenode->isoDirRecord->length[0];
-	fseek(fd, sector * diskStructure.sectorSize + offset, SEEK_SET);
+	if (fseeko(fd, sector * diskStructure.sectorSize + offset, SEEK_SET) ==
+	    -1)
+		err(1, "fseeko");
 	/* Offset now points at the end of the record */
 	TAILQ_FOREACH(myattr, &writenode->head, rr_ll) {
 		fwrite(&(myattr->attr), CD9660_SUSP_ENTRY_SIZE(myattr), 1, fd);
@@ -491,11 +498,12 @@
 				 * Point the offset to the start of this
 				 * record's CE area
 				 */
-				fseek(fd, (diskStructure.
-					susp_continuation_area_start_sector *
-					diskStructure.sectorSize)
+				if (fseeko(fd, ((off_t)diskStructure.
+				    susp_continuation_area_start_sector *
+				    diskStructure.sectorSize)
 				    + writenode->susp_entry_ce_start,
-				    SEEK_SET);
+				    SEEK_SET) == -1)
+					err(1, "fseeko");
 				in_ca = 1;
 			}
 		}
@@ -506,5 +514,7 @@
 	 * where we should be.
 	 */
 	if (in_ca)
-		fseek(fd, sector * diskStructure.sectorSize + offset, SEEK_SET);
+		if (fseeko(fd, sector * diskStructure.sectorSize + offset,
+		    SEEK_SET) == -1)
+			err(1, "fseeko");
 }

Reply via email to