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>
30 #include <afs/afsint.h>
31 #include <afs/venus.h>
37 * We deal with converting pioctl parameters between host and network order.
38 * Painful but somebody has to do this and pioctl is the best place rather than
39 * leaving it to the calling application programs!
44 #define MAXHOSTS 8 /* XXX HARD Limit limitation XXX */
50 struct AclEntry *pluslist;
51 struct AclEntry *minuslist;
55 struct AclEntry *next;
64 afs_int32 BeginTimestamp;
65 afs_int32 EndTimestamp;
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));
104 strcpy(tl->name, tname);
105 tl->rights = trights;
111 ta->pluslist = first;
115 for (i = 0; i < nminus; i++) {
116 sscanf(astr, "%100s %d", tname, &trights);
117 astr = RSkipLine(astr);
118 tl = (struct AclEntry *)malloc(sizeof(struct AclEntry));
121 strcpy(tl->name, tname);
122 tl->rights = trights;
128 ta->minuslist = first;
135 RAclToString(struct Acl *acl, char *mydata, int ntoh_conv)
137 char tstring[MAXSIZE];
140 /* No conversion needed since they're in network order in the first place */
141 sprintf(mydata, "%d\n%d\n", acl->nplus, acl->nminus);
142 for (tp = acl->pluslist; tp; tp = tp->next) {
143 sprintf(tstring, "%s %d\n", tp->name, tp->rights);
144 strcat(mydata, tstring);
146 for (tp = acl->minuslist; tp; tp = tp->next) {
147 sprintf(tstring, "%s %d\n", tp->name, tp->rights);
148 strcat(mydata, tstring);
153 /* Free all malloced stuff */
155 RCleanAcl(struct Acl *aa)
157 register struct AclEntry *te, *ne;
159 for (te = aa->pluslist; te; te = ne) {
163 for (te = aa->minuslist; te; te = ne) {
172 RFetchVolumeStatus_conversion(char *data, int ntoh_conv)
174 struct AFSFetchVolumeStatus *status = (AFSFetchVolumeStatus *) data;
176 if (ntoh_conv) { /* Network -> Host */
177 status->Vid = ntohl(status->Vid);
178 status->ParentId = ntohl(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 = ntohl(status->Type);
187 status->MinQuota = ntohl(status->MinQuota);
188 status->MaxQuota = ntohl(status->MaxQuota);
189 status->BlocksInUse = ntohl(status->BlocksInUse);
190 status->PartBlocksAvail = ntohl(status->PartBlocksAvail);
191 status->PartMaxBlocks = ntohl(status->PartMaxBlocks);
192 } else { /* Host -> Network */
193 status->Vid = htonl(status->Vid);
194 status->ParentId = htonl(status->ParentId);
197 status->OnLine = status->OnLine;
198 status->InService = status->InService;
199 status->Blessed = status->Blessed;
200 status->NeedsSalvage = status->NeedsSalvage;
202 status->Type = htonl(status->Type);
203 status->MinQuota = htonl(status->MinQuota);
204 status->MaxQuota = htonl(status->MaxQuota);
205 status->BlocksInUse = htonl(status->BlocksInUse);
206 status->PartBlocksAvail = htonl(status->PartBlocksAvail);
207 status->PartMaxBlocks = htonl(status->PartMaxBlocks);
212 RClearToken_convert(char *ptr, int ntoh_conv)
214 struct ClearToken *ticket = (struct ClearToken *)ptr;
216 if (ntoh_conv) { /* Network -> host */
217 ticket->AuthHandle = ntohl(ticket->AuthHandle);
218 ticket->ViceId = ntohl(ticket->ViceId);
219 ticket->BeginTimestamp = ntohl(ticket->BeginTimestamp);
220 ticket->EndTimestamp = ntohl(ticket->EndTimestamp);
221 } else { /* Host -> Network */
222 ticket->AuthHandle = htonl(ticket->AuthHandle);
223 ticket->ViceId = htonl(ticket->ViceId);
224 ticket->BeginTimestamp = htonl(ticket->BeginTimestamp);
225 ticket->EndTimestamp = htonl(ticket->EndTimestamp);
230 inparam_conversion(afs_int32 cmd, char *buffer, afs_int32 ntoh_conv)
236 switch (cmd & 0xffff) {
237 case VIOCSETAL & 0xffff:
238 acl = RParseAcl(buffer);
239 RAclToString(acl, buffer, ntoh_conv);
242 case VIOCSETTOK & 0xffff:
243 lptr = (afs_int32 *) buffer;
244 /* i is sizeof of the secret ticket */
254 ptr += i; /* skip over the ticket */
255 lptr = (afs_int32 *) ptr;
256 /* i is now size of the clear token */
266 RClearToken_convert(ptr, ntoh_conv);
267 ptr += i; /* sizeof(struct ClearToken) */
268 lptr = (afs_int32 *) ptr;
270 *lptr = ntohl(*lptr);
272 *lptr = htonl(*lptr);
273 lptr++; /* primary flag */
275 case VIOCSETVOLSTAT & 0xffff:
276 RFetchVolumeStatus_conversion(buffer, ntoh_conv);
278 case VIOCGETTOK & 0xffff:
279 case VIOCCKSERV & 0xffff:
280 case VIOCACCESS & 0xffff:
281 case VIOCSETCACHESIZE & 0xffff:
282 case VIOCGETCELL & 0xffff:
283 case VIOC_AFS_MARINER_HOST & 0xffff:
284 case VIOC_VENUSLOG & 0xffff:
285 case VIOC_AFS_SYSNAME & 0xffff:
286 case VIOC_EXPORTAFS & 0xffff:
287 lptr = (afs_int32 *) buffer;
289 *lptr = ntohl(*lptr);
291 *lptr = htonl(*lptr);
293 case VIOC_SETCELLSTATUS & 0xffff:
294 lptr = (afs_int32 *) buffer;
296 *lptr = ntohl(*lptr);
298 *lptr = htonl(*lptr);
301 *lptr = ntohl(*lptr);
303 *lptr = htonl(*lptr);
305 case VIOCGETAL & 0xffff:
306 case VIOCGETVOLSTAT & 0xffff:
307 case VIOCGETCACHEPARMS & 0xffff:
308 case VIOCFLUSH & 0xffff:
309 case VIOCSTAT & 0xffff:
310 case VIOCUNLOG & 0xffff:
311 case VIOCCKBACK & 0xffff:
312 case VIOCCKCONN & 0xffff:
313 case VIOCGETTIME & 0xffff: /* Obsolete */
314 case VIOCWHEREIS & 0xffff:
315 case VIOCPREFETCH & 0xffff:
316 case VIOCNOP & 0xffff: /* Obsolete */
317 case VIOCENGROUP & 0xffff: /* Obsolete */
318 case VIOCDISGROUP & 0xffff: /* Obsolete */
319 case VIOCLISTGROUPS & 0xffff: /* Obsolete */
320 case VIOCUNPAG & 0xffff:
321 case VIOCWAITFOREVER & 0xffff: /* Obsolete */
322 case VIOCFLUSHCB & 0xffff:
323 case VIOCNEWCELL & 0xffff:
324 case VIOC_AFS_DELETE_MT_PT & 0xffff:
325 case VIOC_AFS_STAT_MT_PT & 0xffff:
326 case VIOC_FILE_CELL_NAME & 0xffff:
327 case VIOC_GET_WS_CELL & 0xffff:
328 case VIOC_GET_PRIMARY_CELL & 0xffff:
329 case VIOC_GETCELLSTATUS & 0xffff:
330 case VIOC_FLUSHVOLUME & 0xffff:
331 case VIOCGETFID & 0xffff: /* nothing yet */
334 /* Note that new pioctls are supposed to be in network order! */
341 outparam_conversion(afs_int32 cmd, char *buffer, afs_int32 ntoh_conv)
347 switch (cmd & 0xffff) {
348 case VIOCGETAL & 0xffff:
349 acl = RParseAcl(buffer);
350 RAclToString(acl, buffer, ntoh_conv);
353 case VIOCGETVOLSTAT & 0xffff:
354 RFetchVolumeStatus_conversion(buffer, ntoh_conv);
356 case VIOCSETVOLSTAT & 0xffff:
357 RFetchVolumeStatus_conversion(buffer, ntoh_conv);
359 case VIOCGETTOK & 0xffff:
360 lptr = (afs_int32 *) buffer;
361 /* i is set to sizeof secret ticket */
371 ptr += i; /* skip over the ticket */
372 lptr = (afs_int32 *) ptr;
373 /* i is set to sizeof clear ticket */
383 RClearToken_convert(ptr, ntoh_conv);
384 ptr += i; /* sizeof(struct ClearToken) */
385 lptr = (afs_int32 *) ptr;
387 *lptr = ntohl(*lptr);
389 *lptr = htonl(*lptr);
390 lptr++; /* primary flag */
392 case VIOCCKCONN & 0xffff:
393 case VIOC_AFS_MARINER_HOST & 0xffff:
394 case VIOC_VENUSLOG & 0xffff:
395 case VIOC_GETCELLSTATUS & 0xffff:
396 case VIOC_AFS_SYSNAME & 0xffff:
397 case VIOC_EXPORTAFS & 0xffff:
398 lptr = (afs_int32 *) buffer;
400 *lptr = ntohl(*lptr);
402 *lptr = htonl(*lptr);
404 case VIOCGETCACHEPARMS & 0xffff:
405 lptr = (afs_int32 *) buffer;
406 for (i = 0; i < MAXGCSIZE; i++, lptr++) {
408 *lptr = ntohl(*lptr);
410 *lptr = htonl(*lptr);
413 case VIOCUNLOG & 0xffff:
414 case VIOCCKSERV & 0xffff: /* Already in network order */
415 case VIOCCKBACK & 0xffff:
416 case VIOCGETTIME & 0xffff: /* Obsolete */
417 case VIOCWHEREIS & 0xffff: /* Already in network order */
418 case VIOCPREFETCH & 0xffff:
419 case VIOCNOP & 0xffff: /* Obsolete */
420 case VIOCENGROUP & 0xffff: /* Obsolete */
421 case VIOCDISGROUP & 0xffff: /* Obsolete */
422 case VIOCLISTGROUPS & 0xffff: /* Obsolete */
423 case VIOCACCESS & 0xffff:
424 case VIOCUNPAG & 0xffff:
425 case VIOCWAITFOREVER & 0xffff: /* Obsolete */
426 case VIOCSETCACHESIZE & 0xffff:
427 case VIOCFLUSHCB & 0xffff:
428 case VIOCNEWCELL & 0xffff:
429 case VIOCGETCELL & 0xffff: /* Already in network order */
430 case VIOC_AFS_DELETE_MT_PT & 0xffff:
431 case VIOC_AFS_STAT_MT_PT & 0xffff:
432 case VIOC_FILE_CELL_NAME & 0xffff: /* no need to convert */
433 case VIOC_GET_WS_CELL & 0xffff: /* no need to convert */
434 case VIOCGETFID & 0xffff: /* nothing yet */
435 case VIOCSETAL & 0xffff:
436 case VIOCFLUSH & 0xffff:
437 case VIOCSTAT & 0xffff:
438 case VIOCSETTOK & 0xffff:
439 case VIOC_GET_PRIMARY_CELL & 0xffff: /* The cell is returned here */
440 case VIOC_SETCELLSTATUS & 0xffff:
441 case VIOC_FLUSHVOLUME & 0xffff:
444 /* Note that new pioctls are supposed to be in network order! */