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[] =
46 #include <sys/param.h>
51 #define SLOT_EMPTY 0x00 /* slot has never been used */
52 #define SLOT_E5 0x05 /* the real value is 0xe5 */
53 #define SLOT_DELETED 0xe5 /* file in this slot deleted */
55 #define ATTR_NORMAL 0x00 /* normal file */
56 #define ATTR_READONLY 0x01 /* file is readonly */
57 #define ATTR_HIDDEN 0x02 /* file is hidden */
58 #define ATTR_SYSTEM 0x04 /* file is a system file */
59 #define ATTR_VOLUME 0x08 /* entry is a volume label */
60 #define ATTR_DIRECTORY 0x10 /* entry is a directory name */
61 #define ATTR_ARCHIVE 0x20 /* file is new or modified */
63 #define ATTR_WIN95 0x0f /* long name record */
66 * This is the format of the contents of the deTime field in the direntry
68 * We don't use bitfields because we don't know how compilers for
69 * arbitrary machines will lay them out.
71 #define DT_2SECONDS_MASK 0x1F /* seconds divided by 2 */
72 #define DT_2SECONDS_SHIFT 0
73 #define DT_MINUTES_MASK 0x7E0 /* minutes */
74 #define DT_MINUTES_SHIFT 5
75 #define DT_HOURS_MASK 0xF800 /* hours */
76 #define DT_HOURS_SHIFT 11
79 * This is the format of the contents of the deDate field in the direntry
82 #define DD_DAY_MASK 0x1F /* day of month */
83 #define DD_DAY_SHIFT 0
84 #define DD_MONTH_MASK 0x1E0 /* month */
85 #define DD_MONTH_SHIFT 5
86 #define DD_YEAR_MASK 0xFE00 /* year - 1980 */
87 #define DD_YEAR_SHIFT 9
91 static struct dosDirEntry *newDosDirEntry(void);
92 static void freeDosDirEntry(struct dosDirEntry *);
93 static struct dirTodoNode *newDirTodo(void);
94 static void freeDirTodo(struct dirTodoNode *);
95 static char *fullpath(struct dosDirEntry *);
96 static u_char calcShortSum(u_char *);
97 static int delete(int, struct bootblock *, struct fatEntry *, cl_t, int,
99 static int removede(int, struct bootblock *, struct fatEntry *, u_char *,
100 u_char *, cl_t, cl_t, cl_t, char *, int);
101 static int checksize(struct bootblock *, struct fatEntry *, u_char *,
102 struct dosDirEntry *);
103 static int readDosDirSection(int, struct bootblock *, struct fatEntry *,
104 struct dosDirEntry *);
107 * Manage free dosDirEntry structures.
109 static struct dosDirEntry *freede;
111 static struct dosDirEntry *
114 struct dosDirEntry *de;
116 if (!(de = freede)) {
117 if (!(de = (struct dosDirEntry *)malloc(sizeof *de)))
125 freeDosDirEntry(struct dosDirEntry *de)
132 * The same for dirTodoNode structures.
134 static struct dirTodoNode *freedt;
136 static struct dirTodoNode *
139 struct dirTodoNode *dt;
141 if (!(dt = freedt)) {
142 if (!(dt = (struct dirTodoNode *)malloc(sizeof *dt)))
150 freeDirTodo(struct dirTodoNode *dt)
157 * The stack of unread directories
159 static struct dirTodoNode *pendingDirectories = NULL;
162 * Return the full pathname for a directory entry.
165 fullpath(struct dosDirEntry *dir)
167 static char namebuf[MAXPATHLEN + 1];
171 cp = namebuf + sizeof namebuf - 1;
174 np = dir->lname[0] ? dir->lname : dir->name;
176 if ((cp -= nl) <= namebuf + 1)
180 } while ((dir = dir->parent) != NULL);
189 * Calculate a checksum over an 8.3 alias name
192 calcShortSum(u_char *p)
197 for (i = 0; i < 11; i++) {
198 sum = (sum << 7)|(sum >> 1); /* rotate right */
206 * Global variables temporarily used during a directory scan
208 static char longName[DOSLONGNAMELEN] = "";
209 static u_char *buffer = NULL;
210 static u_char *delbuf = NULL;
212 static struct dosDirEntry *rootDir;
213 static struct dosDirEntry *lostDir;
216 * Init internal state for a new directory scan.
219 resetDosDirSection(struct bootblock *boot, struct fatEntry *fat)
226 b1 = boot->bpbRootDirEnts * 32;
227 b2 = boot->bpbSecPerClust * boot->bpbBytesPerSec;
229 if ((buffer = malloc(len = MAX(b1, b2))) == NULL) {
230 perr("No space for directory buffer (%zu)", len);
234 if ((delbuf = malloc(len = b2)) == NULL) {
236 perr("No space for directory delbuf (%zu)", len);
240 if ((rootDir = newDosDirEntry()) == NULL) {
243 perr("No space for directory entry");
247 memset(rootDir, 0, sizeof *rootDir);
248 if (boot->flags & FAT32) {
249 if (boot->bpbRootClust < CLUST_FIRST ||
250 boot->bpbRootClust >= boot->NumClusters) {
251 pfatal("Root directory starts with cluster out of range(%u)",
255 cl = fat[boot->bpbRootClust].next;
257 || (cl >= CLUST_RSRVD && cl< CLUST_EOFS)
258 || fat[boot->bpbRootClust].head != boot->bpbRootClust) {
259 if (cl == CLUST_FREE)
260 pwarn("Root directory starts with free cluster\n");
261 else if (cl >= CLUST_RSRVD)
262 pwarn("Root directory starts with cluster marked %s\n",
265 pfatal("Root directory doesn't start a cluster chain");
269 fat[boot->bpbRootClust].next = CLUST_FREE;
275 fat[boot->bpbRootClust].flags |= FAT_USED;
276 rootDir->head = boot->bpbRootClust;
283 * Cleanup after a directory scan
286 finishDosDirSection(void)
288 struct dirTodoNode *p, *np;
289 struct dosDirEntry *d, *nd;
291 for (p = pendingDirectories; p; p = np) {
295 pendingDirectories = NULL;
296 for (d = rootDir; d; d = nd) {
297 if ((nd = d->child) != NULL) {
305 rootDir = lostDir = NULL;
313 * Delete directory entries between startcl, startoff and endcl, endoff.
316 delete(int f, struct bootblock *boot, struct fatEntry *fat, cl_t startcl,
317 int startoff, cl_t endcl, int endoff, int notlast)
321 int clsz = boot->bpbSecPerClust * boot->bpbBytesPerSec;
323 s = delbuf + startoff;
325 while (startcl >= CLUST_FIRST && startcl < boot->NumClusters) {
326 if (startcl == endcl) {
331 off = startcl * boot->bpbSecPerClust + boot->ClusterOffset;
332 off *= boot->bpbBytesPerSec;
333 if (lseek(f, off, SEEK_SET) != off) {
334 perr("Unable to lseek to %" PRId64, off);
337 if (read(f, delbuf, clsz) != clsz) {
338 perr("Unable to read directory");
345 if (lseek(f, off, SEEK_SET) != off) {
346 perr("Unable to lseek to %" PRId64, off);
349 if (write(f, delbuf, clsz) != clsz) {
350 perr("Unable to write directory");
353 if (startcl == endcl)
355 startcl = fat[startcl].next;
362 removede(int f, struct bootblock *boot, struct fatEntry *fat, u_char *start,
363 u_char *end, cl_t startcl, cl_t endcl, cl_t curcl, char *path, int type)
367 pwarn("Invalid long filename entry for %s\n", path);
370 pwarn("Invalid long filename entry at end of directory %s\n",
374 pwarn("Invalid long filename entry for volume label\n");
377 if (ask(0, "Remove")) {
378 if (startcl != curcl) {
379 if (delete(f, boot, fat,
380 startcl, start - buffer,
382 endcl == curcl) == FSFATAL)
386 /* startcl is < CLUST_FIRST for !fat32 root */
387 if ((endcl == curcl) || (startcl < CLUST_FIRST))
388 for (; start < end; start += 32)
389 *start = SLOT_DELETED;
396 * Check an in-memory file entry
399 checksize(struct bootblock *boot, struct fatEntry *fat, u_char *p,
400 struct dosDirEntry *dir)
403 * Check size on ordinary files
405 u_int32_t physicalSize;
407 if (dir->head == CLUST_FREE)
410 if (dir->head < CLUST_FIRST || dir->head >= boot->NumClusters)
412 physicalSize = fat[dir->head].length * boot->ClusterSize;
414 if (physicalSize < dir->size) {
415 pwarn("size of %s is %u, should at most be %u\n",
416 fullpath(dir), dir->size, physicalSize);
417 if (ask(1, "Truncate")) {
418 dir->size = physicalSize;
419 p[28] = (u_char)physicalSize;
420 p[29] = (u_char)(physicalSize >> 8);
421 p[30] = (u_char)(physicalSize >> 16);
422 p[31] = (u_char)(physicalSize >> 24);
426 } else if (physicalSize - dir->size >= boot->ClusterSize) {
427 pwarn("%s has too many clusters allocated\n",
429 if (ask(1, "Drop superfluous clusters")) {
433 for (cl = dir->head, len = sz = 0;
434 (sz += boot->ClusterSize) < dir->size; len++)
436 clearchain(boot, fat, fat[cl].next);
437 fat[cl].next = CLUST_EOF;
438 fat[dir->head].length = len;
447 * Read a directory and
448 * - resolve long name records
449 * - enter file and directory records into the parent's list
450 * - push directories onto the todo-stack
453 readDosDirSection(int f, struct bootblock *boot, struct fatEntry *fat,
454 struct dosDirEntry *dir)
456 struct dosDirEntry dirent, *d;
457 u_char *p, *vallfn, *invlfn, *empty;
460 cl_t cl, valcl = ~0, invcl = ~0, empcl = ~0;
465 #define THISMOD 0x8000 /* Only used within this routine */
468 if (dir->parent && (cl < CLUST_FIRST || cl >= boot->NumClusters)) {
470 * Already handled somewhere else.
475 vallfn = invlfn = empty = NULL;
477 if (!(boot->flags & FAT32) && !dir->parent) {
478 last = boot->bpbRootDirEnts * 32;
479 off = boot->bpbResSectors + boot->bpbFATs *
482 last = boot->bpbSecPerClust * boot->bpbBytesPerSec;
483 off = cl * boot->bpbSecPerClust + boot->ClusterOffset;
486 off *= boot->bpbBytesPerSec;
487 if (lseek(f, off, SEEK_SET) != off
488 || read(f, buffer, last) != last) {
489 perr("Unable to read directory");
494 * Check `.' and `..' entries here? XXX
496 for (p = buffer, i = 0; i < last; i++, p += 32) {
497 if (dir->fsckflags & DIREMPWARN) {
502 if (*p == SLOT_EMPTY || *p == SLOT_DELETED) {
503 if (*p == SLOT_EMPTY) {
504 dir->fsckflags |= DIREMPTY;
511 if (dir->fsckflags & DIREMPTY) {
512 if (!(dir->fsckflags & DIREMPWARN)) {
513 pwarn("%s has entries after end of directory\n",
515 if (ask(1, "Extend")) {
518 dir->fsckflags &= ~DIREMPTY;
519 if (delete(f, boot, fat,
520 empcl, empty - buffer,
521 cl, p - buffer, 1) == FSFATAL)
523 q = empcl == cl ? empty : buffer;
524 for (; q < p; q += 32)
526 mod |= THISMOD|FSDIRMOD;
527 } else if (ask(0, "Truncate"))
528 dir->fsckflags |= DIREMPWARN;
530 if (dir->fsckflags & DIREMPWARN) {
532 mod |= THISMOD|FSDIRMOD;
534 } else if (dir->fsckflags & DIREMPTY)
539 if (p[11] == ATTR_WIN95) {
541 if (shortSum != -1) {
547 memset(longName, 0, sizeof longName);
551 } else if (shortSum != p[13]
552 || lidx != (*p & LRNOMASK)) {
563 lidx = *p & LRNOMASK;
564 t = longName + --lidx * 13;
565 for (k = 1; k < 11 && t < longName +
566 sizeof(longName); k += 2) {
567 if (!p[k] && !p[k + 1])
571 * Warn about those unusable chars in msdosfs here? XXX
577 for (k = 14; k < 26 && t < longName + sizeof(longName); k += 2) {
578 if (!p[k] && !p[k + 1])
585 for (k = 28; k < 32 && t < longName + sizeof(longName); k += 2) {
586 if (!p[k] && !p[k + 1])
592 if (t >= longName + sizeof(longName)) {
593 pwarn("long filename too long\n");
600 if (p[26] | (p[27] << 8)) {
601 pwarn("long filename record cluster start != 0\n");
608 continue; /* long records don't carry further
613 * This is a standard msdosfs directory entry.
615 memset(&dirent, 0, sizeof dirent);
618 * it's a short name record, but we need to know
619 * more, so get the flags first.
621 dirent.flags = p[11];
624 * Translate from 850 to ISO here XXX
626 for (j = 0; j < 8; j++)
627 dirent.name[j] = p[j];
628 dirent.name[8] = '\0';
629 for (k = 7; k >= 0 && dirent.name[k] == ' '; k--)
630 dirent.name[k] = '\0';
631 if (k < 0 || dirent.name[k] != '\0')
633 if (dirent.name[0] == SLOT_E5)
634 dirent.name[0] = 0xe5;
636 if (dirent.flags & ATTR_VOLUME) {
637 if (vallfn || invlfn) {
638 mod |= removede(f, boot, fat,
639 invlfn ? invlfn : vallfn, p,
640 invlfn ? invcl : valcl, -1, 0,
649 dirent.name[k++] = '.';
650 for (j = 0; j < 3; j++)
651 dirent.name[k++] = p[j+8];
652 dirent.name[k] = '\0';
653 for (k--; k >= 0 && dirent.name[k] == ' '; k--)
654 dirent.name[k] = '\0';
656 if (vallfn && shortSum != calcShortSum(p)) {
663 dirent.head = p[26] | (p[27] << 8);
664 if (boot->ClustMask == CLUST32_MASK)
665 dirent.head |= (p[20] << 16) | (p[21] << 24);
666 dirent.size = p[28] | (p[29] << 8) | (p[30] << 16) | (p[31] << 24);
668 strlcpy(dirent.lname, longName,
669 sizeof(dirent.lname));
675 dirent.next = dir->child;
678 mod |= k = removede(f, boot, fat,
679 invlfn, vallfn ? vallfn : p,
680 invcl, vallfn ? valcl : cl, cl,
681 fullpath(&dirent), 0);
685 ? (valcl == cl && vallfn != buffer)
691 vallfn = NULL; /* not used any longer */
694 if (dirent.size == 0 && !(dirent.flags & ATTR_DIRECTORY)) {
695 if (dirent.head != 0) {
696 pwarn("%s has clusters, but size 0\n",
698 if (ask(1, "Drop allocated clusters")) {
700 if (boot->ClustMask == CLUST32_MASK)
702 clearchain(boot, fat, dirent.head);
704 mod |= THISMOD|FSDIRMOD|FSFATMOD;
708 } else if (dirent.head == 0
709 && !strcmp(dirent.name, "..")
710 && dir->parent /* XXX */
711 && !dir->parent->parent) {
713 * Do nothing, the parent is the root
715 } else if (dirent.head < CLUST_FIRST
716 || dirent.head >= boot->NumClusters
717 || fat[dirent.head].next == CLUST_FREE
718 || (fat[dirent.head].next >= CLUST_RSRVD
719 && fat[dirent.head].next < CLUST_EOFS)
720 || fat[dirent.head].head != dirent.head) {
721 if (dirent.head == 0)
722 pwarn("%s has no clusters\n",
724 else if (dirent.head < CLUST_FIRST
725 || dirent.head >= boot->NumClusters)
726 pwarn("%s starts with cluster out of range(%u)\n",
729 else if (fat[dirent.head].next == CLUST_FREE)
730 pwarn("%s starts with free cluster\n",
732 else if (fat[dirent.head].next >= CLUST_RSRVD)
733 pwarn("%s starts with cluster marked %s\n",
735 rsrvdcltype(fat[dirent.head].next));
737 pwarn("%s doesn't start a cluster chain\n",
739 if (dirent.flags & ATTR_DIRECTORY) {
740 if (ask(0, "Remove")) {
742 mod |= THISMOD|FSDIRMOD;
747 if (ask(1, "Truncate")) {
748 p[28] = p[29] = p[30] = p[31] = 0;
750 if (boot->ClustMask == CLUST32_MASK)
753 mod |= THISMOD|FSDIRMOD;
759 if (dirent.head >= CLUST_FIRST && dirent.head < boot->NumClusters)
760 fat[dirent.head].flags |= FAT_USED;
762 if (dirent.flags & ATTR_DIRECTORY) {
764 * gather more info for directories
766 struct dirTodoNode *n;
769 pwarn("Directory %s has size != 0\n",
771 if (ask(1, "Correct")) {
772 p[28] = p[29] = p[30] = p[31] = 0;
774 mod |= THISMOD|FSDIRMOD;
779 * handle `.' and `..' specially
781 if (strcmp(dirent.name, ".") == 0) {
782 if (dirent.head != dir->head) {
783 pwarn("`.' entry in %s has incorrect start cluster\n",
785 if (ask(1, "Correct")) {
786 dirent.head = dir->head;
787 p[26] = (u_char)dirent.head;
788 p[27] = (u_char)(dirent.head >> 8);
789 if (boot->ClustMask == CLUST32_MASK) {
790 p[20] = (u_char)(dirent.head >> 16);
791 p[21] = (u_char)(dirent.head >> 24);
793 mod |= THISMOD|FSDIRMOD;
799 if (strcmp(dirent.name, "..") == 0) {
800 if (dir->parent) { /* XXX */
801 if (!dir->parent->parent) {
803 pwarn("`..' entry in %s has non-zero start cluster\n",
805 if (ask(1, "Correct")) {
808 if (boot->ClustMask == CLUST32_MASK)
810 mod |= THISMOD|FSDIRMOD;
814 } else if (dirent.head != dir->parent->head) {
815 pwarn("`..' entry in %s has incorrect start cluster\n",
817 if (ask(1, "Correct")) {
818 dirent.head = dir->parent->head;
819 p[26] = (u_char)dirent.head;
820 p[27] = (u_char)(dirent.head >> 8);
821 if (boot->ClustMask == CLUST32_MASK) {
822 p[20] = (u_char)(dirent.head >> 16);
823 p[21] = (u_char)(dirent.head >> 24);
825 mod |= THISMOD|FSDIRMOD;
833 /* create directory tree node */
834 if (!(d = newDosDirEntry())) {
835 perr("No space for directory");
838 memcpy(d, &dirent, sizeof(struct dosDirEntry));
839 /* link it into the tree */
842 /* Enter this directory into the todo list */
843 if (!(n = newDirTodo())) {
844 perr("No space for todo list");
847 n->next = pendingDirectories;
849 pendingDirectories = n;
851 mod |= k = checksize(boot, fat, p, &dirent);
858 if (!(boot->flags & FAT32) && !dir->parent)
863 if (lseek(f, off, SEEK_SET) != off
864 || write(f, buffer, last) != last) {
865 perr("Unable to write directory");
870 } while ((cl = fat[cl].next) >= CLUST_FIRST && cl < boot->NumClusters);
871 if (invlfn || vallfn)
872 mod |= removede(f, boot, fat,
873 invlfn ? invlfn : vallfn, p,
874 invlfn ? invcl : valcl, -1, 0,
877 /* The root directory of non fat32 filesystems is in a special
878 * area and may have been modified above without being written out.
880 if ((mod & FSDIRMOD) && !(boot->flags & FAT32) && !dir->parent) {
882 if (lseek(f, off, SEEK_SET) != off
883 || write(f, buffer, last) != last) {
884 perr("Unable to write directory");
889 return mod & ~THISMOD;
893 handleDirTree(int dosfs, struct bootblock *boot, struct fatEntry *fat)
897 mod = readDosDirSection(dosfs, boot, fat, rootDir);
902 * process the directory todo list
904 while (pendingDirectories) {
905 struct dosDirEntry *dir = pendingDirectories->dir;
906 struct dirTodoNode *n = pendingDirectories->next;
909 * remove TODO entry now, the list might change during
912 freeDirTodo(pendingDirectories);
913 pendingDirectories = n;
916 * handle subdirectory
918 mod |= readDosDirSection(dosfs, boot, fat, dir);
927 * Try to reconnect a FAT chain into dir
929 static u_char *lfbuf;
934 reconnect(int dosfs, struct bootblock *boot, struct fatEntry *fat, cl_t head)
936 struct dosDirEntry d;
940 if (!ask(1, "Reconnect"))
944 for (lostDir = rootDir->child; lostDir; lostDir = lostDir->next) {
945 if (!strcmp(lostDir->name, LOSTDIR))
948 if (!lostDir) { /* Create LOSTDIR? XXX */
949 pwarn("No %s directory\n", LOSTDIR);
954 lfbuf = malloc(boot->ClusterSize);
956 perr("No space for buffer");
964 for (; p < lfbuf + boot->ClusterSize; p += 32)
966 || *p == SLOT_DELETED)
968 if (p && p < lfbuf + boot->ClusterSize)
970 lfcl = p ? fat[lfcl].next : lostDir->head;
971 if (lfcl < CLUST_FIRST || lfcl >= boot->NumClusters) {
972 /* Extend LOSTDIR? XXX */
973 pwarn("No space in %s\n", LOSTDIR);
976 lfoff = lfcl * boot->ClusterSize
977 + boot->ClusterOffset * boot->bpbBytesPerSec;
978 if (lseek(dosfs, lfoff, SEEK_SET) != lfoff
979 || (size_t)read(dosfs, lfbuf, boot->ClusterSize) != boot->ClusterSize) {
980 perr("could not read LOST.DIR");
987 /* Ensure uniqueness of entry here! XXX */
988 memset(&d, 0, sizeof d);
989 /* worst case -1 = 4294967295, 10 digits */
990 len = snprintf(d.name, sizeof(d.name), "%u", head);
993 d.size = fat[head].length * boot->ClusterSize;
995 memcpy(p, d.name, len);
996 memset(p + len, ' ', 11 - len);
997 memset(p + 11, 0, 32 - 11);
998 p[26] = (u_char)d.head;
999 p[27] = (u_char)(d.head >> 8);
1000 if (boot->ClustMask == CLUST32_MASK) {
1001 p[20] = (u_char)(d.head >> 16);
1002 p[21] = (u_char)(d.head >> 24);
1004 p[28] = (u_char)d.size;
1005 p[29] = (u_char)(d.size >> 8);
1006 p[30] = (u_char)(d.size >> 16);
1007 p[31] = (u_char)(d.size >> 24);
1008 fat[head].flags |= FAT_USED;
1009 if (lseek(dosfs, lfoff, SEEK_SET) != lfoff
1010 || (size_t)write(dosfs, lfbuf, boot->ClusterSize) != boot->ClusterSize) {
1011 perr("could not write LOST.DIR");