Skip to contentSkip to conversation

Make f2fs-tools easier to maintain

PATCH In review Bart Van Assche 3 participants 36 messages Apr 21, 2022 – Jun 10, 2022 Library code

lore
Share & tools
lore
#0 lore raw

cover Make f2fs-tools easier to maintain

Hi Jaegeuk,

This patch series should make f2fs-tools easier to maintain and fixes a few smaller bugs. Although these patches have been compile-tested only, please consider these patches for the upstream f2fs-tools repository.

Thanks,

Bart.

Bart Van Assche (31):
configure.ac: Stop using obsolete macros configure.ac: Remove two prototype tests configure.ac: Enable the automake -Wall option configure.ac: Sort header file names alphabetically configure.ac: Enable cross-compilation
Switch from the u_int to the uint types
Change the ANDROID_WINDOWS_HOST macro into _WIN32
ci: Build f2fstools upon push and pull requests Change one array member into a flexible array member Verify structure sizes at compile time
Suppress a compiler warning
f2fs_fs.h: Use standard fixed width integer types Remove unnecessary __attribute__((packed)) annotations Move the be32_to_cpu() definition
Include <stddef.h> instead of defining offsetof() Use %zu to format size_t
Fix the MinGW build
configure.ac: Detect the sparse/sparse.h header configure.ac: Detect selinux/android.h mkfs/f2fs_format.c: Suppress a compiler warning
fsck: Remove a superfluous include directive tools/f2fscrypt.c: Fix build without uuid/uuid.h header file fsck/main.c: Suppress a compiler warning
Change #ifdef _WIN32 checks into #ifdef HAVE_.* fsck/segment.c: Remove dead code
tools/f2fs_io: Fix the type of 'ret'
Annotate switch/case fallthrough
Suppress a compiler warning about integer truncation Support cross-compiliation for PowerPC
Fix PowerPC format string warnings
ci: Enable -Wall, -Wextra and -Werror

 .github/workflows/ci.yml |  70 ++++++++++
 README                   |   1 -
 configure.ac             | 131 +++++++++++--------
 fsck/Makefile.am         |   2 +-
 fsck/dir.c               |   8 ++
 fsck/f2fs.h              |  14 +-
 fsck/fsck.c              |   5 +-
 fsck/main.c              |  21 ++-
 fsck/mount.c             |  54 ++++----
 fsck/quotaio.c           |   4 +-
 fsck/quotaio.h           |   3 -
 fsck/quotaio_tree.h      |   4 +-
 fsck/quotaio_v2.h        |  12 +-
 fsck/resize.c            |  28 ++--
 fsck/segment.c           |   3 +-
 fsck/sload.c             |  15 ++-
 fsck/xattr.h             |   4 +-
 include/f2fs_fs.h        | 276 +++++++++++++++++++++++----------------
 include/quota.h          |  30 +++--
 lib/libf2fs.c            |  34 ++---
 lib/libf2fs_io.c         |  24 ++--
 lib/libf2fs_zoned.c      |  18 +--
 mkfs/f2fs_format.c       |  95 ++++++++------
 mkfs/f2fs_format_main.c  |  12 +-
 mkfs/f2fs_format_utils.c |   9 +-
 mkfs/f2fs_format_utils.h |   2 +-
 tools/Makefile.am        |   5 +-
 tools/f2fs_io/f2fs_io.c  |  26 +++-
 tools/f2fs_io/f2fs_io.h  |   8 +-
 tools/f2fscrypt.c        |  19 ++-
 tools/fibmap.c           |   2 +
 31 files changed, 586 insertions(+), 353 deletions(-)
 create mode 100644 .github/workflows/ci.yml

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

#1 lore raw

PATCH 1/31 configure.ac: Stop using obsolete macros

Run autoupdate v2.71 to fix the following autogen.sh warnings:

configure.ac:33: warning: The macro `AC_CONFIG_HEADER' is obsolete. configure.ac:33: You should run autoupdate. ./lib/autoconf/status.m4:719: AC_CONFIG_HEADER is expanded from... configure.ac:33: the top level
configure.ac:49: warning: The macro `AC_PROG_LIBTOOL' is obsolete. configure.ac:49: You should run autoupdate. m4/libtool.m4:100: AC_PROG_LIBTOOL is expanded from... configure.ac:49: the top level

---
 configure.ac | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
configure.ac +2 -2
index 32e97a25053e..f906be780eb2 100644
@@ -30,7 +30,7 @@ AS_IF([test -d .git],[
 		[f2fs-tools date based on Source releases])])
 
 AC_CONFIG_SRCDIR([config.h.in])
-AC_CONFIG_HEADER([config.h])
+AC_CONFIG_HEADERS([config.h])
 AC_CONFIG_MACRO_DIR([m4])
 AC_CONFIG_AUX_DIR([build-aux])
 AM_INIT_AUTOMAKE([foreign tar-pax dist-xz])
