Initial s390-tools-2.0.0 import

This commit is based on the s390-tools-1.39.0 version.

Changes on top of s390-tools-1.39.0:

 - Add MIT license to all source files
 - Add LICENSE file
 - Transform REAMDE to README.md (markdown)
 - Add AUTHORS.md file
 - Add CONTRIBUTING.md file
 - Move changelog from README to CHANGELOG.md file

Reviewed-by: Stefan Haberland <sth@linux.vnet.ibm.com>
Signed-off-by: Michael Holzheu <holzheu@linux.vnet.ibm.com>
This commit is contained in:
Michael Holzheu
2017-08-07 16:13:17 +02:00
commit b627b8d8e1
647 changed files with 168974 additions and 0 deletions
+50
View File
@@ -0,0 +1,50 @@
/*
* dump2tar - tool to dump files and command output into a tar archive
*
* Data buffering functions
*
* Copyright IBM Corp. 2016, 2017
*
* s390-tools is free software; you can redistribute it and/or modify
* it under the terms of the MIT license. See LICENSE for details.
*/
#ifndef BUFFER_H
#define BUFFER_H
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
/* Buffers for building tar file entries */
struct buffer {
size_t total; /* Total number of bytes in buffer */
size_t off; /* Current offset to next free byte in memory buffer */
size_t size; /* Memory buffer size */
char *addr; /* Memory buffer address */
bool fd_open; /* Has fd been openend yet? */
FILE *file; /* FILE * of file containing previous buffer data */
int fd; /* Handle of file containing previous buffer data */
};
void buffer_init(struct buffer *buffer, size_t size);
struct buffer *buffer_alloc(size_t size);
void buffer_reset(struct buffer *buffer);
void buffer_close(struct buffer *buffer);
void buffer_free(struct buffer *buffer, bool dyn);
int buffer_open(struct buffer *buffer);
int buffer_flush(struct buffer *buffer);
ssize_t buffer_make_room(struct buffer *buffer, size_t size, bool usefile,
size_t max_buffer_size);
int buffer_truncate(struct buffer *buffer, size_t len);
ssize_t buffer_read_fd(struct buffer *buffer, int fd, size_t chunk,
bool usefile, size_t max_buffer_size);
int buffer_add_data(struct buffer *buffer, char *addr, size_t len,
bool usefile, size_t max_buffer_size);
typedef int (*buffer_cb_t)(void *data, void *addr, size_t len);
int buffer_iterate(struct buffer *buffer, buffer_cb_t cb, void *data);
void buffer_print(struct buffer *buffer);
#endif /* BUFFER_H */
+29
View File
@@ -0,0 +1,29 @@
/*
* dump2tar - tool to dump files and command output into a tar archive
*
* Reference counting for directory handles
*
* Copyright IBM Corp. 2016, 2017
*
* s390-tools is free software; you can redistribute it and/or modify
* it under the terms of the MIT license. See LICENSE for details.
*/
#ifndef DREF_H
#define DREF_H
#include <dirent.h>
#include <stdbool.h>
/* Multiple jobs may refer to an open DIR * - need reference counting */
struct dref {
DIR *dd;
int dirfd;
unsigned int count;
};
struct dref *dref_create(const char *dirname);
struct dref *dref_get(struct dref *dref);
void dref_put(struct dref *dref);
#endif /* DREF_H */
+63
View File
@@ -0,0 +1,63 @@
/*
* dump2tar - tool to dump files and command output into a tar archive
*
* Main dump logic
*
* Copyright IBM Corp. 2016, 2017
*
* s390-tools is free software; you can redistribute it and/or modify
* it under the terms of the MIT license. See LICENSE for details.
*/
#ifndef DUMP_H
#define DUMP_H
#include <stdbool.h>
#include <stddef.h>
#include <sys/stat.h>
#include "strarray.h"
#define NUM_EXCLUDE_TYPES 7
struct dump_spec {
char *inname;
char *outname;
bool is_cmd;
};
struct dump_opts {
bool add_cmd_status;
bool append;
bool dereference;
bool exclude_type[NUM_EXCLUDE_TYPES];
bool gzip;
bool ignore_failed_read;
bool no_eof;
bool quiet;
bool recursive;
bool threaded;
bool verbose;
const char *output_file;
int file_timeout;
int timeout;
long jobs;
long jobs_per_cpu;
size_t file_max_size;
size_t max_buffer_size;
size_t max_size;
size_t read_chunk_size;
struct strarray exclude;
struct dump_spec *specs;
unsigned int num_specs;
};
struct dump_opts *dump_opts_new(void);
int dump_opts_set_type_excluded(struct dump_opts *opts, char c);
void dump_opts_add_spec(struct dump_opts *opts, char *inname, char *outname,
bool is_cmd);
void dump_opts_free(struct dump_opts *opts);
int dump_to_tar(struct dump_opts *opts);
#endif /* DUMP_H */
+23
View File
@@ -0,0 +1,23 @@
/*
* dump2tar - tool to dump files and command output into a tar archive
*
* Global variables
*
* Copyright IBM Corp. 2016, 2017
*
* s390-tools is free software; you can redistribute it and/or modify
* it under the terms of the MIT license. See LICENSE for details.
*/
#ifndef GLOBAL_H
#define GLOBAL_H
#include <stdbool.h>
extern bool global_threaded;
extern bool global_debug;
extern bool global_verbose;
extern bool global_quiet;
extern bool global_timestamps;
#endif /* GLOBAL_H */
+26
View File
@@ -0,0 +1,26 @@
/*
* dump2tar - tool to dump files and command output into a tar archive
*
* Caches for user and group ID lookups
*
* Copyright IBM Corp. 2016, 2017
*
* s390-tools is free software; you can redistribute it and/or modify
* it under the terms of the MIT license. See LICENSE for details.
*/
#ifndef IDCACHE_H
#define IDCACHE_H
#include <stdlib.h>
#include <sys/types.h>
/* Buffer sizes for getpwuid_r and getgid_r calls (bytes) */
#define PWD_BUFFER_SIZE 4096
#define GRP_BUFFER_SIZE 4096
void uid_to_name(uid_t uid, char *name, size_t len);
void gid_to_name(gid_t gid, char *name, size_t len);
void idcache_cleanup(void);
#endif /* IDCACHE_H */
+101
View File
@@ -0,0 +1,101 @@
/*
* dump2tar - tool to dump files and command output into a tar archive
*
* Helper functions
*
* Copyright IBM Corp. 2016, 2017
*
* s390-tools is free software; you can redistribute it and/or modify
* it under the terms of the MIT license. See LICENSE for details.
*/
#ifndef MISC_H
#define MISC_H
#include <stdbool.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <time.h>
#include "lib/util_libc.h"
#include "global.h"
#define MSG_LEN 256
#define DBG(...) \
do { \
if (global_debug) \
debug(__FILE__, __LINE__, ##__VA_ARGS__); \
} while (0)
#define mwarn(fmt, ...) _mwarn(true, (fmt), ##__VA_ARGS__)
#define mwarnx(fmt, ...) _mwarn(false, (fmt), ##__VA_ARGS__)
/* Helper macro for constructing messages in variables */
#define HANDLE_RC(rc, max, off, label) \
do { \
if ((rc) > 0) \
(off) += (rc); \
if ((off) > (max)) \
goto label; \
} while (0)
/* Program exit codes */
#define EXIT_OK 0
#define EXIT_RUNTIME 1
#define EXIT_USAGE 2
/* Number of nanoseconds in a second */
#define NSEC_PER_SEC 1000000000L
#define NSEC_PER_MSEC 1000000L
#define NSEC_PER_USEC 1000L
extern struct timespec main_start_ts;
struct dref;
int misc_write_data(int fd, char *addr, size_t len);
ssize_t misc_read_data(int fd, char *addr, size_t len);
void inc_timespec(struct timespec *ts, time_t sec, long nsec);
void set_timespec(struct timespec *ts, time_t sec, long nsec);
bool ts_before(struct timespec *a, struct timespec *b);
int snprintf_duration(char *buff, size_t len, struct timespec *start,
struct timespec *end);
char *get_threadname(void);
void debug(const char *file, unsigned long line, const char *format, ...);
void _mwarn(bool print_errno, const char *format, ...);
void verb(const char *format, ...);
void info(const char *format, ...);
#define mmalloc(len) util_zalloc(len)
#define mcalloc(n, len) util_zalloc((n) * (len))
#define mrealloc(ptr, len) util_realloc((ptr), (len))
#define mstrdup(str) util_strdup(str)
#define masprintf(fmt, ...) __masprintf(__func__, __FILE__, __LINE__, \
(fmt), ##__VA_ARGS__)
char *__masprintf(const char *func, const char *file, int line,
const char *fmt, ...);
#define set_threadname(fmt, ...) __set_threadname(__func__, __FILE__, \
__LINE__, (fmt), \
##__VA_ARGS__)
void __set_threadname(const char *func, const char *file, int line,
const char *fmt, ...);
void clear_threadname(void);
void chomp(char *str, char *c);
void lchomp(char *str, char *c);
void remove_double_slashes(char *str);
int stat_file(bool dereference, const char *abs, const char *rel,
struct dref *dref, struct stat *st);
void set_dummy_stat(struct stat *st);
bool starts_with(const char *str, const char *prefix);
bool ends_with(const char *str, const char *suffix);
int cmd_child(int fd, char *cmd);
int cmd_open(char *cmd, pid_t *pid_ptr);
int cmd_close(int fd, pid_t pid, int *status_ptr);
void misc_init(void);
void misc_cleanup(void);
void set_stdout_data(void);
#endif /* MISC_H */
+26
View File
@@ -0,0 +1,26 @@
/*
* dump2tar - tool to dump files and command output into a tar archive
*
* Dynamically growing string arrays
*
* Copyright IBM Corp. 2016, 2017
*
* s390-tools is free software; you can redistribute it and/or modify
* it under the terms of the MIT license. See LICENSE for details.
*/
#ifndef STRARRAY_H
#define STRARRAY_H
/* A string array that can grow in size */
struct strarray {
unsigned int num;
char **str;
};
void free_strarray(struct strarray *array);
void add_str_to_strarray(struct strarray *array, const char *str);
void add_vstr_to_strarray(struct strarray *array, const char *fmt, ...);
int add_file_to_strarray(struct strarray *array, const char *filename);
#endif /* STRARRAY_H */
+44
View File
@@ -0,0 +1,44 @@
/*
* dump2tar - tool to dump files and command output into a tar archive
*
* TAR file generation
*
* Copyright IBM Corp. 2016, 2017
*
* s390-tools is free software; you can redistribute it and/or modify
* it under the terms of the MIT license. See LICENSE for details.
*/
#ifndef TAR_H
#define TAR_H
#include <stdbool.h>
#include <stdlib.h>
#include <sys/stat.h>
#define TYPE_REGULAR '0'
#define TYPE_LINK '2'
#define TYPE_DIR '5'
#define TAR_BLOCKSIZE 512
struct buffer;
/* emit_cb_t - Callback used for emitting chunks of a byte stream
* @data: Arbitrary pointer passed via the @data parameter of the
* tar_emit_file_* functions
* @addr: Pointer to data
* @len: Size of data
* Return %0 on success. Returning non-zero will indicate failure and abort
* further data emission. */
typedef int (*emit_cb_t)(void *data, void *addr, size_t len);
int tar_emit_file_from_buffer(char *filename, char *link, size_t len,
struct stat *stat, char type,
struct buffer *content, emit_cb_t emit_cb,
void *data);
int tar_emit_file_from_data(char *filename, char *link, size_t len,
struct stat *stat, char type, void *addr,
emit_cb_t emit_cb, void *data);
#endif /* TAR_H */