summaryrefslogtreecommitdiff
path: root/linux
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2009-05-29 15:16:22 -0700
committerH. Peter Anvin <hpa@zytor.com>2009-05-29 15:16:22 -0700
commit5e6aef0b866b1e5c1c458cc8ca2a52092928fb0d (patch)
treed88795d0d3aba72776a20bf8ee4c8778815df3d0 /linux
parentdcd9ae222c665a56a57a560be62b407a04573e13 (diff)
parent8833b1c37f7ecfa41e0e2c26e72c2913d5eba969 (diff)
downloadsyslinux-5e6aef0b866b1e5c1c458cc8ca2a52092928fb0d.tar.gz
Merge branch 'master' into core32
Conflicts: com32/include/netinet/in.h com32/include/sys/cpu.h dos/argv.c dos/malloc.c dos/syslinux.c extlinux/main.c libinstaller/setadv.c libinstaller/syslinux.h libinstaller/syslxint.h libinstaller/syslxmod.c linux/syslinux.c mtools/syslinux.c win32/syslinux.c Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Diffstat (limited to 'linux')
-rw-r--r--linux/syslinux.c757
1 files changed, 379 insertions, 378 deletions
diff --git a/linux/syslinux.c b/linux/syslinux.c
index 10c089c0..02323771 100644
--- a/linux/syslinux.c
+++ b/linux/syslinux.c
@@ -81,28 +81,29 @@ off_t filesystem_offset = 0; /* Filesystem offset */
int loop_fd = -1; /* Loop device */
#endif
-void __attribute__((noreturn)) usage(void)
+void __attribute__ ((noreturn)) usage(void)
{
- fprintf(stderr, "Usage: %s [-sfr][-d directory][-o offset] device\n", program);
- exit(1);
+ fprintf(stderr, "Usage: %s [-sfr][-d directory][-o offset] device\n",
+ program);
+ exit(1);
}
-void __attribute__((noreturn)) die(const char *msg)
+void __attribute__ ((noreturn)) die(const char *msg)
{
- fprintf(stderr, "%s: %s\n", program, msg);
+ fprintf(stderr, "%s: %s\n", program, msg);
#if DO_DIRECT_MOUNT
- if ( loop_fd != -1 ) {
- ioctl(loop_fd, LOOP_CLR_FD, 0); /* Free loop device */
- close(loop_fd);
- loop_fd = -1;
- }
+ if (loop_fd != -1) {
+ ioctl(loop_fd, LOOP_CLR_FD, 0); /* Free loop device */
+ close(loop_fd);
+ loop_fd = -1;
+ }
#endif
- if ( mntpath )
- unlink(mntpath);
+ if (mntpath)
+ unlink(mntpath);
- exit(1);
+ exit(1);
}
/*
@@ -110,91 +111,91 @@ void __attribute__((noreturn)) die(const char *msg)
*/
ssize_t xpread(int fd, void *buf, size_t count, off_t offset)
{
- char *bufp = (char *)buf;
- ssize_t rv;
- ssize_t done = 0;
-
- while ( count ) {
- rv = pread(fd, bufp, count, offset);
- if ( rv == 0 ) {
- die("short read");
- } else if ( rv == -1 ) {
- if ( errno == EINTR ) {
- continue;
- } else {
- die(strerror(errno));
- }
- } else {
- bufp += rv;
- offset += rv;
- done += rv;
- count -= rv;
+ char *bufp = (char *)buf;
+ ssize_t rv;
+ ssize_t done = 0;
+
+ while (count) {
+ rv = pread(fd, bufp, count, offset);
+ if (rv == 0) {
+ die("short read");
+ } else if (rv == -1) {
+ if (errno == EINTR) {
+ continue;
+ } else {
+ die(strerror(errno));
+ }
+ } else {
+ bufp += rv;
+ offset += rv;
+ done += rv;
+ count -= rv;
+ }
}
- }
- return done;
+ return done;
}
ssize_t xpwrite(int fd, const void *buf, size_t count, off_t offset)
{
- const char *bufp = (const char *)buf;
- ssize_t rv;
- ssize_t done = 0;
-
- while ( count ) {
- rv = pwrite(fd, bufp, count, offset);
- if ( rv == 0 ) {
- die("short write");
- } else if ( rv == -1 ) {
- if ( errno == EINTR ) {
- continue;
- } else {
- die(strerror(errno));
- }
- } else {
- bufp += rv;
- offset += rv;
- done += rv;
- count -= rv;
+ const char *bufp = (const char *)buf;
+ ssize_t rv;
+ ssize_t done = 0;
+
+ while (count) {
+ rv = pwrite(fd, bufp, count, offset);
+ if (rv == 0) {
+ die("short write");
+ } else if (rv == -1) {
+ if (errno == EINTR) {
+ continue;
+ } else {
+ die(strerror(errno));
+ }
+ } else {
+ bufp += rv;
+ offset += rv;
+ done += rv;
+ count -= rv;
+ }
}
- }
- return done;
+ return done;
}
/*
* Create a block map for ldlinux.sys
*/
-int make_block_map(uint32_t *sectors, int len, int dev_fd, int fd)
+int make_block_map(uint32_t * sectors, int len, int dev_fd, int fd)
{
- int nsectors = 0;
- int blocksize, nblock, block;
- int i;
+ int nsectors = 0;
+ int blocksize, nblock, block;
+ int i;
- (void)dev_fd;
+ (void)dev_fd;
- if (ioctl(fd, FIGETBSZ, &blocksize) < 0)
- die("ioctl FIGETBSZ failed");
+ if (ioctl(fd, FIGETBSZ, &blocksize) < 0)
+ die("ioctl FIGETBSZ failed");
- blocksize >>= SECTOR_SHIFT; /* sectors/block */
+ blocksize >>= SECTOR_SHIFT; /* sectors/block */
- nblock = 0;
- while (len > 0) {
- block = nblock++;
- if (ioctl(fd, FIBMAP, &block) < 0)
- die("ioctl FIBMAP failed");
+ nblock = 0;
+ while (len > 0) {
+ block = nblock++;
+ if (ioctl(fd, FIBMAP, &block) < 0)
+ die("ioctl FIBMAP failed");
- for (i = 0; i < blocksize; i++) {
- if (len <= 0)
- break;
+ for (i = 0; i < blocksize; i++) {
+ if (len <= 0)
+ break;
- *sectors++ = (block*blocksize)+i;
- nsectors++;
- len -= (1 << SECTOR_SHIFT);
+ *sectors++ = (block * blocksize) + i;
+ nsectors++;
+ len -= (1 << SECTOR_SHIFT);
+ }
}
- }
- return nsectors;
+ return nsectors;
}
/*
@@ -202,79 +203,81 @@ int make_block_map(uint32_t *sectors, int len, int dev_fd, int fd)
*/
int do_mount(int dev_fd, int *cookie, const char *mntpath, const char *fstype)
{
- struct stat st;
+ struct stat st;
- (void)cookie;
+ (void)cookie;
- if (fstat(dev_fd, &st) < 0)
- return errno;
+ if (fstat(dev_fd, &st) < 0)
+ return errno;
#if DO_DIRECT_MOUNT
- {
- if ( !S_ISBLK(st.st_mode) ) {
- /* It's file, need to mount it loopback */
- unsigned int n = 0;
- struct loop_info64 loopinfo;
- int loop_fd;
-
- for ( n = 0 ; loop_fd < 0 ; n++ ) {
- snprintf(devfdname, sizeof devfdname, "/dev/loop%u", n);
- loop_fd = open(devfdname, O_RDWR);
- if ( loop_fd < 0 && errno == ENOENT ) {
- die("no available loopback device!");
- }
- if ( ioctl(loop_fd, LOOP_SET_FD, (void *)dev_fd) ) {
- close(loop_fd); loop_fd = -1;
- if ( errno != EBUSY )
- die("cannot set up loopback device");
- else
- continue;
+ {
+ if (!S_ISBLK(st.st_mode)) {
+ /* It's file, need to mount it loopback */
+ unsigned int n = 0;
+ struct loop_info64 loopinfo;
+ int loop_fd;
+
+ for (n = 0; loop_fd < 0; n++) {
+ snprintf(devfdname, sizeof devfdname, "/dev/loop%u", n);
+ loop_fd = open(devfdname, O_RDWR);
+ if (loop_fd < 0 && errno == ENOENT) {
+ die("no available loopback device!");
+ }
+ if (ioctl(loop_fd, LOOP_SET_FD, (void *)dev_fd)) {
+ close(loop_fd);
+ loop_fd = -1;
+ if (errno != EBUSY)
+ die("cannot set up loopback device");
+ else
+ continue;
+ }
+
+ if (ioctl(loop_fd, LOOP_GET_STATUS64, &loopinfo) ||
+ (loopinfo.lo_offset = filesystem_offset,
+ ioctl(loop_fd, LOOP_SET_STATUS64, &loopinfo)))
+ die("cannot set up loopback device");
+ }
+
+ *cookie = loop_fd;
+ } else {
+ snprintf(devfdname, sizeof devfdname, "/proc/%lu/fd/%d",
+ (unsigned long)mypid, dev_fd);
+ *cookie = -1;
}
- if ( ioctl(loop_fd, LOOP_GET_STATUS64, &loopinfo) ||
- (loopinfo.lo_offset = filesystem_offset,
- ioctl(loop_fd, LOOP_SET_STATUS64, &loopinfo)) )
- die("cannot set up loopback device");
- }
-
- *cookie = loop_fd;
- } else {
- snprintf(devfdname, sizeof devfdname, "/proc/%lu/fd/%d",
- (unsigned long)mypid, dev_fd);
- *cookie = -1;
+ return mount(devfdname, mntpath, fstype,
+ MS_NOEXEC | MS_NOSUID, "umask=077,quiet");
}
-
- return mount(devfdname, mntpath, fstype,
- MS_NOEXEC|MS_NOSUID, "umask=077,quiet");
- }
#else
- {
- char devfdname[128], mnt_opts[128];
- pid_t f, w;
- int status;
+ {
+ char devfdname[128], mnt_opts[128];
+ pid_t f, w;
+ int status;
+
+ snprintf(devfdname, sizeof devfdname, "/proc/%lu/fd/%d",
+ (unsigned long)mypid, dev_fd);
+
+ f = fork();
+ if (f < 0) {
+ return -1;
+ } else if (f == 0) {
+ if (!S_ISBLK(st.st_mode)) {
+ snprintf(mnt_opts, sizeof mnt_opts,
+ "rw,nodev,noexec,loop,offset=%llu,umask=077,quiet",
+ (unsigned long long)filesystem_offset);
+ } else {
+ snprintf(mnt_opts, sizeof mnt_opts,
+ "rw,nodev,noexec,umask=077,quiet");
+ }
+ execl(_PATH_MOUNT, _PATH_MOUNT, "-t", fstype, "-o", mnt_opts,
+ devfdname, mntpath, NULL);
+ _exit(255); /* execl failed */
+ }
- snprintf(devfdname, sizeof devfdname, "/proc/%lu/fd/%d",
- (unsigned long)mypid, dev_fd);
-
- f = fork();
- if ( f < 0 ) {
- return -1;
- } else if ( f == 0 ) {
- if ( !S_ISBLK(st.st_mode) ) {
- snprintf(mnt_opts, sizeof mnt_opts,
- "rw,nodev,noexec,loop,offset=%llu,umask=077,quiet",
- (unsigned long long)filesystem_offset);
- } else {
- snprintf(mnt_opts, sizeof mnt_opts, "rw,nodev,noexec,umask=077,quiet");
- }
- execl(_PATH_MOUNT, _PATH_MOUNT, "-t", fstype, "-o", mnt_opts, \
- devfdname, mntpath, NULL);
- _exit(255); /* execl failed */
+ w = waitpid(f, &status, 0);
+ return (w != f || status) ? -1 : 0;
}
-
- w = waitpid(f, &status, 0);
- return ( w != f || status ) ? -1 : 0;
- }
#endif
}
@@ -284,287 +287,285 @@ int do_mount(int dev_fd, int *cookie, const char *mntpath, const char *fstype)
void do_umount(const char *mntpath, int cookie)
{
#if DO_DIRECT_MOUNT
- int loop_fd = cookie;
-
- if ( umount2(mntpath, 0) )
- die("could not umount path");
+ int loop_fd = cookie;
- if ( loop_fd != -1 ) {
- ioctl(loop_fd, LOOP_CLR_FD, 0); /* Free loop device */
- close(loop_fd);
- loop_fd = -1;
- }
+ if (umount2(mntpath, 0))
+ die("could not umount path");
+ if (loop_fd != -1) {
+ ioctl(loop_fd, LOOP_CLR_FD, 0); /* Free loop device */
+ close(loop_fd);
+ loop_fd = -1;
+ }
#else
- pid_t f = fork();
- pid_t w;
- int status;
- (void)cookie;
+ pid_t f = fork();
+ pid_t w;
+ int status;
+ (void)cookie;
- if ( f < 0 ) {
- perror("fork");
- exit(1);
- } else if ( f == 0 ) {
- execl(_PATH_UMOUNT, _PATH_UMOUNT, mntpath, NULL);
- }
+ if (f < 0) {
+ perror("fork");
+ exit(1);
+ } else if (f == 0) {
+ execl(_PATH_UMOUNT, _PATH_UMOUNT, mntpath, NULL);
+ }
- w = waitpid(f, &status, 0);
- if ( w != f || status ) {
- exit(1);
- }
+ w = waitpid(f, &status, 0);
+ if (w != f || status) {
+ exit(1);
+ }
#endif
}
int main(int argc, char *argv[])
{
- static unsigned char sectbuf[SECTOR_SIZE];
- unsigned char *dp;
- const unsigned char *cdp;
- int dev_fd, fd;
- struct stat st;
- int nb, left;
- int err = 0;
- char mntname[128];
- char *ldlinux_name, **argp, *opt;
- const char *subdir = NULL;
- uint32_t *sectors;
- int ldlinux_sectors;
- int nsectors = 0;
- const char *errmsg;
- int mnt_cookie;
- int patch_sectors;
- int i;
-
- int force = 0; /* -f (force) option */
- int stupid = 0; /* -s (stupid) option */
- int raid_mode = 0; /* -r (RAID) option */
-
- (void)argc; /* Unused */
-
- program = argv[0];
- mypid = getpid();
-
- device = NULL;
-
- umask(077);
-
- for ( argp = argv+1 ; *argp ; argp++ ) {
- if ( **argp == '-' ) {
- opt = *argp + 1;
- if ( !*opt )
- usage();
-
- while ( *opt ) {
- if ( *opt == 's' ) {
- stupid = 1;
- } else if ( *opt == 'r' ) {
- raid_mode = 1;
- } else if ( *opt == 'f' ) {
- force = 1; /* Force install */
- } else if ( *opt == 'd' && argp[1] ) {
- subdir = *++argp;
- } else if ( *opt == 'o' && argp[1] ) {
- /* Byte offset */
- filesystem_offset = (off_t)strtoull(*++argp, NULL, 0);
+ static unsigned char sectbuf[SECTOR_SIZE];
+ unsigned char *dp;
+ const unsigned char *cdp;
+ int dev_fd, fd;
+ struct stat st;
+ int nb, left;
+ int err = 0;
+ char mntname[128];
+ char *ldlinux_name, **argp, *opt;
+ const char *subdir = NULL;
+ uint32_t *sectors;
+ int ldlinux_sectors;
+ int nsectors = 0;
+ const char *errmsg;
+ int mnt_cookie;
+ int patch_sectors;
+ int i;
+
+ int force = 0; /* -f (force) option */
+ int stupid = 0; /* -s (stupid) option */
+ int raid_mode = 0; /* -r (RAID) option */
+
+ (void)argc; /* Unused */
+
+ program = argv[0];
+ mypid = getpid();
+
+ device = NULL;
+
+ umask(077);
+
+ for (argp = argv + 1; *argp; argp++) {
+ if (**argp == '-') {
+ opt = *argp + 1;
+ if (!*opt)
+ usage();
+
+ while (*opt) {
+ if (*opt == 's') {
+ stupid = 1;
+ } else if (*opt == 'r') {
+ raid_mode = 1;
+ } else if (*opt == 'f') {
+ force = 1; /* Force install */
+ } else if (*opt == 'd' && argp[1]) {
+ subdir = *++argp;
+ } else if (*opt == 'o' && argp[1]) {
+ /* Byte offset */
+ filesystem_offset = (off_t) strtoull(*++argp, NULL, 0);
+ } else {
+ usage();
+ }
+ opt++;
+ }
} else {
- usage();
+ if (device)
+ usage();
+ device = *argp;
}
- opt++;
- }
- } else {
- if ( device )
+ }
+
+ if (!device)
usage();
- device = *argp;
+
+ /*
+ * First make sure we can open the device at all, and that we have
+ * read/write permission.
+ */
+ dev_fd = open(device, O_RDWR);
+ if (dev_fd < 0 || fstat(dev_fd, &st) < 0) {
+ perror(device);
+ exit(1);
}
- }
-
- if ( !device )
- usage();
-
- /*
- * First make sure we can open the device at all, and that we have
- * read/write permission.
- */
- dev_fd = open(device, O_RDWR);
- if ( dev_fd < 0 || fstat(dev_fd, &st) < 0 ) {
- perror(device);
- exit(1);
- }
- if ( !S_ISBLK(st.st_mode) && !S_ISREG(st.st_mode) && !S_ISCHR(st.st_mode) ) {
- die("not a device or regular file");
- }
+ if (!S_ISBLK(st.st_mode) && !S_ISREG(st.st_mode) && !S_ISCHR(st.st_mode)) {
+ die("not a device or regular file");
+ }
- if ( filesystem_offset && S_ISBLK(st.st_mode) ) {
- die("can't combine an offset with a block device");
- }
+ if (filesystem_offset && S_ISBLK(st.st_mode)) {
+ die("can't combine an offset with a block device");
+ }
- xpread(dev_fd, sectbuf, SECTOR_SIZE, filesystem_offset);
- fsync(dev_fd);
+ xpread(dev_fd, sectbuf, SECTOR_SIZE, filesystem_offset);
+ fsync(dev_fd);
- /*
- * Check to see that what we got was indeed an MS-DOS boot sector/superblock
- */
- if( (errmsg = syslinux_check_bootsect(sectbuf)) ) {
- fprintf(stderr, "%s: %s\n", device, errmsg);
- exit(1);
- }
-
- /*
- * Now mount the device.
- */
- if ( geteuid() ) {
- die("This program needs root privilege");
- } else {
- int i = 0;
- struct stat dst;
- int rv;
-
- /* We're root or at least setuid.
- Make a temp dir and pass all the gunky options to mount. */
-
- if ( chdir(_PATH_TMP) ) {
- perror(program);
- exit(1);
+ /*
+ * Check to see that what we got was indeed an MS-DOS boot sector/superblock
+ */
+ if ((errmsg = syslinux_check_bootsect(sectbuf))) {
+ fprintf(stderr, "%s: %s\n", device, errmsg);
+ exit(1);
}
+ /*
+ * Now mount the device.
+ */
+ if (geteuid()) {
+ die("This program needs root privilege");
+ } else {
+ int i = 0;
+ struct stat dst;
+ int rv;
+
+ /* We're root or at least setuid.
+ Make a temp dir and pass all the gunky options to mount. */
+
+ if (chdir(_PATH_TMP)) {
+ perror(program);
+ exit(1);
+ }
#define TMP_MODE (S_IXUSR|S_IWUSR|S_IXGRP|S_IWGRP|S_IWOTH|S_IXOTH|S_ISVTX)
- if ( stat(".", &dst) || !S_ISDIR(dst.st_mode) ||
- (dst.st_mode & TMP_MODE) != TMP_MODE ) {
- die("possibly unsafe " _PATH_TMP " permissions");
- }
+ if (stat(".", &dst) || !S_ISDIR(dst.st_mode) ||
+ (dst.st_mode & TMP_MODE) != TMP_MODE) {
+ die("possibly unsafe " _PATH_TMP " permissions");
+ }
+
+ for (i = 0;; i++) {
+ snprintf(mntname, sizeof mntname, "syslinux.mnt.%lu.%d",
+ (unsigned long)mypid, i);
+
+ if (lstat(mntname, &dst) != -1 || errno != ENOENT)
+ continue;
+
+ rv = mkdir(mntname, 0000);
+
+ if (rv == -1) {
+ if (errno == EEXIST || errno == EINTR)
+ continue;
+ perror(program);
+ exit(1);
+ }
- for ( i = 0 ; ; i++ ) {
- snprintf(mntname, sizeof mntname, "syslinux.mnt.%lu.%d",
- (unsigned long)mypid, i);
+ if (lstat(mntname, &dst) || dst.st_mode != (S_IFDIR | 0000) ||
+ dst.st_uid != 0) {
+ die("someone is trying to symlink race us!");
+ }
+ break; /* OK, got something... */
+ }
- if ( lstat(mntname, &dst) != -1 || errno != ENOENT )
- continue;
+ mntpath = mntname;
+ }
- rv = mkdir(mntname, 0000);
+ if (do_mount(dev_fd, &mnt_cookie, mntpath, "vfat") &&
+ do_mount(dev_fd, &mnt_cookie, mntpath, "msdos")) {
+ rmdir(mntpath);
+ die("mount failed");
+ }
- if ( rv == -1 ) {
- if ( errno == EEXIST || errno == EINTR )
- continue;
+ ldlinux_name = alloca(strlen(mntpath) + 14 +
+ (subdir ? strlen(subdir) + 2 : 0));
+ if (!ldlinux_name) {
perror(program);
- exit(1);
- }
+ err = 1;
+ goto umount;
+ }
+ sprintf(ldlinux_name, "%s%s%s//ldlinux.sys",
+ mntpath, subdir ? "//" : "", subdir ? subdir : "");
- if ( lstat(mntname, &dst) || dst.st_mode != (S_IFDIR|0000) ||
- dst.st_uid != 0 ) {
- die("someone is trying to symlink race us!");
- }
- break; /* OK, got something... */
+ if ((fd = open(ldlinux_name, O_RDONLY)) >= 0) {
+ uint32_t zero_attr = 0;
+ ioctl(fd, FAT_IOCTL_SET_ATTRIBUTES, &zero_attr);
+ close(fd);
}
- mntpath = mntname;
- }
+ unlink(ldlinux_name);
+ fd = open(ldlinux_name, O_WRONLY | O_CREAT | O_TRUNC, 0444);
+ if (fd < 0) {
+ perror(device);
+ err = 1;
+ goto umount;
+ }
- if (do_mount(dev_fd, &mnt_cookie, mntpath, "vfat") &&
- do_mount(dev_fd, &mnt_cookie, mntpath, "msdos")) {
- rmdir(mntpath);
- die("mount failed");
- }
-
- ldlinux_name = alloca(strlen(mntpath)+14+
- (subdir ? strlen(subdir)+2 : 0));
- if ( !ldlinux_name ) {
- perror(program);
- err = 1;
- goto umount;
- }
- sprintf(ldlinux_name, "%s%s%s//ldlinux.sys",
- mntpath, subdir ? "//" : "", subdir ? subdir : "");
-
- if ((fd = open(ldlinux_name, O_RDONLY)) >= 0) {
- uint32_t zero_attr = 0;
- ioctl(fd, FAT_IOCTL_SET_ATTRIBUTES, &zero_attr);
- close(fd);
- }
-
- unlink(ldlinux_name);
- fd = open(ldlinux_name, O_WRONLY|O_CREAT|O_TRUNC, 0444);
- if ( fd < 0 ) {
- perror(device);
- err = 1;
- goto umount;
- }
-
- cdp = syslinux_ldlinux;
- left = syslinux_ldlinux_len;
- while ( left ) {
- nb = write(fd, cdp, left);
- if ( nb == -1 && errno == EINTR )
- continue;
- else if ( nb <= 0 ) {
- perror(device);
- err = 1;
- goto umount;
+ cdp = syslinux_ldlinux;
+ left = syslinux_ldlinux_len;
+ while (left) {
+ nb = write(fd, cdp, left);
+ if (nb == -1 && errno == EINTR)
+ continue;
+ else if (nb <= 0) {
+ perror(device);
+ err = 1;
+ goto umount;
+ }
+
+ dp += nb;
+ left -= nb;
}
- dp += nb;
- left -= nb;
- }
-
- fsync(fd);
- /*
- * Set the attributes
- */
- {
- uint32_t attr = 0x07; /* Hidden+System+Readonly */
- ioctl(fd, FAT_IOCTL_SET_ATTRIBUTES, &attr);
- }
-
- /*
- * Create a block map.
- */
- ldlinux_sectors = (syslinux_ldlinux_len+SECTOR_SIZE-1) >> SECTOR_SHIFT;
- sectors = calloc(ldlinux_sectors, sizeof *sectors);
- nsectors = make_block_map(sectors, syslinux_ldlinux_len, dev_fd, fd);
-
- close(fd);
- sync();
+ fsync(fd);
+ /*
+ * Set the attributes
+ */
+ {
+ uint32_t attr = 0x07; /* Hidden+System+Readonly */
+ ioctl(fd, FAT_IOCTL_SET_ATTRIBUTES, &attr);
+ }
-umount:
- do_umount(mntpath, mnt_cookie);
- sync();
- rmdir(mntpath);
+ /*
+ * Create a block map.
+ */
+ ldlinux_sectors = (syslinux_ldlinux_len + SECTOR_SIZE - 1) >> SECTOR_SHIFT;
+ sectors = calloc(ldlinux_sectors, sizeof *sectors);
+ nsectors = make_block_map(sectors, syslinux_ldlinux_len, dev_fd, fd);
- if ( err )
- exit(err);
+ close(fd);
+ sync();
- /*
- * Patch ldlinux.sys and the boot sector
- */
- i = syslinux_patch(sectors, nsectors, stupid, raid_mode);
- patch_sectors = (i + SECTOR_SIZE - 1) >> SECTOR_SHIFT;
+umount:
+ do_umount(mntpath, mnt_cookie);
+ sync();
+ rmdir(mntpath);
- /*
- * Write the now-patched first sectors of ldlinux.sys
- */
- for (i = 0; i < patch_sectors; i++) {
- xpwrite(dev_fd, syslinux_ldlinux + i*SECTOR_SIZE, SECTOR_SIZE,
- filesystem_offset+((off_t)sectors[i] << SECTOR_SHIFT));
- }
+ if (err)
+ exit(err);
+
+ /*
+ * Patch ldlinux.sys and the boot sector
+ */
+ i = syslinux_patch(sectors, nsectors, stupid, raid_mode);
+ patch_sectors = (i + SECTOR_SIZE - 1) >> SECTOR_SHIFT;
+
+ /*
+ * Write the now-patched first sectors of ldlinux.sys
+ */
+ for (i = 0; i < patch_sectors; i++) {
+ xpwrite(dev_fd, syslinux_ldlinux + i * SECTOR_SIZE, SECTOR_SIZE,
+ filesystem_offset + ((off_t) sectors[i] << SECTOR_SHIFT));
+ }
- /*
- * To finish up, write the boot sector
- */
+ /*
+ * To finish up, write the boot sector
+ */
- /* Read the superblock again since it might have changed while mounted */
- xpread(dev_fd, sectbuf, SECTOR_SIZE, filesystem_offset);
+ /* Read the superblock again since it might have changed while mounted */
+ xpread(dev_fd, sectbuf, SECTOR_SIZE, filesystem_offset);
- /* Copy the syslinux code into the boot sector */
- syslinux_make_bootsect(sectbuf);
+ /* Copy the syslinux code into the boot sector */
+ syslinux_make_bootsect(sectbuf);
- /* Write new boot sector */
- xpwrite(dev_fd, sectbuf, SECTOR_SIZE, filesystem_offset);
+ /* Write new boot sector */
+ xpwrite(dev_fd, sectbuf, SECTOR_SIZE, filesystem_offset);
- close(dev_fd);
- sync();
+ close(dev_fd);
+ sync();
- /* Done! */
+ /* Done! */
- return 0;
+ return 0;
}