Index: palo/error.c =================================================================== RCS file: /var/cvs/palo/palo/error.c,v retrieving revision 1.7 diff -u -p -r1.7 error.c --- palo/error.c 30 Dec 2003 17:45:02 -0000 1.7 +++ palo/error.c 28 Jan 2005 19:03:10 -0000 @@ -89,7 +89,11 @@ static char *errormessages[] = { "or a ramdisk.\n", /* 19 */ - "mke2fs failed, exit code %d." + "mke2fs failed, exit code %d.", + + /* 20 */ + "Cannot update an uninitialized ext2/3 formatted partition.\n" + }; #define NMESSAGES (sizeof errormessages / sizeof errormessages[0]) Index: palo/palo.c =================================================================== RCS file: /var/cvs/palo/palo/palo.c,v retrieving revision 1.18 diff -u -p -r1.18 palo.c --- palo/palo.c 4 May 2004 21:41:06 -0000 1.18 +++ palo/palo.c 28 Jan 2005 19:03:10 -0000 @@ -440,7 +440,7 @@ do_cdrom(int media, int kernel32, int ke * to cover the first four blocks of the filesystem */ #define EXT2_OFFSET (4*EXT2_BLOCKSIZE) -void +int do_formatted(int init, int media, const char *medianame, int partition, int f0start, int f0length, int bootloaderfd, int do_format, const char *commandline) @@ -468,6 +468,8 @@ do_formatted(int init, int media, const int fd, i; char cmd[512]; + printf("Initializing %s as ext%d\n", partitionname, do_format); + if (verbose) printf("f0 partition starts %d, hole %d-%d, end %d\n", f0start, holestart, holestart + EXT2_HOLE*EXT2_BLOCKSIZE, @@ -524,6 +526,12 @@ do_formatted(int init, int media, const printf("Updating formatted ver=%d, start=%d\n", f.version, f.ipl_addr); + if ((f.version < 4) || (!f.flags & PFLAG_EXT2)) { + printf("Can not update %s. Please initialize first.\n", + partitionname); + return -1; + } + if(commandline) strncpy(f.cmdline, commandline, sizeof(f.cmdline)); @@ -532,6 +540,7 @@ do_formatted(int init, int media, const STRUCTWRITE(media, f, 0); } + return 0; } void @@ -916,24 +925,18 @@ main(int argc, char *argv[]) printf("F0 partition start sector %d length %d\n", ptab[f0].start, ptab[f0].length); } - if (!init) { - STRUCTREAD(media, f, 0); - if (f.version >= 4 && (f.flags & PFLAG_EXT2)) - /* need to update formatted partition */ - format_as = 1; - } if (format_as) { /* if we're going to be a formatted partition, we can't * load anything into it, so check we haven't been asked * to */ - if(kernel32 != -1 || kernel64 != -1 - || ramdisk != -1) - error(18); - printf("OK we're doing a format as ext%d\n", format_as); - do_formatted(init, media, medianame, f0 + 1, + if(kernel32 != -1 || kernel64 != -1 || ramdisk != -1) + error(18); + + if (do_formatted(init, media, medianame, f0 + 1, ptab[f0].start * 512, ptab[f0].length * 512, - bootloader, format_as, commandline); + bootloader, format_as, commandline)) + error(20); } else do_randomaccess(init, media, kernel32, kernel64, commandline, bootloader, ramdisk, ptab[f0].start * 512,