bucoord-protoize-20070104
[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 RCSID
14     ("$Header$");
15
16 #include <sys/types.h>
17 #ifdef AFS_NT40_ENV
18 #include <winsock2.h>
19 #else
20 #include <sys/socket.h>
21 #include <netinet/in.h>
22 #include <netdb.h>
23 #endif
24 #include <rx/xdr.h>
25 #include <afs/vlserver.h>       /*Misc server-side Volume Location stuff */
26 #include <ubik.h>
27 #include "volser.h"
28 #include "bc.h"
29 #include <afs/volint.h>
30
31 extern char *whoami;
32
33 /* ********************************************************************* */
34 /* Volserver routines */
35 /* ********************************************************************* */
36
37 afs_int32
38 bc_GetEntryByID(uclient, volID, volType, vldbEntryPtr)
39      struct ubik_client *uclient;
40      afs_int32 volID;
41      afs_int32 volType;
42      struct vldbentry *vldbEntryPtr;
43 {
44     afs_int32 code = 0;
45
46     code =
47         ubik_VL_GetEntryByID(uclient, 0, volID, volType, vldbEntryPtr);
48     return (code);
49 }
50
51 /* volImageTime
52  *      Determine the time stamp to be recorded with the backup of this
53  *      volume. For backup and r/o volumes this is the clone time, for
54  *      r/w volumes, this is the current time. This timestamp is stored
55  *      directly into the cloneDate field of the bc_volumeDump structure
56  * exit:
57  *      0 - success
58  *      -1 - failed to get information. Sets cloneDate to 0.
59  */
60
61 afs_int32
62 volImageTime(serv, part, volid, voltype, clDatePtr)
63      afs_int32 serv;
64      afs_int32 part;
65      afs_int32 volid;
66      afs_int32 voltype;
67      afs_int32 *clDatePtr;
68 {
69     afs_int32 code = 0;
70     struct volintInfo *viptr;
71
72     if (voltype == RWVOL) {
73         *clDatePtr = time(0);
74         return (0);
75     }
76
77     code = UV_ListOneVolume(htonl(serv), part, volid, &viptr);
78     if (code) {
79         com_err(whoami, code,
80                 "Warning: Can't get clone time of volume %u - using 0",
81                 volid);
82         *clDatePtr = 0;
83         return (0);
84     }
85
86     /* volume types from vol/voldefs.h */
87     switch (viptr->type) {
88     case RWVOL:
89         /* For a r/w volume there may not be any foolproof way of
90          * preventing anomalies in the backups. Use the current time;
91          */
92         *clDatePtr = time(0);
93         break;
94
95     case ROVOL:
96     case BACKVOL:
97         *clDatePtr = viptr->creationDate;       /* use the creation time */
98         break;
99
100     default:
101         com_err(whoami, 0,
102                 "Can't get clone time of volume %u - unknown volume type",
103                 volid);
104         return (-1);
105     }
106     return (0);
107 }