ASEC resize tweaking, allow read-write mounting.
Resize is no-op when sector count is unchanged; the caller can't anticipate how vold does its sector calculations. After resizing, we need to mount the container read-write, so allow the caller to request "ro" or "rw" mode. Handle ENOTSUP when trying to fallocate() on some filesystems Bug: 16514385 Change-Id: I0d3a378280d4c36d14f8108ff428102283d583fa
This commit is contained in:
parent
e82df164e8
commit
43ed123d3f
4 changed files with 16 additions and 9 deletions
|
@ -403,12 +403,16 @@ int CommandListener::AsecCmd::runCommand(SocketClient *cli,
|
||||||
rc = vm->destroyAsec(argv[2], force);
|
rc = vm->destroyAsec(argv[2], force);
|
||||||
} else if (!strcmp(argv[1], "mount")) {
|
} else if (!strcmp(argv[1], "mount")) {
|
||||||
dumpArgs(argc, argv, 3);
|
dumpArgs(argc, argv, 3);
|
||||||
if (argc != 5) {
|
if (argc != 6) {
|
||||||
cli->sendMsg(ResponseCode::CommandSyntaxError,
|
cli->sendMsg(ResponseCode::CommandSyntaxError,
|
||||||
"Usage: asec mount <namespace-id> <key> <ownerUid>", false);
|
"Usage: asec mount <namespace-id> <key> <ownerUid> <ro|rw>", false);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
rc = vm->mountAsec(argv[2], argv[3], atoi(argv[4]));
|
bool readOnly = true;
|
||||||
|
if (!strcmp(argv[5], "rw")) {
|
||||||
|
readOnly = false;
|
||||||
|
}
|
||||||
|
rc = vm->mountAsec(argv[2], argv[3], atoi(argv[4]), readOnly);
|
||||||
} else if (!strcmp(argv[1], "unmount")) {
|
} else if (!strcmp(argv[1], "unmount")) {
|
||||||
dumpArgs(argc, argv, -1);
|
dumpArgs(argc, argv, -1);
|
||||||
if (argc < 3) {
|
if (argc < 3) {
|
||||||
|
|
2
Loop.cpp
2
Loop.cpp
|
@ -260,7 +260,7 @@ int Loop::resizeImageFile(const char *file, unsigned int numSectors) {
|
||||||
SLOGD("Attempting to increase size of %s to %d sectors.", file, numSectors);
|
SLOGD("Attempting to increase size of %s to %d sectors.", file, numSectors);
|
||||||
|
|
||||||
if (fallocate(fd, 0, 0, numSectors * 512)) {
|
if (fallocate(fd, 0, 0, numSectors * 512)) {
|
||||||
if (errno == ENOSYS) {
|
if (errno == ENOSYS || errno == ENOTSUP) {
|
||||||
SLOGW("fallocate not found. Falling back to ftruncate.");
|
SLOGW("fallocate not found. Falling back to ftruncate.");
|
||||||
if (ftruncate(fd, numSectors * 512) < 0) {
|
if (ftruncate(fd, numSectors * 512) < 0) {
|
||||||
SLOGE("Error truncating imagefile (%s)", strerror(errno));
|
SLOGE("Error truncating imagefile (%s)", strerror(errno));
|
||||||
|
|
|
@ -641,7 +641,10 @@ int VolumeManager::resizeAsec(const char *id, unsigned numSectors, const char *k
|
||||||
* add one block for the superblock
|
* add one block for the superblock
|
||||||
*/
|
*/
|
||||||
SLOGD("Resizing from %d sectors to %d sectors", oldNumSec, numImgSectors + 1);
|
SLOGD("Resizing from %d sectors to %d sectors", oldNumSec, numImgSectors + 1);
|
||||||
if (oldNumSec >= numImgSectors + 1) {
|
if (oldNumSec == numImgSectors + 1) {
|
||||||
|
SLOGW("Size unchanged; ignoring resize request");
|
||||||
|
return 0;
|
||||||
|
} else if (oldNumSec > numImgSectors + 1) {
|
||||||
SLOGE("Only growing is currently supported.");
|
SLOGE("Only growing is currently supported.");
|
||||||
close(fd);
|
close(fd);
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -1249,7 +1252,7 @@ int VolumeManager::findAsec(const char *id, char *asecPath, size_t asecPathLen,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int VolumeManager::mountAsec(const char *id, const char *key, int ownerUid) {
|
int VolumeManager::mountAsec(const char *id, const char *key, int ownerUid, bool readOnly) {
|
||||||
char asecFileName[255];
|
char asecFileName[255];
|
||||||
char mountPoint[255];
|
char mountPoint[255];
|
||||||
|
|
||||||
|
@ -1330,9 +1333,9 @@ int VolumeManager::mountAsec(const char *id, const char *key, int ownerUid) {
|
||||||
|
|
||||||
int result;
|
int result;
|
||||||
if (sb.c_opts & ASEC_SB_C_OPTS_EXT4) {
|
if (sb.c_opts & ASEC_SB_C_OPTS_EXT4) {
|
||||||
result = Ext4::doMount(dmDevice, mountPoint, true, false, true);
|
result = Ext4::doMount(dmDevice, mountPoint, readOnly, false, readOnly);
|
||||||
} else {
|
} else {
|
||||||
result = Fat::doMount(dmDevice, mountPoint, true, false, true, ownerUid, 0, 0222, false);
|
result = Fat::doMount(dmDevice, mountPoint, readOnly, false, readOnly, ownerUid, 0, 0222, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result) {
|
if (result) {
|
||||||
|
|
|
@ -106,7 +106,7 @@ public:
|
||||||
*/
|
*/
|
||||||
int fixupAsecPermissions(const char *id, gid_t gid, const char* privateFilename);
|
int fixupAsecPermissions(const char *id, gid_t gid, const char* privateFilename);
|
||||||
int destroyAsec(const char *id, bool force);
|
int destroyAsec(const char *id, bool force);
|
||||||
int mountAsec(const char *id, const char *key, int ownerUid);
|
int mountAsec(const char *id, const char *key, int ownerUid, bool readOnly);
|
||||||
int unmountAsec(const char *id, bool force);
|
int unmountAsec(const char *id, bool force);
|
||||||
int renameAsec(const char *id1, const char *id2);
|
int renameAsec(const char *id1, const char *id2);
|
||||||
int getAsecMountPath(const char *id, char *buffer, int maxlen);
|
int getAsecMountPath(const char *id, char *buffer, int maxlen);
|
||||||
|
|
Loading…
Reference in a new issue