diff --git a/Makefile b/Makefile index 91c4d6a..ecfec82 100644 --- a/Makefile +++ b/Makefile @@ -30,11 +30,9 @@ TLM_SRCS = tlm/tlm_util.c \ tlm/tlm_info.c \ tlm/tlm_hardlink.c -#LDADD = -lmd -lpthread -lc -LDADD = -lmd -lpthread -lc -lzfs -lzfs_core -lnvpair -lumem -lbsm +LDADD = -lmd -lpthread -lc MAN= CFLAGS += -I. -I./include -CFLAGS+= -DEMC_MODEL PREFIX ?= /usr/local DSTDIR = ${PREFIX}/sbin diff --git a/include/ndmp.h b/include/ndmp.h index 2cfb237..53eb23a 100644 --- a/include/ndmp.h +++ b/include/ndmp.h @@ -1,5 +1,6 @@ /* * Copyright 2009 Sun Microsystems, Inc. + * Copyright 2017 Marcelo Araujo . * All rights reserved. * * Use is subject to license terms. @@ -1259,7 +1260,7 @@ typedef enum ndmp_connect_reason ndmp_connect_reason; struct ndmp_notify_connected_request { ndmp_connect_reason reason; u_short protocol_version; - const char *text_reason; + char *text_reason; }; typedef struct ndmp_notify_connected_request ndmp_notify_connected_request; diff --git a/include/ndmp.x b/include/ndmp.x index 3a69170..bbd744d 100644 --- a/include/ndmp.x +++ b/include/ndmp.x @@ -1,6 +1,7 @@ /* * Copyright 1996, 1997 PDC, Network Appliance. * Copyright 2009 Sun Microsystems, Inc. + * Copyright 2015 Marcelo Araujo . * All rights reserved. * * Use is subject to license terms. diff --git a/include/ndmpd.h b/include/ndmpd.h index e7c1a48..723aa4d 100644 --- a/include/ndmpd.h +++ b/include/ndmpd.h @@ -1,6 +1,6 @@ /* * Copyright 2009 Sun Microsystems, Inc. - * Copyright 2015 Marcelo Araujo . + * Copyright 2017 Marcelo Araujo . * All rights reserved. * * Use is subject to license terms. @@ -47,7 +47,6 @@ #include #include /* memset */ #include /* close */ -#include /* free() */ #include @@ -319,6 +318,5 @@ int ndmp_run(u_long port, ndmp_con_handler_func_t con_handler_func); void connection_handler(ndmp_connection_t *connection); bool_t file_exists(const char * filename); int startNDMPD(void); -static char * getline_ndmpd(FILE *fp, char *line, int llen); #endif /* _NDMPD_H_ */ diff --git a/include/ndmpd_fhistory.h b/include/ndmpd_fhistory.h index a511778..7b09257 100644 --- a/include/ndmpd_fhistory.h +++ b/include/ndmpd_fhistory.h @@ -1,5 +1,6 @@ /* * Copyright 2009 Sun Microsystems, Inc. + * Copyright 2017 Marcelo Araujo . * All rights reserved. * * Use is subject to license terms. @@ -60,6 +61,5 @@ int ndmpd_fhnode_v3_cb(lbr_fhlog_call_backs_t *cbp, char *dir, char *file, struct stat *stp, u_longlong_t off); int ndmpd_path_restored_v3(lbr_fhlog_call_backs_t *cbp, char *name, struct stat *st, u_longlong_t ll_idx); -char *get_bk_path_v3(ndmpd_module_params_t *params); #endif /* _NDMPD_FHISTORY_H */ diff --git a/include/ndmpd_prop.h b/include/ndmpd_prop.h index ecdbac7..6f6369b 100755 --- a/include/ndmpd_prop.h +++ b/include/ndmpd_prop.h @@ -1,5 +1,6 @@ /* * Copyright 2009 Sun Microsystems, Inc. + * Copyright 2017 Marcelo Araujo . * All rights reserved. * * Use is subject to license terms. @@ -123,8 +124,6 @@ int ndmpd_load_prop(const char *); char *ndmpd_get_prop(ndmpd_cfg_id_t id); char *ndmpd_get_prop_default(ndmpd_cfg_id_t id, char *dflt); int ndmpd_get_prop_yorn(ndmpd_cfg_id_t id); -void print_prop(void); -void setup(char *line); #ifdef __cplusplus } diff --git a/include/ndmpd_tar_v3.h b/include/ndmpd_tar_v3.h index 36afd5b..749d936 100644 --- a/include/ndmpd_tar_v3.h +++ b/include/ndmpd_tar_v3.h @@ -1,5 +1,6 @@ /* * Copyright 2009 Sun Microsystems, Inc. + * Copyright 2017 Marcelo Araujo . * All rights reserved. * * Use is subject to license terms. @@ -55,7 +56,6 @@ extern bool_t ndmp_ignore_ctime; extern bool_t ndmp_include_lmtime; -extern int multiple_dest_restore; /* Defined */ ndmp_error ndmp_restore_get_params_v3(ndmpd_session_t *session, @@ -67,7 +67,5 @@ int ndmp_send_recovery_stat_v3(ndmpd_module_params_t *params, void setWriteBufDone(tlm_buffers_t *bufs); void setReadBufDone(tlm_buffers_t *bufs); -char ** setupsels(ndmpd_session_t *session, ndmpd_module_params_t *params, - ndmp_lbr_params_t *nlp, int index); #endif /* _NDMPD_TAR_V3_ */ diff --git a/include/ndmpd_util.h b/include/ndmpd_util.h index 4b7961e..cc165ac 100755 --- a/include/ndmpd_util.h +++ b/include/ndmpd_util.h @@ -1,5 +1,6 @@ /* * Copyright 2009 Sun Microsystems, Inc. + * Copyright 2017 Marcelo Araujo . * All rights reserved. * * Use is subject to license terms. @@ -65,11 +66,6 @@ #define IN_ADDR(x) \ (*(struct in_addr *)&x) -/* - * Mutex to protect Nlp - */ -extern mutex_t nlp_mtx; - /* defined in ndmpd_func */ extern int ndmp_full_restore_path; extern int ndmp_ver; @@ -108,7 +104,7 @@ void ndmp_session_ref(ndmpd_session_t *session); void ndmp_session_unref(ndmpd_session_t *session); char *ndmp_new_job_name(char *jname); -int ndmp_get_cur_bk_time(ndmp_lbr_params_t *nlp, time_t *tp); +int ndmp_get_cur_bk_time(ndmp_lbr_params_t *nlp, time_t *tp, char *jname); long ndmp_buffer_get_size(ndmpd_session_t *session); void ndmpd_get_file_entry_type(int mode, ndmp_file_type *ftype); char *ndmp_get_relative_path(char *base, char *fullpath); @@ -120,7 +116,7 @@ void ndmp_lbr_cleanup(ndmpd_session_t *session); bool_t ndmp_valid_v3addr_type(ndmp_addr_type type); int ndmp_connect_sock_v3(u_long addr, u_short port); -const char **ndmpd_make_exc_list(void); +char **ndmpd_make_exc_list(void); bool_t fs_is_valid_logvol(char *path); char *ndmpd_mk_temp(char *buf); @@ -149,7 +145,7 @@ void ndmp_copy_addr_v4(ndmp_addr_v4 *dst, ndmp_addr_v4 *src); int ndmp_lbr_init(ndmpd_session_t *session); void ndmp_copy_addr_v3(ndmp_addr_v3 *dst, ndmp_addr_v3 *src); -const char *cctime(time_t *t); +char *cctime(time_t *t); char *ndmp_base64_encode(char *); char *ndmp_base64_decode(char *); diff --git a/include/tlm_util.h b/include/tlm_util.h index 911f1b7..38c580e 100644 --- a/include/tlm_util.h +++ b/include/tlm_util.h @@ -1,5 +1,6 @@ /* * Copyright 2009 Sun Microsystems, Inc. + * Copyright 2017 Marcelo Araujo . * All rights reserved. * * Use is subject to license terms. @@ -69,6 +70,7 @@ int cstack_pop(cstack_t *stk, void **data, int *len); int cstack_top(cstack_t *stk, void **data, int *len); bool_t match(char *patn, char *str); int match_ci(char *patn, char *str); +static bool_t parse_match(char line, char *seps); char *parse(char **line, char *seps); int oct_atoi(char *p); char *strupr(char *s); diff --git a/out/test_tool/ndmpc b/out/test_tool/ndmpc old mode 100644 new mode 100755 diff --git a/src/ndmp_xdr.c b/src/ndmp_xdr.c index 1093bfa..0c0b907 100644 --- a/src/ndmp_xdr.c +++ b/src/ndmp_xdr.c @@ -1729,7 +1729,7 @@ xdr_ndmp_notify_connected_request(XDR *xdrs, ndmp_notify_connected_request *objp return (FALSE); if (!xdr_u_short(xdrs, &objp->protocol_version)) return (FALSE); - if (!xdr_string(xdrs, (void *)&objp->text_reason, ~0)) + if (!xdr_string(xdrs, &objp->text_reason, ~0)) return (FALSE); return (TRUE); } diff --git a/src/ndmpd.c b/src/ndmpd.c index 4252aeb..0caeee2 100755 --- a/src/ndmpd.c +++ b/src/ndmpd.c @@ -1,5 +1,6 @@ /* * Copyright 2009 Sun Microsystems, Inc. + * Copyright 2017 Marcelo Araujo . * All rights reserved. * * Use is subject to license terms. @@ -40,8 +41,6 @@ */ #include -#include -#include /* getopt */ #include @@ -54,10 +53,14 @@ #include #include +#include +#include + /* for print log function */ #include extern void ndmpd_mover_cleanup(ndmpd_session_t *session); + extern ndmp_connection_t *ndmp_create_xdr_connection(void); extern void ndmp_destroy_xdr_connection(ndmp_connection_t *); extern void *ndmp_malloc(size_t size); @@ -81,12 +84,11 @@ ndmpd_log(int level, const char *fmt,...) { va_list arg; va_start(arg, fmt); - - if (PRINT_DEBUG_LOG) { + if (PRINT_DEBUG_LOG){ vfprintf(stderr, fmt, arg); fprintf(stderr, "\n"); - } else { - if (level != LOG_DEBUG) { + }else{ + if(level!=LOG_DEBUG){ vfprintf(stderr, fmt, arg); fprintf(stderr, "\n"); } @@ -164,11 +166,11 @@ ndmp_run(u_long port, ndmp_con_handler_func_t con_handler_func) sin.sin_family = AF_INET; listenIP = getIPfromNIC(ndmpd_get_prop(NDMP_LISTEN_NIC)); - printf("Management on IP: %s\n", listenIP); - if (strcmp(ndmpd_get_prop(NDMP_SERVE_NIC),"") == 0) - printf("Data Transfer on IP: %s\n",getIPfromNIC(ndmpd_get_prop(NDMP_LISTEN_NIC))); + printf("listen on IP: %s\n",listenIP); + if(strcmp(ndmpd_get_prop(NDMP_SERVE_NIC),"")==0) + printf(" Serve on IP: %s\n",getIPfromNIC(ndmpd_get_prop(NDMP_LISTEN_NIC))); else - printf("Data Transfer on IP: %s\n",getIPfromNIC(ndmpd_get_prop(NDMP_SERVE_NIC))); + printf(" Serve on IP: %s\n",getIPfromNIC(ndmpd_get_prop(NDMP_SERVE_NIC))); sin.sin_addr.s_addr = inet_addr(listenIP); sin.sin_port = htons(port); @@ -207,9 +209,9 @@ ndmp_run(u_long port, ndmp_con_handler_func_t con_handler_func) * * */ childPID = fork(); - if (childPID >= 0) // fork was successful + if(childPID >= 0) // fork was successful { - if (childPID == 0) { + if(childPID == 0) { close(server_socket); ndmpd_log(LOG_DEBUG, "connection fd: %d, got socket, start to process", ns); @@ -220,7 +222,7 @@ ndmp_run(u_long port, ndmp_con_handler_func_t con_handler_func) if ((argp = ndmp_malloc(sizeof (ndmpd_worker_arg_t))) != NULL) { argp->nw_sock = ns; argp->nw_ipaddr = ipaddr; - /* assign handler function */ + /* assign handler function */ argp->nw_con_handler_func = con_handler_func; ndmpd_worker(argp); } @@ -249,7 +251,7 @@ void connection_handler(ndmp_connection_t *connection) { ndmpd_log(LOG_DEBUG, " - connection_handler: handle the connection START - %d", - connection->conn_sock); + connection->conn_sock); static int conn_id = 1; ndmpd_session_t session; ndmp_notify_connected_request req; @@ -290,7 +292,7 @@ connection_handler(ndmp_connection_t *connection) req.reason = NDMP_CONNECTED; req.protocol_version = ndmp_ver; - req.text_reason = ""; + req.text_reason = (char *)""; /* Send request to tell the client that we're ready for connection */ if (ndmp_send_request_lock(connection, @@ -429,3 +431,5 @@ main(int argc, char *argv[]) return 0; } + + diff --git a/src/ndmpd_dtime.c b/src/ndmpd_dtime.c index 27bfd85..09cee42 100644 --- a/src/ndmpd_dtime.c +++ b/src/ndmpd_dtime.c @@ -1,5 +1,6 @@ /* * Copyright 2009 Sun Microsystems, Inc. + * Copyright 2017 Marcelo Araujo . * All rights reserved. * * Use is subject to license terms. @@ -274,7 +275,7 @@ ddates_pathname(char *buf) } /* - * getline_ndmpd + * getline * * Get a line from the file and handle the continued lines. */ diff --git a/src/ndmpd_info.c b/src/ndmpd_info.c index aebf157..ef41568 100755 --- a/src/ndmpd_info.c +++ b/src/ndmpd_info.c @@ -1,5 +1,6 @@ /* * Copyright 2009 Sun Microsystems, Inc. + * Copyright 2017 Marcelo Araujo . * All rights reserved. * * Use is subject to license terms. @@ -245,8 +246,6 @@ ndmpd_config_get_butype_info_v3(ndmp_connection_t *connection, void *body) NDMP_SETENV(envp, "FILESYSTEM", ""); NDMP_SETENV(envp, "UPDATE", ""); NDMP_SETENV(envp, "HIST", "n"); - NDMP_SETENV(envp, "QNAP_EFILE0", ""); - NDMP_SETENV(envp, "QNAP_EDIR0", ""); NDMP_SETENV(envp, "FILES", ""); NDMP_SETENV(envp, "SNAPSURE", "NO"); NDMP_SETENV(envp, "LEVEL", "0"); @@ -571,8 +570,6 @@ ndmpd_config_get_butype_info_v4(ndmp_connection_t *connection, void *body) NDMP_SETENV(envp, "FILESYSTEM", ""); NDMP_SETENV(envp, "UPDATE", ""); NDMP_SETENV(envp, "HIST", "n"); - NDMP_SETENV(envp, "QNAP_EFILE0", ""); - NDMP_SETENV(envp, "QNAP_EDIR0", ""); NDMP_SETENV(envp, "FILES", ""); NDMP_SETENV(envp, "SNAPSURE", "NO"); NDMP_SETENV(envp, "LEVEL", "0"); diff --git a/src/ndmpd_prop.c b/src/ndmpd_prop.c index 7c82392..5962a73 100755 --- a/src/ndmpd_prop.c +++ b/src/ndmpd_prop.c @@ -1,5 +1,6 @@ /* * Copyright 2009 Sun Microsystems, Inc. + * Copyright 2017 Marcelo Araujo . * All rights reserved. * * Use is subject to license terms. @@ -51,7 +52,7 @@ #include "ndmpd.h" typedef struct ndmpd_cfg_param { - const char *name; + char *name; char value[64+1]; } ndmpd_cfg_param_t; @@ -64,7 +65,6 @@ typedef struct ndmpd_cfg_param { * 4. serve-ip * * */ -static ndmpd_cfg_param_t ndmpd_cfg_table[] = { {"listen-nic", ""}, @@ -106,8 +106,7 @@ void print_prop(){ * config table. */ void setup(char *line){ - int ki,vi,iskey; - unsigned long idx; + int ki,vi,idx,iskey; char key[64]; char value[64+1]; ndmpd_cfg_id_t id; @@ -176,6 +175,7 @@ char * ndmpd_get_prop(ndmpd_cfg_id_t id) { char *env_val; + int i=0; if (id < NDMP_MAXALL) { env_val = ndmpd_cfg_table[id].value; diff --git a/src/ndmpd_tar_v3.c b/src/ndmpd_tar_v3.c index 87b71af..f0cc1b3 100755 --- a/src/ndmpd_tar_v3.c +++ b/src/ndmpd_tar_v3.c @@ -1,5 +1,6 @@ /* * Copyright 2009 Sun Microsystems, Inc. + * Copyright 2017 Marcelo Araujo . * All rights reserved. * * Use is subject to license terms. @@ -359,9 +360,9 @@ setupsels(ndmpd_session_t *session, ndmpd_module_params_t *params, */ for (i = 0; i < n; ++i) *(lpp+i) = " "; - - start = index - 1; - end = start + 1; + n = 1; + start = index-1; + end = start+1; lpp += start; /* Next selection entry will be in lpp[start] */ } else { start = 0; @@ -419,7 +420,7 @@ setupsels(ndmpd_session_t *session, ndmpd_module_params_t *params, * pointer to the bp: on success * NULL: otherwise */ -static char * +char * mkrsp(char *bp, char *pp, char *sp, char *np) { if (!bp || !pp) @@ -474,7 +475,7 @@ mkrsp(char *bp, char *pp, char *sp, char *np) * based on nm3_opath and nm3_dpath. path should have matched nm3_opath * in some way. */ -static char * +char * mknewname(const struct rs_name_maker *rnp, char *buf, int idx, char *path) { char *rv; @@ -817,9 +818,6 @@ get_hist_env_v3(ndmpd_module_params_t *params, ndmp_lbr_params_t *nlp) * into strings. The separator of the EXCLUDE environment * variable is the ',' character. * - * For QNAP version, we change this to match EMC behavior. - * Exclude will be sperate to exclude file and folder. - * * Parameters: * params (input) - pointer to the parameters structure * nlp (input) - pointer to the nlp structure @@ -831,68 +829,17 @@ static void get_exc_env_v3(ndmpd_module_params_t *params, ndmp_lbr_params_t *nlp) { char *envp; - char env_parameter[13]; // QNAP_EFILE99, QNAP_EDIR99 - char tmpenv[1024]; - - /* - * we support only 99 exclude file name patterns - * */ - int idx,max_count=100, exclude_count=0; - - - for(idx=1,exclude_count=0;idxnlp_exl=malloc(sizeof(char*)*exclude_count); - - for(idx=1,exclude_count=0;idxnlp_exl[exclude_count]=strdup(tmpenv); - exclude_count++; - } - -#ifdef EMC_MODEL - sprintf(env_parameter,"EMC_EDIR%02d",idx); -#else - sprintf(env_parameter,"QNAP_EDIR%02d",idx); -#endif - envp = MOD_GETENV(params, env_parameter); - if(envp){ - sprintf(tmpenv, "d_%s",envp); - nlp->nlp_exl[exclude_count]=strdup(tmpenv); - exclude_count++; - } + + envp = MOD_GETENV(params, "EXCLUDE"); + if (!envp) { + ndmpd_log(LOG_DEBUG, "env(EXCLUDE) not defined"); + nlp->nlp_exl = NULL; + } else { + ndmpd_log(LOG_DEBUG, "env(EXCLUDE): \"%s\"", envp); + nlp->nlp_exl = split_env(envp, ','); + prl(nlp->nlp_exl); } - nlp->nlp_exl[exclude_count]=NULL; - prl(nlp->nlp_exl); - } /* @@ -1747,6 +1694,8 @@ timebk_v3(void *arg, fst_node_t *pnp, fst_node_t *enp) if (rv != 0) return (rv); + stp = enp->tn_path ? enp->tn_st : pnp->tn_st; + if (shouldskip(bpp, pnp, enp, &rv)) return (rv); @@ -1886,7 +1835,7 @@ backup_reader_v3(backup_reader_arg_t *argp) ndmpd_log(LOG_DEBUG, " nlp->nlp_backup_path = %s", nlp->nlp_backup_path); - bp.bp_excls = (char **)ndmpd_make_exc_list(); + bp.bp_excls = ndmpd_make_exc_list(); ft.ft_path = bp.bp_chkpnm; ndmpd_log(LOG_DEBUG, "path %s", ft.ft_path); @@ -2238,12 +2187,14 @@ tar_backup_v3(ndmpd_session_t *session, ndmpd_module_params_t *params, pthread_t rdtp; char info[256]; + int result; + int err; if (ndmp_get_bk_dir_ino(nlp)) return (-1); - err = 0; + result = err = 0; // exit as if there was an internal error if (session->ns_eof) @@ -2290,6 +2241,9 @@ tar_backup_v3(ndmpd_session_t *session, ndmpd_module_params_t *params, return (-1); } + if ((err = ndmp_tar_writer_v3(session, params, cmds)) != 0) + result = EIO; + nlp->nlp_jstat->js_stop_time = time(NULL); (void) snprintf(info, sizeof (info), @@ -2306,9 +2260,10 @@ tar_backup_v3(ndmpd_session_t *session, ndmpd_module_params_t *params, (void) pthread_barrier_destroy(&arg.br_barrier); //exit as if there was an internal error - if (session->ns_eof) + if (session->ns_eof) { + result = EPIPE; err = -1; - + } if (!session->ns_data.dd_abort) { ndmpd_log(LOG_DEBUG, "Backing up \"%s\" Finished.", @@ -2719,9 +2674,10 @@ ndmpd_rs_sar_tar_v3(ndmpd_session_t *session, ndmpd_module_params_t *params, struct rs_name_maker rn; ndmp_tar_reader_arg_t arg; pthread_t rdtp; + int result; ndmpd_log(LOG_DEBUG, "++++++++ndmpd_rs_sar_tar_v3++++++++"); - err = 0; + result = err = 0; (void) ndmp_new_job_name(jname); if (restore_alloc_structs_v3(session, jname) < 0) return (-1); @@ -2805,6 +2761,8 @@ ndmpd_rs_sar_tar_v3(ndmpd_session_t *session, ndmpd_module_params_t *params, if (session->ns_eof) err = -1; + if (err == -1) + result = EIO; } (void) send_unrecovered_list_v3(params, nlp); /* nothing restored. */ @@ -2812,6 +2770,8 @@ ndmpd_rs_sar_tar_v3(ndmpd_session_t *session, ndmpd_module_params_t *params, if (session->ns_data.dd_abort) { ndmpd_log(LOG_DEBUG, "Restoring to \"%s\" aborted.", (nlp->nlp_restore_path) ? nlp->nlp_restore_path : "NULL"); + result = EINTR; + err = -1; } else { @@ -2965,7 +2925,7 @@ ndmpd_tar_backup_starter_v3(ndmpd_module_params_t *params) get_backup_size(session, nlp->nlp_backup_path); if (err == 0) { - err = ndmp_get_cur_bk_time(nlp, &nlp->nlp_cdate); + err = ndmp_get_cur_bk_time(nlp, &nlp->nlp_cdate, jname); if (err != 0) { ndmpd_log(LOG_DEBUG, "err %d", err); } else { diff --git a/src/ndmpd_util.c b/src/ndmpd_util.c index d98bd54..e01ba67 100755 --- a/src/ndmpd_util.c +++ b/src/ndmpd_util.c @@ -1,5 +1,6 @@ /* * Copyright 2009 Sun Microsystems, Inc. + * Copyright 2017 Marcelo Araujo . * All rights reserved. * * Use is subject to license terms. @@ -65,9 +66,9 @@ #include -/* - * Mutex to protect Nlp - */ +/* + * Mutex to protect Nlp + */ mutex_t nlp_mtx; @@ -117,9 +118,9 @@ int ndmp_force_bk_dirs = 1; /* * List of things to be exluded from backup. */ -static const char *exls[] = { - EXCL_PROC, - EXCL_TMP, +static char *exls[] = { + (char *)EXCL_PROC, + (char *)EXCL_TMP, NULL, /* reserved for a copy of the "backup.directory" */ NULL }; @@ -1556,7 +1557,6 @@ char * getIPfromNIC(char *nicname) { // IPv4 char *ip; - struct sockaddr_in *ipaddr; int fd=0; struct ifreq ifr; @@ -1570,9 +1570,8 @@ getIPfromNIC(char *nicname) { ioctl(fd, SIOCGIFADDR, &ifr); close(fd); - //ip = inet_ntoa(((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr); - ipaddr = (struct sockaddr_in *)(void *)&ifr.ifr_addr; - ip = inet_ntoa(ipaddr->sin_addr); + //sprintf(ip, "%s", inet_ntoa(((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr)); + ip = inet_ntoa(((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr); return ip; } @@ -1658,7 +1657,7 @@ ndmp_create_socket(u_long *addr, u_short *port) * "the epoch": if time is 0. * string format of the time. */ -const char * +char * cctime(time_t *t) { char *bp, *cp; @@ -1823,14 +1822,13 @@ ndmpd_make_bk_dir_path(char *buf, char *fname) * Returns: * list - array of character strings */ -const char ** +char ** ndmpd_make_exc_list(void) { - char *val; - const char **cpp; + char *val, **cpp; int i, n; - n = sizeof(exls); + n = sizeof (exls); if ((cpp = ndmp_malloc(n)) != NULL) { for (i = 0; exls[i] != NULL; i++) cpp[i] = exls[i]; @@ -1927,7 +1925,7 @@ ndmp_check_utf8magic(tlm_cmd_t *cmd) * Get the backup checkpoint time. */ int -ndmp_get_cur_bk_time(ndmp_lbr_params_t *nlp, time_t *tp) +ndmp_get_cur_bk_time(ndmp_lbr_params_t *nlp, time_t *tp, char *jname) { int err=0; @@ -2040,7 +2038,7 @@ void randomize(unsigned char *buffer, int size) { /* LINTED improper alignment */ - unsigned int *p = (unsigned int *)(void *)buffer; + unsigned int *p = (unsigned int *)buffer; unsigned int dwlen = size / sizeof (unsigned int); unsigned int remlen = size % sizeof (unsigned int); unsigned int tmp; diff --git a/tlm/tlm_backup_reader.c b/tlm/tlm_backup_reader.c index 32633e0..ac8d5a3 100644 --- a/tlm/tlm_backup_reader.c +++ b/tlm/tlm_backup_reader.c @@ -1,5 +1,6 @@ /* * Copyright 2009 Sun Microsystems, Inc. + * Copyright 2017 Marcelo Araujo . * All rights reserved. * * Use is subject to license terms. @@ -174,13 +175,8 @@ output_acl_header(sec_attr_t *acl_info, tar_hdr->th_linkflag = LF_ACL; acl_info->attr_type = UFSD_ACL; - //(void) snprintf(acl_info->attr_len, sizeof (acl_info->attr_len), "%06zo", acl_info->attr_info); -//#ifdef QNAP_TS -// acl_size = sizeof (*acl_info)+acl_info->attr_len+acl_info->xattr_len; -//#else acl_size = sizeof (*acl_info)+acl_info->attr_len; -//#endif (void) strlcpy(tar_hdr->th_name, "UFSACL", TLM_NAME_SIZE); (void) snprintf(tar_hdr->th_size, sizeof (tar_hdr->th_size), "%011lo ", acl_size); @@ -199,11 +195,6 @@ output_acl_header(sec_attr_t *acl_info, memcpy(tmpbuf,acl_info,sizeof (*acl_info)); memcpy(tmpbuf+sizeof (*acl_info),acl_info->attr_info,acl_info->attr_len); -//#ifdef QNAP_TS -// memcpy(tmpbuf+sizeof (*acl_info)+acl_info->attr_len, -// acl_info->attr_info+acl_info->attr_len, -// acl_info->xattr_len); -//#endif (void) output_mem(local_commands, (void *)tmpbuf, acl_size); diff --git a/tlm/tlm_lib.c b/tlm/tlm_lib.c index 08c997b..864be41 100644 --- a/tlm/tlm_lib.c +++ b/tlm/tlm_lib.c @@ -1,5 +1,6 @@ /* * Copyright 2009 Sun Microsystems, Inc. + * Copyright 2017 Marcelo Araujo . * All rights reserved. * * Use is subject to license terms. @@ -184,6 +185,9 @@ tlm_get_write_buffer(long want, long *actual_size, * tell the writer that a buffer is available */ tlm_buffer_release_in_buf(buffers); + + buffer = tlm_buffer_advance_in_idx(buffers); + } buffer = tlm_buffer_in_buf(buffers, NULL); diff --git a/tlm/tlm_restore_writer.c b/tlm/tlm_restore_writer.c index 2237d21..c311a65 100755 --- a/tlm/tlm_restore_writer.c +++ b/tlm/tlm_restore_writer.c @@ -1,5 +1,6 @@ /* * Copyright 2009 Sun Microsystems, Inc. + * Copyright 2017 Marcelo Araujo . * All rights reserved. * * Use is subject to license terms. @@ -258,6 +259,8 @@ tar_getdir(tlm_commands_t *commands, /* ...need to preserve across volume changes */ tlm_acls_t *acls; /* file access info */ + bool_t is_long_name = FALSE; + char longname[TLM_MAX_PATH_NAME]; char longlink[TLM_MAX_PATH_NAME]; char hugename[TLM_MAX_PATH_NAME]; @@ -279,6 +282,7 @@ tar_getdir(tlm_commands_t *commands, * restore and its position in the * selections list */ + int nzerohdr; /* the number of empty tar headers */ bool_t break_flg; /* exit the while loop */ int rv; long nm_end, lnk_end; @@ -329,6 +333,7 @@ tar_getdir(tlm_commands_t *commands, * work */ rv = 0; + nzerohdr = 0; break_flg = FALSE; @@ -428,6 +433,7 @@ tar_getdir(tlm_commands_t *commands, if(chk_rv!=1){ continue; } + nzerohdr = 0; /* * When files are spanned to the next tape, the * information of the acls must not be over-written @@ -546,6 +552,7 @@ tar_getdir(tlm_commands_t *commands, } name[0] = 0; + is_long_name = FALSE; } nm_end = 0; @@ -675,6 +682,7 @@ tar_getdir(tlm_commands_t *commands, if (hardlink_tmp_file) { nmp = NULL; want_this_file = FALSE; + hardlink_tmp_file = 0; } /* @@ -738,6 +746,7 @@ tar_getdir(tlm_commands_t *commands, longlink[0] = 0; hugename[0] = 0; name[0] = 0; + is_long_name = FALSE; } break; case LF_XATTR: @@ -849,10 +858,12 @@ tar_getdir(tlm_commands_t *commands, if (size_left != 0) ndmpd_log(LOG_DEBUG, "fsize %ld sleft %ld nmend %ld", file_size, size_left, nm_end); + is_long_name = TRUE; break; case LF_ACL: size_left = load_acl_info(lib, drv, file_size, acls, &acl_spot, local_commands); + break; case LF_VOLHDR: break; @@ -1408,9 +1419,13 @@ is_file_wanted(char *name, * Returns the number of bytes actually read. On error returns -1. */ static int -input_mem(int l, int d, tlm_cmd_t *lcmds, char *mem, int len) +input_mem(int l, + int d, + tlm_cmd_t *lcmds, + char *mem, + int len) { - int err = 0; + int err; int toread, actual_size, rec_size; char *rec; @@ -1683,13 +1698,6 @@ load_acl_info(int lib, acl_len = acls->acl_info.attr_len; ndmpd_log(LOG_DEBUG, "ACL : acl_len=%d",acl_len); -//#ifdef QNAP_TS -// // handle the ACL in xattr. -// xattr_len = acls->acl_info.xattr_len; -// ndmpd_log(LOG_DEBUG, "ACL : xattr_len=%d",xattr_len); -// -//#endif - acl_all_len = acl_len+xattr_len; // we can not use dynamic allocate here, it will overwrite some address that we still need. @@ -1805,11 +1813,7 @@ set_acl(char *name, tlm_acls_t *acls) acl = acl_from_text(acl_txt); if (acl!=NULL) { -#ifdef QNAP_TS - erc = acl_set_file(name, ACL_TYPE_ACCESS, acl); -#else erc = acl_set_file(name, ACL_TYPE_NFS4, acl); -#endif if (erc < 0) { ndmpd_log(LOG_DEBUG, "RESTORE> acl_set errno %d!!!", errno); // if the volume does not support ACL, this will fail. @@ -1822,14 +1826,6 @@ set_acl(char *name, tlm_acls_t *acls) fprintf(stderr, "RESTORE> acl_from_text error on file:%s",name); } -//#ifdef QNAP_TS -// char *aclname="security.NTACL"; -// if(acls->acl_info.xattr_len>0){ -// char *acl_xattr=acls->acl_info.attr_info+acls->acl_info.attr_len; -// setxattr(name, aclname, acl_xattr, acls->acl_info.xattr_len, 0); -// } -//#endif - free(acls->acl_info.attr_info); (void) memset(acls, 0, sizeof (tlm_acls_t));