Fix all mis-used types about large file support 41/130141/5 accepted/tizen/unified/20170522.190731 submit/tizen/20170522.121243 tizen_4.0.m1_release
authorSungbae Yoo <sungbae.yoo@samsung.com>
Fri, 19 May 2017 08:12:24 +0000 (17:12 +0900)
committerSungbae Yoo <sungbae.yoo@samsung.com>
Fri, 19 May 2017 09:32:28 +0000 (18:32 +0900)
Signed-off-by: Sungbae Yoo <sungbae.yoo@samsung.com>
Signed-off-by: s414kim <s414.kim@samsung.com>
Signed-off-by: yeji01kim <yeji01.kim@samsung.com>
Change-Id: I8fb13daeb621b22ce3e394ceab3f0b8b825faaaa

CMakeLists.txt
server/CMakeLists.txt
server/block-device.cpp
server/block-device.h
server/engine/encryption/dmcrypt-engine.cpp
server/engine/encryption/ecryptfs-engine.cpp
server/engine/encryption/ext4-engine.cpp [changed mode: 0644->0755]
server/engine/erase/mmc-engine.cpp

index 30d02bf..6cad5c9 100755 (executable)
@@ -39,7 +39,11 @@ else()
        SET(CXX_STD "c++11")
 endif()
 
-SET(COMPILE_BASE_FLAGS         "-g -fPIC -Werror -Wall -Wl,--as-needed -Wl,--no-whole-archive")
+EXECUTE_PROCESS(COMMAND getconf LFS_CFLAGS OUTPUT_VARIABLE LFS_CFLAGS OUTPUT_STRIP_TRAILING_WHITESPACE)
+EXECUTE_PROCESS(COMMAND getconf LFS_LDFLAGS OUTPUT_VARIABLE LFS_LDFLAGS OUTPUT_STRIP_TRAILING_WHITESPACE)
+EXECUTE_PROCESS(COMMAND getconf LFS_LIBS OUTPUT_VARIABLE LFS_LIBS OUTPUT_STRIP_TRAILING_WHITESPACE)
+
+SET(COMPILE_BASE_FLAGS         "-g -fPIC -Werror -Wall -Wl,--as-needed -Wl,--no-whole-archive ${LFS_CFLAGS}")
 SET(CMAKE_C_FLAGS_PROFILING    "${COMPILE_BASE_FLAGS} -O0 -pg")
 SET(CMAKE_CXX_FLAGS_PROFILING  "${COMPILE_BASE_FLAGS} -O0 -pg -std=${CXX_STD} -fno-rtti")
 SET(CMAKE_C_FLAGS_DEBUG                "${COMPILE_BASE_FLAGS} -O0 -ggdb")
index c07f9e1..72a882b 100644 (file)
@@ -54,7 +54,7 @@ PKG_CHECK_MODULES(SERVER_DEPS REQUIRED ${DEPENDENCY})
 
 INCLUDE_DIRECTORIES(SYSTEM ${SERVER_DEPS_INCLUDE_DIRS} ${ODE_SERVER} ${PROJECT_SOURCE_DIR})
 
-TARGET_LINK_LIBRARIES(${SERVER_NAME} ${SERVER_DEPS_LIBRARIES} pthread)
+TARGET_LINK_LIBRARIES(${SERVER_NAME} ${SERVER_DEPS_LIBRARIES} ${LFS_LDFLAGS} ${LFS_LIBS} pthread)
 
 SET_TARGET_PROPERTIES(${SERVER_NAME} PROPERTIES COMPILE_FLAGS "-fPIE")
 SET_TARGET_PROPERTIES(${SERVER_NAME} PROPERTIES LINK_FLAGS "-pie")
index 89d3e20..e04de25 100644 (file)
@@ -80,7 +80,7 @@ void BlockDevice::close(int descriptor)
        return;
 }
 
-int BlockDevice::discard(const Block &block)
+int BlockDevice::discard(off_t offset, off_t length)
 {
        int devFd = 0;
        unsigned long long range[2];
@@ -90,8 +90,8 @@ int BlockDevice::discard(const Block &block)
                return -1;
        }
 
-       range[0] = block.physicalOffset;
-       range[1] = block.length;
+       range[0] = (unsigned long long)offset;
+       range[1] = (unsigned long long)length;
 
        int ret = ::ioctl(devFd, BLKDISCARD, &range);
 
@@ -100,7 +100,7 @@ int BlockDevice::discard(const Block &block)
        return ret;
 }
 
