Lines Matching +full:t +full:- +full:head
1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
68 * We don't use bitfields because we don't know how compilers for
86 #define DD_YEAR_MASK 0xFE00 /* year - 1980 */
117 freede = de->next; in newDosDirEntry()
124 de->next = freede; in freeDosDirEntry()
142 freedt = dt->next; in newDirTodo()
149 dt->next = freedt; in freeDirTodo()
169 *--cp = '\0'; in fullpath()
172 np = dir->lname[0] ? dir->lname : dir->name; in fullpath()
175 *--cp = '?'; in fullpath()
178 cp -= nl; in fullpath()
180 dir = dir->parent; in fullpath()
183 *--cp = '/'; in fullpath()
229 rootdir_size = boot->bpbRootDirEnts * 32; in resetDosDirSection()
230 cluster_size = boot->bpbSecPerClust * boot->bpbBytesPerSec; in resetDosDirSection()
251 if (boot->flags & FAT32) { in resetDosDirSection()
252 if (!fat_is_cl_head(fat, boot->bpbRootClust)) { in resetDosDirSection()
253 pfatal("Root directory doesn't start a cluster chain"); in resetDosDirSection()
256 rootDir->head = boot->bpbRootClust; in resetDosDirSection()
272 np = p->next; in finishDosDirSection()
277 if ((nd = d->child) != NULL) { in finishDosDirSection()
278 d->child = 0; in finishDosDirSection()
281 if (!(nd = d->next)) in finishDosDirSection()
282 nd = d->parent; in finishDosDirSection()
306 clsz = boot->bpbSecPerClust * boot->bpbBytesPerSec; in delete()
316 off = (startcl - CLUST_FIRST) * boot->bpbSecPerClust + boot->FirstCluster; in delete()
318 off *= boot->bpbBytesPerSec; in delete()
367 startcl, start - buffer, in removede()
368 endcl, end - buffer, in removede()
383 * Check an in-memory file entry
398 if (dir->head == CLUST_FREE) { in checksize()
401 if (!fat_is_valid_cl(fat, dir->head) || !fat_is_cl_head(fat, dir->head)) { in checksize()
403 fullpath(dir), dir->size, dir->head); in checksize()
407 if (boot->ClustMask == CLUST32_MASK) in checksize()
409 dir->size = 0; in checksize()
410 dir->head = CLUST_FREE; in checksize()
416 ret = checkchain(fat, dir->head, &chainsize); in checksize()
428 * The maximum file size on FAT32 is 4GiB - 1, which in checksize()
430 * size. On 32-bit platforms, since size_t is 32-bit, in checksize()
433 physicalSize = (u_int64_t)chainsize * boot->ClusterSize; in checksize()
435 if (physicalSize < dir->size) { in checksize()
437 fullpath(dir), dir->size, (uintmax_t)physicalSize); in checksize()
439 dir->size = physicalSize; in checksize()
447 } else if (physicalSize - dir->size >= boot->ClusterSize) { in checksize()
454 for (cl = dir->head, len = sz = 0; in checksize()
455 (sz += boot->ClusterSize) < dir->size; len++) in checksize()
487 cl = dir->head; in check_subdirectory()
488 if (dir->parent && !fat_is_valid_cl(fat, cl)) { in check_subdirectory()
492 if (!(boot->flags & FAT32) && !dir->parent) { in check_subdirectory()
493 off = boot->bpbResSectors + boot->bpbFATs * in check_subdirectory()
494 boot->FATsecs; in check_subdirectory()
496 off = (cl - CLUST_FIRST) * boot->bpbSecPerClust + boot->FirstCluster; in check_subdirectory()
504 buf = malloc(boot->bpbBytesPerSec); in check_subdirectory()
507 boot->bpbBytesPerSec); in check_subdirectory()
511 off *= boot->bpbBytesPerSec; in check_subdirectory()
513 read(fd, buf, boot->bpbBytesPerSec) != (ssize_t)boot->bpbBytesPerSec) { in check_subdirectory()
526 pwarn("%s: Incorrect `.' for %s.\n", __func__, dir->name); in check_subdirectory()
532 pwarn("%s: Incorrect `..' for %s. \n", __func__, dir->name); in check_subdirectory()
542 * - resolve long name records
543 * - enter file and directory records into the parent's list
544 * - push directories onto the todo-stack
556 char *t; in readDosDirSection() local
566 cl = dir->head; in readDosDirSection()
567 if (dir->parent && (!fat_is_valid_cl(fat, cl))) { in readDosDirSection()
573 shortSum = -1; in readDosDirSection()
585 is_legacyroot = (dir->parent == NULL && !(boot->flags & FAT32)); in readDosDirSection()
587 iosize = boot->bpbRootDirEnts * 32; in readDosDirSection()
588 entries = boot->bpbRootDirEnts; in readDosDirSection()
590 iosize = boot->bpbSecPerClust * boot->bpbBytesPerSec; in readDosDirSection()
592 mod |= checkchain(fat, dir->head, &dirclusters); in readDosDirSection()
598 * Special case for FAT12/FAT16 root -- read in readDosDirSection()
601 off = boot->bpbResSectors + boot->bpbFATs * in readDosDirSection()
602 boot->FATsecs; in readDosDirSection()
608 off = (cl - CLUST_FIRST) * boot->bpbSecPerClust + boot->FirstCluster; in readDosDirSection()
611 off *= boot->bpbBytesPerSec; in readDosDirSection()
619 if (dir->fsckflags & DIREMPWARN) { in readDosDirSection()
626 dir->fsckflags |= DIREMPTY; in readDosDirSection()
633 if (dir->fsckflags & DIREMPTY) { in readDosDirSection()
634 if (!(dir->fsckflags & DIREMPWARN)) { in readDosDirSection()
640 dir->fsckflags &= ~DIREMPTY; in readDosDirSection()
642 empcl, empty - buffer, in readDosDirSection()
643 cl, p - buffer, 1) == FSFATAL) in readDosDirSection()
651 dir->fsckflags |= DIREMPWARN; in readDosDirSection()
653 if (dir->fsckflags & DIREMPWARN) { in readDosDirSection()
657 } else if (dir->fsckflags & DIREMPTY) in readDosDirSection()
664 if (shortSum != -1) { in readDosDirSection()
696 t = longName + --lidx * 13; in readDosDirSection()
697 for (k = 1; k < 11 && t < longName + in readDosDirSection()
701 *t++ = p[k]; in readDosDirSection()
706 t[-1] = '?'; in readDosDirSection()
709 for (k = 14; k < 26 && t < longName + sizeof(longName); k += 2) { in readDosDirSection()
712 *t++ = p[k]; in readDosDirSection()
714 t[-1] = '?'; in readDosDirSection()
717 for (k = 28; k < 32 && t < longName + sizeof(longName); k += 2) { in readDosDirSection()
720 *t++ = p[k]; in readDosDirSection()
722 t[-1] = '?'; in readDosDirSection()
724 if (t >= longName + sizeof(longName)) { in readDosDirSection()
740 continue; /* long records don't carry further in readDosDirSection()
761 for (k = 7; k >= 0 && dirent.name[k] == ' '; k--) in readDosDirSection()
772 invlfn ? invcl : valcl, -1, 0, in readDosDirSection()
785 for (k--; k >= 0 && dirent.name[k] == ' '; k--) in readDosDirSection()
795 dirent.head = p[26] | (p[27] << 8); in readDosDirSection()
796 if (boot->ClustMask == CLUST32_MASK) in readDosDirSection()
797 dirent.head |= (p[20] << 16) | (p[21] << 24); in readDosDirSection()
803 shortSum = -1; in readDosDirSection()
807 dirent.next = dir->child; in readDosDirSection()
835 * by another file) when it's a non-empty file in readDosDirSection()
849 ((!fat_is_valid_cl(fat, dirent.head) || in readDosDirSection()
850 !fat_is_cl_head(fat, dirent.head)))) { in readDosDirSection()
851 if (!fat_is_valid_cl(fat, dirent.head)) { in readDosDirSection()
854 dirent.head); in readDosDirSection()
856 pwarn("%s doesn't start a new cluster chain\n", in readDosDirSection()
871 if (boot->ClustMask == CLUST32_MASK) in readDosDirSection()
874 dirent.head = 0; in readDosDirSection()
901 if (dirent.head != dir->head) { in readDosDirSection()
905 dirent.head = dir->head; in readDosDirSection()
906 p[26] = (u_char)dirent.head; in readDosDirSection()
907 p[27] = (u_char)(dirent.head >> 8); in readDosDirSection()
908 if (boot->ClustMask == CLUST32_MASK) { in readDosDirSection()
909 p[20] = (u_char)(dirent.head >> 16); in readDosDirSection()
910 p[21] = (u_char)(dirent.head >> 24); in readDosDirSection()
918 if (dir->parent) { /* XXX */ in readDosDirSection()
919 if (!dir->parent->parent) { in readDosDirSection()
920 if (dirent.head) { in readDosDirSection()
921 pwarn("`..' entry in %s has non-zero start cluster\n", in readDosDirSection()
924 dirent.head = 0; in readDosDirSection()
926 if (boot->ClustMask == CLUST32_MASK) in readDosDirSection()
932 } else if (dirent.head != dir->parent->head) { in readDosDirSection()
936 dirent.head = dir->parent->head; in readDosDirSection()
937 p[26] = (u_char)dirent.head; in readDosDirSection()
938 p[27] = (u_char)(dirent.head >> 8); in readDosDirSection()
939 if (boot->ClustMask == CLUST32_MASK) { in readDosDirSection()
940 p[20] = (u_char)(dirent.head >> 16); in readDosDirSection()
941 p[21] = (u_char)(dirent.head >> 24); in readDosDirSection()
952 * to dir->head, it's '.'. in readDosDirSection()
954 if (dirent.head == dir->head) { in readDosDirSection()
967 * a dot (.) entry and a dot-dot in readDosDirSection()
988 dir->child = d; in readDosDirSection()
995 n->next = pendingDirectories; in readDosDirSection()
996 n->dir = d; in readDosDirSection()
1003 boot->NumFiles++; in readDosDirSection()
1008 * Don't bother to write back right now because in readDosDirSection()
1010 * non-FAT32 root directory below. in readDosDirSection()
1025 invlfn ? invcl : valcl, -1, 0, in readDosDirSection()
1029 * The root directory of non-FAT32 filesystems is in a special in readDosDirSection()
1057 struct dosDirEntry *dir = pendingDirectories->dir; in handleDirTree()
1058 struct dirTodoNode *n = pendingDirectories->next; in handleDirTree()
1086 reconnect(struct fat_descriptor *fat, cl_t head, size_t length) in reconnect() argument
1099 for (lostDir = rootDir->child; lostDir; lostDir = lostDir->next) { in reconnect()
1100 if (!strcmp(lostDir->name, LOSTDIR)) in reconnect()
1109 lfbuf = malloc(boot->ClusterSize); in reconnect()
1119 for (; p < lfbuf + boot->ClusterSize; p += 32) in reconnect()
1123 if (p && p < lfbuf + boot->ClusterSize) in reconnect()
1125 lfcl = p ? fat_get_cl_next(fat, lfcl) : lostDir->head; in reconnect()
1126 if (lfcl < CLUST_FIRST || lfcl >= boot->NumClusters) { in reconnect()
1129 lfcl = (lostDir->head < boot->NumClusters) ? lostDir->head : 0; in reconnect()
1132 lfoff = (lfcl - CLUST_FIRST) * boot->ClusterSize in reconnect()
1133 + boot->FirstCluster * boot->bpbBytesPerSec; in reconnect()
1136 || (size_t)read(dosfs, lfbuf, boot->ClusterSize) != boot->ClusterSize) { in reconnect()
1143 boot->NumFiles++; in reconnect()
1146 /* worst case -1 = 4294967295, 10 digits */ in reconnect()
1147 len = snprintf(d.name, sizeof(d.name), "%u", head); in reconnect()
1149 d.head = head; in reconnect()
1150 d.size = length * boot->ClusterSize; in reconnect()
1153 memset(p + len, ' ', 11 - len); in reconnect()
1154 memset(p + 11, 0, 32 - 11); in reconnect()
1155 p[26] = (u_char)d.head; in reconnect()
1156 p[27] = (u_char)(d.head >> 8); in reconnect()
1157 if (boot->ClustMask == CLUST32_MASK) { in reconnect()
1158 p[20] = (u_char)(d.head >> 16); in reconnect()
1159 p[21] = (u_char)(d.head >> 24); in reconnect()
1166 || (size_t)write(dosfs, lfbuf, boot->ClusterSize) != boot->ClusterSize) { in reconnect()