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[] =
45 #include <sys/param.h>
50 #define SLOT_EMPTY 0x00 /* slot has never been used */
51 #define SLOT_E5 0x05 /* the real value is 0xe5 */
52 #define SLOT_DELETED 0xe5 /* file in this slot deleted */
54 #define ATTR_NORMAL 0x00 /* normal file */
55 #define ATTR_READONLY 0x01 /* file is readonly */
56 #define ATTR_HIDDEN 0x02 /* file is hidden */
57 #define ATTR_SYSTEM 0x04 /* file is a system file */
58 #define ATTR_VOLUME 0x08 /* entry is a volume label */
59 #define ATTR_DIRECTORY 0x10 /* entry is a directory name */
60 #define ATTR_ARCHIVE 0x20 /* file is new or modified */
62 #define ATTR_WIN95 0x0f /* long name record */
65 * This is the format of the contents of the deTime field in the direntry
67 * We don't use bitfields because we don't know how compilers for
68 * arbitrary machines will lay them out.
70 #define DT_2SECONDS_MASK 0x1F /* seconds divided by 2 */
71 #define DT_2SECONDS_SHIFT 0
72 #define DT_MINUTES_MASK 0x7E0 /* minutes */
73 #define DT_MINUTES_SHIFT 5
74 #define DT_HOURS_MASK 0xF800 /* hours */
75 #define DT_HOURS_SHIFT 11
78 * This is the format of the contents of the deDate field in the direntry
81 #define DD_DAY_MASK 0x1F /* day of month */
82 #define DD_DAY_SHIFT 0
83 #define DD_MONTH_MASK 0x1E0 /* month */
84 #define DD_MONTH_SHIFT 5
85 #define DD_YEAR_MASK 0xFE00 /* year - 1980 */
86 #define DD_YEAR_SHIFT 9
90 static struct dosDirEntry *newDosDirEntry(void);
91 static void freeDosDirEntry(struct dosDirEntry *);
92 static struct dirTodoNode *newDirTodo(void);
93 static void freeDirTodo(struct dirTodoNode *);
94 static char *fullpath(struct dosDirEntry *);
95 static u_char calcShortSum(u_char *);
96 static int delete(int, struct bootblock *, struct fatEntry *, cl_t, int,
98 static int removede(int, struct bootblock *, struct fatEntry *, u_char *,
99 u_char *, cl_t, cl_t, cl_t, char *, int);
100 static int checksize(struct bootblock *, struct fatEntry *, u_char *,
101 struct dosDirEntry *);
102 static int readDosDirSection(int, struct bootblock *, struct fatEntry *,
103 struct dosDirEntry *);
106 * Manage free dosDirEntry structures.
108 static struct dosDirEntry *freede;
110 static struct dosDirEntry *
113 struct dosDirEntry *de;
115 if (!(de = freede)) {
116 if (!(de = (struct dosDirEntry *)malloc(sizeof *de)))
124 freeDosDirEntry(struct dosDirEntry *de)
131 * The same for dirTodoNode structures.
133 static struct dirTodoNode *freedt;
135 static struct dirTodoNode *
138 struct dirTodoNode *dt;
140 if (!(dt = freedt)) {
141 if (!(dt = (struct dirTodoNode *)malloc(sizeof *dt)))
149 freeDirTodo(struct dirTodoNode *dt)
156 * The stack of unread directories
158 static struct dirTodoNode *pendingDirectories = NULL;
161 * Return the full pathname for a directory entry.
164 fullpath(struct dosDirEntry *dir)
166 static char namebuf[MAXPATHLEN + 1];
170 cp = namebuf + sizeof namebuf - 1;
173 np = dir->lname[0] ? dir->lname : dir->name;
175 if ((cp -= nl) <= namebuf + 1)
179 } while ((dir = dir->parent) != NULL);
188 * Calculate a checksum over an 8.3 alias name
191 calcShortSum(u_char *p)
196 for (i = 0; i < 11; i++) {
197 sum = (sum << 7)|(sum >> 1); /* rotate right */
205 * Global variables temporarily used during a directory scan
207 static char longName[DOSLONGNAMELEN] = "";
208 static u_char *buffer = NULL;
209 static u_char *delbuf = NULL;
211 static struct dosDirEntry *rootDir;
212 static struct dosDirEntry *lostDir;
215 * Init internal state for a new directory scan.
218 resetDosDirSection(struct bootblock *boot, struct fatEntry *fat)
225 b1 = boot->bpbRootDirEnts * 32;
226 b2 = boot->bpbSecPerClust * boot->bpbBytesPerSec;
228 if ((buffer = malloc(len = MAX(b1, b2))) == NULL) {
229 perr("No space for directory buffer (%zu)", len);
233 if ((delbuf = malloc(len = b2)) == NULL) {
235 perr("No space for directory delbuf (%zu)", len);
239 if ((rootDir = newDosDirEntry()) == NULL) {
242 perr("No space for directory entry");
246 memset(rootDir, 0, sizeof *rootDir);
247 if (boot->flags & FAT32) {
248 if (boot->bpbRootClust < CLUST_FIRST ||
249 boot->bpbRootClust >= boot->NumClusters) {
250 pfatal("Root directory starts with cluster out of range(%u)",
254 cl = fat[boot->bpbRootClust].next;
256 || (cl >= CLUST_RSRVD && cl< CLUST_EOFS)
257 || fat[boot->bpbRootClust].head != boot->bpbRootClust) {
258 if (cl == CLUST_FREE)
259 pwarn("Root directory starts with free cluster\n");
260 else if (cl >= CLUST_RSRVD)
261 pwarn("Root directory starts with cluster marked %s\n",
264 pfatal("Root directory doesn't start a cluster chain");
268 fat[boot->bpbRootClust].next = CLUST_FREE;
274 fat[boot->bpbRootClust].flags |= FAT_USED;
275 rootDir->head = boot->bpbRootClust;
282 * Cleanup after a directory scan
285 finishDosDirSection(void)
287 struct dirTodoNode *p, *np;
288 struct dosDirEntry *d, *nd;
290 for (p = pendingDirectories; p; p = np) {
294 pendingDirectories = NULL;
295 for (d = rootDir; d; d = nd) {
296 if ((nd = d->child) != NULL) {
304 rootDir = lostDir = NULL;
312 * Delete directory entries between startcl, startoff and endcl, endoff.
315 delete(int f, struct bootblock *boot, struct fatEntry *fat, cl_t startcl,
316 int startoff, cl_t endcl, int endoff, int notlast)
320 int clsz = boot->bpbSecPerClust * boot->bpbBytesPerSec;
322 s = delbuf + startoff;
324 while (startcl >= CLUST_FIRST && startcl < boot->NumClusters) {
325 if (startcl == endcl) {
330 off = startcl * boot->bpbSecPerClust + boot->ClusterOffset;
331 off *= boot->bpbBytesPerSec;
332 if (lseek(f, off, SEEK_SET) != off
333 || read(f, delbuf, clsz) != clsz) {
334 perr("Unable to read directory");
341 if (lseek(f, off, SEEK_SET) != off
342 || write(f, delbuf, clsz) != clsz) {
343 perr("Unable to write directory");
346 if (startcl == endcl)
348 startcl = fat[startcl].next;
355 removede(int f, struct bootblock *boot, struct fatEntry *fat, u_char *start,
356 u_char *end, cl_t startcl, cl_t endcl, cl_t curcl, char *path, int type)
360 pwarn("Invalid long filename entry for %s\n", path);
363 pwarn("Invalid long filename entry at end of directory %s\n",
367 pwarn("Invalid long filename entry for volume label\n");
370 if (ask(0, "Remove")) {
371 if (startcl != curcl) {
372 if (delete(f, boot, fat,
373 startcl, start - buffer,
375 endcl == curcl) == FSFATAL)
379 /* startcl is < CLUST_FIRST for !fat32 root */
380 if ((endcl == curcl) || (startcl < CLUST_FIRST))
381 for (; start < end; start += 32)
382 *start = SLOT_DELETED;
389 * Check an in-memory file entry
392 checksize(struct bootblock *boot, struct fatEntry *fat, u_char *p,
393 struct dosDirEntry *dir)
396 * Check size on ordinary files
398 u_int32_t physicalSize;
400 if (dir->head == CLUST_FREE)
403 if (dir->head < CLUST_FIRST || dir->head >= boot->NumClusters)
405 physicalSize = fat[dir->head].length * boot->ClusterSize;
407 if (physicalSize < dir->size) {
408 pwarn("size of %s is %u, should at most be %u\n",
409 fullpath(dir), dir->size, physicalSize);
410 if (ask(1, "Truncate")) {
411 dir->size = physicalSize;
412 p[28] = (u_char)physicalSize;
413 p[29] = (u_char)(physicalSize >> 8);
414 p[30] = (u_char)(physicalSize >> 16);
415 p[31] = (u_char)(physicalSize >> 24);
419 } else if (physicalSize - dir->size >= boot->ClusterSize) {
420 pwarn("%s has too many clusters allocated\n",
422 if (ask(1, "Drop superfluous clusters")) {
426 for (cl = dir->head, len = sz = 0;
427 (sz += boot->ClusterSize) < dir->size; len++)
429 clearchain(boot, fat, fat[cl].next);
430 fat[cl].next = CLUST_EOF;
431 fat[dir->head].length = len;
440 * Read a directory and
441 * - resolve long name records
442 * - enter file and directory records into the parent's list
443 * - push directories onto the todo-stack
446 readDosDirSection(int f, struct bootblock *boot, struct fatEntry *fat,
447 struct dosDirEntry *dir)
449 struct dosDirEntry dirent, *d;
450 u_char *p, *vallfn, *invlfn, *empty;
453 cl_t cl, valcl = ~0, invcl = ~0, empcl = ~0;
458 #define THISMOD 0x8000 /* Only used within this routine */
461 if (dir->parent && (cl < CLUST_FIRST || cl >= boot->NumClusters)) {
463 * Already handled somewhere else.
468 vallfn = invlfn = empty = NULL;
470 if (!(boot->flags & FAT32) && !dir->parent) {
471 last = boot->bpbRootDirEnts * 32;
472 off = boot->bpbResSectors + boot->bpbFATs *
475 last = boot->bpbSecPerClust * boot->bpbBytesPerSec;
476 off = cl * boot->bpbSecPerClust + boot->ClusterOffset;
479 off *= boot->bpbBytesPerSec;
480 if (lseek(f, off, SEEK_SET) != off
481 || read(f, buffer, last) != last) {
482 perr("Unable to read directory");
487 * Check `.' and `..' entries here? XXX
489 for (p = buffer, i = 0; i < last; i++, p += 32) {
490 if (dir->fsckflags & DIREMPWARN) {
495 if (*p == SLOT_EMPTY || *p == SLOT_DELETED) {
496 if (*p == SLOT_EMPTY) {
497 dir->fsckflags |= DIREMPTY;
504 if (dir->fsckflags & DIREMPTY) {
505 if (!(dir->fsckflags & DIREMPWARN)) {
506 pwarn("%s has entries after end of directory\n",
508 if (ask(1, "Extend")) {
511 dir->fsckflags &= ~DIREMPTY;
512 if (delete(f, boot, fat,
513 empcl, empty - buffer,
514 cl, p - buffer, 1) == FSFATAL)
516 q = empcl == cl ? empty : buffer;
517 for (; q < p; q += 32)
519 mod |= THISMOD|FSDIRMOD;
520 } else if (ask(0, "Truncate"))
521 dir->fsckflags |= DIREMPWARN;
523 if (dir->fsckflags & DIREMPWARN) {
525 mod |= THISMOD|FSDIRMOD;
527 } else if (dir->fsckflags & DIREMPTY)
532 if (p[11] == ATTR_WIN95) {
534 if (shortSum != -1) {
540 memset(longName, 0, sizeof longName);
544 } else if (shortSum != p[13]
545 || lidx != (*p & LRNOMASK)) {
556 lidx = *p & LRNOMASK;
557 t = longName + --lidx * 13;
558 for (k = 1; k < 11 && t < longName +
559 sizeof(longName); k += 2) {
560 if (!p[k] && !p[k + 1])
564 * Warn about those unusable chars in msdosfs here? XXX
570 for (k = 14; k < 26 && t < longName + sizeof(longName); k += 2) {
571 if (!p[k] && !p[k + 1])
578 for (k = 28; k < 32 && t < longName + sizeof(longName); k += 2) {
579 if (!p[k] && !p[k + 1])
585 if (t >= longName + sizeof(longName)) {
586 pwarn("long filename too long\n");
593 if (p[26] | (p[27] << 8)) {
594 pwarn("long filename record cluster start != 0\n");
601 continue; /* long records don't carry further
606 * This is a standard msdosfs directory entry.
608 memset(&dirent, 0, sizeof dirent);
611 * it's a short name record, but we need to know
612 * more, so get the flags first.
614 dirent.flags = p[11];
617 * Translate from 850 to ISO here XXX
619 for (j = 0; j < 8; j++)
620 dirent.name[j] = p[j];
621 dirent.name[8] = '\0';
622 for (k = 7; k >= 0 && dirent.name[k] == ' '; k--)
623 dirent.name[k] = '\0';
624 if (k < 0 || dirent.name[k] != '\0')
626 if (dirent.name[0] == SLOT_E5)
627 dirent.name[0] = 0xe5;
629 if (dirent.flags & ATTR_VOLUME) {
630 if (vallfn || invlfn) {
631 mod |= removede(f, boot, fat,
632 invlfn ? invlfn : vallfn, p,
633 invlfn ? invcl : valcl, -1, 0,
642 dirent.name[k++] = '.';
643 for (j = 0; j < 3; j++)
644 dirent.name[k++] = p[j+8];
645 dirent.name[k] = '\0';
646 for (k--; k >= 0 && dirent.name[k] == ' '; k--)
647 dirent.name[k] = '\0';
649 if (vallfn && shortSum != calcShortSum(p)) {
656 dirent.head = p[26] | (p[27] << 8);
657 if (boot->ClustMask == CLUST32_MASK)
658 dirent.head |= (p[20] << 16) | (p[21] << 24);
659 dirent.size = p[28] | (p[29] << 8) | (p[30] << 16) | (p[31] << 24);
661 strlcpy(dirent.lname, longName,
662 sizeof(dirent.lname));
668 dirent.next = dir->child;
671 mod |= k = removede(f, boot, fat,
672 invlfn, vallfn ? vallfn : p,
673 invcl, vallfn ? valcl : cl, cl,
674 fullpath(&dirent), 0);
678 ? (valcl == cl && vallfn != buffer)
684 vallfn = NULL; /* not used any longer */
687 if (dirent.size == 0 && !(dirent.flags & ATTR_DIRECTORY)) {
688 if (dirent.head != 0) {
689 pwarn("%s has clusters, but size 0\n",
691 if (ask(1, "Drop allocated clusters")) {
693 if (boot->ClustMask == CLUST32_MASK)
695 clearchain(boot, fat, dirent.head);
697 mod |= THISMOD|FSDIRMOD|FSFATMOD;
701 } else if (dirent.head == 0
702 && !strcmp(dirent.name, "..")
703 && dir->parent /* XXX */
704 && !dir->parent->parent) {
706 * Do nothing, the parent is the root
708 } else if (dirent.head < CLUST_FIRST
709 || dirent.head >= boot->NumClusters
710 || fat[dirent.head].next == CLUST_FREE
711 || (fat[dirent.head].next >= CLUST_RSRVD
712 && fat[dirent.head].next < CLUST_EOFS)
713 || fat[dirent.head].head != dirent.head) {
714 if (dirent.head == 0)
715 pwarn("%s has no clusters\n",
717 else if (dirent.head < CLUST_FIRST
718 || dirent.head >= boot->NumClusters)
719 pwarn("%s starts with cluster out of range(%u)\n",
722 else if (fat[dirent.head].next == CLUST_FREE)
723 pwarn("%s starts with free cluster\n",
725 else if (fat[dirent.head].next >= CLUST_RSRVD)
726 pwarn("%s starts with cluster marked %s\n",
728 rsrvdcltype(fat[dirent.head].next));
730 pwarn("%s doesn't start a cluster chain\n",
732 if (dirent.flags & ATTR_DIRECTORY) {
733 if (ask(0, "Remove")) {
735 mod |= THISMOD|FSDIRMOD;
740 if (ask(1, "Truncate")) {
741 p[28] = p[29] = p[30] = p[31] = 0;
743 if (boot->ClustMask == CLUST32_MASK)
746 mod |= THISMOD|FSDIRMOD;
752 if (dirent.head >= CLUST_FIRST && dirent.head < boot->NumClusters)
753 fat[dirent.head].flags |= FAT_USED;
755 if (dirent.flags & ATTR_DIRECTORY) {
757 * gather more info for directories
759 struct dirTodoNode *n;
762 pwarn("Directory %s has size != 0\n",
764 if (ask(1, "Correct")) {
765 p[28] = p[29] = p[30] = p[31] = 0;
767 mod |= THISMOD|FSDIRMOD;
772 * handle `.' and `..' specially
774 if (strcmp(dirent.name, ".") == 0) {
775 if (dirent.head != dir->head) {
776 pwarn("`.' entry in %s has incorrect start cluster\n",
778 if (ask(1, "Correct")) {
779 dirent.head = dir->head;
780 p[26] = (u_char)dirent.head;
781 p[27] = (u_char)(dirent.head >> 8);
782 if (boot->ClustMask == CLUST32_MASK) {
783 p[20] = (u_char)(dirent.head >> 16);
784 p[21] = (u_char)(dirent.head >> 24);
786 mod |= THISMOD|FSDIRMOD;
792 if (strcmp(dirent.name, "..") == 0) {
793 if (dir->parent) { /* XXX */
794 if (!dir->parent->parent) {
796 pwarn("`..' entry in %s has non-zero start cluster\n",
798 if (ask(1, "Correct")) {
801 if (boot->ClustMask == CLUST32_MASK)
803 mod |= THISMOD|FSDIRMOD;
807 } else if (dirent.head != dir->parent->head) {
808 pwarn("`..' entry in %s has incorrect start cluster\n",
810 if (ask(1, "Correct")) {
811 dirent.head = dir->parent->head;
812 p[26] = (u_char)dirent.head;
813 p[27] = (u_char)(dirent.head >> 8);
814 if (boot->ClustMask == CLUST32_MASK) {
815 p[20] = (u_char)(dirent.head >> 16);
816 p[21] = (u_char)(dirent.head >> 24);
818 mod |= THISMOD|FSDIRMOD;
826 /* create directory tree node */
827 if (!(d = newDosDirEntry())) {
828 perr("No space for directory");
831 memcpy(d, &dirent, sizeof(struct dosDirEntry));
832 /* link it into the tree */
835 /* Enter this directory into the todo list */
836 if (!(n = newDirTodo())) {
837 perr("No space for todo list");
840 n->next = pendingDirectories;
842 pendingDirectories = n;
844 mod |= k = checksize(boot, fat, p, &dirent);
851 if (!(boot->flags & FAT32) && !dir->parent)
856 if (lseek(f, off, SEEK_SET) != off
857 || write(f, buffer, last) != last) {
858 perr("Unable to write directory");
863 } while ((cl = fat[cl].next) >= CLUST_FIRST && cl < boot->NumClusters);
864 if (invlfn || vallfn)
865 mod |= removede(f, boot, fat,
866 invlfn ? invlfn : vallfn, p,
867 invlfn ? invcl : valcl, -1, 0,
870 /* The root directory of non fat32 filesystems is in a special
871 * area and may have been modified above without being written out.
873 if ((mod & FSDIRMOD) && !(boot->flags & FAT32) && !dir->parent) {
875 if (lseek(f, off, SEEK_SET) != off
876 || write(f, buffer, last) != last) {
877 perr("Unable to write directory");
882 return mod & ~THISMOD;
886 handleDirTree(int dosfs, struct bootblock *boot, struct fatEntry *fat)
890 mod = readDosDirSection(dosfs, boot, fat, rootDir);
895 * process the directory todo list
897 while (pendingDirectories) {
898 struct dosDirEntry *dir = pendingDirectories->dir;
899 struct dirTodoNode *n = pendingDirectories->next;
902 * remove TODO entry now, the list might change during
905 freeDirTodo(pendingDirectories);
906 pendingDirectories = n;
909 * handle subdirectory
911 mod |= readDosDirSection(dosfs, boot, fat, dir);
920 * Try to reconnect a FAT chain into dir
922 static u_char *lfbuf;
927 reconnect(int dosfs, struct bootblock *boot, struct fatEntry *fat, cl_t head)
929 struct dosDirEntry d;
933 if (!ask(1, "Reconnect"))
937 for (lostDir = rootDir->child; lostDir; lostDir = lostDir->next) {
938 if (!strcmp(lostDir->name, LOSTDIR))
941 if (!lostDir) { /* Create LOSTDIR? XXX */
942 pwarn("No %s directory\n", LOSTDIR);
947 lfbuf = malloc(boot->ClusterSize);
949 perr("No space for buffer");
957 for (; p < lfbuf + boot->ClusterSize; p += 32)
959 || *p == SLOT_DELETED)
961 if (p && p < lfbuf + boot->ClusterSize)
963 lfcl = p ? fat[lfcl].next : lostDir->head;
964 if (lfcl < CLUST_FIRST || lfcl >= boot->NumClusters) {
965 /* Extend LOSTDIR? XXX */
966 pwarn("No space in %s\n", LOSTDIR);
969 lfoff = lfcl * boot->ClusterSize
970 + boot->ClusterOffset * boot->bpbBytesPerSec;
971 if (lseek(dosfs, lfoff, SEEK_SET) != lfoff
972 || (size_t)read(dosfs, lfbuf, boot->ClusterSize) != boot->ClusterSize) {
973 perr("could not read LOST.DIR");
980 /* Ensure uniqueness of entry here! XXX */
981 memset(&d, 0, sizeof d);
982 /* worst case -1 = 4294967295, 10 digits */
983 len = snprintf(d.name, sizeof(d.name), "%u", head);
986 d.size = fat[head].length * boot->ClusterSize;
988 memcpy(p, d.name, len);
989 memset(p + len, ' ', 11 - len);
990 memset(p + 11, 0, 32 - 11);
991 p[26] = (u_char)d.head;
992 p[27] = (u_char)(d.head >> 8);
993 if (boot->ClustMask == CLUST32_MASK) {
994 p[20] = (u_char)(d.head >> 16);
995 p[21] = (u_char)(d.head >> 24);
997 p[28] = (u_char)d.size;
998 p[29] = (u_char)(d.size >> 8);
999 p[30] = (u_char)(d.size >> 16);
1000 p[31] = (u_char)(d.size >> 24);
1001 fat[head].flags |= FAT_USED;
1002 if (lseek(dosfs, lfoff, SEEK_SET) != lfoff
1003 || (size_t)write(dosfs, lfbuf, boot->ClusterSize) != boot->ClusterSize) {
1004 perr("could not write LOST.DIR");