diff options
author | Xin Li <delphij@google.com> | 2019-10-01 15:09:31 -0700 |
---|---|---|
committer | Xin Li <delphij@google.com> | 2019-10-01 15:09:49 -0700 |
commit | a4cbc8877ec4eb004eb0a84d20dd53d1e40fa401 (patch) | |
tree | d00c2de6ea05e62937d718dc4c8d21316f61196c /dir.c | |
parent | d0d0369b34795f02aaa4de66785bbb5d00f625e5 (diff) | |
download | fsck_msdos-a4cbc8877ec4eb004eb0a84d20dd53d1e40fa401.tar.gz |
Import revision 643521d9cba4f6b4717f042e6ce8bb0c71e5a3a0 from FreeBSD.
Change-Id: I5cd6c9fd7064268ceccccaeb92a2f2408871b455
Diffstat (limited to 'dir.c')
-rw-r--r-- | dir.c | 56 |
1 files changed, 23 insertions, 33 deletions
@@ -169,20 +169,24 @@ fullpath(struct dosDirEntry *dir) char *cp, *np; int nl; - cp = namebuf + sizeof namebuf - 1; - *cp = '\0'; - do { + cp = namebuf + sizeof namebuf; + *--cp = '\0'; + + for(;;) { np = dir->lname[0] ? dir->lname : dir->name; nl = strlen(np); - if ((cp -= nl) <= namebuf + 1) + if (cp <= namebuf + 1 + nl) { + *--cp = '?'; break; + } + cp -= nl; memcpy(cp, np, nl); + dir = dir->parent; + if (!dir) + break; *--cp = '/'; - } while ((dir = dir->parent) != NULL); - if (dir) - *--cp = '?'; - else - cp++; + } + return cp; } @@ -220,7 +224,6 @@ int resetDosDirSection(struct bootblock *boot, struct fatEntry *fat) { int b1, b2; - cl_t cl; int ret = FSOK; size_t len; @@ -253,24 +256,9 @@ resetDosDirSection(struct bootblock *boot, struct fatEntry *fat) boot->bpbRootClust); return FSFATAL; } - cl = fat[boot->bpbRootClust].next; - if (cl < CLUST_FIRST - || (cl >= CLUST_RSRVD && cl< CLUST_EOFS) - || fat[boot->bpbRootClust].head != boot->bpbRootClust) { - if (cl == CLUST_FREE) - pwarn("Root directory starts with free cluster\n"); - else if (cl >= CLUST_RSRVD) - pwarn("Root directory starts with cluster marked %s\n", - rsrvdcltype(cl)); - else { - pfatal("Root directory doesn't start a cluster chain"); - return FSFATAL; - } - if (ask(1, "Fix")) { - fat[boot->bpbRootClust].next = CLUST_FREE; - ret = FSFATMOD; - } else - ret = FSFATAL; + if (fat[boot->bpbRootClust].head != boot->bpbRootClust) { + pfatal("Root directory doesn't start a cluster chain"); + return FSFATAL; } fat[boot->bpbRootClust].flags |= FAT_USED; @@ -329,7 +317,8 @@ delete(int f, struct bootblock *boot, struct fatEntry *fat, cl_t startcl, break; e = delbuf + endoff; } - off = startcl * boot->bpbSecPerClust + boot->ClusterOffset; + off = (startcl - CLUST_FIRST) * boot->bpbSecPerClust + boot->FirstCluster; + off *= boot->bpbBytesPerSec; if (lseek(f, off, SEEK_SET) != off) { perr("Unable to lseek to %" PRId64, off); @@ -469,7 +458,7 @@ check_subdirectory(int f, struct bootblock *boot, struct dosDirEntry *dir) off = boot->bpbResSectors + boot->bpbFATs * boot->FATsecs; } else { - off = cl * boot->bpbSecPerClust + boot->ClusterOffset; + off = (cl - CLUST_FIRST) * boot->bpbSecPerClust + boot->FirstCluster; } /* @@ -550,7 +539,7 @@ readDosDirSection(int f, struct bootblock *boot, struct fatEntry *fat, boot->FATsecs; } else { last = boot->bpbSecPerClust * boot->bpbBytesPerSec; - off = cl * boot->bpbSecPerClust + boot->ClusterOffset; + off = (cl - CLUST_FIRST) * boot->bpbSecPerClust + boot->FirstCluster; } off *= boot->bpbBytesPerSec; @@ -1081,8 +1070,9 @@ reconnect(int dosfs, struct bootblock *boot, struct fatEntry *fat, cl_t head) lfcl = (lostDir->head < boot->NumClusters) ? lostDir->head : 0; return FSERROR; } - lfoff = lfcl * boot->ClusterSize - + boot->ClusterOffset * boot->bpbBytesPerSec; + lfoff = (lfcl - CLUST_FIRST) * boot->ClusterSize + + boot->FirstCluster * boot->bpbBytesPerSec; + if (lseek(dosfs, lfoff, SEEK_SET) != lfoff || (size_t)read(dosfs, lfbuf, boot->ClusterSize) != boot->ClusterSize) { perr("could not read LOST.DIR"); |