aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBart Van Assche <bvanassche@acm.org>2022-04-21 15:18:29 -0700
committerJaegeuk Kim <jaegeuk@kernel.org>2022-04-22 12:42:52 -0700
commitb964b79d495d058f645f5a63357699a6c295025e (patch)
treea9bae73f7c269f6ecb760b1a8bff0619b20c0b40
parent28de4d1334d4519c1a64659245dfd84cc2ddfa6c (diff)
downloadf2fs-tools-b964b79d495d058f645f5a63357699a6c295025e.tar.gz
Change #ifdef _WIN32 checks into #ifdef HAVE_.*
It is recommended to test a HAVE_* macro instead of directly testing the host type in source code. Hence this patch. Signed-off-by: Bart Van Assche <bvanassche@acm.org> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
-rw-r--r--configure.ac2
-rw-r--r--lib/libf2fs.c4
-rw-r--r--lib/libf2fs_io.c10
-rw-r--r--lib/libf2fs_zoned.c2
-rw-r--r--mkfs/f2fs_format.c4
-rw-r--r--mkfs/f2fs_format_main.c2
-rw-r--r--mkfs/f2fs_format_utils.c7
7 files changed, 22 insertions, 9 deletions
diff --git a/configure.ac b/configure.ac
index fc094b7..f0ed5f6 100644
--- a/configure.ac
+++ b/configure.ac
@@ -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
diff --git a/lib/libf2fs.c b/lib/libf2fs.c
index 8bec68c..63d07f2 100644
--- a/lib/libf2fs.c
+++ b/lib/libf2fs.c
@@ -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
diff --git a/lib/libf2fs_io.c b/lib/libf2fs_io.c
index 2871993..09a6892 100644
--- a/lib/libf2fs_io.c
+++ b/lib/libf2fs_io.c
@@ -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");
diff --git a/lib/libf2fs_zoned.c b/lib/libf2fs_zoned.c
index 2dfed79..c5c6dde 100644
--- a/lib/libf2fs_zoned.c
+++ b/lib/libf2fs_zoned.c
@@ -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>
diff --git a/mkfs/f2fs_format.c b/mkfs/f2fs_format.c
index 6f2761c..ce7d1c9 100644
--- a/mkfs/f2fs_format.c
+++ b/mkfs/f2fs_format.c
@@ -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>
diff --git a/mkfs/f2fs_format_main.c b/mkfs/f2fs_format_main.c
index 4d4fad9..b8936f1 100644
--- a/mkfs/f2fs_format_main.c
+++ b/mkfs/f2fs_format_main.c
@@ -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>
diff --git a/mkfs/f2fs_format_utils.c b/mkfs/f2fs_format_utils.c
index 53101d1..e3c5893 100644
--- a/mkfs/f2fs_format_utils.c
+++ b/mkfs/f2fs_format_utils.c
@@ -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;