Merge "vold: fix 64 bit ioctl error" am: 3e6c59dc16 am: bf6acf44a9

am: a619c191cc

* commit 'a619c191cc06c08fb19e1bdd486a41da65f6c0af':
  vold: fix 64 bit ioctl error
gugelfrei
Jeff Sharkey 9 years ago committed by android-build-merger
commit 20826a1574

@ -406,7 +406,7 @@ int CommandListener::AsecCmd::runCommand(SocketClient *cli,
return 0; return 0;
} }
unsigned int numSectors = (atoi(argv[3]) * (1024 * 1024)) / 512; unsigned long numSectors = (atoi(argv[3]) * (1024 * 1024)) / 512;
const bool isExternal = (atoi(argv[7]) == 1); const bool isExternal = (atoi(argv[7]) == 1);
rc = vm->createAsec(argv[2], numSectors, argv[4], argv[5], atoi(argv[6]), isExternal); rc = vm->createAsec(argv[2], numSectors, argv[4], argv[5], atoi(argv[6]), isExternal);
} else if (!strcmp(argv[1], "resize")) { } else if (!strcmp(argv[1], "resize")) {
@ -415,7 +415,7 @@ int CommandListener::AsecCmd::runCommand(SocketClient *cli,
cli->sendMsg(ResponseCode::CommandSyntaxError, "Usage: asec resize <container-id> <size_mb> <key>", false); cli->sendMsg(ResponseCode::CommandSyntaxError, "Usage: asec resize <container-id> <size_mb> <key>", false);
return 0; return 0;
} }
unsigned int numSectors = (atoi(argv[3]) * (1024 * 1024)) / 512; unsigned long numSectors = (atoi(argv[3]) * (1024 * 1024)) / 512;
rc = vm->resizeAsec(argv[2], numSectors, argv[4]); rc = vm->resizeAsec(argv[2], numSectors, argv[4]);
} else if (!strcmp(argv[1], "finalize")) { } else if (!strcmp(argv[1], "finalize")) {
dumpArgs(argc, argv, -1); dumpArgs(argc, argv, -1);

@ -164,7 +164,7 @@ int Devmapper::lookupActive(const char *name, char *ubuffer, size_t len) {
} }
int Devmapper::create(const char *name, const char *loopFile, const char *key, int Devmapper::create(const char *name, const char *loopFile, const char *key,
unsigned int numSectors, char *ubuffer, size_t len) { unsigned long numSectors, char *ubuffer, size_t len) {
char *buffer = (char *) malloc(DEVMAPPER_BUFFER_SIZE); char *buffer = (char *) malloc(DEVMAPPER_BUFFER_SIZE);
if (!buffer) { if (!buffer) {
SLOGE("Error allocating memory (%s)", strerror(errno)); SLOGE("Error allocating memory (%s)", strerror(errno));

@ -25,7 +25,7 @@ class SocketClient;
class Devmapper { class Devmapper {
public: public:
static int create(const char *name, const char *loopFile, const char *key, static int create(const char *name, const char *loopFile, const char *key,
unsigned int numSectors, char *buffer, size_t len); unsigned long numSectors, char *buffer, size_t len);
static int destroy(const char *name); static int destroy(const char *name);
static int lookupActive(const char *name, char *buffer, size_t len); static int lookupActive(const char *name, char *buffer, size_t len);
static int dumpState(SocketClient *c); static int dumpState(SocketClient *c);

@ -253,7 +253,7 @@ int Loop::destroyByFile(const char * /*loopFile*/) {
return -1; return -1;
} }
int Loop::createImageFile(const char *file, unsigned int numSectors) { int Loop::createImageFile(const char *file, unsigned long numSectors) {
int fd; int fd;
if ((fd = creat(file, 0600)) < 0) { if ((fd = creat(file, 0600)) < 0) {
@ -270,7 +270,7 @@ int Loop::createImageFile(const char *file, unsigned int numSectors) {
return 0; return 0;
} }
int Loop::resizeImageFile(const char *file, unsigned int numSectors) { int Loop::resizeImageFile(const char *file, unsigned long numSectors) {
int fd; int fd;
if ((fd = open(file, O_RDWR | O_CLOEXEC)) < 0) { if ((fd = open(file, O_RDWR | O_CLOEXEC)) < 0) {
@ -278,7 +278,7 @@ int Loop::resizeImageFile(const char *file, unsigned int numSectors) {
return -1; return -1;
} }
SLOGD("Attempting to increase size of %s to %d sectors.", file, numSectors); SLOGD("Attempting to increase size of %s to %lu sectors.", file, numSectors);
if (fallocate(fd, 0, 0, numSectors * 512)) { if (fallocate(fd, 0, 0, numSectors * 512)) {
if (errno == ENOSYS || errno == ENOTSUP) { if (errno == ENOSYS || errno == ENOTSUP) {

@ -31,8 +31,8 @@ public:
static int create(const char *id, const char *loopFile, char *loopDeviceBuffer, size_t len); static int create(const char *id, const char *loopFile, char *loopDeviceBuffer, size_t len);
static int destroyByDevice(const char *loopDevice); static int destroyByDevice(const char *loopDevice);
static int destroyByFile(const char *loopFile); static int destroyByFile(const char *loopFile);
static int createImageFile(const char *file, unsigned int numSectors); static int createImageFile(const char *file, unsigned long numSectors);
static int resizeImageFile(const char *file, unsigned int numSectors); static int resizeImageFile(const char *file, unsigned long numSectors);
static int dumpState(SocketClient *c); static int dumpState(SocketClient *c);
}; };

@ -115,21 +115,21 @@ static int writeSuperBlock(const char* name, struct asec_superblock *sb, unsigne
return 0; return 0;
} }
static int adjustSectorNumExt4(unsigned numSectors) { static unsigned long adjustSectorNumExt4(unsigned long numSectors) {
// Ext4 started to reserve 2% or 4096 clusters, whichever is smaller for // Ext4 started to reserve 2% or 4096 clusters, whichever is smaller for
// preventing costly operations or unexpected ENOSPC error. // preventing costly operations or unexpected ENOSPC error.
// Ext4::format() uses default block size without clustering. // Ext4::format() uses default block size without clustering.
unsigned clusterSectors = 4096 / 512; unsigned long clusterSectors = 4096 / 512;
unsigned reservedSectors = (numSectors * 2)/100 + (numSectors % 50 > 0); unsigned long reservedSectors = (numSectors * 2)/100 + (numSectors % 50 > 0);
numSectors += reservedSectors > (4096 * clusterSectors) ? (4096 * clusterSectors) : reservedSectors; numSectors += reservedSectors > (4096 * clusterSectors) ? (4096 * clusterSectors) : reservedSectors;
return ROUND_UP_POWER_OF_2(numSectors, 3); return ROUND_UP_POWER_OF_2(numSectors, 3);
} }
static int adjustSectorNumFAT(unsigned numSectors) { static unsigned long adjustSectorNumFAT(unsigned long numSectors) {
/* /*
* Add some headroom * Add some headroom
*/ */
unsigned fatSize = (((numSectors * 4) / 512) + 1) * 2; unsigned long fatSize = (((numSectors * 4) / 512) + 1) * 2;
numSectors += fatSize + 2; numSectors += fatSize + 2;
/* /*
* FAT is aligned to 32 kb with 512b sectors. * FAT is aligned to 32 kb with 512b sectors.
@ -154,7 +154,7 @@ static int setupLoopDevice(char* buffer, size_t len, const char* asecFileName, c
return 0; return 0;
} }
static int setupDevMapperDevice(char* buffer, size_t len, const char* loopDevice, const char* asecFileName, const char* key, const char* idHash , int numImgSectors, bool* createdDMDevice, bool debug) { static int setupDevMapperDevice(char* buffer, size_t len, const char* loopDevice, const char* asecFileName, const char* key, const char* idHash , unsigned long numImgSectors, bool* createdDMDevice, bool debug) {
if (strcmp(key, "none")) { if (strcmp(key, "none")) {
if (Devmapper::lookupActive(idHash, buffer, len)) { if (Devmapper::lookupActive(idHash, buffer, len)) {
if (Devmapper::create(idHash, loopDevice, key, numImgSectors, if (Devmapper::create(idHash, loopDevice, key, numImgSectors,
@ -767,7 +767,7 @@ int VolumeManager::getAsecFilesystemPath(const char *id, char *buffer, int maxle
return 0; return 0;
} }
int VolumeManager::createAsec(const char *id, unsigned int numSectors, const char *fstype, int VolumeManager::createAsec(const char *id, unsigned long numSectors, const char *fstype,
const char *key, const int ownerUid, bool isExternal) { const char *key, const int ownerUid, bool isExternal) {
struct asec_superblock sb; struct asec_superblock sb;
memset(&sb, 0, sizeof(sb)); memset(&sb, 0, sizeof(sb));
@ -795,7 +795,7 @@ int VolumeManager::createAsec(const char *id, unsigned int numSectors, const cha
sb.ver = ASEC_SB_VER; sb.ver = ASEC_SB_VER;
if (numSectors < ((1024*1024)/512)) { if (numSectors < ((1024*1024)/512)) {
SLOGE("Invalid container size specified (%d sectors)", numSectors); SLOGE("Invalid container size specified (%lu sectors)", numSectors);
errno = EINVAL; errno = EINVAL;
return -1; return -1;
} }
@ -824,7 +824,7 @@ int VolumeManager::createAsec(const char *id, unsigned int numSectors, const cha
return -1; return -1;
} }
unsigned numImgSectors; unsigned long numImgSectors;
if (usingExt4) if (usingExt4)
numImgSectors = adjustSectorNumExt4(numSectors); numImgSectors = adjustSectorNumExt4(numSectors);
else else
@ -961,7 +961,7 @@ int VolumeManager::createAsec(const char *id, unsigned int numSectors, const cha
return 0; return 0;
} }
int VolumeManager::resizeAsec(const char *id, unsigned numSectors, const char *key) { int VolumeManager::resizeAsec(const char *id, unsigned long numSectors, const char *key) {
char asecFileName[255]; char asecFileName[255];
char mountPoint[255]; char mountPoint[255];
bool cleanupDm = false; bool cleanupDm = false;
@ -991,7 +991,7 @@ int VolumeManager::resizeAsec(const char *id, unsigned numSectors, const char *k
struct asec_superblock sb; struct asec_superblock sb;
int fd; int fd;
unsigned int oldNumSec = 0; unsigned long oldNumSec = 0;
if ((fd = open(asecFileName, O_RDONLY | O_CLOEXEC)) < 0) { if ((fd = open(asecFileName, O_RDONLY | O_CLOEXEC)) < 0) {
SLOGE("Failed to open ASEC file (%s)", strerror(errno)); SLOGE("Failed to open ASEC file (%s)", strerror(errno));
@ -1007,7 +1007,7 @@ int VolumeManager::resizeAsec(const char *id, unsigned numSectors, const char *k
oldNumSec = info.st_size / 512; oldNumSec = info.st_size / 512;
unsigned numImgSectors; unsigned long numImgSectors;
if (sb.c_opts & ASEC_SB_C_OPTS_EXT4) if (sb.c_opts & ASEC_SB_C_OPTS_EXT4)
numImgSectors = adjustSectorNumExt4(numSectors); numImgSectors = adjustSectorNumExt4(numSectors);
else else
@ -1015,7 +1015,7 @@ 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 %lu sectors to %lu sectors", oldNumSec, numImgSectors + 1);
if (oldNumSec == numImgSectors + 1) { if (oldNumSec == numImgSectors + 1) {
SLOGW("Size unchanged; ignoring resize request"); SLOGW("Size unchanged; ignoring resize request");
return 0; return 0;

@ -143,9 +143,9 @@ public:
/* ASEC */ /* ASEC */
int findAsec(const char *id, char *asecPath = NULL, size_t asecPathLen = 0, int findAsec(const char *id, char *asecPath = NULL, size_t asecPathLen = 0,
const char **directory = NULL) const; const char **directory = NULL) const;
int createAsec(const char *id, unsigned numSectors, const char *fstype, int createAsec(const char *id, unsigned long numSectors, const char *fstype,
const char *key, const int ownerUid, bool isExternal); const char *key, const int ownerUid, bool isExternal);
int resizeAsec(const char *id, unsigned numSectors, const char *key); int resizeAsec(const char *id, unsigned long numSectors, const char *key);
int finalizeAsec(const char *id); int finalizeAsec(const char *id);
/** /**

@ -151,17 +151,17 @@ status_t Mount(const std::string& source, const std::string& target, bool ro,
return rc; return rc;
} }
status_t Resize(const std::string& source, unsigned int numSectors) { status_t Resize(const std::string& source, unsigned long numSectors) {
std::vector<std::string> cmd; std::vector<std::string> cmd;
cmd.push_back(kResizefsPath); cmd.push_back(kResizefsPath);
cmd.push_back("-f"); cmd.push_back("-f");
cmd.push_back(source); cmd.push_back(source);
cmd.push_back(StringPrintf("%u", numSectors)); cmd.push_back(StringPrintf("%lu", numSectors));
return ForkExecvp(cmd); return ForkExecvp(cmd);
} }
status_t Format(const std::string& source, unsigned int numSectors, status_t Format(const std::string& source, unsigned long numSectors,
const std::string& target) { const std::string& target) {
std::vector<std::string> cmd; std::vector<std::string> cmd;
cmd.push_back(kMkfsPath); cmd.push_back(kMkfsPath);
@ -172,7 +172,7 @@ status_t Format(const std::string& source, unsigned int numSectors,
if (numSectors) { if (numSectors) {
cmd.push_back("-l"); cmd.push_back("-l");
cmd.push_back(StringPrintf("%u", numSectors * 512)); cmd.push_back(StringPrintf("%lu", numSectors * 512));
} }
// Always generate a real UUID // Always generate a real UUID

@ -30,9 +30,9 @@ bool IsSupported();
status_t Check(const std::string& source, const std::string& target); status_t Check(const std::string& source, const std::string& target);
status_t Mount(const std::string& source, const std::string& target, bool ro, status_t Mount(const std::string& source, const std::string& target, bool ro,
bool remount, bool executable); bool remount, bool executable);
status_t Format(const std::string& source, unsigned int numSectors, status_t Format(const std::string& source, unsigned long numSectors,
const std::string& target); const std::string& target);
status_t Resize(const std::string& source, unsigned int numSectors); status_t Resize(const std::string& source, unsigned long numSectors);
} // namespace ext4 } // namespace ext4
} // namespace vold } // namespace vold

@ -164,7 +164,7 @@ status_t Mount(const std::string& source, const std::string& target, bool ro,
return rc; return rc;
} }
status_t Format(const std::string& source, unsigned int numSectors) { status_t Format(const std::string& source, unsigned long numSectors) {
std::vector<std::string> cmd; std::vector<std::string> cmd;
cmd.push_back(kMkfsPath); cmd.push_back(kMkfsPath);
cmd.push_back("-F"); cmd.push_back("-F");
@ -177,7 +177,7 @@ status_t Format(const std::string& source, unsigned int numSectors) {
if (numSectors) { if (numSectors) {
cmd.push_back("-s"); cmd.push_back("-s");
cmd.push_back(StringPrintf("%u", numSectors)); cmd.push_back(StringPrintf("%lu", numSectors));
} }
cmd.push_back(source); cmd.push_back(source);

@ -31,7 +31,7 @@ status_t Check(const std::string& source);
status_t Mount(const std::string& source, const std::string& target, bool ro, status_t Mount(const std::string& source, const std::string& target, bool ro,
bool remount, bool executable, int ownerUid, int ownerGid, int permMask, bool remount, bool executable, int ownerUid, int ownerGid, int permMask,
bool createLost); bool createLost);
status_t Format(const std::string& source, unsigned int numSectors); status_t Format(const std::string& source, unsigned long numSectors);
} // namespace vfat } // namespace vfat
} // namespace vold } // namespace vold

Loading…
Cancel
Save