-
Notifications
You must be signed in to change notification settings - Fork 1
/
dat1ValidateLocator.c
148 lines (127 loc) · 5.26 KB
/
dat1ValidateLocator.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
/*
*+
* Name:
* dat1ValidateLocator
* Purpose:
* Check the supplied locator is usable.
* Language:
* Starlink ANSI C
* Type of Module:
* Library routine
* Invocation:
* dat1ValidateLocator( const char *func, int checklock, const HDSLoc *loc,
* int rdonly, int * status );
* Arguments:
* func = const char * (Given)
* Name of calling function. Used in error messages.
* checklock = int (Given)
* If non-zero, an error is reported if the supplied locator is not
* locked by the current thread (see datLock). This check is not
* performed if "checklock" is zero.
* loc = HDSLoc * (Given)
* Locator to validate.
* rdonly = int (Given)
* Indicates if the calling function may or may not make any
* changes to the HDF object or locator structure. If a non-zero
* value is supplied, it is assumed that the calling function will
* never make any changes to either the HDF object on disk or the
* locator structure. This determines the type of lock that the
* calling thread must have on the object (read-only or read-write)
* to avoid an error being reported by this function.
* status = int* (Given and Returned)
* Pointer to global status.
* Description:
* An error is reported if the supplied locator is not valid. This can
* occur for instance if the supplied locator is a secondary locator
* that has been annulled automatically as a result of the file being
* closed. An error is also reported if the current thread does no
* have an appropriate lock on the supplied object.
* Authors:
* DSB: David Berry (EAO)
* {enter_new_authors_here}
* History:
* 7-JUL-2017 (DSB):
* Initial version
* {enter_further_changes_here}
* Copyright:
* Copyright (C) 2017 East Asian Observatory
* All Rights Reserved.
* Licence:
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
* Bugs:
* {note_any_bugs_here}
*-
*/
#include <pthread.h>
#include "sae_par.h"
#include "ems.h"
#include "dat1.h"
#include "hds1.h"
#include "hds.h"
#include "dat_err.h"
int dat1ValidateLocator( const char *func, int checklock, const HDSLoc *loc,
int rdonly, int * status ) {
/* Local Variables; */
int valid;
int lock_status;
/* If the locator has been annulled (e.g. due to the container file being
closed when the last primary locator was annulled), report an error. */
datValid( loc, &valid, status );
if( !valid && *status == SAI__OK ) {
*status = DAT__LOCIN;
emsRepf(" ", "%s: The supplied HDS locator is invalid - it may have been "
"annulled as a result of the associated file being closed.",
status, func );
}
/* If the LockCheck tuning parameter is False, never check locks. */
if( checklock ) checklock = hds1GetLockCheck();
/* If required, check that the object is locked by the current thread for
the appropriate type of access. Do not check any child objects as these
will be checked if and when accessed. */
if( checklock && *status == SAI__OK && loc->handle->docheck ) {
dat1HandleLock( loc->handle, 1, 0, 0, &lock_status, status );
/* Calling function will not make any change to the object. In this case
the current thread must have a lock but the type (read-only or
read-write) does not matter. */
if( rdonly ) {
if( lock_status != 1 && lock_status != 3 && *status == SAI__OK ) {
*status = DAT__THREAD;
datMsg( "O", loc );
emsRepf( " ", "%s: The supplied HDS locator for '^O' cannot be used.",
status, func );
emsRep( " ", "It has not been locked for read-only or read-write "
"access by the current thread (programming error).",
status );
}
/* Calling function may make changes to the object. In this case the
current thread must have a read-write lock. */
} else if( lock_status != 1 && *status == SAI__OK ) {
*status = DAT__THREAD;
datMsg( "O", loc );
emsRepf( " ", "%s: The supplied HDS locator for '^O' cannot be used.",
status, func );
if( lock_status == 3 ) {
emsRep( " ", "Write-access is not allowed (the current thread "
"has locked it for read-only access - programming error).",
status );
} else {
emsRep( " ", "It has not been locked for read-write access by the "
"current thread (programming error).", status );
}
}
}
return *status;
}