2 * Copyright 2000, International Business Machines Corporation and others.
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
10 #include <afsconfig.h>
11 #include <afs/param.h>
15 #include <afs/afs_consts.h>
17 #include <afs/afsint.h>
18 #include <afs/venus.h>
25 * We deal with converting pioctl parameters between host and network order.
26 * Painful but somebody has to do this and pioctl is the best place rather than
27 * leaving it to the calling application programs!
36 struct AclEntry
*pluslist
;
37 struct AclEntry
*minuslist
;
41 struct AclEntry
*next
;
50 afs_int32 BeginTimestamp
;
51 afs_int32 EndTimestamp
;
67 int nplus
, nminus
, i
, trights
;
69 struct AclEntry
*first
, *last
, *tl
;
71 sscanf(astr
, "%d", &nplus
);
72 astr
= RSkipLine(astr
);
73 sscanf(astr
, "%d", &nminus
);
74 astr
= RSkipLine(astr
);
76 ta
= malloc(sizeof(struct Acl
));
82 for (i
= 0; i
< nplus
; i
++) {
83 sscanf(astr
, "%100s %d", tname
, &trights
);
84 astr
= RSkipLine(astr
);
85 tl
= malloc(sizeof(struct AclEntry
));
88 strcpy(tl
->name
, tname
);
99 for (i
= 0; i
< nminus
; i
++) {
100 sscanf(astr
, "%100s %d", tname
, &trights
);
101 astr
= RSkipLine(astr
);
102 tl
= malloc(sizeof(struct AclEntry
));
105 strcpy(tl
->name
, tname
);
106 tl
->rights
= trights
;
112 ta
->minuslist
= first
;
119 RAclToString(struct Acl
*acl
, char *mydata
, int ntoh_conv
)
121 char tstring
[AFS_PIOCTL_MAXSIZE
];
124 /* No conversion needed since they're in network order in the first place */
125 sprintf(mydata
, "%d\n%d\n", acl
->nplus
, acl
->nminus
);
126 for (tp
= acl
->pluslist
; tp
; tp
= tp
->next
) {
127 sprintf(tstring
, "%s %d\n", tp
->name
, tp
->rights
);
128 strcat(mydata
, tstring
);
130 for (tp
= acl
->minuslist
; tp
; tp
= tp
->next
) {
131 sprintf(tstring
, "%s %d\n", tp
->name
, tp
->rights
);
132 strcat(mydata
, tstring
);
137 /* Free all malloced stuff */
139 RCleanAcl(struct Acl
*aa
)
141 struct AclEntry
*te
, *ne
;
143 for (te
= aa
->pluslist
; te
; te
= ne
) {
147 for (te
= aa
->minuslist
; te
; te
= ne
) {
156 RFetchVolumeStatus_conversion(char *data
, int ntoh_conv
)
158 struct AFSFetchVolumeStatus
*status
= (AFSFetchVolumeStatus
*) data
;
160 if (ntoh_conv
) { /* Network -> Host */
161 status
->Vid
= ntohl(status
->Vid
);
162 status
->ParentId
= ntohl(status
->ParentId
);
165 status
->OnLine
= status
->OnLine
;
166 status
->InService
= status
->InService
;
167 status
->Blessed
= status
->Blessed
;
168 status
->NeedsSalvage
= status
->NeedsSalvage
;
170 status
->Type
= ntohl(status
->Type
);
171 status
->MinQuota
= ntohl(status
->MinQuota
);
172 status
->MaxQuota
= ntohl(status
->MaxQuota
);
173 status
->BlocksInUse
= ntohl(status
->BlocksInUse
);
174 status
->PartBlocksAvail
= ntohl(status
->PartBlocksAvail
);
175 status
->PartMaxBlocks
= ntohl(status
->PartMaxBlocks
);
176 } else { /* Host -> Network */
177 status
->Vid
= htonl(status
->Vid
);
178 status
->ParentId
= htonl(status
->ParentId
);
181 status
->OnLine
= status
->OnLine
;
182 status
->InService
= status
->InService
;
183 status
->Blessed
= status
->Blessed
;
184 status
->NeedsSalvage
= status
->NeedsSalvage
;
186 status
->Type
= htonl(status
->Type
);
187 status
->MinQuota
= htonl(status
->MinQuota
);
188 status
->MaxQuota
= htonl(status
->MaxQuota
);
189 status
->BlocksInUse
= htonl(status
->BlocksInUse
);
190 status
->PartBlocksAvail
= htonl(status
->PartBlocksAvail
);
191 status
->PartMaxBlocks
= htonl(status
->PartMaxBlocks
);
196 RClearToken_convert(char *ptr
, int ntoh_conv
)
198 struct ClearToken
*ticket
= (struct ClearToken
*)ptr
;
200 if (ntoh_conv
) { /* Network -> host */
201 ticket
->AuthHandle
= ntohl(ticket
->AuthHandle
);
202 ticket
->ViceId
= ntohl(ticket
->ViceId
);
203 ticket
->BeginTimestamp
= ntohl(ticket
->BeginTimestamp
);
204 ticket
->EndTimestamp
= ntohl(ticket
->EndTimestamp
);
205 } else { /* Host -> Network */
206 ticket
->AuthHandle
= htonl(ticket
->AuthHandle
);
207 ticket
->ViceId
= htonl(ticket
->ViceId
);
208 ticket
->BeginTimestamp
= htonl(ticket
->BeginTimestamp
);
209 ticket
->EndTimestamp
= htonl(ticket
->EndTimestamp
);
214 inparam_conversion(afs_int32 cmd
, char *buffer
, afs_int32 ntoh_conv
)
220 switch (cmd
& 0xffff) {
221 case VIOCSETAL
& 0xffff:
222 acl
= RParseAcl(buffer
);
223 RAclToString(acl
, buffer
, ntoh_conv
);
226 case VIOCSETTOK
& 0xffff:
227 lptr
= (afs_int32
*) buffer
;
228 /* i is sizeof of the secret ticket */
238 ptr
+= i
; /* skip over the ticket */
239 lptr
= (afs_int32
*) ptr
;
240 /* i is now size of the clear token */
250 RClearToken_convert(ptr
, ntoh_conv
);
251 ptr
+= i
; /* sizeof(struct ClearToken) */
252 lptr
= (afs_int32
*) ptr
;
254 *lptr
= ntohl(*lptr
);
256 *lptr
= htonl(*lptr
);
257 lptr
++; /* primary flag */
259 case VIOCSETVOLSTAT
& 0xffff:
260 RFetchVolumeStatus_conversion(buffer
, ntoh_conv
);
262 case VIOCGETTOK
& 0xffff:
263 case VIOCCKSERV
& 0xffff:
264 case VIOCACCESS
& 0xffff:
265 case VIOCSETCACHESIZE
& 0xffff:
266 case VIOCGETCELL
& 0xffff:
267 case VIOC_AFS_MARINER_HOST
& 0xffff:
268 case VIOC_VENUSLOG
& 0xffff:
269 case VIOC_AFS_SYSNAME
& 0xffff:
270 case VIOC_EXPORTAFS
& 0xffff:
271 lptr
= (afs_int32
*) buffer
;
273 *lptr
= ntohl(*lptr
);
275 *lptr
= htonl(*lptr
);
277 case VIOC_SETCELLSTATUS
& 0xffff:
278 lptr
= (afs_int32
*) buffer
;
280 *lptr
= ntohl(*lptr
);
282 *lptr
= htonl(*lptr
);
285 *lptr
= ntohl(*lptr
);
287 *lptr
= htonl(*lptr
);
289 case VIOCGETAL
& 0xffff:
290 case VIOCGETVOLSTAT
& 0xffff:
291 case VIOCGETCACHEPARMS
& 0xffff:
292 case VIOCFLUSH
& 0xffff:
293 case VIOCSTAT
& 0xffff:
294 case VIOCUNLOG
& 0xffff:
295 case VIOCCKBACK
& 0xffff:
296 case VIOCCKCONN
& 0xffff:
297 case VIOCGETTIME
& 0xffff: /* Obsolete */
298 case VIOCWHEREIS
& 0xffff:
299 case VIOCPREFETCH
& 0xffff:
300 case VIOCNOP
& 0xffff: /* Obsolete */
301 case VIOCENGROUP
& 0xffff: /* Obsolete */
302 case VIOCDISGROUP
& 0xffff: /* Obsolete */
303 case VIOCLISTGROUPS
& 0xffff: /* Obsolete */
304 case VIOCUNPAG
& 0xffff:
305 case VIOCWAITFOREVER
& 0xffff: /* Obsolete */
306 case VIOCFLUSHCB
& 0xffff:
307 case VIOCNEWCELL
& 0xffff:
308 case VIOC_AFS_DELETE_MT_PT
& 0xffff:
309 case VIOC_AFS_STAT_MT_PT
& 0xffff:
310 case VIOC_FILE_CELL_NAME
& 0xffff:
311 case VIOC_GET_WS_CELL
& 0xffff:
312 case VIOC_GET_PRIMARY_CELL
& 0xffff:
313 case VIOC_GETCELLSTATUS
& 0xffff:
314 case VIOC_FLUSHVOLUME
& 0xffff:
315 case VIOCGETFID
& 0xffff: /* nothing yet */
318 /* Note that new pioctls are supposed to be in network order! */
325 outparam_conversion(afs_int32 cmd
, char *buffer
, afs_int32 ntoh_conv
)
331 switch (cmd
& 0xffff) {
332 case VIOCGETAL
& 0xffff:
333 acl
= RParseAcl(buffer
);
334 RAclToString(acl
, buffer
, ntoh_conv
);
337 case VIOCGETVOLSTAT
& 0xffff:
338 RFetchVolumeStatus_conversion(buffer
, ntoh_conv
);
340 case VIOCSETVOLSTAT
& 0xffff:
341 RFetchVolumeStatus_conversion(buffer
, ntoh_conv
);
343 case VIOCGETTOK
& 0xffff:
344 lptr
= (afs_int32
*) buffer
;
345 /* i is set to sizeof secret ticket */
355 ptr
+= i
; /* skip over the ticket */
356 lptr
= (afs_int32
*) ptr
;
357 /* i is set to sizeof clear ticket */
367 RClearToken_convert(ptr
, ntoh_conv
);
368 ptr
+= i
; /* sizeof(struct ClearToken) */
369 lptr
= (afs_int32
*) ptr
;
371 *lptr
= ntohl(*lptr
);
373 *lptr
= htonl(*lptr
);
374 lptr
++; /* primary flag */
376 case VIOCCKCONN
& 0xffff:
377 case VIOC_AFS_MARINER_HOST
& 0xffff:
378 case VIOC_VENUSLOG
& 0xffff:
379 case VIOC_GETCELLSTATUS
& 0xffff:
380 case VIOC_AFS_SYSNAME
& 0xffff:
381 case VIOC_EXPORTAFS
& 0xffff:
382 lptr
= (afs_int32
*) buffer
;
384 *lptr
= ntohl(*lptr
);
386 *lptr
= htonl(*lptr
);
388 case VIOCGETCACHEPARMS
& 0xffff:
389 lptr
= (afs_int32
*) buffer
;
390 for (i
= 0; i
< MAXGCSIZE
; i
++, lptr
++) {
392 *lptr
= ntohl(*lptr
);
394 *lptr
= htonl(*lptr
);
397 case VIOCUNLOG
& 0xffff:
398 case VIOCCKSERV
& 0xffff: /* Already in network order */
399 case VIOCCKBACK
& 0xffff:
400 case VIOCGETTIME
& 0xffff: /* Obsolete */
401 case VIOCWHEREIS
& 0xffff: /* Already in network order */
402 case VIOCPREFETCH
& 0xffff:
403 case VIOCNOP
& 0xffff: /* Obsolete */
404 case VIOCENGROUP
& 0xffff: /* Obsolete */
405 case VIOCDISGROUP
& 0xffff: /* Obsolete */
406 case VIOCLISTGROUPS
& 0xffff: /* Obsolete */
407 case VIOCACCESS
& 0xffff:
408 case VIOCUNPAG
& 0xffff:
409 case VIOCWAITFOREVER
& 0xffff: /* Obsolete */
410 case VIOCSETCACHESIZE
& 0xffff:
411 case VIOCFLUSHCB
& 0xffff:
412 case VIOCNEWCELL
& 0xffff:
413 case VIOCGETCELL
& 0xffff: /* Already in network order */
414 case VIOC_AFS_DELETE_MT_PT
& 0xffff:
415 case VIOC_AFS_STAT_MT_PT
& 0xffff:
416 case VIOC_FILE_CELL_NAME
& 0xffff: /* no need to convert */
417 case VIOC_GET_WS_CELL
& 0xffff: /* no need to convert */
418 case VIOCGETFID
& 0xffff: /* nothing yet */
419 case VIOCSETAL
& 0xffff:
420 case VIOCFLUSH
& 0xffff:
421 case VIOCSTAT
& 0xffff:
422 case VIOCSETTOK
& 0xffff:
423 case VIOC_GET_PRIMARY_CELL
& 0xffff: /* The cell is returned here */
424 case VIOC_SETCELLSTATUS
& 0xffff:
425 case VIOC_FLUSHVOLUME
& 0xffff:
428 /* Note that new pioctls are supposed to be in network order! */