diff options
author | qemx13 <qemx13@motorola.com> | 2015-10-19 13:05:55 -0700 |
---|---|---|
committer | Steve Kondik <steve@cyngn.com> | 2016-08-24 11:02:02 -0700 |
commit | bf53b3a5a470916a1b5f2e6300a14b9645c04372 (patch) | |
tree | 2b3394e40b5b55bdea9cf3f9e298b1015d9ce55c /lib | |
parent | 5bd943d50d103eb6f48a72f199a49dce4feeb61a (diff) | |
download | android_external_f2fs-tools-bf53b3a5a470916a1b5f2e6300a14b9645c04372.tar.gz android_external_f2fs-tools-bf53b3a5a470916a1b5f2e6300a14b9645c04372.tar.bz2 android_external_f2fs-tools-bf53b3a5a470916a1b5f2e6300a14b9645c04372.zip |
Modifications to reserve space for encrypted filesystem support
Original patch by Motorola modified for lollipop
Change-Id: Ie77467a11c6b50d51c67d63644677caec7959031
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libf2fs.c | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/lib/libf2fs.c b/lib/libf2fs.c index 9e19e9b..a7021ad 100644 --- a/lib/libf2fs.c +++ b/lib/libf2fs.c @@ -362,6 +362,7 @@ void f2fs_init_configuration(struct f2fs_configuration *c) c->vol_label = ""; c->device_name = NULL; c->trim = 1; + c->bytes_reserved = 0; } static int is_mounted(const char *mpt, const char *device) @@ -457,7 +458,20 @@ int f2fs_get_device_info(struct f2fs_configuration *c) } if (S_ISREG(stat_buf.st_mode)) { - c->total_sectors = stat_buf.st_size / c->sector_size; + if (c->bytes_reserved >= stat_buf.st_size) { + MSG(0, "\n\Error: reserved bytes (%u) is bigger than the device size (%u bytes)\n", + (unsigned int) c->bytes_reserved, + (unsigned int) stat_buf.st_size); + return -1; + } + + c->total_sectors = (stat_buf.st_size - c->bytes_reserved) / c->sector_size; + + if (c->bytes_reserved) { + MSG(0, "Info: Reserved %u bytes ", (unsigned int) c->bytes_reserved); + MSG(0, "from device of size %u sectors\n", + (unsigned int) (stat_buf.st_size / c->sector_size)); + } } else if (S_ISBLK(stat_buf.st_mode)) { if (ioctl(fd, BLKSSZGET, §or_size) < 0) { MSG(0, "\tError: Using the default sector size\n"); @@ -482,6 +496,28 @@ int f2fs_get_device_info(struct f2fs_configuration *c) total_sectors /= c->sector_size; c->total_sectors = total_sectors; #endif + + if (c->bytes_reserved) { + unsigned int reserved_sectors; + + reserved_sectors = c->bytes_reserved / c->sector_size; + if (c->bytes_reserved % c->sector_size) {reserved_sectors++;} + + if(reserved_sectors >= c->total_sectors) { + MSG(0, "\n\Error: reserved bytes (%u sectors) is bigger than the device size (%u sectors)\n", + (unsigned int) reserved_sectors, + (unsigned int) c->total_sectors); + return -1; + } + + MSG(0, "\n"); + MSG(0, "Info: Reserved %u sectors ", (unsigned int) reserved_sectors); + MSG(0, "from device of size %u sectors\n", + (unsigned int) c->total_sectors); + + c->total_sectors -= reserved_sectors; + } + if (ioctl(fd, HDIO_GETGEO, &geom) < 0) c->start_sector = 0; else |