Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix sdcard #1

Open
wants to merge 2 commits into
base: android-5.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
130 changes: 100 additions & 30 deletions Android.mk
Original file line number Diff line number Diff line change
@@ -1,20 +1,6 @@
LOCAL_PATH:= $(call my-dir)

common_cflags := \
-Werror=format \
-Wno-unused-parameter

ifneq ($(BOARD_VOLD_MAX_PARTITIONS),)
common_cflags += -DVOLD_MAX_PARTITIONS=$(BOARD_VOLD_MAX_PARTITIONS)
endif

ifeq ($(BOARD_VOLD_EMMC_SHARES_DEV_MAJOR), true)
common_cflags += -DVOLD_EMMC_SHARES_DEV_MAJOR
endif

ifeq ($(BOARD_VOLD_DISC_HAS_MULTIPLE_MAJORS), true)
common_cflags += -DVOLD_DISC_HAS_MULTIPLE_MAJORS
endif
common_cflags := -Werror -Wno-unused-parameter

common_src_files := \
VolumeManager.cpp \
Expand All @@ -27,14 +13,17 @@ common_src_files := \
Process.cpp \
Ext4.cpp \
Fat.cpp \
Ntfs.cpp \
Exfat.cpp \
F2FS.cpp \
Loop.cpp \
Devmapper.cpp \
ResponseCode.cpp \
CheckBattery.cpp \
VoldUtil.c \
fstrim.c \
cryptfs.c
cryptfs.c \
main.cpp

common_c_includes := \
system/extras/ext4_utils \
Expand All @@ -49,57 +38,138 @@ common_c_includes := \
system/security/softkeymaster/include/keymaster \
external/e2fsprogs/lib

common_shared_libraries := \
common_libraries := \
libsysutils \
libstlport \
libbinder \
libcutils \
liblog \
libdiskconfig \
libhardware_legacy \
liblogwrap \
libext4_utils \
libf2fs_sparseblock \
libcrypto \
libselinux \
libutils \

common_shared_libraries := \
$(common_libraries) \
libhardware_legacy \
libcrypto \
libhardware \
libstlport \
libsoftkeymaster \
libext2_blkid

common_static_libraries := \
libfs_mgr \
libext4_utils_static \
libscrypt_static \
libmincrypt \
libbatteryservice
libminshacrypt \
libbatteryservice \
libext2_blkid \
libext2_uuid_static

ifneq ($(BOARD_VOLD_MAX_PARTITIONS),)
common_cflags += -DVOLD_MAX_PARTITIONS=$(BOARD_VOLD_MAX_PARTITIONS)
endif

ifeq ($(BOARD_VOLD_EMMC_SHARES_DEV_MAJOR), true)
common_cflags += -DVOLD_EMMC_SHARES_DEV_MAJOR
endif

ifeq ($(BOARD_VOLD_DISC_HAS_MULTIPLE_MAJORS), true)
common_cflags += -DVOLD_DISC_HAS_MULTIPLE_MAJORS
endif

include $(CLEAR_VARS)

LOCAL_MODULE := libvold

LOCAL_SRC_FILES := $(common_src_files)

LOCAL_C_INCLUDES := $(common_c_includes)

LOCAL_CFLAGS := $(common_cflags)

LOCAL_SHARED_LIBRARIES := $(common_shared_libraries)

LOCAL_STATIC_LIBRARIES := $(common_static_libraries)
LOCAL_CFLAGS := $(common_cflags)

ifeq ($(TARGET_HW_DISK_ENCRYPTION),true)
LOCAL_C_INCLUDES += device/qcom/common/cryptfs_hw
LOCAL_SHARED_LIBRARIES += libcryptfs_hw
LOCAL_CFLAGS += -DCONFIG_HW_DISK_ENCRYPTION
endif

LOCAL_MODULE_TAGS := eng tests

include $(BUILD_STATIC_LIBRARY)

include $(CLEAR_VARS)

LOCAL_MODULE:= vold

