From 483e9f45b71458b84ccbbaf658449b58f029a63b Mon Sep 17 00:00:00 2001 From: Ethan Yonker Date: Mon, 11 Jan 2016 22:21:18 -0600 Subject: Improve sdcard partitioning process -Improve code for partitioning sdcards -Allow user to select a device for partitioning (must be removable) -Use sgdisk to partition sdcards -Set default sizes for ext and swap to 0 -Change increments for ext to 256MB and swap to 64MB Note: sgdisk is included in 6.0. I have included a static prebuilt sgdisk for trees that do not have sgdisk, however the prebuilt sgdisk is a decent bit larger than the old parted binary. The old parted binary is quite old at this point and we only have it for armv7a. sgdisk should be maintained by AOSP and can be built from source so it should work across architectures. Change-Id: Ib80882d9b5776e5e9358b11340fba392e6f1ae09 --- twrp-functions.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'twrp-functions.cpp') diff --git a/twrp-functions.cpp b/twrp-functions.cpp index 6eb6cd59d..def265ca6 100644 --- a/twrp-functions.cpp +++ b/twrp-functions.cpp @@ -1043,4 +1043,23 @@ void TWFunc::Disable_Stock_Recovery_Replace(void) { } } +unsigned long long TWFunc::IOCTL_Get_Block_Size(const char* block_device) { + unsigned long block_device_size; + int ret = 0; + + int fd = open(block_device, O_RDONLY); + if (fd < 0) { + LOGINFO("Find_Partition_Size: Failed to open '%s', (%s)\n", block_device, strerror(errno)); + } else { + ret = ioctl(fd, BLKGETSIZE, &block_device_size); + close(fd); + if (ret) { + LOGINFO("Find_Partition_Size: ioctl error: (%s)\n", strerror(errno)); + } else { + return (unsigned long long)(block_device_size) * 512LLU; + } + } + return 0; +} + #endif // ndef BUILD_TWRPTAR_MAIN -- cgit v1.2.3