2009-11-12 Robert Millan <rmh.grub@aybabtu.com>

* util/mkisofs/eltorito.c (init_boot_catalog): Handle return code
        of write calls (converting them to fwrite() if they aren't already).
        (get_torito_desc): Likewise.
        * util/mkisofs/rock.c (generate_rock_ridge_attributes): Likewise.
This commit is contained in:
Robert Millan 2009-11-12 21:32:47 +00:00
parent 7f2b34d84e
commit 6e1e0d8954
3 changed files with 36 additions and 26 deletions

View file

@ -1,3 +1,10 @@
2009-11-12 Robert Millan <rmh.grub@aybabtu.com>
* util/mkisofs/eltorito.c (init_boot_catalog): Handle return code
of write calls (converting them to fwrite() if they aren't already).
(get_torito_desc): Likewise.
* util/mkisofs/rock.c (generate_rock_ridge_attributes): Likewise.
2009-11-12 Robert Millan <rmh.grub@aybabtu.com> 2009-11-12 Robert Millan <rmh.grub@aybabtu.com>
* util/i386/pc/grub-install.in: Move from here ... * util/i386/pc/grub-install.in: Move from here ...

View file

@ -59,8 +59,7 @@ static int tvd_write __PR((FILE * outfile));
*/ */
void FDECL1(init_boot_catalog, const char *, path) void FDECL1(init_boot_catalog, const char *, path)
{ {
FILE *bcat;
int bcat;
char * bootpath; /* filename of boot catalog */ char * bootpath; /* filename of boot catalog */
char * buf; char * buf;
struct stat statbuf; struct stat statbuf;
@ -108,19 +107,22 @@ void FDECL1(init_boot_catalog, const char *, path)
* file does not exist, so we create it * file does not exist, so we create it
* make it one CD sector long * make it one CD sector long
*/ */
bcat = open(bootpath, O_WRONLY | O_CREAT | O_BINARY, S_IROTH | S_IRGRP | S_IRWXU ); bcat = fopen (bootpath, "wb");
if (bcat == -1) if (bcat == NULL)
error (1, errno, "Error creating boot catalog (%s)", bootpath); error (1, errno, "Error creating boot catalog (%s)", bootpath);
buf = (char *) e_malloc( 2048 ); buf = (char *) e_malloc( 2048 );
write(bcat, buf, 2048); if (fwrite (buf, 1, 2048, bcat) != 2048)
close(bcat); error (1, errno, "Error writing to boot catalog (%s)", bootpath);
fclose (bcat);
chmod (bootpath, S_IROTH | S_IRGRP | S_IRWXU);
free(bootpath); free(bootpath);
} /* init_boot_catalog(... */ } /* init_boot_catalog(... */
void FDECL1(get_torito_desc, struct eltorito_boot_descriptor *, boot_desc) void FDECL1(get_torito_desc, struct eltorito_boot_descriptor *, boot_desc)
{ {
int bootcat; FILE *bootcat;
int checksum; int checksum;
unsigned char * checksum_ptr; unsigned char * checksum_ptr;
struct directory_entry * de; struct directory_entry * de;
@ -263,38 +265,36 @@ void FDECL1(get_torito_desc, struct eltorito_boot_descriptor *, boot_desc)
/* /*
* now write it to disk * now write it to disk
*/ */
bootcat = open(de2->whole_name, O_RDWR | O_BINARY); bootcat = fopen (de2->whole_name, "r+b");
if (bootcat == -1) if (bootcat == NULL)
{ error (1, errno, "Error opening boot catalog for update");
fprintf(stderr,"Error opening boot catalog for update.\n");
perror("");
exit(1);
}
/* /*
* write out * write out
*/ */
write(bootcat, &valid_desc, 32); if (fwrite (&valid_desc, 1, 32, bootcat) != 32)
write(bootcat, &default_desc, 32); error (1, errno, "Error writing to boot catalog");
close(bootcat); if (fwrite (&default_desc, 1, 32, bootcat) != 32)
error (1, errno, "Error writing to boot catalog");
fclose (bootcat);
/* If the user has asked for it, patch the boot image */ /* If the user has asked for it, patch the boot image */
if (use_boot_info_table) if (use_boot_info_table)
{ {
int bootimage; FILE *bootimage;
uint32_t bi_checksum; uint32_t bi_checksum;
unsigned int total_len; unsigned int total_len;
static char csum_buffer[SECTOR_SIZE]; static char csum_buffer[SECTOR_SIZE];
int len; int len;
struct eltorito_boot_info bi_table; struct eltorito_boot_info bi_table;
bootimage = open (de->whole_name, O_RDWR | O_BINARY); bootimage = fopen (de->whole_name, "r+b");
if (bootimage == -1) if (bootimage == NULL)
error (1, errno, "Error opening boot image file '%s' for update", error (1, errno, "Error opening boot image file '%s' for update",
de->whole_name); de->whole_name);
/* Compute checksum of boot image, sans 64 bytes */ /* Compute checksum of boot image, sans 64 bytes */
total_len = 0; total_len = 0;
bi_checksum = 0; bi_checksum = 0;
while ((len = read (bootimage, csum_buffer, SECTOR_SIZE)) > 0) while ((len = fread (csum_buffer, 1, SECTOR_SIZE, bootimage)) > 0)
{ {
if (total_len & 3) if (total_len & 3)
error (1, 0, "Odd alignment at non-end-of-file in boot image '%s'", error (1, 0, "Odd alignment at non-end-of-file in boot image '%s'",
@ -312,7 +312,7 @@ void FDECL1(get_torito_desc, struct eltorito_boot_descriptor *, boot_desc)
error (1, 0, "Boot image file '%s' changed underneath us", error (1, 0, "Boot image file '%s' changed underneath us",
de->whole_name); de->whole_name);
/* End of file, set position to byte 8 */ /* End of file, set position to byte 8 */
lseek (bootimage, (off_t) 8, SEEK_SET); fseeko (bootimage, (off_t) 8, SEEK_SET);
memset (&bi_table, 0, sizeof (bi_table)); memset (&bi_table, 0, sizeof (bi_table));
/* Is it always safe to assume PVD is at session_start+16? */ /* Is it always safe to assume PVD is at session_start+16? */
set_731 (bi_table.pvd_addr, session_start + 16); set_731 (bi_table.pvd_addr, session_start + 16);
@ -320,8 +320,9 @@ void FDECL1(get_torito_desc, struct eltorito_boot_descriptor *, boot_desc)
set_731 (bi_table.file_length, de->size); set_731 (bi_table.file_length, de->size);
set_731 (bi_table.file_checksum, bi_checksum); set_731 (bi_table.file_checksum, bi_checksum);
write (bootimage, &bi_table, sizeof (bi_table)); /* FIXME: check return value */ if (fwrite (&bi_table, 1, sizeof (bi_table), bootimage) != sizeof (bi_table))
close (bootimage); error (1, errno, "Error writing to boot image (%s)", bootimage);
fclose (bootimage);
} }
} /* get_torito_desc(... */ } /* get_torito_desc(... */

View file

@ -45,6 +45,7 @@ static char rcsid[] ="$Id: rock.c,v 1.8 1999/03/02 03:41:26 eric Exp $";
#include "mkisofs.h" #include "mkisofs.h"
#include "iso9660.h" #include "iso9660.h"
#include <string.h> #include <string.h>
#include <errno.h>
#ifdef DOESNT_WORK #ifdef DOESNT_WORK
@ -480,7 +481,8 @@ int deep_opt;
OK_flag = 1; OK_flag = 1;
zipfile = fopen(whole_name, "rb"); zipfile = fopen(whole_name, "rb");
fread(header, 1, sizeof(header), zipfile); if (fread (header, 1, sizeof (header), zipfile) != sizeof(header))
error (1, errno, "fread");
/* Check some magic numbers from gzip. */ /* Check some magic numbers from gzip. */
if(header[0] != 0x1f || header[1] != 0x8b || header[2] != 8) OK_flag = 0; if(header[0] != 0x1f || header[1] != 0x8b || header[2] != 8) OK_flag = 0;