Skip to content

Commit ca9e34e

Browse files
committed
Enable exFAT mount
1 parent b2362c0 commit ca9e34e

File tree

4 files changed

+6
-194
lines changed

4 files changed

+6
-194
lines changed

Fat.cpp

Lines changed: 3 additions & 169 deletions
Original file line numberDiff line numberDiff line change
@@ -45,73 +45,8 @@
4545
#include "Fat.h"
4646
#include "VoldUtil.h"
4747

48-
static char FSCK_MSDOS_PATH[] = "/system/bin/fsck_msdos";
49-
static char MKDOSFS_PATH[] = "/system/bin/newfs_msdos";
5048
extern "C" int mount(const char *, const char *, const char *, unsigned long, const void *);
5149

52-
int Fat::check(const char *fsPath) {
53-
bool rw = true;
54-
if (access(FSCK_MSDOS_PATH, X_OK)) {
55-
SLOGW("Skipping fs checks\n");
56-
return 0;
57-
}
58-
59-
int pass = 1;
60-
int rc = 0;
61-
do {
62-
const char *args[4];
63-
int status;
64-
args[0] = FSCK_MSDOS_PATH;
65-
args[1] = "-p";
66-
args[2] = "-f";
67-
args[3] = fsPath;
68-
69-
rc = android_fork_execvp(ARRAY_SIZE(args), (char **)args, &status,
70-
false, true);
71-
if (rc != 0) {
72-
SLOGE("Filesystem check failed due to logwrap error");
73-
errno = EIO;
74-
return -1;
75-
}
76-
77-
if (!WIFEXITED(status)) {
78-
SLOGE("Filesystem check did not exit properly");
79-
errno = EIO;
80-
return -1;
81-
}
82-
83-
status = WEXITSTATUS(status);
84-
85-
switch(status) {
86-
case 0:
87-
SLOGI("Filesystem check completed OK");
88-
return 0;
89-
90-
case 2:
91-
SLOGE("Filesystem check failed (not a FAT filesystem)");
92-
errno = ENODATA;
93-
return -1;
94-
95-
case 4:
96-
if (pass++ <= 3) {
97-
SLOGW("Filesystem modified - rechecking (pass %d)",
98-
pass);
99-
continue;
100-
}
101-
SLOGE("Failing check after too many rechecks");
102-
errno = EIO;
103-
return -1;
104-
105-
default:
106-
SLOGE("Filesystem check failed (unknown exit code %d)", status);
107-
errno = EIO;
108-
return -1;
109-
}
110-
} while (0);
111-
112-
return 0;
113-
}
114-
11550
int Fat::doMount(const char *fsPath, const char *mountPoint,
11651
bool ro, bool remount, bool executable,
11752
int ownerUid, int ownerGid, int permMask, bool createLost) {
@@ -140,117 +75,16 @@ int Fat::doMount(const char *fsPath, const char *mountPoint,
14075
}
14176

14277
sprintf(mountData,
143-
"utf8,uid=%d,gid=%d,fmask=%o,dmask=%o,shortname=mixed",
78+
"utf8,uid=%d,gid=%d,fmask=%o,dmask=%o",
14479
ownerUid, ownerGid, permMask, permMask);
14580

146-
rc = mount(fsPath, mountPoint, "vfat", flags, mountData);
81+
rc = mount(fsPath, mountPoint, "exfat", flags, mountData);
14782

14883
if (rc && errno == EROFS) {
14984
SLOGE("%s appears to be a read only filesystem - retrying mount RO", fsPath);
15085
flags |= MS_RDONLY;
151-
rc = mount(fsPath, mountPoint, "vfat", flags, mountData);
152-
}
153-
154-
if (rc == 0 && createLost) {
155-
char *lost_path;
156-
asprintf(&lost_path, "%s/LOST.DIR", mountPoint);
157-
if (access(lost_path, F_OK)) {
158-
/*
159-
* Create a LOST.DIR in the root so we have somewhere to put
160-
* lost cluster chains (fsck_msdos doesn't currently do this)
161-
*/
162-
if (mkdir(lost_path, 0755)) {
163-
SLOGE("Unable to create LOST.DIR (%s)", strerror(errno));
164-
}
165-
}
166-
free(lost_path);
86+
rc = mount(fsPath, mountPoint, "exfat", flags, mountData);
16787
}
16888

16989
return rc;
17090
}
171-
172-
int Fat::format(const char *fsPath, unsigned int numSectors, bool wipe) {
173-
int fd;
174-
const char *args[11];
175-
int rc;
176-
int status;
177-
178-
if (wipe) {
179-
Fat::wipe(fsPath, numSectors);
180-
}
181-
182-
args[0] = MKDOSFS_PATH;
183-
args[1] = "-F";
184-
args[2] = "32";
185-
args[3] = "-O";
186-
args[4] = "android";
187-
args[5] = "-c";
188-
args[6] = "64";
189-
args[7] = "-A";
190-
191-
if (numSectors) {
192-
char tmp[32];
193-
snprintf(tmp, sizeof(tmp), "%u", numSectors);
194-
const char *size = tmp;
195-
args[8] = "-s";
196-
args[9] = size;
197-
args[10] = fsPath;
198-
rc = android_fork_execvp(ARRAY_SIZE(args), (char **)args, &status,
199-
false, true);
200-
} else {
201-
args[8] = fsPath;
202-
rc = android_fork_execvp(9, (char **)args, &status, false,
203-
true);
204-
}
205-
206-
if (rc != 0) {
207-
SLOGE("Filesystem format failed due to logwrap error");
208-
errno = EIO;
209-
return -1;
210-
}
211-
212-
if (!WIFEXITED(status)) {
213-
SLOGE("Filesystem format did not exit properly");
214-
errno = EIO;
215-
return -1;
216-
}
217-
218-
status = WEXITSTATUS(status);
219-
220-
if (status == 0) {
221-
SLOGI("Filesystem formatted OK");
222-
return 0;
223-
} else {
224-
SLOGE("Format failed (unknown exit code %d)", status);
225-
errno = EIO;
226-
return -1;
227-
}
228-
return 0;
229-
}
230-
231-
void Fat::wipe(const char *fsPath, unsigned int numSectors) {
232-
int fd;
233-
unsigned long long range[2];
234-
235-
fd = open(fsPath, O_RDWR);
236-
if (fd >= 0) {
237-
if (numSectors == 0) {
238-
numSectors = get_blkdev_size(fd);
239-
}
240-
if (numSectors == 0) {
241-
SLOGE("Fat wipe failed to determine size of %s", fsPath);
242-
close(fd);
243-
return;
244-
}
245-
range[0] = 0;
246-
range[1] = (unsigned long long)numSectors * 512;
247-
if (ioctl(fd, BLKDISCARD, &range) < 0) {
248-
SLOGE("Fat wipe failed to discard blocks on %s", fsPath);
249-
} else {
250-
SLOGI("Fat wipe %d sectors on %s succeeded", numSectors, fsPath);
251-
}
252-
close(fd);
253-
} else {
254-
SLOGE("Fat wipe failed to open device %s", fsPath);
255-
}
256-
}

