summaryrefslogtreecommitdiffstats
path: root/partition.cpp
diff options
context:
space:
mode:
authorEthan Yonker <dees_troy@teamw.in>2015-12-14 17:17:00 +0100
committerEthan Yonker <dees_troy@teamw.in>2015-12-19 15:38:12 +0100
commitd18a821e009a4e31208541d4c96cd54bd7f313ba (patch)
tree128af8505d486e3176d8f603ad4f6c95aa61bcaa /partition.cpp
parentMultiple Language Support (diff)
downloadandroid_bootable_recovery-d18a821e009a4e31208541d4c96cd54bd7f313ba.tar
android_bootable_recovery-d18a821e009a4e31208541d4c96cd54bd7f313ba.tar.gz
android_bootable_recovery-d18a821e009a4e31208541d4c96cd54bd7f313ba.tar.bz2
android_bootable_recovery-d18a821e009a4e31208541d4c96cd54bd7f313ba.tar.lz
android_bootable_recovery-d18a821e009a4e31208541d4c96cd54bd7f313ba.tar.xz
android_bootable_recovery-d18a821e009a4e31208541d4c96cd54bd7f313ba.tar.zst
android_bootable_recovery-d18a821e009a4e31208541d4c96cd54bd7f313ba.zip
Diffstat (limited to '')
-rw-r--r--partition.cpp44
1 files changed, 29 insertions, 15 deletions
diff --git a/partition.cpp b/partition.cpp
index df408e6b7..a17a647c4 100644
--- a/partition.cpp
+++ b/partition.cpp
@@ -879,6 +879,26 @@ bool TWPartition::Get_Size_Via_df(bool Display_Error) {
return true;
}
+unsigned long long TWPartition::IOCTL_Get_Block_Size() {
+ unsigned long block_device_size;
+ int ret = 0;
+
+ Find_Actual_Block_Device();
+ int fd = open(Actual_Block_Device.c_str(), O_RDONLY);
+ if (fd < 0) {
+ LOGINFO("Find_Partition_Size: Failed to open '%s', (%s)\n", Actual_Block_Device.c_str(), 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;
+}
+
bool TWPartition::Find_Partition_Size(void) {
FILE* fp;
char line[512];
@@ -907,6 +927,12 @@ bool TWPartition::Find_Partition_Size(void) {
}
}
+ unsigned long long ioctl_size = IOCTL_Get_Block_Size();
+ if (ioctl_size) {
+ Size = ioctl_size;
+ return true;
+ }
+
// In this case, we'll first get the partitions we care about (with labels)
fp = fopen("/proc/partitions", "rt");
if (fp == NULL)
@@ -1360,22 +1386,10 @@ bool TWPartition::Resize() {
Find_Actual_Block_Device();
command = "/sbin/resize2fs " + Actual_Block_Device;
if (Length != 0) {
- unsigned int block_device_size;
- int fd, ret;
-
- fd = open(Actual_Block_Device.c_str(), O_RDONLY);
- if (fd < 0) {
- gui_msg(Msg(msg::kError, "error_opening_strerr=Error opening: '{1}' ({2})")(Actual_Block_Device)(strerror(errno)));
- return false;
- }
- ret = ioctl(fd, BLKGETSIZE, &block_device_size);
- close(fd);
- if (ret) {
- gui_msg(Msg(msg::kError, "unable_resize=Unable to resize {1}.")(Display_Name));
- LOGINFO("Resize: ioctl error\n");
+ unsigned long long Actual_Size = IOCTL_Get_Block_Size();
+ if (Actual_Size == 0)
return false;
- }
- unsigned long long Actual_Size = (unsigned long long)(block_device_size) * 512LLU;
+
unsigned long long Block_Count;
if (Length < 0) {
// Reduce overall size by this length