Fix the MinGW build

commit 1790203deed19a93c60813f75956f2788ac96c95
category: bugfix
issue: #I6VAS0
CVE: NA

Signed-off-by: DongSenhao <dongsenhao2@huawei.com>
---------------------------------------

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

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Signed-off-by: dongsenhao <dongsenhao2@huawei.com>
This commit is contained in:
Bart Van Assche 2022-04-21 15:18:22 -07:00 committed by dongsenhao
parent 20f34a96bb
commit 1d9cbf3c83
14 changed files with 108 additions and 18 deletions

View File

@ -83,6 +83,12 @@ AC_CHECK_LIB([uuid], [uuid_clear],
[Define if you have libuuid]) [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. # Checks for header files.
AC_CHECK_HEADERS(m4_flatten([ AC_CHECK_HEADERS(m4_flatten([
attr/xattr.h attr/xattr.h
@ -100,6 +106,7 @@ AC_CHECK_HEADERS(m4_flatten([
linux/xattr.h linux/xattr.h
mach/mach_time.h mach/mach_time.h
mntent.h mntent.h
pthread_time.h
scsi/sg.h scsi/sg.h
selinux/selinux.h selinux/selinux.h
stdlib.h stdlib.h
@ -129,7 +136,9 @@ AC_CHECK_FUNCS_ONCE([
fsetxattr fsetxattr
fstat fstat
fstat64 fstat64
getgid
getmntent getmntent
getuid
keyctl keyctl
llseek llseek
lseek64 lseek64
@ -140,6 +149,18 @@ AC_CHECK_FUNCS_ONCE([
AS_IF([test "$ac_cv_header_byteswap_h" = "yes"], AS_IF([test "$ac_cv_header_byteswap_h" = "yes"],
[AC_CHECK_DECLS([bswap_64],,,[#include <byteswap.h>])]) [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 is needed to access the 'host_os' variable
AC_CANONICAL_HOST AC_CANONICAL_HOST
@ -209,4 +230,29 @@ AC_SUBST(LIBF2FS_CURRENT, 8)
AC_SUBST(LIBF2FS_REVISION, 0) AC_SUBST(LIBF2FS_REVISION, 0)
AC_SUBST(LIBF2FS_AGE, 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 AC_OUTPUT

View File

@ -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 \ node.c segment.c dir.c sload.c xattr.c compress.c \
dict.c mkquota.c quotaio.c quotaio_tree.c quotaio_v2.c dict.c mkquota.c quotaio.c quotaio_tree.c quotaio_v2.c
fsck_f2fs_LDADD = ${libselinux_LIBS} ${libuuid_LIBS} \ fsck_f2fs_LDADD = ${libselinux_LIBS} ${libuuid_LIBS} \
${liblzo2_LIBS} ${liblz4_LIBS} \ ${liblzo2_LIBS} ${liblz4_LIBS} ${libwinpthread_LIBS} \
$(top_builddir)/lib/libf2fs.la $(top_builddir)/lib/libf2fs.la
install-data-hook: install-data-hook:

View File

@ -474,11 +474,19 @@ static void init_inode_block(struct f2fs_sb_info *sbi,
links++; links++;
blocks++; blocks++;
} else if (de->file_type == F2FS_FT_REG_FILE) { } else if (de->file_type == F2FS_FT_REG_FILE) {
#ifdef S_IFREG
mode |= S_IFREG; mode |= S_IFREG;
#else
ASSERT(0);
#endif
size = 0; size = 0;
} else if (de->file_type == F2FS_FT_SYMLINK) { } else if (de->file_type == F2FS_FT_SYMLINK) {
ASSERT(de->link); ASSERT(de->link);
#ifdef S_IFLNK
mode |= S_IFLNK; mode |= S_IFLNK;
#else
ASSERT(0);
#endif
size = strlen(de->link); size = strlen(de->link);
if (size + 1 > MAX_INLINE_DATA(node_blk)) if (size + 1 > MAX_INLINE_DATA(node_blk))
blocks++; blocks++;

View File

@ -27,8 +27,12 @@
#include <mach/mach_time.h> #include <mach/mach_time.h>
#endif #endif
#include <sys/stat.h> #include <sys/stat.h>
#ifdef HAVE_SYS_IOCTL_H
#include <sys/ioctl.h> #include <sys/ioctl.h>
#endif
#ifdef HAVE_SYS_MOUNT_H
#include <sys/mount.h> #include <sys/mount.h>
#endif
#include <assert.h> #include <assert.h>
#include "f2fs_fs.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_IFCHR >> S_SHIFT] = F2FS_FT_CHRDEV,
[S_IFBLK >> S_SHIFT] = F2FS_FT_BLKDEV, [S_IFBLK >> S_SHIFT] = F2FS_FT_BLKDEV,
[S_IFIFO >> S_SHIFT] = F2FS_FT_FIFO, [S_IFIFO >> S_SHIFT] = F2FS_FT_FIFO,
#ifdef S_IFSOCK
[S_IFSOCK >> S_SHIFT] = F2FS_FT_SOCK, [S_IFSOCK >> S_SHIFT] = F2FS_FT_SOCK,
#endif
#ifdef S_IFLNK
[S_IFLNK >> S_SHIFT] = F2FS_FT_SYMLINK, [S_IFLNK >> S_SHIFT] = F2FS_FT_SYMLINK,
#endif
}; };
static inline int map_de_type(umode_t mode) static inline int map_de_type(umode_t mode)

View File

@ -1065,16 +1065,12 @@ static int do_label(struct f2fs_sb_info *sbi)
} }
#endif #endif
#if defined(__APPLE__) #ifdef HAVE_MACH_TIME_H
static u64 get_boottime_ns() static u64 get_boottime_ns()
{ {
#ifdef HAVE_MACH_TIME_H
return mach_absolute_time(); return mach_absolute_time();
#else
return 0;
#endif
} }
#else #elif defined(HAVE_CLOCK_GETTIME) && defined(HAVE_CLOCK_BOOTTIME)
static u64 get_boottime_ns() static u64 get_boottime_ns()
{ {
struct timespec t; struct timespec t;
@ -1082,6 +1078,11 @@ static u64 get_boottime_ns()
clock_gettime(CLOCK_BOOTTIME, &t); clock_gettime(CLOCK_BOOTTIME, &t);
return (u64)t.tv_sec * 1000000000LL + t.tv_nsec; return (u64)t.tv_sec * 1000000000LL + t.tv_nsec;
} }
#else
static u64 get_boottime_ns()
{
return 0;
}
#endif #endif
int main(int argc, char **argv) int main(int argc, char **argv)

View File

@ -31,6 +31,8 @@
#define ACL_OTHER (0x20) #define ACL_OTHER (0x20)
#endif #endif
#ifdef HAVE_LINUX_BLKZONED_H
static int get_device_idx(struct f2fs_sb_info *sbi, uint32_t segno) static int get_device_idx(struct f2fs_sb_info *sbi, uint32_t segno)
{ {
block_t seg_start_blkaddr; block_t seg_start_blkaddr;
@ -45,8 +47,6 @@ static int get_device_idx(struct f2fs_sb_info *sbi, uint32_t segno)
return 0; return 0;
} }
#ifdef HAVE_LINUX_BLKZONED_H
static int get_zone_idx_from_dev(struct f2fs_sb_info *sbi, static int get_zone_idx_from_dev(struct f2fs_sb_info *sbi,
uint32_t segno, uint32_t dev_idx) uint32_t segno, uint32_t dev_idx)
{ {

View File

@ -21,7 +21,6 @@
#include <limits.h> #include <limits.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <arpa/inet.h>
#include "dict.h" #include "dict.h"
#include "f2fs_fs.h" #include "f2fs_fs.h"

View File

@ -30,6 +30,7 @@ typedef void (*fs_config_f)(const char *path, int dir,
unsigned *uid, unsigned *gid, unsigned *uid, unsigned *gid,
unsigned *mode, uint64_t *capabilities); unsigned *mode, uint64_t *capabilities);
#ifndef _WIN32
static fs_config_f fs_config_func = NULL; static fs_config_f fs_config_func = NULL;
#ifdef WITH_ANDROID #ifdef WITH_ANDROID
@ -64,6 +65,7 @@ static int f2fs_make_directory(struct f2fs_sb_info *sbi,
return ret; return ret;
} }
#endif
#ifdef HAVE_LIBSELINUX #ifdef HAVE_LIBSELINUX
static int set_selinux_xattr(struct f2fs_sb_info *sbi, const char *path, static int set_selinux_xattr(struct f2fs_sb_info *sbi, const char *path,
@ -101,6 +103,7 @@ static int set_selinux_xattr(struct f2fs_sb_info *sbi, const char *path,
#define set_selinux_xattr(...) 0 #define set_selinux_xattr(...) 0
#endif #endif
#ifndef _WIN32
static int set_perms_and_caps(struct dentry *de) static int set_perms_and_caps(struct dentry *de)
{ {
uint64_t capabilities = 0; uint64_t capabilities = 0;
@ -293,6 +296,14 @@ out_free:
free(dentries); free(dentries);
return 0; 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) static int configure_files(void)
{ {

View File

@ -20,7 +20,14 @@
#include <sys/mount.h> #include <sys/mount.h>
#endif #endif
#include <time.h> #include <time.h>
#include "config.h"
#ifdef HAVE_UUID_UUID_H
#include <uuid/uuid.h> #include <uuid/uuid.h>
#else
#define uuid_parse(a, b) -1
#define uuid_generate(a)
#endif
#include "f2fs_fs.h" #include "f2fs_fs.h"
#include "quota.h" #include "quota.h"

View File

@ -21,7 +21,6 @@
#include <sys/mount.h> #include <sys/mount.h>
#endif #endif
#include <time.h> #include <time.h>
#include <uuid/uuid.h>
#include <errno.h> #include <errno.h>
#include <getopt.h> #include <getopt.h>
@ -29,6 +28,9 @@
#ifdef HAVE_LIBBLKID #ifdef HAVE_LIBBLKID
#include <blkid/blkid.h> #include <blkid/blkid.h>
#endif #endif
#ifdef HAVE_UUID_UUID_H
#include <uuid/uuid.h>
#endif
#include "f2fs_fs.h" #include "f2fs_fs.h"
#include "quota.h" #include "quota.h"

View File

@ -2,7 +2,10 @@
AM_CPPFLAGS = ${libuuid_CFLAGS} -I$(top_srcdir)/include AM_CPPFLAGS = ${libuuid_CFLAGS} -I$(top_srcdir)/include
AM_CFLAGS = -Wall 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 f2fstat_SOURCES = f2fstat.c
fibmap_f2fs_SOURCES = fibmap.c fibmap_f2fs_SOURCES = fibmap.c
parse_f2fs_SOURCES = f2fs_io_parse.c parse_f2fs_SOURCES = f2fs_io_parse.c

View File

@ -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() static u64 get_current_us()
{ {
#ifdef HAVE_MACH_TIME_H
return mach_absolute_time() / 1000; return mach_absolute_time() / 1000;
#else
return 0;
#endif
} }
#else #elif defined(HAVE_CLOCK_GETTIME) && defined(HAVE_CLOCK_BOOTTIME)
static u64 get_current_us() static u64 get_current_us()
{ {
struct timespec t; struct timespec t;
@ -149,6 +145,11 @@ static u64 get_current_us()
clock_gettime(CLOCK_BOOTTIME, &t); clock_gettime(CLOCK_BOOTTIME, &t);
return (u64)t.tv_sec * 1000000LL + t.tv_nsec / 1000; return (u64)t.tv_sec * 1000000LL + t.tv_nsec / 1000;
} }
#else
static u64 get_current_us()
{
return 0;
}
#endif #endif
#define fsync_desc "fsync" #define fsync_desc "fsync"

View File

@ -43,7 +43,9 @@
#ifdef __KERNEL__ #ifdef __KERNEL__
#include <linux/fs.h> #include <linux/fs.h>
#endif #endif
#ifdef HAVE_UUID_UUID_H
#include <uuid/uuid.h> #include <uuid/uuid.h>
#endif
#if !defined(HAVE_ADD_KEY) || !defined(HAVE_KEYCTL) #if !defined(HAVE_ADD_KEY) || !defined(HAVE_KEYCTL)
#include <sys/syscall.h> #include <sys/syscall.h>

View File

@ -23,7 +23,9 @@
#include <fcntl.h> #include <fcntl.h>
#include <errno.h> #include <errno.h>
#include <sys/types.h> #include <sys/types.h>
#ifdef HAVE_SYS_IOCTL_H
#include <sys/ioctl.h> #include <sys/ioctl.h>
#endif
#include <sys/stat.h> #include <sys/stat.h>
#ifdef HAVE_SYS_SYSMACROS_H #ifdef HAVE_SYS_SYSMACROS_H
#include <sys/sysmacros.h> #include <sys/sysmacros.h>