Skip to content

Commit 0c5bfdc

Browse files
committed
common: build fixes for FreeBSD (stat64/lstat64, headers, logging)
These are the core FreeBSD portability changes extracted from the FreeBSD ports tree work. The port currently is still under review. Port PR: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=291679 Port review: https://reviews.freebsd.org/D54230 The Patches: - Add FreeBSD compatibility for stat64/lstat64 by mapping them to stat/lstat (which are 64 bit by default on FreeBSD) - Include missing system headers in the path/parameter helper so struct stat and related macros are consistently available - Fix MFU_LOG(... "errno=%d %s" ...) callsites in mfu_util.c to actually pass both errno and strerrno(errno) (prevents format/argument mismatch and undefined behavior) - Include <fcntl.h> in mfu_util.c for file/flag-related definitions used by the code on non-Linux systems Signed-off-by: Rikka Göring <rikka.goering@outlook.de>
1 parent 5114273 commit 0c5bfdc

21 files changed

Lines changed: 190 additions & 22 deletions

src/common/mfu_bz2.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55
#include <string.h>
66
#include <errno.h>
77

8-
/* for statfs */
9-
#include <sys/vfs.h>
8+
#if defined(__linux__)
9+
#include <sys/vfs.h> /* for statfs */
10+
#endif
1011

12+
#if defined(__linux__) && LUSTRE_SUPPORT
1113
/* for LL_SUPER_MAGIC */
12-
#if LUSTRE_SUPPORT
1314
#include <lustre/lustre_user.h>
14-
#endif /* LUSTRE_SUPPORT */
15+
#endif /* __linux__ && LUSTRE_SUPPORT */
1516

1617
#include "mpi.h"
1718
#include "mfu.h"

src/common/mfu_bz2.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef MFU_BZ2_H
22
#define MFU_BZ2_H
33

4+
int mfu_compress_bz2_static(const char* src_name, const char* dst_name, int b_size);
45
int mfu_compress_bz2(const char* src_name, const char* dst_name, int b_size);
56
int mfu_decompress_bz2(const char* src_name, const char* dst_name);
67

src/common/mfu_bz2_static.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
#include <unistd.h>
66
#include <stdio.h>
77
#include <stdlib.h>
8+
#if defined(__linux__)
89
#include <sys/sysinfo.h>
10+
#endif
911
#include <string.h>
1012
#include <sys/time.h>
1113
#include <sys/resource.h>
@@ -23,6 +25,10 @@
2325
#include "mfu.h"
2426
#include "mfu_bz2.h"
2527

28+
#ifndef O_LARGEFILE
29+
#define O_LARGEFILE 0
30+
#endif
31+
2632
#define FILE_MODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)
2733

2834
int mfu_compress_bz2_static(const char* src_name, const char* dst_name, int b_size)

src/common/mfu_compress_bz2_libcircle.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
#include <unistd.h>
66
#include <stdio.h>
77
#include <stdlib.h>
8+
#if defined(__linux__)
89
#include <sys/sysinfo.h>
10+
#endif
911
#include <string.h>
1012
#include <sys/time.h>
1113
#include <sys/resource.h>
@@ -23,6 +25,7 @@
2325
#include "mfu.h"
2426
#include "mfu_bz2.h"
2527

28+
#if defined(__linux__)
2629
#define FILE_MODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)
2730

