Hi All, I've been playing around with GRUB, trying to get it to install itself onto a disk image I've made. I kept on getting strange error messages, so I had a delve into the code and came up with the included patch. The problem with the current code, is that when you're installing under Linux it assumes that the partitions will always be broken out into their own files. If, for example, I'm installing to "disk.img", it will try and access the first partition as a file called "disk.img1" (note the '1' at the end); rather than from the same file. This (arguably) does the right thing when installing to a disk under Linux; but doesn't do the right thing if you're working with images.
The included patch adds a check in the appropriate place and handles both block devices and regular files appropriately. I'm not too sure if it does the right thing, but it appears to work for me. . . Hope that all makes sense, Sam
--- stage2/disk_io.c~ 2002-12-04 22:54:14.000000000 +0000 +++ stage2/disk_io.c 2003-12-15 11:03:25.000000000 +0000 @@ -334,6 +334,25 @@ return 1; } +#if defined(GRUB_UTIL) && defined(__linux__) + +#include <sys/types.h> +#include <sys/stat.h> +#include <unistd.h> + +int +is_block_device(const char * name) +{ + struct stat fs; + + if (stat (name, &fs) == -1) + return -1; + + return S_ISBLK (fs.st_mode) ? 1 : 0; +} + +#endif /* GRUB_UTIL && __linux__ */ + int devwrite (int sector, int sector_count, char *buf) { @@ -344,11 +363,23 @@ embed a Stage 1.5 into a partition instead of a MBR, use system calls directly instead of biosdisk, because of the bug in Linux. *sigh* */ - return write_to_partition (device_map, current_drive, current_partition, - sector, sector_count, buf); + switch (is_block_device (device_map[current_drive])) + { + case -1: + errnum = ERR_NO_PART; + return 0; + + case 0: + break; + + case 1: + return write_to_partition (device_map, current_drive, + current_partition, sector, + sector_count, buf); + } } - else #endif /* GRUB_UTIL && __linux__ */ { int i;
_______________________________________________ Bug-grub mailing list [EMAIL PROTECTED] http://mail.gnu.org/mailman/listinfo/bug-grub