LOCAL_SRC_FILES := \
main.cpp \
$(common_src_files)
LOCAL_SRC_FILES := vold.c

LOCAL_C_INCLUDES := $(common_c_includes)
LOCAL_CFLAGS := $(common_cflags)

LOCAL_SHARED_LIBRARIES := $(common_shared_libraries)
LOCAL_STATIC_LIBRARIES := $(common_static_libraries)

LOCAL_STATIC_LIBRARIES := libvold $(common_static_libraries)

LOCAL_CFLAGS += -Werror=format

ifeq ($(TARGET_HW_DISK_ENCRYPTION),true)
LOCAL_C_INCLUDES += device/qcom/common/cryptfs_hw
LOCAL_SHARED_LIBRARIES += libcryptfs_hw
LOCAL_CFLAGS += -DCONFIG_HW_DISK_ENCRYPTION
endif

ifneq ($(BOARD_VOLD_MAX_PARTITIONS),)
LOCAL_CFLAGS += -DVOLD_MAX_PARTITIONS=$(BOARD_VOLD_MAX_PARTITIONS)
endif

ifeq ($(BOARD_VOLD_DISC_HAS_MULTIPLE_MAJORS), true)
LOCAL_CFLAGS += -DVOLD_DISC_HAS_MULTIPLE_MAJORS
endif

ifeq ($(BOARD_VOLD_EMMC_SHARES_DEV_MAJOR), true)
LOCAL_CFLAGS += -DVOLD_EMMC_SHARES_DEV_MAJOR
endif

include $(BUILD_EXECUTABLE)

include $(CLEAR_VARS)

LOCAL_SRC_FILES:= vdc.c

LOCAL_MODULE:= vdc

LOCAL_C_INCLUDES :=
LOCAL_CFLAGS :=

LOCAL_CFLAGS := $(common_cflags)

LOCAL_SHARED_LIBRARIES := libcutils

include $(BUILD_EXECUTABLE)

