linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] f2fs-tools: fix the sector_size to default value
@ 2018-05-04  9:20 Yunlong Song
  2018-05-04  9:56 ` Chao Yu
  2018-05-07  2:15 ` [PATCH v2] f2fs-tools: fix to match with the start_sector Yunlong Song
  0 siblings, 2 replies; 5+ messages in thread
From: Yunlong Song @ 2018-05-04  9:20 UTC (permalink / raw)
  To: jaegeuk, chao, yuchao0, yunlong.song, yunlong.song
  Cc: miaoxie, bintian.wang, shengyong1, heyunlei, linux-f2fs-devel,
	linux-kernel

f2fs-tools uses ioctl BLKSSZGET to get sector_size, however, this ioctl
will return a value which may be larger than 512 (according to the value
of q->limits.logical_block_size), then this will be inconsistent with
the start_sector, since start_sector is got from ioctl HDIO_GETGEO and
is always in 512 size unit for a sector. To fix this problem, just set
the sector_size to the default value 512.

Signed-off-by: Yunlong Song <yunlong.song@huawei.com>
---
 lib/libf2fs.c | 7 -------
 1 file changed, 7 deletions(-)

diff --git a/lib/libf2fs.c b/lib/libf2fs.c
index 102e579..e160f2a 100644
--- a/lib/libf2fs.c
+++ b/lib/libf2fs.c
@@ -768,7 +768,6 @@ void get_kernel_uname_version(__u8 *version)
 int get_device_info(int i)
 {
 	int32_t fd = 0;
-	uint32_t sector_size;
 #ifndef BLKGETSIZE64
 	uint32_t total_sectors;
 #endif
@@ -822,12 +821,6 @@ int get_device_info(int i)
 	} else if (S_ISREG(stat_buf->st_mode)) {
 		dev->total_sectors = stat_buf->st_size / dev->sector_size;
 	} else if (S_ISBLK(stat_buf->st_mode)) {
-#ifdef BLKSSZGET
-		if (ioctl(fd, BLKSSZGET, &sector_size) < 0)
-			MSG(0, "\tError: Using the default sector size\n");
-		else if (dev->sector_size < sector_size)
-			dev->sector_size = sector_size;
-#endif
 #ifdef BLKGETSIZE64
 		if (ioctl(fd, BLKGETSIZE64, &dev->total_sectors) < 0) {
 			MSG(0, "\tError: Cannot get the device size\n");
-- 
1.8.5.2

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] f2fs-tools: fix the sector_size to default value
  2018-05-04  9:20 [PATCH] f2fs-tools: fix the sector_size to default value Yunlong Song
@ 2018-05-04  9:56 ` Chao Yu
  2018-05-07  2:15 ` [PATCH v2] f2fs-tools: fix to match with the start_sector Yunlong Song
  1 sibling, 0 replies; 5+ messages in thread
From: Chao Yu @ 2018-05-04  9:56 UTC (permalink / raw)
  To: Yunlong Song, jaegeuk, chao, yunlong.song
  Cc: miaoxie, bintian.wang, shengyong1, heyunlei, linux-f2fs-devel,
	linux-kernel

On 2018/5/4 17:20, Yunlong Song wrote:
> f2fs-tools uses ioctl BLKSSZGET to get sector_size, however, this ioctl
> will return a value which may be larger than 512 (according to the value
> of q->limits.logical_block_size), then this will be inconsistent with
> the start_sector, since start_sector is got from ioctl HDIO_GETGEO and
> is always in 512 size unit for a sector. To fix this problem, just set
> the sector_size to the default value 512.

Please check below discussion:

https://sourceforge.net/p/linux-f2fs/mailman/message/36282479/

Anyway, we will not set sector_size to 512 by default for backward
compatibility, since some users may calculated total_sector_number by
theirselves via BLKSSZGET.

Usage: mkfs.f2fs [options] device [sectors]:
sectors: number of sectors. [default: determined by device size]

So how about changing as below?

	zone_align_start_offset =
		(c.start_sector * DEFAULT_SECTOR_SIZE +
		2 * F2FS_BLKSIZE + zone_size_bytes - 1) /
		zone_size_bytes * zone_size_bytes -
		c.start_sector * DEFAULT_SECTOR_SIZE;

Thanks,

> 
> Signed-off-by: Yunlong Song <yunlong.song@huawei.com>
> ---
>  lib/libf2fs.c | 7 -------
>  1 file changed, 7 deletions(-)
> 
> diff --git a/lib/libf2fs.c b/lib/libf2fs.c
> index 102e579..e160f2a 100644
> --- a/lib/libf2fs.c
> +++ b/lib/libf2fs.c
> @@ -768,7 +768,6 @@ void get_kernel_uname_version(__u8 *version)
>  int get_device_info(int i)
>  {
>  	int32_t fd = 0;
> -	uint32_t sector_size;
>  #ifndef BLKGETSIZE64
>  	uint32_t total_sectors;
>  #endif
> @@ -822,12 +821,6 @@ int get_device_info(int i)
>  	} else if (S_ISREG(stat_buf->st_mode)) {
>  		dev->total_sectors = stat_buf->st_size / dev->sector_size;
>  	} else if (S_ISBLK(stat_buf->st_mode)) {
> -#ifdef BLKSSZGET
> -		if (ioctl(fd, BLKSSZGET, &sector_size) < 0)
> -			MSG(0, "\tError: Using the default sector size\n");
> -		else if (dev->sector_size < sector_size)
> -			dev->sector_size = sector_size;
> -#endif
>  #ifdef BLKGETSIZE64
>  		if (ioctl(fd, BLKGETSIZE64, &dev->total_sectors) < 0) {
>  			MSG(0, "\tError: Cannot get the device size\n");
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2] f2fs-tools: fix to match with the start_sector
  2018-05-04  9:20 [PATCH] f2fs-tools: fix the sector_size to default value Yunlong Song
  2018-05-04  9:56 ` Chao Yu
@ 2018-05-07  2:15 ` Yunlong Song
  2018-05-26  8:13   ` Yunlong Song
  2018-05-28  7:11   ` Chao Yu
  1 sibling, 2 replies; 5+ messages in thread
From: Yunlong Song @ 2018-05-07  2:15 UTC (permalink / raw)
  To: jaegeuk, chao, yuchao0, yunlong.song, yunlong.song
  Cc: miaoxie, bintian.wang, shengyong1, heyunlei, linux-f2fs-devel,
	linux-kernel

f2fs-tools uses ioctl BLKSSZGET to get sector_size, however, this ioctl
will return a value which may be larger than 512 (according to the value
of q->limits.logical_block_size), then this will be inconsistent with
the start_sector, since start_sector is got from ioctl HDIO_GETGEO and
is always in 512 size unit for a sector. To fix this problem, just
change the sector_size to the default value when computing with
start_sector. And fix sectors_per_blk as well.

Signed-off-by: Yunlong Song <yunlong.song@huawei.com>
---
 fsck/resize.c      |  4 ++--
 mkfs/f2fs_format.c | 12 ++++++------
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/fsck/resize.c b/fsck/resize.c
index d285dd7..ada2155 100644
--- a/fsck/resize.c
+++ b/fsck/resize.c
@@ -27,10 +27,10 @@ static int get_new_sb(struct f2fs_super_block *sb)
 
 	zone_size_bytes = segment_size_bytes * segs_per_zone;
 	zone_align_start_offset =
-		(c.start_sector * c.sector_size +
+		(c.start_sector * DEFAULT_SECTOR_SIZE +
 		2 * F2FS_BLKSIZE + zone_size_bytes - 1) /
 		zone_size_bytes * zone_size_bytes -
-		c.start_sector * c.sector_size;
+		c.start_sector * DEFAULT_SECTOR_SIZE;
 
 	set_sb(segment_count, (c.target_sectors * c.sector_size -
 				zone_align_start_offset) / segment_size_bytes /
diff --git a/mkfs/f2fs_format.c b/mkfs/f2fs_format.c
index 0a99a77..ced5fea 100644
--- a/mkfs/f2fs_format.c
+++ b/mkfs/f2fs_format.c
@@ -212,18 +212,18 @@ static int f2fs_prepare_super_block(void)
 	set_sb(block_count, c.total_sectors >> log_sectors_per_block);
 
 	zone_align_start_offset =
-		(c.start_sector * c.sector_size +
+		(c.start_sector * DEFAULT_SECTOR_SIZE +
 		2 * F2FS_BLKSIZE + zone_size_bytes - 1) /
 		zone_size_bytes * zone_size_bytes -
-		c.start_sector * c.sector_size;
+		c.start_sector * DEFAULT_SECTOR_SIZE;
 
-	if (c.start_sector % c.sectors_per_blk) {
+	if (c.start_sector % DEFAULT_SECTORS_PER_BLOCK) {
 		MSG(1, "\t%s: Align start sector number to the page unit\n",
 				c.zoned_mode ? "FAIL" : "WARN");
 		MSG(1, "\ti.e., start sector: %d, ofs:%d (sects/page: %d)\n",
 				c.start_sector,
-				c.start_sector % c.sectors_per_blk,
-				c.sectors_per_blk);
+				c.start_sector % DEFAULT_SECTORS_PER_BLOCK,
+				DEFAULT_SECTORS_PER_BLOCK);
 		if (c.zoned_mode)
 			return -1;
 	}
@@ -235,7 +235,7 @@ static int f2fs_prepare_super_block(void)
 					get_sb(segment0_blkaddr));
 
 	if (c.zoned_mode && (get_sb(segment0_blkaddr) + c.start_sector /
-					c.sectors_per_blk) % c.zone_blocks) {
+					DEFAULT_SECTORS_PER_BLOCK) % c.zone_blocks) {
 		MSG(1, "\tError: Unaligned segment0 block address %u\n",
 				get_sb(segment0_blkaddr));
 		return -1;
-- 
1.8.5.2

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] f2fs-tools: fix to match with the start_sector
  2018-05-07  2:15 ` [PATCH v2] f2fs-tools: fix to match with the start_sector Yunlong Song
@ 2018-05-26  8:13   ` Yunlong Song
  2018-05-28  7:11   ` Chao Yu
  1 sibling, 0 replies; 5+ messages in thread
From: Yunlong Song @ 2018-05-26  8:13 UTC (permalink / raw)
  To: jaegeuk, chao, yuchao0, yunlong.song
  Cc: miaoxie, bintian.wang, shengyong1, heyunlei, linux-f2fs-devel,
	linux-kernel

ping...

On 2018/5/7 10:15, Yunlong Song wrote:
> f2fs-tools uses ioctl BLKSSZGET to get sector_size, however, this ioctl
> will return a value which may be larger than 512 (according to the value
> of q->limits.logical_block_size), then this will be inconsistent with
> the start_sector, since start_sector is got from ioctl HDIO_GETGEO and
> is always in 512 size unit for a sector. To fix this problem, just
> change the sector_size to the default value when computing with
> start_sector. And fix sectors_per_blk as well.
>
> Signed-off-by: Yunlong Song <yunlong.song@huawei.com>
> ---
>   fsck/resize.c      |  4 ++--
>   mkfs/f2fs_format.c | 12 ++++++------
>   2 files changed, 8 insertions(+), 8 deletions(-)
>
> diff --git a/fsck/resize.c b/fsck/resize.c
> index d285dd7..ada2155 100644
> --- a/fsck/resize.c
> +++ b/fsck/resize.c
> @@ -27,10 +27,10 @@ static int get_new_sb(struct f2fs_super_block *sb)
>   
>   	zone_size_bytes = segment_size_bytes * segs_per_zone;
>   	zone_align_start_offset =
> -		(c.start_sector * c.sector_size +
> +		(c.start_sector * DEFAULT_SECTOR_SIZE +
>   		2 * F2FS_BLKSIZE + zone_size_bytes - 1) /
>   		zone_size_bytes * zone_size_bytes -
> -		c.start_sector * c.sector_size;
> +		c.start_sector * DEFAULT_SECTOR_SIZE;
>   
>   	set_sb(segment_count, (c.target_sectors * c.sector_size -
>   				zone_align_start_offset) / segment_size_bytes /
> diff --git a/mkfs/f2fs_format.c b/mkfs/f2fs_format.c
> index 0a99a77..ced5fea 100644
> --- a/mkfs/f2fs_format.c
> +++ b/mkfs/f2fs_format.c
> @@ -212,18 +212,18 @@ static int f2fs_prepare_super_block(void)
>   	set_sb(block_count, c.total_sectors >> log_sectors_per_block);
>   
>   	zone_align_start_offset =
> -		(c.start_sector * c.sector_size +
> +		(c.start_sector * DEFAULT_SECTOR_SIZE +
>   		2 * F2FS_BLKSIZE + zone_size_bytes - 1) /
>   		zone_size_bytes * zone_size_bytes -
> -		c.start_sector * c.sector_size;
> +		c.start_sector * DEFAULT_SECTOR_SIZE;
>   
> -	if (c.start_sector % c.sectors_per_blk) {
> +	if (c.start_sector % DEFAULT_SECTORS_PER_BLOCK) {
>   		MSG(1, "\t%s: Align start sector number to the page unit\n",
>   				c.zoned_mode ? "FAIL" : "WARN");
>   		MSG(1, "\ti.e., start sector: %d, ofs:%d (sects/page: %d)\n",
>   				c.start_sector,
> -				c.start_sector % c.sectors_per_blk,
> -				c.sectors_per_blk);
> +				c.start_sector % DEFAULT_SECTORS_PER_BLOCK,
> +				DEFAULT_SECTORS_PER_BLOCK);
>   		if (c.zoned_mode)
>   			return -1;
>   	}
> @@ -235,7 +235,7 @@ static int f2fs_prepare_super_block(void)
>   					get_sb(segment0_blkaddr));
>   
>   	if (c.zoned_mode && (get_sb(segment0_blkaddr) + c.start_sector /
> -					c.sectors_per_blk) % c.zone_blocks) {
> +					DEFAULT_SECTORS_PER_BLOCK) % c.zone_blocks) {
>   		MSG(1, "\tError: Unaligned segment0 block address %u\n",
>   				get_sb(segment0_blkaddr));
>   		return -1;

-- 
Thanks,
Yunlong Song

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] f2fs-tools: fix to match with the start_sector
  2018-05-07  2:15 ` [PATCH v2] f2fs-tools: fix to match with the start_sector Yunlong Song
  2018-05-26  8:13   ` Yunlong Song
@ 2018-05-28  7:11   ` Chao Yu
  1 sibling, 0 replies; 5+ messages in thread
From: Chao Yu @ 2018-05-28  7:11 UTC (permalink / raw)
  To: Yunlong Song, jaegeuk, chao, yunlong.song
  Cc: miaoxie, bintian.wang, shengyong1, heyunlei, linux-f2fs-devel,
	linux-kernel

On 2018/5/7 10:15, Yunlong Song wrote:
> f2fs-tools uses ioctl BLKSSZGET to get sector_size, however, this ioctl
> will return a value which may be larger than 512 (according to the value
> of q->limits.logical_block_size), then this will be inconsistent with
> the start_sector, since start_sector is got from ioctl HDIO_GETGEO and
> is always in 512 size unit for a sector. To fix this problem, just
> change the sector_size to the default value when computing with
> start_sector. And fix sectors_per_blk as well.
> 
> Signed-off-by: Yunlong Song <yunlong.song@huawei.com>

Reviewed-by: Chao Yu <yuchao0@huawei.com>

Thanks,

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-05-28  7:12 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-04  9:20 [PATCH] f2fs-tools: fix the sector_size to default value Yunlong Song
2018-05-04  9:56 ` Chao Yu
2018-05-07  2:15 ` [PATCH v2] f2fs-tools: fix to match with the start_sector Yunlong Song
2018-05-26  8:13   ` Yunlong Song
2018-05-28  7:11   ` Chao Yu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).