This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
tsmpipe/lib/dsmlist.c

221 lines
5.6 KiB
C
Raw Permalink Normal View History

2013-07-18 13:59:14 +00:00
/*
* This function will list the contents that we have stored with tsmpipe
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "dsmrc.h"
#include "dsmapitd.h"
#include "../tsmpipe.h"
dsBool_t headerPrinted=bFalse; // Have we rendered the heading row yet
2015-09-23 05:07:22 +00:00
char *units(double size) {
extern int verbose;
static const char *SIZES[] = { "B", "KiB", "MiB", "GiB" };
int div = 0;
double rem = 0;
int base = 1024;
int s_size = 128;
2015-09-23 05:07:22 +00:00
char *s;
s = "\0";
s = malloc(s_size);
2015-09-23 05:07:22 +00:00
if (s==NULL) {
perror("Arg, out of memory?");
exit(255);
}
memset(s,0x00,s_size);
2015-09-23 05:07:22 +00:00
while (size >= base && div < (int)(sizeof SIZES / sizeof *SIZES)-1) {
if (verbose > 2)
2016-06-23 02:33:51 +00:00
fprintf(stderr,"%s: BEFORE - SIZE: [%3.2f], DIV: [%d], REM: [%3.2f]\n",__func__,size,div,rem);
2015-09-23 05:07:22 +00:00
rem = ((int)size % base);
size /= base;
div++;
}
if (verbose > 2)
2016-06-23 02:33:51 +00:00
fprintf(stderr,"%s: AFTER - SIZE: [%3.2f], DIV: [%d], REM: [%3.2f]\n",__func__,size,div,rem);
2015-09-23 05:07:22 +00:00
sprintf(s,"%3.2f %s",size,SIZES[div]);
return s;
}
2013-07-18 13:59:14 +00:00
/*
* Our Callback to show what is in TSM
*/
2015-09-23 05:07:22 +00:00
int tsm_listfile_cb(dsmQueryType qType, DataBlk *qResp, void *userdata, dsBool_t friendly) {
2016-06-23 02:33:51 +00:00
extern int verbose;
2013-07-19 04:19:03 +00:00
char stor[2];
char state[3];
char ced[4];
char objInfo[DSM_MAX_OBJINFO_LENGTH];
2015-09-23 05:07:22 +00:00
char *s;
s = malloc(1024);
2013-07-18 13:59:14 +00:00
if (userdata != NULL ) {
debugLog(0,__func__,"ERROR: Internal error: userdata != NULL",0);
2013-07-18 13:59:14 +00:00
return -1;
}
if (qType == qtArchive) {
if (! headerPrinted++) {
2015-09-23 05:07:22 +00:00
printf("%-40s %2s %s %3s %-19s %-19s %12s %-10s %-10s",
2013-11-04 13:13:12 +00:00
"NAME",
"ST",
"L",
"CED",
2015-09-23 05:07:22 +00:00
"ARCHIVE",
2013-11-04 13:13:12 +00:00
"EXPIRE",
"SIZE",
2013-11-04 13:13:12 +00:00
"ID",
"DESC"
);
#ifdef USE_DIGEST
printf(" %s","OBJINFO");
#endif
printf("\n");
}
qryRespArchiveData respArchive;
2013-07-18 13:59:14 +00:00
memset(&respArchive,0x00,sizeof(qryRespArchiveData));
qryRespArchiveData *qr = (void *) qResp->bufferPtr;
respArchive = *qr;
2013-11-04 13:13:12 +00:00
// The Object Status
switch (respArchive.objName.objType) {
case (DSM_OBJ_FILE) : strcpy(state,"F"); break;
case (DSM_OBJ_DIRECTORY) : strcpy(state,"D"); break;
default: strcpy(state,"?");
2013-11-04 13:13:12 +00:00
}
// Location
switch (respArchive.mediaClass) {
case (MEDIA_FIXED) : strcpy(stor,"D"); break;
case (MEDIA_LIBRARY) : strcpy(stor,"T"); break;
default: strcpy(stor,"?");
2013-11-04 13:13:12 +00:00
}
// Compression, Encryption, De-Duplication
strcpy(ced,(respArchive.compressType == DSM_OBJ_COMPRESSED_YES ? "C" :
(respArchive.compressType == DSM_OBJ_COMPRESSED_NO ? "-" : "?")));
strcat(ced,(respArchive.encryptionType & DSM_ENCRYPT_CLIENTENCRKEY ? "C" :
(respArchive.encryptionType & DSM_ENCRYPT_USER ? "U" : "-")));
strcat(ced,respArchive.clientDeduplicated ? "D" : "-");
2015-09-23 05:07:22 +00:00
if (friendly) {
s = units((double)dsmSizeToNum(respArchive.sizeEstimate,bFalse));
} else {
sprintf(s,"%7.3f MB",dsmSizeToNum(respArchive.sizeEstimate,bTrue));
}
2013-11-04 13:13:12 +00:00
// The Object Status
2015-09-23 05:07:22 +00:00
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);
2013-07-18 13:59:14 +00:00
} else if (qType == qtBackup) {
if (! headerPrinted++) {
2015-09-23 05:07:22 +00:00
printf("%-40s %2s %s %3s %-19s %-19s %12s %-10s",
2013-11-04 13:13:12 +00:00
"NAME",
"ST",
"L",
"CED",
"BACKUP",
"EXPIRE",
"SIZE",
2013-11-04 13:13:12 +00:00
"ID"
);
#ifdef USE_DIGEST
printf(" %s","OBJINFO");
#endif
printf("\n");
}
qryRespBackupData respBackup;
2013-07-18 13:59:14 +00:00
memset(&respBackup,0x00,sizeof(qryRespBackupData));
qryRespBackupData *qr = (void *) qResp->bufferPtr;
respBackup = *qr;
// The Object Status
switch (respBackup.objName.objType) {
case (DSM_OBJ_FILE) : strcpy(state,"F"); break;
case (DSM_OBJ_DIRECTORY) : strcpy(state,"D"); break;
default: strcpy(state,"?");
2013-07-18 13:59:14 +00:00
}
switch (respBackup.objState) {
case (DSM_ACTIVE) : strcat(state,"A"); break;
case (DSM_INACTIVE) : strcat(state,"I"); break;
default: strcat(state,"?");
2013-07-18 13:59:14 +00:00
}
// Location
switch (respBackup.mediaClass) {
case (MEDIA_FIXED) : strcpy(stor,"D"); break;
case (MEDIA_LIBRARY) : strcpy(stor,"T"); break;
default: strcpy(stor,"?");
2013-07-18 13:59:14 +00:00
}
// Compression, Encryption, De-Duplication
strcpy(ced,(respBackup.compressType == DSM_OBJ_COMPRESSED_YES ? "C" :
(respBackup.compressType == DSM_OBJ_COMPRESSED_NO ? "-" : "?")));
strcat(ced,(respBackup.encryptionType & DSM_ENCRYPT_CLIENTENCRKEY ? "C" :
(respBackup.encryptionType & DSM_ENCRYPT_USER ? "U" : "-")));
strcat(ced,respBackup.clientDeduplicated ? "D" : "-");
2016-06-23 02:33:51 +00:00
if (verbose > 2)
fprintf(stderr,"%s: clientDeduplicated: %d\n",__func__,respBackup.clientDeduplicated);
2013-07-18 13:59:14 +00:00
#ifdef USE_DIGEST
// Object Info
memset(&objInfo,0x00,sizeof(objInfo));
if (respBackup.objInfolen)
strncat(objInfo,respBackup.objInfo,respBackup.objInfolen);
#endif
2013-11-04 13:13:12 +00:00
2015-09-23 05:07:22 +00:00
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);
2013-07-18 13:59:14 +00:00
} else {
fprintf(stderr,"%s: UNKNOWN Type %d\n",__func__,qType);
2013-07-18 13:59:14 +00:00
return -1;
}
#ifdef USE_DIGEST
printf("|%s",objInfo);
#endif
printf("\n");
2013-07-18 13:59:14 +00:00
return 1;
}
/*
* List objects that are in TSM
*/
2015-09-23 05:07:22 +00:00
int tsm_listfile(dsUint32_t sesshandle, dsmQueryType qType, qryArchiveData qaData, qryBackupData qbData, dsBool_t friendly) {
2013-07-18 13:59:14 +00:00
dsInt16_t rc=0;
2015-09-23 05:07:22 +00:00
rc = tsm_queryfile(sesshandle,qType,tsm_listfile_cb,NULL,qaData,qbData,friendly);
2013-07-18 13:59:14 +00:00
if (rc != DSM_RC_OK && rc != DSM_RC_ABORT_NO_MATCH)
return 0;
return 1;
}