Skip to content

Commit 063ceea

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
1 parent 5114273 commit 063ceea

19 files changed

Lines changed: 148 additions & 18 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_copy.c

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,10 @@
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+
#endif
4446

4547
/* define PRI64 */
4648
#include <inttypes.h>
@@ -99,6 +101,47 @@ typedef struct {
99101
#endif
100102
} mfu_copy_file_cache_t;
101103

104+
#if DCOPY_USE_XATTRS && !defined(__linux__)
105+
106+
#include <errno.h>
107+
#include <sys/types.h>
108+
109+
static inline ssize_t
110+
llistxattr(const char *path, char *list, size_t size)
111+
{
112+
(void)path;
113+
(void)list;
114+
(void)size;
115+
errno = ENOTSUP;
116+
return -1;
117+
}
118+
119+
static inline ssize_t
120+
lgetxattr(const char *path, const char *name, void *value, size_t size)
121+
{
122+
(void)path;
123+
(void)name;
124+
(void)value;
125+
(void)size;
126+
errno = ENOTSUP;
127+
return -1;
128+
}
129+
130+
static inline int
131+
lsetxattr(const char *path, const char *name,
132+
const void *value, size_t size, int flags)
133+
{
134+
(void)path;
135+
(void)name;
136+
(void)value;
137+
(void)size;
138+
(void)flags;
139+
errno = ENOTSUP;
140+
return -1;
141+
}
142+
143+
#endif
144+
102145
/****************************************
103146
* Define globals
104147
***************************************/
@@ -1926,6 +1969,7 @@ struct mfu_extent_list *mfu_extent_list_realloc(struct mfu_extent_list *orig, si
19261969
return extent_list;
19271970
}
19281971

1972+
#ifdef __linux__
19291973
static struct mfu_extent_list * mfu_fiemap_get_extents(
19301974
const char* src,
19311975
const char* dest,
@@ -2026,6 +2070,7 @@ static struct mfu_extent_list * mfu_fiemap_get_extents(
20262070
fail_no_fiemap:
20272071
return NULL;
20282072
}
2073+
#endif
20292074

20302075
/*
20312076
* if returned extent_list * is non-NULL, and normal_copy_required == false,
@@ -2175,6 +2220,7 @@ static int mfu_copy_file_extents(
21752220
free(extent_list);
21762221
}
21772222

2223+
#ifdef __linux__
21782224
/* extents acquired by fiemap ioctl */
21792225
extent_list = mfu_fiemap_get_extents( src, dest,
21802226
offset, length, file_size, normal_copy_required, copy_opts,
@@ -2183,6 +2229,9 @@ static int mfu_copy_file_extents(
21832229
if (!extent_list || *normal_copy_required == true) {
21842230
goto fail_fiemap;
21852231
}
2232+
#else
2233+
goto fail_normal_copy;
2234+
#endif
21862235
}
21872236

21882237
/* seek to offset in source file */

src/common/mfu_flist_walk.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,13 @@ static void walk_getdents_process_dir(const char* dir, CIRCLE_handle* handle)
205205
/* Read all directory entries */
206206
while (1) {
207207
/* execute system call to get block of directory entries */
208-
int nread = syscall(SYS_getdents, mfu_file->fd, buf, (int) BUF_SIZE);
208+
int nread;
209+
210+
#ifdef __linux__
211+
nread = syscall(SYS_getdents, mfu_file->fd, buf, (int)BUF_SIZE);
212+
#else
213+
nread = getdents(mfu_file->fd, buf, (size_t)BUF_SIZE);
214+
#endif
209215
if (nread == -1) {
210216
MFU_LOG(MFU_LOG_ERR, "syscall to getdents failed when reading `%s' (errno=%d %s)", dir, errno, strerror(errno));
211217
WALK_RESULT = -1;
@@ -767,7 +773,7 @@ void mfu_flist_stat(
767773
/* check whether we should skip this item */
768774
if (skip_fn != NULL && skip_fn(name, skip_args)) {
769775
/* skip this file, don't include it in new list */
770-
MFU_LOG(MFU_LOG_INFO, "skip %s");
776+
MFU_LOG(MFU_LOG_INFO, "skip %s", name);
771777
continue;
772778
}
773779

src/common/mfu_io.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@
2121
#include "mfu.h"
2222
#include "mfu_errors.h"
2323

24+
#ifdef __FreeBSD__
25+
#undef lstat64
26+
#define lstat64(path, buf) lstat((path), (struct stat *)(buf))
27+
#endif
28+
2429
#define MFU_IO_TRIES (5)
2530
#define MFU_IO_USLEEP (100)
2631

0 commit comments

Comments
 (0)