Fat.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,10 @@
2121

2222
class Fat {
2323
public:
24-
static int check(const char *fsPath);
2524
static int doMount(const char *fsPath, const char *mountPoint,
2625
bool ro, bool remount, bool executable,
2726
int ownerUid, int ownerGid, int permMask,
2827
bool createLost);
29-
static int format(const char *fsPath, unsigned int numSectors, bool wipe);
30-
31-
private:
32-
static void wipe(const char *fsPath, unsigned int numSectors);
3328
};
3429

3530
#endif

Volume.cpp

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -273,11 +273,7 @@ int Volume::formatVol(bool wipe) {
273273

274274
if (mDebug) {
275275
SLOGI("Formatting volume %s (%s)", getLabel(), devicePath);
276-
}
277-
278-
if (Fat::format(devicePath, 0, wipe)) {
279-
SLOGE("Failed to format (%s)", strerror(errno));
280-
goto err;
276+
SLOGI("Format volume not implemented %s (%s)", getLabel(), devicePath);
281277
}
282278

283279
ret = 0;
@@ -423,24 +419,11 @@ int Volume::mountVol() {
423419
errno = 0;
424420
setState(Volume::State_Checking);
425421

426-
if (Fat::check(devicePath)) {
427-
if (errno == ENODATA) {
428-
SLOGW("%s does not contain a FAT filesystem\n", devicePath);
429-
continue;
430-
}
431-
errno = EIO;
432-
/* Badness - abort the mount */
433-
SLOGE("%s failed FS checks (%s)", devicePath, strerror(errno));
434-
setState(Volume::State_Idle);
435-
return -1;
436-
}
437-
438-
errno = 0;
439422
int gid;
440423

441424
if (Fat::doMount(devicePath, getMountpoint(), false, false, false,
442425
AID_MEDIA_RW, AID_MEDIA_RW, 0007, true)) {
443-
SLOGE("%s failed to mount via VFAT (%s)\n", devicePath, strerror(errno));
426+
SLOGE("%s failed to mount via exFAT (%s)\n", devicePath, strerror(errno));
444427
continue;
445428
}
446429

VolumeManager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ int VolumeManager::createAsec(const char *id, unsigned int numSectors, const cha
525525
if (usingExt4) {
526526
formatStatus = Ext4::format(dmDevice, numImgSectors, mountPoint);
527527
} else {
528-
formatStatus = Fat::format(dmDevice, numImgSectors, 0);
528+
formatStatus = -1;
529529
}
530530

531531
if (formatStatus < 0) {

0 commit comments

Comments
 (0)