--- /dev/null
+/*
+ * Copyright 2021 Olaf Wintermann
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef MZCP_ATOMIC_H
+#define MZCP_ATOMIC_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#if defined(__clang__) || defined(__GNUC__)
+
+#define mz_atomic_inc64(intptr) __sync_fetch_and_add(intptr, 1)
+#define mz_atomic_dec64(intptr) __sync_fetch_and_sub(intptr, 1)
+#define mz_atomic_add64(intptr, val) __sync_fetch_and_add(intptr, val)
+
+#elif defined(__sun)
+
+#include <atomic.h>
+
+#define mz_atomic_inc64(intptr) atomic_inc_64_nv(intptr)
+#define mz_atomic_dec64(intptr) atomic_dec_64_nv(intptr)
+#define mz_atomic_add64(intptr, val) atomic_add_64_nv(intptr, val)
+
+#endif
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* MZCP_ATOMIC_H */
+
#include "main.h"
#include "srvctrl.h"
+#include "atomic.h"
#include <stdio.h>
#include <stdlib.h>
+#include <inttypes.h>
#include <string.h>
#include <unistd.h>
#include <signal.h>
static int scan_complete;
+
+static uint64_t stat_num_files;
+static uint64_t stat_copied_files;
+static uint64_t stat_error_files;
+static uint64_t stat_total_size;
+static uint64_t stat_copied_size;
+
int main(int argc, char** argv) {
int ret = 1;
SrcFile *f = calloc(1, sizeof(SrcFile));
f->path = util_concat_path(elm->path, name);
f->isdir = S_ISDIR(s.st_mode);
+ f->size = s.st_size;
f->mode = s.st_mode;
f->depends_on = elm;
// TODO: error?
fprintf(stderr, "enqueue failed\n");
break;
+ } else {
+ mz_atomic_inc64(&stat_num_files);
+ int64_t sz = s.st_size;
+ mz_atomic_add64(&stat_total_size, sz);
}
// put dir on stack
return 1;
}
+ int64_t copied = 0;
ssize_t r;
while((r = read(fin, buffer, bufsize)) > 0) {
- if(write(fout, buffer, r) != r) {
+ ssize_t w = write(fout, buffer, r);
+ if(w > 0) {
+ mz_atomic_add64(&stat_copied_size, w);
+ copied += w;
+ }
+ if(w != r) {
ret = 1;
break;
}
close(fin);
close(fout);
- file_set_status(file, !ret ? 1 : -1);
+ if(!ret) {
+ file_set_status(file, 1);
+ mz_atomic_inc64(&stat_copied_files);
+ if(copied != file->size) {
+ // size changed after scan -> readjust total size
+ int64_t filesz_diff = copied - file->size;
+ mz_atomic_add64(&stat_total_size, filesz_diff);
+ }
+ } else {
+ file_set_status(file, -1);
+ mz_atomic_inc64(&stat_error_files);
+ if(copied != file->size) {
+ // count the full file size as copied, although we had an error
+ int64_t filesz_diff = file->size - copied;
+ mz_atomic_add64(&stat_copied_size, filesz_diff);
+ }
+ }
return ret;
}
*/
mode_t mode;
+ /*
+ * file size
+ */
+ uint64_t size;
+
/*
* processing this file depends on another file (directory)
*/
--- /dev/null
+/*
+ * Copyright 2019 Olaf Wintermann
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#include "vfs.h"
--- /dev/null
+/*
+ * Copyright 2019 Olaf Wintermann
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef VFS_H
+#define VFS_H
+
+#include <stdlib.h>
+#include <unistd.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* VFS_H */
+