Merge "vold: fix 64 bit ioctl error"

This commit is contained in:
Jeff Sharkey 2015-12-03 16:56:13 +00:00 committed by Gerrit Code Review
commit 3e6c59dc16
11 changed files with 33 additions and 33 deletions

View file

@ -408,7 +408,7 @@ int CommandListener::AsecCmd::runCommand(SocketClient *cli,
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);
rc = vm->createAsec(argv[2], numSectors, argv[4], argv[5], atoi(argv[6]), isExternal);
} else if (!strcmp(argv[1], "resize")) {
@ -417,7 +417,7 @@ int CommandListener::AsecCmd::runCommand(SocketClient *cli,
cli->sendMsg(ResponseCode::CommandSyntaxError, "Usage: asec resize <container-id> <size_mb> <key>", false);
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]);
} else if (!strcmp(argv[1], "finalize")) {
dumpArgs(argc, argv, -1);

View file

@ -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,
unsigned int numSectors, char *ubuffer, size_t len) {
unsigned long numSectors, char *ubuffer, size_t len) {
char *buffer = (char *) malloc(DEVMAPPER_BUFFER_SIZE);
if (!buffer) {
SLOGE("Error allocating memory (%s)", strerror(errno));

View file

@ -25,7 +25,7 @@ class SocketClient;
class Devmapper {
public:
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 lookupActive(const char *name, char *buffer, size_t len);
static int dumpState(SocketClient *c);

View file

@ -253,7 +253,7 @@ int Loop::destroyByFile(const char * /*loopFile*/) {
return -1;
}
int Loop::createImageFile(const char *file, unsigned int numSectors) {
int Loop::createImageFile(const char *file, unsigned long numSectors) {
int fd;
if ((fd = creat(file, 0600)) < 0) {
@ -270,7 +270,7 @@ int Loop::createImageFile(const char *file, unsigned int numSectors) {
return 0;
}
int Loop::resizeImageFile(const char *file, unsigned int numSectors) {
int Loop::resizeImageFile(const char *file, unsigned long numSectors) {
int fd;
if ((fd = open(file, O_RDWR | O_CLOEXEC)) < 0) {
@ -278,7 +278,7 @@ int Loop::resizeImageFile(const char *file, unsigned int numSectors) {
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 (errno == ENOSYS || errno == ENOTSUP) {

4
Loop.h
View file

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

View file

@ -115,21 +115,21 @@ static int writeSuperBlock(const char* name, struct asec_superblock *sb, unsigne
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
// preventing costly operations or unexpected ENOSPC error.
// Ext4::format() uses default block size without clustering.
unsigned clusterSectors = 4096 / 512;
unsigned reservedSectors = (numSectors * 2)/100 + (numSectors % 50 > 0);
unsigned long clusterSectors = 4096 / 512;
unsigned long reservedSectors = (numSectors * 2)/100 + (numSectors % 50 > 0);
numSectors += reservedSectors > (4096 * clusterSectors) ? (4096 * clusterSectors) : reservedSectors;
return ROUND_UP_POWER_OF_2(numSectors, 3);
}
static int adjustSectorNumFAT(unsigned numSectors) {
static unsigned long adjustSectorNumFAT(unsigned long numSectors) {
/*
* Add some headroom
*/
unsigned fatSize = (((numSectors * 4) / 512) + 1) * 2;
unsigned long fatSize = (((numSectors * 4) / 512) + 1) * 2;
numSectors += fatSize + 2;
/*
* 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;
}
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 (Devmapper::lookupActive(idHash, buffer, len)) {
if (Devmapper::create(idHash, loopDevice, key, numImgSectors,
@ -767,7 +767,7 @@ int VolumeManager::getAsecFilesystemPath(const char *id, char *buffer, int maxle
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) {
struct asec_superblock 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;
if (numSectors < ((1024*1024)/512)) {
SLOGE("Invalid container size specified (%d sectors)", numSectors);
SLOGE("Invalid container size specified (%lu sectors)", numSectors);
errno = EINVAL;
return -1;
}
@ -824,7 +824,7 @@ int VolumeManager::createAsec(const char *id, unsigned int numSectors, const cha
return -1;
}
unsigned numImgSectors;
unsigned long numImgSectors;
if (usingExt4)
numImgSectors = adjustSectorNumExt4(numSectors);
else
@ -961,7 +961,7 @@ int VolumeManager::createAsec(const char *id, unsigned int numSectors, const cha
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 mountPoint[255];
bool cleanupDm = false;
@ -991,7 +991,7 @@ int VolumeManager::resizeAsec(const char *id, unsigned numSectors, const char *k
struct asec_superblock sb;
int fd;
unsigned int oldNumSec = 0;
unsigned long oldNumSec = 0;
if ((fd = open(asecFileName, O_RDONLY | O_CLOEXEC)) < 0) {
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;
unsigned numImgSectors;
unsigned long numImgSectors;
if (sb.c_opts & ASEC_SB_C_OPTS_EXT4)
numImgSectors = adjustSectorNumExt4(numSectors);
else
@ -1015,7 +1015,7 @@ int VolumeManager::resizeAsec(const char *id, unsigned numSectors, const char *k
/*
* 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) {
SLOGW("Size unchanged; ignoring resize request");
return 0;

View file

@ -143,9 +143,9 @@ public:
/* ASEC */
int findAsec(const char *id, char *asecPath = NULL, size_t asecPathLen = 0,
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);
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);
/**

View file

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

View file

@ -30,9 +30,9 @@ bool IsSupported();
status_t Check(const std::string& source, const std::string& target);
status_t Mount(const std::string& source, const std::string& target, bool ro,
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);
status_t Resize(const std::string& source, unsigned int numSectors);
status_t Resize(const std::string& source, unsigned long numSectors);
} // namespace ext4
} // namespace vold

View file

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

View file

@ -31,7 +31,7 @@ status_t Check(const std::string& source);
status_t Mount(const std::string& source, const std::string& target, bool ro,
bool remount, bool executable, int ownerUid, int ownerGid, int permMask,
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 vold