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

154 lines
4.6 KiB
C
Raw 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
extern char *dsmDateToStr(dsmDate date);
extern char *dsmObjnameToStr(dsmObjName objName);
extern double dsmSizeToNum(dsStruct64_t dsStruct64);
extern dsmObjName dsmNameToObjname(char *fsname, char *filename, int verbose);
extern dsInt16_t tsm_queryfile(dsUint32_t sesshandle, dsmObjName *objName, char *description, dsmSendType sendtype, char verbose, tsm_query_callback usercb, void * userdata, char *pitdate, int querytype);
/*
* Our Callback to show what is in TSM
*/
int tsm_listfile_cb(dsmQueryType qType, DataBlk *qResp, void *userdata) {
2013-07-19 04:19:03 +00:00
char stor[2];
char state[3];
char ced[4];
2013-07-18 13:59:14 +00:00
qryRespBackupData respBackup;
qryRespArchiveData respArchive;
if (userdata != NULL ) {
fprintf(stderr, "tsm_listfile_cb: Internal error: userdate != NULL");
return -1;
}
if (qType == qtArchive) {
2013-11-04 13:13:12 +00:00
if (! headerPrinted++)
printf("%40s %2s %s %3s %19s %19s %10s %10s %s\n",
"NAME",
"ST",
"L",
"CED",
"BACKUP",
"EXPIRE",
"EST SIZE",
"ID",
"DESC"
);
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,"?");
}
// Location
switch (respArchive.mediaClass) {
case (MEDIA_FIXED) : strcpy(stor,"D"); break;
case (MEDIA_LIBRARY) : strcpy(stor,"T"); break;
default : strcpy(stor,"?");
}
// 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" : "-");
// The Object Status
printf("%40s|%2s|%s|%3s|%19s|%19s|%7.3f MB|%u-%u|%s\n",dsmObjnameToStr(respArchive.objName),state,stor,ced,dsmDateToStr(respArchive.insDate),respArchive.expDate.year ? dsmDateToStr(respArchive.expDate) : "",dsmSizeToNum(respArchive.sizeEstimate),respArchive.objId.hi,respArchive.objId.lo,respArchive.descr);
2013-07-18 13:59:14 +00:00
} else if (qType ==qtBackup) {
2013-11-04 13:13:12 +00:00
if (! headerPrinted++)
printf("%40s %2s %s %3s %19s %19s %10s %s\n",
"NAME",
"ST",
"L",
"CED",
"BACKUP",
"EXPIRE",
"EST SIZE",
"ID"
);
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,"?");
}
switch (respBackup.objState) {
case (DSM_ACTIVE) : strcat(state,"A"); break;
case (DSM_INACTIVE) : strcat(state,"I"); break;
default : strcat(state,"?");
}
// Location
switch (respBackup.mediaClass) {
case (MEDIA_FIXED) : strcpy(stor,"D"); break;
case (MEDIA_LIBRARY) : strcpy(stor,"T"); break;
default : strcpy(stor,"?");
}
// 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" : "-");
2013-11-04 13:13:12 +00:00
printf("%40s|%2s|%s|%3s|%19s|%19s|%7.3f MB|%u-%u\n",dsmObjnameToStr(respBackup.objName),state,stor,ced,dsmDateToStr(respBackup.insDate),respBackup.expDate.year ? dsmDateToStr(respBackup.expDate) : "",dsmSizeToNum(respBackup.sizeEstimate),respBackup.objId.hi,respBackup.objId.lo);
2013-07-18 13:59:14 +00:00
} else {
fprintf(stderr,"tsm_listfile_cb: Internal error: Unknown qType %d\n",qType);
return -1;
}
return 1;
}
/*
* List objects that are in TSM
*/
int tsm_listfile(dsUint32_t sesshandle, char *fsname, char *filename, char *description, dsmSendType sendtype, char verbose, char *pitdate) {
dsInt16_t rc=0;
dsmObjName objName;
objName = dsmNameToObjname(fsname,filename,verbose);
rc = tsm_queryfile(sesshandle, &objName, description, sendtype, verbose, tsm_listfile_cb, NULL, pitdate, DSM_ANY_MATCH);
if (rc != DSM_RC_OK && rc != DSM_RC_ABORT_NO_MATCH)
return 0;
return 1;
}