2831
struct block_info {
@@ -531,3 +534,11 @@ int mfu_compress_bz2_libcircle(const char* src, const char* dst, int b_size, ssi
531534

532535
return rc;
533536
}
537+
#else
538+
int mfu_compress_bz2_libcircle(const char* src, const char* dst,
539+
int b_size, ssize_t opts_memory)
540+
{
541+
(void)opts_memory;
542+
return mfu_compress_bz2_static(src, dst, b_size);
543+
}
544+
#endif

src/common/mfu_decompress_bz2_libcircle.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
#include <unistd.h>
66
#include <stdio.h>
77
#include <stdlib.h>
8+
#if defined(__linux__)
89
#include <sys/sysinfo.h>
10+
#endif
911
#include <string.h>
1012
#include <sys/time.h>
1113
#include <sys/resource.h>

src/common/mfu_flist.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
#include <stdlib.h>
1313
#include <sys/types.h>
1414
#include <sys/stat.h>
15+
#if !defined(__linux__)
16+
#undef DCOPY_USE_XATTRS
17+
#endif
1518
#include <string.h>
1619
#include <unistd.h>
1720
#include <getopt.h>
@@ -35,8 +38,10 @@
3538
#include <sys/ioctl.h>
3639
#include <sys/param.h>
3740

41+
#ifdef __linux__
3842
#include <linux/fs.h>
3943
#include <linux/fiemap.h>
44+
#endif
4045

4146
#include <libgen.h> /* dirname */
4247
#include "libcircle.h"

src/common/mfu_flist.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ extern "C" {
4444
#include <stdbool.h>
4545
#include "mpi.h"
4646

47-
#if DCOPY_USE_XATTRS
47+
#if defined(__linux__) && DCOPY_USE_XATTRS
4848
#include <sys/xattr.h>
4949
/*
5050
* Newer versions of attr deprecated attr/xattr.h which defines ENOATTR as a

src/common/mfu_flist_archive.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@
4040
#include <lustre/lustreapi.h>
4141
#endif
4242

43+
#ifndef O_NOATIME
44+
#define O_NOATIME 0
45+
#endif
46+
47+
#ifndef O_LARGEFILE
48+
#define O_LARGEFILE 0
49+
#endif
50+
4351
/* for magic value we use "DTAR_IDX" in ASCII (8-bit) */
4452
#define DTAR_MAGIC (0x445441525F494458)
4553

@@ -5265,7 +5273,12 @@ static int extract_xattrs(
52655273
r = archive_entry_xattr_next(entry, &xname, &xval, &xsize);
52665274
if (r == ARCHIVE_OK) {
52675275
/* successfully extracted xattr, now try to set it */
5276+
#ifdef __linux__
52685277
int set_rc = setxattr(path, xname, xval, xsize, 0);
5278+
#else
5279+
int set_rc = -1;
5280+
errno = ENOTSUP;
5281+
#endif
52695282
if (set_rc == -1) {
52705283
MFU_LOG(MFU_LOG_ERR, "failed to setxattr '%s' on '%s' errno=%d %s",
52715284
xname, path, errno, strerror(errno)

src/common/mfu_flist_copy.c

Lines changed: 62 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,15 @@
3939
#include <sys/ioctl.h>
4040
#include <sys/param.h>
4141

42+
#ifdef __linux__
4243
#include <linux/fs.h>
4344
#include <linux/fiemap.h>
45+
typedef __u64 mfu_u64;
46+
typedef __u32 mfu_u32;
47+
#else
48+
typedef uint64_t mfu_u64;
49+
typedef uint32_t mfu_u32;
50+
#endif
4451

4552
/* define PRI64 */
4653
#include <inttypes.h>
@@ -72,6 +79,10 @@
7279
#include <linux/hpssfs.h>
7380
#endif
7481

82+
#ifndef O_NOATIME
83+
#define O_NOATIME 0
84+
#endif
85+
7586
/****************************************
7687
* Define types
7788
***************************************/
@@ -99,6 +110,47 @@ typedef struct {
99110
#endif
100111
} mfu_copy_file_cache_t;
101112

113+
#if DCOPY_USE_XATTRS && !defined(__linux__)
114+
115+
#include <errno.h>
116+
#include <sys/types.h>
117+
118+
static inline ssize_t
119+
llistxattr(const char *path, char *list, size_t size)
120+
{
121+
(void)path;
122+
(void)list;
123+
(void)size;
124+
errno = ENOTSUP;
125+
return -1;
126+
}
127+
128+
static inline ssize_t
129+
lgetxattr(const char *path, const char *name, void *value, size_t size)
130+
{
131+
(void)path;
132+
(void)name;
133+
(void)value;
134+
(void)size;
135+
errno = ENOTSUP;
136+
return -1;
137+
}
138+
139+
static inline int
140+
lsetxattr(const char *path, const char *name,
141+
const void *value, size_t size, int flags)
142+
{
143+
(void)path;
144+
(void)name;
145+
(void)value;
146+
(void)size;
147+
(void)flags;
148+
errno = ENOTSUP;
149+
return -1;
150+
}
151+
152+
#endif
153+
102154
/****************************************
103155
* Define globals
104156
***************************************/
@@ -1889,13 +1941,13 @@ static int mfu_copy_file_normal(
18891941
}
18901942

18911943
struct mfu_extent {
1892-
__u64 me_logical; /* logical offset in bytes for the start of the extent */
1893-
__u64 me_length; /* length in bytes for this extent */
1944+
mfu_u64 me_logical; /* logical offset in bytes for the start of the extent */
1945+
mfu_u64 me_length; /* length in bytes for this extent */
18941946
};
18951947

18961948
struct mfu_extent_list {
1897-
__u32 mel_mapped_extents;/* number of extents that were mapped */
1898-
__u32 mel_extent_count; /* size of fm_extents array */
1949+
mfu_u32 mel_mapped_extents;/* number of extents that were mapped */
1950+
mfu_u32 mel_extent_count; /* size of fm_extents array */
18991951
struct mfu_extent mel_extents[0]; /* array of mapped extents */
19001952
};
19011953

@@ -1926,6 +1978,7 @@ struct mfu_extent_list *mfu_extent_list_realloc(struct mfu_extent_list *orig, si
19261978
return extent_list;
19271979
}
19281980

1981+
#ifdef __linux__
19291982
static struct mfu_extent_list * mfu_fiemap_get_extents(
19301983
const char* src,
19311984
const char* dest,
@@ -2026,6 +2079,7 @@ static struct mfu_extent_list * mfu_fiemap_get_extents(
20262079
fail_no_fiemap:
20272080
return NULL;
20282081
}
2082+
#endif
20292083

20302084
/*
20312085
* if returned extent_list * is non-NULL, and normal_copy_required == false,
@@ -2175,6 +2229,7 @@ static int mfu_copy_file_extents(
21752229
free(extent_list);
21762230
}
21772231

2232+
#ifdef __linux__
21782233
/* extents acquired by fiemap ioctl */
21792234
extent_list = mfu_fiemap_get_extents( src, dest,
21802235
offset, length, file_size, normal_copy_required, copy_opts,
@@ -2183,6 +2238,9 @@ static int mfu_copy_file_extents(
21832238
if (!extent_list || *normal_copy_required == true) {
21842239
goto fail_fiemap;
21852240
}
2241+
#else
2242+
goto fail_normal_copy;
2243+
#endif
21862244
}
21872245

21882246
/* seek to offset in source file */

src/common/mfu_flist_walk.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@
3939
#include "mfu_flist_internal.h"
4040
#include "strmap.h"
4141

42+
#ifndef O_NOATIME
43+
#define O_NOATIME 0
44+
#endif
45+
4246
/****************************************
4347
* Globals
4448
***************************************/
@@ -205,7 +209,13 @@ static void walk_getdents_process_dir(const char* dir, CIRCLE_handle* handle)
205209
/* Read all directory entries */
206210
while (1) {
207211
/* execute system call to get block of directory entries */
208-
int nread = syscall(SYS_getdents, mfu_file->fd, buf, (int) BUF_SIZE);
212+
int nread;
213+
214+
#ifdef __linux__
215+
nread = syscall(SYS_getdents, mfu_file->fd, buf, (int)BUF_SIZE);
216+
#else
217+
nread = getdents(mfu_file->fd, buf, (size_t)BUF_SIZE);
218+
#endif
209219
if (nread == -1) {
210220
MFU_LOG(MFU_LOG_ERR, "syscall to getdents failed when reading `%s' (errno=%d %s)", dir, errno, strerror(errno));
211221
WALK_RESULT = -1;
@@ -767,7 +777,7 @@ void mfu_flist_stat(
767777
/* check whether we should skip this item */
768778
if (skip_fn != NULL && skip_fn(name, skip_args)) {
769779
/* skip this file, don't include it in new list */
770-
MFU_LOG(MFU_LOG_INFO, "skip %s");
780+
MFU_LOG(MFU_LOG_INFO, "skip %s", name);
771781
continue;
772782
}
773783

0 commit comments

Comments
 (0)