include $(CLEAR_VARS)
LOCAL_MODULE:= libminivold
LOCAL_SRC_FILES := $(common_src_files)
LOCAL_C_INCLUDES := $(common_c_includes) system/core/fs_mgr/include system/core/logwrapper/include
LOCAL_CFLAGS := $(common_cflags) -DMINIVOLD -DHELPER_PATH=\"/sbin/\"
LOCAL_MODULE_TAGS := optional
include $(BUILD_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE:= minivold
LOCAL_SRC_FILES := vold.c
LOCAL_C_INCLUDES := $(common_c_includes)
LOCAL_CFLAGS := $(common_cflags) -DMINIVOLD
LOCAL_STATIC_LIBRARIES := libminivold
LOCAL_STATIC_LIBRARIES += libc libstdc++ libstlport_static
LOCAL_STATIC_LIBRARIES += $(common_static_libraries) $(common_libraries)
LOCAL_STATIC_LIBRARIES += libcrypto_static libvold
LOCAL_FORCE_STATIC_EXECUTABLE := true
LOCAL_MODULE_CLASS := RECOVERY_EXECUTABLES
LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/sbin
LOCAL_MODULE_TAGS := optional
include $(BUILD_EXECUTABLE)
1 change: 1 addition & 0 deletions CleanSpec.mk
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,4 @@
# ************************************************
# NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST
# ************************************************
$(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/EXECUTABLES/vold_intermediates)
23 changes: 19 additions & 4 deletions CommandListener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,20 +148,25 @@ int CommandListener::VolumeCmd::runCommand(SocketClient *cli,
} else if (!strcmp(argv[1], "unmount")) {
if (argc < 3 || argc > 4 ||
((argc == 4 && strcmp(argv[3], "force")) &&
(argc == 4 && strcmp(argv[3], "force_and_revert")))) {
cli->sendMsg(ResponseCode::CommandSyntaxError, "Usage: volume unmount <path> [force|force_and_revert]", false);
(argc == 4 && strcmp(argv[3], "force_and_revert")) &&
(argc == 4 && strcmp(argv[3], "detach")))) {
cli->sendMsg(ResponseCode::CommandSyntaxError, "Usage: volume unmount <path> [force|force_and_revert|detach]", false);
return 0;
}

bool force = false;
bool revert = false;
bool detach = false;
if (argc >= 4 && !strcmp(argv[3], "force")) {
force = true;
} else if (argc >= 4 && !strcmp(argv[3], "force_and_revert")) {
force = true;
revert = true;
}
rc = vm->unmountVolume(argv[2], force, revert);
else if (argc >= 4 && !strcmp(argv[3], "detach")) {
detach = true;
}
rc = vm->unmountVolume(argv[2], force, revert, detach);
} else if (!strcmp(argv[1], "format")) {
if (argc < 3 || argc > 4 ||
(argc == 4 && strcmp(argv[3], "wipe"))) {
Expand Down Expand Up @@ -568,7 +573,17 @@ int CommandListener::CryptfsCmd::runCommand(SocketClient *cli,

int rc = 0;

if (!strcmp(argv[1], "checkpw")) {
if (!strcmp(argv[1], "pfe")) {
if (argc != 3) {
cli->sendMsg(ResponseCode::CommandSyntaxError, "Usage: cryptfs pfe <enable|disable>", false);
return 0;
}
dumpArgs(argc, argv, 2);
if (!strcmp(argv[2], "enable"))
rc = cryptfs_pfe_activate();
else if (!strcmp(argv[2], "disable"))
rc = cryptfs_pfe_deactivate();
} else if (!strcmp(argv[1], "checkpw")) {
if (argc != 3) {
cli->sendMsg(ResponseCode::CommandSyntaxError, "Usage: cryptfs checkpw <passwd>", false);
return 0;
Expand Down
69 changes: 55 additions & 14 deletions DirectVolume.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ DirectVolume::DirectVolume(VolumeManager *vm, const fstab_rec* rec, int flags) :
mDiskMinor = -1;
mDiskNumParts = 0;
mIsDecrypted = 0;
mIsValid = true;

if (strcmp(rec->mount_point, "auto") != 0) {
ALOGE("Vold managed volumes must have auto mount point; ignoring %s",
Expand All @@ -88,10 +89,16 @@ DirectVolume::DirectVolume(VolumeManager *vm, const fstab_rec* rec, int flags) :

char mount[PATH_MAX];

#ifdef MINIVOLD
// In recovery, directly mount to /storage/* since we have no fuse daemon
snprintf(mount, PATH_MAX, "%s/%s", Volume::FUSE_DIR, rec->label);
mMountpoint = mFuseMountpoint = strdup(mount);
#else
snprintf(mount, PATH_MAX, "%s/%s", Volume::MEDIA_DIR, rec->label);
mMountpoint = strdup(mount);
snprintf(mount, PATH_MAX, "%s/%s", Volume::FUSE_DIR, rec->label);
mFuseMountpoint = strdup(mount);
#endif

setState(Volume::State_NoMedia);
}
Expand All @@ -115,14 +122,6 @@ dev_t DirectVolume::getDiskDevice() {

dev_t DirectVolume::getShareDevice() {
if (mPartIdx != -1) {
#ifdef VOLD_DISC_HAS_MULTIPLE_MAJORS
int major = getMajorNumberForBadPartition(mPartIdx);
if(major != -1) {
SLOGE("getShareDevice() returning correct major: %d, minor: %d", major, mPartMinors[mPartIdx - 1]);
return MKDEV(major, mPartMinors[mPartIdx - 1]);
}
else
#endif
return MKDEV(mDiskMajor, mPartIdx);
} else {
return MKDEV(mDiskMajor, mDiskMinor);
Expand All @@ -137,12 +136,38 @@ void DirectVolume::handleVolumeUnshared() {
setState(Volume::State_Idle);
}

int DirectVolume::getUICCVolumeNum(const char *dp) {
int mVolNum = -1;
if (strstr(dp, ":0:0:0"))
mVolNum = 0;
else if (strstr(dp, ":0:0:1"))
mVolNum = 1;

return mVolNum;
}

int DirectVolume::handleBlockEvent(NetlinkEvent *evt) {
const char *dp = evt->findParam("DEVPATH");

PathCollection::iterator it;
for (it = mPaths->begin(); it != mPaths->end(); ++it) {
if ((*it)->match(dp)) {

/* Check for UICC prefix in label */
if (strstr(getLabel(), "uicc")) {
char mLabel[15];
int mNum = getUICCVolumeNum(dp);
if (mNum < 0) {
SLOGE("Invalid uicc volume number");
continue;
}

snprintf(mLabel, sizeof(mLabel), "uicc%d", mNum);
if (strncmp(getLabel(), mLabel, strlen(mLabel)) != 0)
continue;
}
setValidSysfs(true);

/* We can handle this disk */
int action = evt->getAction();
const char *devtype = evt->findParam("DEVTYPE");
Expand Down Expand Up @@ -211,8 +236,7 @@ void DirectVolume::handleDiskAdded(const char * /*devpath*/,
}

mPendingPartCount = mDiskNumParts;
for (int i = 0; i < MAX_PARTITIONS; i++)
mPartMinors[i] = -1;


if (mDiskNumParts == 0) {
#ifdef PARTITION_DEBUG
Expand Down Expand Up @@ -267,8 +291,8 @@ void DirectVolume::handlePartitionAdded(const char *devpath, NetlinkEvent *evt)
#ifdef PARTITION_DEBUG
SLOGD("Dv:partAdd: part_num = %d, minor = %d\n", part_num, minor);
#endif
if (part_num >= MAX_PARTITIONS) {
SLOGE("Dv:partAdd: ignoring part_num = %d (max: %d)\n", part_num, MAX_PARTITIONS-1);
if (part_num > MAX_PARTITIONS) {
SLOGE("Dv:partAdd: ignoring part_num = %d (max: %d)\n", part_num, MAX_PARTITIONS);
} else {
if ((mPartMinors[part_num - 1] == -1) && mPendingPartCount)
mPendingPartCount--;
Expand Down Expand Up @@ -347,6 +371,23 @@ void DirectVolume::handleDiskRemoved(const char * /*devpath*/,
getLabel(), getFuseMountpoint(), major, minor);
mVm->getBroadcaster()->sendBroadcast(ResponseCode::VolumeDiskRemoved,
msg, false);

if ((dev_t) MKDEV(major, minor) == mCurrentlyMountedKdev) {

bool providesAsec = (getFlags() & VOL_PROVIDES_ASEC) != 0;
if (providesAsec && mVm->cleanupAsec(this, true)) {
SLOGE("Failed to cleanup ASEC - unmount will probably fail!");
}

if (Volume::unmountVol(true, false, false)) {
SLOGE("Failed to unmount volume on bad removal (%s)",
strerror(errno));
// XXX: At this point we're screwed for now
} else {
SLOGD("Crisis averted");
}
}

setState(Volume::State_NoMedia);
}

Expand Down Expand Up @@ -385,7 +426,7 @@ void DirectVolume::handlePartitionRemoved(const char * /*devpath*/,
mVm->getBroadcaster()->sendBroadcast(ResponseCode::VolumeBadRemoval,
msg, false);

if (Volume::unmountVol(true, false)) {
if (Volume::unmountVol(true, false, false)) {
SLOGE("Failed to unmount volume on bad removal (%s)",
strerror(errno));
// XXX: At this point we're screwed for now
Expand Down Expand Up @@ -417,7 +458,7 @@ int DirectVolume::getDeviceNodes(dev_t *devs, int max) {
// If the disk has no partitions, try the disk itself
if (!mDiskNumParts) {
devs[0] = MKDEV(mDiskMajor, mDiskMinor);
SLOGD("Disc has only one partition.");
SLOGD("Disc has only one partition.");
return 1;
}

Expand Down
Loading