summaryrefslogtreecommitdiffstats
path: root/meta/recipes-devtools/dosfstools/dosfstools
diff options
context:
space:
mode:
Diffstat (limited to 'meta/recipes-devtools/dosfstools/dosfstools')
-rw-r--r--meta/recipes-devtools/dosfstools/dosfstools/alignment_hack.patch38
-rw-r--r--meta/recipes-devtools/dosfstools/dosfstools/dosfstools-msdos_fs-types.patch37
-rw-r--r--meta/recipes-devtools/dosfstools/dosfstools/fix_populated_dosfs_creation.patch489
-rw-r--r--meta/recipes-devtools/dosfstools/dosfstools/include-linux-types.patch22
-rw-r--r--meta/recipes-devtools/dosfstools/dosfstools/mkdosfs-bootcode.patch241
-rw-r--r--meta/recipes-devtools/dosfstools/dosfstools/mkdosfs-dir.patch639
-rw-r--r--meta/recipes-devtools/dosfstools/dosfstools/msdos_fat12_undefined.patch19
-rw-r--r--meta/recipes-devtools/dosfstools/dosfstools/nofat32_autoselect.patch27
8 files changed, 1512 insertions, 0 deletions
diff --git a/meta/recipes-devtools/dosfstools/dosfstools/alignment_hack.patch b/meta/recipes-devtools/dosfstools/dosfstools/alignment_hack.patch
new file mode 100644
index 0000000..b46b2db
--- /dev/null
+++ b/meta/recipes-devtools/dosfstools/dosfstools/alignment_hack.patch
@@ -0,0 +1,38 @@
1The problem is that unsigned char[2] is
2guranteed to be 8Bit aligned on arm
3but unsigned short is/needs to be 16bit aligned
4the union { unsigned short; unsigned char[2] } trick
5didn't work so no we use the alpha hack.
6
7memcpy into an 16bit aligned
8
9 -zecke
10
11Upstream-Status: Inappropriate [licensing]
12We're tracking an old release of dosfstools due to licensing issues.
13
14Signed-off-by: Scott Garman <scott.a.garman@intel.com>
15
16--- dosfstools/dosfsck/boot.c.orig 2003-05-15 19:32:23.000000000 +0200
17+++ dosfstools/dosfsck/boot.c 2003-06-13 17:44:25.000000000 +0200
18@@ -36,17 +36,15 @@
19 { 0xff, "5.25\" 320k floppy 2s/40tr/8sec" },
20 };
21
22-#if defined __alpha || defined __ia64__ || defined __s390x__ || defined __x86_64__ || defined __ppc64__
23+
24 /* Unaligned fields must first be copied byte-wise */
25 #define GET_UNALIGNED_W(f) \
26 ({ \
27 unsigned short __v; \
28 memcpy( &__v, &f, sizeof(__v) ); \
29- CF_LE_W( *(unsigned short *)&f ); \
30+ CF_LE_W( *(unsigned short *)&__v ); \
31 })
32-#else
33-#define GET_UNALIGNED_W(f) CF_LE_W( *(unsigned short *)&f )
34-#endif
35+
36
37
38 static char *get_media_descr( unsigned char media )
diff --git a/meta/recipes-devtools/dosfstools/dosfstools/dosfstools-msdos_fs-types.patch b/meta/recipes-devtools/dosfstools/dosfstools/dosfstools-msdos_fs-types.patch
new file mode 100644
index 0000000..35abd1a
--- /dev/null
+++ b/meta/recipes-devtools/dosfstools/dosfstools/dosfstools-msdos_fs-types.patch
@@ -0,0 +1,37 @@
1Ensure the __s8 type is properly defined.
2
3Upstream-Status: Inappropriate [licensing]
4We're tracking an old release of dosfstools due to licensing issues.
5
6Signed-off-by: Scott Garman <scott.a.garman@intel.com>
7
8--- dosfstools-2.10/dosfsck/dosfsck.h.org 2006-02-21 08:36:14.000000000 -0700
9+++ dosfstools-2.10/dosfsck/dosfsck.h 2006-02-21 08:40:12.000000000 -0700
10@@ -22,6 +22,14 @@
11 #undef __KERNEL__
12 #endif
13
14+#ifndef __s8
15+#include <asm/types.h>
16+#endif
17+
18+#ifndef __ASM_STUB_BYTEORDER_H__
19+#include <asm/byteorder.h>
20+#endif
21+
22 #include <linux/msdos_fs.h>
23
24 /* 2.1 kernels use le16_to_cpu() type functions for CF_LE_W & Co., but don't
25--- dosfstools-2.10/dosfsck/file.c.org 2006-02-21 08:37:36.000000000 -0700
26+++ dosfstools-2.10/dosfsck/file.c 2006-02-21 08:37:47.000000000 -0700
27@@ -23,6 +23,10 @@
28 #undef __KERNEL__
29 #endif
30
31+#ifndef __s8
32+#include <asm/types.h>
33+#endif
34+
35 #include <linux/msdos_fs.h>
36
37 #include "common.h"
diff --git a/meta/recipes-devtools/dosfstools/dosfstools/fix_populated_dosfs_creation.patch b/meta/recipes-devtools/dosfstools/dosfstools/fix_populated_dosfs_creation.patch
new file mode 100644
index 0000000..9d7f732
--- /dev/null
+++ b/meta/recipes-devtools/dosfstools/dosfstools/fix_populated_dosfs_creation.patch
@@ -0,0 +1,489 @@
1Upstream-Status: Inappropriate
2
3This patch fixes populated dosfs image creation with directory
4structures. Earlier it was causing segfault; and only image
5population with no subdirectories was working.
6
7Issues fixed:
81. (dir->count == dir->entries) check was only needed for root
9 directory entries. And this check is wrong for non-root
10 directories.
112. For each dir entry 2 dir->table entries were needed, one for
12 the file/dir and 2nd for long file name support. Earlier long
13 name support was added for filenames but the 2nd entry
14 allocation, initialization & counting was missed.
153. The memory clearing was missed at the code path after dir->table
16 memroy allocation.
174. Add entries for . & .. directories in all non-root directories.
185. The . directory points to the correct entry in fat now.
196. All directoriy entries' size was not zero as required for dosfsck,
20 Now all directory entries' size is zero.
21
22Enhancements:
231. Added support for long names for directory names. This is same
24 as the existing long name support for filenames.
252. Added error messages for previously silent memory allocation and
26 other errors.
273. -d options does not work correctly with fat32, so now throwing
28 an error for that.
294. Use predefined structures from kernel's msdos_fs.h file, rather
30 than defining again here. And accordingly change the names & use
31 of structure variables.
32
33Outstanding Issues:
341. The .. directory entry do not point to the parent of current
35 directory. This issue can be fixed by running dosfsck -a after
36 image creation.
372. For files the filesize is correct, but the clusters size is more
38 than it needs to be, this also can be fixed by running dosfsck -a
39 after image creation.
40
41Signed-off-by: Nitin A Kamble <nitin.a.kamble@intel.com>
422011/12/13
43
44
45Index: dosfstools-2.11/mkdosfs/mkdosfs.c
46===================================================================
47--- dosfstools-2.11.orig/mkdosfs/mkdosfs.c
48+++ dosfstools-2.11/mkdosfs/mkdosfs.c
49@@ -21,7 +21,17 @@
50 June 2004 - Jordan Crouse (info.linux@amd.com)
51 Added -d <directory> support to populate the image
52 Copyright (C) 2004, Advanced Micro Devices, All Rights Reserved
53-
54+
55+ 2011-12-13: Nitin A Kamble <nitin.a.kamble@intel.com>
56+ Enhanced the -d <directory> support for population of image while
57+ creation. Earlier subdirectores support was broken, only files in
58+ the rootdir were supported. Now directory hirarchy is supported.
59+ Also added long filename support to directory names.
60+ The -d <directory> option (image population while creation)
61+ is broken with fat32.
62+ Copyright (C) 2011, Intel Corporation, All Rights Reserved
63+
64+
65 Fixes/additions May 1998 by Roman Hodek
66 <Roman.Hodek@informatik.uni-erlangen.de>:
67 - Atari format support
68@@ -86,23 +96,23 @@
69 # undef __KERNEL__
70 #endif
71
72-#if __BYTE_ORDER == __BIG_ENDIAN
73-
74+#ifndef __ASM_STUB_BYTEORDER_H__
75 #include <asm/byteorder.h>
76-#ifdef __le16_to_cpu
77-/* ++roman: 2.1 kernel headers define these function, they're probably more
78- * efficient then coding the swaps machine-independently. */
79-#define CF_LE_W __le16_to_cpu
80-#define CF_LE_L __le32_to_cpu
81-#define CT_LE_W __cpu_to_le16
82-#define CT_LE_L __cpu_to_le32
83-#else
84-#define CF_LE_W(v) ((((v) & 0xff) << 8) | (((v) >> 8) & 0xff))
85-#define CF_LE_L(v) (((unsigned)(v)>>24) | (((unsigned)(v)>>8)&0xff00) | \
86- (((unsigned)(v)<<8)&0xff0000) | ((unsigned)(v)<<24))
87+#endif
88+
89+#include <linux/msdos_fs.h>
90+
91+#undef CF_LE_W
92+#undef CF_LE_L
93+#undef CT_LE_W
94+#undef CT_LE_L
95+
96+#if __BYTE_ORDER == __BIG_ENDIAN
97+#include <byteswap.h>
98+#define CF_LE_W(v) bswap_16(v)
99+#define CF_LE_L(v) bswap_32(v)
100 #define CT_LE_W(v) CF_LE_W(v)
101 #define CT_LE_L(v) CF_LE_L(v)
102-#endif /* defined(__le16_to_cpu) */
103
104 #else
105
106@@ -253,33 +263,6 @@ struct fat32_fsinfo {
107 __u32 reserved2[4];
108 };
109
110-/* This stores up to 13 chars of the name */
111-
112-struct msdos_dir_slot {
113- __u8 id; /* sequence number for slot */
114- __u8 name0_4[10]; /* first 5 characters in name */
115- __u8 attr; /* attribute byte */
116- __u8 reserved; /* always 0 */
117- __u8 alias_checksum; /* checksum for 8.3 alias */
118- __u8 name5_10[12]; /* 6 more characters in name */
119- __u16 start; /* starting cluster number, 0 in long slots */
120- __u8 name11_12[4]; /* last 2 characters in name */
121-};
122-
123-struct msdos_dir_entry
124- {
125- char name[8], ext[3]; /* name and extension */
126- __u8 attr; /* attribute bits */
127- __u8 lcase; /* Case for base and extension */
128- __u8 ctime_ms; /* Creation time, milliseconds */
129- __u16 ctime; /* Creation time */
130- __u16 cdate; /* Creation date */
131- __u16 adate; /* Last access date */
132- __u16 starthi; /* high 16 bits of first cl. (FAT32) */
133- __u16 time, date, start; /* time, date and first cluster */
134- __u32 size; /* file size (in bytes) */
135- } __attribute__ ((packed));
136-
137 /* The "boot code" we put into the filesystem... it writes a message and
138 tells the user to try again */
139
140@@ -356,7 +339,6 @@ static struct msdos_dir_entry *root_dir;
141 static int size_root_dir; /* Size of the root directory in bytes */
142 static int sectors_per_cluster = 0; /* Number of sectors per disk cluster */
143 static int root_dir_entries = 0; /* Number of root directory entries */
144-static int root_dir_num_entries = 0;
145 static int last_cluster_written = 0;
146
147 static char *blank_sector; /* Blank sector - all zeros */
148@@ -1315,7 +1297,7 @@ setup_tables (void)
149 de->date = CT_LE_W((unsigned short)(ctime->tm_mday +
150 ((ctime->tm_mon+1) << 5) +
151 ((ctime->tm_year-80) << 9)));
152- de->ctime_ms = 0;
153+ de->ctime_cs = 0;
154 de->ctime = de->time;
155 de->cdate = de->date;
156 de->adate = de->date;
157@@ -1451,16 +1433,23 @@ write_tables (void)
158
159 /* Add a file to the specified directory entry, and also write it into the image */
160
161-static void copy_filename(char *filename, char *base, char *ext) {
162+static void copy_filename(char *filename, char *dos_name) {
163
164 char *ch = filename;
165 int i, len;
166
167- memset(base, 0x20, 8);
168- memset(ext, 0x20, 3);
169+ if (!strcmp(filename, ".")) {
170+ strncpy(dos_name, MSDOS_DOT, MSDOS_NAME);
171+ return;
172+ }
173+ if (!strcmp(filename, "..")) {
174+ strncpy(dos_name, MSDOS_DOTDOT, MSDOS_NAME);
175+ return;
176+ }
177+ memset(dos_name, 0x20, MSDOS_NAME);
178
179 for(len = 0 ; *ch && *ch != '.'; ch++) {
180- base[len++] = toupper(*ch);
181+ dos_name[len++] = toupper(*ch);
182 if (len == 8) break;
183 }
184
185@@ -1468,7 +1457,7 @@ static void copy_filename(char *filename
186 if (*ch) ch++;
187
188 for(len = 0 ; *ch; ch++) {
189- ext[len++] = toupper(*ch);
190+ dos_name[8 + len++] = toupper(*ch);
191 if (len == 3) break;
192 }
193 }
194@@ -1551,7 +1540,7 @@ static int add_file(char *filename, stru
195 int start;
196 int usedsec, totalsec;
197
198- char name83[8], ext83[3];
199+ char dos_name[MSDOS_NAME+1];
200
201 struct msdos_dir_slot *slot;
202 int i;
203@@ -1562,23 +1551,22 @@ static int add_file(char *filename, stru
204 if (dir->root) {
205 if (dir->count == dir->entries) {
206 printf("Error - too many directory entries\n");
207+ return;
208 }
209 }
210 else {
211- if (dir->count == dir->entries) {
212- if (!dir->table)
213- dir->table =
214- (struct msdos_dir_entry *) malloc(sizeof(struct msdos_dir_entry));
215- else {
216- dir->table =
217- (struct msdos_dir_entry *) realloc(dir->table, (dir->entries + 1) *
218- sizeof(struct msdos_dir_entry));
219-
220- memset(&dir->table[dir->entries], 0, sizeof(struct msdos_dir_entry));
221- }
222-
223- dir->entries++;
224- }
225+ /* 2 entries, one extra for long filename */
226+ if (!dir->table)
227+ dir->table =
228+ (struct msdos_dir_entry *) malloc(2 * sizeof(struct msdos_dir_entry));
229+ else
230+ dir->table =
231+ (struct msdos_dir_entry *) realloc(dir->table, 2 * (dir->entries + 1) *
232+ sizeof(struct msdos_dir_entry));
233+ if (!dir->table)
234+ printf("Error - realloc failed\n");
235+ memset(&dir->table[dir->entries], 0, 2 * sizeof(struct msdos_dir_entry));
236+ dir->entries += 2;
237 }
238
239 infile = open(filename, O_RDONLY, 0);
240@@ -1611,13 +1599,13 @@ static int add_file(char *filename, stru
241 return -1;
242 }
243
244- printf("ADD %s\n", filename);
245+ printf("ADD FILE %s\n", filename);
246
247 /* Grab the basename of the file */
248 base = basename(filename);
249
250- /* Extract out the 8.3 name */
251- copy_filename(base, name83, ext83);
252+ /* convert for dos fat structure */
253+ copy_filename(base, dos_name);
254
255 /* Make an extended name slot */
256
257@@ -1629,12 +1617,9 @@ static int add_file(char *filename, stru
258
259 slot->alias_checksum = 0;
260
261- for(i = 0; i < 8; i++)
262- slot->alias_checksum = (((slot->alias_checksum&1)<<7)|((slot->alias_checksum&0xfe)>>1)) + name83[i];
263+ for(i = 0; i < MSDOS_NAME; i++)
264+ slot->alias_checksum = (((slot->alias_checksum&1)<<7)|((slot->alias_checksum&0xfe)>>1)) + dos_name[i];
265
266- for(i = 0; i < 3; i++)
267- slot->alias_checksum = (((slot->alias_checksum&1)<<7)|((slot->alias_checksum&0xfe)>>1)) + ext83[i];
268-
269 p = base;
270
271 copy_name(slot->name0_4, 10, &p);
272@@ -1645,8 +1630,7 @@ static int add_file(char *filename, stru
273 /* Get the entry from the root filesytem */
274 entry = &dir->table[dir->count++];
275
276- strncpy(entry->name, name83, 8);
277- strncpy(entry->ext, ext83, 3);
278+ strncpy(entry->name, dos_name, MSDOS_NAME);
279
280
281 /* If the user has it read only, then add read only to the incoming
282@@ -1665,7 +1649,7 @@ static int add_file(char *filename, stru
283 ((ctime->tm_mon+1) << 5) +
284 ((ctime->tm_year-80) << 9)));
285
286- entry->ctime_ms = 0;
287+ entry->ctime_cs = 0;
288 entry->ctime = entry->time;
289 entry->cdate = entry->date;
290 entry->adate = entry->date;
291@@ -1711,6 +1695,7 @@ static int add_file(char *filename, stru
292
293 exit_add:
294 if (infile) close(infile);
295+ return 0;
296 }
297
298 /* Add a new directory to the specified directory entry, and in turn populate
299@@ -1727,10 +1712,18 @@ static void add_directory(char *filename
300 struct dirent *dentry = 0;
301 int remain;
302 char *data;
303+ char *base;
304+ char dos_name[MSDOS_NAME+1];
305+ struct msdos_dir_slot *slot;
306+ int i;
307+ char *p;
308
309 /* If the directory doesn't exist */
310- if (!rddir) return;
311-
312+ if (!rddir) {
313+ printf("Error - dir does not exist: %s\n", filename);
314+ return;
315+ }
316+
317 if (dir->root) {
318 if (dir->count == dir->entries) {
319 printf("Error - too many directory entries\n");
320@@ -1738,28 +1731,58 @@ static void add_directory(char *filename
321 }
322 }
323 else {
324- if (dir->count == dir->entries) {
325- if (!dir->table)
326- dir->table = (struct msdos_dir_entry *) malloc(sizeof(struct msdos_dir_entry));
327- else {
328- dir->table = (struct msdos_dir_entry *) realloc(dir->table, (dir->entries + 1) *
329- sizeof(struct msdos_dir_entry));
330-
331- /* Zero it out to avoid issues */
332- memset(&dir->table[dir->entries], 0, sizeof(struct msdos_dir_entry));
333- }
334- dir->entries++;
335+ /* 2 entries, one extra for long name of the directory */
336+ if (!dir->table)
337+ dir->table = (struct msdos_dir_entry *) malloc(2 * sizeof(struct msdos_dir_entry));
338+ else
339+ dir->table = (struct msdos_dir_entry *) realloc(dir->table, 2 * (dir->entries + 1) *
340+ sizeof(struct msdos_dir_entry));
341+ if (!dir->table) {
342+ printf("Error - memory allocation failed\n");
343+ goto exit_add_dir;
344 }
345+ /* Zero it out to avoid issues */
346+ memset(&dir->table[dir->entries], 0, 2 * sizeof(struct msdos_dir_entry));
347+ dir->entries += 2;
348 }
349
350+ printf("ADD DIR %s\n", filename);
351 /* Now, create a new directory entry for the new directory */
352 newdir = (struct dir_entry *) calloc(1, sizeof(struct dir_entry));
353- if (!newdir) goto exit_add_dir;
354+ if (!newdir) {
355+ printf("Error - calloc failed\n");
356+ goto exit_add_dir;
357+ }
358+
359+ /* Grab the basename of the file */
360+ base = basename(filename);
361+
362+ /* convert for dos structure */
363+ copy_filename(base, dos_name);
364+
365+ /* Make an extended name slot */
366+ slot = (struct msdos_dir_slot *) &dir->table[dir->count++];
367+ slot->id = 'A';
368+ slot->attr = 0x0F;
369+ slot->reserved = 0;
370+ slot->start = 0;
371+
372+ slot->alias_checksum = 0;
373
374+ for (i = 0; i < MSDOS_NAME; i++)
375+ slot->alias_checksum = (((slot->alias_checksum&1)<<7)|((slot->alias_checksum&0xfe)>>1)) + dos_name[i];
376+
377+ p = base;
378+
379+ copy_name(slot->name0_4, 10, &p);
380+ copy_name(slot->name5_10, 12, &p);
381+ copy_name(slot->name11_12, 4, &p);
382+
383+ /* Get the entry from the root filesytem */
384 entry = &dir->table[dir->count++];
385
386- strncpy(entry->name, basename(filename), sizeof(entry->name));
387-
388+ strncpy(entry->name, dos_name, MSDOS_NAME);
389+
390 entry->attr = ATTR_DIR;
391 ctime = localtime(&create_time);
392
393@@ -1770,25 +1793,32 @@ static void add_directory(char *filename
394 ((ctime->tm_mon+1) << 5) +
395 ((ctime->tm_year-80) << 9)));
396
397- entry->ctime_ms = 0;
398+ entry->ctime_cs = 0;
399 entry->ctime = entry->time;
400 entry->cdate = entry->date;
401 entry->adate = entry->date;
402
403 /* Now, read the directory */
404
405- while((dentry = readdir(rddir))) {
406+
407+ while((base[0] != '.') && (dentry = readdir(rddir))) {
408 struct stat st;
409 char *buffer;
410-
411- if (!strcmp(dentry->d_name, ".") || !strcmp(dentry->d_name, ".."))
412- continue;
413
414- /* DOS wouldn't like a typical unix . (dot) file, so we skip those too */
415- if (dentry->d_name[0] == '.') continue;
416+ if (dentry->d_name[0] == '.') {
417+ /* dos also has . & .. directory entries */
418+ if (! ((!strcmp(dentry->d_name, ".")) || (!strcmp(dentry->d_name, "..")))) {
419+ /* ignore other .* files */
420+ printf("Error - File/Dir name is not dos compatible, ignored: %s\n", dentry->d_name);
421+ continue;
422+ }
423+ }
424
425 buffer = malloc(strlen(filename) + strlen(dentry->d_name) + 3);
426- if (!buffer) continue;
427+ if (!buffer) {
428+ printf("Error - malloc failed\n");
429+ goto exit_add_dir;
430+ }
431
432 sprintf(buffer, "%s/%s", filename, dentry->d_name);
433 if (!stat(buffer, &st)) {
434@@ -1806,11 +1836,23 @@ static void add_directory(char *filename
435 /* Now that the entire directory has been written, go ahead and write the directory
436 entry as well */
437
438+ entry->size = 0; /* a directory has zero size */
439+
440+ if (base[0] == '.') { /* . & .. point to parent's cluster */
441+ goto exit_add_dir;
442+ }
443+
444 entry->start = CT_LE_W(last_cluster_written);
445 entry->starthi = CT_LE_W((last_cluster_written & 0xFFFF0000) >> 16);
446- entry->size = newdir->count * sizeof(struct msdos_dir_entry);
447+
448+/* . dir start points to parent */
449+ newdir->table[1].start = entry->start;
450+/* .. dir points to parent of parent*/
451+/* .. dir start is not set yet, would need more changes to the code,
452+ * but dosfsck can fix these .. entry start pointers correctly */
453+
454+ remain = newdir->count * sizeof(struct msdos_dir_entry);
455
456- remain = entry->size;
457 data = (char *) newdir->table;
458
459 while(remain) {
460@@ -1858,6 +1900,7 @@ static void add_root_directory(char *dir
461
462 if (!newdir) {
463 closedir(dir);
464+ printf("Error - calloc failed!\n");
465 return;
466 }
467
468@@ -1877,7 +1920,10 @@ static void add_root_directory(char *dir
469 if (entry->d_name[0] == '.') continue;
470
471 buffer = malloc(strlen(dirname) + strlen(entry->d_name) + 3);
472- if (!buffer) continue;
473+ if (!buffer) {
474+ printf("Error - malloc failed!\n");
475+ continue;
476+ }
477
478 sprintf(buffer, "%s/%s", dirname, entry->d_name);
479 if (!stat(buffer, &st)) {
480@@ -2245,6 +2291,9 @@ main (int argc, char **argv)
481 if (check && listfile) /* Auto and specified bad block handling are mutually */
482 die ("-c and -l are incompatible"); /* exclusive of each other! */
483
484+ if (dirname && (size_fat == 32))
485+ die ("-d is incompatible with FAT32");
486+
487 if (!create) {
488 check_mount (device_name); /* Is the device already mounted? */
489 dev = open (device_name, O_RDWR); /* Is it a suitable device to build the FS on? */
diff --git a/meta/recipes-devtools/dosfstools/dosfstools/include-linux-types.patch b/meta/recipes-devtools/dosfstools/dosfstools/include-linux-types.patch
new file mode 100644
index 0000000..ab5c8cf
--- /dev/null
+++ b/meta/recipes-devtools/dosfstools/dosfstools/include-linux-types.patch
@@ -0,0 +1,22 @@
1mkdsofs is using types of the style __u8, which it gets with some
2versions of libc headers via linux/hdreg.h including asm/types.h.
3Newer version of fedora (at least) have a hdreg.h whichdoes not
4include asm/types.h. To work around this patch mkdosfs.c to explicity
5include linux/types.h which will in turn pull in asm/types.h which
6defines these variables.
7
8Upstream-Status: Inappropriate [licensing]
9We're tracking an old release of dosfstools due to licensing issues.
10
11Signed-off-by: Scott Garman <scott.a.garman@intel.com>
12
13--- dosfstools-2.10/mkdosfs/mkdosfs.c~ 2006-07-12 18:46:21.000000000 +1000
14+++ dosfstools-2.10/mkdosfs/mkdosfs.c 2006-07-12 18:46:21.000000000 +1000
15@@ -60,6 +60,7 @@
16 #include "../version.h"
17
18 #include <fcntl.h>
19+#include <linux/types.h>
20 #include <linux/hdreg.h>
21 #include <linux/fs.h>
22 #include <linux/fd.h>
diff --git a/meta/recipes-devtools/dosfstools/dosfstools/mkdosfs-bootcode.patch b/meta/recipes-devtools/dosfstools/dosfstools/mkdosfs-bootcode.patch
new file mode 100644
index 0000000..ae21bee
--- /dev/null
+++ b/meta/recipes-devtools/dosfstools/dosfstools/mkdosfs-bootcode.patch
@@ -0,0 +1,241 @@
1Add option to read in bootcode from a file.
2
3Upstream-Status: Inappropriate [licensing]
4We're tracking an old release of dosfstools due to licensing issues.
5
6Signed-off-by: Scott Garman <scott.a.garman@intel.com>
7
8Index: dosfstools-2.11/mkdosfs/ChangeLog
9===================================================================
10--- dosfstools-2.11.orig/mkdosfs/ChangeLog 1997-06-18 10:09:38.000000000 +0000
11+++ dosfstools-2.11/mkdosfs/ChangeLog 2011-12-06 12:14:23.634011558 +0000
12@@ -1,3 +1,14 @@
13+19th June 2003 Sam Bingner (sam@bingner.com)
14+
15+ Added option to read in bootcode from a file so that if you have
16+ for example Windows 2000 boot code, you can have it write that
17+ as the bootcode. This is a dump of the behinning of a partition
18+ generally 512 bytes, but can be up to reserved sectors*512 bytes.
19+ Also writes 0x80 as the BIOS drive number if we are formatting a
20+ hard drive, and sets the number of hidden sectors to be the
21+ number of sectors in one track. These were required so that DOS
22+ could boot using the bootcode.
23+
24 28th January 1995 H. Peter Anvin (hpa@yggdrasil.com)
25
26 Better algorithm to select cluster sizes on large filesystems.
27Index: dosfstools-2.11/mkdosfs/mkdosfs.8
28===================================================================
29--- dosfstools-2.11.orig/mkdosfs/mkdosfs.8 2004-02-25 19:36:07.000000000 +0000
30+++ dosfstools-2.11/mkdosfs/mkdosfs.8 2011-12-06 12:19:54.777888434 +0000
31@@ -44,6 +44,10 @@
32 .I message-file
33 ]
34 [
35+.B \-B
36+.I bootcode-file
37+]
38+[
39 .B \-n
40 .I volume-name
41 ]
42@@ -165,6 +169,18 @@
43 carriage return-line feed combinations, and tabs have been expanded.
44 If the filename is a hyphen (-), the text is taken from standard input.
45 .TP
46+.BI \-B " bootcode-file"
47+Uses boot machine code from file "file". On any thing other than FAT32,
48+this only writes the first 3 bytes, and 480 bytes from offset 3Eh. On
49+FAT32, this writes the first 3 bytes, 420 bytes from offset 5Ah to both
50+primary and backup boot sectors. Also writes all other reserved sectors
51+excluding the sectors following boot sectors (usually sector 2 and 7).
52+Does not require that the input file be as large as reserved_sectors*512.
53+To make a FAT32 partition bootable, you will need at least the first
54+13 sectors (6656 bytes). You can also specify a partition as the argument
55+to clone the boot code from that partition.
56+i.e mkdosfs -B /dev/sda1 /dev/sda1
57+.TP
58 .BI \-n " volume-name"
59 Sets the volume name (label) of the filesystem. The volume name can
60 be up to 11 characters long. The default is no label.
61@@ -198,8 +214,9 @@
62 simply will not support it ;)
63 .SH AUTHOR
64 Dave Hudson - <dave@humbug.demon.co.uk>; modified by Peter Anvin
65-<hpa@yggdrasil.com>. Fixes and additions by Roman Hodek
66-<roman@hodek.net> for Debian/GNU Linux.
67+<hpa@yggdrasil.com> and Sam Bingner <sam@bingner.com>. Fixes and
68+additions by Roman Hodek <Roman.Hodek@informatik.uni-erlangen.de>
69+for Debian/GNU Linux.
70 .SH ACKNOWLEDGEMENTS
71 .B mkdosfs
72 is based on code from
73Index: dosfstools-2.11/mkdosfs/mkdosfs.c
74===================================================================
75--- dosfstools-2.11.orig/mkdosfs/mkdosfs.c 2005-03-12 16:12:16.000000000 +0000
76+++ dosfstools-2.11/mkdosfs/mkdosfs.c 2011-12-06 12:27:55.121886076 +0000
77@@ -24,6 +24,12 @@
78 - New options -A, -S, -C
79 - Support for filesystems > 2GB
80 - FAT32 support
81+
82+ Fixes/additions June 2003 by Sam Bingner
83+ <sam@bingner.com>:
84+ - Add -B option to read in bootcode from a file
85+ - Write BIOS drive number so that FS can properly boot
86+ - Set number of hidden sectors before boot code to be one track
87
88 Copying: Copyright 1993, 1994 David Hudson (dave@humbug.demon.co.uk)
89
90@@ -153,6 +159,8 @@
91 #define FAT_BAD 0x0ffffff7
92
93 #define MSDOS_EXT_SIGN 0x29 /* extended boot sector signature */
94+#define HD_DRIVE_NUMBER 0x80 /* Boot off first hard drive */
95+#define FD_DRIVE_NUMBER 0x00 /* Boot off first floppy drive */
96 #define MSDOS_FAT12_SIGN "FAT12 " /* FAT12 filesystem signature */
97 #define MSDOS_FAT16_SIGN "FAT16 " /* FAT16 filesystem signature */
98 #define MSDOS_FAT32_SIGN "FAT32 " /* FAT32 filesystem signature */
99@@ -175,6 +183,8 @@
100 #define BOOTCODE_SIZE 448
101 #define BOOTCODE_FAT32_SIZE 420
102
103+#define MAX_RESERVED 0xFFFF
104+
105 /* __attribute__ ((packed)) is used on all structures to make gcc ignore any
106 * alignments */
107
108@@ -202,7 +212,7 @@
109 __u16 fat_length; /* sectors/FAT */
110 __u16 secs_track; /* sectors per track */
111 __u16 heads; /* number of heads */
112- __u32 hidden; /* hidden sectors (unused) */
113+ __u32 hidden; /* hidden sectors (one track) */
114 __u32 total_sect; /* number of sectors (if sectors == 0) */
115 union {
116 struct {
117@@ -285,6 +295,8 @@
118
119 /* Global variables - the root of all evil :-) - see these and weep! */
120
121+static char *template_boot_code; /* Variable to store a full template boot sector in */
122+static int use_template = 0;
123 static char *program_name = "mkdosfs"; /* Name of the program */
124 static char *device_name = NULL; /* Name of the device on which to create the filesystem */
125 static int atari_format = 0; /* Use Atari variation of MS-DOS FS format */
126@@ -837,6 +849,12 @@
127 vi->volume_id[2] = (unsigned char) ((volume_id & 0x00ff0000) >> 16);
128 vi->volume_id[3] = (unsigned char) (volume_id >> 24);
129 }
130+ if (bs.media == 0xf8) {
131+ vi->drive_number = HD_DRIVE_NUMBER; /* Set bios drive number to 80h */
132+ }
133+ else {
134+ vi->drive_number = FD_DRIVE_NUMBER; /* Set bios drive number to 00h */
135+ }
136
137 if (!atari_format) {
138 memcpy(vi->volume_label, volume_name, 11);
139@@ -1362,6 +1380,32 @@
140 * dir area on FAT12/16, and the first cluster on FAT32. */
141 writebuf( (char *) root_dir, size_root_dir, "root directory" );
142
143+ if (use_template == 1) {
144+ /* dupe template into reserved sectors */
145+ seekto( 0, "Start of partition" );
146+ if (size_fat == 32) {
147+ writebuf( template_boot_code, 3, "backup jmpBoot" );
148+ seekto( 0x5a, "sector 1 boot area" );
149+ writebuf( template_boot_code+0x5a, 420, "sector 1 boot area" );
150+ seekto( 512*2, "third sector" );
151+ if (backup_boot != 0) {
152+ writebuf( template_boot_code+512*2, backup_boot*sector_size - 512*2, "data to backup boot" );
153+ seekto( backup_boot*sector_size, "backup boot sector" );
154+ writebuf( template_boot_code, 3, "backup jmpBoot" );
155+ seekto( backup_boot*sector_size+0x5a, "backup boot sector boot area" );
156+ writebuf( template_boot_code+0x5a, 420, "backup boot sector boot area" );
157+ seekto( (backup_boot+2)*sector_size, "sector following backup code" );
158+ writebuf( template_boot_code+(backup_boot+2)*sector_size, (reserved_sectors-backup_boot-2)*512, "remaining data" );
159+ } else {
160+ writebuf( template_boot_code+512*2, (reserved_sectors-2)*512, "remaining data" );
161+ }
162+ } else {
163+ writebuf( template_boot_code, 3, "jmpBoot" );
164+ seekto( 0x3e, "sector 1 boot area" );
165+ writebuf( template_boot_code+0x3e, 448, "boot code" );
166+ }
167+ }
168+
169 if (blank_sector) free( blank_sector );
170 if (info_sector) free( info_sector );
171 free (root_dir); /* Free up the root directory space from setup_tables */
172@@ -1376,7 +1420,7 @@
173 {
174 fatal_error("\
175 Usage: mkdosfs [-A] [-c] [-C] [-v] [-I] [-l bad-block-file] [-b backup-boot-sector]\n\
176- [-m boot-msg-file] [-n volume-name] [-i volume-id]\n\
177+ [-m boot-msg-file] [-n volume-name] [-i volume-id] [-B bootcode]\n\
178 [-s sectors-per-cluster] [-S logical-sector-size] [-f number-of-FATs]\n\
179 [-h hidden-sectors] [-F fat-size] [-r root-dir-entries] [-R reserved-sectors]\n\
180 /dev/name [blocks]\n");
181@@ -1439,7 +1483,7 @@
182 printf ("%s " VERSION " (" VERSION_DATE ")\n",
183 program_name);
184
185- while ((c = getopt (argc, argv, "AbcCf:F:Ii:l:m:n:r:R:s:S:h:v")) != EOF)
186+ while ((c = getopt (argc, argv, "AbcCf:F:Ii:l:m:n:r:R:s:S:v:B:")) != EOF)
187 /* Scan the command line for options */
188 switch (c)
189 {
190@@ -1509,6 +1553,51 @@
191 listfile = optarg;
192 break;
193
194+ case 'B': /* B : read in bootcode */
195+ if ( strcmp(optarg, "-") )
196+ {
197+ msgfile = fopen(optarg, "r");
198+ if ( !msgfile )
199+ perror(optarg);
200+ }
201+ else
202+ msgfile = stdin;
203+
204+ if ( msgfile )
205+ {
206+ if (!(template_boot_code = malloc( MAX_RESERVED )))
207+ die( "Out of memory" );
208+ /* The template boot sector including reserved must not be > 65535 */
209+ use_template = 1;
210+ i = 0;
211+ do
212+ {
213+ ch = getc(msgfile);
214+ switch (ch)
215+ {
216+ case EOF:
217+ break;
218+
219+ default:
220+ template_boot_code[i++] = ch; /* Store character */
221+ break;
222+ }
223+ }
224+ while ( ch != EOF && i < MAX_RESERVED );
225+ ch = getc(msgfile); /* find out if we're at EOF */
226+
227+ /* Fill up with zeros */
228+ while( i < MAX_RESERVED )
229+ template_boot_code[i++] = '\0';
230+
231+ if ( ch != EOF )
232+ printf ("Warning: template too long; truncated after %d bytes\n", i);
233+
234+ if ( msgfile != stdin )
235+ fclose(msgfile);
236+ }
237+ break;
238+
239 case 'm': /* m : Set boot message */
240 if ( strcmp(optarg, "-") )
241 {
diff --git a/meta/recipes-devtools/dosfstools/dosfstools/mkdosfs-dir.patch b/meta/recipes-devtools/dosfstools/dosfstools/mkdosfs-dir.patch
new file mode 100644
index 0000000..3ba4711
--- /dev/null
+++ b/meta/recipes-devtools/dosfstools/dosfstools/mkdosfs-dir.patch
@@ -0,0 +1,639 @@
1Add -d <directory> support to populate the image.
2
3Upstream-Status: Inappropriate [licensing]
4We're tracking an old release of dosfstools due to licensing issues.
5
6Signed-off-by: Scott Garman <scott.a.garman@intel.com>
7
8Index: dosfstools-2.11/mkdosfs/mkdosfs.c
9===================================================================
10--- dosfstools-2.11.orig/mkdosfs/mkdosfs.c 2011-12-06 12:27:55.000000000 +0000
11+++ dosfstools-2.11/mkdosfs/mkdosfs.c 2011-12-06 12:37:13.445950703 +0000
12@@ -18,6 +18,10 @@
13 as a rule), and not the block. For example the boot block does not
14 occupy a full cluster.
15
16+ June 2004 - Jordan Crouse (info.linux@amd.com)
17+ Added -d <directory> support to populate the image
18+ Copyright (C) 2004, Advanced Micro Devices, All Rights Reserved
19+
20 Fixes/additions May 1998 by Roman Hodek
21 <Roman.Hodek@informatik.uni-erlangen.de>:
22 - Atari format support
23@@ -71,6 +75,8 @@
24 #include <unistd.h>
25 #include <time.h>
26 #include <errno.h>
27+#include <libgen.h>
28+#include <dirent.h>
29
30 #include <linux/version.h>
31 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)
32@@ -110,6 +116,8 @@
33 * sufficient (or even better :) for 64 bit offsets in the meantime */
34 #define llseek lseek
35
36+#define ROUND_UP(value, divisor) (value + (divisor - (value % divisor))) / divisor
37+
38 /* Constant definitions */
39
40 #define TRUE 1 /* Boolean constants */
41@@ -149,7 +157,6 @@
42 #define ATTR_VOLUME 8 /* volume label */
43 #define ATTR_DIR 16 /* directory */
44 #define ATTR_ARCH 32 /* archived */
45-
46 #define ATTR_NONE 0 /* no attribute bits */
47 #define ATTR_UNUSED (ATTR_VOLUME | ATTR_ARCH | ATTR_SYS | ATTR_HIDDEN)
48 /* attribute bits that are copied "as is" */
49@@ -245,6 +252,19 @@
50 __u32 reserved2[4];
51 };
52
53+/* This stores up to 13 chars of the name */
54+
55+struct msdos_dir_slot {
56+ __u8 id; /* sequence number for slot */
57+ __u8 name0_4[10]; /* first 5 characters in name */
58+ __u8 attr; /* attribute byte */
59+ __u8 reserved; /* always 0 */
60+ __u8 alias_checksum; /* checksum for 8.3 alias */
61+ __u8 name5_10[12]; /* 6 more characters in name */
62+ __u16 start; /* starting cluster number, 0 in long slots */
63+ __u8 name11_12[4]; /* last 2 characters in name */
64+};
65+
66 struct msdos_dir_entry
67 {
68 char name[8], ext[3]; /* name and extension */
69@@ -293,6 +313,15 @@
70
71 #define MESSAGE_OFFSET 29 /* Offset of message in above code */
72
73+/* Special structure to keep track of directories as we add them for the -d option */
74+
75+struct dir_entry {
76+ int root; /* Specifies if this is the root dir or not */
77+ int count; /* Number of items in the table */
78+ int entries; /* Number of entries in the table */
79+ struct msdos_dir_entry *table; /* Pointer to the entry table */
80+};
81+
82 /* Global variables - the root of all evil :-) - see these and weep! */
83
84 static char *template_boot_code; /* Variable to store a full template boot sector in */
85@@ -326,6 +355,9 @@
86 static int size_root_dir; /* Size of the root directory in bytes */
87 static int sectors_per_cluster = 0; /* Number of sectors per disk cluster */
88 static int root_dir_entries = 0; /* Number of root directory entries */
89+static int root_dir_num_entries = 0;
90+static int last_cluster_written = 0;
91+
92 static char *blank_sector; /* Blank sector - all zeros */
93 static int hidden_sectors = 0; /* Number of hidden sectors */
94
95@@ -399,7 +431,6 @@
96 }
97 }
98
99-
100 /* Mark a specified sector as having a particular value in it's FAT entry */
101
102 static void
103@@ -1266,6 +1297,9 @@
104 die ("unable to allocate space for root directory in memory");
105 }
106
107+
108+ last_cluster_written = 2;
109+
110 memset(root_dir, 0, size_root_dir);
111 if ( memcmp(volume_name, " ", 11) )
112 {
113@@ -1314,11 +1348,11 @@
114 }
115
116 if (!(blank_sector = malloc( sector_size )))
117- die( "Out of memory" );
118+ die( "Out of memory" );
119+
120 memset(blank_sector, 0, sector_size);
121 }
122-
123-
124+
125 /* Write the new filesystem's data tables to wherever they're going to end up! */
126
127 #define error(str) \
128@@ -1340,7 +1374,7 @@
129 do { \
130 int __size = (size); \
131 if (write (dev, buf, __size) != __size) \
132- error ("failed whilst writing " errstr); \
133+ error ("failed whilst writing " errstr); \
134 } while(0)
135
136
137@@ -1412,6 +1446,452 @@
138 free (fat); /* Free up the fat table space reserved during setup_tables */
139 }
140
141+/* Add a file to the specified directory entry, and also write it into the image */
142+
143+static void copy_filename(char *filename, char *base, char *ext) {
144+
145+ char *ch = filename;
146+ int i, len;
147+
148+ memset(base, 0x20, 8);
149+ memset(ext, 0x20, 3);
150+
151+ for(len = 0 ; *ch && *ch != '.'; ch++) {
152+ base[len++] = toupper(*ch);
153+ if (len == 8) break;
154+ }
155+
156+ for ( ; *ch && *ch != '.'; ch++);
157+ if (*ch) ch++;
158+
159+ for(len = 0 ; *ch; ch++) {
160+ ext[len++] = toupper(*ch);
161+ if (len == 3) break;
162+ }
163+}
164+
165+/* Check for an .attrib.<filename> file, and read the attributes therein */
166+
167+/* We are going to be pretty pedantic about this. The file needs 3
168+ bytes at the beginning, the attributes are listed in this order:
169+
170+ (H)idden|(S)ystem|(A)rchived
171+
172+ A capital HSA means to enable it, anything else will disable it
173+ (I recommend a '-') The unix user attributes will still be used
174+ for write access.
175+
176+ For example, to enable system file access for ldlinux.sys, write
177+ the following to .attrib.ldlinux.sys: -S-
178+*/
179+
180+unsigned char check_attrib_file(char *dir, char *filename) {
181+
182+ char attrib[4] = { '-', '-', '-' };
183+ unsigned char *buffer = 0;
184+ int ret = ATTR_NONE;
185+ int fd = -1;
186+
187+ buffer = (char *) calloc(1, strlen(dir) + strlen(filename) + 10);
188+ if (!buffer) return ATTR_NONE;
189+
190+ sprintf(buffer, "%s/.attrib.%s", dir, filename);
191+
192+ if (access(buffer, R_OK))
193+ goto exit_attrib;
194+
195+ if ((fd = open(buffer, O_RDONLY, 0)) < 0)
196+ goto exit_attrib;
197+
198+ if (read(fd, attrib, 3) < 0)
199+ goto exit_attrib;
200+
201+ if (attrib[0] == 'H') ret |= ATTR_HIDDEN;
202+ if (attrib[1] == 'S') ret |= ATTR_SYS;
203+ if (attrib[2] == 'A') ret |= ATTR_ARCH;
204+
205+ printf("%s: Setting atrribute %x\n", filename, ret);
206+
207+ exit_attrib:
208+ if (fd >= 0) close(fd);
209+ if (buffer) free(buffer);
210+
211+ return ret;
212+}
213+
214+static void copy_name(char *buffer, int size, char **pointer) {
215+ int i;
216+
217+ for(i = 0; i < size; i += 2) {
218+ if (*pointer) {
219+ buffer[i] = **pointer;
220+ buffer[i + 1] = 0x00;
221+ *pointer = **pointer ? *pointer + 1 : 0;
222+ }
223+ else {
224+ buffer[i] = 0xFF;
225+ buffer[i + 1] = 0xFF;
226+ }
227+ }
228+}
229+
230+static int add_file(char *filename, struct dir_entry *dir, unsigned char attr)
231+{
232+ struct stat stat;
233+ struct msdos_dir_entry *entry;
234+ int infile = 0;
235+ int sectors, clusters;
236+ struct tm *ctime;
237+ int c, s;
238+ int ptr;
239+ char *buffer, *base;
240+ int start;
241+ int usedsec, totalsec;
242+
243+ char name83[8], ext83[3];
244+
245+ struct msdos_dir_slot *slot;
246+ int i;
247+ char *p;
248+
249+ /* The root directory is static, everything else grows as needed */
250+
251+ if (dir->root) {
252+ if (dir->count == dir->entries) {
253+ printf("Error - too many directory entries\n");
254+ }
255+ }
256+ else {
257+ if (dir->count == dir->entries) {
258+ if (!dir->table)
259+ dir->table =
260+ (struct msdos_dir_entry *) malloc(sizeof(struct msdos_dir_entry));
261+ else {
262+ dir->table =
263+ (struct msdos_dir_entry *) realloc(dir->table, (dir->entries + 1) *
264+ sizeof(struct msdos_dir_entry));
265+
266+ memset(&dir->table[dir->entries], 0, sizeof(struct msdos_dir_entry));
267+ }
268+
269+ dir->entries++;
270+ }
271+ }
272+
273+ infile = open(filename, O_RDONLY, 0);
274+ if (!infile) return;
275+
276+ if (fstat(infile, &stat))
277+ goto exit_add;
278+
279+ if (S_ISCHR(stat.st_mode) ||S_ISBLK(stat.st_mode) ||
280+ S_ISFIFO(stat.st_mode) || S_ISLNK(stat.st_mode)) {
281+ printf("Error - cannot create a special file in a FATFS\n");
282+ goto exit_add;
283+ }
284+
285+ /* FIXME: This isn't very pretty */
286+
287+ usedsec = start_data_sector + (size_root_dir / sector_size) +
288+ (last_cluster_written * bs.cluster_size);
289+
290+ totalsec = blocks * BLOCK_SIZE / sector_size;
291+
292+ /* Figure out how many sectors / clustors the file requires */
293+
294+ sectors = ROUND_UP(stat.st_size, sector_size);
295+ clusters = ROUND_UP(sectors, (int) bs.cluster_size);
296+
297+ if (usedsec + sectors > totalsec) {
298+ printf("Error - %s is too big (%d vs %d)\n", filename, sectors, totalsec - usedsec);
299+ close(infile);
300+ return -1;
301+ }
302+
303+ printf("ADD %s\n", filename);
304+
305+ /* Grab the basename of the file */
306+ base = basename(filename);
307+
308+ /* Extract out the 8.3 name */
309+ copy_filename(base, name83, ext83);
310+
311+ /* Make an extended name slot */
312+
313+ slot = (struct msdos_dir_slot *) &dir->table[dir->count++];
314+ slot->id = 'A';
315+ slot->attr = 0x0F;
316+ slot->reserved = 0;
317+ slot->start = 0;
318+
319+ slot->alias_checksum = 0;
320+
321+ for(i = 0; i < 8; i++)
322+ slot->alias_checksum = (((slot->alias_checksum&1)<<7)|((slot->alias_checksum&0xfe)>>1)) + name83[i];
323+
324+ for(i = 0; i < 3; i++)
325+ slot->alias_checksum = (((slot->alias_checksum&1)<<7)|((slot->alias_checksum&0xfe)>>1)) + ext83[i];
326+
327+ p = base;
328+
329+ copy_name(slot->name0_4, 10, &p);
330+ copy_name(slot->name5_10, 12, &p);
331+ copy_name(slot->name11_12, 4, &p);
332+
333+
334+ /* Get the entry from the root filesytem */
335+ entry = &dir->table[dir->count++];
336+
337+ strncpy(entry->name, name83, 8);
338+ strncpy(entry->ext, ext83, 3);
339+
340+
341+ /* If the user has it read only, then add read only to the incoming
342+ attribute settings */
343+
344+ if (!(stat.st_mode & S_IWUSR)) attr |= ATTR_RO;
345+ entry->attr = attr;
346+
347+ /* Set the access time on the file */
348+ ctime = localtime(&create_time);
349+
350+ entry->time = CT_LE_W((unsigned short)((ctime->tm_sec >> 1) +
351+ (ctime->tm_min << 5) + (ctime->tm_hour << 11)));
352+
353+ entry->date = CT_LE_W((unsigned short)(ctime->tm_mday +
354+ ((ctime->tm_mon+1) << 5) +
355+ ((ctime->tm_year-80) << 9)));
356+
357+ entry->ctime_ms = 0;
358+ entry->ctime = entry->time;
359+ entry->cdate = entry->date;
360+ entry->adate = entry->date;
361+ entry->size = stat.st_size;
362+
363+ start = last_cluster_written;
364+
365+ entry->start = CT_LE_W(start); /* start sector */
366+ entry->starthi = CT_LE_W((start & 0xFFFF0000) >> 16); /* High start sector (for FAT32) */
367+
368+ /* We mark all of the clusters we use in the FAT */
369+
370+ for(c = 0; c < clusters; c++ ) {
371+ int free;
372+ int next = c == (clusters - 1) ? FAT_EOF : start + c + 1;
373+ mark_FAT_cluster(start + c, next);
374+ last_cluster_written++;
375+ }
376+
377+ /* This confused me too - cluster 2 starts after the
378+ root directory data - search me as to why */
379+
380+ ptr = (start_data_sector * sector_size) + size_root_dir;
381+ ptr += (start - 2) * bs.cluster_size * sector_size;
382+
383+ buffer = (char *) malloc(sector_size);
384+
385+ if (!buffer) {
386+ printf("Error - couldn't allocate memory\n");
387+ goto exit_add;
388+ }
389+
390+ /* Write the file into the file block */
391+
392+ seekto(ptr, "datafile");
393+
394+ while(1) {
395+ int size = read(infile, buffer, sector_size);
396+ if (size <= 0) break;
397+
398+ writebuf(buffer, size, "data");
399+ }
400+
401+ exit_add:
402+ if (infile) close(infile);
403+}
404+
405+/* Add a new directory to the specified directory entry, and in turn populate
406+ it with its own files */
407+
408+/* FIXME: This should check to make sure there is enough size to add itself */
409+
410+static void add_directory(char *filename, struct dir_entry *dir) {
411+
412+ struct dir_entry *newdir = 0;
413+ struct msdos_dir_entry *entry;
414+ struct tm *ctime;
415+ DIR *rddir = opendir(filename);
416+ struct dirent *dentry = 0;
417+ int remain;
418+ char *data;
419+
420+ /* If the directory doesn't exist */
421+ if (!rddir) return;
422+
423+ if (dir->root) {
424+ if (dir->count == dir->entries) {
425+ printf("Error - too many directory entries\n");
426+ goto exit_add_dir;
427+ }
428+ }
429+ else {
430+ if (dir->count == dir->entries) {
431+ if (!dir->table)
432+ dir->table = (struct msdos_dir_entry *) malloc(sizeof(struct msdos_dir_entry));
433+ else {
434+ dir->table = (struct msdos_dir_entry *) realloc(dir->table, (dir->entries + 1) *
435+ sizeof(struct msdos_dir_entry));
436+
437+ /* Zero it out to avoid issues */
438+ memset(&dir->table[dir->entries], 0, sizeof(struct msdos_dir_entry));
439+ }
440+ dir->entries++;
441+ }
442+ }
443+
444+ /* Now, create a new directory entry for the new directory */
445+ newdir = (struct dir_entry *) calloc(1, sizeof(struct dir_entry));
446+ if (!newdir) goto exit_add_dir;
447+
448+ entry = &dir->table[dir->count++];
449+
450+ strncpy(entry->name, basename(filename), sizeof(entry->name));
451+
452+ entry->attr = ATTR_DIR;
453+ ctime = localtime(&create_time);
454+
455+ entry->time = CT_LE_W((unsigned short)((ctime->tm_sec >> 1) +
456+ (ctime->tm_min << 5) + (ctime->tm_hour << 11)));
457+
458+ entry->date = CT_LE_W((unsigned short)(ctime->tm_mday +
459+ ((ctime->tm_mon+1) << 5) +
460+ ((ctime->tm_year-80) << 9)));
461+
462+ entry->ctime_ms = 0;
463+ entry->ctime = entry->time;
464+ entry->cdate = entry->date;
465+ entry->adate = entry->date;
466+
467+ /* Now, read the directory */
468+
469+ while((dentry = readdir(rddir))) {
470+ struct stat st;
471+ char *buffer;
472+
473+ if (!strcmp(dentry->d_name, ".") || !strcmp(dentry->d_name, ".."))
474+ continue;
475+
476+ /* DOS wouldn't like a typical unix . (dot) file, so we skip those too */
477+ if (dentry->d_name[0] == '.') continue;
478+
479+ buffer = malloc(strlen(filename) + strlen(dentry->d_name) + 3);
480+ if (!buffer) continue;
481+
482+ sprintf(buffer, "%s/%s", filename, dentry->d_name);
483+ if (!stat(buffer, &st)) {
484+ if (S_ISDIR(st.st_mode))
485+ add_directory(buffer, newdir);
486+ else if (S_ISREG(st.st_mode)) {
487+ unsigned char attrib = check_attrib_file(filename, dentry->d_name);
488+ add_file(buffer, newdir, attrib);
489+ }
490+ }
491+
492+ free(buffer);
493+ }
494+
495+ /* Now that the entire directory has been written, go ahead and write the directory
496+ entry as well */
497+
498+ entry->start = CT_LE_W(last_cluster_written);
499+ entry->starthi = CT_LE_W((last_cluster_written & 0xFFFF0000) >> 16);
500+ entry->size = newdir->count * sizeof(struct msdos_dir_entry);
501+
502+ remain = entry->size;
503+ data = (char *) newdir->table;
504+
505+ while(remain) {
506+ int size =
507+ remain > bs.cluster_size * sector_size ? bs.cluster_size * sector_size : remain;
508+
509+ int pos = (start_data_sector * sector_size) + size_root_dir;
510+ pos += (last_cluster_written - 2) * bs.cluster_size * sector_size;
511+
512+ seekto(pos, "add_dir");
513+ writebuf(data, size, "add_dir");
514+
515+ remain -= size;
516+ data += size;
517+
518+ mark_FAT_cluster(last_cluster_written, remain ? last_cluster_written + 1 : FAT_EOF);
519+ last_cluster_written++;
520+ }
521+
522+ exit_add_dir:
523+ if (rddir) closedir(rddir);
524+ if (newdir->table) free(newdir->table);
525+ if (newdir) free(newdir);
526+}
527+
528+/* Given a directory, add all the files and directories to the root directory of the
529+ image.
530+*/
531+
532+static void add_root_directory(char *dirname)
533+{
534+ DIR *dir = opendir(dirname);
535+ struct dirent *entry = 0;
536+ struct dir_entry *newdir = 0;
537+
538+ if (!dir) {
539+ printf("Error - directory %s does not exist\n", dirname);
540+ return;
541+ }
542+
543+ /* Create the root directory structure - this is a bit different then
544+ above, because the table already exists, we just refer to it. */
545+
546+ newdir = (struct dir_entry *) calloc(1,sizeof(struct dir_entry));
547+
548+ if (!newdir) {
549+ closedir(dir);
550+ return;
551+ }
552+
553+ newdir->entries = root_dir_entries;
554+ newdir->root = 1;
555+ newdir->count = 0;
556+ newdir->table = root_dir;
557+
558+ while((entry = readdir(dir))) {
559+ struct stat st;
560+ char *buffer;
561+
562+ if (!strcmp(entry->d_name, ".") || !strcmp(entry->d_name, ".."))
563+ continue;
564+
565+ /* DOS wouldn't like a typical unix . (dot) file, so we skip those too */
566+ if (entry->d_name[0] == '.') continue;
567+
568+ buffer = malloc(strlen(dirname) + strlen(entry->d_name) + 3);
569+ if (!buffer) continue;
570+
571+ sprintf(buffer, "%s/%s", dirname, entry->d_name);
572+ if (!stat(buffer, &st)) {
573+ if (S_ISDIR(st.st_mode))
574+ add_directory(buffer, newdir);
575+ else if (S_ISREG(st.st_mode)) {
576+ unsigned char attrib = check_attrib_file(dirname, entry->d_name);
577+ add_file(buffer, newdir, attrib);
578+ }
579+ }
580+
581+ free(buffer);
582+ }
583+
584+ closedir(dir);
585+ if (newdir) free(newdir);
586+}
587
588 /* Report the command usage and return a failure error code */
589
590@@ -1423,7 +1903,7 @@
591 [-m boot-msg-file] [-n volume-name] [-i volume-id] [-B bootcode]\n\
592 [-s sectors-per-cluster] [-S logical-sector-size] [-f number-of-FATs]\n\
593 [-h hidden-sectors] [-F fat-size] [-r root-dir-entries] [-R reserved-sectors]\n\
594- /dev/name [blocks]\n");
595+ [-d directory] /dev/name [blocks]\n");
596 }
597
598 /*
599@@ -1463,6 +1943,8 @@
600 int c;
601 char *tmp;
602 char *listfile = NULL;
603+ char *dirname = NULL;
604+
605 FILE *msgfile;
606 struct stat statbuf;
607 int i = 0, pos, ch;
608@@ -1483,7 +1965,7 @@
609 printf ("%s " VERSION " (" VERSION_DATE ")\n",
610 program_name);
611
612- while ((c = getopt (argc, argv, "AbcCf:F:Ii:l:m:n:r:R:s:S:v:B:")) != EOF)
613+ while ((c = getopt (argc, argv, "AbcCd:f:F:Ii:l:m:n:r:R:s:S:v:B:")) != EOF)
614 /* Scan the command line for options */
615 switch (c)
616 {
617@@ -1508,6 +1990,10 @@
618 create = TRUE;
619 break;
620
621+ case 'd':
622+ dirname = optarg;
623+ break;
624+
625 case 'f': /* f : Choose number of FATs */
626 nr_fats = (int) strtol (optarg, &tmp, 0);
627 if (*tmp || nr_fats < 1 || nr_fats > 4)
628@@ -1811,8 +2297,10 @@
629 else if (listfile)
630 get_list_blocks (listfile);
631
632- write_tables (); /* Write the file system tables away! */
633
634+ if (dirname) add_root_directory(dirname);
635+
636+ write_tables (); /* Write the file system tables away! */
637 exit (0); /* Terminate with no errors! */
638 }
639
diff --git a/meta/recipes-devtools/dosfstools/dosfstools/msdos_fat12_undefined.patch b/meta/recipes-devtools/dosfstools/dosfstools/msdos_fat12_undefined.patch
new file mode 100644
index 0000000..11e8a75
--- /dev/null
+++ b/meta/recipes-devtools/dosfstools/dosfstools/msdos_fat12_undefined.patch
@@ -0,0 +1,19 @@
1Fix a compilation error due to undefined MSDOS_FAT12.
2
3Upstream-Status: Inappropriate [licensing]
4We're tracking an old release of dosfstools due to licensing issues.
5
6Signed-off-by: Scott Garman <scott.a.garman@intel.com>
7
8--- dosfstools-2.10/dosfsck/boot.c.orig 2004-10-15 08:51:42.394725176 -0600
9+++ dosfstools-2.10/dosfsck/boot.c 2004-10-15 08:49:16.776862456 -0600
10@@ -14,6 +14,9 @@
11 #include "io.h"
12 #include "boot.h"
13
14+#ifndef MSDOS_FAT12
15+#define MSDOS_FAT12 4084
16+#endif
17
18 #define ROUND_TO_MULTIPLE(n,m) ((n) && (m) ? (n)+(m)-1-((n)-1)%(m) : 0)
19 /* don't divide by zero */
diff --git a/meta/recipes-devtools/dosfstools/dosfstools/nofat32_autoselect.patch b/meta/recipes-devtools/dosfstools/dosfstools/nofat32_autoselect.patch
new file mode 100644
index 0000000..6ee3f7f
--- /dev/null
+++ b/meta/recipes-devtools/dosfstools/dosfstools/nofat32_autoselect.patch
@@ -0,0 +1,27 @@
1FAT32 appears to be broken when used with the -d option to populate the msdos
2image. This disables the FAT32 autoselection code which means we don't get
3broken images with the -d option. It can still be enabled on the commandline
4at the users own risk. This changes us back to the 2.10 version's behaviour
5which was known to work well even with large images.
6
7Upstream-Status: Inapproriate [depends on other patches we apply]
8
9RP 2011/12/13
10
11Index: dosfstools-2.11/mkdosfs/mkdosfs.c
12===================================================================
13--- dosfstools-2.11.orig/mkdosfs/mkdosfs.c 2011-12-13 13:54:37.538509391 +0000
14+++ dosfstools-2.11/mkdosfs/mkdosfs.c 2011-12-13 13:55:10.258508631 +0000
15@@ -808,10 +808,12 @@
16 bs.media = (char) 0xf8; /* Set up the media descriptor for a hard drive */
17 bs.dir_entries[0] = (char) 0; /* Default to 512 entries */
18 bs.dir_entries[1] = (char) 2;
19+/*
20 if (!size_fat && blocks*SECTORS_PER_BLOCK > 1064960) {
21 if (verbose) printf("Auto-selecting FAT32 for large filesystem\n");
22 size_fat = 32;
23 }
24+*/
25 if (size_fat == 32) {
26 /* For FAT32, try to do the same as M$'s format command:
27 * fs size < 256M: 0.5k clusters