vold2: Enable support for custom mount perm masks and wire to asec

Signed-off-by: San Mehat <san@google.com>
This commit is contained in:
San Mehat 2010-01-06 19:19:46 -08:00
parent a19b250bd2
commit fff0b47998
4 changed files with 23 additions and 21 deletions

29
Fat.cpp
View file

@ -92,9 +92,12 @@ int Fat::check(const char *fsPath) {
return 0; return 0;
} }
int Fat::doMount(const char *fsPath, const char *mountPoint, bool ro, bool remount) { int Fat::doMount(const char *fsPath, const char *mountPoint,
bool ro, bool remount, int ownerUid, int ownerGid,
int permMask, bool createLost) {
int rc; int rc;
unsigned long flags; unsigned long flags;
char mountData[255];
flags = MS_NODEV | MS_NOEXEC | MS_NOSUID | MS_DIRSYNC; flags = MS_NODEV | MS_NOEXEC | MS_NOSUID | MS_DIRSYNC;
@ -112,28 +115,22 @@ int Fat::doMount(const char *fsPath, const char *mountPoint, bool ro, bool remou
if (value[0] == '1') { if (value[0] == '1') {
LOGW("The SD card is world-writable because the" LOGW("The SD card is world-writable because the"
" 'persist.sampling_profiler' system property is set to '1'."); " 'persist.sampling_profiler' system property is set to '1'.");
rc = mount(fsPath, mountPoint, (const char *) "vfat", (unsigned long) flags, permMask = 0;
(const void *) "utf8,uid=1000,gid=1015,fmask=000,dmask=000,shortname=mixed");
} else {
/*
* The mount masks restrict access so that:
* 1. The 'system' user cannot access the SD card at all -
* (protects system_server from grabbing file references)
* 2. Group users can RWX
* 3. Others can only RX
*/
rc = mount(fsPath, mountPoint, "vfat", flags,
"utf8,uid=1000,gid=1015,fmask=702,dmask=702,shortname=mixed");
} }
sprintf(mountData,
"utf8,uid=%d,gid=%d,fmask=%o,dmask=%o,shortname=mixed",
ownerUid, ownerGid, permMask, permMask);
rc = mount(fsPath, mountPoint, "vfat", flags, mountData);
if (rc && errno == EROFS) { if (rc && errno == EROFS) {
LOGE("%s appears to be a read only filesystem - retrying mount RO", fsPath); LOGE("%s appears to be a read only filesystem - retrying mount RO", fsPath);
flags |= MS_RDONLY; flags |= MS_RDONLY;
rc = mount(fsPath, mountPoint, "vfat", flags, rc = mount(fsPath, mountPoint, "vfat", flags, mountData);
"utf8,uid=1000,gid=1015,fmask=702,dmask=702,shortname=mixed");
} }
if (rc == 0) { if (rc == 0 && createLost) {
char *lost_path; char *lost_path;
asprintf(&lost_path, "%s/LOST.DIR", mountPoint); asprintf(&lost_path, "%s/LOST.DIR", mountPoint);
if (access(lost_path, F_OK)) { if (access(lost_path, F_OK)) {

3
Fat.h
View file

@ -23,7 +23,8 @@ class Fat {
public: public:
static int check(const char *fsPath); static int check(const char *fsPath);
static int doMount(const char *fsPath, const char *mountPoint, bool ro, static int doMount(const char *fsPath, const char *mountPoint, bool ro,
bool remount); bool remount, int ownerUid, int ownerGid, int permMask,
bool createLost);
static int format(const char *fsPath); static int format(const char *fsPath);
}; };

View file

@ -268,7 +268,8 @@ int Volume::mountVol() {
LOGI("%s checks out - attempting to mount\n", devicePath); LOGI("%s checks out - attempting to mount\n", devicePath);
errno = 0; errno = 0;
if (!(rc = Fat::doMount(devicePath, getMountpoint(), false, false))) { if (!(rc = Fat::doMount(devicePath, getMountpoint(), false, false,
1000, 1015, 0702, true))) {
LOGI("%s sucessfully mounted for volume %s\n", devicePath, LOGI("%s sucessfully mounted for volume %s\n", devicePath,
getLabel()); getLabel());
setState(Volume::State_Mounted); setState(Volume::State_Mounted);

View file

@ -226,7 +226,8 @@ int VolumeManager::createAsec(const char *id, int sizeMb,
return -1; return -1;
} }
if (Fat::doMount(loopDevice, mountPoint, false, false)) { if (Fat::doMount(loopDevice, mountPoint, false, false, ownerUid,
0, 0007, false)) {
LOGE("ASEC FAT mount failed (%s)", strerror(errno)); LOGE("ASEC FAT mount failed (%s)", strerror(errno));
Loop::destroyByDevice(loopDevice); Loop::destroyByDevice(loopDevice);
unlink(asecFileName); unlink(asecFileName);
@ -250,7 +251,8 @@ int VolumeManager::finalizeAsec(const char *id) {
} }
snprintf(mountPoint, sizeof(mountPoint), "/asec/%s", id); snprintf(mountPoint, sizeof(mountPoint), "/asec/%s", id);
if (Fat::doMount(loopDevice, mountPoint, true, true)) { // XXX:
if (Fat::doMount(loopDevice, mountPoint, true, true, 0, 0, 0227, false)) {
LOGE("ASEC finalize mount failed (%s)", strerror(errno)); LOGE("ASEC finalize mount failed (%s)", strerror(errno));
return -1; return -1;
} }
@ -331,7 +333,8 @@ int VolumeManager::mountAsec(const char *id, const char *key, int ownerUid) {
return -1; return -1;
} }
if (Fat::doMount(loopDevice, mountPoint, true, false)) { if (Fat::doMount(loopDevice, mountPoint, true, false, ownerUid, 0,
0227, false)) {
LOGE("ASEC mount failed (%s)", strerror(errno)); LOGE("ASEC mount failed (%s)", strerror(errno));
return -1; return -1;
} }