Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.sbin/makefs - simple fseek->fseeko conversion. probably ...
details: https://anonhg.NetBSD.org/src/rev/a6edccaa1f9f
branches: trunk
changeset: 758148:a6edccaa1f9f
user: christos <christos%NetBSD.org@localhost>
date: Fri Oct 22 00:49:15 2010 +0000
description:
- simple fseek->fseeko conversion. probably needs more work.
- use a constant instead of sprinkling 2048 everywhere.
diffstat:
usr.sbin/makefs/cd9660.h | 13 ++--
usr.sbin/makefs/cd9660/cd9660_debug.c | 26 +++++----
usr.sbin/makefs/cd9660/cd9660_eltorito.c | 9 ++-
usr.sbin/makefs/cd9660/cd9660_write.c | 80 ++++++++++++++++++--------------
4 files changed, 71 insertions(+), 57 deletions(-)
diffs (truncated from 380 to 300 lines):
diff -r 7c72f971813d -r a6edccaa1f9f usr.sbin/makefs/cd9660.h
--- a/usr.sbin/makefs/cd9660.h Thu Oct 21 11:43:22 2010 +0000
+++ b/usr.sbin/makefs/cd9660.h Fri Oct 22 00:49:15 2010 +0000
@@ -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);
diff -r 7c72f971813d -r a6edccaa1f9f usr.sbin/makefs/cd9660/cd9660_debug.c
--- a/usr.sbin/makefs/cd9660/cd9660_debug.c Thu Oct 21 11:43:22 2010 +0000
+++ b/usr.sbin/makefs/cd9660/cd9660_debug.c Fri Oct 22 00:49:15 2010 +0000
@@ -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);
diff -r 7c72f971813d -r a6edccaa1f9f usr.sbin/makefs/cd9660/cd9660_eltorito.c
--- a/usr.sbin/makefs/cd9660/cd9660_eltorito.c Thu Oct 21 11:43:22 2010 +0000
+++ b/usr.sbin/makefs/cd9660/cd9660_eltorito.c Fri Oct 22 00:49:15 2010 +0000
@@ -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",
diff -r 7c72f971813d -r a6edccaa1f9f usr.sbin/makefs/cd9660/cd9660_write.c
--- a/usr.sbin/makefs/cd9660/cd9660_write.c Thu Oct 21 11:43:22 2010 +0000
+++ b/usr.sbin/makefs/cd9660/cd9660_write.c Fri Oct 22 00:49:15 2010 +0000
@@ -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 @@
Home |
Main Index |
Thread Index |
Old Index