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