Skip to content

Commit

Permalink
EXT4 mount support for the vold daemon.
Browse files Browse the repository at this point in the history
Change-Id: I1daf2370e984f642483c37ef72d1c81934eaa760
  • Loading branch information
Cristian Henzel committed Mar 6, 2011
1 parent bc4054f commit d0087cc
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 10 deletions.
49 changes: 41 additions & 8 deletions Fat.cpp
Expand Up @@ -39,13 +39,14 @@
#include "Fat.h"

static char FSCK_MSDOS_PATH[] = "/system/bin/fsck_msdos";
static char FSCK_EXT_PATH[] = "/system/bin/e2fsck";
static char MKDOSFS_PATH[] = "/system/bin/newfs_msdos";
extern "C" int logwrap(int argc, const char **argv, int background);
extern "C" int mount(const char *, const char *, const char *, unsigned long, const void *);

int Fat::check(const char *fsPath) {
bool rw = true;
if (access(FSCK_MSDOS_PATH, X_OK)) {
if (access(FSCK_MSDOS_PATH, X_OK) || access(FSCK_EXT_PATH, X_OK)) {
SLOGW("Skipping fs checks\n");
return 0;
}
Expand All @@ -61,14 +62,39 @@ int Fat::check(const char *fsPath) {
args[4] = NULL;

rc = logwrap(4, args, 1);
if (rc == 0) {
// if rc is 0, the check was ok
// That means the FileSystem is FAT
fsType = 1;
} else {
args[0] = FSCK_EXT_PATH;
args[1] = "-p";
args[2] = "-f";
args[3] = fsPath;
args[4] = NULL;
rc = logwrap(4, args, 1);
if (rc == 0)
// if rc is 0, the check was ok
// That means the FileSystem is EXT
fsType = 2;
}

switch(rc) {
case 0:
SLOGI("Filesystem check completed OK");
// TODO: Remove this print.
const char *fsTypePrint;
if (fsType == 1)
fsTypePrint = "VFAT";
else if (fsType == 2)
fsTypePrint = "EXT";
else
fsTypePrint = "Unknown";
SLOGI("Filesystem type is: %s", fsTypePrint);
return 0;

case 2:
SLOGE("Filesystem check failed (not a FAT filesystem)");
SLOGW("Filesystem check failed (not a FAT or EXT filesystem)");
errno = ENODATA;
return -1;

Expand Down Expand Up @@ -98,6 +124,7 @@ int Fat::doMount(const char *fsPath, const char *mountPoint,
int rc;
unsigned long flags;
char mountData[255];
const char *mntFSType;

flags = MS_NODEV | MS_NOSUID | MS_DIRSYNC;

Expand All @@ -119,19 +146,25 @@ int Fat::doMount(const char *fsPath, const char *mountPoint,
permMask = 0;
}

sprintf(mountData,
"utf8,uid=%d,gid=%d,fmask=%o,dmask=%o,shortname=mixed",
ownerUid, ownerGid, permMask, permMask);
if (fsType == 2) {
sprintf(mountData, "noauto_da_alloc");
mntFSType = "ext4";
} else {
sprintf(mountData,
"utf8,uid=%d,gid=%d,fmask=%o,dmask=%o,shortname=mixed",
ownerUid, ownerGid, permMask, permMask);
mntFSType = "vfat";
}

rc = mount(fsPath, mountPoint, "vfat", flags, mountData);
rc = mount(fsPath, mountPoint, mntFSType, flags, mountData);

if (rc && errno == EROFS) {
SLOGE("%s appears to be a read only filesystem - retrying mount RO", fsPath);
flags |= MS_RDONLY;
rc = mount(fsPath, mountPoint, "vfat", flags, mountData);
rc = mount(fsPath, mountPoint, mntFSType, flags, mountData);
}

if (rc == 0 && createLost) {
if (rc == 0 && createLost && fsType == 1) {
char *lost_path;
asprintf(&lost_path, "%s/LOST.DIR", mountPoint);
if (access(lost_path, F_OK)) {
Expand Down
2 changes: 2 additions & 0 deletions Fat.h
Expand Up @@ -19,6 +19,8 @@

#include <unistd.h>

static int fsType;

class Fat {
public:
static int check(const char *fsPath);
Expand Down
4 changes: 2 additions & 2 deletions Volume.cpp
Expand Up @@ -329,7 +329,7 @@ int Volume::mountVol() {

if (Fat::check(devicePath)) {
if (errno == ENODATA) {
SLOGW("%s does not contain a FAT filesystem\n", devicePath);
SLOGW("%s does not contain a FAT or EXT4 filesystem\n", devicePath);
continue;
}
errno = EIO;
Expand All @@ -346,7 +346,7 @@ int Volume::mountVol() {
errno = 0;
if (Fat::doMount(devicePath, "/mnt/secure/staging", false, false, false,
1000, 1015, 0702, true)) {
SLOGE("%s failed to mount via VFAT (%s)\n", devicePath, strerror(errno));
SLOGE("%s failed to mount (%s)\n", devicePath, strerror(errno));
continue;
}

Expand Down

0 comments on commit d0087cc

Please sign in to comment.