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>
17 #include <sys/param.h>
18 #include <sys/types.h>
24 #include <netinet/in.h>
36 #include <afs/afsint.h>
37 #include <afs/venus.h>
43 * We deal with converting pioctl parameters between host and network order.
44 * Painful but somebody has to do this and pioctl is the best place rather than
45 * leaving it to the calling application programs!
50 #define MAXHOSTS 8 /* XXX HARD Limit limitation XXX */
56 struct AclEntry *pluslist;
57 struct AclEntry *minuslist;
61 struct AclEntry *next;
70 afs_int32 BeginTimestamp;
71 afs_int32 EndTimestamp;
89 int nplus, nminus, i, trights;
91 struct AclEntry *first, *last, *tl;
93 sscanf(astr, "%d", &nplus);
94 astr = RSkipLine(astr);
95 sscanf(astr, "%d", &nminus);
96 astr = RSkipLine(astr);
98 ta = (struct Acl *)malloc(sizeof(struct Acl));
104 for (i = 0; i < nplus; i++) {
105 sscanf(astr, "%100s %d", tname, &trights);
106 astr = RSkipLine(astr);
107 tl = (struct AclEntry *)malloc(sizeof(struct AclEntry));
110 strcpy(tl->name, tname);
111 tl->rights = trights;
117 ta->pluslist = first;
121 for (i = 0; i < nminus; i++) {
122 sscanf(astr, "%100s %d", tname, &trights);
123 astr = RSkipLine(astr);
124 tl = (struct AclEntry *)malloc(sizeof(struct AclEntry));
127 strcpy(tl->name, tname);
128 tl->rights = trights;
134 ta->minuslist = first;
141 RAclToString(struct Acl *acl, char *mydata, int ntoh_conv)
143 char tstring[MAXSIZE];
146 /* No conversion needed since they're in network order in the first place */
147 sprintf(mydata, "%d\n%d\n", acl->nplus, acl->nminus);
148 for (tp = acl->pluslist; tp; tp = tp->next) {
149 sprintf(tstring, "%s %d\n", tp->name, tp->rights);
150 strcat(mydata, tstring);
152 for (tp = acl->minuslist; tp; tp = tp->next) {
153 sprintf(tstring, "%s %d\n", tp->name, tp->rights);
154 strcat(mydata, tstring);
159 /* Free all malloced stuff */
161 RCleanAcl(struct Acl *aa)
163 register struct AclEntry *te, *ne;
165 for (te = aa->pluslist; te; te = ne) {
169 for (te = aa->minuslist; te; te = ne) {
178 RFetchVolumeStatus_conversion(char *data, int ntoh_conv)
180 struct AFSFetchVolumeStatus *status = (AFSFetchVolumeStatus *) data;
182 if (ntoh_conv) { /* Network -> Host */
183 status->Vid = ntohl(status->Vid);
184 status->ParentId = ntohl(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 = ntohl(status->Type);
193 status->MinQuota = ntohl(status->MinQuota);
194 status->MaxQuota = ntohl(status->MaxQuota);
195 status->BlocksInUse = ntohl(status->BlocksInUse);
196 status->PartBlocksAvail = ntohl(status->PartBlocksAvail);
197 status->PartMaxBlocks = ntohl(status->PartMaxBlocks);
198 } else { /* Host -> Network */
199 status->Vid = htonl(status->Vid);
200 status->ParentId = htonl(status->ParentId);
203 status->OnLine = status->OnLine;
204 status->InService = status->InService;
205 status->Blessed = status->Blessed;
206 status->NeedsSalvage = status->NeedsSalvage;
208 status->Type = htonl(status->Type);
209 status->MinQuota = htonl(status->MinQuota);
210 status->MaxQuota = htonl(status->MaxQuota);
211 status->BlocksInUse = htonl(status->BlocksInUse);
212 status->PartBlocksAvail = htonl(status->PartBlocksAvail);
213 status->PartMaxBlocks = htonl(status->PartMaxBlocks);
218 RClearToken_convert(char *ptr, int ntoh_conv)
220 struct ClearToken *ticket = (struct ClearToken *)ptr;
222 if (ntoh_conv) { /* Network -> host */
223 ticket->AuthHandle = ntohl(ticket->AuthHandle);
224 ticket->ViceId = ntohl(ticket->ViceId);
225 ticket->BeginTimestamp = ntohl(ticket->BeginTimestamp);
226 ticket->EndTimestamp = ntohl(ticket->EndTimestamp);
227 } else { /* Host -> Network */
228 ticket->AuthHandle = htonl(ticket->AuthHandle);
229 ticket->ViceId = htonl(ticket->ViceId);
230 ticket->BeginTimestamp = htonl(ticket->BeginTimestamp);
231 ticket->EndTimestamp = htonl(ticket->EndTimestamp);
236 inparam_conversion(afs_int32 cmd, char *buffer, afs_int32 ntoh_conv)
242 switch (cmd & 0xffff) {
243 case VIOCSETAL & 0xffff:
244 acl = RParseAcl(buffer);
245 RAclToString(acl, buffer, ntoh_conv);
248 case VIOCSETTOK & 0xffff:
249 lptr = (afs_int32 *) buffer;
250 /* i is sizeof of the secret ticket */
260 ptr += i; /* skip over the ticket */
261 lptr = (afs_int32 *) ptr;
262 /* i is now size of the clear token */
272 RClearToken_convert(ptr, ntoh_conv);
273 ptr += i; /* sizeof(struct ClearToken) */
274 lptr = (afs_int32 *) ptr;
276 *lptr = ntohl(*lptr);
278 *lptr = htonl(*lptr);
279 lptr++; /* primary flag */
281 case VIOCSETVOLSTAT & 0xffff:
282 RFetchVolumeStatus_conversion(buffer, ntoh_conv);
284 case VIOCGETTOK & 0xffff:
285 case VIOCCKSERV & 0xffff:
286 case VIOCACCESS & 0xffff:
287 case VIOCSETCACHESIZE & 0xffff:
288 case VIOCGETCELL & 0xffff:
289 case VIOC_AFS_MARINER_HOST & 0xffff:
290 case VIOC_VENUSLOG & 0xffff:
291 case VIOC_AFS_SYSNAME & 0xffff:
292 case VIOC_EXPORTAFS & 0xffff:
293 lptr = (afs_int32 *) buffer;
295 *lptr = ntohl(*lptr);
297 *lptr = htonl(*lptr);
299 case VIOC_SETCELLSTATUS & 0xffff:
300 lptr = (afs_int32 *) buffer;
302 *lptr = ntohl(*lptr);
304 *lptr = htonl(*lptr);
307 *lptr = ntohl(*lptr);
309 *lptr = htonl(*lptr);
311 case VIOCGETAL & 0xffff:
312 case VIOCGETVOLSTAT & 0xffff:
313 case VIOCGETCACHEPARMS & 0xffff:
314 case VIOCFLUSH & 0xffff:
315 case VIOCSTAT & 0xffff:
316 case VIOCUNLOG & 0xffff:
317 case VIOCCKBACK & 0xffff:
318 case VIOCCKCONN & 0xffff:
319 case VIOCGETTIME & 0xffff: /* Obsolete */
320 case VIOCWHEREIS & 0xffff:
321 case VIOCPREFETCH & 0xffff:
322 case VIOCNOP & 0xffff: /* Obsolete */
323 case VIOCENGROUP & 0xffff: /* Obsolete */
324 case VIOCDISGROUP & 0xffff: /* Obsolete */
325 case VIOCLISTGROUPS & 0xffff: /* Obsolete */
326 case VIOCUNPAG & 0xffff:
327 case VIOCWAITFOREVER & 0xffff: /* Obsolete */
328 case VIOCFLUSHCB & 0xffff:
329 case VIOCNEWCELL & 0xffff:
330 case VIOC_AFS_DELETE_MT_PT & 0xffff:
331 case VIOC_AFS_STAT_MT_PT & 0xffff:
332 case VIOC_FILE_CELL_NAME & 0xffff:
333 case VIOC_GET_WS_CELL & 0xffff:
334 case VIOC_GET_PRIMARY_CELL & 0xffff:
335 case VIOC_GETCELLSTATUS & 0xffff:
336 case VIOC_FLUSHVOLUME & 0xffff:
337 case VIOCGETFID & 0xffff: /* nothing yet */
340 /* Note that new pioctls are supposed to be in network order! */
347 outparam_conversion(afs_int32 cmd, char *buffer, afs_int32 ntoh_conv)
353 switch (cmd & 0xffff) {
354 case VIOCGETAL & 0xffff:
355 acl = RParseAcl(buffer);
356 RAclToString(acl, buffer, ntoh_conv);
359 case VIOCGETVOLSTAT & 0xffff:
360 RFetchVolumeStatus_conversion(buffer, ntoh_conv);
362 case VIOCSETVOLSTAT & 0xffff:
363 RFetchVolumeStatus_conversion(buffer, ntoh_conv);
365 case VIOCGETTOK & 0xffff:
366 lptr = (afs_int32 *) buffer;
367 /* i is set to sizeof secret ticket */
377 ptr += i; /* skip over the ticket */
378 lptr = (afs_int32 *) ptr;
379 /* i is set to sizeof clear ticket */
389 RClearToken_convert(ptr, ntoh_conv);
390 ptr += i; /* sizeof(struct ClearToken) */
391 lptr = (afs_int32 *) ptr;
393 *lptr = ntohl(*lptr);
395 *lptr = htonl(*lptr);
396 lptr++; /* primary flag */
398 case VIOCCKCONN & 0xffff:
399 case VIOC_AFS_MARINER_HOST & 0xffff:
400 case VIOC_VENUSLOG & 0xffff:
401 case VIOC_GETCELLSTATUS & 0xffff:
402 case VIOC_AFS_SYSNAME & 0xffff:
403 case VIOC_EXPORTAFS & 0xffff:
404 lptr = (afs_int32 *) buffer;
406 *lptr = ntohl(*lptr);
408 *lptr = htonl(*lptr);
410 case VIOCGETCACHEPARMS & 0xffff:
411 lptr = (afs_int32 *) buffer;
412 for (i = 0; i < MAXGCSIZE; i++, lptr++) {
414 *lptr = ntohl(*lptr);
416 *lptr = htonl(*lptr);
419 case VIOCUNLOG & 0xffff:
420 case VIOCCKSERV & 0xffff: /* Already in network order */
421 case VIOCCKBACK & 0xffff:
422 case VIOCGETTIME & 0xffff: /* Obsolete */
423 case VIOCWHEREIS & 0xffff: /* Already in network order */
424 case VIOCPREFETCH & 0xffff:
425 case VIOCNOP & 0xffff: /* Obsolete */
426 case VIOCENGROUP & 0xffff: /* Obsolete */
427 case VIOCDISGROUP & 0xffff: /* Obsolete */
428 case VIOCLISTGROUPS & 0xffff: /* Obsolete */
429 case VIOCACCESS & 0xffff:
430 case VIOCUNPAG & 0xffff:
431 case VIOCWAITFOREVER & 0xffff: /* Obsolete */
432 case VIOCSETCACHESIZE & 0xffff:
433 case VIOCFLUSHCB & 0xffff:
434 case VIOCNEWCELL & 0xffff:
435 case VIOCGETCELL & 0xffff: /* Already in network order */
436 case VIOC_AFS_DELETE_MT_PT & 0xffff:
437 case VIOC_AFS_STAT_MT_PT & 0xffff:
438 case VIOC_FILE_CELL_NAME & 0xffff: /* no need to convert */
439 case VIOC_GET_WS_CELL & 0xffff: /* no need to convert */
440 case VIOCGETFID & 0xffff: /* nothing yet */
441 case VIOCSETAL & 0xffff:
442 case VIOCFLUSH & 0xffff:
443 case VIOCSTAT & 0xffff:
444 case VIOCSETTOK & 0xffff:
445 case VIOC_GET_PRIMARY_CELL & 0xffff: /* The cell is returned here */
446 case VIOC_SETCELLSTATUS & 0xffff:
447 case VIOC_FLUSHVOLUME & 0xffff:
450 /* Note that new pioctls are supposed to be in network order! */