2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (C) 1995, 1996, 1997 Wolfgang Solfrank
5 * Copyright (c) 1995 Martin Husemann
6 * Some structure declaration borrowed from Paul Popelka
7 * (paulp@uts.amdahl.com), see /sys/msdosfs/ for reference.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #include <sys/cdefs.h>
33 __RCSID("$NetBSD: dir.c,v 1.20 2006/06/05 16:51:18 christos Exp $");
34 static const char rcsid[] =
47 #include <sys/param.h>
52 #define SLOT_EMPTY 0x00 /* slot has never been used */
53 #define SLOT_E5 0x05 /* the real value is 0xe5 */
54 #define SLOT_DELETED 0xe5 /* file in this slot deleted */
56 #define ATTR_NORMAL 0x00 /* normal file */
57 #define ATTR_READONLY 0x01 /* file is readonly */
58 #define ATTR_HIDDEN 0x02 /* file is hidden */
59 #define ATTR_SYSTEM 0x04 /* file is a system file */
60 #define ATTR_VOLUME 0x08 /* entry is a volume label */
61 #define ATTR_DIRECTORY 0x10 /* entry is a directory name */
62 #define ATTR_ARCHIVE 0x20 /* file is new or modified */
64 #define ATTR_WIN95 0x0f /* long name record */
67 * This is the format of the contents of the deTime field in the direntry
69 * We don't use bitfields because we don't know how compilers for
70 * arbitrary machines will lay them out.
72 #define DT_2SECONDS_MASK 0x1F /* seconds divided by 2 */
73 #define DT_2SECONDS_SHIFT 0
74 #define DT_MINUTES_MASK 0x7E0 /* minutes */
75 #define DT_MINUTES_SHIFT 5
76 #define DT_HOURS_MASK 0xF800 /* hours */
77 #define DT_HOURS_SHIFT 11
80 * This is the format of the contents of the deDate field in the direntry
83 #define DD_DAY_MASK 0x1F /* day of month */
84 #define DD_DAY_SHIFT 0
85 #define DD_MONTH_MASK 0x1E0 /* month */
86 #define DD_MONTH_SHIFT 5
87 #define DD_YEAR_MASK 0xFE00 /* year - 1980 */
88 #define DD_YEAR_SHIFT 9
92 static struct dosDirEntry *newDosDirEntry(void);
93 static void freeDosDirEntry(struct dosDirEntry *);
94 static struct dirTodoNode *newDirTodo(void);
95 static void freeDirTodo(struct dirTodoNode *);
96 static char *fullpath(struct dosDirEntry *);
97 static u_char calcShortSum(u_char *);
98 static int delete(int, struct bootblock *, struct fatEntry *, cl_t, int,
100 static int removede(int, struct bootblock *, struct fatEntry *, u_char *,
101 u_char *, cl_t, cl_t, cl_t, char *, int);
102 static int checksize(struct bootblock *, struct fatEntry *, u_char *,
103 struct dosDirEntry *);
104 static int readDosDirSection(int, struct bootblock *, struct fatEntry *,
105 struct dosDirEntry *);
108 * Manage free dosDirEntry structures.
110 static struct dosDirEntry *freede;
112 static struct dosDirEntry *
115 struct dosDirEntry *de;
117 if (!(de = freede)) {
118 if (!(de = (struct dosDirEntry *)malloc(sizeof *de)))
126 freeDosDirEntry(struct dosDirEntry *de)
133 * The same for dirTodoNode structures.
135 static struct dirTodoNode *freedt;
137 static struct dirTodoNode *
140 struct dirTodoNode *dt;
142 if (!(dt = freedt)) {
143 if (!(dt = (struct dirTodoNode *)malloc(sizeof *dt)))
151 freeDirTodo(struct dirTodoNode *dt)
158 * The stack of unread directories
160 static struct dirTodoNode *pendingDirectories = NULL;
163 * Return the full pathname for a directory entry.
166 fullpath(struct dosDirEntry *dir)
168 static char namebuf[MAXPATHLEN + 1];
172 cp = namebuf + sizeof namebuf - 1;
175 np = dir->lname[0] ? dir->lname : dir->name;
177 if ((cp -= nl) <= namebuf + 1)
181 } while ((dir = dir->parent) != NULL);
190 * Calculate a checksum over an 8.3 alias name
193 calcShortSum(u_char *p)
198 for (i = 0; i < 11; i++) {
199 sum = (sum << 7)|(sum >> 1); /* rotate right */
207 * Global variables temporarily used during a directory scan
209 static char longName[DOSLONGNAMELEN] = "";
210 static u_char *buffer = NULL;
211 static u_char *delbuf = NULL;
213 static struct dosDirEntry *rootDir;
214 static struct dosDirEntry *lostDir;
217 * Init internal state for a new directory scan.
220 resetDosDirSection(struct bootblock *boot, struct fatEntry *fat)
227 b1 = boot->bpbRootDirEnts * 32;
228 b2 = boot->bpbSecPerClust * boot->bpbBytesPerSec;
230 if ((buffer = malloc(len = MAX(b1, b2))) == NULL) {
231 perr("No space for directory buffer (%zu)", len);
235 if ((delbuf = malloc(len = b2)) == NULL) {
237 perr("No space for directory delbuf (%zu)", len);
241 if ((rootDir = newDosDirEntry()) == NULL) {
244 perr("No space for directory entry");
248 memset(rootDir, 0, sizeof *rootDir);
249 if (boot->flags & FAT32) {
250 if (boot->bpbRootClust < CLUST_FIRST ||
251 boot->bpbRootClust >= boot->NumClusters) {
252 pfatal("Root directory starts with cluster out of range(%u)",
256 cl = fat[boot->bpbRootClust].next;
258 || (cl >= CLUST_RSRVD && cl< CLUST_EOFS)
259 || fat[boot->bpbRootClust].head != boot->bpbRootClust) {
260 if (cl == CLUST_FREE)
261 pwarn("Root directory starts with free cluster\n");
262 else if (cl >= CLUST_RSRVD)
263 pwarn("Root directory starts with cluster marked %s\n",
266 pfatal("Root directory doesn't start a cluster chain");
270 fat[boot->bpbRootClust].next = CLUST_FREE;
276 fat[boot->bpbRootClust].flags |= FAT_USED;
277 rootDir->head = boot->bpbRootClust;
284 * Cleanup after a directory scan
287 finishDosDirSection(void)
289 struct dirTodoNode *p, *np;
290 struct dosDirEntry *d, *nd;
292 for (p = pendingDirectories; p; p = np) {
296 pendingDirectories = NULL;
297 for (d = rootDir; d; d = nd) {
298 if ((nd = d->child) != NULL) {
306 rootDir = lostDir = NULL;
314 * Delete directory entries between startcl, startoff and endcl, endoff.
317 delete(int f, struct bootblock *boot, struct fatEntry *fat, cl_t startcl,
318 int startoff, cl_t endcl, int endoff, int notlast)
322 int clsz = boot->bpbSecPerClust * boot->bpbBytesPerSec;
324 s = delbuf + startoff;
326 while (startcl >= CLUST_FIRST && startcl < boot->NumClusters) {
327 if (startcl == endcl) {
332 off = startcl * boot->bpbSecPerClust + boot->ClusterOffset;
333 off *= boot->bpbBytesPerSec;
334 if (lseek(f, off, SEEK_SET) != off) {
335 perr("Unable to lseek to %" PRId64, off);
338 if (read(f, delbuf, clsz) != clsz) {
339 perr("Unable to read directory");
346 if (lseek(f, off, SEEK_SET) != off) {
347 perr("Unable to lseek to %" PRId64, off);
350 if (write(f, delbuf, clsz) != clsz) {
351 perr("Unable to write directory");
354 if (startcl == endcl)
356 startcl = fat[startcl].next;
363 removede(int f, struct bootblock *boot, struct fatEntry *fat, u_char *start,
364 u_char *end, cl_t startcl, cl_t endcl, cl_t curcl, char *path, int type)
368 pwarn("Invalid long filename entry for %s\n", path);
371 pwarn("Invalid long filename entry at end of directory %s\n",
375 pwarn("Invalid long filename entry for volume label\n");
378 if (ask(0, "Remove")) {
379 if (startcl != curcl) {
380 if (delete(f, boot, fat,
381 startcl, start - buffer,
383 endcl == curcl) == FSFATAL)
387 /* startcl is < CLUST_FIRST for !fat32 root */
388 if ((endcl == curcl) || (startcl < CLUST_FIRST))
389 for (; start < end; start += 32)
390 *start = SLOT_DELETED;
397 * Check an in-memory file entry
400 checksize(struct bootblock *boot, struct fatEntry *fat, u_char *p,
401 struct dosDirEntry *dir)
404 * Check size on ordinary files
406 u_int32_t physicalSize;
408 if (dir->head == CLUST_FREE)
411 if (dir->head < CLUST_FIRST || dir->head >= boot->NumClusters)
413 physicalSize = fat[dir->head].length * boot->ClusterSize;
415 if (physicalSize < dir->size) {
416 pwarn("size of %s is %u, should at most be %u\n",
417 fullpath(dir), dir->size, physicalSize);
418 if (ask(1, "Truncate")) {
419 dir->size = physicalSize;
420 p[28] = (u_char)physicalSize;
421 p[29] = (u_char)(physicalSize >> 8);
422 p[30] = (u_char)(physicalSize >> 16);
423 p[31] = (u_char)(physicalSize >> 24);
427 } else if (physicalSize - dir->size >= boot->ClusterSize) {
428 pwarn("%s has too many clusters allocated\n",
430 if (ask(1, "Drop superfluous clusters")) {
434 for (cl = dir->head, len = sz = 0;
435 (sz += boot->ClusterSize) < dir->size; len++)
437 clearchain(boot, fat, fat[cl].next);
438 fat[cl].next = CLUST_EOF;
439 fat[dir->head].length = len;
448 * Read a directory and
449 * - resolve long name records
450 * - enter file and directory records into the parent's list
451 * - push directories onto the todo-stack
454 readDosDirSection(int f, struct bootblock *boot, struct fatEntry *fat,
455 struct dosDirEntry *dir)
457 struct dosDirEntry dirent, *d;
458 u_char *p, *vallfn, *invlfn, *empty;
461 cl_t cl, valcl = ~0, invcl = ~0, empcl = ~0;
466 #define THISMOD 0x8000 /* Only used within this routine */
469 if (dir->parent && (cl < CLUST_FIRST || cl >= boot->NumClusters)) {
471 * Already handled somewhere else.
476 vallfn = invlfn = empty = NULL;
478 if (!(boot->flags & FAT32) && !dir->parent) {
479 last = boot->bpbRootDirEnts * 32;
480 off = boot->bpbResSectors + boot->bpbFATs *
483 last = boot->bpbSecPerClust * boot->bpbBytesPerSec;
484 off = cl * boot->bpbSecPerClust + boot->ClusterOffset;
487 off *= boot->bpbBytesPerSec;
488 if (lseek(f, off, SEEK_SET) != off
489 || read(f, buffer, last) != last) {
490 perr("Unable to read directory");
495 * Check `.' and `..' entries here? XXX
497 for (p = buffer, i = 0; i < last; i++, p += 32) {
498 if (dir->fsckflags & DIREMPWARN) {
503 if (*p == SLOT_EMPTY || *p == SLOT_DELETED) {
504 if (*p == SLOT_EMPTY) {
505 dir->fsckflags |= DIREMPTY;
512 if (dir->fsckflags & DIREMPTY) {
513 if (!(dir->fsckflags & DIREMPWARN)) {
514 pwarn("%s has entries after end of directory\n",
516 if (ask(1, "Extend")) {
519 dir->fsckflags &= ~DIREMPTY;
520 if (delete(f, boot, fat,
521 empcl, empty - buffer,
522 cl, p - buffer, 1) == FSFATAL)
524 q = ((empcl == cl) ? empty : buffer);
526 for (; q < p; q += 32)
528 mod |= THISMOD|FSDIRMOD;
529 } else if (ask(0, "Truncate"))
530 dir->fsckflags |= DIREMPWARN;
532 if (dir->fsckflags & DIREMPWARN) {
534 mod |= THISMOD|FSDIRMOD;
536 } else if (dir->fsckflags & DIREMPTY)
541 if (p[11] == ATTR_WIN95) {
543 if (shortSum != -1) {
549 memset(longName, 0, sizeof longName);
553 } else if (shortSum != p[13]
554 || lidx != (*p & LRNOMASK)) {
565 lidx = *p & LRNOMASK;
566 t = longName + --lidx * 13;
567 for (k = 1; k < 11 && t < longName +
568 sizeof(longName); k += 2) {
569 if (!p[k] && !p[k + 1])
573 * Warn about those unusable chars in msdosfs here? XXX
579 for (k = 14; k < 26 && t < longName + sizeof(longName); k += 2) {
580 if (!p[k] && !p[k + 1])
587 for (k = 28; k < 32 && t < longName + sizeof(longName); k += 2) {
588 if (!p[k] && !p[k + 1])
594 if (t >= longName + sizeof(longName)) {
595 pwarn("long filename too long\n");
602 if (p[26] | (p[27] << 8)) {
603 pwarn("long filename record cluster start != 0\n");
610 continue; /* long records don't carry further
615 * This is a standard msdosfs directory entry.
617 memset(&dirent, 0, sizeof dirent);
620 * it's a short name record, but we need to know
621 * more, so get the flags first.
623 dirent.flags = p[11];
626 * Translate from 850 to ISO here XXX
628 for (j = 0; j < 8; j++)
629 dirent.name[j] = p[j];
630 dirent.name[8] = '\0';
631 for (k = 7; k >= 0 && dirent.name[k] == ' '; k--)
632 dirent.name[k] = '\0';
633 if (k < 0 || dirent.name[k] != '\0')
635 if (dirent.name[0] == SLOT_E5)
636 dirent.name[0] = 0xe5;
638 if (dirent.flags & ATTR_VOLUME) {
639 if (vallfn || invlfn) {
640 mod |= removede(f, boot, fat,
641 invlfn ? invlfn : vallfn, p,
642 invlfn ? invcl : valcl, -1, 0,
651 dirent.name[k++] = '.';
652 for (j = 0; j < 3; j++)
653 dirent.name[k++] = p[j+8];
654 dirent.name[k] = '\0';
655 for (k--; k >= 0 && dirent.name[k] == ' '; k--)
656 dirent.name[k] = '\0';
658 if (vallfn && shortSum != calcShortSum(p)) {
665 dirent.head = p[26] | (p[27] << 8);
666 if (boot->ClustMask == CLUST32_MASK)
667 dirent.head |= (p[20] << 16) | (p[21] << 24);
668 dirent.size = p[28] | (p[29] << 8) | (p[30] << 16) | (p[31] << 24);
670 strlcpy(dirent.lname, longName,
671 sizeof(dirent.lname));
677 dirent.next = dir->child;
680 mod |= k = removede(f, boot, fat,
681 invlfn, vallfn ? vallfn : p,
682 invcl, vallfn ? valcl : cl, cl,
683 fullpath(&dirent), 0);
687 ? (valcl == cl && vallfn != buffer)
693 vallfn = NULL; /* not used any longer */
696 if (dirent.size == 0 && !(dirent.flags & ATTR_DIRECTORY)) {
697 if (dirent.head != 0) {
698 pwarn("%s has clusters, but size 0\n",
700 if (ask(1, "Drop allocated clusters")) {
702 if (boot->ClustMask == CLUST32_MASK)
704 clearchain(boot, fat, dirent.head);
706 mod |= THISMOD|FSDIRMOD|FSFATMOD;
710 } else if (dirent.head == 0
711 && !strcmp(dirent.name, "..")
712 && dir->parent /* XXX */
713 && !dir->parent->parent) {
715 * Do nothing, the parent is the root
717 } else if (dirent.head < CLUST_FIRST
718 || dirent.head >= boot->NumClusters
719 || fat[dirent.head].next == CLUST_FREE
720 || (fat[dirent.head].next >= CLUST_RSRVD
721 && fat[dirent.head].next < CLUST_EOFS)
722 || fat[dirent.head].head != dirent.head) {
723 if (dirent.head == 0)
724 pwarn("%s has no clusters\n",
726 else if (dirent.head < CLUST_FIRST
727 || dirent.head >= boot->NumClusters)
728 pwarn("%s starts with cluster out of range(%u)\n",
731 else if (fat[dirent.head].next == CLUST_FREE)
732 pwarn("%s starts with free cluster\n",
734 else if (fat[dirent.head].next >= CLUST_RSRVD)
735 pwarn("%s starts with cluster marked %s\n",
737 rsrvdcltype(fat[dirent.head].next));
739 pwarn("%s doesn't start a cluster chain\n",
741 if (dirent.flags & ATTR_DIRECTORY) {
742 if (ask(0, "Remove")) {
744 mod |= THISMOD|FSDIRMOD;
749 if (ask(1, "Truncate")) {
750 p[28] = p[29] = p[30] = p[31] = 0;
752 if (boot->ClustMask == CLUST32_MASK)
755 mod |= THISMOD|FSDIRMOD;
761 if (dirent.head >= CLUST_FIRST && dirent.head < boot->NumClusters)
762 fat[dirent.head].flags |= FAT_USED;
764 if (dirent.flags & ATTR_DIRECTORY) {
766 * gather more info for directories
768 struct dirTodoNode *n;
771 pwarn("Directory %s has size != 0\n",
773 if (ask(1, "Correct")) {
774 p[28] = p[29] = p[30] = p[31] = 0;
776 mod |= THISMOD|FSDIRMOD;
781 * handle `.' and `..' specially
783 if (strcmp(dirent.name, ".") == 0) {
784 if (dirent.head != dir->head) {
785 pwarn("`.' entry in %s has incorrect start cluster\n",
787 if (ask(1, "Correct")) {
788 dirent.head = dir->head;
789 p[26] = (u_char)dirent.head;
790 p[27] = (u_char)(dirent.head >> 8);
791 if (boot->ClustMask == CLUST32_MASK) {
792 p[20] = (u_char)(dirent.head >> 16);
793 p[21] = (u_char)(dirent.head >> 24);
795 mod |= THISMOD|FSDIRMOD;
801 if (strcmp(dirent.name, "..") == 0) {
802 if (dir->parent) { /* XXX */
803 if (!dir->parent->parent) {
805 pwarn("`..' entry in %s has non-zero start cluster\n",
807 if (ask(1, "Correct")) {
810 if (boot->ClustMask == CLUST32_MASK)
812 mod |= THISMOD|FSDIRMOD;
816 } else if (dirent.head != dir->parent->head) {
817 pwarn("`..' entry in %s has incorrect start cluster\n",
819 if (ask(1, "Correct")) {
820 dirent.head = dir->parent->head;
821 p[26] = (u_char)dirent.head;
822 p[27] = (u_char)(dirent.head >> 8);
823 if (boot->ClustMask == CLUST32_MASK) {
824 p[20] = (u_char)(dirent.head >> 16);
825 p[21] = (u_char)(dirent.head >> 24);
827 mod |= THISMOD|FSDIRMOD;
835 /* create directory tree node */
836 if (!(d = newDosDirEntry())) {
837 perr("No space for directory");
840 memcpy(d, &dirent, sizeof(struct dosDirEntry));
841 /* link it into the tree */
844 /* Enter this directory into the todo list */
845 if (!(n = newDirTodo())) {
846 perr("No space for todo list");
849 n->next = pendingDirectories;
851 pendingDirectories = n;
853 mod |= k = checksize(boot, fat, p, &dirent);
860 if (!(boot->flags & FAT32) && !dir->parent)
865 if (lseek(f, off, SEEK_SET) != off
866 || write(f, buffer, last) != last) {
867 perr("Unable to write directory");
872 } while ((cl = fat[cl].next) >= CLUST_FIRST && cl < boot->NumClusters);
873 if (invlfn || vallfn)
874 mod |= removede(f, boot, fat,
875 invlfn ? invlfn : vallfn, p,
876 invlfn ? invcl : valcl, -1, 0,
879 /* The root directory of non fat32 filesystems is in a special
880 * area and may have been modified above without being written out.
882 if ((mod & FSDIRMOD) && !(boot->flags & FAT32) && !dir->parent) {
884 if (lseek(f, off, SEEK_SET) != off
885 || write(f, buffer, last) != last) {
886 perr("Unable to write directory");
891 return mod & ~THISMOD;
895 handleDirTree(int dosfs, struct bootblock *boot, struct fatEntry *fat)
899 mod = readDosDirSection(dosfs, boot, fat, rootDir);
904 * process the directory todo list
906 while (pendingDirectories) {
907 struct dosDirEntry *dir = pendingDirectories->dir;
908 struct dirTodoNode *n = pendingDirectories->next;
911 * remove TODO entry now, the list might change during
914 freeDirTodo(pendingDirectories);
915 pendingDirectories = n;
918 * handle subdirectory
920 mod |= readDosDirSection(dosfs, boot, fat, dir);
929 * Try to reconnect a FAT chain into dir
931 static u_char *lfbuf;
936 reconnect(int dosfs, struct bootblock *boot, struct fatEntry *fat, cl_t head)
938 struct dosDirEntry d;
942 if (!ask(1, "Reconnect"))
946 for (lostDir = rootDir->child; lostDir; lostDir = lostDir->next) {
947 if (!strcmp(lostDir->name, LOSTDIR))
950 if (!lostDir) { /* Create LOSTDIR? XXX */
951 pwarn("No %s directory\n", LOSTDIR);
956 lfbuf = malloc(boot->ClusterSize);
958 perr("No space for buffer");
966 for (; p < lfbuf + boot->ClusterSize; p += 32)
968 || *p == SLOT_DELETED)
970 if (p && p < lfbuf + boot->ClusterSize)
972 lfcl = p ? fat[lfcl].next : lostDir->head;
973 if (lfcl < CLUST_FIRST || lfcl >= boot->NumClusters) {
974 /* Extend LOSTDIR? XXX */
975 pwarn("No space in %s\n", LOSTDIR);
978 lfoff = lfcl * boot->ClusterSize
979 + boot->ClusterOffset * boot->bpbBytesPerSec;
980 if (lseek(dosfs, lfoff, SEEK_SET) != lfoff
981 || (size_t)read(dosfs, lfbuf, boot->ClusterSize) != boot->ClusterSize) {
982 perr("could not read LOST.DIR");
989 /* Ensure uniqueness of entry here! XXX */
990 memset(&d, 0, sizeof d);
991 /* worst case -1 = 4294967295, 10 digits */
992 len = snprintf(d.name, sizeof(d.name), "%u", head);
995 d.size = fat[head].length * boot->ClusterSize;
997 memcpy(p, d.name, len);
998 memset(p + len, ' ', 11 - len);
999 memset(p + 11, 0, 32 - 11);
1000 p[26] = (u_char)d.head;
1001 p[27] = (u_char)(d.head >> 8);
1002 if (boot->ClustMask == CLUST32_MASK) {
1003 p[20] = (u_char)(d.head >> 16);
1004 p[21] = (u_char)(d.head >> 24);
1006 p[28] = (u_char)d.size;
1007 p[29] = (u_char)(d.size >> 8);
1008 p[30] = (u_char)(d.size >> 16);
1009 p[31] = (u_char)(d.size >> 24);
1010 fat[head].flags |= FAT_USED;
1011 if (lseek(dosfs, lfoff, SEEK_SET) != lfoff
1012 || (size_t)write(dosfs, lfbuf, boot->ClusterSize) != boot->ClusterSize) {
1013 perr("could not write LOST.DIR");