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>
16 #include <sys/param.h>
17 #include <sys/types.h>
23 #include <netinet/in.h>
35 #include <afs/afsint.h>
36 #include <afs/venus.h>
42 * We deal with converting pioctl parameters between host and network order.
43 * Painful but somebody has to do this and pioctl is the best place rather than
44 * leaving it to the calling application programs!
49 #define MAXHOSTS 8 /* XXX HARD Limit limitation XXX */
55 struct AclEntry *pluslist;
56 struct AclEntry *minuslist;
60 struct AclEntry *next;
69 afs_int32 BeginTimestamp;
70 afs_int32 EndTimestamp;
73 char *RSkipLine (astr)
74 register char *astr; {
75 while (*astr !='\n') astr++;
81 struct Acl *RParseAcl(astr)
83 int nplus, nminus, i, trights;
85 struct AclEntry *first, *last, *tl;
87 sscanf(astr, "%d", &nplus);
88 astr = RSkipLine(astr);
89 sscanf(astr, "%d", &nminus);
90 astr = RSkipLine(astr);
92 ta = (struct Acl *) malloc (sizeof (struct Acl));
98 for(i=0;i<nplus;i++) {
99 sscanf(astr, "%100s %d", tname, &trights);
100 astr = RSkipLine(astr);
101 tl = (struct AclEntry *) malloc(sizeof (struct AclEntry));
102 if (!first) first = tl;
103 strcpy(tl->name, tname);
104 tl->rights = trights;
106 if (last) last->next = tl;
109 ta->pluslist = first;
113 for(i=0;i<nminus;i++) {
114 sscanf(astr, "%100s %d", tname, &trights);
115 astr = RSkipLine(astr);
116 tl = (struct AclEntry *) malloc(sizeof (struct AclEntry));
117 if (!first) first = tl;
118 strcpy(tl->name, tname);
119 tl->rights = trights;
121 if (last) last->next = tl;
124 ta->minuslist = first;
130 RAclToString(acl, mydata, ntoh_conv)
134 char tstring[MAXSIZE];
137 /* No conversion needed since they're in network order in the first place */
138 sprintf(mydata, "%d\n%d\n", acl->nplus, acl->nminus);
139 for(tp = acl->pluslist;tp;tp=tp->next) {
140 sprintf(tstring, "%s %d\n", tp->name, tp->rights);
141 strcat(mydata, tstring);
143 for(tp = acl->minuslist;tp;tp=tp->next) {
144 sprintf(tstring, "%s %d\n", tp->name, tp->rights);
145 strcat(mydata, tstring);
150 /* Free all malloced stuff */
153 register struct AclEntry *te, *ne;
155 for(te = aa->pluslist; te; te=ne) {
159 for(te = aa->minuslist; te; te=ne) {
167 RFetchVolumeStatus_conversion(data, ntoh_conv)
171 struct AFSFetchVolumeStatus *status = (AFSFetchVolumeStatus *)data;
173 if (ntoh_conv) { /* Network -> Host */
174 status->Vid = ntohl(status->Vid);
175 status->ParentId = ntohl(status->ParentId);
178 status->OnLine = status->OnLine;
179 status->InService = status->InService;
180 status->Blessed = status->Blessed;
181 status->NeedsSalvage = status->NeedsSalvage;
183 status->Type = ntohl(status->Type);
184 status->MinQuota = ntohl(status->MinQuota);
185 status->MaxQuota = ntohl(status->MaxQuota);
186 status->BlocksInUse = ntohl(status->BlocksInUse);
187 status->PartBlocksAvail = ntohl(status->PartBlocksAvail);
188 status->PartMaxBlocks = ntohl(status->PartMaxBlocks);
189 } else { /* Host -> Network */
190 status->Vid = htonl(status->Vid);
191 status->ParentId = htonl(status->ParentId);
194 status->OnLine = status->OnLine;
195 status->InService = status->InService;
196 status->Blessed = status->Blessed;
197 status->NeedsSalvage = status->NeedsSalvage;
199 status->Type = htonl(status->Type);
200 status->MinQuota = htonl(status->MinQuota);
201 status->MaxQuota = htonl(status->MaxQuota);
202 status->BlocksInUse = htonl(status->BlocksInUse);
203 status->PartBlocksAvail = htonl(status->PartBlocksAvail);
204 status->PartMaxBlocks = htonl(status->PartMaxBlocks);
208 RClearToken_convert(ptr, ntoh_conv)
212 struct ClearToken *ticket = (struct ClearToken *)ptr;
214 if (ntoh_conv) { /* Network -> host */
215 ticket->AuthHandle = ntohl(ticket->AuthHandle);
216 ticket->ViceId = ntohl(ticket->ViceId);
217 ticket->BeginTimestamp = ntohl(ticket->BeginTimestamp);
218 ticket->EndTimestamp = ntohl(ticket->EndTimestamp);
219 } else { /* Host -> Network */
220 ticket->AuthHandle = htonl(ticket->AuthHandle);
221 ticket->ViceId = htonl(ticket->ViceId);
222 ticket->BeginTimestamp = htonl(ticket->BeginTimestamp);
223 ticket->EndTimestamp = htonl(ticket->EndTimestamp);
227 inparam_conversion(cmd, buffer, ntoh_conv)
228 afs_int32 cmd, ntoh_conv;
235 switch (cmd & 0xffff) {
236 case VIOCSETAL & 0xffff:
237 acl = RParseAcl(buffer);
238 RAclToString(acl, buffer, ntoh_conv);
241 case VIOCSETTOK & 0xffff:
242 lptr = (afs_int32 *)buffer;
243 /* i is sizeof of the secret ticket */
253 ptr += i; /* skip over the ticket */
254 lptr = (afs_int32 *)ptr;
255 /* i is now size of the clear token */
265 RClearToken_convert(ptr, ntoh_conv);
266 ptr += i; /* sizeof(struct ClearToken) */
267 lptr = (afs_int32 *)ptr;
269 *lptr = ntohl(*lptr);
271 *lptr = htonl(*lptr);
272 lptr++; /* primary flag */
274 case VIOCSETVOLSTAT & 0xffff:
275 RFetchVolumeStatus_conversion(buffer, ntoh_conv);
277 case VIOCGETTOK & 0xffff:
278 lptr = (afs_int32 *)buffer;
280 *lptr = ntohl(*lptr);
282 *lptr = htonl(*lptr);
284 case VIOCCKSERV & 0xffff:
285 lptr = (afs_int32 *)buffer;
287 *lptr = ntohl(*lptr);
289 *lptr = htonl(*lptr);
291 case VIOCACCESS & 0xffff:
292 lptr = (afs_int32 *)buffer;
294 *lptr = ntohl(*lptr);
296 *lptr = htonl(*lptr);
298 case VIOCSETCACHESIZE & 0xffff:
299 lptr = (afs_int32 *)buffer;
301 *lptr = ntohl(*lptr);
303 *lptr = htonl(*lptr);
305 case VIOCGETCELL & 0xffff:
306 lptr = (afs_int32 *)buffer;
308 *lptr = ntohl(*lptr);
310 *lptr = htonl(*lptr);
312 case VIOC_AFS_MARINER_HOST & 0xffff:
313 lptr = (afs_int32 *)buffer;
315 *lptr = ntohl(*lptr);
317 *lptr = htonl(*lptr);
319 case VIOC_VENUSLOG & 0xffff:
320 lptr = (afs_int32 *)buffer;
322 *lptr = ntohl(*lptr);
324 *lptr = htonl(*lptr);
326 case VIOC_SETCELLSTATUS & 0xffff:
327 lptr = (afs_int32 *)buffer;
329 *lptr = ntohl(*lptr);
331 *lptr = htonl(*lptr);
334 *lptr = ntohl(*lptr);
336 *lptr = htonl(*lptr);
338 case VIOC_AFS_SYSNAME & 0xffff:
339 lptr = (afs_int32 *)buffer;
341 *lptr = ntohl(*lptr);
343 *lptr = htonl(*lptr);
345 case VIOC_EXPORTAFS & 0xffff:
346 lptr = (afs_int32 *)buffer;
348 *lptr = ntohl(*lptr);
350 *lptr = htonl(*lptr);
352 case VIOCGETAL & 0xffff:
353 case VIOCGETVOLSTAT & 0xffff:
354 case VIOCGETCACHEPARMS & 0xffff:
355 case VIOCFLUSH & 0xffff:
356 case VIOCSTAT & 0xffff:
357 case VIOCUNLOG & 0xffff:
358 case VIOCCKBACK & 0xffff:
359 case VIOCCKCONN & 0xffff:
360 case VIOCGETTIME & 0xffff: /* Obsolete */
361 case VIOCWHEREIS & 0xffff:
362 case VIOCPREFETCH & 0xffff:
363 case VIOCNOP & 0xffff: /* Obsolete */
364 case VIOCENGROUP & 0xffff: /* Obsolete */
365 case VIOCDISGROUP & 0xffff: /* Obsolete */
366 case VIOCLISTGROUPS & 0xffff: /* Obsolete */
367 case VIOCUNPAG & 0xffff:
368 case VIOCWAITFOREVER & 0xffff: /* Obsolete */
369 case VIOCFLUSHCB & 0xffff:
370 case VIOCNEWCELL & 0xffff:
371 case VIOC_AFS_DELETE_MT_PT & 0xffff:
372 case VIOC_AFS_STAT_MT_PT & 0xffff:
373 case VIOC_FILE_CELL_NAME & 0xffff:
374 case VIOC_GET_WS_CELL & 0xffff:
375 case VIOC_GET_PRIMARY_CELL & 0xffff:
376 case VIOC_GETCELLSTATUS & 0xffff:
377 case VIOC_FLUSHVOLUME & 0xffff:
378 case VIOCGETFID & 0xffff: /* nothing yet */
381 /* Note that new pioctls are supposed to be in network order! */
387 outparam_conversion(cmd, buffer, ntoh_conv)
388 afs_int32 cmd, ntoh_conv;
395 switch (cmd & 0xffff) {
396 case VIOCGETAL & 0xffff:
397 acl = RParseAcl(buffer);
398 RAclToString(acl, buffer, ntoh_conv);
401 case VIOCGETVOLSTAT & 0xffff:
402 RFetchVolumeStatus_conversion(buffer, ntoh_conv);
404 case VIOCSETVOLSTAT & 0xffff:
405 RFetchVolumeStatus_conversion(buffer, ntoh_conv);
407 case VIOCGETTOK & 0xffff:
408 lptr = (afs_int32 *)buffer;
409 /* i is set to sizeof secret ticket */
419 ptr += i; /* skip over the ticket */
420 lptr = (afs_int32 *)ptr;
421 /* i is set to sizeof clear ticket */
431 RClearToken_convert(ptr, ntoh_conv);
432 ptr += i; /* sizeof(struct ClearToken) */
433 lptr = (afs_int32 *)ptr;
435 *lptr = ntohl(*lptr);
437 *lptr = htonl(*lptr);
438 lptr++; /* primary flag */
440 case VIOCCKCONN & 0xffff:
442 *lptr = ntohl(*lptr);
444 *lptr = htonl(*lptr);
446 case VIOC_AFS_MARINER_HOST & 0xffff:
447 lptr = (afs_int32 *)buffer;
449 *lptr = ntohl(*lptr);
451 *lptr = htonl(*lptr);
453 case VIOC_VENUSLOG & 0xffff:
454 lptr = (afs_int32 *)buffer;
456 *lptr = ntohl(*lptr);
458 *lptr = htonl(*lptr);
460 case VIOC_GETCELLSTATUS & 0xffff:
461 lptr = (afs_int32 *)buffer;
463 *lptr = ntohl(*lptr);
465 *lptr = htonl(*lptr);
467 case VIOC_AFS_SYSNAME & 0xffff:
468 lptr = (afs_int32 *)buffer;
470 *lptr = ntohl(*lptr);
472 *lptr = htonl(*lptr);
474 case VIOC_EXPORTAFS & 0xffff:
475 lptr = (afs_int32 *)buffer;
477 *lptr = ntohl(*lptr);
479 *lptr = htonl(*lptr);
481 case VIOCGETCACHEPARMS & 0xffff:
482 lptr = (afs_int32 *)buffer;
483 for (i=0; i < MAXGCSIZE; i++, lptr++) {
485 *lptr = ntohl(*lptr);
487 *lptr = htonl(*lptr);
490 case VIOCUNLOG & 0xffff:
491 case VIOCCKSERV & 0xffff: /* Already in network order */
492 case VIOCCKBACK & 0xffff:
493 case VIOCGETTIME & 0xffff: /* Obsolete */
494 case VIOCWHEREIS & 0xffff: /* Already in network order */
495 case VIOCPREFETCH & 0xffff:
496 case VIOCNOP & 0xffff: /* Obsolete */
497 case VIOCENGROUP & 0xffff: /* Obsolete */
498 case VIOCDISGROUP & 0xffff: /* Obsolete */
499 case VIOCLISTGROUPS & 0xffff: /* Obsolete */
500 case VIOCACCESS & 0xffff:
501 case VIOCUNPAG & 0xffff:
502 case VIOCWAITFOREVER & 0xffff: /* Obsolete */
503 case VIOCSETCACHESIZE & 0xffff:
504 case VIOCFLUSHCB & 0xffff:
505 case VIOCNEWCELL & 0xffff:
506 case VIOCGETCELL & 0xffff: /* Already in network order */
507 case VIOC_AFS_DELETE_MT_PT & 0xffff:
508 case VIOC_AFS_STAT_MT_PT & 0xffff:
509 case VIOC_FILE_CELL_NAME & 0xffff: /* no need to convert */
510 case VIOC_GET_WS_CELL & 0xffff: /* no need to convert */
511 case VIOCGETFID & 0xffff: /* nothing yet */
512 case VIOCSETAL & 0xffff:
513 case VIOCFLUSH & 0xffff:
514 case VIOCSTAT & 0xffff:
515 case VIOCSETTOK & 0xffff:
516 case VIOC_GET_PRIMARY_CELL & 0xffff: /* The cell is returned here */
517 case VIOC_SETCELLSTATUS & 0xffff:
518 case VIOC_FLUSHVOLUME & 0xffff:
521 /* Note that new pioctls are supposed to be in network order! */