Enabled friendly output -F
This commit is contained in:
@@ -12,14 +12,50 @@
|
||||
|
||||
dsBool_t headerPrinted=bFalse; // Have we rendered the heading row yet
|
||||
|
||||
char *units(double size) {
|
||||
extern int verbose;
|
||||
static const char *SIZES[] = { "B", "KiB", "MiB", "GiB" };
|
||||
int div = 0;
|
||||
double rem = 0;
|
||||
int base = 1024;
|
||||
|
||||
char *s;
|
||||
|
||||
s = "\0";
|
||||
s = malloc(128);
|
||||
if (s==NULL) {
|
||||
perror("Arg, out of memory?");
|
||||
exit(255);
|
||||
}
|
||||
memset(s,0x00,(sizeof s));
|
||||
|
||||
while (size >= base && div < (int)(sizeof SIZES / sizeof *SIZES)-1) {
|
||||
if (verbose > 2)
|
||||
fprintf(stderr,"BEFORE: %s: SIZE: [%3.2f], DIV: [%d], REM: [%3.2f]\n",__func__,size,div,rem);
|
||||
|
||||
rem = ((int)size % base);
|
||||
size /= base;
|
||||
div++;
|
||||
}
|
||||
|
||||
if (verbose > 2)
|
||||
fprintf(stderr,"AFTER: %s: SIZE: [%3.2f], DIV: [%d], REM: [%3.2f]\n",__func__,size,div,rem);
|
||||
|
||||
sprintf(s,"%3.2f %s",size,SIZES[div]);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
/*
|
||||
* Our Callback to show what is in TSM
|
||||
*/
|
||||
int tsm_listfile_cb(dsmQueryType qType, DataBlk *qResp, void *userdata) {
|
||||
int tsm_listfile_cb(dsmQueryType qType, DataBlk *qResp, void *userdata, dsBool_t friendly) {
|
||||
char stor[2];
|
||||
char state[3];
|
||||
char ced[4];
|
||||
char objInfo[DSM_MAX_OBJINFO_LENGTH];
|
||||
char *s;
|
||||
s = malloc(1024);
|
||||
|
||||
if (userdata != NULL ) {
|
||||
debugLog(0,__func__,"ERROR: Internal error: userdata != NULL",0);
|
||||
@@ -28,12 +64,12 @@ int tsm_listfile_cb(dsmQueryType qType, DataBlk *qResp, void *userdata) {
|
||||
|
||||
if (qType == qtArchive) {
|
||||
if (! headerPrinted++) {
|
||||
printf("%40s %2s %s %3s %19s %19s %10s %10s %10s",
|
||||
printf("%-40s %2s %s %3s %-19s %-19s %12s %-10s %-10s",
|
||||
"NAME",
|
||||
"ST",
|
||||
"L",
|
||||
"CED",
|
||||
"BACKUP",
|
||||
"ARCHIVE",
|
||||
"EXPIRE",
|
||||
"SIZE",
|
||||
"ID",
|
||||
@@ -74,12 +110,18 @@ int tsm_listfile_cb(dsmQueryType qType, DataBlk *qResp, void *userdata) {
|
||||
|
||||
strcat(ced,respArchive.clientDeduplicated ? "D" : "-");
|
||||
|
||||
if (friendly) {
|
||||
s = units((double)dsmSizeToNum(respArchive.sizeEstimate,bFalse));
|
||||
} else {
|
||||
sprintf(s,"%7.3f MB",dsmSizeToNum(respArchive.sizeEstimate,bTrue));
|
||||
}
|
||||
|
||||
// The Object Status
|
||||
printf("%40s|%2s|%s|%3s|%19s|%19s|%7.3f MB|%u-%u|%s",dsmObjnameToStr(respArchive.objName),state,stor,ced,dsmDateToStr(respArchive.insDate),respArchive.expDate.year ? dsmDateToStr(respArchive.expDate) : "",dsmSizeToNum(respArchive.sizeEstimate,bTrue),respArchive.objId.hi,respArchive.objId.lo,respArchive.descr);
|
||||
printf("%-40s|%2s|%s|%3s|%-19s|%-19s|%12s|%u-%8u|%10s",dsmObjnameToStr(respArchive.objName),state,stor,ced,dsmDateToStr(respArchive.insDate),respArchive.expDate.year ? dsmDateToStr(respArchive.expDate) : "",s,respArchive.objId.hi,respArchive.objId.lo,respArchive.descr);
|
||||
|
||||
} else if (qType == qtBackup) {
|
||||
if (! headerPrinted++) {
|
||||
printf("%40s %2s %s %3s %19s %19s %10s %10s",
|
||||
printf("%-40s %2s %s %3s %-19s %-19s %12s %-10s",
|
||||
"NAME",
|
||||
"ST",
|
||||
"L",
|
||||
@@ -139,7 +181,13 @@ int tsm_listfile_cb(dsmQueryType qType, DataBlk *qResp, void *userdata) {
|
||||
strncat(objInfo,respBackup.objInfo,respBackup.objInfolen);
|
||||
#endif
|
||||
|
||||
printf("%40s|%2s|%s|%3s|%19s|%19s|%7.3f MB|%u-%8u",dsmObjnameToStr(respBackup.objName),state,stor,ced,dsmDateToStr(respBackup.insDate),respBackup.expDate.year ? dsmDateToStr(respBackup.expDate) : "",dsmSizeToNum(respBackup.sizeEstimate,bTrue),respBackup.objId.hi,respBackup.objId.lo);
|
||||
if (friendly) {
|
||||
s = units((double)dsmSizeToNum(respBackup.sizeEstimate,bFalse));
|
||||
} else {
|
||||
sprintf(s,"%7.3f MB",dsmSizeToNum(respBackup.sizeEstimate,bTrue));
|
||||
}
|
||||
|
||||
printf("%-40s|%2s|%s|%3s|%19s|%19s|%12s|%u-%8u",dsmObjnameToStr(respBackup.objName),state,stor,ced,dsmDateToStr(respBackup.insDate),respBackup.expDate.year ? dsmDateToStr(respBackup.expDate) : "",s,respBackup.objId.hi,respBackup.objId.lo);
|
||||
} else {
|
||||
fprintf(stderr,"%s: UNKNOWN Type %d\n",__func__,qType);
|
||||
return -1;
|
||||
@@ -156,10 +204,10 @@ int tsm_listfile_cb(dsmQueryType qType, DataBlk *qResp, void *userdata) {
|
||||
/*
|
||||
* List objects that are in TSM
|
||||
*/
|
||||
int tsm_listfile(dsUint32_t sesshandle, dsmQueryType qType, qryArchiveData qaData, qryBackupData qbData) {
|
||||
int tsm_listfile(dsUint32_t sesshandle, dsmQueryType qType, qryArchiveData qaData, qryBackupData qbData, dsBool_t friendly) {
|
||||
dsInt16_t rc=0;
|
||||
|
||||
rc = tsm_queryfile(sesshandle,qType,tsm_listfile_cb,NULL,qaData,qbData);
|
||||
rc = tsm_queryfile(sesshandle,qType,tsm_listfile_cb,NULL,qaData,qbData,friendly);
|
||||
|
||||
if (rc != DSM_RC_OK && rc != DSM_RC_ABORT_NO_MATCH)
|
||||
return 0;
|
||||
|
@@ -16,9 +16,12 @@
|
||||
|
||||
#include "../tsmpipe.h"
|
||||
|
||||
int tsm_matchone_cb(dsmQueryType qType, DataBlk *qResp, void *userdata) {
|
||||
int tsm_matchone_cb(dsmQueryType qType, DataBlk *qResp, void *userdata, dsmBool_t friendly) {
|
||||
struct matchone_cb_data *cbdata = userdata;
|
||||
|
||||
if (friendly)
|
||||
debugLog(0,__func__,"ERROR: Friendly is set?",1);
|
||||
|
||||
cbdata->numfound++;
|
||||
|
||||
if (qType == qtArchive) {
|
||||
@@ -339,6 +342,7 @@ int tsm_restorefile(dsUint32_t dsmHandle, dsmQueryType qType, qryArchiveData qaD
|
||||
dsmGetList getList;
|
||||
DataBlk dataBlk;
|
||||
dsmGetType gType;
|
||||
dsmBool_t friendly=bFalse;
|
||||
|
||||
memset(&cbdata,0x00,sizeof(cbdata));
|
||||
cbdata.numfound = 0;
|
||||
@@ -348,14 +352,14 @@ int tsm_restorefile(dsUint32_t dsmHandle, dsmQueryType qType, qryArchiveData qaD
|
||||
fprintf(stderr,"%s: Starting to receive %s via stdin\n",__func__,dsmObjnameToStr(*qaData.objName));
|
||||
|
||||
gType = gtArchive;
|
||||
rc = tsm_queryfile(dsmHandle,qType,tsm_matchone_cb,&cbdata,qaData,qbData);
|
||||
rc = tsm_queryfile(dsmHandle,qType,tsm_matchone_cb,&cbdata,qaData,qbData,friendly);
|
||||
|
||||
} else if (qType == qtBackup) {
|
||||
if (verbose)
|
||||
fprintf(stderr,"%s: Starting to receive %s via stdin\n",__func__,dsmObjnameToStr(*qbData.objName));
|
||||
|
||||
gType = gtBackup;
|
||||
rc = tsm_queryfile(dsmHandle,qType,tsm_matchone_cb,&cbdata,qaData,qbData);
|
||||
rc = tsm_queryfile(dsmHandle,qType,tsm_matchone_cb,&cbdata,qaData,qbData,friendly);
|
||||
|
||||
} else {
|
||||
fprintf(stderr,"%s: UNKNOWN Type %d\n",__func__,qType);
|
||||
@@ -438,10 +442,11 @@ int tsm_deletefile(dsUint32_t dsmHandle, dsmQueryType qType, qryArchiveData qaDa
|
||||
dsmDelInfo *dInfoP;
|
||||
dsmDelType dType;
|
||||
struct matchone_cb_data cbdata;
|
||||
dsmBool_t friendly=bFalse;
|
||||
|
||||
cbdata.numfound = 0;
|
||||
|
||||
rc = tsm_queryfile(dsmHandle,qType,tsm_matchone_cb,&cbdata,qaData,qbData);
|
||||
rc = tsm_queryfile(dsmHandle,qType,tsm_matchone_cb,&cbdata,qaData,qbData,friendly);
|
||||
if (rc != DSM_RC_OK) {
|
||||
return 0;
|
||||
}
|
||||
|
@@ -197,7 +197,7 @@ int tsm_sessioninfo(dsUint32_t dsmHandle) {
|
||||
case DSM_COMM_TCP : strcpy(t,"TCP/IP"); break;
|
||||
case DSM_COMM_NAMEDPIPE : strcpy(t,"NAMED PIPE"); break;
|
||||
case DSM_COMM_SHM : strcpy(t,"SHARED MEMORY"); break;
|
||||
case 6 : strcpy(t,"TCP/IP v6"); break; // There is no DSM_COMM_ const for TCPIPv6
|
||||
case DSM_COMM_TCPIP6 : strcpy(t,"TCP/IP v6"); break;
|
||||
default: strcpy(t,"UNKNOWN");
|
||||
}
|
||||
|
||||
@@ -293,7 +293,7 @@ int tsm_sessioninfo(dsUint32_t dsmHandle) {
|
||||
* 0 if tsm_queryfile() should skip processing the remaining matches.
|
||||
* 1 otherwise.
|
||||
*/
|
||||
dsInt16_t tsm_queryfile(dsUint32_t dsmHandle, dsmQueryType qType, tsm_query_callback usercb, void *userdata, qryArchiveData qaData, qryBackupData qbData) {
|
||||
dsInt16_t tsm_queryfile(dsUint32_t dsmHandle, dsmQueryType qType, tsm_query_callback usercb, void *userdata, qryArchiveData qaData, qryBackupData qbData, dsBool_t friendly) {
|
||||
extern int verbose;
|
||||
dsInt16_t rc=0;
|
||||
dsmQueryBuff *qDataP;
|
||||
@@ -371,7 +371,7 @@ dsInt16_t tsm_queryfile(dsUint32_t dsmHandle, dsmQueryType qType, tsm_query_call
|
||||
if (usercb == NULL)
|
||||
continue;
|
||||
|
||||
cbret = usercb(qType,&qResp,userdata);
|
||||
cbret = usercb(qType,&qResp,userdata,friendly);
|
||||
if (cbret < 0) {
|
||||
return DSM_RC_UNKNOWN_ERROR;
|
||||
|
||||
|
Reference in New Issue
Block a user