common/rc: factor out _scratch_xfs_[get|set]_sb_field
[xfstests-dev.git] / dmapi / src / common / lib / stubs.c
1 /*
2  * Copyright (c) 2000-2001 Silicon Graphics, Inc.
3  * All Rights Reserved.
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License as
7  * published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it would be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write the Free Software Foundation,
16  * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17  */
18
19 #include <errno.h>
20
21 #include <stdlib.h>
22 #include <lib/dmport.h>
23
24
25 /* See dmport.h for a description of why all these wrapper routines are
26    necessary.  Because SGI defines stub routines for all functions it didn't
27    implement, no SGI-specific wrappers are required.
28 */
29
30
31 #ifdef  VERITAS_21
32
33 /* The Veritas version of dm_downgrade_right has two additional parameters
34    not defined in the XDSM spec.  Provide values that make dm_downgrade_right
35    work according to the spec.
36 */
37
38 extern int
39 xvfs_dm_downgrade_right(
40         dm_sessid_t     sid,
41         void            *hanp,
42         size_t          hlen,
43         dm_token_t      token)
44 {
45 #undef  dm_downgrade_right
46         return(dm_downgrade_right(sid, hanp, hlen, token, 0, DM_RIGHT_SHARED));
47 }
48
49
50 /* The last byte in a Veritas handle is a 'pad' byte which they don't bother
51    to initialize to zero.  As a result, you can't do binary compares of
52    two handles to see if they are the same.  This stub (along with others)
53    forces the pad byte to zero so that binary compares are possible
54 */
55
56 extern int
57 xvfs_dm_fd_to_handle(
58         int             fd,
59         void            **hanpp,
60         size_t          *hlenp)
61 {
62 #undef  dm_fd_to_handle
63         int             rc;
64
65         if ((rc = dm_fd_to_handle(fd, hanpp, hlenp)) == 0) {
66                 if (*hlenp == 16) {
67                         char    *cp = (char *)*hanpp;
68                         cp[15] = '\0';
69                 }
70         }
71         return(rc);
72 }
73
74
75 /* The Veritas version of dm_get_config_events has a slightly different name.
76 */
77
78 extern int
79 dm_get_config_events(
80         void            *hanp,
81         size_t          hlen,
82         u_int           nelem,
83         dm_eventset_t   *eventsetp,
84         u_int           *nelemp)
85 {
86         return(dm_get_config_event(hanp, hlen, nelem, eventsetp, nelemp));
87 }
88
89
90 /* In version 2.1 uflags was defined as 'int nowait', so a value of zero in
91    this field means that the caller wants to wait.  In XDSM this was reversed,
92    where if the bottom bit of uflags is set then the caller wants to wait.
93    This routine makes the conversion.
94 */
95
96 extern int
97 xvfs_dm_get_events(
98         dm_sessid_t     sid,
99         u_int           maxmsgs,
100         u_int           uflags,
101         size_t          buflen,
102         void            *bufp,
103         size_t          *rlenp)
104 {
105 #undef  dm_get_events
106         int     nowait = 1;
107
108         if (uflags & DM_EV_WAIT)
109                 nowait = 0;
110
111         return(dm_get_events(sid, maxmsgs, nowait, buflen, bufp, rlenp));
112 }
113
114
115 /* The Veritas version of dm_get_mountinfo has the parameters in a different
116    order than in the XDSM spec.  Hide this in the wrapper.
117 */
118
119 extern int
120 xvfs_dm_get_mountinfo(
121         dm_sessid_t     sid,
122         void            *hanp,
123         size_t          hlen,
124         dm_token_t      token,
125         size_t          buflen,
126         void            *bufp,
127         size_t          *rlenp)
128 {
129 #undef  dm_get_mountinfo
130         return(dm_get_mountinfo(sid, token, hanp, hlen, buflen, bufp, rlenp));
131 }
132
133
134 /* Veritas does not support the dm_getall_disp function.  Furthermore, their
135    dm_dispinfo_t structure is missing the _link field that is needed for the
136    DM_STEP_TO_NEXT() macro to work.
137 */
138
139 extern int
140 dm_getall_disp(
141         dm_sessid_t     sid,
142         size_t          buflen,
143         void            *bufp,
144         size_t          *rlenp)
145 {
146         return(ENOSYS);
147 }
148
149
150 /* Veritas does not support the dm_getall_dmattr function.  Furthermore, their
151    dm_attrlist_t structure is missing the _link field that is needed for the
152    DM_STEP_TO_NEXT() macro to work.
153 */
154
155 extern int
156 dm_getall_dmattr(
157         dm_sessid_t     sid,
158         void            *hanp,
159         size_t          hlen,
160         dm_token_t      token,
161         size_t          buflen,
162         void            *bufp,
163         size_t          *rlenp)
164 {
165         return(ENOSYS);
166 }
167
168
169 /* Veritas does not support dm_handle_is_valid.  We emulate it by checking
170    fields which have known values, as DMF uses this a lot.
171 */
172
173 extern dm_boolean_t
174 dm_handle_is_valid(
175         void            *hanp,
176         size_t          hlen)
177 {
178         char            *cp = (char *)hanp;
179
180         if (hlen != 16) {
181                 return(DM_FALSE);
182         }
183         if (cp[15] != '\0') {
184                 return(DM_FALSE);
185         }
186         switch (cp[14]) {
187         case 1:
188         case 2:
189         case 4:
190                 break;
191         default:
192                 return(DM_FALSE);
193         }
194         switch (cp[13]) {
195         case 0:
196         case 1:
197                 break;
198         default:
199                 return(DM_FALSE);
200         }
201         return(DM_TRUE);
202 }
203
204
205 /* Veritas uses a dev_t for their dm_fsid_t, and named their routines
206    accordingly.  Hide this in the wrapper.  Note that a dev_t is 32 bits
207    and the SGI dm_fsid_t is defined to be a uint64_t.  If this gets to
208    be a problem (e.g. %x verus %llx), the Veritas dm_fsid_t could be made
209    to match SGI with a little casting here and there.
210 */
211
212 extern int
213 dm_handle_to_fsid(
214         void            *hanp,
215         size_t          hlen,
216         dm_fsid_t       *fsidp)
217 {
218         dev_t           dev;
219
220         dev = dm_handle_to_dev(hanp, hlen);
221         *fsidp = (dm_fsid_t)dev;
222         return(0);
223 }
224
225
226 /* The Veritas dm_handle_to_fgen returns a long which is really the
227    file's generation number.  dm_igen_t is typedef'd to be a long also,
228    so the cast here is safe.
229 */
230
231 extern int
232 dm_handle_to_igen(
233         void            *hanp,
234         size_t          hlen,
235         dm_igen_t       *igenp)
236 {
237 #undef  dm_handle_to_igen
238         long            igen;
239
240         igen = (dm_igen_t)dm_handle_to_fgen(hanp, hlen);
241         *igenp = (dm_igen_t)igen;
242         return(0);
243 }
244
245
246 /* Veritas uses a long for their dm_ino_t, which is really an ino_t.
247    Hide this in the wrapper.  Note that a ino_t is 32 bits and the SGI
248    dm_ino_t is defined to be a uint64_t.  If this gets to be a problem
249    (e.g. %x verus %llx), the Veritas dm_ino_t could be made to match SGI
250    with a little casting here and there.
251 */
252
253
254 extern int
255 xvfs_dm_handle_to_ino(
256         void            *hanp,
257         size_t          hlen,
258         dm_ino_t        *inop)
259 {
260 #undef  dm_handle_to_ino
261         long            ino;
262
263         ino = (dm_ino_t)dm_handle_to_ino(hanp, hlen);
264         *inop = (dm_ino_t)ino;
265         return(0);
266 }
267
268
269 /* Version 2.1 of the spec did not specify the versionstrpp parameter.  This
270    code makes the routine appear to work correctly to the caller, but it
271    is not really able to do the runtime check that the parameter is
272    supposed to provide.
273 */
274
275 extern int
276 xvfs_dm_init_service(
277         char            **versionstrpp)
278 {
279 #undef  dm_init_service
280         *versionstrpp = DM_VER_STR_CONTENTS;
281         return(dm_init_service());
282 }
283
284
285 extern int
286 xvfs_dm_make_fshandle(
287         dm_fsid_t       *fsidp,
288         void            **hanpp,
289         size_t    *hlenp)
290 {
291 #undef  dm_make_fshandle
292         dev_t           dev;
293
294         dev = (dev_t)*fsidp;
295         return(dm_make_fshandle(dev, hanpp, hlenp));
296 }
297
298
299 extern int
300 xvfs_dm_make_handle(
301         dm_fsid_t       *fsidp,
302         dm_ino_t        *inop,
303         dm_igen_t       *igenp,
304         void            **hanpp,
305         size_t    *hlenp)
306 {
307 #undef  dm_make_handle
308         dev_t           dev;
309         long            ino;
310         long            igen;
311
312         dev = (dev_t)*fsidp;
313         ino = (long)*inop;
314         igen = (long)*igenp;
315         return(dm_make_handle(dev, ino, igen, hanpp, hlenp));
316 }
317
318
319 /* The last byte in a Veritas handle is a 'pad' byte which they don't bother
320    to initialize to zero.  As a result, you can't do binary compares of
321    two handles to see if they are the same.  This stub (along with others)
322    forces the pad byte to zero so that binary compares are possible
323 */
324
325 extern int
326 xvfs_dm_path_to_fshandle(
327         char            *path,
328         void            **fshanpp,
329         size_t          *fshlenp)
330 {
331 #undef  dm_path_to_fshandle
332         int             rc;
333
334         if ((rc = dm_path_to_fshandle(path, fshanpp, fshlenp)) == 0) {
335                 if (*fshlenp == 16) {
336                         char    *cp = (char *)*fshanpp;
337                         cp[15] = '\0';
338                 }
339         }
340         return(rc);
341 }
342
343
344 /* The last byte in a Veritas handle is a 'pad' byte which they don't bother
345    to initialize to zero.  As a result, you can't do binary compares of
346    two handles to see if they are the same.  This stub (along with others)
347    forces the pad byte to zero so that binary compares are possible
348 */
349
350 extern int
351 xvfs_dm_path_to_handle(
352         char            *path,
353         void            **hanpp,
354         size_t          *hlenp)
355 {
356 #undef  dm_path_to_handle
357         int             rc;
358
359         if ((rc = dm_path_to_handle(path, hanpp, hlenp)) == 0) {
360                 if (*hlenp == 16) {
361                         char    *cp = (char *)*hanpp;
362                         cp[15] = '\0';
363                 }
364         }
365         return(rc);
366 }
367
368
369 /* Veritas has a prototype for this function even though it is not
370    implemented.
371 */
372
373 extern int
374 xvfs_dm_pending(
375         dm_sessid_t     sid,
376         dm_token_t      token,
377         dm_timestruct_t *delay)
378 {
379 #undef  dm_pending
380         return(ENOSYS);
381 }
382
383
384 extern int
385 xvfs_dm_read_invis(
386         dm_sessid_t     sid,
387         void            *hanp,
388         size_t          hlen,
389         dm_token_t      token,
390         dm_off_t        off,
391         dm_size_t       len,
392         void            *bufp)
393 {
394 #undef  dm_read_invis
395         return(dm_read_invis(sid, hanp, hlen, token, off, (dm_ssize_t)len, bufp));
396 }
397
398
399 /* In version 2.1 uflags was defined as 'int nowait', so a value of zero in
400    this field means that the caller wants to wait.  In XDSM this was reversed,
401    where if the bottom bit of uflags is set then the caller wants to wait.
402    This routine makes the conversion.
403 */
404
405 extern int
406 xvfs_dm_request_right(
407         dm_sessid_t     sid,
408         void            *hanp,
409         size_t          hlen,
410         dm_token_t      token,
411         u_int           uflags,
412         dm_right_t      right)
413 {
414 #undef  dm_request_right
415         int     nowait = 1;
416
417         if (uflags & DM_RR_WAIT)
418                 nowait = 0;
419         return(dm_request_right(sid, hanp, hlen, token, nowait, right));
420 }
421
422
423 extern int
424 xvfs_dm_set_inherit(
425         dm_sessid_t     sid,
426         void            *hanp,
427         size_t          hlen,
428         dm_token_t      token,
429         dm_attrname_t   *attrnamep,
430         mode_t          mode)
431 {
432 #undef  dm_set_inherit
433         return(dm_set_inherit(sid, hanp, hlen, token, attrnamep, (u_int)mode));
434 }
435
436
437 extern int
438 xvfs_dm_set_region(
439         dm_sessid_t     sid,
440         void            *hanp,
441         size_t          hlen,
442         dm_token_t      token,
443         u_int           nelem,
444         dm_region_t     *regbufp,
445         dm_boolean_t    *exactflagp)
446 {
447 #undef  dm_set_region
448         return(dm_set_region(sid, hanp, hlen, token, nelem, regbufp, (u_int *)exactflagp));
449 }
450
451
452 extern int
453 dm_set_return_on_destroy(
454         dm_sessid_t     sid,
455         void            *hanp,
456         size_t          hlen,
457         dm_token_t      token,
458         dm_attrname_t   *attrnamep,
459         dm_boolean_t    enable)
460 {
461         return(dm_set_return_ondestroy(sid, hanp, hlen, token,  attrnamep, (int)enable));
462 }
463
464
465 extern int
466 xvfs_dm_sync_by_handle(
467         dm_sessid_t     sid,
468         void            *hanp,
469         size_t          hlen,
470         dm_token_t      token)
471 {
472 #undef  dm_sync_by_handle
473         return((int)dm_sync_by_handle(sid, hanp, hlen, token));
474 }
475
476 extern int
477 xvfs_dm_upgrade_right(
478         dm_sessid_t     sid,
479         void            *hanp,
480         size_t          hlen,
481         dm_token_t      token)
482 {
483 #undef  dm_upgrade_right
484         return(dm_upgrade_right(sid, hanp, hlen, token, 0, DM_RIGHT_EXCL));
485 }
486
487
488 extern int
489 xvfs_dm_write_invis(
490         dm_sessid_t     sid,
491         void            *hanp,
492         size_t          hlen,
493         dm_token_t      token,
494         int             flags,
495         dm_off_t        off,
496         dm_size_t       len,
497         void            *bufp)
498 {
499 #undef  dm_write_invis
500         return(dm_write_invis(sid, hanp, hlen, token, off, (dm_ssize_t)len, bufp, flags));
501 }
502
503 #endif