-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdsmarc.c
2795 lines (2398 loc) · 55.6 KB
/
dsmarc.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* DSMARC.C is an archive/retieve utility for iRODS using the TSM API. */
/* System include files. */
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <limits.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <pwd.h>
#include <grp.h>
#include <time.h>
/* TSM API include files. */
#include "dsmapitd.h"
#include "tsmapitd.h"
#include "dsmapifp.h"
#include "tsmapifp.h"
#include "dsmapips.h"
#include "dsmrc.h"
#include "dapitype.h"
#include "dapiproc.h"
/* Bail out if not POSIX. */
#ifndef _POSIX_VERSION
#error We do only POSIX
#endif
/* End of string character. */
#define EOS ((char) '\0')
/* Newline character. */
#define NL ((char) '\n')
/* Blank character. */
#define SPACE ((char) ' ')
/* Default debug level. */
#define DEFAULT_DEBUG_LEVEL ((int) 0)
/* Maximum path length. Hope we got the POSIX stuff. */
#ifndef PATH_MAX
#ifdef _POSIX_PATH_MAX
#define PATH_MAX _POSIX_PATH_MAX
#else
#define PATH_MAX ((int) 255)
#endif
#endif
/* Comment string length. */
#define COMMENT_STRING_MAX ((int) 255)
/* Time maximum length all long formats. */
#define TIMEMAX ((int) 128)
/* ISO standard date format string. */
#define DEFAULT_DATE_FORMAT "%Y-%m-%dT%H:%M:%S"
/* iRODS standard date format string, almost ISO. */
#define IRODS_DATE_FORMAT "%Y-%m-%d-%H.%M.%S"
/* ISO printf format to convert from TSM. */
#define ISO_PRINTF_FORMAT "%04d-%02d-%02dT%02d:%02d:%02d"
/* iRODS date format string to convert from TSM. */
#define IRODS_PRINTF_FORMAT "%04d-%02d-%02d-%02d.%02d.%02d"
/* Length of date string is 20 + 1. Tsm may return year 65535. */
#define DATE_LENGTH ((int) 32)
/* Default I/O buffer size. */
#define DEFAULT_BUFFER_SIZE ((size_t) 1048576)
/* Boolean literals. */
#ifndef true
#define true ((int) 1)
#endif
#ifndef true
#define true ((int) 0)
#endif
/* Exit codes. */
#define SUCCESS ((int) 0)
#define FAILURE ((int) 1)
/* Our objInfo structure. Contains extra information about an archive file. */
typedef struct
{
/* Version and magic. */
unsigned long version;
/* Copy of the original stat info. */
struct stat sb;
} ourInfo;
/* Version and magic for ourInfo. */
#define OURINFO_VERSION 0xfefefefe00000001
/* Object type on the TSM server. */
typedef enum
{
file,
directory,
any
} object_type_t;
/* Comment in TSM info fields. */
#define IRODS_TSM_COMMENT "iRODS TSM API"
/* Globals to store query results. */
/* Maximum number of query results. */
#define MAX_QR 1024
/* Global definitions. */
/* Debug level. */
static int debug = DEFAULT_DEBUG_LEVEL;
/* Force actions. */
static int forced = false;
/* Sort by restore order. */
static int restoreorder = false;
/* Query responses. */
static qryRespArchiveData *qr = NULL;
/* Query responses index, the number of responses returned. */
static int nqr = 0;
/* Query response array size. */
static int maxqr = MAX_QR;
/* Maximum number of TSM object handles. */
#define MAX_HANDLES 1024
/* Global end of file flag array for TSM objects.
We think that the TSM object handle is a small integer. */
int eof_flags[MAX_HANDLES];
/* Print message. */
static void
msg (const char *format, ...)
{
va_list args;
va_start (args, format);
(void) vfprintf (stdout, format, args);
va_end (args);
(void) fprintf (stdout, "\n");
}
/* Simple error report and exit. */
static void
error (const char *format, ...)
{
va_list args;
/* Print error message. */
va_start (args, format);
(void) vfprintf (stderr, format, args);
va_end (args);
(void) fprintf (stderr, "\n");
/* Add errno info. Paranoid flush. */
if (errno != 0)
{
perror ("Errno info");
}
(void) fflush (stderr);
exit (FAILURE);
}
/* Allocate memory. */
static void *
allocate (size_t s)
{
void *p;
p = malloc (s);
if (p == NULL)
{
error ("Cannot allocate memory");
}
return (p);
}
/* Compare strings. */
static int
seq (const char *a, const char *b)
{
int status;
status = strcasecmp (a, b);
return (status == 0);
}
/* Safe copy. */
static void
scp (char *d, const char *s, size_t n)
{
size_t len;
char *r;
const char *from;
char *to;
size_t i;
char ch;
/* Set up from and to pointers. */
from = s;
if (d == (char *) NULL)
{
/* Destination is NULL, allocate space for string + EOS. */
len = strlen (s) + 1;
if (len > n)
{
error ("Dynamic allocation but specified size %lu is small", n);
}
r = (char *) allocate (len);
to = r;
}
else
{
len = n;
r = d;
to = d;
}
i = (size_t) 0;
ch = *from;
while (ch != EOS)
{
/* Copy. */
*to = ch;
/* Move forward and get the next character. */
from++;
to++;
ch = *from;
i++;
/* Abort if it would not fit. */
if (i >= len)
{
error ("Destination string cannot fit %lu characters plus EOS", i);
}
}
/* All copied, append EOS. */
*to = EOS;
}
/* String append, until eos but not more than n characters. */
static char *
sapp (char *d, const char *s, size_t n)
{
size_t len;
size_t dlen;
char *r;
const char *from;
char *to;
size_t i;
char ch;
/* Set up from and to pointers. */
from = s;
if (d == (char *) NULL)
{
error ("Destination is null for function sapp");
}
else
{
dlen = strlen (d) + 1;
len = n - dlen;
r = d;
to = d + dlen - 1;
}
i = (size_t) 0;
ch = *from;
while (ch != EOS)
{
/* Copy. */
*to = ch;
/* Move forward and get the next character. */
from++;
to++;
ch = *from;
i++;
/* Abort if it would not fit. */
if (i > len)
{
error ("Destination string cannot fit %lu characters plus EOS", i);
}
}
/* All copied, append EOS. */
*to = EOS;
return (r);
}
/* Print tsm format message. */
static void
tmsg (const char *desc, const char *format, ...)
{
va_list args;
fprintf (stdout, "%38s: ", desc);
va_start (args, format);
(void) vfprintf (stdout, format, args);
va_end (args);
(void) fprintf (stdout, "\n");
}
/* Open file for reading. */
static int
open_file_read (char *filename)
{
int status;
status = open (filename, O_RDONLY|O_NOATIME);
if (status == -1)
{
error ("Could not open local file %s", filename);
}
return (status);
}
/* Open file for writing. */
static int
open_file_write (char *filename)
{
int status;
/* Old umask. */
mode_t umold;
/* Creation modes for files. */
mode_t owrgron = (mode_t) 00640;
mode_t owrgwron = (mode_t) 00660;
/* Umasks with various protections. */
mode_t mask_owrgwron = (mode_t) 00002;
mode_t mask_owrgron = (mode_t) 00027;
mode_t mask_none = (mode_t) 00777;
/* Open as owner:rw, group:rw, others:none.
Create file. Do not overwrite. Lock while writing. */
umold = umask (mask_owrgwron);
status = open (filename, O_RDWR|O_CREAT|O_EXCL, owrgwron);
(void) umask ((mode_t) umold);
if (status == -1)
{
error ("Could not open local file %s", filename);
}
return (status);
}
/* Close file. */
static void
close_file (int fd)
{
int status;
status = close (fd);
if (status == -1)
{
error ("Could not close local file %d", fd);
}
}
/* Read from file. */
static ssize_t
read_file (int fd, void *buf, size_t len)
{
ssize_t status;
status = read (fd, buf, len);
if (status == -1)
{
error ("Error reading local file %d", fd);
}
return (status);
}
/* Write file. */
static ssize_t
write_file (int fd, void *buf, size_t len)
{
ssize_t status;
status = write (fd, buf, len);
if (status == -1)
{
error ("Error writing local file %d", fd);
}
if (status != (ssize_t) len)
{
error ("Short write on local file %d", fd);
}
return (status);
}
/* Stat file. */
static void
stat_file (char *filename, struct stat *sb)
{
int status;
status = stat (filename, sb);
if (status == -1)
{
error ("Stat failed for local file %s", filename);
}
}
/* Initialize stat block. */
static void
init_stat (struct stat *sb)
{
time_t now;
struct passwd *passwd;
/* Zero fill structure. */
(void) memset (sb, 0, sizeof (struct stat));
/* Get current timestamp and uid/gid. */
now = time (NULL);
passwd = getpwuid (getuid ());
if (passwd == NULL)
{
error ("getpwuid failed in init_stat");
}
/* Initialize. */
sb->st_dev = 0;
sb->st_ino = 0;
sb->st_mode = 00660;
sb->st_nlink = 0;
sb->st_uid = passwd->pw_uid;
sb->st_gid = passwd->pw_gid;
sb->st_rdev = 0;
sb->st_blksize = 0;
sb->st_blocks = 0;
sb->st_atime = now;
sb->st_mtime = now;
sb->st_ctime = now;
/* TSM will need some size estimate. */
sb->st_size = DEFAULT_BUFFER_SIZE;
}
/* Parse path name to filespace, low level name and high level name. */
static void
parse_path (char *fs, char *hl, char *ll, char *path)
{
size_t len;
char *p;
int n;
/* Check. */
if (*path != '/')
{
error ("Pathname should be absolute");
}
len = strlen (path);
if (len > (size_t) (PATH_MAX - 1))
{
error ("Pathname is too long");
}
if (*(path + len - 1) == '/')
{
error ("Trailing slash - wrong");
}
/* First part of the pathname will be the filespace name. */
n = 0;
p = path;
*fs = *p;
p++;
fs++;
n++;
while (*p != '/')
{
*fs = *p;
p++;
fs++;
n++;
if (n > DSM_MAX_FSNAME_LENGTH)
{
error ("Filespace name too long");
}
}
*fs = EOS;
/* Second path is the high level name, which is the directory name. */
n = 0;
p = path;
*hl = *p;
p++;
hl++;
n++;
while (*p != EOS)
{
*hl = *p;
p++;
hl++;
n++;
if (n > DSM_MAX_HL_LENGTH)
{
error ("HL name too long");
}
}
*hl = EOS;
/* Copied the whole thing now scan from the back to find the slash.
Overwrite the slash with EOS. */
while (*hl != '/')
{
hl--;
}
*hl = EOS;
/* Now copy out the low level name. Should start with a slash. */
n = 0;
*ll = '/';
hl++;
ll++;
n++;
*ll = *hl;
hl++;
ll++;
n++;
while (*hl != EOS)
{
*ll = *hl;
hl++;
ll++;
n++;
if (n > DSM_MAX_LL_LENGTH)
{
error ("LL name too long");
}
}
*ll = EOS;
}
/* Print error message and exit TSM API. */
static void
tsm_error (dsUint32_t handle, dsInt16_t status, const char *format, ...)
{
dsUint16_t reason = DSM_RS_ABORT_SYSTEM_ERROR;
va_list args;
dsInt16_t rcmsg_status;
char rcmsg[DSM_MAX_RC_MSG_LENGTH];
char *cp;
/* Terminate the transaction if any. */
(void) dsmEndTxn (handle, DSM_VOTE_ABORT, &reason);
/* Get TSM status message. Cut newline at start and at the end. */
*rcmsg = EOS;
rcmsg_status = dsmRCMsg (handle, status, rcmsg);
cp = (char *) rcmsg;
*cp = SPACE;
cp = (char *) (rcmsg + strlen (rcmsg) - 1);
*cp = SPACE;
/* Finish with TSM. */
(void) dsmTerminate (handle);
(void) dsmCleanUp(DSM_MULTITHREAD);
/* Print error message and quit. */
va_start (args, format);
(void) vfprintf (stderr, format, args);
va_end (args);
(void) fprintf (stderr, "\n");
if (status != (dsInt16_t) 0)
{
if (rcmsg_status == 0)
{
/* Quit with message retrieved from TSM. */
error ("TSM API error: %s", rcmsg);
}
else
{
/* Could not retrieve message for non-zero status code. */
error ("TSM API error status: %d", (int) status);
}
}
else
{
/* TSM status was success error was for other reasons. */
error ("TSM API was successful but error exit was requested");
}
}
/* TSM setup. */
static void
tsm_setup (char *argv[])
{
/* Threaded initialization / setup. We need this only to have
multiple streams. */
/* Environment info for the dsmSetUp call. */
envSetUp envsetup;
/* TSM status. */
dsInt16_t status;
/* For dsmSetUp. */
(void) memset (&envsetup, 0, sizeof(envSetUp));
envsetup.stVersion = envSetUpVersion;
strcpy (envsetup.dsmiDir, "");
strcpy (envsetup.dsmiConfig, "");
strcpy (envsetup.dsmiLog, "");
strcpy (envsetup.logName, "");
envsetup.argv = argv;
/* Initialize. */
status = dsmSetUp (DSM_MULTITHREAD, &envsetup);
if (status != DSM_RC_OK)
{
(void) dsmCleanUp (DSM_MULTITHREAD);
error ("Calling dsmSetUp failed with %d", status);
}
}
/* Initialize the TSM API. */
static dsUint32_t
tsm_init (void)
{
dsmInitExIn_t exin;
dsmInitExOut_t exout;
dsmApiVersionEx exver;
dsUint32_t handle;
dsInt16_t status;
ApiSessInfo sessinfo;
/* Checks. */
if (sizeof (off_t) * CHAR_BIT != 64)
{
error ("Offsets should be 64-bit");
}
if (sizeof (unsigned long) * CHAR_BIT != 64)
{
error ("Word size should be 64-bit");
}
if (sizeof (ourInfo) > DSM_MAX_OBJINFO_LENGTH)
{
error ("ourInfo structure became too big");
}
/* Zero and load parameter blocks. */
(void) memset (&exver, 0, sizeof (dsmApiVersionEx));
exver.stVersion = apiVersionExVer;
exver.version = DSM_API_VERSION;
exver.release = DSM_API_RELEASE;
exver.level = DSM_API_LEVEL;
exver.subLevel = DSM_API_SUBLEVEL;
(void) memset (&exin, 0, sizeof (dsmInitExIn_t));
exin.stVersion = dsmInitExInVersion;
exin.apiVersionExP = &exver;
exin.clientNodeNameP = NULL;
exin.clientOwnerNameP = NULL;
exin.clientPasswordP = NULL;
exin.applicationTypeP = NULL;
exin.configfile = NULL;
exin.options = NULL;
exin.userNameP = NULL;
exin.userPasswordP = NULL;
exin.dirDelimiter = '\0';
exin.useUnicode = dsmFalse;
exin.bEncryptKeyEnabled = dsmFalse;
exin.encryptionPasswordP = NULL;
(void) memset (&exout, 0, sizeof (dsmInitExOut_t));
exout.stVersion = dsmInitExOutVersion;
/* Initialize and get handle. */
status = dsmInitEx (&handle, &exin, &exout);
if (status != DSM_RC_OK)
{
/* Failure, bail out. */
tsm_error (handle, status, "dsmInitEx failed");
}
/* Get session info. */
(void) memset (&sessinfo, 0, sizeof (ApiSessInfo));
sessinfo.stVersion = ApiSessInfoVersion;
status = dsmQuerySessInfo (handle, &sessinfo);
if (status != DSM_RC_OK)
{
/* Failure, bail out. */
tsm_error (handle, status, "dsmQuerySessInfo failed");
}
/* Success, return handle. */
return (handle);
}
/* Finish using the TSM API. */
static void
tsm_exit (dsUint32_t handle)
{
/* Reason code for dsmEndTxn. */
dsUint16_t reason;
/* Close transaction with commit just to be on the safe side. */
reason = 0;
(void) dsmEndTxn (handle, DSM_VOTE_COMMIT, &reason);
(void) dsmCleanUp (DSM_MULTITHREAD);
(void) dsmTerminate (handle);
}
/* Send data to the server. */
static void
tsm_send_data (dsUint32_t handle, void *buffer, size_t bufsize)
{
DataBlk data;
dsInt16_t status;
/* Fill out data block structure. */
data.stVersion = DataBlkVersion;
data.bufferLen = bufsize;
data.numBytes = 0;
data.bufferPtr = (char *) buffer;
/* Call API. */
status = dsmSendData (handle, &data);
if (status != DSM_RC_OK)
{
tsm_error (handle, status, "Cannot send data");
}
/* Number of bytes transferred returned in numBytes, check. */
if (data.numBytes != data.bufferLen)
{
tsm_error (handle, status, "Short send to TSM");
}
}
/* Create object conforming to a local file. */
static void
tsm_create_object (dsUint32_t handle, object_type_t o,
struct stat *s, char *path)
{
/* Type of filespace and info, used when filespace is to be created. */
char filespace_type[COMMENT_STRING_MAX];
char filespace_info[COMMENT_STRING_MAX];
/* TSM object name structure. */
dsmObjName name;
/* TSM filespace, high level and low level names. */
char fs[DSM_MAX_FSNAME_LENGTH + 1];
char hl[DSM_MAX_HL_LENGTH + 1];
char ll[DSM_MAX_LL_LENGTH + 1];
/* TSM object attributes structure. */
ObjAttr attr;
/* Passwd entry. */
struct passwd *passwd;
/* Status block local copy. */
struct stat sb;
/* Current time. */
time_t now;
/* Object info. */
ourInfo objinfo;
/* Archive description. */
char archive_descr[COMMENT_STRING_MAX];
/* Filespace data. */
regFSData fsdata;
/* TSM status. */
dsInt16_t status;
/* Management class bind info. */
mcBindKey mcinfo;
/* Archive extra data. */
sndArchiveData archdata;
/* Initialize comment fields. */
scp (filespace_type, IRODS_TSM_COMMENT, COMMENT_STRING_MAX);
scp (filespace_info, IRODS_TSM_COMMENT, COMMENT_STRING_MAX);
/* Initialize object name structure.
Get the path. We think it's a mounted file system so the
filespace name is the same as the first word of the path. */
(void) memset (&name, 0, sizeof (dsmObjName));
parse_path (fs, hl, ll, path);
scp (name.fs, fs, DSM_MAX_FSNAME_LENGTH);
scp (name.hl, hl, DSM_MAX_HL_LENGTH);
scp (name.ll, ll, DSM_MAX_LL_LENGTH);
switch (o)
{
case file:
name.objType = DSM_OBJ_FILE;
break;
case directory:
name.objType = DSM_OBJ_DIRECTORY;
break;
case any:
error ("Archive object %s can not have type ANY", path);
break;
}
/* Now the attributes structure. */
(void) memset (&attr, 0, sizeof (ObjAttr));
attr.stVersion = ObjAttrVersion;
/* Object owner is our username string. */
passwd = getpwuid (getuid ());
if (passwd == NULL)
{
error ("getpwuid failed");
}
scp (attr.owner, passwd->pw_name, 32);
/* Deal with the size estimate and get status block if any. */
if (s != NULL)
{
/* Copy the status block and set the size attributes. */
(void) memcpy (&sb, s, sizeof (struct stat));
attr.sizeEstimate.hi = sb.st_size >> 32;
attr.sizeEstimate.lo = sb.st_size & 0x00000000ffffffff;
}
else
{
/* Just zero for attributes. */
attr.sizeEstimate.hi = 0;
attr.sizeEstimate.lo = 0;
/* No status block given, reasonable defaults. */
(void) memset (&sb, 0, sizeof (struct stat));
now = time (NULL);
sb.st_dev = 0;
sb.st_ino = 0;
sb.st_mode = 00660;
sb.st_nlink = 0;
sb.st_uid = passwd->pw_uid;
sb.st_gid = passwd->pw_gid;
sb.st_rdev = 0;
sb.st_size = (off_t) 0;
sb.st_blksize = (u_long) 0;
sb.st_blocks = (u_long) 0;
sb.st_atime = now;
sb.st_mtime = now;
sb.st_ctime = now;
}
/* Load our object info block into the attr structure. */
(void) memset (&objinfo, 0, sizeof (ourInfo));
objinfo.version = OURINFO_VERSION;
(void) memcpy (&objinfo.sb, &sb, sizeof (struct stat));
attr.objInfo = (char *) &objinfo;
attr.objInfoLength = sizeof (ourInfo);
/* Others. */
attr.mcNameP = NULL;
/* Register the file space if needed. */
(void) memset (&fsdata, 0, sizeof (regFSData));
fsdata.stVersion = regFSDataVersion;
fsdata.fsName = fs;
fsdata.fsType = filespace_type;
(void) strcpy(fsdata.fsAttr.unixFSAttr.fsInfo, filespace_info);
fsdata.fsAttr.unixFSAttr.fsInfoLength =
strlen(filespace_info) + 1;
fsdata.occupancy.hi = 0;
fsdata.occupancy.lo = 0;
fsdata.capacity.hi = 0;
fsdata.capacity.lo = 1073741824;
status = dsmRegisterFS (handle, &fsdata);
if (status != DSM_RC_OK)
{
if (status != DSM_RC_FS_ALREADY_REGED)
{
tsm_error (handle, status, "Cannot register filespace %s", fs);
}
}
/* Open the transaction. */
status = dsmBeginTxn (handle);
if (status != DSM_RC_OK)
{
tsm_error (handle, status, "dsmBeginTxn failed");
}
/* Bind management class and check. */
(void) memset (&mcinfo, 0, sizeof (mcBindKey));
mcinfo.stVersion = mcBindKeyVersion;
status = dsmBindMC (handle, &name, stArchive, &mcinfo);
if (status != DSM_RC_OK)
{
tsm_error (handle, status, "Cannot bind management class for %s", path);
}
if (!mcinfo.archive_cg_exists)
{
tsm_error (handle, status, "Cannot find archive copygroup");
}
/* Set description. */
(void) memset (&archdata, 0, sizeof (sndArchiveData));
archdata.stVersion = sndArchiveDataVersion;
scp (archive_descr, "", COMMENT_STRING_MAX);
archdata.descr = archive_descr;
/* Create object reference. */
status = dsmSendObj (handle, stArchive, (void *) &archdata,
&name, &attr, NULL);
if (status != DSM_RC_OK)
{
tsm_error (handle, status, "dsmSendObj failed for %s", path);
}
}
/* Finish with the object. End sending the object and close transaction. */
static void
tsm_finish_with_object (dsUint32_t handle)
{
/* TSM status. */
dsInt16_t status;
/* Reason code for dsmEndTxn. */
dsUint16_t reason;
/* Object finished. */
status = dsmEndSendObj (handle);
if (status != DSM_RC_OK)
{
tsm_error (handle, status, "dsmEndSendObj failed");
}
/* Close transaction assuming success. */
reason = (dsUint16_t) 0;
status = dsmEndTxn (handle, DSM_VOTE_COMMIT, &reason);
if (status != DSM_RC_OK)
{
tsm_error (handle, status, "dsmEndTxn failed");
}
if (reason != 0)
{
tsm_error (handle, status, "dsmEndTxn failed on reason %d", reason);
}
}
/* Archive an object. */
static void