aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorjoerg jungermann <jj@borkum.net>2014-09-25 22:05:12 -0700
committerJP Abgrall <jpa@google.com>2014-11-07 15:32:18 -0800
commit290d040e855230dbc21c35ccec7ee76fa6696567 (patch)
tree4cd050dffcb9b32013c1bd1c455b659690154554 /lib
parent7b74ed3d7cc84c3bb7e85b825cf17540baa3bbfa (diff)
downloadandroid_external_f2fs-tools-290d040e855230dbc21c35ccec7ee76fa6696567.tar.gz
android_external_f2fs-tools-290d040e855230dbc21c35ccec7ee76fa6696567.tar.bz2
android_external_f2fs-tools-290d040e855230dbc21c35ccec7ee76fa6696567.zip
mkfs.f2fs: possible endianes bug in mkfs.f2fs roll-forward speed
I might found a bug in mkfs.f2fs. while experimenting with f2fs on my big endian MIPS32 device (platform lantiq, 14.07-rc3, uclibc). I ran into an issue that mkfs.f2fs, was not able to format block devices if I did not specify the sector count manually. I hunted it down to lib/libf2fs.c. After I found that the detected sector count equals to the wanted sector count shifted left (32+9) times. I found two issues: Firstly it uses ioctl BLKGETSIZE, which writes to an uint32_t the size of the device. As c->total_sectors is of type uint64_t, the value is written in to the first 4 bytes. That explained the left shift of 32 bits. Secondly BLKGETSIZE determines the size of the device in bytes (AFAIK, learned by observation). In the first branch of the if-block patched below, the c->total_sectors is calculated by c->total_sectors = stat_buf.st_size / c->sector_size; The else branch omits the devision. sector_sice is mostly 512, that explained the left shift by 9 bytes. * fixes sector count calculation * uses BLKGETSIZE64 if avail Signed-off-by: joerg jungermann <jj@borkum.net> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/libf2fs.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/lib/libf2fs.c b/lib/libf2fs.c
index 01ef4e9..73c551b 100644
--- a/lib/libf2fs.c
+++ b/lib/libf2fs.c
@@ -422,6 +422,9 @@ int f2fs_get_device_info(struct f2fs_configuration *c)
{
int32_t fd = 0;
uint32_t sector_size;
+#ifndef BLKGETSIZE64
+ uint32_t total_sectors;
+#endif
struct stat stat_buf;
struct hd_geometry geom;
u_int64_t wanted_total_sectors = c->total_sectors;
@@ -454,11 +457,20 @@ int f2fs_get_device_info(struct f2fs_configuration *c)
}
}
- if (ioctl(fd, BLKGETSIZE, &c->total_sectors) < 0) {
+#ifdef BLKGETSIZE64
+ if (ioctl(fd, BLKGETSIZE64, &c->total_sectors) < 0) {
MSG(0, "\tError: Cannot get the device size\n");
return -1;
}
-
+ c->total_sectors /= c->sector_size;
+#else
+ if (ioctl(fd, BLKGETSIZE, &total_sectors) < 0) {
+ MSG(0, "\tError: Cannot get the device size\n");
+ return -1;
+ }
+ total_sectors /= c->sector_size;
+ c->total_sectors = total_sectors;
+#endif
if (ioctl(fd, HDIO_GETGEO, &geom) < 0)
c->start_sector = 0;
else