From 5ff128de7b2f3d200c10bf3ff02877e3cb421c13 Mon Sep 17 00:00:00 2001 From: hpa Date: Wed, 22 Dec 2004 07:17:53 +0000 Subject: [PATCH] Fix handling of -o offset --- extlinux/Makefile | 4 ++-- mtools/syslinux.c | 16 ++++++++-------- unix/syslinux.c | 20 ++++++++++---------- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/extlinux/Makefile b/extlinux/Makefile index c3fd5dd..3358f5a 100644 --- a/extlinux/Makefile +++ b/extlinux/Makefile @@ -1,8 +1,8 @@ CC = gcc -OPTFLAGS = -g -Os -DDEBUG +OPTFLAGS = -g -Os INCLUDES = -I. -I.. -I../libfat CFLAGS = -W -Wall -Wno-sign-compare -D_FILE_OFFSET_BITS=64 $(OPTFLAGS) $(INCLUDES) -LDFLAGS = -g +LDFLAGS = -s SRCS = extlinux.c ../extlinux_bss_bin.c ../extlinux_sys_bin.c OBJS = $(patsubst %.c,%.o,$(notdir $(SRCS))) diff --git a/mtools/syslinux.c b/mtools/syslinux.c index 20111c6..2db0a75 100644 --- a/mtools/syslinux.c +++ b/mtools/syslinux.c @@ -42,6 +42,7 @@ char *program; /* Name of program */ char *device; /* Device to install to */ pid_t mypid; +off_t filesystem_offset = 0; /* Offset of filesystem */ void usage(void) { @@ -115,7 +116,7 @@ ssize_t xpwrite(int fd, void *buf, size_t count, off_t offset) */ int libfat_xpread(intptr_t pp, void *buf, size_t secsize, libfat_sector_t sector) { - off_t offset = (off_t)sector * secsize; + off_t offset = (off_t)sector * secsize + filesystem_offset; return xpread(pp, buf, secsize, offset); } @@ -128,7 +129,6 @@ int main(int argc, char *argv[]) int status; char **argp, *opt; int force = 0; /* -f (force) option */ - off_t offset = 0; /* -o (offset) option */ char mtools_conf[] = "/tmp/syslinux-mtools-XXXXXX"; int mtc_fd; FILE *mtc, *mtp; @@ -157,7 +157,7 @@ int main(int argc, char *argv[]) } else if ( *opt == 'f' ) { force = 1; /* Force install */ } else if ( *opt == 'o' && argp[1] ) { - offset = (off_t)strtoull(*++argp, NULL, 0); /* Byte offset */ + filesystem_offset = (off_t)strtoull(*++argp, NULL, 0); /* Byte offset */ } else { usage(); } @@ -188,7 +188,7 @@ int main(int argc, char *argv[]) exit(1); } - xpread(dev_fd, sectbuf, 512, offset); + xpread(dev_fd, sectbuf, 512, filesystem_offset); /* * Check to see that what we got was indeed an MS-DOS boot sector/superblock @@ -214,7 +214,7 @@ int main(int argc, char *argv[]) " offset=%llu\n", (unsigned long)mypid, dev_fd, - (unsigned long long)offset); + (unsigned long long)filesystem_offset); fclose(mtc); /* @@ -270,20 +270,20 @@ int main(int argc, char *argv[]) /* * Write the now-patched first sector of ldlinux.sys */ - xpwrite(dev_fd, syslinux_ldlinux, 512, offset + ((off_t)sectors[0] << 9)); + xpwrite(dev_fd, syslinux_ldlinux, 512, filesystem_offset + ((off_t)sectors[0] << 9)); /* * To finish up, write the boot sector */ /* Read the superblock again since it might have changed while mounted */ - xpread(dev_fd, sectbuf, 512, offset); + xpread(dev_fd, sectbuf, 512, filesystem_offset); /* Copy the syslinux code into the boot sector */ syslinux_make_bootsect(sectbuf); /* Write new boot sector */ - xpwrite(dev_fd, sectbuf, 512, offset); + xpwrite(dev_fd, sectbuf, 512, filesystem_offset); close(dev_fd); sync(); diff --git a/unix/syslinux.c b/unix/syslinux.c index 60d114f..c0cf346 100644 --- a/unix/syslinux.c +++ b/unix/syslinux.c @@ -66,6 +66,7 @@ const char *program; /* Name of program */ const char *device; /* Device to install to */ pid_t mypid; char *mntpath = NULL; /* Path on which to mount */ +off_t filesystem_offset = 0; /* Filesystem offset */ #if DO_DIRECT_MOUNT int loop_fd = -1; /* Loop device */ #endif @@ -154,7 +155,7 @@ ssize_t xpwrite(int fd, void *buf, size_t count, off_t offset) */ int libfat_xpread(intptr_t pp, void *buf, size_t secsize, libfat_sector_t sector) { - off_t offset = (off_t)sector * secsize; + off_t offset = (off_t)sector * secsize + filesystem_offset; return xpread(pp, buf, secsize, offset); } @@ -172,7 +173,6 @@ int main(int argc, char *argv[]) char mntname[64], devfdname[64]; char *ldlinux_name, **argp, *opt; int force = 0; /* -f (force) option */ - off_t offset = 0; /* -o (offset) option */ struct libfat_filesystem *fs; libfat_sector_t s, *secp, sectors[65]; /* 65 is maximum possible */ int32_t ldlinux_cluster; @@ -200,7 +200,7 @@ int main(int argc, char *argv[]) } else if ( *opt == 'f' ) { force = 1; /* Force install */ } else if ( *opt == 'o' && argp[1] ) { - offset = (off_t)strtoull(*++argp, NULL, 0); /* Byte offset */ + filesystem_offset = (off_t)strtoull(*++argp, NULL, 0); /* Byte offset */ } else { usage(); } @@ -230,11 +230,11 @@ int main(int argc, char *argv[]) die("not a block device or regular file (use -f to override)"); } - if ( !force && offset != 0 && !S_ISREG(st.st_mode) ) { + if ( !force && filesystem_offset && !S_ISREG(st.st_mode) ) { die("not a regular file and an offset specified (use -f to override)"); } - xpread(dev_fd, sectbuf, 512, offset); + xpread(dev_fd, sectbuf, 512, filesystem_offset); fsync(dev_fd); /* @@ -316,7 +316,7 @@ int main(int argc, char *argv[]) } if ( ioctl(loop_fd, LOOP_GET_STATUS64, &loopinfo) || - (loopinfo.lo_offset = offset, + (loopinfo.lo_offset = filesystem_offset, ioctl(loop_fd, LOOP_SET_STATUS64, &loopinfo)) ) die("cannot set up loopback device"); } @@ -343,7 +343,7 @@ int main(int argc, char *argv[]) char mnt_opts[128]; if ( S_ISREG(st.st_mode) ) { snprintf(mnt_opts, sizeof mnt_opts, "rw,nodev,noexec,loop,offset=%llu,umask=077,quiet", - (unsigned long long)offset); + (unsigned long long)filesystem_offset); } else { snprintf(mnt_opts, sizeof mnt_opts, "rw,nodev,noexec,umask=077,quiet"); } @@ -464,20 +464,20 @@ umount: /* * Write the now-patched first sector of ldlinux.sys */ - xpwrite(dev_fd, syslinux_ldlinux, 512, offset + ((off_t)sectors[0] << 9)); + xpwrite(dev_fd, syslinux_ldlinux, 512, filesystem_offset + ((off_t)sectors[0] << 9)); /* * To finish up, write the boot sector */ /* Read the superblock again since it might have changed while mounted */ - xpread(dev_fd, sectbuf, 512, offset); + xpread(dev_fd, sectbuf, 512, filesystem_offset); /* Copy the syslinux code into the boot sector */ syslinux_make_bootsect(sectbuf); /* Write new boot sector */ - xpwrite(dev_fd, sectbuf, 512, offset); + xpwrite(dev_fd, sectbuf, 512, filesystem_offset); close(dev_fd); sync(); -- 2.7.4