@@ -46,7 +46,7 @@ AC_ARG_WITH([blkid],
 
 # Checks for programs.
 AC_PROG_CC
-AC_PROG_LIBTOOL
+LT_INIT
 AC_PATH_PROG([LDCONFIG], [ldconfig],
        [AC_MSG_ERROR([ldconfig not found])],
        [$PATH:/sbin])

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

#2 lore raw

PATCH 2/31 configure.ac: Remove two prototype tests

In reply to Bart Van Assche

Since no code uses the HAVE_.*_PROTOTYPE macros, remove the code that sets these macros.

---
 configure.ac | 25 -------------------------
 1 file changed, 25 deletions(-)
configure.ac +0 -25
index f906be780eb2..c908c9394613 100644
@@ -146,31 +146,6 @@ AC_CHECK_FUNCS_ONCE([
 AS_IF([test "$ac_cv_header_byteswap_h" = "yes"],
       [AC_CHECK_DECLS([bswap_64],,,[#include <byteswap.h>])])
 
-dnl
-dnl Check to see if llseek() is declared in unistd.h.  On some libc's
-dnl it is, and on others it isn't..... Thank you glibc developers....
-dnl
-AC_CHECK_DECL(llseek,[AC_DEFINE(HAVE_LLSEEK_PROTOTYPE, 1,
-			[Define to 1 if llseek declared in unistd.h])],,
-			[#include <unistd.h>])
-dnl
-dnl Check to see if lseek64() is declared in unistd.h.  Glibc's header files
-dnl are so convoluted that I can't tell whether it will always be defined,
-dnl and if it isn't defined while lseek64 is defined in the library,
-dnl disaster will strike.
-dnl
-dnl Warning!  Use of --enable-gcc-wall may throw off this test.
-dnl
-dnl
-AC_CHECK_DECL(lseek64,[AC_DEFINE(HAVE_LSEEK64_PROTOTYPE, 1,
-		[Define to 1 if lseek64 declared in unistd.h])],,
-		[#define _LARGEFILE_SOURCE
-		#define _LARGEFILE64_SOURCE
-		#include <unistd.h>])
-dnl
-dnl Word sizes...
-dnl
-
 # AC_CANONICAL_HOST is needed to access the 'host_os' variable
 AC_CANONICAL_HOST
 

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

#3 lore raw

PATCH 3/31 configure.ac: Enable the automake -Wall option

In reply to Bart Van Assche

This patch fixes the following automake warnings:

/usr/share/automake-1.16/am/ltlibrary.am: warning: 'libf2fs.la': linking libtool libraries using a non-POSIX /usr/share/automake-1.16/am/ltlibrary.am: archiver requires 'AM_PROG_AR' in 'configure.ac'
lib/Makefile.am:3: while processing Libtool library 'libf2fs.la'
/usr/share/automake-1.16/am/ltlibrary.am: warning: 'libf2fs_format.la': linking libtool libraries using a non-POSIX /usr/share/automake-1.16/am/ltlibrary.am: archiver requires 'AM_PROG_AR' in 'configure.ac'
mkfs/Makefile.am:11: while processing Libtool library 'libf2fs_format.la'

---
 configure.ac | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
configure.ac +2 -1
index c908c9394613..b40012bd8745 100644
@@ -33,7 +33,7 @@ AC_CONFIG_SRCDIR([config.h.in])
 AC_CONFIG_HEADERS([config.h])
 AC_CONFIG_MACRO_DIR([m4])
 AC_CONFIG_AUX_DIR([build-aux])
-AM_INIT_AUTOMAKE([foreign tar-pax dist-xz])
+AM_INIT_AUTOMAKE([-Wall -Werror foreign tar-pax dist-xz])
 
 # Test configure options.
 AC_ARG_WITH([selinux],
@@ -46,6 +46,7 @@ AC_ARG_WITH([blkid],
 
 # Checks for programs.
 AC_PROG_CC
+AM_PROG_AR
 LT_INIT
 AC_PATH_PROG([LDCONFIG], [ldconfig],
        [AC_MSG_ERROR([ldconfig not found])],

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

#4 lore raw

PATCH 4/31 configure.ac: Sort header file names alphabetically

In reply to Bart Van Assche
---
 configure.ac | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
configure.ac +2 -2
index b40012bd8745..0d7872abde19 100644
@@ -100,13 +100,13 @@ AC_CHECK_HEADERS(m4_flatten([
 	fcntl.h
 	linux/blkzoned.h
 	linux/falloc.h
+	linux/fiemap.h
 	linux/fs.h
 	linux/hdreg.h
 	linux/limits.h
 	linux/posix_acl.h
 	linux/types.h
 	linux/xattr.h
-	linux/fiemap.h
 	mach/mach_time.h
 	mntent.h
 	scsi/sg.h
@@ -114,8 +114,8 @@ AC_CHECK_HEADERS(m4_flatten([
 	string.h
 	sys/acl.h
 	sys/ioctl.h
-	sys/syscall.h
 	sys/mount.h
+	sys/syscall.h
 	sys/sysmacros.h
 	sys/utsname.h
 	sys/xattr.h

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

#5 lore raw

PATCH 5/31 configure.ac: Enable cross-compilation

In reply to Bart Van Assche

Stop using PKG_CHECK_MODULES() since that macro is not compatible with cross-compilation.

---
 README                  |  1 -
 configure.ac            | 47 ++++++++++++++++++-----------------------
 mkfs/f2fs_format.c      |  2 +-
 mkfs/f2fs_format_main.c |  4 ++--
 tools/f2fscrypt.c       |  2 +-
 5 files changed, 24 insertions(+), 32 deletions(-)
README +0 -1
index afe334fc6170..c9b0c1f6f721 100644
@@ -9,7 +9,6 @@ Before compilation
 
 You should install the following packages.
  - libuuid-devel or uuid-dev
- - pkg-config
  - autoconf
  - libtool
  - libselinux1-dev
configure.ac +20 -27

75 lines not on this page · raw message

mkfs/f2fs_format.c +1 -1
index dba0cec61e60..d237d1a8c12e 100644
@@ -18,7 +18,7 @@
 #include <sys/mount.h>
 #endif
 #include <time.h>
-#include <uuid.h>
+#include <uuid/uuid.h>
 
 #include "f2fs_fs.h"
 #include "quota.h"
mkfs/f2fs_format_main.c +2 -2
index bf78756ed374..797e90a948f5 100644
@@ -19,13 +19,13 @@
 #include <sys/mount.h>
 #endif
 #include <time.h>
-#include <uuid.h>
+#include <uuid/uuid.h>
 #include <errno.h>
 #include <getopt.h>
 
 #include "config.h"
 #ifdef HAVE_LIBBLKID
-#include <blkid.h>
+#include <blkid/blkid.h>
 #endif
 
 #include "f2fs_fs.h"
tools/f2fscrypt.c +1 -1
index d5bc3c5ff50b..fe3e0ff3c1a9 100644
@@ -43,7 +43,7 @@
 #ifdef __KERNEL__
 #include <linux/fs.h>
 #endif
-#include <uuid.h>
+#include <uuid/uuid.h>
 
 #if !defined(HAVE_ADD_KEY) || !defined(HAVE_KEYCTL)
 #include <sys/syscall.h>

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

#6 lore raw

PATCH 6/31 Switch from the u_int to the uint types

In reply to Bart Van Assche

Many format strings use one of the PRI* macros. These macros are compatible with the uint types but not with the u_int types. Hence this patch that switches from the u_int to the uint types.

---
 fsck/fsck.c              |   4 +-
 fsck/mount.c             |  44 ++++++++--------
 fsck/resize.c            |  28 +++++-----
 include/f2fs_fs.h        | 110 +++++++++++++++++++--------------------
 include/quota.h          |  16 +++---
 lib/libf2fs.c            |  22 ++++----
 lib/libf2fs_io.c         |   4 +-
 lib/libf2fs_zoned.c      |  16 +++---
 mkfs/f2fs_format.c       |  80 ++++++++++++++--------------
 mkfs/f2fs_format_main.c  |   2 +-
 mkfs/f2fs_format_utils.c |   2 +-
 mkfs/f2fs_format_utils.h |   2 +-
 tools/f2fs_io/f2fs_io.h  |   8 +--
 13 files changed, 167 insertions(+), 171 deletions(-)
fsck/fsck.c +2 -2
index ddcede32b4cb..798779cfaf8a 100644
@@ -2312,7 +2312,7 @@ static void fix_checkpoint(struct f2fs_sb_info *sbi)
 	block_t cp_blocks;
 	u32 i;
 	int ret;
-	u_int32_t crc = 0;
+	uint32_t crc = 0;
 
 	/* should call from fsck */
 	ASSERT(c.func == FSCK);
@@ -2438,7 +2438,7 @@ static int check_curseg_write_pointer(struct f2fs_sb_info *sbi, int type)
 	struct f2fs_fsck *fsck = F2FS_FSCK(sbi);
 	struct blk_zone blkz;
 	block_t cs_block, wp_block, zone_last_vblock;
-	u_int64_t cs_sector, wp_sector;
+	uint64_t cs_sector, wp_sector;
 	int i, ret;
 	unsigned int zone_segno;
 	int log_sectors_per_block = sbi->log_blocksize - SECTOR_SHIFT;
fsck/mount.c +22 -22

125 lines not on this page · raw message

fsck/resize.c +14 -14
index 78d578ec2cc1..f1b770123428 100644
@@ -11,27 +11,27 @@
 
 static int get_new_sb(struct f2fs_super_block *sb)
 {
-	u_int32_t zone_size_bytes;
-	u_int64_t zone_align_start_offset;
-	u_int32_t blocks_for_sit, blocks_for_nat, blocks_for_ssa;
-	u_int32_t sit_segments, nat_segments, diff, total_meta_segments;
-	u_int32_t total_valid_blks_available;
-	u_int32_t sit_bitmap_size, max_sit_bitmap_size;
-	u_int32_t max_nat_bitmap_size, max_nat_segments;
-	u_int32_t segment_size_bytes = 1 << (get_sb(log_blocksize) +
+	uint32_t zone_size_bytes;
+	uint64_t zone_align_start_offset;
+	uint32_t blocks_for_sit, blocks_for_nat, blocks_for_ssa;
+	uint32_t sit_segments, nat_segments, diff, total_meta_segments;
+	uint32_t total_valid_blks_available;
+	uint32_t sit_bitmap_size, max_sit_bitmap_size;
+	uint32_t max_nat_bitmap_size, max_nat_segments;
+	uint32_t segment_size_bytes = 1 << (get_sb(log_blocksize) +
 					get_sb(log_blocks_per_seg));
-	u_int32_t blks_per_seg = 1 << get_sb(log_blocks_per_seg);
-	u_int32_t segs_per_zone = get_sb(segs_per_sec) * get_sb(secs_per_zone);
+	uint32_t blks_per_seg = 1 << get_sb(log_blocks_per_seg);
+	uint32_t segs_per_zone = get_sb(segs_per_sec) * get_sb(secs_per_zone);
 
 	set_sb(block_count, c.target_sectors >>
 				get_sb(log_sectors_per_block));
 
 	zone_size_bytes = segment_size_bytes * segs_per_zone;
 	zone_align_start_offset =
-		((u_int64_t) c.start_sector * DEFAULT_SECTOR_SIZE +
+		((uint64_t) c.start_sector * DEFAULT_SECTOR_SIZE +
 		2 * F2FS_BLKSIZE + zone_size_bytes - 1) /
 		zone_size_bytes * zone_size_bytes -
-		(u_int64_t) c.start_sector * DEFAULT_SECTOR_SIZE;
+		(uint64_t) c.start_sector * DEFAULT_SECTOR_SIZE;
 
 	set_sb(segment_count, (c.target_sectors * c.sector_size -
 				zone_align_start_offset) / segment_size_bytes /
@@ -76,7 +76,7 @@ static int get_new_sb(struct f2fs_super_block *sb)
 		/* use cp_payload if free space of f2fs_checkpoint is not enough */
 		if (max_sit_bitmap_size + max_nat_bitmap_size >
 						MAX_BITMAP_SIZE_IN_CKPT) {
-			u_int32_t diff =  max_sit_bitmap_size +
+			uint32_t diff =  max_sit_bitmap_size +
 						max_nat_bitmap_size -
 						MAX_BITMAP_SIZE_IN_CKPT;
 			set_sb(cp_payload, F2FS_BLK_ALIGN(diff));
@@ -457,7 +457,7 @@ static void rebuild_checkpoint(struct f2fs_sb_info *sbi,
 	block_t new_cp_blks = 1 + get_newsb(cp_payload);
 	block_t orphan_blks = 0;
 	block_t new_cp_blk_no, old_cp_blk_no;
-	u_int32_t crc = 0;
+	uint32_t crc = 0;
 	u32 flags;
 	void *buf;
 	int i, ret;
include/f2fs_fs.h +53 -57

202 lines not on this page · raw message

include/quota.h +8 -8
index f578621fa2b4..627a86f6421f 100644
@@ -46,18 +46,18 @@ enum quota_type {
 
 #pragma pack(push, 1)
 struct v2_disk_dqheader {
-	u_int32_t dqh_magic;	/* Magic number identifying file */
-	u_int32_t dqh_version;	/* File version */
+	uint32_t dqh_magic;	/* Magic number identifying file */
+	uint32_t dqh_version;	/* File version */
 } __attribute__ ((packed));
 
 /* Header with type and version specific information */
 struct v2_disk_dqinfo {
-	u_int32_t dqi_bgrace;	/* Time before block soft limit becomes hard limit */
-	u_int32_t dqi_igrace;	/* Time before inode soft limit becomes hard limit */
-	u_int32_t dqi_flags;	/* Flags for quotafile (DQF_*) */
-	u_int32_t dqi_blocks;	/* Number of blocks in file */
-	u_int32_t dqi_free_blk;	/* Number of first free block in the list */
-	u_int32_t dqi_free_entry;	/* Number of block with at least one free entry */
+	uint32_t dqi_bgrace;	/* Time before block soft limit becomes hard limit */
+	uint32_t dqi_igrace;	/* Time before inode soft limit becomes hard limit */
+	uint32_t dqi_flags;	/* Flags for quotafile (DQF_*) */
+	uint32_t dqi_blocks;	/* Number of blocks in file */
+	uint32_t dqi_free_blk;	/* Number of first free block in the list */
+	uint32_t dqi_free_entry;	/* Number of block with at least one free entry */
 } __attribute__ ((packed));
 
 struct v2r1_disk_dqblk {
lib/libf2fs.c +11 -11
index 94fb91d46d28..b0a892772de1 100644
@@ -104,7 +104,7 @@ static const char *utf8_to_wchar(const char *input, wchar_t *wc,
 	return NULL;
 }
 
-static u_int16_t *wchar_to_utf16(u_int16_t *output, wchar_t wc, size_t outsize)
+static uint16_t *wchar_to_utf16(uint16_t *output, wchar_t wc, size_t outsize)
 {
 	if (wc <= 0xffff) {
 		if (outsize == 0)
@@ -120,11 +120,11 @@ static u_int16_t *wchar_to_utf16(u_int16_t *output, wchar_t wc, size_t outsize)
 	return output + 2;
 }
 
-int utf8_to_utf16(u_int16_t *output, const char *input, size_t outsize,
+int utf8_to_utf16(uint16_t *output, const char *input, size_t outsize,
 		size_t insize)
 {
 	const char *inp = input;
-	u_int16_t *outp = output;
+	uint16_t *outp = output;
 	wchar_t wc;
 
 	while ((size_t)(inp - input) < insize && *inp) {
@@ -143,7 +143,7 @@ int utf8_to_utf16(u_int16_t *output, const char *input, size_t outsize,
 	return 0;
 }
 
-static const u_int16_t *utf16_to_wchar(const u_int16_t *input, wchar_t *wc,
+static const uint16_t *utf16_to_wchar(const uint16_t *input, wchar_t *wc,
 		size_t insize)
 {
 	if ((le16_to_cpu(input[0]) & 0xfc00) == 0xd800) {
@@ -206,10 +206,10 @@ static char *wchar_to_utf8(char *output, wchar_t wc, size_t outsize)
 	return output;
 }
 
-int utf16_to_utf8(char *output, const u_int16_t *input, size_t outsize,
+int utf16_to_utf8(char *output, const uint16_t *input, size_t outsize,
 		size_t insize)
 {
-	const u_int16_t *inp = input;
+	const uint16_t *inp = input;
 	char *outp = output;
 	wchar_t wc;
 
@@ -229,7 +229,7 @@ int utf16_to_utf8(char *output, const u_int16_t *input, size_t outsize,
 	return 0;
 }
 
-int log_base_2(u_int32_t num)
+int log_base_2(uint32_t num)
 {
 	int ret = 0;
 	if (num <= 0 || (num & (num - 1)) != 0)
@@ -530,7 +530,7 @@ unsigned int f2fs_max_file_offset(struct f2fs_inode *i)
  */
 #define CRCPOLY_LE 0xedb88320
 
-u_int32_t f2fs_cal_crc32(u_int32_t crc, void *buf, int len)
+uint32_t f2fs_cal_crc32(uint32_t crc, void *buf, int len)
 {
 	int i;
 	unsigned char *p = (unsigned char *)buf;
@@ -542,9 +542,9 @@ u_int32_t f2fs_cal_crc32(u_int32_t crc, void *buf, int len)
 	return crc;
 }
 
-int f2fs_crc_valid(u_int32_t blk_crc, void *buf, int len)
+int f2fs_crc_valid(uint32_t blk_crc, void *buf, int len)
 {
-	u_int32_t cal_crc = 0;
+	uint32_t cal_crc = 0;
 
 	cal_crc = f2fs_cal_crc32(F2FS_SUPER_MAGIC, buf, len);
 
@@ -1197,7 +1197,7 @@ int f2fs_get_f2fs_info(void)
 		c.devices[0].total_sectors = c.total_sectors;
 	}
 	if (c.total_sectors * c.sector_size >
-		(u_int64_t)F2FS_MAX_SEGMENT * 2 * 1024 * 1024) {
+		(uint64_t)F2FS_MAX_SEGMENT * 2 * 1024 * 1024) {
 		MSG(0, "\tError: F2FS can support 16TB at most!!!\n");
 		return -1;
 	}
lib/libf2fs_io.c +2 -2
index 320ee6c431f0..b985e6f37a0a 100644
@@ -43,7 +43,7 @@ struct f2fs_configuration c;
 #include <sparse/sparse.h>
 struct sparse_file *f2fs_sparse_file;
 static char **blocks;
-u_int64_t blocks_count;
+uint64_t blocks_count;
 static char *zeroed_block;
 #endif
 
@@ -661,7 +661,7 @@ int f2fs_init_sparse_file(void)
 			return -1;
 
 		c.device_size = sparse_file_len(f2fs_sparse_file, 0, 0);
-		c.device_size &= (~((u_int64_t)(F2FS_BLKSIZE - 1)));
+		c.device_size &= (~((uint64_t)(F2FS_BLKSIZE - 1)));
 	}
 
 	if (sparse_file_block_size(f2fs_sparse_file) != F2FS_BLKSIZE) {
lib/libf2fs_zoned.c +8 -8
index ce73b9af66ec..c408a4991fa1 100644
@@ -192,7 +192,7 @@ int f2fs_get_zone_blocks(int i)
 	return 0;
 }
 
-int f2fs_report_zone(int i, u_int64_t sector, void *blkzone)
+int f2fs_report_zone(int i, uint64_t sector, void *blkzone)
 {
 	struct blk_zone *blkz = (struct blk_zone *)blkzone;
 	struct blk_zone_report *rep;
@@ -227,9 +227,9 @@ int f2fs_report_zones(int j, report_zones_cb_t *report_zones_cb, void *opaque)
 	struct blk_zone_report *rep;
 	struct blk_zone *blkz;
 	unsigned int i, n = 0;
-	u_int64_t total_sectors = (dev->total_sectors * c.sector_size)
+	uint64_t total_sectors = (dev->total_sectors * c.sector_size)
 		>> SECTOR_SHIFT;
-	u_int64_t sector = 0;
+	uint64_t sector = 0;
 	int ret = -1;
 
 	rep = malloc(F2FS_REPORT_ZONES_BUFSZ);
@@ -280,8 +280,8 @@ int f2fs_check_zones(int j)
 	struct blk_zone_report *rep;
 	struct blk_zone *blkz;
 	unsigned int i, n = 0;
-	u_int64_t total_sectors;
-	u_int64_t sector;
+	uint64_t total_sectors;
+	uint64_t sector;
 	int last_is_conv = 1;
 	int ret = -1;
 
@@ -433,8 +433,8 @@ int f2fs_reset_zones(int j)
 	struct blk_zone_report *rep;
 	struct blk_zone *blkz;
 	struct blk_zone_range range;
-	u_int64_t total_sectors;
-	u_int64_t sector;
+	uint64_t total_sectors;
+	uint64_t sector;
 	unsigned int i;
 	int ret = -1;
 
@@ -522,7 +522,7 @@ uint32_t f2fs_get_usable_segments(struct f2fs_super_block *sb)
 
 #else
 
-int f2fs_report_zone(int i, u_int64_t UNUSED(sector), void *UNUSED(blkzone))
+int f2fs_report_zone(int i, uint64_t UNUSED(sector), void *UNUSED(blkzone))
 {
 	ERR_MSG("%d: Unsupported zoned block device\n", i);
 	return -1;
mkfs/f2fs_format.c +40 -40

171 lines not on this page · raw message

mkfs/f2fs_format_main.c +1 -1
index 797e90a948f5..d05d4e2cb4e5 100644
@@ -253,7 +253,7 @@ static void f2fs_parse_options(int argc, char *argv[])
 			break;
 		case 'S':
 			c.device_size = atoll(optarg);
-			c.device_size &= (~((u_int64_t)(F2FS_BLKSIZE - 1)));
+			c.device_size &= (~((uint64_t)(F2FS_BLKSIZE - 1)));
 			c.sparse_mode = 1;
 			break;
 		case 'z':
mkfs/f2fs_format_utils.c +1 -1
index f2d55adb7e4b..e84311ae1287 100644
@@ -52,7 +52,7 @@ static int trim_device(int i)
 	unsigned long long range[2];
 	struct stat *stat_buf;
 	struct device_info *dev = c.devices + i;
-	u_int64_t bytes = dev->total_sectors * dev->sector_size;
+	uint64_t bytes = dev->total_sectors * dev->sector_size;
 	int fd = dev->fd;
 
 	stat_buf = malloc(sizeof(struct stat));
mkfs/f2fs_format_utils.h +1 -1
index 274db7bff5db..807e7c327601 100644
@@ -12,6 +12,6 @@
 
 extern struct f2fs_configuration c;
 
-int f2fs_trim_device(int, u_int64_t);
+int f2fs_trim_device(int, uint64_t);
 int f2fs_trim_devices(void);
 int f2fs_format_device(void);
tools/f2fs_io/f2fs_io.h +4 -4
index cdaf00f421fe..bd8db0b724e5 100644
@@ -30,10 +30,10 @@
 # define UNUSED(x) x
 #endif
 
-typedef u_int64_t	u64;
-typedef u_int32_t	u32;
-typedef u_int16_t	u16;
-typedef u_int8_t	u8;
+typedef uint64_t	u64;
+typedef uint32_t	u32;
+typedef uint16_t	u16;
+typedef uint8_t		u8;
 
 #ifndef HAVE_LINUX_TYPES_H
 typedef u8	__u8;

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

#7 lore raw

PATCH 7/31 Change the ANDROID_WINDOWS_HOST macro into _WIN32

In reply to Bart Van Assche

This makes it easier to build f2fs-tools for Windows.

---
 lib/libf2fs.c            | 10 +++++-----
 lib/libf2fs_io.c         |  6 +++---
 lib/libf2fs_zoned.c      |  2 +-
 mkfs/f2fs_format.c       |  2 +-
 mkfs/f2fs_format_main.c  |  2 +-
 mkfs/f2fs_format_utils.c |  4 ++--
 6 files changed, 13 insertions(+), 13 deletions(-)
lib/libf2fs.c +5 -5
index b0a892772de1..c7102528f2f4 100644
@@ -22,7 +22,7 @@
 #endif
 #include <time.h>
 #include <sys/stat.h>
-#ifndef ANDROID_WINDOWS_HOST
+#ifndef _WIN32
 #include <sys/mount.h>
 #include <sys/ioctl.h>
 #endif
@@ -49,7 +49,7 @@
 #define MODELINQUIRY	0x12,0x00,0x00,0x00,0x4A,0x00
 #endif
 
-#ifndef ANDROID_WINDOWS_HOST /* O_BINARY is windows-specific flag */
+#ifndef _WIN32 /* O_BINARY is windows-specific flag */
 #define O_BINARY 0
 #else
 /* On Windows, wchar_t is 8 bit sized and it causes compilation errors. */
@@ -606,7 +606,7 @@ int write_inode(struct f2fs_node *inode, u64 blkaddr)
  */
 char *get_rootdev()
 {
-#if defined(ANDROID_WINDOWS_HOST) || defined(WITH_ANDROID)
+#if defined(_WIN32) || defined(WITH_ANDROID)
 	return NULL;
 #else
 	struct stat sb;
@@ -740,7 +740,7 @@ static int is_mounted(const char *mpt, const char *device)
 
 int f2fs_dev_is_umounted(char *path)
 {
-#ifdef ANDROID_WINDOWS_HOST
+#ifdef _WIN32
 	return 0;
 #else
 	struct stat *st_buf;
@@ -872,7 +872,7 @@ void get_kernel_uname_version(__u8 *version)
 #define BLKSSZGET	DKIOCGETBLOCKCOUNT
 #endif /* APPLE_DARWIN */
 
-#ifndef ANDROID_WINDOWS_HOST
+#ifndef _WIN32
 static int open_check_fs(char *path, int flag)
 {
 	if (c.func != DUMP && (c.func != FSCK || c.fix_on || c.auto_fix))
lib/libf2fs_io.c +3 -3
index b985e6f37a0a..bf6dfe240bb7 100644
@@ -23,7 +23,7 @@
 #include <mntent.h>
 #endif
 #include <time.h>
-#ifndef ANDROID_WINDOWS_HOST
+#ifndef _WIN32
 #include <sys/stat.h>
 #include <sys/mount.h>
 #include <sys/ioctl.h>
@@ -634,7 +634,7 @@ int dev_reada_block(__u64 blk_addr)
 
 int f2fs_fsync_device(void)
 {
-#ifndef ANDROID_WINDOWS_HOST
+#ifndef _WIN32
 	int i;
 
 	for (i = 0; i < c.ndevs; i++) {
@@ -783,7 +783,7 @@ int f2fs_finalize_device(void)
 	 * in the block device page cache.
 	 */
 	for (i = 0; i < c.ndevs; i++) {
-#ifndef ANDROID_WINDOWS_HOST
+#ifndef _WIN32
 		ret = fsync(c.devices[i].fd);
 		if (ret < 0) {
 			MSG(0, "\tError: Could not conduct fsync!!!\n");
lib/libf2fs_zoned.c +1 -1
index c408a4991fa1..cb954feabe61 100644
@@ -22,7 +22,7 @@
 #ifdef HAVE_LINUX_LIMITS_H
 #include <linux/limits.h>
 #endif
-#ifndef ANDROID_WINDOWS_HOST
+#ifndef _WIN32
 #include <sys/ioctl.h>
 #endif
 #include <libgen.h>
mkfs/f2fs_format.c +1 -1
index 8bd33ac003c5..332abf60d0d9 100644
@@ -13,7 +13,7 @@
 #include <fcntl.h>
 #include <string.h>
 #include <unistd.h>
-#ifndef ANDROID_WINDOWS_HOST
+#ifndef _WIN32
 #include <sys/stat.h>
 #include <sys/mount.h>
 #endif
mkfs/f2fs_format_main.c +1 -1
index d05d4e2cb4e5..ecc942b61d63 100644
@@ -15,7 +15,7 @@
 #include <stdbool.h>
 #include <unistd.h>
 #include <sys/stat.h>
-#ifndef ANDROID_WINDOWS_HOST
+#ifndef _WIN32
 #include <sys/mount.h>
 #endif
 #include <time.h>
mkfs/f2fs_format_utils.c +2 -2
index e84311ae1287..53101d1bd790 100644
@@ -26,7 +26,7 @@
 #include <unistd.h>
 #include <stdlib.h>
 #include <stdbool.h>
-#ifndef ANDROID_WINDOWS_HOST
+#ifndef _WIN32
 #include <sys/ioctl.h>
 #endif
 #include <sys/stat.h>
@@ -48,7 +48,7 @@
 
 static int trim_device(int i)
 {
-#ifndef ANDROID_WINDOWS_HOST
+#ifndef _WIN32
 	unsigned long long range[2];
 	struct stat *stat_buf;
 	struct device_info *dev = c.devices + i;

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

#8 lore raw

Re: [f2fs-dev] [PATCH 07/31] Change the ANDROID_WINDOWS_HOST macro into _WIN32

Fixed a missing resolution from [PATCH 06/31].

In include/f2fs_fs.h,

71 #ifdef ANDROID_WINDOWS_HOST
72 #undef HAVE_LINUX_TYPES_H
73 #endif

Quoted 145 lines · Bart Van Assche

This makes it easier to build f2fs-tools for Windows.

---
 lib/libf2fs.c            | 10 +++++-----
 lib/libf2fs_io.c         |  6 +++---
 lib/libf2fs_zoned.c      |  2 +-
 mkfs/f2fs_format.c       |  2 +-
 mkfs/f2fs_format_main.c  |  2 +-
 mkfs/f2fs_format_utils.c |  4 ++--
 6 files changed, 13 insertions(+), 13 deletions(-)
lib/libf2fs.c +5 -5
index b0a892772de1..c7102528f2f4 100644
@@ -22,7 +22,7 @@
 #endif
 #include <time.h>
 #include <sys/stat.h>
-#ifndef ANDROID_WINDOWS_HOST
+#ifndef _WIN32
 #include <sys/mount.h>
 #include <sys/ioctl.h>
 #endif
@@ -49,7 +49,7 @@
 #define MODELINQUIRY	0x12,0x00,0x00,0x00,0x4A,0x00
 #endif
 
-#ifndef ANDROID_WINDOWS_HOST /* O_BINARY is windows-specific flag */
+#ifndef _WIN32 /* O_BINARY is windows-specific flag */
 #define O_BINARY 0
 #else
 /* On Windows, wchar_t is 8 bit sized and it causes compilation errors. */
@@ -606,7 +606,7 @@ int write_inode(struct f2fs_node *inode, u64 blkaddr)
  */
 char *get_rootdev()
 {
-#if defined(ANDROID_WINDOWS_HOST) || defined(WITH_ANDROID)
+#if defined(_WIN32) || defined(WITH_ANDROID)
 	return NULL;
 #else
 	struct stat sb;
@@ -740,7 +740,7 @@ static int is_mounted(const char *mpt, const char *device)
 
 int f2fs_dev_is_umounted(char *path)
 {
-#ifdef ANDROID_WINDOWS_HOST
+#ifdef _WIN32
 	return 0;
 #else
 	struct stat *st_buf;
@@ -872,7 +872,7 @@ void get_kernel_uname_version(__u8 *version)
 #define BLKSSZGET	DKIOCGETBLOCKCOUNT
 #endif /* APPLE_DARWIN */
 
-#ifndef ANDROID_WINDOWS_HOST
+#ifndef _WIN32
 static int open_check_fs(char *path, int flag)
 {
 	if (c.func != DUMP && (c.func != FSCK || c.fix_on || c.auto_fix))
lib/libf2fs_io.c +3 -3
index b985e6f37a0a..bf6dfe240bb7 100644
@@ -23,7 +23,7 @@
 #include <mntent.h>
 #endif
 #include <time.h>
-#ifndef ANDROID_WINDOWS_HOST
+#ifndef _WIN32
 #include <sys/stat.h>
 #include <sys/mount.h>
 #include <sys/ioctl.h>
@@ -634,7 +634,7 @@ int dev_reada_block(__u64 blk_addr)
 
 int f2fs_fsync_device(void)
 {
-#ifndef ANDROID_WINDOWS_HOST
+#ifndef _WIN32
 	int i;
 
 	for (i = 0; i < c.ndevs; i++) {
@@ -783,7 +783,7 @@ int f2fs_finalize_device(void)
 	 * in the block device page cache.
 	 */
 	for (i = 0; i < c.ndevs; i++) {
-#ifndef ANDROID_WINDOWS_HOST
+#ifndef _WIN32
 		ret = fsync(c.devices[i].fd);
 		if (ret < 0) {
 			MSG(0, "\tError: Could not conduct fsync!!!\n");
lib/libf2fs_zoned.c +1 -1
index c408a4991fa1..cb954feabe61 100644
@@ -22,7 +22,7 @@
 #ifdef HAVE_LINUX_LIMITS_H
 #include <linux/limits.h>
 #endif
-#ifndef ANDROID_WINDOWS_HOST
+#ifndef _WIN32
 #include <sys/ioctl.h>
 #endif
 #include <libgen.h>
mkfs/f2fs_format.c +1 -1
index 8bd33ac003c5..332abf60d0d9 100644
@@ -13,7 +13,7 @@
 #include <fcntl.h>
 #include <string.h>
 #include <unistd.h>
-#ifndef ANDROID_WINDOWS_HOST
+#ifndef _WIN32
 #include <sys/stat.h>
 #include <sys/mount.h>
 #endif
mkfs/f2fs_format_main.c +1 -1
index d05d4e2cb4e5..ecc942b61d63 100644
@@ -15,7 +15,7 @@
 #include <stdbool.h>
 #include <unistd.h>
 #include <sys/stat.h>
-#ifndef ANDROID_WINDOWS_HOST
+#ifndef _WIN32
 #include <sys/mount.h>
 #endif
 #include <time.h>
mkfs/f2fs_format_utils.c +1 -1
index e84311ae1287..53101d1bd790 100644
@@ -26,7 +26,7 @@
 #include <unistd.h>
 #include <stdlib.h>
 #include <stdbool.h>
-#ifndef ANDROID_WINDOWS_HOST
+#ifndef _WIN32
 #include <sys/ioctl.h>
 #endif
 #include <sys/stat.h>

mkfs/f2fs_format_utils.c line 54

Quoted 8 lines
mkfs/f2fs_format_utils.c +1 -1
@@ -48,7 +48,7 @@
 
 static int trim_device(int i)
 {
-#ifndef ANDROID_WINDOWS_HOST
+#ifndef _WIN32
 	unsigned long long range[2];
 	struct stat *stat_buf;
 	struct device_info *dev = c.devices + i;

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

#9 lore raw

PATCH 8/31 ci: Build f2fstools upon push and pull requests

In reply to Bart Van Assche

For those who use Github to contribute f2fs-tools patches, let the github servers build the f2fs-tools source code upon every push and pull requests. This change does not affect users who do not use Github.

---
 .github/workflows/ci.yml | 70 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 70 insertions(+)
 create mode 100644 .github/workflows/ci.yml
.github/workflows/ci.yml new file +70 -0
new file mode 100644
index 000000000000..0c774f92fac8
@@ -0,0 +1,70 @@
+# See also https://docs.github.com/en/actions/learn-github-actions/expressions
+# See also https://github.com/marketplace/actions/setup-android-ndk
+
+name: CI
+
+on: [push, pull_request]
+
+jobs:
+  build:
+    runs-on: ubuntu-latest
+    strategy:
+      fail-fast: false
+      matrix:
+        build:
+        - android
+        - linux-gcc
+        - linux-clang
+        - linux-x86-gcc
+        - linux-powerpc64-gcc
+        - linux-mingw64-gcc
+        - macos
+        include:
+        - build: android
+          cc: clang
+          host: aarch64-linux-android32
+        - build: linux-gcc
+          cc: gcc
+        - build: linux-clang
+          cc: clang
+        - build: linux-x86-gcc
+          cc: gcc
+          arch: x86
+        - build: linux-powerpc64-gcc
+          cc: gcc
+          host: powerpc64-linux-gnu
+        - build: linux-mingw64-gcc
+          cc: gcc
+          host: x86_64-w64-mingw32
+          cflags: -D__USE_MINGW_ANSI_STDIO
+        - build: macos
+          cc: clang
+          os: macos-latest
+    steps:
+      - uses: actions/checkout@v3
+      - name: Install Android NDK
+        run: |
+          if [ ${{matrix.build}} = android ]; then \
+              wget --quiet https://dl.google.com/android/repository/android-ndk-r24-linux.zip; \
+              unzip -q android-ndk-r24-linux.zip;  \
+          fi
+      - name: Install Ubuntu packages
+        run: |
+          sudo apt-get -q update
+          case "${{matrix.host}}" in                                        \
+            x86_64-w64-mingw32)                                             \
+              sudo apt-get -q install -y binutils-mingw-w64 gcc-mingw-w64;; \
+            powerpc64-linux-gnu)                                            \
+              sudo apt-get -q install -y binutils-powerpc64-linux-gnu       \
+              gcc-powerpc64-linux-gnu;;                                     \
+          esac
+      - name: Build
+        run: |
+          echo "HOST=${{matrix.host}}"
+          NDK=$PWD/android-ndk-r24/toolchains/llvm/prebuilt/linux-x86_64/bin
+          export PATH="$NDK:$PATH"
+          ./autogen.sh
+          ./configure --host=${{matrix.host}} \
+              CC=${{ matrix.host && format('{0}-{1}', matrix.host, matrix.cc) || matrix.cc }} \
+              CFLAGS="${{matrix.cflags}}"
+          make -j$(nproc)

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

#10 lore raw

PATCH 9/31 Change one array member into a flexible array member

In reply to Bart Van Assche

Prepare for verifying structure sizes with static_assert().

---
 fsck/f2fs.h       | 4 ++--
 include/f2fs_fs.h | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
fsck/f2fs.h +2 -2
index 7fb328ff8861..eacfd42478b8 100644
@@ -381,7 +381,7 @@ static inline void *__bitmap_ptr(struct f2fs_sb_info *sbi, int flag)
 					CP_MIN_CHKSUM_OFFSET)
 			chksum_size = sizeof(__le32);
 
-		return &ckpt->sit_nat_version_bitmap + offset + chksum_size;
+		return &ckpt->sit_nat_version_bitmap[offset + chksum_size];
 	}
 
 	if (le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_payload) > 0) {
@@ -392,7 +392,7 @@ static inline void *__bitmap_ptr(struct f2fs_sb_info *sbi, int flag)
 	} else {
 		offset = (flag == NAT_BITMAP) ?
 			le32_to_cpu(ckpt->sit_ver_bitmap_bytesize) : 0;
-		return &ckpt->sit_nat_version_bitmap + offset;
+		return &ckpt->sit_nat_version_bitmap[offset];
 	}
 }
 
include/f2fs_fs.h +1 -1
index 1e38d93ff40d..e6fc8a0e08f6 100644
@@ -832,7 +832,7 @@ struct f2fs_checkpoint {
 	unsigned char alloc_type[MAX_ACTIVE_LOGS];
 
 	/* SIT and NAT version bitmap */
-	unsigned char sit_nat_version_bitmap[1];
+	unsigned char sit_nat_version_bitmap[];
 } __attribute__((packed));
 
 #define CP_BITMAP_OFFSET	\

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

#11 lore raw

PATCH 10/31 Verify structure sizes at compile time

In reply to Bart Van Assche

Before modifying the __attribute__((packed)) annotations, let the compiler verify the sizes of on-disk data structures.

---
 fsck/quotaio.c      |  2 ++
 fsck/quotaio_tree.h |  2 ++
 fsck/quotaio_v2.h   |  6 +++++
 fsck/xattr.h        |  2 ++
 include/f2fs_fs.h   | 54 +++++++++++++++++++++++++++++++++++++++++++++
 include/quota.h     |  7 ++++++
 tools/f2fscrypt.c   |  4 ++++
 7 files changed, 77 insertions(+)
fsck/quotaio.c +2 -0
index 51abbb7b2c57..52e962432c72 100644
@@ -33,6 +33,8 @@ struct disk_dqheader {
 	__le32 dqh_version;
 } __attribute__ ((packed));
 
+static_assert(sizeof(struct disk_dqheader) == 8, "");
+
 int cur_qtype = -1;
 u32 qf_last_blkofs[MAXQUOTAS] = {0, 0, 0};
 enum qf_szchk_type_t qf_szchk_type[MAXQUOTAS] =
fsck/quotaio_tree.h +2 -0
index 8f4dae054691..b88c55c01d5c 100644
@@ -35,6 +35,8 @@ struct qt_disk_dqdbheader {
 	__le32 dqdh_pad2;
 } __attribute__ ((packed));
 
+static_assert(sizeof(struct qt_disk_dqdbheader) == 16, "");
+
 struct dquot;
 struct quota_handle;
 
fsck/quotaio_v2.h +6 -0
index de2db2785cb0..a37300d78bd0 100644
@@ -20,6 +20,8 @@ struct v2_disk_dqheader {
 	__le32 dqh_version;	/* File version */
 } __attribute__ ((packed));
 
+static_assert(sizeof(struct v2_disk_dqheader) == 8, "");
+
 /* Flags for version specific files */
 #define V2_DQF_MASK  0x0000	/* Mask for all valid ondisk flags */
 
@@ -36,6 +38,8 @@ struct v2_disk_dqinfo {
 					 * free entry */
 } __attribute__ ((packed));
 
+static_assert(sizeof(struct v2_disk_dqinfo) == 24, "");
+
 struct v2r1_disk_dqblk {
 	__le32 dqb_id;	/* id this quota applies to */
 	__le32 dqb_pad;
@@ -51,4 +55,6 @@ struct v2r1_disk_dqblk {
 	__le64 dqb_itime;	/* time limit for excessive inode use */
 } __attribute__ ((packed));
 
+static_assert(sizeof(struct v2r1_disk_dqblk) == 72, "");
+
 #endif
fsck/xattr.h +2 -0
index 579ab6c42585..5709a7df7adb 100644
@@ -47,6 +47,8 @@ struct fscrypt_context {
 	u8 nonce[FS_KEY_DERIVATION_NONCE_SIZE];
 } __attribute__((packed));
 
+static_assert(sizeof(struct fscrypt_context) == 28, "");
+
 #define F2FS_ACL_VERSION	0x0001
 
 struct f2fs_acl_entry {
include/f2fs_fs.h +54 -0

199 lines not on this page · raw message

include/quota.h +7 -0
index 627a86f6421f..5b7aaa891d28 100644
@@ -50,6 +50,8 @@ struct v2_disk_dqheader {
 	uint32_t dqh_version;	/* File version */
 } __attribute__ ((packed));
 
+static_assert(sizeof(struct v2_disk_dqheader) == 8, "");
+
 /* Header with type and version specific information */
 struct v2_disk_dqinfo {
 	uint32_t dqi_bgrace;	/* Time before block soft limit becomes hard limit */
@@ -60,6 +62,8 @@ struct v2_disk_dqinfo {
 	uint32_t dqi_free_entry;	/* Number of block with at least one free entry */
 } __attribute__ ((packed));
 
+static_assert(sizeof(struct v2_disk_dqinfo) == 24, "");
+
 struct v2r1_disk_dqblk {
 	__le32 dqb_id;  	/* id this quota applies to */
 	__le32 dqb_pad;
@@ -74,6 +78,9 @@ struct v2r1_disk_dqblk {
 	__le64 dqb_btime;       /* time limit for excessive disk use */
 	__le64 dqb_itime;       /* time limit for excessive inode use */
 } __attribute__ ((packed));
+
+static_assert(sizeof(struct v2r1_disk_dqblk) == 72, "");
+
 #pragma pack(pop)
 
 #endif
tools/f2fscrypt.c +4 -0
index fe3e0ff3c1a9..97624ba5e185 100644
@@ -104,6 +104,8 @@ struct f2fs_fscrypt_policy {
 	__u8 master_key_descriptor[F2FS_KEY_DESCRIPTOR_SIZE];
 } __attribute__((packed));
 
+static_assert(sizeof(struct f2fs_fscrypt_policy) == 12, "");
+
 #define F2FS_IOC_SET_ENCRYPTION_POLICY	_IOR('f', 19, struct f2fs_fscrypt_policy)
 #define F2FS_IOC_GET_ENCRYPTION_PWSALT	_IOW('f', 20, __u8[16])
 #define F2FS_IOC_GET_ENCRYPTION_POLICY	_IOW('f', 21, struct f2fs_fscrypt_policy)
@@ -121,6 +123,8 @@ struct f2fs_encryption_key {
         __u32 size;
 } __attribute__((__packed__));
 
+static_assert(sizeof(struct f2fs_encryption_key) == 72, "");
+
 int options;
 
 extern void f2fs_sha512(const unsigned char *in, unsigned long in_size,

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

#12 lore raw

Re: [f2fs-dev] [PATCH 10/31] Verify structure sizes at compile time

Hi Bart,

Quoted 1 line · Bart Van Assche

+static_assert(sizeof(struct f2fs_dentry_block) == 4096, "");

I noticed that this static_assert fails when PAGE_SIZE is defined to a value other than 4096.

I have to admit to being unfamiliar with f2fs. Is this an on-disk data structure? If so, does it mean that non-4K page size kernels are unable to mount f2fs file systems if the f2fs-tools were not built with a matching PAGE_SIZE define?

In any event, maybe s/4096/PAGE_SIZE/g above is the correct fix for now?

Peter

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

#13 lore raw

Re: [f2fs-dev] [PATCH 10/31] Verify structure sizes at compile time

Quoted 6 lines · Peter Collingbourne
Quoted 1 line · Bart Van Assche

+static_assert(sizeof(struct f2fs_dentry_block) == 4096, "");

I noticed that this static_assert fails when PAGE_SIZE is defined to a value other than 4096.

Quoted 7 lines

I have to admit to being unfamiliar with f2fs. Is this an on-disk data structure? If so, does it mean that non-4K page size kernels are unable to mount f2fs file systems if the f2fs-tools were not built with a matching PAGE_SIZE define?

In any event, maybe s/4096/PAGE_SIZE/g above is the correct fix for now?

Hi Peter,

How this issue should be fixed depends on whether or not f2fs_dentry_block is an on-disk data structure. I'm not sure about the answer. Jaegeuk, can you help with answering this question?

Thanks,

Bart.

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

#14 lore raw

PATCH 11/31 Suppress a compiler warning

In reply to Bart Van Assche

Suppress the following compiler warning:

segment.c:698:12: warning: ‘n’ may be used uninitialized in this function [-Wmaybe-uninitialized]
698 | if (n < 0)
| ^

---
 fsck/segment.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fsck/segment.c +1 -1
index fe63615423f7..254a0d1425e9 100644
@@ -555,7 +555,7 @@ exit:
 
 int f2fs_build_file(struct f2fs_sb_info *sbi, struct dentry *de)
 {
-	int fd, n;
+	int fd, n = -1;
 	pgoff_t off = 0;
 	u8 buffer[BLOCK_SZ];
 	struct node_info ni;

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

#15 lore raw

PATCH 12/31 f2fs_fs.h: Use standard fixed width integer types

In reply to Bart Van Assche

Use uint64_t instead of __u64 in the definitions of the endianness conversion macros. This patch fixes the following compiler warning:

dir.c: In function ‘f2fs_create’:
dir.c:785:16: warning: format ‘%lx’ expects argument of type ‘long unsigned int’, but argument 12 has type ‘long long unsigned int’ [-Wformat=]
785 | MSG(1, "Info: Create %s -> %s\n"

      |                ^~~~~~~~~~~~~~~~~~~~~~~~~

../include/f2fs_fs.h:252:32: note: in definition of macro ‘MSG’
252 | printf(fmt, ##__VA_ARGS__); \
| ^~~

---
 fsck/mount.c      |  2 +-
 include/f2fs_fs.h | 16 ++++++++--------
 2 files changed, 9 insertions(+), 9 deletions(-)
fsck/mount.c +1 -1
index f15260e02cab..e075d3184f83 100644
@@ -250,7 +250,7 @@ void print_inode_info(struct f2fs_sb_info *sbi,
 		MSG(0, " - File name         : %s%s\n", en,
 				enc_name ? " <encrypted>" : "");
 		setlocale(LC_ALL, "");
-		MSG(0, " - File size         : %'llu (bytes)\n",
+		MSG(0, " - File size         : %'" PRIu64 " (bytes)\n",
 				le64_to_cpu(inode->i_size));
 		return;
 	}
include/f2fs_fs.h +8 -8
index 7804dd158de4..cfd3b711f288 100644
@@ -188,12 +188,12 @@ static inline uint64_t bswap_64(uint64_t val)
 #endif
 
 #if __BYTE_ORDER == __LITTLE_ENDIAN
-#define le16_to_cpu(x)	((__u16)(x))
-#define le32_to_cpu(x)	((__u32)(x))
-#define le64_to_cpu(x)	((__u64)(x))
-#define cpu_to_le16(x)	((__u16)(x))
-#define cpu_to_le32(x)	((__u32)(x))
-#define cpu_to_le64(x)	((__u64)(x))
+#define le16_to_cpu(x)	((uint16_t)(x))
+#define le32_to_cpu(x)	((uint32_t)(x))
+#define le64_to_cpu(x)	((uint64_t)(x))
+#define cpu_to_le16(x)	((uint16_t)(x))
+#define cpu_to_le32(x)	((uint32_t)(x))
+#define cpu_to_le64(x)	((uint64_t)(x))
 #elif __BYTE_ORDER == __BIG_ENDIAN
 #define le16_to_cpu(x)	bswap_16(x)
 #define le32_to_cpu(x)	bswap_32(x)
@@ -291,10 +291,10 @@ static inline uint64_t bswap_64(uint64_t val)
 	do {								\
 		assert(sizeof((ptr)->member) == 8);			\
 		if (c.layout)						\
-			printf("%-30s %llu\n",				\
+			printf("%-30s %" PRIu64 "\n",			\
 			#member":", le64_to_cpu(((ptr)->member)));	\
 		else							\
-			printf("%-30s" "\t\t[0x%8llx : %llu]\n",	\
+			printf("%-30s" "\t\t[0x%8" PRIx64 " : %" PRIu64 "]\n",	\
 			#member, le64_to_cpu(((ptr)->member)),		\
 			le64_to_cpu(((ptr)->member)));			\
 	} while (0)

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

#16 lore raw

PATCH 13/31 Remove unnecessary __attribute__((packed)) annotations

In reply to Bart Van Assche

Applying the __attribute__((packed)) annotation to members that do not need it impacts performance negatively on architectures that do not support efficient unaligned accesses (e.g. ARMv7). Hence minimize the __attribute__((packed)) annotations.

See also CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS in the Linux kernel.

---
 fsck/quotaio.c      |  2 +-
 fsck/quotaio_tree.h |  2 +-
 fsck/quotaio_v2.h   |  6 +++---
 fsck/xattr.h        |  2 +-
 include/f2fs_fs.h   | 52 ++++++++++++++++++++++-----------------------
 include/quota.h     |  9 +++-----
 tools/f2fscrypt.c   |  4 ++--
 7 files changed, 37 insertions(+), 40 deletions(-)
fsck/quotaio.c +1 -1
index 52e962432c72..a3815b0c8835 100644
@@ -31,7 +31,7 @@ static const char * const extensions[MAXQUOTAS] = {
 struct disk_dqheader {
 	__le32 dqh_magic;
 	__le32 dqh_version;
-} __attribute__ ((packed));
+};
 
 static_assert(sizeof(struct disk_dqheader) == 8, "");
 
fsck/quotaio_tree.h +1 -1
index b88c55c01d5c..8072c6e188fd 100644
@@ -33,7 +33,7 @@ struct qt_disk_dqdbheader {
 	__le16 dqdh_entries; /* Number of valid entries in block */
 	__le16 dqdh_pad1;
 	__le32 dqdh_pad2;
-} __attribute__ ((packed));
+};
 
 static_assert(sizeof(struct qt_disk_dqdbheader) == 16, "");
 
fsck/quotaio_v2.h +3 -3
index a37300d78bd0..b054422f5a6e 100644
@@ -18,7 +18,7 @@
 struct v2_disk_dqheader {
 	__le32 dqh_magic;	/* Magic number identifying file */
 	__le32 dqh_version;	/* File version */
-} __attribute__ ((packed));
+};
 
 static_assert(sizeof(struct v2_disk_dqheader) == 8, "");
 
@@ -36,7 +36,7 @@ struct v2_disk_dqinfo {
 	__le32 dqi_free_blk;	/* Number of first free block in the list */
 	__le32 dqi_free_entry;	/* Number of block with at least one
 					 * free entry */
-} __attribute__ ((packed));
+};
 
 static_assert(sizeof(struct v2_disk_dqinfo) == 24, "");
 
@@ -53,7 +53,7 @@ struct v2r1_disk_dqblk {
 	__le64 dqb_curspace;	/* current space occupied (in bytes) */
 	__le64 dqb_btime;	/* time limit for excessive disk use */
 	__le64 dqb_itime;	/* time limit for excessive inode use */
-} __attribute__ ((packed));
+};
 
 static_assert(sizeof(struct v2r1_disk_dqblk) == 72, "");
 
fsck/xattr.h +1 -1
index 5709a7df7adb..4e4b50d47bd7 100644
@@ -45,7 +45,7 @@ struct fscrypt_context {
 	u8 flags;
 	u8 master_key_descriptor[FS_KEY_DESCRIPTOR_SIZE];
 	u8 nonce[FS_KEY_DERIVATION_NONCE_SIZE];
-} __attribute__((packed));
+};
 
 static_assert(sizeof(struct fscrypt_context) == 28, "");
 
include/f2fs_fs.h +26 -26

176 lines not on this page · raw message

include/quota.h +3 -6
index 5b7aaa891d28..f0eff71a9a26 100644
@@ -44,11 +44,10 @@ enum quota_type {
 
 #define QT_TREEOFF	1	/* Offset of tree in file in blocks */
 
-#pragma pack(push, 1)
 struct v2_disk_dqheader {
 	uint32_t dqh_magic;	/* Magic number identifying file */
 	uint32_t dqh_version;	/* File version */
-} __attribute__ ((packed));
+};
 
 static_assert(sizeof(struct v2_disk_dqheader) == 8, "");
 
@@ -60,7 +59,7 @@ struct v2_disk_dqinfo {
 	uint32_t dqi_blocks;	/* Number of blocks in file */
 	uint32_t dqi_free_blk;	/* Number of first free block in the list */
 	uint32_t dqi_free_entry;	/* Number of block with at least one free entry */
-} __attribute__ ((packed));
+};
 
 static_assert(sizeof(struct v2_disk_dqinfo) == 24, "");
 
@@ -77,10 +76,8 @@ struct v2r1_disk_dqblk {
 	__le64 dqb_curspace;    /* current space occupied (in bytes) */
 	__le64 dqb_btime;       /* time limit for excessive disk use */
 	__le64 dqb_itime;       /* time limit for excessive inode use */
-} __attribute__ ((packed));
+};
 
 static_assert(sizeof(struct v2r1_disk_dqblk) == 72, "");
 
-#pragma pack(pop)
-
 #endif
tools/f2fscrypt.c +2 -2
index 97624ba5e185..72bfb6467300 100644
@@ -102,7 +102,7 @@ struct f2fs_fscrypt_policy {
 	__u8 filenames_encryption_mode;
 	__u8 flags;
 	__u8 master_key_descriptor[F2FS_KEY_DESCRIPTOR_SIZE];
-} __attribute__((packed));
+};
 
 static_assert(sizeof(struct f2fs_fscrypt_policy) == 12, "");
 
@@ -121,7 +121,7 @@ struct f2fs_encryption_key {
         __u32 mode;
         char raw[F2FS_MAX_KEY_SIZE];
         __u32 size;
-} __attribute__((__packed__));
+};
 
 static_assert(sizeof(struct f2fs_encryption_key) == 72, "");
 

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

#17 lore raw

PATCH 14/31 Move the be32_to_cpu() definition

In reply to Bart Van Assche

Move the be32_to_cpu() definition next to the little endian conversion functions. This patch improves portability since the MinGW ntohl() function exists in another library than the C library.

---
 fsck/quotaio.h    | 2 --
 include/f2fs_fs.h | 2 ++
 2 files changed, 2 insertions(+), 2 deletions(-)
fsck/quotaio.h +0 -2
index 999e800f82c7..0024fe570727 100644
@@ -197,8 +197,6 @@ struct quotafile_ops {
 #define __force
 #endif
 
-#define be32_to_cpu(n) ntohl(n)
-
 /* Open existing quotafile of given type (and verify its format) on given
  * filesystem. */
 errcode_t quota_file_open(struct f2fs_sb_info *sbi, struct quota_handle *h,
include/f2fs_fs.h +2 -0
index 49438eb2e6f2..60b6dfced74b 100644
@@ -194,6 +194,7 @@ static inline uint64_t bswap_64(uint64_t val)
 #define cpu_to_le16(x)	((uint16_t)(x))
 #define cpu_to_le32(x)	((uint32_t)(x))
 #define cpu_to_le64(x)	((uint64_t)(x))
+#define be32_to_cpu(x)	__builtin_bswap64(x)
 #elif __BYTE_ORDER == __BIG_ENDIAN
 #define le16_to_cpu(x)	bswap_16(x)
 #define le32_to_cpu(x)	bswap_32(x)
@@ -201,6 +202,7 @@ static inline uint64_t bswap_64(uint64_t val)
 #define cpu_to_le16(x)	bswap_16(x)
 #define cpu_to_le32(x)	bswap_32(x)
 #define cpu_to_le64(x)	bswap_64(x)
+#define be32_to_cpu(x)	((uint64_t)(x))
 #endif
 
 #define typecheck(type,x) \

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

#18 lore raw

PATCH 15/31 Include <stddef.h> instead of defining offsetof()

In reply to Bart Van Assche

Prepare for enabling -Wmacro-redefined.

---
 fsck/f2fs.h       | 2 +-
 include/f2fs_fs.h | 5 +----
 2 files changed, 2 insertions(+), 5 deletions(-)
fsck/f2fs.h +1 -1
index eacfd42478b8..e5130ba19961 100644
@@ -15,6 +15,7 @@
 #include <unistd.h>
 #include <stdio.h>
 #include <stdbool.h>
+#include <stddef.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <string.h>
@@ -37,7 +38,6 @@
 		typecheck(unsigned long long, b) &&                     \
 		((long long)((a) - (b)) > 0))
 
-#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
 #define container_of(ptr, type, member) ({			\
 	const typeof(((type *)0)->member) * __mptr = (ptr);	\
 	(type *)((char *)__mptr - offsetof(type, member)); })
include/f2fs_fs.h +1 -4
index 60b6dfced74b..dd62bc89a926 100644
@@ -19,6 +19,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <stddef.h>
 #include <string.h>
 #include <time.h>
 #ifdef HAVE_CONFIG_H
@@ -914,10 +915,6 @@ static_assert(sizeof(struct f2fs_extent) == 12, "");
 #define F2FS_PIN_FILE		0x40	/* file should not be gced */
 #define F2FS_COMPRESS_RELEASED	0x80	/* file released compressed blocks */
 
-#if !defined(offsetof)
-#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
-#endif
-
 #define F2FS_EXTRA_ISIZE_OFFSET				\
 	offsetof(struct f2fs_inode, i_extra_isize)
 #define F2FS_TOTAL_EXTRA_ATTR_SIZE			\

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

#19 lore raw

PATCH 16/31 Use %zu to format size_t

In reply to Bart Van Assche

Use %zu to format size_t as required by the POSIX standards.

---
 fsck/mount.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fsck/mount.c +2 -2
index e075d3184f83..584385d682b5 100644
@@ -1429,7 +1429,7 @@ static int f2fs_early_init_nid_bitmap(struct f2fs_sb_info *sbi)
 
 	if (nats_in_cursum(journal) > NAT_JOURNAL_ENTRIES) {
 		MSG(0, "\tError: f2fs_init_nid_bitmap truncate n_nats(%u) to "
-			"NAT_JOURNAL_ENTRIES(%lu)\n",
+			"NAT_JOURNAL_ENTRIES(%zu)\n",
 			nats_in_cursum(journal), NAT_JOURNAL_ENTRIES);
 		journal->n_nats = cpu_to_le16(NAT_JOURNAL_ENTRIES);
 		c.fix_on = 1;
@@ -2381,7 +2381,7 @@ static int build_sit_entries(struct f2fs_sb_info *sbi)
 
 	if (sits_in_cursum(journal) > SIT_JOURNAL_ENTRIES) {
 		MSG(0, "\tError: build_sit_entries truncate n_sits(%u) to "
-			"SIT_JOURNAL_ENTRIES(%lu)\n",
+			"SIT_JOURNAL_ENTRIES(%zu)\n",
 			sits_in_cursum(journal), SIT_JOURNAL_ENTRIES);
 		journal->n_sits = cpu_to_le16(SIT_JOURNAL_ENTRIES);
 		c.fix_on = 1;

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

#20 lore raw

PATCH 17/31 Fix the MinGW build

In reply to Bart Van Assche

Fix multiple compiler warnings and build errors reported by the MinGW cross-compiler.

---
 configure.ac            | 46 +++++++++++++++++++++++++++++++++++++++++
 fsck/Makefile.am        |  2 +-
 fsck/dir.c              |  8 +++++++
 fsck/f2fs.h             |  8 +++++++
 fsck/main.c             | 13 ++++++------
 fsck/mount.c            |  4 ++--
 fsck/quotaio.h          |  1 -
 fsck/sload.c            | 11 ++++++++++
 mkfs/f2fs_format.c      |  7 +++++++
 mkfs/f2fs_format_main.c |  4 +++-
 tools/Makefile.am       |  5 ++++-
 tools/f2fs_io/f2fs_io.c | 13 ++++++------
 tools/f2fscrypt.c       |  2 ++
 tools/fibmap.c          |  2 ++
 14 files changed, 108 insertions(+), 18 deletions(-)
configure.ac +46 -0
index 4a3afa4853eb..06aaed9a57d9 100644
@@ -83,6 +83,12 @@ AC_CHECK_LIB([uuid], [uuid_clear],
 		[Define if you have libuuid])
 	], [], [])
 
+AC_CHECK_LIB([winpthread], [clock_gettime],
+	[AC_SUBST([libwinpthread_LIBS], ["-lwinpthread"])
+		AC_DEFINE([HAVE_LIBWINPTHREAD], [1],
+		[Define if you have libwinpthread])
+	], [], [])
+
 # Checks for header files.
 AC_CHECK_HEADERS(m4_flatten([
 	attr/xattr.h
@@ -100,6 +106,7 @@ AC_CHECK_HEADERS(m4_flatten([
 	linux/xattr.h
 	mach/mach_time.h
 	mntent.h
+	pthread_time.h
 	scsi/sg.h
 	selinux/selinux.h
 	stdlib.h
@@ -129,7 +136,9 @@ AC_CHECK_FUNCS_ONCE([
 	fsetxattr
 	fstat
 	fstat64
+	getgid
 	getmntent
+	getuid
 	keyctl
 	llseek
 	lseek64
@@ -140,6 +149,18 @@ AC_CHECK_FUNCS_ONCE([
 AS_IF([test "$ac_cv_header_byteswap_h" = "yes"],
       [AC_CHECK_DECLS([bswap_64],,,[#include <byteswap.h>])])
 
+AC_MSG_CHECKING([for CLOCK_BOOTIME])
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
+#include <time.h>
+#ifdef HAVE_PTHREAD_TIME_H
+#include <pthread_time.h>
+#endif
+],[return CLOCK_BOOTTIME])],
+		  [AC_MSG_RESULT([yes])
+		  AC_DEFINE([HAVE_CLOCK_BOOTTIME], [1],
+		  [Define if CLOCK_BOOTTIME is available])],
+		  [AC_MSG_RESULT([no])])
+
 # AC_CANONICAL_HOST is needed to access the 'host_os' variable
 AC_CANONICAL_HOST
 
@@ -209,4 +230,29 @@ AC_SUBST(LIBF2FS_CURRENT, 8)
 AC_SUBST(LIBF2FS_REVISION, 0)
 AC_SUBST(LIBF2FS_AGE, 0)
 
+AH_BOTTOM([
+#ifndef _CONFIG_H_
+#define _CONFIG_H_
+
+#ifdef HAVE_SYS_STAT_H
+#include <sys/stat.h>
+#endif
+
+#ifndef HAVE_GETUID
+static inline unsigned int getuid(void) { return -1; }
+#endif
+#ifndef HAVE_GETGID
+static inline unsigned int getgid(void) { return -1; }
+#endif
+
+#ifndef S_ISLNK
+#define S_ISLNK(mode) false
+#endif
+#ifndef S_ISSOCK
+#define S_ISSOCK(mode) false
+#endif
+
+#endif
+])
+
 AC_OUTPUT
fsck/Makefile.am +1 -1
index e31d4166e227..579dd26cd6c9 100644
@@ -10,7 +10,7 @@ fsck_f2fs_SOURCES = main.c fsck.c dump.c mount.c defrag.c resize.c \
 		node.c segment.c dir.c sload.c xattr.c compress.c \
 		dict.c mkquota.c quotaio.c quotaio_tree.c quotaio_v2.c
 fsck_f2fs_LDADD = ${libselinux_LIBS} ${libuuid_LIBS} \
-	${liblzo2_LIBS} ${liblz4_LIBS} \
+	${liblzo2_LIBS} ${liblz4_LIBS} ${libwinpthread_LIBS} \
 	$(top_builddir)/lib/libf2fs.la
 
 install-data-hook:
fsck/dir.c +8 -0
index f7491a778a30..4a3eb6ea7788 100644
@@ -474,11 +474,19 @@ static void init_inode_block(struct f2fs_sb_info *sbi,
 		links++;
 		blocks++;
 	} else if (de->file_type == F2FS_FT_REG_FILE) {
+#ifdef S_IFREG
 		mode |= S_IFREG;
+#else
+		ASSERT(0);
+#endif
 		size = 0;
 	} else if (de->file_type == F2FS_FT_SYMLINK) {
 		ASSERT(de->link);
+#ifdef S_IFLNK
 		mode |= S_IFLNK;
+#else
+		ASSERT(0);
+#endif
 		size = strlen(de->link);
 		if (size + 1 > MAX_INLINE_DATA(node_blk))
 			blocks++;
fsck/f2fs.h +8 -0
index e5130ba19961..875f953fb6cc 100644
@@ -27,8 +27,12 @@
 #include <mach/mach_time.h>
 #endif
 #include <sys/stat.h>
+#ifdef HAVE_SYS_IOCTL_H
 #include <sys/ioctl.h>
+#endif
+#ifdef HAVE_SYS_MOUNT_H
 #include <sys/mount.h>
+#endif
 #include <assert.h>
 
 #include "f2fs_fs.h"
@@ -589,8 +593,12 @@ static unsigned char f2fs_type_by_mode[S_IFMT >> S_SHIFT] = {
 	[S_IFCHR >> S_SHIFT]    = F2FS_FT_CHRDEV,
 	[S_IFBLK >> S_SHIFT]    = F2FS_FT_BLKDEV,
 	[S_IFIFO >> S_SHIFT]    = F2FS_FT_FIFO,
+#ifdef S_IFSOCK
 	[S_IFSOCK >> S_SHIFT]   = F2FS_FT_SOCK,
+#endif
+#ifdef S_IFLNK
 	[S_IFLNK >> S_SHIFT]    = F2FS_FT_SYMLINK,
+#endif
 };
 
 static inline int map_de_type(umode_t mode)
fsck/main.c +7 -6
index e4cfdf443867..b555ff4dbee7 100644
@@ -1065,16 +1065,12 @@ static int do_label(struct f2fs_sb_info *sbi)
 }
 #endif
 
-#if defined(__APPLE__)
+#ifdef HAVE_MACH_TIME_H
 static u64 get_boottime_ns()
 {
-#ifdef HAVE_MACH_TIME_H
 	return mach_absolute_time();
-#else
-	return 0;
-#endif
 }
-#else
+#elif defined(HAVE_CLOCK_GETTIME) && defined(HAVE_CLOCK_BOOTTIME)
 static u64 get_boottime_ns()
 {
 	struct timespec t;
@@ -1082,6 +1078,11 @@ static u64 get_boottime_ns()
 	clock_gettime(CLOCK_BOOTTIME, &t);
 	return (u64)t.tv_sec * 1000000000LL + t.tv_nsec;
 }
+#else
+static u64 get_boottime_ns()
+{
+	return 0;
+}
 #endif
 
 int main(int argc, char **argv)
fsck/mount.c +2 -2
index 584385d682b5..b1e318f099f0 100644
@@ -31,6 +31,8 @@
 #define ACL_OTHER		(0x20)
 #endif
 
+#ifdef HAVE_LINUX_BLKZONED_H
+
 static int get_device_idx(struct f2fs_sb_info *sbi, uint32_t segno)
 {
 	block_t seg_start_blkaddr;
@@ -45,8 +47,6 @@ static int get_device_idx(struct f2fs_sb_info *sbi, uint32_t segno)
 	return 0;
 }
 
-#ifdef HAVE_LINUX_BLKZONED_H
-
 static int get_zone_idx_from_dev(struct f2fs_sb_info *sbi,
 					uint32_t segno, uint32_t dev_idx)
 {
fsck/quotaio.h +0 -1
index 0024fe570727..fc40f98e8741 100644
@@ -21,7 +21,6 @@
 #include <limits.h>
 #include <sys/types.h>
 #include <sys/stat.h>
-#include <arpa/inet.h>
 
 #include "dict.h"
 #include "f2fs_fs.h"
fsck/sload.c +11 -0
index 692902344a55..475ea6dac5f6 100644
@@ -28,6 +28,7 @@ typedef void (*fs_config_f)(const char *path, int dir,
 			    unsigned *uid, unsigned *gid,
 			    unsigned *mode, uint64_t *capabilities);
 
+#ifndef _WIN32
 static fs_config_f fs_config_func = NULL;
 
 #ifdef WITH_ANDROID
@@ -62,6 +63,7 @@ static int f2fs_make_directory(struct f2fs_sb_info *sbi,
 
 	return ret;
 }
+#endif
 
 #ifdef HAVE_LIBSELINUX
 static int set_selinux_xattr(struct f2fs_sb_info *sbi, const char *path,
@@ -99,6 +101,7 @@ static int set_selinux_xattr(struct f2fs_sb_info *sbi, const char *path,
 #define set_selinux_xattr(...)	0
 #endif
 
+#ifndef _WIN32
 static int set_perms_and_caps(struct dentry *de)
 {
 	uint64_t capabilities = 0;
@@ -291,6 +294,14 @@ out_free:
 	free(dentries);
 	return 0;
 }
+#else
+static int build_directory(struct f2fs_sb_info *sbi, const char *full_path,
+			const char *dir_path, const char *target_out_dir,
+			nid_t dir_ino)
+{
+	return -1;
+}
+#endif
 
 static int configure_files(void)
 {
mkfs/f2fs_format.c +7 -0
index 332abf60d0d9..173f619585f3 100644
@@ -18,7 +18,14 @@
 #include <sys/mount.h>
 #endif
 #include <time.h>
+
+#include "config.h"
+#ifdef HAVE_UUID_UUID_H
 #include <uuid/uuid.h>
+#else
+#define uuid_parse(a, b) -1
+#define uuid_generate(a)
+#endif
 
 #include "f2fs_fs.h"
 #include "quota.h"
mkfs/f2fs_format_main.c +3 -1
index ecc942b61d63..88b267492245 100644
@@ -19,7 +19,6 @@
 #include <sys/mount.h>
 #endif
 #include <time.h>
-#include <uuid/uuid.h>
 #include <errno.h>
 #include <getopt.h>
 
@@ -27,6 +26,9 @@
 #ifdef HAVE_LIBBLKID
 #include <blkid/blkid.h>
 #endif
+#ifdef HAVE_UUID_UUID_H
+#include <uuid/uuid.h>
+#endif
 
 #include "f2fs_fs.h"
 #include "quota.h"
tools/Makefile.am +4 -1
index 56bf2e4e8a99..8756a298fdcf 100644
@@ -2,7 +2,10 @@
 
 AM_CPPFLAGS = ${libuuid_CFLAGS} -I$(top_srcdir)/include
 AM_CFLAGS = -Wall
-sbin_PROGRAMS = f2fstat fibmap.f2fs parse.f2fs
+sbin_PROGRAMS = f2fstat
+if !WINDOWS
+sbin_PROGRAMS += fibmap.f2fs parse.f2fs
+endif
 f2fstat_SOURCES = f2fstat.c
 fibmap_f2fs_SOURCES = fibmap.c
 parse_f2fs_SOURCES = f2fs_io_parse.c
tools/f2fs_io/f2fs_io.c +7 -6
index af4a34b63471..e807177a4174 100644
@@ -132,16 +132,12 @@ static void full_write(int fd, const void *buf, size_t count)
 	}
 }
 
-#if defined(__APPLE__)
+#ifdef HAVE_MACH_TIME_H
 static u64 get_current_us()
 {
-#ifdef HAVE_MACH_TIME_H
 	return mach_absolute_time() / 1000;
-#else
-	return 0;
-#endif
 }
-#else
+#elif defined(HAVE_CLOCK_GETTIME) && defined(HAVE_CLOCK_BOOTTIME)
 static u64 get_current_us()
 {
 	struct timespec t;
@@ -149,6 +145,11 @@ static u64 get_current_us()
 	clock_gettime(CLOCK_BOOTTIME, &t);
 	return (u64)t.tv_sec * 1000000LL + t.tv_nsec / 1000;
 }
+#else
+static u64 get_current_us()
+{
+	return 0;
+}
 #endif
 
 #define fsync_desc "fsync"
tools/f2fscrypt.c +2 -0
index 72bfb6467300..0f0650f4dd63 100644
@@ -43,7 +43,9 @@
 #ifdef __KERNEL__
 #include <linux/fs.h>
 #endif
+#ifdef HAVE_UUID_UUID_H
 #include <uuid/uuid.h>
+#endif
 
 #if !defined(HAVE_ADD_KEY) || !defined(HAVE_KEYCTL)
 #include <sys/syscall.h>
tools/fibmap.c +2 -0
index 9e96cb68cecc..3238f294e869 100644
@@ -23,7 +23,9 @@
 #include <fcntl.h>
 #include <errno.h>
 #include <sys/types.h>
+#ifdef HAVE_SYS_IOCTL_H
 #include <sys/ioctl.h>
+#endif
 #include <sys/stat.h>
 #ifdef HAVE_SYS_SYSMACROS_H
 #include <sys/sysmacros.h>

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

#21 lore raw

PATCH 18/31 configure.ac: Detect the sparse/sparse.h header

In reply to Bart Van Assche

The <sparse/sparse.h> header is available in Android but not in the Android NDK. Hence this patch that only includes the sparse header file if it is available.

---
 configure.ac            |  1 +
 lib/libf2fs_io.c        | 10 +++++-----
 mkfs/f2fs_format_main.c |  2 +-
 3 files changed, 7 insertions(+), 6 deletions(-)
configure.ac +1 -0
index 06aaed9a57d9..317030dad44f 100644
@@ -109,6 +109,7 @@ AC_CHECK_HEADERS(m4_flatten([
 	pthread_time.h
 	scsi/sg.h
 	selinux/selinux.h
+	sparse/sparse.h
 	stdlib.h
 	string.h
 	sys/acl.h
lib/libf2fs_io.c +5 -5
index bf6dfe240bb7..287199314190 100644
@@ -39,7 +39,7 @@
 
 struct f2fs_configuration c;
 
-#ifdef WITH_ANDROID
+#ifdef HAVE_SPARSE_SPARSE_H
 #include <sparse/sparse.h>
 struct sparse_file *f2fs_sparse_file;
 static char **blocks;
@@ -398,7 +398,7 @@ int dev_read_version(void *buf, __u64 offset, size_t len)
 	return 0;
 }
 
-#ifdef WITH_ANDROID
+#ifdef HAVE_SPARSE_SPARSE_H
 static int sparse_read_blk(__u64 block, int count, void *buf)
 {
 	int i;
@@ -649,7 +649,7 @@ int f2fs_fsync_device(void)
 
 int f2fs_init_sparse_file(void)
 {
-#ifdef WITH_ANDROID
+#ifdef HAVE_SPARSE_SPARSE_H
 	if (c.func == MKFS) {
 		f2fs_sparse_file = sparse_file_new(F2FS_BLKSIZE, c.device_size);
 		if (!f2fs_sparse_file)
@@ -691,7 +691,7 @@ int f2fs_init_sparse_file(void)
 
 void f2fs_release_sparse_resource(void)
 {
-#ifdef WITH_ANDROID
+#ifdef HAVE_SPARSE_SPARSE_H
 	int j;
 
 	if (c.sparse_mode) {
@@ -716,7 +716,7 @@ int f2fs_finalize_device(void)
 	int i;
 	int ret = 0;
 
-#ifdef WITH_ANDROID
+#ifdef HAVE_SPARSE_SPARSE_H
 	if (c.sparse_mode) {
 		int64_t chunk_start = (blocks[0] == NULL) ? -1 : 0;
 		uint64_t j;
mkfs/f2fs_format_main.c +1 -1
index 88b267492245..4d4fad9ad86d 100644
@@ -37,7 +37,7 @@
 #ifdef HAVE_SYS_UTSNAME_H
 #include <sys/utsname.h>
 #endif
-#ifdef WITH_ANDROID
+#ifdef HAVE_SPARSE_SPARSE_H
 #include <sparse/sparse.h>
 extern struct sparse_file *f2fs_sparse_file;
 #endif

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

#22 lore raw

Re: [f2fs-dev] [PATCH 18/31] configure.ac: Detect the sparse/sparse.h header

Quoted 3 lines · Bart Van Assche

The <sparse/sparse.h> header is available in Android but not in the Android NDK. Hence this patch that only includes the sparse header file if it is available.

Need this in android_config.h

+#define HAVE_SPARSE_SPARSE_H 1

Quoted 74 lines
---
 configure.ac            |  1 +
 lib/libf2fs_io.c        | 10 +++++-----
 mkfs/f2fs_format_main.c |  2 +-
 3 files changed, 7 insertions(+), 6 deletions(-)
configure.ac +1 -0
index 06aaed9a57d9..317030dad44f 100644
@@ -109,6 +109,7 @@ AC_CHECK_HEADERS(m4_flatten([
 	pthread_time.h
 	scsi/sg.h
 	selinux/selinux.h
+	sparse/sparse.h
 	stdlib.h
 	string.h
 	sys/acl.h
lib/libf2fs_io.c +5 -5
index bf6dfe240bb7..287199314190 100644
@@ -39,7 +39,7 @@
 
 struct f2fs_configuration c;
 
-#ifdef WITH_ANDROID
+#ifdef HAVE_SPARSE_SPARSE_H
 #include <sparse/sparse.h>
 struct sparse_file *f2fs_sparse_file;
 static char **blocks;
@@ -398,7 +398,7 @@ int dev_read_version(void *buf, __u64 offset, size_t len)
 	return 0;
 }
 
-#ifdef WITH_ANDROID
+#ifdef HAVE_SPARSE_SPARSE_H
 static int sparse_read_blk(__u64 block, int count, void *buf)
 {
 	int i;
@@ -649,7 +649,7 @@ int f2fs_fsync_device(void)
 
 int f2fs_init_sparse_file(void)
 {
-#ifdef WITH_ANDROID
+#ifdef HAVE_SPARSE_SPARSE_H
 	if (c.func == MKFS) {
 		f2fs_sparse_file = sparse_file_new(F2FS_BLKSIZE, c.device_size);
 		if (!f2fs_sparse_file)
@@ -691,7 +691,7 @@ int f2fs_init_sparse_file(void)
 
 void f2fs_release_sparse_resource(void)
 {
-#ifdef WITH_ANDROID
+#ifdef HAVE_SPARSE_SPARSE_H
 	int j;
 
 	if (c.sparse_mode) {
@@ -716,7 +716,7 @@ int f2fs_finalize_device(void)
 	int i;
 	int ret = 0;
 
-#ifdef WITH_ANDROID
+#ifdef HAVE_SPARSE_SPARSE_H
 	if (c.sparse_mode) {
 		int64_t chunk_start = (blocks[0] == NULL) ? -1 : 0;
 		uint64_t j;
mkfs/f2fs_format_main.c +0 -0
index 88b267492245..4d4fad9ad86d 100644

mkfs/f2fs_format_main.c line 43

Quoted 8 lines
mkfs/f2fs_format_main.c +1 -1
@@ -37,7 +37,7 @@
 #ifdef HAVE_SYS_UTSNAME_H
 #include <sys/utsname.h>
 #endif
-#ifdef WITH_ANDROID
+#ifdef HAVE_SPARSE_SPARSE_H
 #include <sparse/sparse.h>
 extern struct sparse_file *f2fs_sparse_file;
 #endif

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

#23 lore raw

PATCH 19/31 configure.ac: Detect selinux/android.h

In reply to Bart Van Assche

The selinux/android.h header file is available in Android but not in the Android NDK. Hence this patch that detects presence of that header file at configure time.

---
 configure.ac | 1 +
 fsck/sload.c | 4 ++--
 2 files changed, 3 insertions(+), 2 deletions(-)
configure.ac +1 -0
index 317030dad44f..fc094b72b583 100644
@@ -108,6 +108,7 @@ AC_CHECK_HEADERS(m4_flatten([
 	mntent.h
 	pthread_time.h
 	scsi/sg.h
+	selinux/android.h
 	selinux/selinux.h
 	sparse/sparse.h
 	stdlib.h
fsck/sload.c +2 -2
index 475ea6dac5f6..00c3403dace0 100644
@@ -31,7 +31,7 @@ typedef void (*fs_config_f)(const char *path, int dir,
 #ifndef _WIN32
 static fs_config_f fs_config_func = NULL;
 
-#ifdef WITH_ANDROID
+#ifdef HAVE_SELINUX_ANDROID_H
 #include <selinux/android.h>
 #include <private/android_filesystem_config.h>
 #include <private/canned_fs_config.h>
@@ -324,7 +324,7 @@ static int configure_files(void)
 #endif
 skip:
 #endif
-#ifdef WITH_ANDROID
+#ifdef HAVE_SELINUX_ANDROID_H
 	/* Load the FS config */
 	if (c.fs_config_file) {
 		int ret = load_canned_fs_config(c.fs_config_file);

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

#24 lore raw

PATCH 20/31 mkfs/f2fs_format.c: Suppress a compiler warning

In reply to Bart Van Assche

Suppress the following compiler warning:

f2fs_format.c:1653:37: warning: adding 'int' to a string does not append to the

      string [-Wstring-plus-int]
                memcpy(dent_blk->filename[3], LPF + F2FS_SLOT_LEN,
                                              ~~~~^~~~~~~~~~~~~~~
f2fs_format.c:1653:37: note: use array indexing to silence this warning
                memcpy(dent_blk->filename[3], LPF + F2FS_SLOT_LEN,
                                                  ^
                                              &   [              ]
---
 mkfs/f2fs_format.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mkfs/f2fs_format.c +1 -1
index 173f619585f3..6f2761cfdb75 100644
@@ -1650,7 +1650,7 @@ static int f2fs_add_default_dentry_root(void)
 		dent_blk->dentry[2].file_type = F2FS_FT_DIR;
 		memcpy(dent_blk->filename[2], LPF, F2FS_SLOT_LEN);
 
-		memcpy(dent_blk->filename[3], LPF + F2FS_SLOT_LEN,
+		memcpy(dent_blk->filename[3], &LPF[F2FS_SLOT_LEN],
 				len - F2FS_SLOT_LEN);
 
 		test_and_set_bit_le(2, dent_blk->dentry_bitmap);

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

#25 lore raw

PATCH 21/31 fsck: Remove a superfluous include directive

In reply to Bart Van Assche
---
 fsck/main.c | 5 -----
 1 file changed, 5 deletions(-)
fsck/main.c +0 -5
index b555ff4dbee7..fc776eb0af1f 100644
@@ -32,11 +32,6 @@
 
 struct f2fs_fsck gfsck;
 
-#ifdef WITH_ANDROID
-#include <sparse/sparse.h>
-extern struct sparse_file *f2fs_sparse_file;
-#endif
-
 INIT_FEATURE_TABLE;
 
 static char *absolute_path(const char *file)

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

#26 lore raw

PATCH 22/31 tools/f2fscrypt.c: Fix build without uuid/uuid.h header file

In reply to Bart Van Assche
---
 tools/f2fscrypt.c | 6 ++++++
 1 file changed, 6 insertions(+)
tools/f2fscrypt.c +6 -0
index 0f0650f4dd63..293173fcb5b4 100644
@@ -45,6 +45,8 @@
 #endif
 #ifdef HAVE_UUID_UUID_H
 #include <uuid/uuid.h>
+#else
+typedef unsigned char uuid_t[16];
 #endif
 
 #if !defined(HAVE_ADD_KEY) || !defined(HAVE_KEYCTL)
@@ -354,11 +356,13 @@ static void parse_salt(char *salt_str, int flags)
 			perror("F2FS_IOC_GET_ENCRYPTION_PWSALT");
 			exit(1);
 		}
+#ifdef HAVE_UUID_UUID_H
 		if (options & OPT_VERBOSE) {
 			char tmp[80];
 			uuid_unparse(buf, tmp);
 			printf("%s has pw salt %s\n", cp, tmp);
 		}
+#endif
 		salt_len = 16;
 	} else if (strncmp(cp, "f:", 2) == 0) {
 		cp += 2;
@@ -380,8 +384,10 @@ static void parse_salt(char *salt_str, int flags)
 				(((unsigned char)(h - hexchars) << 4) +
 				 (unsigned char)(l - hexchars));
 		}
+#ifdef HAVE_UUID_UUID_H
 	} else if (uuid_parse(cp, buf) == 0) {
 		salt_len = 16;
+#endif
 	} else {
 	invalid_salt:
 		fprintf(stderr, "Invalid salt: %s\n", salt_str);

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

#27 lore raw

PATCH 23/31 fsck/main.c: Suppress a compiler warning

In reply to Bart Van Assche

Suppress the following compiler warning:

main.c:37:14: warning: unused function 'absolute_path' [-Wunused-function] static char *absolute_path(const char *file)

             ^
---
 fsck/main.c | 2 ++
 1 file changed, 2 insertions(+)
fsck/main.c +2 -0
index fc776eb0af1f..8676f17555c5 100644
@@ -34,6 +34,7 @@ struct f2fs_fsck gfsck;
 
 INIT_FEATURE_TABLE;
 
+#ifdef WITH_SLOAD
 static char *absolute_path(const char *file)
 {
 	char *ret;
@@ -51,6 +52,7 @@ static char *absolute_path(const char *file)
 		ret = strdup(file);
 	return ret;
 }
+#endif
 
 void fsck_usage()
 {

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

#28 lore raw

PATCH 24/31 Change #ifdef _WIN32 checks into #ifdef HAVE_.*

In reply to Bart Van Assche

It is recommended to test a HAVE_* macro instead of directly testing the host type in source code. Hence this patch.

---
 configure.ac             |  2 ++
 lib/libf2fs.c            |  4 +++-
 lib/libf2fs_io.c         | 10 +++++++---
 lib/libf2fs_zoned.c      |  2 +-
 mkfs/f2fs_format.c       |  4 +++-
 mkfs/f2fs_format_main.c  |  2 +-
 mkfs/f2fs_format_utils.c |  7 +++++--
 7 files changed, 22 insertions(+), 9 deletions(-)
configure.ac +2 -0
index fc094b72b583..f0ed5f6528d9 100644
@@ -116,6 +116,7 @@ AC_CHECK_HEADERS(m4_flatten([
 	sys/acl.h
 	sys/ioctl.h
 	sys/mount.h
+	sys/stat.h
 	sys/syscall.h
 	sys/sysmacros.h
 	sys/utsname.h
@@ -138,6 +139,7 @@ AC_CHECK_FUNCS_ONCE([
 	fsetxattr
 	fstat
 	fstat64
+	fsync
 	getgid
 	getmntent
 	getuid
lib/libf2fs.c +3 -1
index c7102528f2f4..aa4e854acc9d 100644
@@ -22,8 +22,10 @@
 #endif
 #include <time.h>
 #include <sys/stat.h>
-#ifndef _WIN32
+#ifdef HAVE_SYS_MOUNT_H
 #include <sys/mount.h>
+#endif
+#ifdef HAVE_SYS_IOCTL_H
 #include <sys/ioctl.h>
 #endif
 #ifdef HAVE_SYS_SYSMACROS_H
lib/libf2fs_io.c +7 -3
index 287199314190..09a689293356 100644
@@ -23,9 +23,13 @@
 #include <mntent.h>
 #endif
 #include <time.h>
-#ifndef _WIN32
+#ifdef HAVE_SYS_STAT_H
 #include <sys/stat.h>
+#endif
+#ifdef HAVE_SYS_MOUNT_H
 #include <sys/mount.h>
+#endif
+#ifdef HAVE_SYS_IOCTL_H
 #include <sys/ioctl.h>
 #endif
 #ifdef HAVE_LINUX_HDREG_H
@@ -634,7 +638,7 @@ int dev_reada_block(__u64 blk_addr)
 
 int f2fs_fsync_device(void)
 {
-#ifndef _WIN32
+#ifdef HAVE_FSYNC
 	int i;
 
 	for (i = 0; i < c.ndevs; i++) {
@@ -783,7 +787,7 @@ int f2fs_finalize_device(void)
 	 * in the block device page cache.
 	 */
 	for (i = 0; i < c.ndevs; i++) {
-#ifndef _WIN32
+#ifdef HAVE_FSYNC
 		ret = fsync(c.devices[i].fd);
 		if (ret < 0) {
 			MSG(0, "\tError: Could not conduct fsync!!!\n");
lib/libf2fs_zoned.c +1 -1
index cb954feabe61..fdde3f70a606 100644
@@ -22,7 +22,7 @@
 #ifdef HAVE_LINUX_LIMITS_H
 #include <linux/limits.h>
 #endif
-#ifndef _WIN32
+#ifdef HAVE_SYS_IOCTL_H
 #include <sys/ioctl.h>
 #endif
 #include <libgen.h>
mkfs/f2fs_format.c +3 -1
index 6f2761cfdb75..ce7d1c9e40bd 100644
@@ -13,8 +13,10 @@
 #include <fcntl.h>
 #include <string.h>
 #include <unistd.h>
-#ifndef _WIN32
+#ifdef HAVE_SYS_STAT_H
 #include <sys/stat.h>
+#endif
+#ifdef HAVE_SYS_MOUNT_H
 #include <sys/mount.h>
 #endif
 #include <time.h>
mkfs/f2fs_format_main.c +1 -1
index 4d4fad9ad86d..b8936f15e0f2 100644
@@ -15,7 +15,7 @@
 #include <stdbool.h>
 #include <unistd.h>
 #include <sys/stat.h>
-#ifndef _WIN32
+#ifdef HAVE_SYS_MOUNT_H
 #include <sys/mount.h>
 #endif
 #include <time.h>
mkfs/f2fs_format_utils.c +5 -2
index 53101d1bd790..e3c58936e968 100644
@@ -26,7 +26,7 @@
 #include <unistd.h>
 #include <stdlib.h>
 #include <stdbool.h>
-#ifndef _WIN32
+#ifdef HAVE_SYS_IOCTL_H
 #include <sys/ioctl.h>
 #endif
 #include <sys/stat.h>
@@ -39,16 +39,19 @@
 #include <linux/falloc.h>
 #endif
 
+#ifdef __linux__
 #ifndef BLKDISCARD
 #define BLKDISCARD	_IO(0x12,119)
 #endif
 #ifndef BLKSECDISCARD
 #define BLKSECDISCARD	_IO(0x12,125)
 #endif
+#endif
 
 static int trim_device(int i)
 {
-#ifndef _WIN32
+#if defined(FALLOC_FL_PUNCH_HOLE) || defined(BLKDISCARD) || \
+	defined(BLKSECDISCARD)
 	unsigned long long range[2];
 	struct stat *stat_buf;
 	struct device_info *dev = c.devices + i;

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

#29 lore raw

PATCH 25/31 fsck/segment.c: Remove dead code

In reply to Bart Van Assche

Since 'remained_blkentries' is unsigned, the assert statement that verifies whether that variable is positive will never fail. Hence remove that assert statement.

---
 fsck/segment.c | 1 -
 1 file changed, 1 deletion(-)
fsck/segment.c +0 -1
index 254a0d1425e9..401cbb69e0d7 100644
@@ -537,7 +537,6 @@ static void update_largest_extent(struct f2fs_sb_info *sbi, nid_t ino)
 		cur_blk += count;
 		dn.ofs_in_node += count;
 		remained_blkentries -= count;
-		ASSERT(remained_blkentries >= 0);
 	}
 
 exit:

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

#30 lore raw

PATCH 26/31 tools/f2fs_io: Fix the type of 'ret'

In reply to Bart Van Assche

Make it possible to check whether the return value of ioctl() is negative.

---
 tools/f2fs_io/f2fs_io.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
tools/f2fs_io/f2fs_io.c +9 -1
index e807177a4174..6bb094cc7f25 100644
@@ -513,7 +513,7 @@ static void do_erase(int argc, char **argv, const struct cmd_desc *cmd)
 
 static void do_write(int argc, char **argv, const struct cmd_desc *cmd)
 {
-	u64 buf_size = 0, inc_num = 0, ret = 0, written = 0;
+	u64 buf_size = 0, inc_num = 0, written = 0;
 	u64 offset;
 	char *buf = NULL;
 	unsigned bs, count, i;
@@ -561,6 +561,8 @@ static void do_write(int argc, char **argv, const struct cmd_desc *cmd)
 	fd = xopen(argv[6], O_CREAT | O_WRONLY | flags, 0755);
 
 	if (atomic_commit || atomic_abort) {
+		int ret;
+
 		if (argc == 8)
 			useconds = atoi(argv[7]) * 1000;
 
@@ -573,6 +575,8 @@ static void do_write(int argc, char **argv, const struct cmd_desc *cmd)
 
 	total_time = get_current_us();
 	for (i = 0; i < count; i++) {
+		uint64_t ret;
+
 		if (!strcmp(argv[4], "inc_num"))
 			*(int *)buf = inc_num++;
 		else if (!strcmp(argv[4], "rand"))
@@ -593,12 +597,16 @@ static void do_write(int argc, char **argv, const struct cmd_desc *cmd)
 		usleep(useconds);
 
 	if (atomic_commit) {
+		int ret;
+
 		ret = ioctl(fd, F2FS_IOC_COMMIT_ATOMIC_WRITE);
 		if (ret < 0) {
 			fputs("committing atomic write failed\n", stderr);
 			exit(1);
 		}
 	} else if (atomic_abort) {
+		int ret;
+
 		ret = ioctl(fd, F2FS_IOC_ABORT_VOLATILE_WRITE);
 		if (ret < 0) {
 			fputs("aborting atomic write failed\n", stderr);

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

#31 lore raw

PATCH 27/31 Annotate switch/case fallthrough

In reply to Bart Van Assche

Just like in the Linux kernel source code, annotate switch/case fallthrough.

---
 fsck/fsck.c       | 1 +
 fsck/main.c       | 1 +
 include/f2fs_fs.h | 6 ++++++
 tools/f2fscrypt.c | 1 +
 4 files changed, 9 insertions(+)
fsck/fsck.c +1 -0
index 798779cfaf8a..19a28b0eedad 100644
@@ -1669,6 +1669,7 @@ static int __chk_dentries(struct f2fs_sb_info *sbi, int casefolded,
 				switch (ret) {
 				case 1:
 					fixed = 1;
+					fallthrough;
 				case 0:
 					child->dots++;
 					break;
fsck/main.c +1 -0
index 8676f17555c5..aef797e98405 100644
@@ -370,6 +370,7 @@ void f2fs_parse_options(int argc, char *argv[])
 				exit(0);
 			case '?':
 				option = optopt;
+				fallthrough;
 			default:
 				err = EUNKNOWN_OPT;
 				break;
include/f2fs_fs.h +6 -0
index dd62bc89a926..73dc48e25ec0 100644
@@ -73,6 +73,12 @@
 #define static_assert _Static_assert
 #endif
 
+#ifdef __clang__
+#define fallthrough do {} while (0) /* fall through */
+#else
+#define fallthrough __attribute__((__fallthrough__))
+#endif
+
 #ifdef ANDROID_WINDOWS_HOST
 #undef HAVE_LINUX_TYPES_H
 #endif
tools/f2fscrypt.c +1 -0
index 293173fcb5b4..f2fbf0bf3878 100644
@@ -726,6 +726,7 @@ static void do_add_key(int argc, char **argv, const struct cmd_desc *cmd)
 			break;
 		default:
 			fprintf(stderr, "Unrecognized option: %c\n", opt);
+			fallthrough;
 		case '?':
 			fputs("USAGE:\n  ", stderr);
 			fputs(cmd->cmd_help, stderr);

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

#32 lore raw

PATCH 28/31 Suppress a compiler warning about integer truncation

In reply to Bart Van Assche

This patch prevents that older compilers report the following warning:

f2fs_format.c: In function ‘f2fs_prepare_super_block’:
../include/f2fs_fs.h:350:26: error: conversion from ‘unsigned int’ to ‘__uint16_t’ {aka ‘short unsigned int’} changes value from ‘4076150800’ to ‘8208’ [-Werror=overflow]
350 | #define F2FS_SUPER_MAGIC 0xF2F52010 /* F2FS Magic Number */

      |                          ^~~~~~~~~~

../include/f2fs_fs.h:574:49: note: in expansion of macro ‘cpu_to_le16’
574 | #define set_sb_le16(member, val) (sb->member = cpu_to_le16(val))
| ^~~~~~~~~~~

---
 include/f2fs_fs.h | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)
include/f2fs_fs.h +12 -12
index 73dc48e25ec0..bc57dd07819a 100644
@@ -579,14 +579,14 @@ struct f2fs_configuration {
 #define get_newsb_le32(member)			le32_to_cpu(new_sb->member)
 #define get_newsb_le16(member)			le16_to_cpu(new_sb->member)
 
-#define set_sb(member, val)	\
+#define set_sb(member, val)						\
 			do {						\
-				typeof(sb->member) t;			\
+				typeof(sb->member) t = (val);		\
 				switch (sizeof(t)) {			\
-				case 8: set_sb_le64(member, val); break; \
-				case 4: set_sb_le32(member, val); break; \
-				case 2: set_sb_le16(member, val); break; \
-				} \
+				case 8: set_sb_le64(member, t); break;	\
+				case 4: set_sb_le32(member, t); break;	\
+				case 2: set_sb_le16(member, t); break;	\
+				}					\
 			} while(0)
 
 #define get_sb(member)		\
@@ -617,14 +617,14 @@ struct f2fs_configuration {
 #define get_cp_le32(member)			le32_to_cpu(cp->member)
 #define get_cp_le16(member)			le16_to_cpu(cp->member)
 
-#define set_cp(member, val)	\
+#define set_cp(member, val)						\
 			do {						\
-				typeof(cp->member) t;			\
+				typeof(cp->member) t = (val);		\
 				switch (sizeof(t)) {			\
-				case 8: set_cp_le64(member, val); break; \
-				case 4: set_cp_le32(member, val); break; \
-				case 2: set_cp_le16(member, val); break; \
-				} \
+				case 8: set_cp_le64(member, t); break;	\
+				case 4: set_cp_le32(member, t); break;	\
+				case 2: set_cp_le16(member, t); break;	\
+				}					\
 			} while(0)
 
 #define get_cp(member)		\

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

#33 lore raw

PATCH 29/31 Support cross-compiliation for PowerPC

In reply to Bart Van Assche

Some PowerPC cross-compilers have the uuid.h header file but not the uuid library. Hence this patch that causes f2fs-tools only to use the uuid functions if both the uuid header file and library are available.

---
 mkfs/f2fs_format.c | 2 +-
 tools/f2fscrypt.c  | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
mkfs/f2fs_format.c +1 -1
index ce7d1c9e40bd..60a6b15af8ec 100644
@@ -22,7 +22,7 @@
 #include <time.h>
 
 #include "config.h"
-#ifdef HAVE_UUID_UUID_H
+#if defined(HAVE_UUID_UUID_H) && defined(HAVE_LIBUUID)
 #include <uuid/uuid.h>
 #else
 #define uuid_parse(a, b) -1
tools/f2fscrypt.c +2 -2
index f2fbf0bf3878..37c791e52e7f 100644
@@ -356,7 +356,7 @@ static void parse_salt(char *salt_str, int flags)
 			perror("F2FS_IOC_GET_ENCRYPTION_PWSALT");
 			exit(1);
 		}
-#ifdef HAVE_UUID_UUID_H
+#if defined(HAVE_UUID_UUID_H) && defined(HAVE_LIBUUID)
 		if (options & OPT_VERBOSE) {
 			char tmp[80];
 			uuid_unparse(buf, tmp);
@@ -384,7 +384,7 @@ static void parse_salt(char *salt_str, int flags)
 				(((unsigned char)(h - hexchars) << 4) +
 				 (unsigned char)(l - hexchars));
 		}
-#ifdef HAVE_UUID_UUID_H
+#if defined(HAVE_UUID_UUID_H) && defined(HAVE_LIBUUID)
 	} else if (uuid_parse(cp, buf) == 0) {
 		salt_len = 16;
 #endif

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

#34 lore raw

PATCH 30/31 Fix PowerPC format string warnings

In reply to Bart Van Assche

__SANE_USERSPACE_TYPES__ must be defined before <linux/types.h> is included. Hence this patch that moves the definition of that macro into the source files that need it.

---
 include/f2fs_fs.h       | 7 ++++---
 tools/f2fs_io/f2fs_io.c | 3 +++
 2 files changed, 7 insertions(+), 3 deletions(-)
include/f2fs_fs.h +4 -3
index bc57dd07819a..eedb38a6da1c 100644
@@ -17,6 +17,10 @@
 #ifndef __F2FS_FS_H__
 #define __F2FS_FS_H__
 
+#ifndef __SANE_USERSPACE_TYPES__
+#define __SANE_USERSPACE_TYPES__       /* For PPC64, to get LL64 types */
+#endif
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <stddef.h>
@@ -42,9 +46,6 @@
 
 #include <inttypes.h>
 #ifdef HAVE_LINUX_TYPES_H
-#ifndef __SANE_USERSPACE_TYPES__
-#define __SANE_USERSPACE_TYPES__       /* For PPC64, to get LL64 types */
-#endif
 #include <linux/types.h>
 #endif
 #include <sys/types.h>
tools/f2fs_io/f2fs_io.c +3 -0
index 6bb094cc7f25..0edac6fedf33 100644
@@ -18,6 +18,9 @@
 #ifndef O_LARGEFILE
 #define O_LARGEFILE 0
 #endif
+#ifndef __SANE_USERSPACE_TYPES__
+#define __SANE_USERSPACE_TYPES__       /* For PPC64, to get LL64 types */
+#endif
 
 #include <errno.h>
 #include <fcntl.h>

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

#35 lore raw

PATCH 31/31 ci: Enable -Wall, -Wextra and -Werror

In reply to Bart Van Assche

Make the Github continuous integration checks more strict.

---
 .github/workflows/ci.yml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
.github/workflows/ci.yml +1 -1
index 0c774f92fac8..428039db860d 100644
@@ -66,5 +66,5 @@ jobs:
           ./autogen.sh
           ./configure --host=${{matrix.host}} \
               CC=${{ matrix.host && format('{0}-{1}', matrix.host, matrix.cc) || matrix.cc }} \
-              CFLAGS="${{matrix.cflags}}"
+              CFLAGS="-Wall -Wextra -Werror -Wno-sign-compare -Wno-unused-function -Wno-unused-parameter ${{matrix.cflags}}"
           make -j$(nproc)

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel