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>
28 #include <afs/afsint.h>
29 #include <afs/venus.h>
35 * We deal with converting pioctl parameters between host and network order.
36 * Painful but somebody has to do this and pioctl is the best place rather than
37 * leaving it to the calling application programs!
42 #define MAXHOSTS 8 /* XXX HARD Limit limitation XXX */
48 struct AclEntry *pluslist;
49 struct AclEntry *minuslist;
53 struct AclEntry *next;
62 afs_int32 BeginTimestamp;
63 afs_int32 EndTimestamp;
66 char *RSkipLine (astr)
67 register char *astr; {
68 while (*astr !='\n') astr++;
74 struct Acl *RParseAcl(astr)
76 int nplus, nminus, i, trights;
78 struct AclEntry *first, *last, *tl;
80 sscanf(astr, "%d", &nplus);
81 astr = RSkipLine(astr);
82 sscanf(astr, "%d", &nminus);
83 astr = RSkipLine(astr);
85 ta = (struct Acl *) malloc (sizeof (struct Acl));
91 for(i=0;i<nplus;i++) {
92 sscanf(astr, "%100s %d", tname, &trights);
93 astr = RSkipLine(astr);
94 tl = (struct AclEntry *) malloc(sizeof (struct AclEntry));
95 if (!first) first = tl;
96 strcpy(tl->name, tname);
99 if (last) last->next = tl;
102 ta->pluslist = first;
106 for(i=0;i<nminus;i++) {
107 sscanf(astr, "%100s %d", tname, &trights);
108 astr = RSkipLine(astr);
109 tl = (struct AclEntry *) malloc(sizeof (struct AclEntry));
110 if (!first) first = tl;
111 strcpy(tl->name, tname);
112 tl->rights = trights;
114 if (last) last->next = tl;
117 ta->minuslist = first;
123 RAclToString(acl, mydata, ntoh_conv)
127 char tstring[MAXSIZE];
130 /* No conversion needed since they're in network order in the first place */
131 sprintf(mydata, "%d\n%d\n", acl->nplus, acl->nminus);
132 for(tp = acl->pluslist;tp;tp=tp->next) {
133 sprintf(tstring, "%s %d\n", tp->name, tp->rights);
134 strcat(mydata, tstring);
136 for(tp = acl->minuslist;tp;tp=tp->next) {
137 sprintf(tstring, "%s %d\n", tp->name, tp->rights);
138 strcat(mydata, tstring);
143 /* Free all malloced stuff */
146 register struct AclEntry *te, *ne;
148 for(te = aa->pluslist; te; te=ne) {
152 for(te = aa->minuslist; te; te=ne) {
160 RFetchVolumeStatus_conversion(data, ntoh_conv)
164 struct AFSFetchVolumeStatus *status = (AFSFetchVolumeStatus *)data;
166 if (ntoh_conv) { /* Network -> Host */
167 status->Vid = ntohl(status->Vid);
168 status->ParentId = ntohl(status->ParentId);
171 status->OnLine = status->OnLine;
172 status->InService = status->InService;
173 status->Blessed = status->Blessed;
174 status->NeedsSalvage = status->NeedsSalvage;
176 status->Type = ntohl(status->Type);
177 status->MinQuota = ntohl(status->MinQuota);
178 status->MaxQuota = ntohl(status->MaxQuota);
179 status->BlocksInUse = ntohl(status->BlocksInUse);
180 status->PartBlocksAvail = ntohl(status->PartBlocksAvail);
181 status->PartMaxBlocks = ntohl(status->PartMaxBlocks);
182 } else { /* Host -> Network */
183 status->Vid = htonl(status->Vid);
184 status->ParentId = htonl(status->ParentId);
187 status->OnLine = status->OnLine;
188 status->InService = status->InService;
189 status->Blessed = status->Blessed;
190 status->NeedsSalvage = status->NeedsSalvage;
192 status->Type = htonl(status->Type);
193 status->MinQuota = htonl(status->MinQuota);
194 status->MaxQuota = htonl(status->MaxQuota);
195 status->BlocksInUse = htonl(status->BlocksInUse);
196 status->PartBlocksAvail = htonl(status->PartBlocksAvail);
197 status->PartMaxBlocks = htonl(status->PartMaxBlocks);
201 RClearToken_convert(ptr, ntoh_conv)
205 struct ClearToken *ticket = (struct ClearToken *)ptr;
207 if (ntoh_conv) { /* Network -> host */
208 ticket->AuthHandle = ntohl(ticket->AuthHandle);
209 ticket->ViceId = ntohl(ticket->ViceId);
210 ticket->BeginTimestamp = ntohl(ticket->BeginTimestamp);
211 ticket->EndTimestamp = ntohl(ticket->EndTimestamp);
212 } else { /* Host -> Network */
213 ticket->AuthHandle = htonl(ticket->AuthHandle);
214 ticket->ViceId = htonl(ticket->ViceId);
215 ticket->BeginTimestamp = htonl(ticket->BeginTimestamp);
216 ticket->EndTimestamp = htonl(ticket->EndTimestamp);
220 inparam_conversion(cmd, buffer, ntoh_conv)
221 afs_int32 cmd, ntoh_conv;
228 switch (cmd & 0xffff) {
229 case VIOCSETAL & 0xffff:
230 acl = RParseAcl(buffer);
231 RAclToString(acl, buffer, ntoh_conv);
234 case VIOCSETTOK & 0xffff:
235 lptr = (afs_int32 *)buffer;
236 /* i is sizeof of the secret ticket */
246 ptr += i; /* skip over the ticket */
247 lptr = (afs_int32 *)ptr;
248 /* i is now size of the clear token */
258 RClearToken_convert(ptr, ntoh_conv);
259 ptr += i; /* sizeof(struct ClearToken) */
260 lptr = (afs_int32 *)ptr;
262 *lptr = ntohl(*lptr);
264 *lptr = htonl(*lptr);
265 lptr++; /* primary flag */
267 case VIOCSETVOLSTAT & 0xffff:
268 RFetchVolumeStatus_conversion(buffer, ntoh_conv);
270 case VIOCGETTOK & 0xffff:
271 lptr = (afs_int32 *)buffer;
273 *lptr = ntohl(*lptr);
275 *lptr = htonl(*lptr);
277 case VIOCCKSERV & 0xffff:
278 lptr = (afs_int32 *)buffer;
280 *lptr = ntohl(*lptr);
282 *lptr = htonl(*lptr);
284 case VIOCACCESS & 0xffff:
285 lptr = (afs_int32 *)buffer;
287 *lptr = ntohl(*lptr);
289 *lptr = htonl(*lptr);
291 case VIOCSETCACHESIZE & 0xffff:
292 lptr = (afs_int32 *)buffer;
294 *lptr = ntohl(*lptr);
296 *lptr = htonl(*lptr);
298 case VIOCGETCELL & 0xffff:
299 lptr = (afs_int32 *)buffer;
301 *lptr = ntohl(*lptr);
303 *lptr = htonl(*lptr);
305 case VIOC_AFS_MARINER_HOST & 0xffff:
306 lptr = (afs_int32 *)buffer;
308 *lptr = ntohl(*lptr);
310 *lptr = htonl(*lptr);
312 case VIOC_VENUSLOG & 0xffff:
313 lptr = (afs_int32 *)buffer;
315 *lptr = ntohl(*lptr);
317 *lptr = htonl(*lptr);
319 case VIOC_SETCELLSTATUS & 0xffff:
320 lptr = (afs_int32 *)buffer;
322 *lptr = ntohl(*lptr);
324 *lptr = htonl(*lptr);
327 *lptr = ntohl(*lptr);
329 *lptr = htonl(*lptr);
331 case VIOC_AFS_SYSNAME & 0xffff:
332 lptr = (afs_int32 *)buffer;
334 *lptr = ntohl(*lptr);
336 *lptr = htonl(*lptr);
338 case VIOC_EXPORTAFS & 0xffff:
339 lptr = (afs_int32 *)buffer;
341 *lptr = ntohl(*lptr);
343 *lptr = htonl(*lptr);
345 case VIOCGETAL & 0xffff:
346 case VIOCGETVOLSTAT & 0xffff:
347 case VIOCGETCACHEPARMS & 0xffff:
348 case VIOCFLUSH & 0xffff:
349 case VIOCSTAT & 0xffff:
350 case VIOCUNLOG & 0xffff:
351 case VIOCCKBACK & 0xffff:
352 case VIOCCKCONN & 0xffff:
353 case VIOCGETTIME & 0xffff: /* Obsolete */
354 case VIOCWHEREIS & 0xffff:
355 case VIOCPREFETCH & 0xffff:
356 case VIOCNOP & 0xffff: /* Obsolete */
357 case VIOCENGROUP & 0xffff: /* Obsolete */
358 case VIOCDISGROUP & 0xffff: /* Obsolete */
359 case VIOCLISTGROUPS & 0xffff: /* Obsolete */
360 case VIOCUNPAG & 0xffff:
361 case VIOCWAITFOREVER & 0xffff: /* Obsolete */
362 case VIOCFLUSHCB & 0xffff:
363 case VIOCNEWCELL & 0xffff:
364 case VIOC_AFS_DELETE_MT_PT & 0xffff:
365 case VIOC_AFS_STAT_MT_PT & 0xffff:
366 case VIOC_FILE_CELL_NAME & 0xffff:
367 case VIOC_GET_WS_CELL & 0xffff:
368 case VIOC_GET_PRIMARY_CELL & 0xffff:
369 case VIOC_GETCELLSTATUS & 0xffff:
370 case VIOC_FLUSHVOLUME & 0xffff:
371 case VIOCGETFID & 0xffff: /* nothing yet */
374 /* Note that new pioctls are supposed to be in network order! */
380 outparam_conversion(cmd, buffer, ntoh_conv)
381 afs_int32 cmd, ntoh_conv;
388 switch (cmd & 0xffff) {
389 case VIOCGETAL & 0xffff:
390 acl = RParseAcl(buffer);
391 RAclToString(acl, buffer, ntoh_conv);
394 case VIOCGETVOLSTAT & 0xffff:
395 RFetchVolumeStatus_conversion(buffer, ntoh_conv);
397 case VIOCSETVOLSTAT & 0xffff:
398 RFetchVolumeStatus_conversion(buffer, ntoh_conv);
400 case VIOCGETTOK & 0xffff:
401 lptr = (afs_int32 *)buffer;
402 /* i is set to sizeof secret ticket */
412 ptr += i; /* skip over the ticket */
413 lptr = (afs_int32 *)ptr;
414 /* i is set to sizeof clear ticket */
424 RClearToken_convert(ptr, ntoh_conv);
425 ptr += i; /* sizeof(struct ClearToken) */
426 lptr = (afs_int32 *)ptr;
428 *lptr = ntohl(*lptr);
430 *lptr = htonl(*lptr);
431 lptr++; /* primary flag */
433 case VIOCCKCONN & 0xffff:
435 *lptr = ntohl(*lptr);
437 *lptr = htonl(*lptr);
439 case VIOC_AFS_MARINER_HOST & 0xffff:
440 lptr = (afs_int32 *)buffer;
442 *lptr = ntohl(*lptr);
444 *lptr = htonl(*lptr);
446 case VIOC_VENUSLOG & 0xffff:
447 lptr = (afs_int32 *)buffer;
449 *lptr = ntohl(*lptr);
451 *lptr = htonl(*lptr);
453 case VIOC_GETCELLSTATUS & 0xffff:
454 lptr = (afs_int32 *)buffer;
456 *lptr = ntohl(*lptr);
458 *lptr = htonl(*lptr);
460 case VIOC_AFS_SYSNAME & 0xffff:
461 lptr = (afs_int32 *)buffer;
463 *lptr = ntohl(*lptr);
465 *lptr = htonl(*lptr);
467 case VIOC_EXPORTAFS & 0xffff:
468 lptr = (afs_int32 *)buffer;
470 *lptr = ntohl(*lptr);
472 *lptr = htonl(*lptr);
474 case VIOCGETCACHEPARMS & 0xffff:
475 lptr = (afs_int32 *)buffer;
476 for (i=0; i < MAXGCSIZE; i++, lptr++) {
478 *lptr = ntohl(*lptr);
480 *lptr = htonl(*lptr);
483 case VIOCUNLOG & 0xffff:
484 case VIOCCKSERV & 0xffff: /* Already in network order */
485 case VIOCCKBACK & 0xffff:
486 case VIOCGETTIME & 0xffff: /* Obsolete */
487 case VIOCWHEREIS & 0xffff: /* Already in network order */
488 case VIOCPREFETCH & 0xffff:
489 case VIOCNOP & 0xffff: /* Obsolete */
490 case VIOCENGROUP & 0xffff: /* Obsolete */
491 case VIOCDISGROUP & 0xffff: /* Obsolete */
492 case VIOCLISTGROUPS & 0xffff: /* Obsolete */
493 case VIOCACCESS & 0xffff:
494 case VIOCUNPAG & 0xffff:
495 case VIOCWAITFOREVER & 0xffff: /* Obsolete */
496 case VIOCSETCACHESIZE & 0xffff:
497 case VIOCFLUSHCB & 0xffff:
498 case VIOCNEWCELL & 0xffff:
499 case VIOCGETCELL & 0xffff: /* Already in network order */
500 case VIOC_AFS_DELETE_MT_PT & 0xffff:
501 case VIOC_AFS_STAT_MT_PT & 0xffff:
502 case VIOC_FILE_CELL_NAME & 0xffff: /* no need to convert */
503 case VIOC_GET_WS_CELL & 0xffff: /* no need to convert */
504 case VIOCGETFID & 0xffff: /* nothing yet */
505 case VIOCSETAL & 0xffff:
506 case VIOCFLUSH & 0xffff:
507 case VIOCSTAT & 0xffff:
508 case VIOCSETTOK & 0xffff:
509 case VIOC_GET_PRIMARY_CELL & 0xffff: /* The cell is returned here */
510 case VIOC_SETCELLSTATUS & 0xffff:
511 case VIOC_FLUSHVOLUME & 0xffff:
514 /* Note that new pioctls are supposed to be in network order! */