7efbca5a86710001f1236a2b1c7f7c19f267087b
[openafs.git] / src / bucoord / volstub.c
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
5  * This software has been released under the terms of the IBM Public
6  * License.  For details, see the LICENSE file in the top-level source
7  * directory or online at http://www.openafs.org/dl/license10.html
8  */
9
10 #include <afsconfig.h>
11 #include <afs/param.h>
12
13
14 #include <sys/types.h>
15 #ifdef AFS_NT40_ENV
16 #include <winsock2.h>
17 #else
18 #include <sys/socket.h>
19 #include <netinet/in.h>
20 #include <netdb.h>
21 #endif
22 #include <rx/xdr.h>
23 #include <afs/vlserver.h>       /*Misc server-side Volume Location stuff */
24 #include <ubik.h>
25 #include "volser.h"
26 #include "bc.h"
27 #include <afs/volint.h>
28 #include <afs/volser.h>
29 #include <afs/volser_prototypes.h>
30 #include <afs/com_err.h>
31
32 extern char *whoami;
33
34 /* ********************************************************************* */
35 /* Volserver routines */
36 /* ********************************************************************* */
37
38 afs_int32
39 bc_GetEntryByID(struct ubik_client *uclient, afs_int32 volID, 
40                 afs_int32 volType, struct vldbentry *vldbEntryPtr)
41 {
42     afs_int32 code = 0;
43
44     code =
45         ubik_VL_GetEntryByID(uclient, 0, volID, volType, vldbEntryPtr);
46     return (code);
47 }
48
49 /* volImageTime
50  *      Determine the time stamp to be recorded with the backup of this
51  *      volume. For backup and r/o volumes this is the clone time, for
52  *      r/w volumes, this is the current time. This timestamp is stored
53  *      directly into the cloneDate field of the bc_volumeDump structure
54  * exit:
55  *      0 - success
56  *      -1 - failed to get information. Sets cloneDate to 0.
57  */
58
59 afs_int32
60 volImageTime(afs_int32 serv, afs_int32 part, afs_int32 volid, 
61              afs_int32 voltype, afs_int32 *clDatePtr)
62 {
63     afs_int32 code = 0;
64     struct volintInfo *viptr;
65
66     if (voltype == RWVOL) {
67         *clDatePtr = time(0);
68         return (0);
69     }
70
71     code = UV_ListOneVolume(htonl(serv), part, volid, &viptr);
72     if (code) {
73         afs_com_err(whoami, code,
74                 "Warning: Can't get clone time of volume %u - using 0",
75                 volid);
76         *clDatePtr = 0;
77         return (0);
78     }
79
80     /* volume types from vol/voldefs.h */
81     switch (viptr->type) {
82     case RWVOL:
83         /* For a r/w volume there may not be any foolproof way of
84          * preventing anomalies in the backups. Use the current time;
85          */
86         *clDatePtr = time(0);
87         break;
88
89     case ROVOL:
90     case BACKVOL:
91         *clDatePtr = viptr->creationDate;       /* use the creation time */
92         break;
93
94     default:
95         afs_com_err(whoami, 0,
96                 "Can't get clone time of volume %u - unknown volume type",
97                 volid);
98         return (-1);
99     }
100     return (0);
101 }