2013-07-18 13:59:14 +00:00
|
|
|
/*
|
|
|
|
* Date manipulations functions for tsmpipe
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "dsmapitd.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This function will take a string date entered and convert that to a TSM
|
|
|
|
* date
|
|
|
|
*
|
|
|
|
* The date is passed to this function in the format mmddYYYY
|
|
|
|
*/
|
2013-11-07 04:10:18 +00:00
|
|
|
dsmDate dsmStrToDate(char *s) {
|
|
|
|
extern int verbose;
|
2013-07-18 13:59:14 +00:00
|
|
|
dsmDate *date;
|
2013-11-07 04:10:18 +00:00
|
|
|
dsUint32_t d,t;
|
|
|
|
char *x=NULL, *y=NULL;
|
2013-07-18 13:59:14 +00:00
|
|
|
|
|
|
|
date = (dsmDate*)malloc(sizeof(dsmDate));
|
2013-11-07 04:10:18 +00:00
|
|
|
x = (char *)malloc(sizeof(s));
|
|
|
|
y = (char *)malloc(sizeof(s));
|
2013-07-18 13:59:14 +00:00
|
|
|
|
|
|
|
if (date==NULL) {
|
|
|
|
perror("Arg, out of memory?");
|
|
|
|
exit(255);
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(date,0x00,sizeof(dsmDate));
|
|
|
|
|
|
|
|
if (verbose)
|
|
|
|
printf("dsmStrToDate: Date String: %s\n", s);
|
|
|
|
|
|
|
|
/* if user key in some inputs */
|
|
|
|
if (s[0] != '\0') {
|
2013-11-11 02:49:46 +00:00
|
|
|
y=strchr(s,':');
|
|
|
|
|
|
|
|
if (y != NULL) {
|
|
|
|
strncpy(x,s,strlen(s)-strlen(y));
|
|
|
|
x[strlen(s)-strlen(y)] = '\0';
|
|
|
|
y = strchr(s,':')+1;
|
|
|
|
} else
|
|
|
|
x = s;
|
2013-11-07 04:10:18 +00:00
|
|
|
|
|
|
|
d = atol(x);
|
|
|
|
date->month = d / 1000000;
|
|
|
|
|
|
|
|
d %= 1000000;
|
|
|
|
date->day = d / 10000;
|
|
|
|
date->year = d % 10000;
|
2013-07-18 13:59:14 +00:00
|
|
|
|
2013-11-11 02:49:46 +00:00
|
|
|
if (y != NULL) {
|
2013-11-07 04:10:18 +00:00
|
|
|
t = atol(y);
|
|
|
|
date->hour = t / 10000;
|
|
|
|
|
|
|
|
t %= 10000;
|
|
|
|
date->minute = t / 100;
|
|
|
|
date->second = t % 100;
|
|
|
|
}
|
2013-07-18 13:59:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (verbose)
|
2013-11-07 04:10:18 +00:00
|
|
|
printf("dsmStrToDate: date = %d, month = %d, year = %d, hour = %d, minute = %d, second = %d\n", date->day, date->month, date->year, date->hour, date->minute, date->second);
|
2013-07-18 13:59:14 +00:00
|
|
|
|
|
|
|
return *date;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Display the dsmDate value as a string */
|
|
|
|
char *dsmDateToStr(dsmDate date) {
|
|
|
|
char *s;
|
|
|
|
|
|
|
|
s = malloc(19);
|
|
|
|
|
|
|
|
if (s==NULL) {
|
|
|
|
perror("Arg, out of memory?");
|
|
|
|
exit(255);
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(s,0x00,sizeof(s));
|
|
|
|
|
|
|
|
sprintf(s,"%02i/%02i/%04i %02i:%02i:%02i",
|
|
|
|
(dsInt16_t)date.day,
|
|
|
|
(dsInt16_t)date.month,
|
|
|
|
date.year,
|
|
|
|
(dsInt16_t)date.hour,
|
|
|
|
(dsInt16_t)date.minute,
|
|
|
|
(dsInt16_t)date.second);
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2013-11-07 04:10:18 +00:00
|
|
|
dsmObjName dsmNameToObjname(char *fsname, char *filename) {
|
|
|
|
extern int verbose;
|
2013-07-18 13:59:14 +00:00
|
|
|
dsmObjName *objname;
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
objname = (dsmObjName*)malloc(sizeof(dsmObjName));
|
|
|
|
|
|
|
|
if (objname==NULL) {
|
|
|
|
perror("Arg, out of memory?");
|
|
|
|
exit(255);
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(objname,0x00,sizeof(dsmObjName));
|
|
|
|
|
|
|
|
if (verbose)
|
|
|
|
fprintf(stderr,"dsmNameToObjname: FS: %s Filename: %s\n",fsname,filename);
|
|
|
|
|
|
|
|
/* fs == "/filesystem", hl == "/directory/path", ll == "/filename" */
|
|
|
|
strcpy(objname->fs,fsname);
|
|
|
|
|
|
|
|
p = strrchr(filename, '/');
|
|
|
|
|
|
|
|
if (p) {
|
|
|
|
*p = '\0';
|
|
|
|
|
|
|
|
if (*filename && *filename != '/')
|
|
|
|
strcpy(objname->hl, "/");
|
|
|
|
|
|
|
|
strcpy(objname->hl,filename);
|
|
|
|
sprintf(objname->ll,"/%s",p+1);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
if (*filename && *filename != '/')
|
|
|
|
strcpy(objname->ll, "/");
|
|
|
|
|
|
|
|
strcat(objname->ll,filename);
|
|
|
|
}
|
|
|
|
|
|
|
|
objname->objType = DSM_OBJ_FILE;
|
|
|
|
|
|
|
|
return *objname;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *dsmObjnameToStr(dsmObjName objName) {
|
|
|
|
char *s;
|
|
|
|
|
|
|
|
s = malloc(sizeof(dsmObjName));
|
|
|
|
|
|
|
|
if (s==NULL) {
|
|
|
|
perror("Arg, out of memory?");
|
|
|
|
exit(255);
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(s,0x00,sizeof(s));
|
|
|
|
|
|
|
|
sprintf(s,"%s%s%s",objName.fs,objName.hl,objName.ll);
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
double dsmSizeToNum(dsStruct64_t dsStruct64) {
|
|
|
|
unsigned long long filesize=0;
|
|
|
|
|
|
|
|
filesize = 0x00;
|
|
|
|
|
|
|
|
filesize = dsStruct64.hi;
|
|
|
|
filesize <<= 32;
|
|
|
|
filesize |= dsStruct64.lo;
|
|
|
|
|
|
|
|
// Return number in MB
|
|
|
|
return (float)filesize/1024/1024;
|
|
|
|
}
|
2013-11-07 04:10:18 +00:00
|
|
|
|
|
|
|
void debugLog(int level, _IO_FILE *output, char *message, int die) {
|
|
|
|
extern int verbose;
|
|
|
|
|
|
|
|
if (level > verbose)
|
|
|
|
return;
|
|
|
|
|
|
|
|
fprintf(output,"%s\n",message);
|
|
|
|
|
|
|
|
if (die)
|
|
|
|
exit(die);
|
|
|
|
}
|