summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorandroid-build-team Robot <android-build-team-robot@google.com>2020-04-29 01:14:29 +0000
committerandroid-build-team Robot <android-build-team-robot@google.com>2020-04-29 01:14:29 +0000
commit6083d154868c46b96009bdd29a4d49dbd4b13f60 (patch)
treedd4ed4f55de937e63bdd649a4e29a2c5bf819703
parent94bb4d2cec54f263adf1cdf9ee91432a50a08f55 (diff)
parent4f36a18db8d324e8495f2a237e4824c03182e4ab (diff)
downloadfsck_msdos-android11-release.tar.gz
Snap for 6440900 from 4f36a18db8d324e8495f2a237e4824c03182e4ab to rvc-releaseandroid-vts-11.0_r9android-vts-11.0_r8android-vts-11.0_r7android-vts-11.0_r6android-vts-11.0_r5android-vts-11.0_r4android-vts-11.0_r3android-vts-11.0_r2android-vts-11.0_r16android-vts-11.0_r15android-vts-11.0_r14android-vts-11.0_r13android-vts-11.0_r12android-vts-11.0_r11android-vts-11.0_r10android-vts-11.0_r1android-security-11.0.0_r76android-security-11.0.0_r75android-security-11.0.0_r74android-security-11.0.0_r73android-security-11.0.0_r72android-security-11.0.0_r71android-security-11.0.0_r70android-security-11.0.0_r69android-security-11.0.0_r68android-security-11.0.0_r67android-security-11.0.0_r66android-security-11.0.0_r65android-security-11.0.0_r64android-security-11.0.0_r63android-security-11.0.0_r62android-security-11.0.0_r61android-security-11.0.0_r60android-security-11.0.0_r59android-security-11.0.0_r58android-security-11.0.0_r57android-security-11.0.0_r56android-security-11.0.0_r55android-security-11.0.0_r54android-security-11.0.0_r53android-security-11.0.0_r52android-security-11.0.0_r51android-security-11.0.0_r50android-security-11.0.0_r49android-security-11.0.0_r1android-cts-11.0_r9android-cts-11.0_r8android-cts-11.0_r7android-cts-11.0_r6android-cts-11.0_r5android-cts-11.0_r4android-cts-11.0_r3android-cts-11.0_r2android-cts-11.0_r16android-cts-11.0_r15android-cts-11.0_r14android-cts-11.0_r13android-cts-11.0_r12android-cts-11.0_r11android-cts-11.0_r10android-cts-11.0_r1android-11.0.0_r5android-11.0.0_r4android-11.0.0_r3android-11.0.0_r25android-11.0.0_r2android-11.0.0_r17android-11.0.0_r1android11-tests-releaseandroid11-security-releaseandroid11-s1-releaseandroid11-release
Change-Id: I14e56664d39dcdce37450680de7f4c3b7e3cd9fc
-rw-r--r--boot.c13
-rw-r--r--check.c40
-rw-r--r--ext.h2
-rw-r--r--fat.c48
4 files changed, 88 insertions, 15 deletions
diff --git a/boot.c b/boot.c
index 86528ce..887312e 100644
--- a/boot.c
+++ b/boot.c
@@ -28,7 +28,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: boot.c,v 1.21 2018/02/08 09:05:17 dholland Exp $");
+__RCSID("$NetBSD: boot.c,v 1.22 2020/01/11 16:29:07 christos Exp $");
static const char rcsid[] =
"$FreeBSD$";
#endif /* not lint */
@@ -267,10 +267,11 @@ readboot(int dosfs, struct bootblock *boot)
}
/*
- * The number of clusters is derived from available data sectors, divided
- * by sectors per cluster.
+ * The number of clusters is derived from available data sectors,
+ * divided by sectors per cluster.
*/
- boot->NumClusters = (boot->NumSectors - boot->FirstCluster) / boot->bpbSecPerClust;
+ boot->NumClusters =
+ (boot->NumSectors - boot->FirstCluster) / boot->bpbSecPerClust;
if (boot->flags & FAT32) {
if (boot->NumClusters > (CLUST_RSRVD & CLUST32_MASK)) {
@@ -320,8 +321,8 @@ readboot(int dosfs, struct bootblock *boot)
}
/*
- * There are two reserved clusters. To avoid adding CLUST_FIRST every time
- * when we perform boundary checks, we increment the NumClusters by 2,
+ * There are two reserved clusters. To avoid adding CLUST_FIRST every
+ * time we perform boundary checks, we increment the NumClusters by 2,
* which is CLUST_FIRST to denote the first out-of-range cluster number.
*/
boot->NumClusters += CLUST_FIRST;
diff --git a/check.c b/check.c
index 2c38662..9519315 100644
--- a/check.c
+++ b/check.c
@@ -33,6 +33,9 @@ static const char rcsid[] =
"$FreeBSD$";
#endif /* not lint */
+#ifdef HAVE_LIBUTIL_H
+#include <libutil.h>
+#endif
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
@@ -51,6 +54,8 @@ checkfilesys(const char *fname)
int finish_dosdirsection=0;
int mod = 0;
int ret = 8;
+ int64_t freebytes;
+ int64_t badbytes;
rdonly = alwaysno;
if (!preen)
@@ -126,15 +131,34 @@ checkfilesys(const char *fname)
mod |= FSERROR;
}
+ freebytes = (int64_t)boot.NumFree * boot.ClusterSize;
+ badbytes = (int64_t)boot.NumBad * boot.ClusterSize;
+
+#ifdef HAVE_LIBUTIL_H
+ char freestr[7], badstr[7];
+
+ humanize_number(freestr, sizeof(freestr), freebytes, "",
+ HN_AUTOSCALE, HN_DECIMAL | HN_IEC_PREFIXES);
+ if (boot.NumBad) {
+ humanize_number(badstr, sizeof(badstr), badbytes, "",
+ HN_AUTOSCALE, HN_B | HN_DECIMAL | HN_IEC_PREFIXES);
+
+ pwarn("%d files, %sB free (%d clusters), %sB bad (%d clusters)\n",
+ boot.NumFiles, freestr, boot.NumFree,
+ badstr, boot.NumBad);
+ } else {
+ pwarn("%d files, %sB free (%d clusters)\n",
+ boot.NumFiles, freestr, boot.NumFree);
+ }
+#else
if (boot.NumBad)
- pwarn("%d files, %d free (%d clusters), %d bad (%d clusters)\n",
- boot.NumFiles,
- boot.NumFree * boot.ClusterSize / 1024, boot.NumFree,
- boot.NumBad * boot.ClusterSize / 1024, boot.NumBad);
+ pwarn("%d files, %jd KiB free (%d clusters), %jd KiB bad (%d clusters)\n",
+ boot.NumFiles, (intmax_t)freebytes / 1024, boot.NumFree,
+ (intmax_t)badbytes / 1024, boot.NumBad);
else
- pwarn("%d files, %d free (%d clusters)\n",
- boot.NumFiles,
- boot.NumFree * boot.ClusterSize / 1024, boot.NumFree);
+ pwarn("%d files, %jd KiB free (%d clusters)\n",
+ boot.NumFiles, (intmax_t)freebytes / 1024, boot.NumFree);
+#endif
if (mod && (mod & FSERROR) == 0) {
if (mod & FSDIRTY) {
@@ -143,7 +167,7 @@ checkfilesys(const char *fname)
if (mod & FSDIRTY) {
pwarn("MARKING FILE SYSTEM CLEAN\n");
- mod |= writefat(fat);
+ mod |= cleardirty(fat);
} else {
pwarn("\n***** FILE SYSTEM IS LEFT MARKED AS DIRTY *****\n");
mod |= FSERROR; /* file system not clean */
diff --git a/ext.h b/ext.h
index 6e9ba7f..532e840 100644
--- a/ext.h
+++ b/ext.h
@@ -90,6 +90,8 @@ int writefsinfo(int, struct bootblock *);
/* Opaque type */
struct fat_descriptor;
+int cleardirty(struct fat_descriptor *);
+
void fat_clear_cl_head(struct fat_descriptor *, cl_t);
bool fat_is_cl_head(struct fat_descriptor *, cl_t);
diff --git a/fat.c b/fat.c
index cb92010..e35e2f2 100644
--- a/fat.c
+++ b/fat.c
@@ -578,7 +578,6 @@ valid_cl(struct fat_descriptor *fat, cl_t cl)
* h = hard error flag (1 = ok; 0 = I/O error)
* x = any value ok
*/
-
int
checkdirty(int fs, struct bootblock *boot)
{
@@ -642,6 +641,53 @@ err:
return ret;
}
+int
+cleardirty(struct fat_descriptor *fat)
+{
+ int fd, ret = FSERROR;
+ struct bootblock *boot;
+ u_char *buffer;
+ size_t len;
+ off_t off;
+
+ boot = boot_of_(fat);
+ fd = fd_of_(fat);
+
+ if (boot->ClustMask != CLUST16_MASK && boot->ClustMask != CLUST32_MASK)
+ return 0;
+
+ off = boot->bpbResSectors;
+ off *= boot->bpbBytesPerSec;
+
+ buffer = malloc(len = boot->bpbBytesPerSec);
+ if (buffer == NULL) {
+ perr("No memory for FAT sectors (%zu)", len);
+ return 1;
+ }
+
+ if ((size_t)pread(fd, buffer, len, off) != len) {
+ perr("Unable to read FAT");
+ goto err;
+ }
+
+ if (boot->ClustMask == CLUST16_MASK) {
+ buffer[3] |= 0x80;
+ } else {
+ buffer[7] |= 0x08;
+ }
+
+ if ((size_t)pwrite(fd, buffer, len, off) != len) {
+ perr("Unable to write FAT");
+ goto err;
+ }
+
+ ret = FSOK;
+
+err:
+ free(buffer);
+ return ret;
+}
+
/*
* Read a FAT from disk. Returns 1 if successful, 0 otherwise.
*/