int VolumeManager::destroyAsec(const char *id, bool force) { char asecFileName[255]; char mountPoint[255]; snprintf(asecFileName, sizeof(asecFileName), "%s/%s.asec", Volume::SEC_ASECDIR, id); snprintf(mountPoint, sizeof(mountPoint), "%s/%s", Volume::ASECDIR, id); if (isMountpointMounted(mountPoint)) { if (mDebug) { SLOGD("Unmounting container before destroy"); } if (unmountAsec(id, force)) { SLOGE("Failed to unmount asec %s for destroy (%s)", id, strerror(errno)); return -1; } } if (unlink(asecFileName)) { SLOGE("Failed to unlink asec '%s' (%s)", asecFileName, strerror(errno)); return -1; } if (mDebug) { SLOGD("ASEC %s destroyed", id); } return 0; }
void DirectVolume::handlePartitionAdded(const char *devpath, NetlinkEvent *evt) { int major = atoi(evt->findParam("MAJOR")); int minor = atoi(evt->findParam("MINOR")); int part_num; const char *tmp = evt->findParam("PARTN"); if (tmp) { part_num = atoi(tmp); } else { SLOGW("Kernel block uevent missing 'PARTN'"); part_num = 1; } if (part_num > MAX_PARTITIONS || part_num < 1) { SLOGE("Invalid 'PARTN' value"); return; } if (part_num > mDiskNumParts) { mDiskNumParts = part_num; } if (major != mDiskMajor) { SLOGE("Partition '%s' has a different major than its disk!", devpath); return; } #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); } else { if ((mPartMinors[part_num - 1] == -1) && mPendingPartNum) mPendingPartNum--; mPartMinors[part_num -1] = minor; } // mPendingPartMap &= ~(1 << part_num); if (!mPendingPartNum) { #ifdef PARTITION_DEBUG SLOGD("Dv:partAdd: Got all partitions - ready to rock!"); #endif if (getState() != Volume::State_Formatting) { setState(Volume::State_Idle); if(mVm->getIpoState() == VolumeManager::State_Ipo_Start) { if (mRetryMount == true) { mRetryMount = false; mountVol(); } } } } else { #ifdef PARTITION_DEBUG SLOGD("Dv:partAdd: pending %d disk", mPendingPartNum); #endif } }
GLuint CanvasLayerShader::createProgram(const char* vSource, const char* fSource) { //Load and compile the vertex shader GLuint vertexShader = loadShader(GL_VERTEX_SHADER, vSource); if (!vertexShader) { SLOGD("Couldn't load the vertex shader"); return -1; } //Load and compile the fragment shader GLuint fragmentShader = loadShader(GL_FRAGMENT_SHADER, fSource); if (!fragmentShader) { SLOGD("couldn't load the pixel shader!"); return -1; } //Create the program GLuint program = glCreateProgram(); if (program) { SLOGD("++++++++++++++++++++++++++++++++++++++++++++++Creating shader for canvas"); glAttachShader(program, vertexShader); GLUtils::checkGlError("Attaching canvas vertex shader to program", false); glAttachShader(program, fragmentShader); GLUtils::checkGlError("Attaching canvas fragment shader to program", false); //Linking program glLinkProgram(program); GLint status = GL_FALSE; glGetProgramiv(program, GL_LINK_STATUS, &status); if (status != GL_TRUE) { GLint info = 0; glGetProgramiv(program, GL_INFO_LOG_LENGTH, &info); if (info) { char* buffer = (char*) malloc(info); if (buffer) { glGetProgramInfoLog(program, info, 0, buffer); SLOGD("Could not link canvas program: %s", buffer); free(buffer); } } glDeleteProgram(program); program = -1; } } return program; }
void DirectVolume::handlePartitionRemoved(const char *devpath, NetlinkEvent *evt) { int major = atoi(evt->findParam("MAJOR")); int minor = atoi(evt->findParam("MINOR")); char msg[255]; int state; SLOGD("Volume %s %s partition %d:%d removed\n", getLabel(), getMountpoint(), major, minor); /* * The framework doesn't need to get notified of * partition removal unless it's mounted. Otherwise * the removal notification will be sent on the Disk * itself */ state = getState(); if (state != Volume::State_Mounted && state != Volume::State_Shared) { return; } if ((dev_t) MKDEV(major, minor) == mCurrentlyMountedKdev) { /* * Yikes, our mounted partition is going away! */ bool providesAsec = (getFlags() & VOL_PROVIDES_ASEC) != 0; if (providesAsec && mVm->cleanupAsec(this, true)) { SLOGE("Failed to cleanup ASEC - unmount will probably fail!"); } snprintf(msg, sizeof(msg), "Volume %s %s bad removal (%d:%d)", getLabel(), getFuseMountpoint(), major, minor); mVm->getBroadcaster()->sendBroadcast(ResponseCode::VolumeBadRemoval, msg, false); if (Volume::unmountVol(true, 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"); } } else if (state == Volume::State_Shared) { /* removed during mass storage */ snprintf(msg, sizeof(msg), "Volume %s bad removal (%d:%d)", getLabel(), major, minor); mVm->getBroadcaster()->sendBroadcast(ResponseCode::VolumeBadRemoval, msg, false); if (mVm->unshareVolume(getLabel(), "ums")) { SLOGE("Failed to unshare volume on bad removal (%s)", strerror(errno)); } else { SLOGD("Crisis averted"); } } }
void NetlinkEvent::dump() { int i; SLOGD("NL action '%d'\n", mAction); SLOGD("NL subsystem '%s'\n", mSubsystem); for (i = 0; i < NL_PARAMS_MAX; i++) { if (!mParams[i]) break; SLOGD("NL param '%s'\n", mParams[i]); } }
void DirectVolume::handleDiskRemoved(const char *devpath, NetlinkEvent *evt) { int major = atoi(evt->findParam("MAJOR")); int minor = atoi(evt->findParam("MINOR")); char msg[255]; int state; if(0 == mDiskNumParts) { state = getState(); if (state != Volume::State_Mounted && state != Volume::State_Shared) { SLOGD("Status is %d, skip unmountVol()", getState()); } else if ((dev_t) MKDEV(major, minor) == mCurrentlyMountedKdev) { /* * Yikes, our mounted partition is going away! */ snprintf(msg, sizeof(msg), "Volume %s %s bad removal (%d:%d)", getLabel(), getMountpoint(), major, minor); mVm->getBroadcaster()->sendBroadcast(ResponseCode::VolumeBadRemoval, msg, false); mVm->waitForAfCleanupAsec(this); if (Volume::unmountVol(true, 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"); } } else if (state == Volume::State_Shared) { /* removed during mass storage */ snprintf(msg, sizeof(msg), "Volume %s bad removal (%d:%d)", getLabel(), major, minor); mVm->getBroadcaster()->sendBroadcast(ResponseCode::VolumeBadRemoval, msg, false); if (mVm->unshareVolume(getLabel(), "ums")) { SLOGE("Failed to unshare volume on bad removal (%s)", strerror(errno)); } else { SLOGD("Crisis averted"); } } } SLOGD("Volume %s %s disk %d:%d removed\n", getLabel(), getMountpoint(), major, minor); if(mVm->getIpoState() == VolumeManager::State_Ipo_Start) { snprintf(msg, sizeof(msg), "Volume %s %s disk removed (%d:%d)", getLabel(), getMountpoint(), major, minor); mVm->getBroadcaster()->sendBroadcast(ResponseCode::VolumeDiskRemoved, msg, false); } setState(Volume::State_NoMedia); }
void PhoneMachine::receiveUnsolicited(const Parcel& data) { int message = data.readInt32(); int ivalue = 0; String16 svalue; UnsolicitedMessages flags = UM_NONE; MAPTYPE *pmap = eventmap; SLOGD("<<< Unsolicited message=%s [%d]\n", rilMessageStr(message), message); while (pmap->flags != UM_NONE && message != pmap->message) pmap++; if (pmap->flags) flags = pmap->flags; switch (message) { case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED: ivalue = data.readInt32(); SLOGD(" RIL Radio state changed to %d\n", ivalue); if (ivalue == RADIO_STATE_OFF) { RILRequest * request = new RILRequest(NULL, -1, RIL_REQUEST_RADIO_POWER); request->writeInt(1); // One value request->writeInt(1); // Turn the radio on sendToRILD(request); } break; case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED: sendToRILD(new RILRequest(NULL, -1, RIL_REQUEST_GET_CURRENT_CALLS)); break; case RIL_UNSOL_NITZ_TIME_RECEIVED: svalue = data.readString16(); break; case RIL_UNSOL_SIGNAL_STRENGTH: ivalue = data.readInt32(); SLOGD(" Signal strength changed %d\n", ivalue); break; #if defined(SHORT_PLATFORM_VERSION) && (SHORT_PLATFORM_VERSION == 23) #else case RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED: break; case RIL_UNSOL_RIL_CONNECTED: { int n = data.readInt32(); // Number of integers ivalue = data.readInt32(); // RIL Version SLOGD(" RIL connected version=%d\n", ivalue); break; } #endif default: SLOGD("### Unhandled unsolicited message received from RIL: %d\n", message); break; } if (flags) mService->broadcastUnsolicited(flags, message, ivalue, svalue); }
int Volume::doUnmount(const char *path, bool force) { int retries = 3; int need_to_wait_count = 0; bool need_to_wait = false; bool isHotPlug = mVm->getHotPlug(); if (isHotPlug == true) { retries = 5; } SLOGD("doUnmount: %s retries = %d, isHotPlug=%d", path, retries, isHotPlug); if (mDebug) { SLOGD("Unmounting {%s}, force = %d", path, force); } while (retries--) { if (!umount(path) || errno == EINVAL || errno == ENOENT) { SLOGI("%s sucessfully unmounted", path); return 0; } int action = 0; if (force) { if (retries == 1) { action = 2; // SIGKILL } else if (retries == 2) { action = 1; // SIGHUP } } SLOGW("Failed to unmount %s (%s, retries %d, action %d)", path, strerror(errno), retries, action); Process::killProcessesWithOpenFiles(path, action); if (retries > 0) usleep(1000*1000); if(isHotPlug && (retries == 1)) usleep(1000*1000); } errno = EBUSY; SLOGE("Giving up on unmount %s (%s)", path, strerror(errno)); Process::FindProcessesWithOpenFiles(path); return -1; }
/* * Returns the correct major number for a bad partition. * Returns -1 if the partition is good. */ int DirectVolume::getMajorNumberForBadPartition(int part_num) { SLOGD("Checking for bad partition major number"); bool found = false; android::List<ValuePair>::iterator iterator = badPartitions.begin(); for(;iterator != badPartitions.end(); iterator++) { if((*iterator).part_num == part_num) { found = true; SLOGD("Found bad partition"); break; } } if(found == true) return (*iterator).major; else return -1; }
//============================================================================== std::shared_ptr<Socket> SocketImpl::Accept() const noexcept { auto ret = std::make_shared<SocketImpl>(m_protocol, m_spConfig); struct sockaddr_in socketAddress; auto *pSocketAddress = reinterpret_cast<sockaddr *>(&socketAddress); socklen_t socketAddressLength = sizeof(socketAddress); socket_type skt = ::accept(m_socketHandle, pSocketAddress, &socketAddressLength); if (skt == InvalidSocket()) { SLOGS(m_socketHandle, "Error accepting"); ret.reset(); } else { SLOGD( m_socketHandle, "Accepted new socket: %d (%d)", ret->GetSocketId(), skt); ret->m_socketHandle = skt; ret->m_clientIp = ntohl(socketAddress.sin_addr.s_addr); ret->m_clientPort = ntohs(socketAddress.sin_port); ret->m_aConnectedState.store(ConnectedState::Connected); } return ret; }
// Read a file into a buffer in a single gulp, for atomicity. // Null-terminate the buffer. // Retry until the buffer is big enough. static int read_file_as_string_atomically(const std::string &path, std::string &contents) { ssize_t buffer_size = INIT_BUFFER_SIZE; while (true) { int fd = open(path.c_str(), O_RDONLY | O_CLOEXEC); if (fd < 0) { SLOGE("Failed to open %s: %s", path.c_str(), strerror(errno)); return -1; } contents.resize(buffer_size); ssize_t read_size = read(fd, &contents[0], buffer_size); if (read_size < 0) { SLOGE("Failed to read from %s: %s", path.c_str(), strerror(errno)); close(fd); return -1; } close(fd); if (read_size < buffer_size) { contents.resize(read_size); return 0; } SLOGD("%s too big for buffer of size %zu", path.c_str(), buffer_size); buffer_size <<= 1; } }
//Code to load and compile a shader GLuint CanvasLayerShader::loadShader(GLenum shaderType, const char* shaderSource) { GLuint shader = glCreateShader(shaderType); if (shader) { glShaderSource(shader, 1, &shaderSource, 0); glCompileShader(shader); GLint compileStatus = 0; glGetShaderiv(shader, GL_COMPILE_STATUS, &compileStatus); if (!compileStatus) { GLint info = 0; glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &info); if (info) { char* buffer = (char*) malloc(info); if (buffer) { glGetShaderInfoLog(shader, info, 0, buffer); SLOGD("Canvas shader compilation failed: %s", buffer); free(buffer); } glDeleteShader(shader); shader = 0; } } } return shader; }
Bicr *Bicr::Instance() { if (!sInstance) sInstance = new Bicr(); SLOGD("[%s]: cd-rom state: %s", __func__, status_name[sInstance->mState]); return sInstance; }
void Volume::setState(int state) { char msg[255]; int oldState = mState; if (oldState == state) { SLOGW("Duplicate state (%d)\n", state); return; } if ((oldState == Volume::State_Pending) && (state != Volume::State_Idle)) { mRetryMount = false; } mState = state; SLOGD("Volume %s state changing %d (%s) -> %d (%s)", mLabel, oldState, stateToStr(oldState), mState, stateToStr(mState)); snprintf(msg, sizeof(msg), "Volume %s %s state changed from %d (%s) to %d (%s)", getLabel(), getMountpoint(), oldState, stateToStr(oldState), mState, stateToStr(mState)); mVm->getBroadcaster()->sendBroadcast(ResponseCode::VolumeStateChange, msg, false); }
int e4crypt_set_user_crypto_policies(const char *dir) { if (e4crypt_crypto_complete(DATA_MNT_POINT) != 0) { return 0; } SLOGD("e4crypt_set_user_crypto_policies"); std::unique_ptr<DIR, int(*)(DIR*)> dirp(opendir(dir), closedir); if (!dirp) { SLOGE("Unable to read directory %s, error %s\n", dir, strerror(errno)); return -1; } for (;;) { struct dirent *result = readdir(dirp.get()); if (!result) { // ext4enc:TODO check errno break; } if (result->d_type != DT_DIR || !is_numeric(result->d_name)) { continue; // skips user 0, which is a symlink } auto user_dir = std::string() + dir + "/" + result->d_name; // ext4enc:TODO don't hardcode /data if (e4crypt_set_user_policy("/data", result->d_name, user_dir.c_str(), false)) { // ext4enc:TODO If this function fails, stop the boot: we must // deliver on promised encryption. SLOGE("Unable to set policy on %s\n", user_dir.c_str()); } } return 0; }
void CommandListener::dumpArgs(int argc, char **argv, int argObscure) { char buffer[4096]; char *p = buffer; memset(buffer, 0, sizeof(buffer)); int i; for (i = 0; i < argc; i++) { unsigned int len = strlen(argv[i]) + 1; // Account for space if (i == argObscure) { len += 2; // Account for {} } if (((p - buffer) + len) < (sizeof(buffer)-1)) { if (i == argObscure) { *p++ = '{'; *p++ = '}'; *p++ = ' '; continue; } strcpy(p, argv[i]); p+= strlen(argv[i]); if (i != (argc -1)) { *p++ = ' '; } } } SLOGD("%s", buffer); LOG(INFO) << "dumpArgs : " << buffer; }
int VolumeManager::cleanupAsec(Volume *v, bool force) { // Continue for the primary storage (VOL_PROVIDES_ASEC) and for the // external apps volume (VOL_EXTERNAL_APPS) if app moving is enabled if ((v->getFlags() & VOL_PROVIDES_ASEC) == 0 && ((v->getFlags() & VOL_EXTERNAL_APPS) == 0 || !v->isExternalAppsEnabled())) { return 0; } int rc = 0; char asecFileName[255]; AsecIdCollection removeAsec; AsecIdCollection removeObb; for (AsecIdCollection::iterator it = mActiveContainers->begin(); it != mActiveContainers->end(); ++it) { ContainerData* cd = *it; if (cd->type == ASEC) { if (findAsec(cd->id, asecFileName, sizeof(asecFileName))) { SLOGE("Couldn't find ASEC %s; cleaning up", cd->id); removeAsec.push_back(cd); } else { SLOGD("Found ASEC at path %s", asecFileName); if (!strncmp(asecFileName, Volume::SEC_ASECDIR_EXT, strlen(Volume::SEC_ASECDIR_EXT))) { removeAsec.push_back(cd); } } } else if (cd->type == OBB) { if (v == getVolumeForFile(cd->id)) { removeObb.push_back(cd); } } else { SLOGE("Unknown container type %d!", cd->type); } } for (AsecIdCollection::iterator it = removeAsec.begin(); it != removeAsec.end(); ++it) { ContainerData *cd = *it; SLOGI("Unmounting ASEC %s (dependent on %s)", cd->id, v->getLabel()); if (unmountAsec(cd->id, force)) { SLOGE("Failed to unmount ASEC %s (%s)", cd->id, strerror(errno)); rc = -1; } } for (AsecIdCollection::iterator it = removeObb.begin(); it != removeObb.end(); ++it) { ContainerData *cd = *it; SLOGI("Unmounting OBB %s (dependent on %s)", cd->id, v->getLabel()); if (unmountObb(cd->id, force)) { SLOGE("Failed to unmount OBB %s (%s)", cd->id, strerror(errno)); rc = -1; } } return rc; }
int Volume::doUnmount(const char *path, bool force) { int retries = 10; if (mDebug) { SLOGD("Unmounting {%s}, force = %d", path, force); } while (retries--) { if (!umount(path) || errno == EINVAL || errno == ENOENT) { SLOGI("%s sucessfully unmounted", path); return 0; } int action = 0; if (force) { if (retries == 1) { action = 2; // SIGKILL } else if (retries == 2) { action = 1; // SIGHUP } } SLOGW("Failed to unmount %s (%s, retries %d, action %d)", path, strerror(errno), retries, action); Process::killProcessesWithOpenFiles(path, action); usleep(1000*1000); } errno = EBUSY; SLOGE("Giving up on unmount %s (%s)", path, strerror(errno)); return -1; }
int Volume::doMoveMount(const char *src, const char *dst, bool force) { unsigned int flags = MS_MOVE; int retries = 5; while(retries--) { if (!mount(src, dst, "", flags, NULL)) { if (mDebug) { SLOGD("Moved mount %s -> %s sucessfully", src, dst); } return 0; } else if (errno != EBUSY) { SLOGE("Failed to move mount %s -> %s (%s)", src, dst, strerror(errno)); return -1; } int action = 0; if (force) { if (retries == 1) { action = 2; // SIGKILL } else if (retries == 2) { action = 1; // SIGHUP } } SLOGW("Failed to move %s -> %s (%s, retries %d, action %d)", src, dst, strerror(errno), retries, action); Process::killProcessesWithOpenFiles(src, action); usleep(1000*250); } errno = EBUSY; SLOGE("Giving up on move %s -> %s (%s)", src, dst, strerror(errno)); return -1; }
int VolumeManager::finalizeAsec(const char *id) { char asecFileName[255]; char loopDevice[255]; char mountPoint[255]; snprintf(asecFileName, sizeof(asecFileName), "%s/%s.asec", Volume::SEC_ASECDIR, id); char idHash[33]; if (!asecHash(id, idHash, sizeof(idHash))) { SLOGE("Hash of '%s' failed (%s)", id, strerror(errno)); return -1; } if (Loop::lookupActive(idHash, loopDevice, sizeof(loopDevice))) { SLOGE("Unable to finalize %s (%s)", id, strerror(errno)); return -1; } snprintf(mountPoint, sizeof(mountPoint), "%s/%s", Volume::ASECDIR, id); // XXX: if (Fat::doMount(loopDevice, mountPoint, true, true, true, 0, 0, 0227, false)) { SLOGE("ASEC finalize mount failed (%s)", strerror(errno)); return -1; } if (mDebug) { SLOGD("ASEC %s finalized", id); } return 0; }
void DirectVolume::handlePartitionAdded(const char *devpath, NetlinkEvent *evt) { int major = atoi(evt->findParam("MAJOR")); int minor = atoi(evt->findParam("MINOR")); int part_num; const char *tmp = evt->findParam("PARTN"); if (tmp) { part_num = atoi(tmp); } else { SLOGW("Kernel block uevent missing 'PARTN'"); part_num = 1; } if (part_num > MAX_PARTITIONS || part_num < 1) { SLOGW("Invalid 'PARTN' value"); part_num = 1; } if (part_num > mDiskNumParts) { mDiskNumParts = part_num; } if (major != mDiskMajor) { SLOGE("Partition '%s' has a different major than its disk!", devpath); return; } #ifdef PARTITION_DEBUG SLOGD("Dv:partAdd: part_num = %d, minor = %d\n", part_num, minor); #endif mPartMinors[part_num -1] = minor; mPendingPartMap &= ~(1 << part_num); if (!mPendingPartMap) { #ifdef PARTITION_DEBUG SLOGD("Dv:partAdd: Got all partitions - ready to rock!"); #endif if (getState() != Volume::State_Formatting) { setState(Volume::State_Idle); } } else { #ifdef PARTITION_DEBUG SLOGD("Dv:partAdd: pending mask now = 0x%x", mPendingPartMap); #endif } }
Bicr::Bicr() { #ifdef MTK_BICR_SUPPORT mState = UNSHARED; #else mState = NOT_EXIST; #endif SLOGD("[%s]: cd-rom state: %s",__func__, status_name[mState]); }
int VolumeManager::finalizeAsec(const char *id) { char asecFileName[255]; char loopDevice[255]; char mountPoint[255]; if (!isLegalAsecId(id)) { SLOGE("finalizeAsec: Invalid asec id \"%s\"", id); errno = EINVAL; return -1; } if (findAsec(id, asecFileName, sizeof(asecFileName))) { SLOGE("Couldn't find ASEC %s", id); return -1; } char idHash[33]; if (!asecHash(id, idHash, sizeof(idHash))) { SLOGE("Hash of '%s' failed (%s)", id, strerror(errno)); return -1; } if (Loop::lookupActive(idHash, loopDevice, sizeof(loopDevice))) { SLOGE("Unable to finalize %s (%s)", id, strerror(errno)); return -1; } unsigned int nr_sec = 0; struct asec_superblock sb; if (Loop::lookupInfo(loopDevice, &sb, &nr_sec)) { return -1; } int written = snprintf(mountPoint, sizeof(mountPoint), "%s/%s", Volume::ASECDIR, id); if ((written < 0) || (size_t(written) >= sizeof(mountPoint))) { SLOGE("ASEC finalize failed: couldn't construct mountPoint"); return -1; } int result = 0; if (sb.c_opts & ASEC_SB_C_OPTS_EXT4) { result = Ext4::doMount(loopDevice, mountPoint, true, true, true, false); } else { result = Fat::doMount(loopDevice, mountPoint, true, true, true, 0, 0, 0227, false); } if (result) { SLOGE("ASEC finalize mount failed (%s)", strerror(errno)); return -1; } if (mDebug) { SLOGD("ASEC %s finalized", id); } return 0; }
void NetlinkEvent::dump() { int i; for (i = 0; i < NL_PARAMS_MAX; i++) { if (!mParams[i]) break; SLOGD("NL param '%s'\n", mParams[i]); } }
void DirectVolume::handleDiskAdded(const char *devpath, NetlinkEvent *evt) { mDiskMajor = atoi(evt->findParam("MAJOR")); mDiskMinor = atoi(evt->findParam("MINOR")); if(first_udisk_major==-1&&first_udisk_minor==-1){ SLOGD("first udisk add\n"); first_udisk_major = mDiskMajor; first_udisk_minor = mDiskMinor; }else{ SLOGD("not first udisk add\n"); return ; } const char *tmp = evt->findParam("NPARTS"); if (tmp) { mDiskNumParts = atoi(tmp); } else { SLOGW("Kernel block uevent missing 'NPARTS'"); mDiskNumParts = 1; } int partmask = 0; int i; for (i = 1; i <= mDiskNumParts; i++) { partmask |= (1 << i); } mPendingPartMap = partmask; if (mDiskNumParts == 0) { #ifdef PARTITION_DEBUG SLOGD("Dv::diskIns - No partitions - good to go son!"); #endif setState(Volume::State_Idle); } else { #ifdef PARTITION_DEBUG SLOGD("Dv::diskIns - waiting for %d partitions (mask 0x%x)", mDiskNumParts, mPendingPartMap); #endif setState(Volume::State_Pending); } }
void DirectVolume::handleDiskAdded(const char *devpath, NetlinkEvent *evt) { mDiskMajor = atoi(evt->findParam("MAJOR")); mDiskMinor = atoi(evt->findParam("MINOR")); const char *tmp = evt->findParam("NPARTS"); if (tmp) { mDiskNumParts = atoi(tmp); } else { SLOGW("Kernel block uevent missing 'NPARTS'"); mDiskNumParts = 1; } if (strcmp(devpath, "/devices/virtual/block/stheno") == 0) mDiskNumParts = 0; char msg[255]; int partmask = 0; int i; for (i = 1; i <= mDiskNumParts; i++) { partmask |= (1 << i); } mPendingPartMap = partmask; if (mDiskNumParts == 0) { #ifdef PARTITION_DEBUG SLOGD("Dv::diskIns - No partitions - good to go son!"); #endif setState(Volume::State_Idle); } else { #ifdef PARTITION_DEBUG SLOGD("Dv::diskIns - waiting for %d partitions (mask 0x%x)", mDiskNumParts, mPendingPartMap); #endif setState(Volume::State_Pending); } snprintf(msg, sizeof(msg), "Volume %s %s disk inserted (%d:%d)", getLabel(), getMountpoint(), mDiskMajor, mDiskMinor); mVm->getBroadcaster()->sendBroadcast(ResponseCode::VolumeDiskInserted, msg, false); }
void DirectVolume::handleDiskAdded(const char *devpath, NetlinkEvent *evt) { mDiskMajor = atoi(evt->findParam("MAJOR")); mDiskMinor = atoi(evt->findParam("MINOR")); const char *tmp = evt->findParam("NPARTS"); if (tmp) { mDiskNumParts = atoi(tmp); } else { SLOGW("Kernel block uevent missing 'NPARTS'"); mDiskNumParts = 1; } char msg[255]; /* int partmask = 0; int i; for (i = 1; i <= mDiskNumParts; i++) { partmask |= (1 << i); } */ mPendingPartNum = mDiskNumParts; for (int i = 0; i < MAX_PARTITIONS; i++) mPartMinors[i] = -1; if (mDiskNumParts == 0) { #ifdef PARTITION_DEBUG SLOGD("Dv::diskIns - No partitions - good to go son!"); #endif setState(Volume::State_Idle); } else { #ifdef PARTITION_DEBUG SLOGD("Dv::diskIns - waiting for %d partitions (pending partitions: %d)", mDiskNumParts, mPendingPartNum); #endif setState(Volume::State_Pending); } if(mVm->getIpoState() == VolumeManager::State_Ipo_Start) { snprintf(msg, sizeof(msg), "Volume %s %s disk inserted (%d:%d)", getLabel(), getMountpoint(), mDiskMajor, mDiskMinor); mVm->getBroadcaster()->sendBroadcast(ResponseCode::VolumeDiskInserted, msg, false); } }
unsigned int is_hw_disk_encryption(const char* encryption_mode) { int ret = 0; if(encryption_mode) { if (!strcmp(encryption_mode, "aes-xts")) { SLOGD("HW based disk encryption is enabled \n"); ret = 1; } } return ret; }
int VolumeManager::destroyAsec(const char *id, bool force) { char asecFileName[255]; char mountPoint[255]; if (!isLegalAsecId(id)) { SLOGE("destroyAsec: Invalid asec id \"%s\"", id); errno = EINVAL; return -1; } if (findAsec(id, asecFileName, sizeof(asecFileName))) { SLOGE("Couldn't find ASEC %s", id); return -1; } int written = snprintf(mountPoint, sizeof(mountPoint), "%s/%s", Volume::ASECDIR, id); if ((written < 0) || (size_t(written) >= sizeof(mountPoint))) { SLOGE("ASEC destroy failed for %s: couldn't construct mountpoint", id); return -1; } if (isMountpointMounted(mountPoint)) { if (mDebug) { SLOGD("Unmounting container before destroy"); } if (unmountAsec(id, force)) { SLOGE("Failed to unmount asec %s for destroy (%s)", id, strerror(errno)); return -1; } } if (unlink(asecFileName)) { SLOGE("Failed to unlink asec '%s' (%s)", asecFileName, strerror(errno)); return -1; } if (mDebug) { SLOGD("ASEC %s destroyed", id); } return 0; }
void DirectVolume::handleDiskRemoved(const char *devpath, NetlinkEvent *evt) { int major = atoi(evt->findParam("MAJOR")); int minor = atoi(evt->findParam("MINOR")); char msg[255]; SLOGD("Volume %s %s disk %d:%d removed\n", getLabel(), getMountpoint(), major, minor); snprintf(msg, sizeof(msg), "Volume %s %s disk removed (%d:%d)", getLabel(), getMountpoint(), major, minor); mVm->getBroadcaster()->sendBroadcast(ResponseCode::VolumeDiskRemoved, msg, false); setState(Volume::State_NoMedia); }