Module Name: src Committed By: perseant Date: Wed Jul 24 00:40:38 UTC 2024
Modified Files: src/usr.sbin/dumpexfatfs [perseant-exfatfs]: dumpexfatfs.c Log Message: Add -B option to allow saving bootcode to a file. Report the first cluster of a directory in hex. Fix the computation of first cluster directory so we can correctly list other directories than the root. To generate a diff of this commit: cvs rdiff -u -r1.1.2.4 -r1.1.2.5 src/usr.sbin/dumpexfatfs/dumpexfatfs.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/usr.sbin/dumpexfatfs/dumpexfatfs.c diff -u src/usr.sbin/dumpexfatfs/dumpexfatfs.c:1.1.2.4 src/usr.sbin/dumpexfatfs/dumpexfatfs.c:1.1.2.5 --- src/usr.sbin/dumpexfatfs/dumpexfatfs.c:1.1.2.4 Fri Jul 19 16:19:16 2024 +++ src/usr.sbin/dumpexfatfs/dumpexfatfs.c Wed Jul 24 00:40:38 2024 @@ -82,8 +82,9 @@ int main(int argc, char **argv) { int devfd, c; struct exfatfs *fs; + char *bootcodefile = NULL; - while ((c = getopt(argc, argv, "Aabcd:fruv")) != -1) { + while ((c = getopt(argc, argv, "AaB:bcd:fruv")) != -1) { switch (c) { case 'A': Aflag = !Aflag; @@ -95,6 +96,9 @@ int main(int argc, char **argv) case 'a': Aflag = !Aflag; break; + case 'B': + bootcodefile = optarg; + break; case 'b': Bflag = !Bflag; break; @@ -144,7 +148,7 @@ int main(int argc, char **argv) exit(0); } - + if (Aflag + Bflag + Dflag + Fflag + Rflag + Uflag == 0) Aflag = Bflag = Fflag = Rflag = Uflag = 1; @@ -152,6 +156,21 @@ int main(int argc, char **argv) if (devfd <= 0) err(1, argv[optind]); + if (bootcodefile != NULL) { + /* + * Extract the bootcode and write it to a file. + * exFAT bootcode is 390 bytes starting at offset 120. + */ + FILE *fp; + char buf[390]; + if (pread(devfd, buf, sizeof(buf), 120) < sizeof(buf)) + err(1, argv[optind]); + fp = fopen(bootcodefile, "wb"); + if (fp == NULL || fwrite(buf, 390, 1, fp) < 1) + err(1, argv[optind]); + fclose(fp); + } + /* Set dev_bshift to match dev_bsize */ for (dev_bshift = 0; (1 << dev_bshift) < dev_bsize; ++dev_bshift) ; @@ -389,9 +408,12 @@ void print_dir(struct exfatfs *fs, uint3 printf("Reading dirent from %d/%d, physical blk 0x%x\n", (int)dirclust, (int)diroff, (unsigned)blkno); - bread(fs->xf_devvp, blkno, EXFATFS_LSIZE(fs), 0, &bp); + bread(fs->xf_devvp, blkno, EXFATFS_SSIZE(fs), 0, &bp); dse = malloc(sizeof(*dse)); - memcpy(dse, ((struct exfatfs_dse *)bp->b_data) + (diroff % EXFATFS_S2D(fs, 1)) + 1, sizeof(*dse)); + /* The stream entry is always the second entry in a file set */ + memcpy(dse, ((struct exfatfs_dse *)bp->b_data) + + (diroff & (EXFATFS_D2DIRENT(fs, 1) - 1)) + 1, + sizeof(*dse)); brelse(bp, 0); bp = NULL; clust = dse->xd_firstCluster; @@ -400,7 +422,7 @@ void print_dir(struct exfatfs *fs, uint3 if (action == ACTION_PRINT) { printf("Directory entries:\n"); - printf(" Reading from cluster %d\n", clust); + printf(" Reading from cluster %d (0x%x)\n", clust, clust); } for (off = 0; off * sizeof(*dfp) < maxlen; ++off) { i = off % (EXFATFS_LSIZE(fs) / sizeof(*dfp)); @@ -457,7 +479,7 @@ void print_dir(struct exfatfs *fs, uint3 printf("\tAllocation Bitmap\n"); printf("\t\tFlags: %hhx\n", ((struct exfatfs_dirent_allocation_bitmap *)dp)->xd_bitmapFlags); - printf("\t\tFirst Cluster: %lx\n", (unsigned long) + printf("\t\tFirst Cluster: 0x%lx\n", (unsigned long) ((struct exfatfs_dirent_allocation_bitmap *)dp)->xd_firstCluster); printf("\t\tData Length: %llu\n", (unsigned long long) ((struct exfatfs_dirent_allocation_bitmap *)dp)->xd_dataLength); @@ -473,7 +495,7 @@ void print_dir(struct exfatfs *fs, uint3 printf("\tUpcase Table\n"); printf("\t\tChecksum: %lx\n", (unsigned long) ((struct exfatfs_dirent_upcase_table *)dp)->xd_tableChecksum); - printf("\t\tFirst Cluster: %lx\n", (unsigned long) + printf("\t\tFirst Cluster: 0x%lx\n", (unsigned long) ((struct exfatfs_dirent_upcase_table *)dp)->xd_firstCluster); printf("\t\tData Length: %llu\n", (unsigned long long) ((struct exfatfs_dirent_upcase_table *)dp)->xd_dataLength); @@ -609,7 +631,7 @@ void print_dir(struct exfatfs *fs, uint3 dsp->xd_nameHash); printf("\t\tValid Data Length: %llu\n", (unsigned long long)dsp->xd_validDataLength); - printf("\t\tFirst Cluster: %lu\n", + printf("\t\tFirst Cluster: 0x%lx\n", (unsigned long)dsp->xd_firstCluster); printf("\t\tData Length: %llu\n", (unsigned long long)dsp->xd_dataLength);