Added
Link Here
|
1 |
--- mtools/syslinux.c.orig 2010-10-20 21:25:38.000000000 +0200 |
2 |
+++ mtools/syslinux.c 2010-11-16 14:59:55.668749526 +0100 |
3 |
@@ -20,12 +20,12 @@ |
4 |
*/ |
5 |
|
6 |
#define _GNU_SOURCE |
7 |
-#include <alloca.h> |
8 |
+//#include <alloca.h> |
9 |
#include <errno.h> |
10 |
#include <fcntl.h> |
11 |
#include <getopt.h> |
12 |
#include <inttypes.h> |
13 |
-#include <mntent.h> |
14 |
+//#include <mntent.h> |
15 |
#include <paths.h> |
16 |
#include <stdio.h> |
17 |
#include <string.h> |
18 |
@@ -42,6 +42,8 @@ |
19 |
#include "setadv.h" |
20 |
#include "syslxopt.h" |
21 |
|
22 |
+int verbose=0; |
23 |
+ |
24 |
char *program; /* Name of program */ |
25 |
pid_t mypid; |
26 |
|
27 |
@@ -124,6 +126,53 @@ |
28 |
return xpread(pp, buf, secsize, offset); |
29 |
} |
30 |
|
31 |
+/* |
32 |
+ * load a file to be used as boot image |
33 |
+ */ |
34 |
+static int load_boot_image(const char *name) |
35 |
+{ |
36 |
+ int l, fd; |
37 |
+ struct stat sb; |
38 |
+ unsigned char *buf; |
39 |
+ |
40 |
+ memset(&sb, 0, sizeof(sb)); |
41 |
+ fd = open(name, O_RDONLY); |
42 |
+ if (fd < 0) { |
43 |
+ fprintf(stderr, "cannot open boot image %s\n", name); |
44 |
+ return 1; |
45 |
+ } |
46 |
+ if (fstat(fd, &sb)) { |
47 |
+ fprintf(stderr, "cannot stat boot image %s\n", name); |
48 |
+ return 1; |
49 |
+ } |
50 |
+ if ( (sb.st_mode & S_IFREG) == 0) { |
51 |
+ fprintf(stderr, "boot image %s is not a file 0x%x\n", name, sb.st_mode); |
52 |
+ return 1; |
53 |
+ } |
54 |
+ if (sb.st_size < 1024 || sb.st_size > 0x8000) { |
55 |
+ fprintf(stderr, "boot image %s bad size %lld\n", name, (long long int)sb.st_size); |
56 |
+ return 1; |
57 |
+ } |
58 |
+ buf = calloc(1, sb.st_size); |
59 |
+ if (buf == NULL) { |
60 |
+ fprintf(stderr, "malloc failed for boot image %s\n", name); |
61 |
+ return 1; |
62 |
+ } |
63 |
+ l = read(fd, buf, sb.st_size); |
64 |
+ if (l != sb.st_size) { |
65 |
+ fprintf(stderr, "read failed for boot image %s got %d\n", name, l); |
66 |
+ return 1; |
67 |
+ } |
68 |
+ if (buf[0] != 0xeb || buf[0x200] != 0x0d) { |
69 |
+ fprintf(stderr, "bad content for boot image %s\n", name); |
70 |
+ return 1; |
71 |
+ } |
72 |
+ syslinux_bootsect = buf; |
73 |
+ syslinux_ldlinux = buf + 512; |
74 |
+ syslinux_ldlinux_len = sb.st_size - 512; |
75 |
+ return 0; |
76 |
+} |
77 |
+ |
78 |
int main(int argc, char *argv[]) |
79 |
{ |
80 |
static unsigned char sectbuf[SECTOR_SIZE]; |
81 |
@@ -150,9 +199,15 @@ |
82 |
|
83 |
parse_options(argc, argv, MODE_SYSLINUX); |
84 |
|
85 |
+ if (opt.verbose) |
86 |
+ verbose = 1; |
87 |
+ |
88 |
if (!opt.device) |
89 |
usage(EX_USAGE, MODE_SYSLINUX); |
90 |
|
91 |
+ if (opt.bimage != NULL) |
92 |
+ load_boot_image(opt.bimage); |
93 |
+ |
94 |
if (opt.sectors || opt.heads || opt.reset_adv || opt.set_once |
95 |
|| (opt.update_only > 0) || opt.menu_save) { |
96 |
fprintf(stderr, |
97 |
@@ -216,11 +271,9 @@ |
98 |
/* These are needed for some flash memories */ |
99 |
"MTOOLS_SKIP_CHECK=1\n" |
100 |
"MTOOLS_FAT_COMPATIBILITY=1\n" |
101 |
- "drive s:\n" |
102 |
- " file=\"/proc/%lu/fd/%d\"\n" |
103 |
+ "drive s: file=\"%s\"\n" |
104 |
" offset=%llu\n", |
105 |
- (unsigned long)mypid, |
106 |
- dev_fd, (unsigned long long)opt.offset); |
107 |
+ opt.device, (unsigned long long)opt.offset); |
108 |
|
109 |
if (ferror(mtc) || fclose(mtc)) |
110 |
die_err(mtools_conf); |
111 |
@@ -239,9 +292,11 @@ |
112 |
syslinux_reset_adv(syslinux_adv); |
113 |
|
114 |
/* This command may fail legitimately */ |
115 |
+ if (verbose) fprintf(stderr, "doing mattrib\n"); |
116 |
status = system("mattrib -h -r -s s:/ldlinux.sys 2>/dev/null"); |
117 |
(void)status; /* Keep _FORTIFY_SOURCE happy */ |
118 |
|
119 |
+ if (verbose) fprintf(stderr, "doing mcopy\n"); |
120 |
mtp = popen("mcopy -D o -D O -o - s:/ldlinux.sys", "w"); |
121 |
if (!mtp || |
122 |
fwrite(syslinux_ldlinux, 1, syslinux_ldlinux_len, mtp) |
123 |
@@ -259,7 +314,9 @@ |
124 |
+ SECTOR_SIZE - 1) >> SECTOR_SHIFT; |
125 |
sectors = calloc(ldlinux_sectors, sizeof *sectors); |
126 |
fs = libfat_open(libfat_xpread, dev_fd); |
127 |
+ if (verbose) fprintf(stderr, "libfat_open returns %p\n", fs); |
128 |
ldlinux_cluster = libfat_searchdir(fs, 0, "LDLINUX SYS", NULL); |
129 |
+ if (verbose) fprintf(stderr, "libfat_searchdir returns %d\n", ldlinux_cluster); |
130 |
secp = sectors; |
131 |
nsectors = 0; |
132 |
s = libfat_clustertosector(fs, ldlinux_cluster); |
133 |
@@ -267,6 +324,7 @@ |
134 |
*secp++ = s; |
135 |
nsectors++; |
136 |
s = libfat_nextsector(fs, s); |
137 |
+ if (verbose) fprintf(stderr, "libfat_nextsector returns %d\n", (int)s); |
138 |
} |
139 |
libfat_close(fs); |
140 |
|