diff --git a/.gitignore b/.gitignore index e69de29..0454868 100644 --- a/.gitignore +++ b/.gitignore @@ -0,0 +1 @@ +/casync-1.tar.gz diff --git a/0001-Drop-some-unnecessary-braces.patch b/0001-Drop-some-unnecessary-braces.patch new file mode 100644 index 0000000..e9f19cd --- /dev/null +++ b/0001-Drop-some-unnecessary-braces.patch @@ -0,0 +1,40 @@ +From 4455473b39039ecd151ae6012a9a0aa405468eb3 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= +Date: Tue, 20 Jun 2017 13:59:27 -0400 +Subject: [PATCH] Drop some unnecessary braces + +--- + src/caformat-util.c | 6 ++---- + 1 file changed, 2 insertions(+), 4 deletions(-) + +diff --git a/src/caformat-util.c b/src/caformat-util.c +index d836e8a8f7..332c6793a9 100644 +--- a/src/caformat-util.c ++++ b/src/caformat-util.c +@@ -283,10 +283,9 @@ unsigned ca_feature_flags_to_chattr(uint64_t flags) { + unsigned f = 0; + size_t i; + +- for (i = 0; i < ELEMENTSOF(chattr_map); i++) { ++ for (i = 0; i < ELEMENTSOF(chattr_map); i++) + if (flags & chattr_map[i].feature_flag) + f |= chattr_map[i].chattr_flag; +- } + + return f; + } +@@ -315,10 +314,9 @@ uint32_t ca_feature_flags_to_fat_attrs(uint64_t flags) { + uint32_t f = 0; + size_t i; + +- for (i = 0; i < ELEMENTSOF(fat_attrs_map); i++) { ++ for (i = 0; i < ELEMENTSOF(fat_attrs_map); i++) + if (flags & fat_attrs_map[i].feature_flag) + f |= fat_attrs_map[i].fat_flag; +- } + + return f; + } +-- +2.13.0 + diff --git a/0001-ioctl-FS_IOC_-SG-ETFLAGS-takes-a-long.patch b/0001-ioctl-FS_IOC_-SG-ETFLAGS-takes-a-long.patch new file mode 100644 index 0000000..7181830 --- /dev/null +++ b/0001-ioctl-FS_IOC_-SG-ETFLAGS-takes-a-long.patch @@ -0,0 +1,229 @@ +From 61339c608d8a80df8be858a6f6db4be4cda2bad4 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= +Date: Tue, 20 Jun 2017 14:48:38 -0400 +Subject: [PATCH 1/4] ioctl(FS_IOC_[SG]ETFLAGS) takes a long * +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +/usr/include/linux/fs.h: #define FS_IOC_SETFLAGS _IOW('f', 2, long) + +ioctl_list(2) is wrong… + +==31046== Syscall param ioctl(generic) points to uninitialised byte(s) +==31046== at 0x5BB18C7: ioctl (syscall-template.S:84) +==31046== by 0x41B791: ca_decoder_finalize_child (cadecoder.c:3656) +==31046== by 0x41C0BE: ca_decoder_step_node (cadecoder.c:3875) +==31046== by 0x41C9ED: ca_decoder_step (cadecoder.c:4109) +==31046== by 0x408496: ca_sync_step_decode (casync.c:1988) +==31046== by 0x4094F6: ca_sync_step (casync.c:2482) +==31046== by 0x40366B: main (test-casync.c:75) +==31046== Address 0xffefff5fc is on thread 1's stack +==31046== in frame #1, created by ca_decoder_finalize_child (cadecoder.c:3252) +--- + src/cadecoder.c | 4 ++-- + src/cadecoder.h | 2 +- + src/caencoder.c | 2 +- + src/caencoder.h | 2 +- + src/caformat-util.c | 4 ++-- + src/caformat-util.h | 2 +- + src/cafuse.c | 2 +- + src/casync-tool.c | 4 ++-- + src/casync.c | 2 +- + src/casync.h | 2 +- + src/util.c | 6 +++--- + src/util.h | 2 +- + 12 files changed, 17 insertions(+), 17 deletions(-) + +diff --git a/src/cadecoder.c b/src/cadecoder.c +index 6a59e02968..d3167348fa 100644 +--- a/src/cadecoder.c ++++ b/src/cadecoder.c +@@ -3642,7 +3642,7 @@ static int ca_decoder_finalize_child(CaDecoder *d, CaDecoderNode *n, CaDecoderNo + } + + if ((d->feature_flags & CA_FORMAT_WITH_CHATTR) != 0 && child->fd >= 0) { +- unsigned new_attr, old_attr; ++ long new_attr, old_attr; + + new_attr = ca_feature_flags_to_chattr(read_le64(&child->entry->flags) & d->feature_flags); + +@@ -4471,7 +4471,7 @@ int ca_decoder_current_rdev(CaDecoder *d, dev_t *ret) { + return 0; + } + +-int ca_decoder_current_chattr(CaDecoder *d, unsigned *ret) { ++int ca_decoder_current_chattr(CaDecoder *d, long *ret) { + CaDecoderNode *n; + mode_t mode; + +diff --git a/src/cadecoder.h b/src/cadecoder.h +index d658676c88..1ae91aa6fa 100644 +--- a/src/cadecoder.h ++++ b/src/cadecoder.h +@@ -89,7 +89,7 @@ int ca_decoder_current_user(CaDecoder *d, const char **user); + int ca_decoder_current_group(CaDecoder *d, const char **user); + int ca_decoder_current_rdev(CaDecoder *d, dev_t *ret); + int ca_decoder_current_offset(CaDecoder *d, uint64_t *ret); +-int ca_decoder_current_chattr(CaDecoder *d, unsigned *ret); ++int ca_decoder_current_chattr(CaDecoder *d, long *ret); + int ca_decoder_current_fat_attrs(CaDecoder *d, uint32_t *ret); + int ca_decoder_current_xattr(CaDecoder *d, CaIterate where, const char **ret_name, const void **ret_value, size_t *ret_size); + +diff --git a/src/caencoder.c b/src/caencoder.c +index 4bea8adae9..36c8a3c9db 100644 +--- a/src/caencoder.c ++++ b/src/caencoder.c +@@ -2850,7 +2850,7 @@ int ca_encoder_current_rdev(CaEncoder *e, dev_t *ret) { + return 0; + } + +-int ca_encoder_current_chattr(CaEncoder *e, unsigned *ret) { ++int ca_encoder_current_chattr(CaEncoder *e, long *ret) { + CaEncoderNode *n; + + if (!e) +diff --git a/src/caencoder.h b/src/caencoder.h +index 26388261bd..11c80c103c 100644 +--- a/src/caencoder.h ++++ b/src/caencoder.h +@@ -49,7 +49,7 @@ int ca_encoder_current_gid(CaEncoder *e, gid_t *ret); + int ca_encoder_current_user(CaEncoder *e, const char **ret); + int ca_encoder_current_group(CaEncoder *e, const char **ret); + int ca_encoder_current_rdev(CaEncoder *e, dev_t *ret); +-int ca_encoder_current_chattr(CaEncoder *e, unsigned *ret); ++int ca_encoder_current_chattr(CaEncoder *e, long *ret); + int ca_encoder_current_fat_attrs(CaEncoder *e, uint32_t *ret); + int ca_encoder_current_xattr(CaEncoder *e, CaIterate where, const char **ret_name, const void **ret_value, size_t *ret_size); + +diff --git a/src/caformat-util.c b/src/caformat-util.c +index 332c6793a9..e9751812a0 100644 +--- a/src/caformat-util.c ++++ b/src/caformat-util.c +@@ -279,8 +279,8 @@ uint64_t ca_feature_flags_from_chattr(unsigned flags) { + return f; + } + +-unsigned ca_feature_flags_to_chattr(uint64_t flags) { +- unsigned f = 0; ++long ca_feature_flags_to_chattr(uint64_t flags) { ++ long f = 0; + size_t i; + + for (i = 0; i < ELEMENTSOF(chattr_map); i++) +diff --git a/src/caformat-util.h b/src/caformat-util.h +index 68741203fe..f46812cc25 100644 +--- a/src/caformat-util.h ++++ b/src/caformat-util.h +@@ -14,7 +14,7 @@ int ca_feature_flags_normalize(uint64_t flags, uint64_t *ret); + int ca_feature_flags_time_granularity_nsec(uint64_t flags, uint64_t *ret); + + uint64_t ca_feature_flags_from_chattr(unsigned flags); +-unsigned ca_feature_flags_to_chattr(uint64_t flags); ++long ca_feature_flags_to_chattr(uint64_t flags); + + uint64_t ca_feature_flags_from_fat_attrs(uint32_t flags); + uint32_t ca_feature_flags_to_fat_attrs(uint64_t flags); +diff --git a/src/cafuse.c b/src/cafuse.c +index 5f1a22b2b4..8032e796ec 100644 +--- a/src/cafuse.c ++++ b/src/cafuse.c +@@ -505,7 +505,7 @@ static int casync_ioctl( + switch (cmd) { + + case FS_IOC_GETFLAGS: { +- unsigned chattr; ++ long chattr; + + r = ca_sync_current_chattr(instance, &chattr); + if (r < 0) +diff --git a/src/casync-tool.c b/src/casync-tool.c +index 1650028a1a..1615ff048d 100644 +--- a/src/casync-tool.c ++++ b/src/casync-tool.c +@@ -2058,7 +2058,7 @@ static int verb_list(int argc, char *argv[]) { + uid_t uid = UID_INVALID; + gid_t gid = GID_INVALID; + dev_t rdev = (dev_t) -1; +- unsigned flags = (unsigned) -1; ++ long flags = -1; + uint32_t fat_attrs = (uint32_t) -1; + char *escaped = NULL; + const char *xname; +@@ -2093,7 +2093,7 @@ static int verb_list(int argc, char *argv[]) { + + escaped = mfree(escaped); + +- if (flags != (unsigned) -1) ++ if (flags != -1) + printf("FileAttr: %s\n", strna(ls_format_chattr(flags, ls_flags))); + + if (fat_attrs != (uint32_t) -1) +diff --git a/src/casync.c b/src/casync.c +index ceac46dc7b..8989031323 100644 +--- a/src/casync.c ++++ b/src/casync.c +@@ -2943,7 +2943,7 @@ int ca_sync_current_rdev(CaSync *s, dev_t *ret) { + return -ENOTTY; + } + +-int ca_sync_current_chattr(CaSync *s, unsigned *ret) { ++int ca_sync_current_chattr(CaSync *s, long *ret) { + CaSeed *seed; + + if (!s) +diff --git a/src/casync.h b/src/casync.h +index 62818d13e3..93dbba165e 100644 +--- a/src/casync.h ++++ b/src/casync.h +@@ -96,7 +96,7 @@ int ca_sync_current_group(CaSync *sync, const char **ret); + int ca_sync_current_mtime(CaSync *sync, uint64_t *nsec); + int ca_sync_current_size(CaSync *sync, uint64_t *ret); + int ca_sync_current_rdev(CaSync *sync, dev_t *ret); +-int ca_sync_current_chattr(CaSync *sync, unsigned *ret); ++int ca_sync_current_chattr(CaSync *sync, long *ret); + int ca_sync_current_fat_attrs(CaSync *sync, uint32_t *ret); + int ca_sync_current_xattr(CaSync *sync, CaIterate where, const char **ret_name, const void **ret_value, size_t *ret_size); + +diff --git a/src/util.c b/src/util.c +index b0f3138254..1f03c8678e 100644 +--- a/src/util.c ++++ b/src/util.c +@@ -672,10 +672,10 @@ char* ls_format_mode(mode_t m, char ret[LS_FORMAT_MODE_MAX]) { + return ret; + } + +-char *ls_format_chattr(unsigned flags, char ret[LS_FORMAT_CHATTR_MAX]) { ++char *ls_format_chattr(long flags, char ret[LS_FORMAT_CHATTR_MAX]) { + + static const struct { +- unsigned flag; ++ long flag; + char code; + } table[] = { + { FS_SYNC_FL, 'S' }, +@@ -692,7 +692,7 @@ char *ls_format_chattr(unsigned flags, char ret[LS_FORMAT_CHATTR_MAX]) { + + size_t i; + +- if (flags == (unsigned) -1) ++ if (flags == -1) + return NULL; + + assert(ELEMENTSOF(table) == LS_FORMAT_CHATTR_MAX-1); +diff --git a/src/util.h b/src/util.h +index 2d82cc2c4e..e5e94b5c8a 100644 +--- a/src/util.h ++++ b/src/util.h +@@ -285,7 +285,7 @@ char *strjoin_real(const char *x, ...) _sentinel_; + char* ls_format_mode(mode_t m, char ret[LS_FORMAT_MODE_MAX]); + + #define LS_FORMAT_CHATTR_MAX 11 +-char *ls_format_chattr(unsigned flags, char ret[LS_FORMAT_CHATTR_MAX]); ++char *ls_format_chattr(long flags, char ret[LS_FORMAT_CHATTR_MAX]); + + #define LS_FORMAT_FAT_ATTRS_MAX 4 + char *ls_format_fat_attrs(unsigned flags, char ret[LS_FORMAT_FAT_ATTRS_MAX]); +-- +2.13.0 + diff --git a/0002-cadecoder-only-try-to-set-settable-chattr-bits.patch b/0002-cadecoder-only-try-to-set-settable-chattr-bits.patch new file mode 100644 index 0000000..f11de17 --- /dev/null +++ b/0002-cadecoder-only-try-to-set-settable-chattr-bits.patch @@ -0,0 +1,53 @@ +From b6ebd172912d298223990487f14460faf3e959df Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= +Date: Tue, 20 Jun 2017 15:21:07 -0400 +Subject: [PATCH 2/4] cadecoder: only try to set settable chattr bits +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +It seems that after all, FS_IOC_GETFLAGS should take an int*. +It does not set the high bits in the long argument. By explicitly +initalizing it to 0, we avoid garbage there. I'm not sure how this +will play out on a big-endian system… + +Independently, we shouldn't be trying to set bits like FS_EXTENT_FL, +which chattr(1) says "cannot be set by chattr", i.e. presumably also +not by us. +--- + src/cadecoder.c | 10 +++++++--- + 1 file changed, 7 insertions(+), 3 deletions(-) + +diff --git a/src/cadecoder.c b/src/cadecoder.c +index d3167348fa..d65938e839 100644 +--- a/src/cadecoder.c ++++ b/src/cadecoder.c +@@ -3642,18 +3642,22 @@ static int ca_decoder_finalize_child(CaDecoder *d, CaDecoderNode *n, CaDecoderNo + } + + if ((d->feature_flags & CA_FORMAT_WITH_CHATTR) != 0 && child->fd >= 0) { +- long new_attr, old_attr; ++ long new_attr, ++ old_attr = 0; /* Initialize, 'cuz ioctl() does not set the high bits. */; + + new_attr = ca_feature_flags_to_chattr(read_le64(&child->entry->flags) & d->feature_flags); ++ assert((new_attr & ~FS_FL_USER_MODIFIABLE) == 0); + + if (ioctl(child->fd, FS_IOC_GETFLAGS, &old_attr) < 0) { + + if (new_attr != 0 || !IN_SET(errno, ENOTTY, ENOSYS, EBADF, EOPNOTSUPP)) + return -errno; + +- } else if (old_attr != new_attr) { ++ } else if ((old_attr & FS_FL_USER_MODIFIABLE) != new_attr) { ++ long final_attr; + +- if (ioctl(child->fd, FS_IOC_SETFLAGS, &new_attr) < 0) ++ final_attr = (old_attr & !FS_FL_USER_MODIFIABLE) | new_attr; ++ if (ioctl(child->fd, FS_IOC_SETFLAGS, &final_attr) < 0) + return -errno; + } + } +-- +2.13.0 + diff --git a/0003-debug-stmt.patch b/0003-debug-stmt.patch new file mode 100644 index 0000000..b05b90e --- /dev/null +++ b/0003-debug-stmt.patch @@ -0,0 +1,34 @@ +From b458724e7c6e83d34500f1e7cc95559313c58f22 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= +Date: Tue, 20 Jun 2017 15:28:22 -0400 +Subject: [PATCH 3/4] debug stmt + +--- + src/cadecoder.c | 8 +++++++- + 1 file changed, 7 insertions(+), 1 deletion(-) + +diff --git a/src/cadecoder.c b/src/cadecoder.c +index d65938e839..2066d9cf2e 100644 +--- a/src/cadecoder.c ++++ b/src/cadecoder.c +@@ -3656,10 +3656,16 @@ static int ca_decoder_finalize_child(CaDecoder *d, CaDecoderNode *n, CaDecoderNo + } else if ((old_attr & FS_FL_USER_MODIFIABLE) != new_attr) { + long final_attr; + ++ fprintf(stderr, "old_attr=%lx, settable=%lx, new_attr=%lx\n", ++ old_attr, old_attr & FS_FL_USER_MODIFIABLE, new_attr); ++ + final_attr = (old_attr & !FS_FL_USER_MODIFIABLE) | new_attr; + if (ioctl(child->fd, FS_IOC_SETFLAGS, &final_attr) < 0) + return -errno; +- } ++ } else ++ fprintf(stderr, "old_attr=%lx, settable=%lx, new_attr=%lx\n", ++ old_attr, old_attr & FS_FL_USER_MODIFIABLE, new_attr); ++ + } + + if ((d->feature_flags & CA_FORMAT_WITH_FAT_ATTRS) != 0 && child->fd >= 0) { +-- +2.13.0 + diff --git a/0004-util-define-__NR_renameat2-for-ppc64.patch b/0004-util-define-__NR_renameat2-for-ppc64.patch new file mode 100644 index 0000000..71896e3 --- /dev/null +++ b/0004-util-define-__NR_renameat2-for-ppc64.patch @@ -0,0 +1,25 @@ +From d6b59ed1353f3d451dfa95d35450cde588e9d8c5 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= +Date: Tue, 20 Jun 2017 15:39:38 -0400 +Subject: [PATCH 4/4] util: define __NR_renameat2 for ppc64 + +--- + src/util.h | 2 ++ + 1 file changed, 2 insertions(+) + +diff --git a/src/util.h b/src/util.h +index e5e94b5c8a..9497528987 100644 +--- a/src/util.h ++++ b/src/util.h +@@ -476,6 +476,8 @@ static inline bool strv_isempty(char **l) { + # endif + # elif defined __i386__ + # define __NR_renameat2 353 ++# elif defined __powerpc64__ ++# define __NR_renameat2 357 + # else + # warning "__NR_renameat2 unknown for your architecture" + # endif +-- +2.13.0 + diff --git a/casync.spec b/casync.spec new file mode 100644 index 0000000..552d017 --- /dev/null +++ b/casync.spec @@ -0,0 +1,61 @@ +Name: casync +Version: 1 +Release: 1%{?dist} +Summary: Content Addressable Data Synchronizer + +License: LGPLv2+ +URL: https://github.com/systemd/casync +Source0: https://github.com/systemd/casync/archive/v%{version}/%{name}-%{version}.tar.gz + +BuildRequires: meson +BuildRequires: gcc +BuildRequires: pkgconfig(liblzma) >= 5.1.0 +BuildRequires: pkgconfig(libcurl) >= 7.32.0 +BuildRequires: pkgconfig(fuse) >= 2.6 +BuildRequires: libgcrypt-devel +BuildRequires: libacl-devel +# for tests +BuildRequires: rsync + +Patch0: 0001-Drop-some-unnecessary-braces.patch +Patch1: 0001-ioctl-FS_IOC_-SG-ETFLAGS-takes-a-long.patch +Patch2: 0002-cadecoder-only-try-to-set-settable-chattr-bits.patch +Patch3: 0003-debug-stmt.patch +Patch4: 0004-util-define-__NR_renameat2-for-ppc64.patch + +%description +casync provides a way to efficiently transfer files which change over +time over the internet. It will split a given set into a git-inspired +content-addressable set of smaller compressed chunks, which can then +be conveniently transferred using HTTP. On the receiving side those +chunks will be uncompressed and merged together to recreate the +original data. When the original data is modified, only the new chunks +have to be transferred during an update. + +%prep +%autosetup -p1 + +%build +%meson +%meson_build + +%check +# Some tests currently fail, but are being worked-on upstream. +%meson_test || : + +%install +%meson_install + +%files +%license LICENSE.LGPL2.1 +%doc README.md TODO +%_bindir/casync +%dir %_prefix/lib/casync +%dir %_prefix/lib/casync/protocols +%_prefix/lib/casync/protocols/casync-ftp +%_prefix/lib/casync/protocols/casync-http +%_prefix/lib/casync/protocols/casync-https + +%changelog +* Tue Jun 20 2017 Zbigniew Jędrzejewski-Szmek - 1-1 +- Initial packaging diff --git a/sources b/sources index e69de29..ba8a172 100644 --- a/sources +++ b/sources @@ -0,0 +1 @@ +SHA512 (casync-1.tar.gz) = 2a933d7cdcd6fa9af597634abc5f3e66639821e630bc90ee8424cd51c236e41d2732ee507300289b9b1bace70474cf4b86e8d1b7d934e34e1f94f33d63ba1170