-int BlockDevice::secDiscard(const Block &block)
+int BlockDevice::secDiscard(off_t offset, off_t length)
 {
        int devFd = 0;
        unsigned long long range[2];
@@ -110,8 +110,8 @@ int BlockDevice::secDiscard(const Block &block)
                return -1;
        }
 
-       range[0] = block.physicalOffset;
-       range[1] = block.length;
+       range[0] = (unsigned long long)offset;
+       range[1] = (unsigned long long)length;
 
        int ret = ::ioctl(devFd, BLKSECDISCARD, &range);
 
@@ -128,7 +128,7 @@ const std::string &BlockDevice::getName() const
        return name;
 }
 
-int BlockDevice::getSize()
+blksize_t BlockDevice::getBlockSize()
 {
        if (name == "") {
                throw runtime::Exception("Cannot get device name");
index 095da51..13e6546 100644 (file)
 
 namespace ode {
 
-class Block {
-public:
-       template <typename OffsetType, typename LengthType>
-       Block(OffsetType offset, LengthType len) : physicalOffset(offset), length(len) {}
-       ~Block() {}
-
-       unsigned long long physicalOffset;
-       unsigned long long length;
-};
-
 class BlockDevice final {
 public:
        typedef std::unordered_map<std::string, std::string> DeviceList;
@@ -58,11 +48,11 @@ public:
        int open(int flags);
        void close(int descriptor);
 
-       int discard(const Block &block);
-       int secDiscard(const Block &block);
+       int discard(off_t offset, off_t length);
+       int secDiscard(off_t offset, off_t length);
 
        const std::string &getName() const;
-       int getSize();
+       blksize_t getBlockSize();
 
 private:
        void createDeviceList();
@@ -70,7 +60,7 @@ private:
 
 private:
        std::string name;
-       int blockSize;
+       blksize_t blockSize;
 
        DeviceList deviceList;
 };
index 9086669..7c4d16d 100644 (file)
@@ -44,18 +44,18 @@ namespace ode {
 
 namespace {
 
-size_t getFileSystemSize(const std::string &src)
+blkcnt_t getBlockCount(const std::string &src)
 {
        int fd = open(src.c_str(), O_RDONLY);
        if (fd < 0)
                return 0;
 
-       size_t size = 0;
+       unsigned long long size = 0;
        if ((ioctl(fd, BLKGETSIZE, &size)) == -1)
                size = 0;
        close(fd);
 
-       return size;
+       return (blkcnt_t)size;
 }
 
 const std::string convertToHex(const DMCryptEngine::data &binary)
@@ -86,7 +86,7 @@ void initDMIoctl(char *buf, size_t size, const std::string &name, unsigned flags
 
 const std::string createCryptoBlkDev(const std::string &realBlkDev, const std::string &mountName, const DMCryptEngine::data &key, std::string cryptoTypeName)
 {
-       size_t fileSystemSize = getFileSystemSize(realBlkDev);
+       auto blockCount = getBlockCount(realBlkDev);
        std::string cryptoBlkDev;
        int fd = -1;
 
@@ -138,7 +138,7 @@ const std::string createCryptoBlkDev(const std::string &realBlkDev, const std::s
        dmIo->target_count = 1;
        dmTs->status = 0;
        dmTs->sector_start = 0;
-       dmTs->length = fileSystemSize;
+       dmTs->length = blockCount;
        ::memset(dmTs->target_type, 0, sizeof(dmTs->target_type));
        ::strncpy(dmTs->target_type, "crypt", sizeof(dmTs->target_type) - 1);
 
@@ -201,19 +201,19 @@ ode::DMCryptEngine::data sanitizeKey(const ode::DMCryptEngine::data &key)
 }
 
 void copyInPlace(const std::string &source,    const std::string &destination,
-                                       const std::function<bool(unsigned int)> &isTarget,
+                                       const std::function<bool(blkcnt_t)> &isTarget,
                                        const std::function<void(int, int)> &addProgress)
 {
        Ext4Tool ext4tool(source);
-       const size_t srcBlockSize = ext4tool.getBlockSize();
-       const size_t srcTotalBlockCount = ext4tool.getTotalBlockCount();
+       const blksize_t srcBlockSize = ext4tool.getBlockSize();
+       const blkcnt_t srcTotalBlockCount = ext4tool.getTotalBlockCount();
        char buf[srcBlockSize];
 
        runtime::File src(source, O_RDONLY);
        runtime::File dst(destination, O_WRONLY);
 
-       for (size_t n = 0, pos = 0; n < srcTotalBlockCount;
-                       n++, pos += srcBlockSize) {
+       off_t pos = 0;
+       for (blkcnt_t n = 0; n < srcTotalBlockCount; n++, pos += srcBlockSize) {
                if (!isTarget(n)) {
                        continue;
                }
@@ -275,7 +275,7 @@ void DMCryptEngine::encrypt(const DMCryptEngine::data &key, unsigned int options
        // should be encrypted here.
        auto cryptoBlkDev = createCryptoBlkDev(source, DM_DEFAULT_LABEL_NAME, sanitizeKey(key), DM_DEFAULT_CRYPTO_NAME);
 
-       std::function<bool(unsigned int)> isTarget;
+       std::function<bool(blkcnt_t)> isTarget;
        if (!(options & OPTION_INCLUDE_UNUSED_REGION)) {
                INFO("FastEncryption: Disabled");
                isTarget = std::bind(&Ext4Tool::isUsedBlock, &ext4Source, _1);
@@ -308,7 +308,7 @@ void DMCryptEngine::decrypt(const DMCryptEngine::data &key, unsigned int options
        Ext4Tool ext4CryptoBlkDev(cryptoBlkDev);
        ext4CryptoBlkDev.forceCleanUp();
 
-       std::function<bool(unsigned int)> isTarget;
+       std::function<bool(blkcnt_t)> isTarget;
        if (!(options & OPTION_INCLUDE_UNUSED_REGION)) {
                INFO("FastEncryption: Disabled");
                isTarget = std::bind(&Ext4Tool::isUsedBlock, &ext4CryptoBlkDev, _1);
index b78e614..51fb925 100644 (file)
@@ -133,14 +133,14 @@ namespace ode {
 
 namespace {
 
-unsigned long long getAvailableSpace(const std::string& mountPoint)
+off_t getAvailableSpace(const std::string& mountPoint)
 {
        struct statfs statbuf;
        if (::statfs(mountPoint.c_str(), &statbuf)) {
                throw runtime::Exception("Failed to access " + mountPoint);
        }
 
-       return (unsigned long long)statbuf.f_bfree * statbuf.f_bsize;
+       return statbuf.f_bfree * statbuf.f_bsize;
 }
 
 bool wasEncrypted(const std::string &path)
@@ -167,9 +167,9 @@ bool wasEncrypted(const std::string &path)
 #endif
 }
 
-unsigned long long getEncryptedSize(const runtime::File &file) {
-       unsigned long long originalSize = file.size();
-       unsigned long long result = 0;
+off_t getEncryptedSize(const runtime::File &file) {
+       off_t originalSize = file.size();
+       off_t result = 0;
 
        if (originalSize % 4096) {
                originalSize = (1 + originalSize / 4096) * 4096;
@@ -187,7 +187,7 @@ unsigned long long getEncryptedSize(const runtime::File &file) {
 
        //TODO : block size have to not hard-coded.
        //       If there is a better way, the followings have to be changed.
-       unsigned int blockSize = 4096;
+       blksize_t blockSize = 4096;
        if (result % blockSize) {
                result = (1 + result / blockSize) * blockSize;
        }
@@ -195,9 +195,9 @@ unsigned long long getEncryptedSize(const runtime::File &file) {
        return result;
 }
 
-unsigned long long getDecryptedSize(const runtime::File &file) {
-       unsigned long long originalSize = file.size();
-       unsigned long long result = originalSize;
+off_t getDecryptedSize(const runtime::File &file) {
+       off_t originalSize = file.size();
+       off_t result = originalSize;
 
        if (wasEncrypted(file.getPath())) {
                if (originalSize > 2 * 4096) {
@@ -209,7 +209,7 @@ unsigned long long getDecryptedSize(const runtime::File &file) {
 
        //TODO : block size have to not hard-coded.
        //       If there is a better way, the followings have to be changed.
-       unsigned int blockSize = 4096;
+       blksize_t blockSize = 4096;
        if (result % blockSize) {
                result = (1 + result / blockSize) * blockSize;
        }
@@ -218,9 +218,9 @@ unsigned long long getDecryptedSize(const runtime::File &file) {
 }
 
 bool isEnoughToCopyInPlace(const std::string& path,
-       const std::function<unsigned long long(const runtime::File&)> getSizeFunc)
+       const std::function<off_t(const runtime::File&)> getSizeFunc)
 {
-       unsigned long long availableSpace = getAvailableSpace(path);
+       off_t availableSpace = getAvailableSpace(path);
 
        std::function<bool(const std::string &path)> check;
        check = [&check, &getSizeFunc, availableSpace](const std::string &path) {
@@ -245,7 +245,7 @@ bool isEnoughToCopyInPlace(const std::string& path,
 void copyInPlace(const std::string& source, const std::string& destination,
                                        const std::string& temp,
                                        const std::function<bool(const std::string&)> &isTarget,
-                                       const std::function<void(unsigned long long)> &addProgress)
+                                       const std::function<void(off_t)> &addProgress)
 {
        for (runtime::DirectoryIterator iter(source), end;
                        iter != end; ++iter) {
@@ -383,7 +383,7 @@ void EcryptfsEngine::encrypt(const data &key, unsigned int options)
        }
 
        try {
-               unsigned long long totalSize = getAvailableSpace(source), current;
+               off_t totalSize = getAvailableSpace(source), current;
            runtime::File tempDir(destination + "/" ENCRYPTION_TMP_DIR);
 
                if (tempDir.exists()) {
@@ -396,7 +396,7 @@ void EcryptfsEngine::encrypt(const data &key, unsigned int options)
                                        [](const std::string &file) {
                                                return true;
                                        },
-                                       [&current, &totalSize, this](unsigned long long size) {
+                                       [&current, &totalSize, this](off_t size) {
                                                current += size;
                                                this->progress.update(current * 100 / totalSize);
                                        });
@@ -424,7 +424,7 @@ void EcryptfsEngine::decrypt(const data &key, unsigned int options)
        progress.update(0);
 
        try {
-               unsigned long long totalSize = getAvailableSpace(source), current;
+               off_t totalSize = getAvailableSpace(source), current;
            runtime::File tempDir(source + "/" ENCRYPTION_TMP_DIR);
                runtime::File tempMountpoint(tempDir.getPath() + "/mount");
 
@@ -438,7 +438,7 @@ void EcryptfsEngine::decrypt(const data &key, unsigned int options)
 
                copyInPlace(tempMountpoint.getPath(), source,
                                        tempDir.getPath(), wasEncrypted,
-                                       [&current, &totalSize, this](unsigned long long size) {
+                                       [&current, &totalSize, this](off_t size) {
                                                current += size;
                                                this->progress.update(current * 100 / totalSize);
                                        });
old mode 100644 (file)
new mode 100755 (executable)
index d0a0cb2..a48cb2f
@@ -188,24 +188,24 @@ bool hasPolicy(const std::string& dir)
        return true;
 }
 
-unsigned long long getUsedSpace(const std::string& mountPoint)
+off_t getUsedSpace(const std::string& mountPoint)
 {
        struct statfs statbuf;
        if (::statfs(mountPoint.c_str(), &statbuf)) {
                throw runtime::Exception("Failed to access " + mountPoint);
        }
 
-       return (unsigned long long)(statbuf.f_blocks - statbuf.f_bfree) * statbuf.f_bsize;
+       return (off_t)(statbuf.f_blocks - statbuf.f_bfree) * statbuf.f_bsize;
 }
 
-unsigned long long getAvailableSpace(const std::string& mountPoint)
+off_t getAvailableSpace(const std::string& mountPoint)
 {
        struct statfs statbuf;
        if (::statfs(mountPoint.c_str(), &statbuf)) {
                throw runtime::Exception("Failed to access " + mountPoint);
        }
 
-       return (unsigned long long)statbuf.f_bfree * statbuf.f_bsize;
+       return (off_t)statbuf.f_bfree * statbuf.f_bsize;
 }
 
 static void copyDac(const std::string& srcPath, const std::string& destPath)
@@ -243,7 +243,7 @@ static void copyMac(const std::string& srcPath, const std::string& destPath)
 
 bool isEnoughToCopyInPlace(const std::string& path)
 {
-       unsigned long long availableSpace = getAvailableSpace(path);
+       off_t availableSpace = getAvailableSpace(path);
 
        std::function<bool(const std::string &path)> check;
        check = [&check, availableSpace](const std::string &path) {
@@ -264,7 +264,7 @@ bool isEnoughToCopyInPlace(const std::string& path)
 }
 
 void copyInPlace(const std::string& source, const std::string& destination,
-                                       const std::function<void(unsigned long long)> &addProgress)
+                                       const std::function<void(off_t)> &addProgress)
 {
        for (runtime::DirectoryIterator iter(source), end; iter != end; ++iter) {
                if (iter->getPath() == destination) {
@@ -350,9 +350,9 @@ void Ext4Engine::encrypt(const Ext4Engine::data& key, unsigned int options)
        encrypted.makeDirectory();
        setPolicy(encrypted.getPath(), sanitizedKey);
 
-       unsigned long long totalSize = getUsedSpace(source), current = 0;
+       off_t totalSize = getUsedSpace(source), current = 0;
        copyInPlace(destination, encrypted.getPath(),
-                               [&current, &totalSize, this](unsigned long long size) {
+                               [&current, &totalSize, this](off_t size) {
                                        current += size;
                                        this->progress.update(current, totalSize, 1);
                                });
@@ -378,9 +378,9 @@ void Ext4Engine::decrypt(const Ext4Engine::data& key, unsigned int options)
 
        runtime::File encrypted(destination + "/" ENCRYPTION_DIR);
 
-       unsigned long long totalSize = getUsedSpace(source), current = 0;
+       off_t totalSize = getUsedSpace(source), current = 0;
        copyInPlace(encrypted.getPath(), destination,
-                               [&current, &totalSize, this](unsigned long long size) {
+                               [&current, &totalSize, this](off_t size) {
                                        current += size;
                                        this->progress.update(current, totalSize, 1);
                                });
index f4c869e..470f18f 100644 (file)
@@ -72,16 +72,16 @@ MMCEraseEngine::~MMCEraseEngine()
 int MMCEraseEngine::cleanDevice(const std::string &path)
 {
        BlockDevice blockDevice(path);
-       unsigned totalBlock, blockSize;
-
+       blkcnt_t totalBlock;
+       blksize_t blockSize;
        Ext4Tool ext4Tool(blockDevice.getName());
-       totalBlock = ext4Tool.getTotalBlockCount();
-       blockSize = (unsigned int)blockDevice.getSize();
 
-       for (unsigned int i = 0; i < totalBlock; i++) {
+       totalBlock = (blkcnt_t)ext4Tool.getTotalBlockCount();
+       blockSize = blockDevice.getBlockSize();
+
+       for (blkcnt_t i = 0; i < totalBlock; i++) {
                if (!ext4Tool.isUsedBlock(i)) {
-                       Block block(i * blockSize, blockSize);
-                       blockDevice.discard(block);
+                       blockDevice.discard(i*blockSize, blockSize);
                }
                progressBar.update(i, totalBlock, 1);
        }
@@ -92,6 +92,9 @@ int MMCEraseEngine::cleanDevice(const std::string &path)
 
 int MMCEraseEngine::eraseDevice(const std::string &path)
 {
+       blkcnt_t totalBlock;
+       blksize_t blockSize;
+
        runtime::File file(path, O_WRONLY);
        if (!file.exists()) {
                throw runtime::Exception("Target doesn't exist");
@@ -100,12 +103,11 @@ int MMCEraseEngine::eraseDevice(const std::string &path)
        BlockDevice blockDevice(path);
        Ext4Tool ext4Tool(blockDevice.getName());
 
-       unsigned int totalBlock = ext4Tool.getTotalBlockCount();
-       unsigned int blockSize = (unsigned int)blockDevice.getSize();
+       totalBlock = ext4Tool.getTotalBlockCount();
+       blockSize = blockDevice.getBlockSize();
 
-       for (unsigned int i = 0; i < totalBlock; i++) {
-               Block block(i * blockSize, blockSize);
-               blockDevice.discard(block);
+       for (blkcnt_t i = 0; i < totalBlock; i++) {
+               blockDevice.discard(i * blockSize, blockSize);
                progressBar.update(i, totalBlock, 1);
        }
 
@@ -116,7 +118,7 @@ int MMCEraseEngine::eraseDevice(const std::string &path)
 int MMCEraseEngine::eraseFile(const std::string &path)
 {
        int ret = 0, fd = 0;
-       int extentBlockCount = 0;
+       blkcnt_t extentBlockCount = 0;
        char buf[4096] = "";
        struct fiemap *fmap = (struct fiemap *)buf;
        struct fiemap_extent *fm_ext = NULL;
@@ -145,9 +147,8 @@ int MMCEraseEngine::eraseFile(const std::string &path)
        extentBlockCount = (int)fmap->fm_mapped_extents;
 
        BlockDevice blockDevice(path);
-       for (int i = 0; i < extentBlockCount; i++) {
-               Block block(fm_ext[i].fe_physical, fm_ext[i].fe_length);
-               ret = blockDevice.secDiscard(block);
+       for (blkcnt_t i = 0; i < extentBlockCount; i++) {
+               ret = blockDevice.secDiscard(fm_ext[i].fe_physical, fm_ext[i].fe_length);
                if (ret < 0) {
                        throw runtime::Exception("failed to erase the device");
                }