From 2c55dbc0d53c1e78936a83602d8e0179f82452b2 Mon Sep 17 00:00:00 2001 From: Robert Millan Date: Wed, 11 Nov 2009 00:23:29 +0000 Subject: [PATCH] 2009-11-11 Robert Millan Large file support for grub-mkisofs. * conf/common.rmk (grub_mkisofs_CFLAGS): Add `-D_FILE_OFFSET_BITS=64'. * util/mkisofs/mkisofs.c (next_extent, last_extent) (session_start): Upgrade type to `uint64_t'. Update all users. * util/mkisofs/mkisofs.h: Include `'. (struct directory_entry): Upgrade type of `starting_block' and `size' to `uint64_t'. Update all users. (struct deferred): Remove unused structure. (xfwrite): Upgrade type of `count' and `size' to `uint64_t'. Update all users. * util/mkisofs/tree.c (stat_filter, lstat_filter): Return -1 when file is larger than `UINT32_MAX'. * util/mkisofs/write.c (xfwrite): Upgrade type of `count' and `size' to `uint64_t'. Update all users. Fix handling of fwrite() return value. (struct deferred_write): Upgrade type of `extent' and `size' to `uint64_t'. Update all users. (last_extent_written): Upgrade type to `uint64_t'. Update all users. (write_one_file): Upgrade type of `count' and `size' to `uint64_t'. Update all users. Upgrade type of `remain' to `int64_t' and `use' to `size_t'. Use error() to handle fread() errors. (write_files): Rely on write_one_file() rather than calling xfwrite() directly. --- ChangeLog | 28 +++++++++++++++++++++++++ conf/common.rmk | 4 +++- util/mkisofs/mkisofs.c | 8 +++---- util/mkisofs/mkisofs.h | 23 +++++++-------------- util/mkisofs/tree.c | 14 +++++++++++-- util/mkisofs/write.c | 47 +++++++++++++++++++----------------------- 6 files changed, 76 insertions(+), 48 deletions(-) diff --git a/ChangeLog b/ChangeLog index 33e154e99..b27b5e290 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,31 @@ +2009-11-11 Robert Millan + + Large file support for grub-mkisofs. + + * conf/common.rmk (grub_mkisofs_CFLAGS): Add `-D_FILE_OFFSET_BITS=64'. + * util/mkisofs/mkisofs.c (next_extent, last_extent) + (session_start): Upgrade type to `uint64_t'. Update all users. + * util/mkisofs/mkisofs.h: Include `'. + (struct directory_entry): Upgrade type of `starting_block' and + `size' to `uint64_t'. Update all users. + (struct deferred): Remove unused structure. + (xfwrite): Upgrade type of `count' and `size' to `uint64_t'. + Update all users. + * util/mkisofs/tree.c (stat_filter, lstat_filter): Return -1 when + file is larger than `UINT32_MAX'. + * util/mkisofs/write.c (xfwrite): Upgrade type of `count' and + `size' to `uint64_t'. Update all users. Fix handling of fwrite() + return value. + (struct deferred_write): Upgrade type of `extent' and `size' to + `uint64_t'. Update all users. + (last_extent_written): Upgrade type to `uint64_t'. Update all + users. + (write_one_file): Upgrade type of `count' and `size' to `uint64_t'. + Update all users. Upgrade type of `remain' to `int64_t' and + `use' to `size_t'. Use error() to handle fread() errors. + (write_files): Rely on write_one_file() rather than calling + xfwrite() directly. + 2009-11-09 Felix Zielcke * util/mkisofs/mkisofs.c (ld_options): Fix a spelling mistake. diff --git a/conf/common.rmk b/conf/common.rmk index 6340373c3..a66bd97fd 100644 --- a/conf/common.rmk +++ b/conf/common.rmk @@ -37,7 +37,9 @@ grub_mkisofs_SOURCES = util/mkisofs/eltorito.c \ util/mkisofs/write.c \ \ gnulib/fnmatch.c gnulib/getopt1.c gnulib/getopt.c -grub_mkisofs_CFLAGS = -I$(srcdir)/util/mkisofs/include -I$(srcdir)/gnulib -Wno-all -Werror +grub_mkisofs_CFLAGS = -D_FILE_OFFSET_BITS=64 \ + -I$(srcdir)/util/mkisofs/include -I$(srcdir)/gnulib \ + -Wno-all -Werror # For grub-fstest. util/grub-fstest.c_DEPENDENCIES = grub_fstest_init.h diff --git a/util/mkisofs/mkisofs.c b/util/mkisofs/mkisofs.c index 8e256c005..8497723e6 100644 --- a/util/mkisofs/mkisofs.c +++ b/util/mkisofs/mkisofs.c @@ -68,9 +68,9 @@ static char version_string[] = "mkisofs 1.12b5"; char * outfile; FILE * discimage; -unsigned int next_extent = 0; -unsigned int last_extent = 0; -unsigned int session_start = 0; +uint64_t next_extent = 0; +uint64_t last_extent = 0; +uint64_t session_start = 0; unsigned int path_table_size = 0; unsigned int path_table[4] = {0,}; unsigned int path_blocks = 0; @@ -1365,7 +1365,7 @@ parse_input_files: fprintf(stderr,"Max brk space used %x\n", (unsigned int)(((unsigned long)sbrk(0)) - mem_start)); #endif - fprintf(stderr,"%d extents written (%d Mb)\n", last_extent, last_extent >> 9); + fprintf (stderr, "%llu extents written (%llu MiB)\n", last_extent, last_extent >> 9); } #ifdef VMS diff --git a/util/mkisofs/mkisofs.h b/util/mkisofs/mkisofs.h index e32918682..52acc72b5 100644 --- a/util/mkisofs/mkisofs.h +++ b/util/mkisofs/mkisofs.h @@ -26,6 +26,7 @@ */ #include +#include #include #include @@ -159,8 +160,8 @@ struct directory_entry{ struct directory_entry * next; struct directory_entry * jnext; struct iso_directory_record isorec; - unsigned int starting_block; - unsigned int size; + uint64_t starting_block; + uint64_t size; unsigned short priority; unsigned char jreclen; /* Joliet record len */ char * name; @@ -266,21 +267,13 @@ struct directory{ unsigned short dir_nlink; }; -struct deferred{ - struct deferred * next; - unsigned int starting_block; - char * name; - struct directory * filedir; - unsigned int flags; -}; - extern int goof; extern struct directory * root; extern struct directory * reloc_dir; -extern unsigned int next_extent; -extern unsigned int last_extent; -extern unsigned int last_extent_written; -extern unsigned int session_start; +extern uint64_t next_extent; +extern uint64_t last_extent; +extern uint64_t last_extent_written; +extern uint64_t session_start; extern unsigned int path_table_size; extern unsigned int path_table[4]; @@ -353,7 +346,7 @@ extern void DECL(generate_one_directory,(struct directory *, FILE*)); extern void DECL(memcpy_max, (char *, char *, int)); extern int DECL(oneblock_size, (int starting_extent)); extern struct iso_primary_descriptor vol_desc; -extern void DECL(xfwrite, (void * buffer, int count, int size, FILE * file)); +extern void DECL(xfwrite, (void * buffer, uint64_t count, uint64_t size, FILE * file)); extern void DECL(set_732, (char * pnt, unsigned int i)); extern void DECL(set_722, (char * pnt, unsigned int i)); extern void DECL(outputlist_insert, (struct output_fragment * frag)); diff --git a/util/mkisofs/tree.c b/util/mkisofs/tree.c index 9d5418965..355dd9873 100644 --- a/util/mkisofs/tree.c +++ b/util/mkisofs/tree.c @@ -6,9 +6,11 @@ Copyright 1993 Yggdrasil Computing, Incorporated + Copyright (C) 2009 Free Software Foundation, Inc. + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2, or (at your option) + the Free Software Foundation; either version 3, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -17,7 +19,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software + along with this program; if not, see . Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ static char rcsid[] ="$Id: tree.c,v 1.29 1999/03/07 17:41:19 eric Exp $"; @@ -141,6 +143,10 @@ FDECL2(stat_filter, char *, path, struct stat *, st) int result = stat(path, st); if (result >= 0 && rationalize) stat_fix(st); + + if ((unsigned) st->st_size > UINT32_MAX) + result = -1; + return result; } @@ -150,6 +156,10 @@ FDECL2(lstat_filter, char *, path, struct stat *, st) int result = lstat(path, st); if (result >= 0 && rationalize) stat_fix(st); + + if ((unsigned) st->st_size > UINT32_MAX) + result = -1; + return result; } diff --git a/util/mkisofs/write.c b/util/mkisofs/write.c index 8d46d89c6..7c4540492 100644 --- a/util/mkisofs/write.c +++ b/util/mkisofs/write.c @@ -127,7 +127,7 @@ void FDECL2(set_733, char *, pnt, unsigned int, i) pnt[4] = pnt[3] = (i >> 24) & 0xff; } -void FDECL4(xfwrite, void *, buffer, int, count, int, size, FILE *, file) +void FDECL4(xfwrite, void *, buffer, uint64_t, count, uint64_t, size, FILE *, file) { /* * This is a hack that could be made better. XXXIs this the only place? @@ -156,11 +156,11 @@ void FDECL4(xfwrite, void *, buffer, int, count, int, size, FILE *, file) } while(count) { - int got = fwrite(buffer,size,count,file); + size_t got = fwrite (buffer, size, count, file); - if(got<=0) + if (got != count) { - fprintf(stderr,"cannot fwrite %d*%d\n",size,count); + fprintf(stderr,"cannot fwrite %llu*%llu\n",size,count); exit(1); } count-=got,*(char**)&buffer+=size*got; @@ -171,14 +171,14 @@ struct deferred_write { struct deferred_write * next; char * table; - unsigned int extent; - unsigned int size; + uint64_t extent; + uint64_t size; char * name; }; static struct deferred_write * dw_head = NULL, * dw_tail = NULL; -unsigned int last_extent_written =0; +uint64_t last_extent_written = 0; static unsigned int path_table_index; static time_t begun; @@ -235,12 +235,12 @@ static int FDECL1(assign_directory_addresses, struct directory *, node) } static void FDECL3(write_one_file, char *, filename, - unsigned int, size, FILE *, outfile) + uint64_t, size, FILE *, outfile) { char buffer[SECTOR_SIZE * NSECT]; FILE * infile; - int remain; - unsigned int use; + int64_t remain; + size_t use; if ((infile = fopen(filename, "rb")) == NULL) @@ -260,10 +260,7 @@ static void FDECL3(write_one_file, char *, filename, use = ROUND_UP(use); /* Round up to nearest sector boundary */ memset(buffer, 0, use); if (fread(buffer, 1, use, infile) == 0) - { - fprintf(stderr,"cannot read from %s\n",filename); - exit(1); - } + error (1, errno, "cannot read %llu bytes from %s", use, filename); xfwrite(buffer, 1, use, outfile); last_extent_written += use/SECTOR_SIZE; #if 0 @@ -298,12 +295,10 @@ static void FDECL1(write_files, FILE *, outfile) { if(dwpnt->table) { - xfwrite(dwpnt->table, 1, ROUND_UP(dwpnt->size), outfile); - last_extent_written += ROUND_UP(dwpnt->size) / SECTOR_SIZE; - table_size += dwpnt->size; -/* fprintf(stderr,"Size %d ", dwpnt->size); */ - free(dwpnt->table); - } + write_one_file (dwpnt->table, dwpnt->size, outfile); + table_size += dwpnt->size; + free (dwpnt->table); + } else { @@ -673,7 +668,7 @@ static void FDECL1(assign_file_addresses, struct directory *, dpnt) last_extent += ROUND_UP(s_entry->size) >> 11; if(verbose > 2) { - fprintf(stderr,"%d %d %s\n", s_entry->starting_block, + fprintf(stderr,"%llu %llu %s\n", s_entry->starting_block, last_extent-1, whole_path); } #ifdef DBG_ISO @@ -1131,17 +1126,17 @@ static int FDECL1(file_write, FILE *, outfile) if( print_size > 0 ) { - fprintf(stderr,"Total extents scheduled to be written = %d\n", + fprintf(stderr,"Total extents scheduled to be written = %llu\n", last_extent - session_start); exit(0); } if( verbose > 2 ) { #ifdef DBG_ISO - fprintf(stderr,"Total directory extents being written = %d\n", last_extent); + fprintf(stderr,"Total directory extents being written = %llu\n", last_extent); #endif - fprintf(stderr,"Total extents scheduled to be written = %d\n", + fprintf(stderr,"Total extents scheduled to be written = %llu\n", last_extent - session_start); } @@ -1158,7 +1153,7 @@ static int FDECL1(file_write, FILE *, outfile) return 0; } - fprintf(stderr,"Total extents actually written = %d\n", + fprintf(stderr,"Total extents actually written = %llu\n", last_extent_written - session_start); /* @@ -1168,7 +1163,7 @@ static int FDECL1(file_write, FILE *, outfile) if(should_write + session_start != last_extent) { fprintf(stderr,"Number of extents written not what was predicted. Please fix.\n"); - fprintf(stderr,"Predicted = %d, written = %d\n", should_write, last_extent); + fprintf(stderr,"Predicted = %d, written = %llu\n", should_write, last_extent); } fprintf(stderr,"Total translation table size: %d\n", table_size);