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