openafs-string-header-cleanup-20071030
[openafs.git] / src / viced / fsprobe.c
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
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
8  */
9
10 #include <afsconfig.h>
11 #include <afs/param.h>
12
13 RCSID
14     ("$Header$");
15
16 #include <afs/stds.h>
17 #include <afs/afsint.h>
18 #include <sys/socket.h>
19 #include <rx/rx_globals.h>
20 #include <netinet/in.h>
21 #include <arpa/inet.h>
22 #include <netdb.h>
23 #include <ubik.h>
24 #include <string.h>
25
26 struct ubik_client *cstruct;
27 struct rx_connection *serverconns[MAXSERVERS];
28 char *(args[50]);
29
30 extern int AFS_FetchData(), AFS_StoreData(), AFS_StoreACL();
31 extern int RXAFS_GetTime(), AFS_GetStatistics(), AFS_FetchStatus(),
32 AFS_FetchACL();
33 extern int AFS_StoreStatus(), AFS_RemoveFile(), AFS_CreateFile();
34 extern int AFS_Rename(), AFS_Symlink(), AFS_HardLink(), AFS_MakeDir(),
35 AFS_RemoveDir();
36 extern int AFS_Readdir(), AFS_MakeMountPoint(), AFS_ReleaseTokens(),
37 AFS_GetToken();
38 extern int AFS_BulkStatus(), AFS_Lookup();
39 extern int AFS_BulkStatus(), AFS_BulkLookup(), AFS_RenewAllTokens();
40 extern int AFS_BulkFetchVV(), AFS_BulkKeepAlive();
41 extern int AFS_Spare1(), AFS_Spare2(), AFS_Spare3(), AFS_Spare4(),
42 AFS_Spare5(), AFS_Spare6();
43
44 afs_int32
45 pxclient_Initialize(int auth, afs_int32 serverAddr)
46 {
47     afs_int32 code;
48     afs_int32 scIndex;
49     struct rx_securityClass *sc;
50
51     code = rx_Init(htons(2115) /*0 */ );
52     if (code) {
53         fprintf(stderr, "pxclient_Initialize:  Could not initialize rx.\n");
54         return code;
55     }
56     scIndex = 0;
57     rx_SetRxDeadTime(50);
58     switch (scIndex) {
59     case 0:
60         sc = rxnull_NewClientSecurityObject();
61         break;
62
63 #ifdef notdef                   /* security */
64     case 1:
65         sc = rxvab_NewClientSecurityObject(&ttoken.sessionKey, ttoken.ticket,
66                                            0);
67         break;
68
69     case 2:
70         sc = rxkad_NewClientSecurityObject(rxkad_clear, &ttoken.sessionKey,
71                                            ttoken.kvno, ttoken.ticketLen,
72                                            ttoken.ticket);
73 #endif /* notdef */
74     }
75     serverconns[0] =
76         rx_NewConnection(serverAddr, htons(7000), 1, sc, scIndex);
77
78     code = ubik_ClientInit(serverconns, &cstruct);
79
80     if (code) {
81         fprintf(stderr, "pxclient_Initialize: ubik client init failed.\n");
82         return code;
83     }
84     return 0;
85 }
86
87 /* main program */
88
89 #include "AFS_component_version_number.c"
90
91 int
92 main(int argc, char **argv)
93 {
94     char **av = argv;
95     struct sockaddr_in host;
96     register afs_int32 code;
97     extern struct hostent *gethostbyname();
98     struct hostent *hp;
99     char *hostname;
100     char hnamebuf[200];
101     struct timeval tv;
102     int noAuth = 1;             /* Default is authenticated connections */
103
104     argc--, av++;
105     if (argc < 1) {
106         printf("usage: pxclient <serverHost>\n");
107         exit(1);
108     }
109     memset((char *)&host, 0, sizeof(struct sockaddr_in));
110     host.sin_family = AF_INET;
111     host.sin_addr.s_addr = inet_addr(av[0]);
112 #ifdef STRUCT_SOCKADDR_HAS_SA_LEN
113     host.sin_len = sizeof(struct sockaddr_in);
114 #endif
115     if (host.sin_addr.s_addr != -1) {
116         strcpy(hnamebuf, av[0]);
117         hostname = hnamebuf;
118     } else {
119         hp = gethostbyname(av[0]);
120         if (hp) {
121             host.sin_family = hp->h_addrtype;
122             memcpy((caddr_t) & host.sin_addr, hp->h_addr, hp->h_length);
123             hostname = hp->h_name;
124         } else {
125             printf("unknown server host %s\n", av[0]);
126             exit(1);
127         }
128     }
129     if ((code = pxclient_Initialize(noAuth, host.sin_addr.s_addr)) != 0) {
130         printf("Couldn't initialize fs library (code=%d).\n", code);
131         exit(1);
132     }
133
134     code = ubik_Call(RXAFS_GetTime, cstruct, 0, &tv.tv_sec, &tv.tv_usec);
135     if (!code)
136         printf("AFS_GetTime on %s sec=%ld, usec=%ld\n", av[0], tv.tv_sec,
137                tv.tv_usec);
138     else
139         printf("return code is %d\n", code);
140
141 #ifdef notdef
142     while (1) {
143         char line[500];
144         int nargs;
145
146         printf("fs> ");
147         if (fgets(line, 499, stdin) != NULL) {
148             char *oper;
149             register char **argp = args;
150             GetArgs(line, argp, &nargs);
151             oper = &argp[0][0];
152             ++argp, --nargs;
153             if (!strcmp(oper, "probe")) {
154                 code =
155                     ubik_Call(RXAFS_GetTime, cstruct, 0, &tv.tv_sec,
156                               &tv.tv_usec);
157                 printf("return code is %d\n", code);
158                 if (!code)
159                     printf("sec=%d\n", tv.tv_sec);
160             } else if (!strcmp(oper, "fsstats")) {
161                 struct afsStatistics stats;
162
163                 code = ubik_AFS_GetStatistics(cstruct, 0, &stats);
164                 printf("return code is %d\n", code);
165             } else if (!strcmp(oper, "fd")) {
166                 code = FetchData(argp);
167                 printf("return code is %d\n", code);
168             } else if (!strcmp(oper, "fs")) {
169                 code = FetchStatus(argp);
170                 printf("return code is %d\n", code);
171             } else if (!strcmp(oper, "fa")) {
172                 code = FetchACL(argp);
173                 printf("return code is %d\n", code);
174             } else if (!strcmp(oper, "sd")) {
175                 code = StoreData(argp);
176                 printf("return code is %d\n", code);
177             } else if (!strcmp(oper, "ss")) {
178                 code = StoreStatus(argp);
179                 printf("return code is %d\n", code);
180             } else if (!strcmp(oper, "sa")) {
181                 code = StoreACL(argp);
182                 printf("return code is %d\n", code);
183             } else if (!strcmp(oper, "cf")) {
184                 code = CreateFile(argp);
185                 printf("return code is %d\n", code);
186             } else if (!strcmp(oper, "rf")) {
187                 code = RemoveFile(argp);
188                 printf("return code is %d\n", code);
189             } else if (!strcmp(oper, "rn")) {
190                 code = Rename(argp);
191                 printf("return code is %d\n", code);
192             } else if (!strcmp(oper, "sl")) {
193                 code = Symlink(argp);
194                 printf("return code is %d\n", code);
195             } else if (!strcmp(oper, "hl")) {
196                 code = HardLink(argp);
197                 printf("return code is %d\n", code);
198             } else if (!strcmp(oper, "md")) {
199                 code = MakeDir(argp);
200                 printf("return code is %d\n", code);
201             } else if (!strcmp(oper, "rd")) {
202                 code = RemoveDir(argp);
203                 printf("return code is %d\n", code);
204             } else if (!strcmp(oper, "rdd")) {
205                 code = Readdir(argp);
206                 printf("return code is %d\n", code);
207             } else if (!strcmp(oper, "mm")) {
208                 code = MakeMountPoint(argp);
209                 printf("return code is %d\n", code);
210             } else if (!strcmp(oper, "rt")) {
211                 code = ReleaseTokens(argp);
212                 printf("return code is %d\n", code);
213             } else if (!strcmp(oper, "bs")) {
214                 code = BulkStatus(argp);
215                 printf("return code is %d\n", code);
216             } else if (!strcmp(oper, "lk")) {
217                 code = Lookup(argp);
218                 printf("return code is %d\n", code);
219             } else if (!strcmp(oper, "gt")) {
220                 code = GetToken(argp);
221                 printf("return code is %d\n", code);
222             } else if (!strcmp(oper, "ka")) {
223                 code = KeepAlive(argp);
224                 printf("return code is %d\n", code);
225             } else if ((!strcmp(oper, "q")) || !strcmp(oper, "quit"))
226                 exit(0);
227             else {
228                 printf("Unknown oper! Available operations: \n\n");
229                 printf("fd <vnode> <unique> <pos> <len>\n");
230                 printf("fs <vnode> <unique>\n");
231                 printf("fa <vnode> <unique>\n");
232                 printf
233                     ("sd <vnode> <unique> <pos> <len> <flen> [<mode>|-1] [<owner>|-1] [<length>|-1] <string>\n");
234                 printf
235                     ("ss <vnode> <unique> [<mode>|-1] [<owner>|-1] [<length>|-1]\n");
236                 printf("sa <vnode> <unique> <string>\n");
237                 printf("rf <vnode> <unique> <name>\n");
238                 printf
239                     ("cf <vnode> <unique> <name> [<mode>|-1] [<owner>|-1] [<length>|-1]\n");
240                 printf
241                     ("rn <ovnode> <ounique> <oname> <nvnode> <nunique> <nname>\n");
242                 printf
243                     ("sl <vnode> <unique> <name> <contents> [<mode>|-1] [<owner>|-1] [<length>|-1]\n");
244                 printf("hl <dvnode> <dunique> <name> <evnode> <eunique>\n");
245                 printf
246                     ("md <vnode> <unique> <name> [<mode>|-1] [<owner>|-1] [<length>|-1]\n");
247                 printf("rd <vnode> <unique> <name>\n");
248                 printf("rdd <vnode> <unique> <pos> <len>\n");
249                 printf("lk <vnode> <unique> <name>\n");
250                 printf("gt <vnode> <unique> <tokenID>\n");
251                 printf("ka <vol.l> <vnode> <unique> <isExec> <kaTime>\n");
252             }
253         }
254     }
255 #endif
256 }
257
258
259 void
260 GetArgs(register char *line, register char **args, register int *nargs)
261 {
262     *nargs = 0;
263     while (*line) {
264         register char *last = line;
265         while (*line == ' ')
266             line++;
267         if (*last == ' ')
268             *last = 0;
269         if (!*line)
270             break;
271         *args++ = line, (*nargs)++;
272         while (*line && *line != ' ')
273             line++;
274     }
275 }
276
277 #ifdef notdef
278 afs_int32
279 FetchData(char **argp)
280 {
281     struct afsFetchStatus OutStatus;
282     struct afsToken Token;
283     struct afsVolSync tsync;
284     struct afsFid fid;
285     int vnode, unique, position, length;
286     int code;
287     struct rx_call *tcall;
288
289     sscanf(&(*argp)[0], "%d", &vnode);
290     ++argp;
291     sscanf(&(*argp)[0], "%d", &unique);
292     ++argp;
293     memset(&fid, 0, sizeof(struct afsFid));
294     fid.Volume.low = 10;        /* XXX */
295     fid.Vnode = vnode;
296     fid.Unique = unique;
297     sscanf(&(*argp)[0], "%d", &position);
298     ++argp;
299     sscanf(&(*argp)[0], "%d", &length);
300     ++argp;
301     tcall = rx_NewCall(cstruct->conns[0]);
302     code = StartAFS_FetchData(tcall, &fid, &hyp0, position, length, 0);
303     if (!code) {
304         code = FetchProc(tcall);
305     }
306     if (!code) {
307         code = EndAFS_FetchData(tcall, &OutStatus, &Token, &tsync);
308     }
309     code = rx_EndCall(tcall, code);
310     return code;
311 }
312
313
314 static afs_int32
315 FetchProc(register struct rx_call *acall)
316 {
317     extern char *malloc();
318     register char *tbuffer;
319     afs_int32 tlen, length, code;
320
321     code = rx_Read(acall, &length, sizeof(afs_int32));
322     length = ntohl(length);
323     if (code != sizeof(afs_int32))
324         return -1;
325     tbuffer = malloc(256);
326     while (length > 0) {
327         tlen = (length > 256 ? 256 : length);
328         code = rx_Read(acall, tbuffer, tlen);
329         if (code != tlen) {
330             free(tbuffer);
331             return -1;
332         }
333         length -= tlen;
334     }
335     free(tbuffer);
336     return 0;
337 }
338
339
340 afs_int32
341 FetchStatus(char **argp)
342 {
343     struct afsFetchStatus OutStatus;
344     struct afsToken Token;
345     struct afsVolSync tsync;
346     struct afsFid fid;
347     int vnode, unique;
348     int code;
349
350     sscanf(&(*argp)[0], "%d", &vnode);
351     ++argp;
352     sscanf(&(*argp)[0], "%d", &unique);
353     ++argp;
354     memset(&fid, 0, sizeof(struct afsFid));
355     fid.Volume.low = 10;        /* XXX */
356     fid.Vnode = vnode;
357     fid.Unique = unique;
358     code =
359         ubik_AFS_FetchStatus(cstruct, 0, &fid, &hyp0, 0, &OutStatus,
360                   &Token, &tsync);
361     return (code);
362 }
363
364
365 afs_int32
366 FetchACL(char **argp)
367 {
368     struct afsFetchStatus OutStatus;
369     struct afsACL AccessList;
370     struct afsToken Token;
371     struct afsVolSync tsync;
372     struct afsFid fid;
373     int vnode, unique;
374     int code;
375
376     sscanf(&(*argp)[0], "%d", &vnode);
377     ++argp;
378     sscanf(&(*argp)[0], "%d", &unique);
379     ++argp;
380     memset(&fid, 0, sizeof(struct afsFid));
381     fid.Volume.low = 10;        /* XXX */
382     fid.Vnode = vnode;
383     fid.Unique = unique;
384     code =
385         ubik_AFS_FetchACL(cstruct, 0, &fid, &hyp0, 0, &AccessList,
386                   &OutStatus, &tsync);
387     return (code);
388 }
389
390
391 afs_int32
392 StoreData(char **argp)
393 {
394     struct afsStoreStatus InStatus;
395     struct afsFetchStatus OutStatus;
396     struct afsVolSync tsync;
397     struct afsFid fid;
398     int vnode, unique, position, length, filelength;
399     int mode, owner, len;
400     int code;
401     char *string;
402     struct rx_call *tcall;
403
404     sscanf(&(*argp)[0], "%d", &vnode);
405     ++argp;
406     sscanf(&(*argp)[0], "%d", &unique);
407     ++argp;
408     memset(&fid, 0, sizeof(struct afsFid));
409     fid.Volume.low = 10;        /* XXX */
410     fid.Vnode = vnode;
411     fid.Unique = unique;
412     sscanf(&(*argp)[0], "%d", &position);
413     ++argp;
414     sscanf(&(*argp)[0], "%d", &length);
415     ++argp;
416     sscanf(&(*argp)[0], "%d", &filelength);
417     ++argp;
418     memset(&InStatus, 0, sizeof(struct afsStoreStatus));
419     sscanf(&(*argp)[0], "%d", &mode);
420     ++argp;
421     sscanf(&(*argp)[0], "%d", &owner);
422     ++argp;
423     sscanf(&(*argp)[0], "%d", &len);
424     ++argp;
425     if (mode != -1) {
426         InStatus.mode = mode;
427         InStatus.mask |= AFS_SETMODE;
428     }
429     if (owner != -1) {
430         InStatus.owner = owner;
431         InStatus.mask |= AFS_SETOWNER;
432     }
433     if (length != -1) {
434         InStatus.length = length;
435         InStatus.mask |= AFS_SETLENGTH;
436     }
437     string = &argp[0][0];
438     ++argp;
439
440     tcall = rx_NewCall(cstruct->conns[0]);
441     code =
442         StartAFS_StoreData(tcall, &fid, &InStatus, position, length,
443                            filelength, &hyp0, 0);
444     if (!code) {
445         code = StoreProc(tcall, string, length);
446     }
447     if (!code) {
448         code = EndAFS_StoreData(tcall, &OutStatus, &tsync);
449     }
450     code = rx_EndCall(tcall, code);
451     return (code);
452 }
453
454
455 static afs_int32
456 StoreProc(register struct rx_call *acall, char *string, int length)
457 {
458     afs_int32 tlen, code;
459
460     while (length > 0) {
461         tlen = (length > 256 ? 256 : length);
462         code = rx_Write(acall, string, tlen);
463         if (code != tlen) {
464             return -1;
465         }
466         length -= tlen;
467     }
468     return 0;
469 }
470
471
472 afs_int32
473 StoreStatus(char **argp)
474 {
475     struct afsStoreStatus InStatus;
476     struct afsFetchStatus OutStatus;
477     struct afsVolSync tsync;
478     struct afsFid fid;
479     int vnode, unique, mode, owner, length;
480     int code;
481
482     sscanf(&(*argp)[0], "%d", &vnode);
483     ++argp;
484     sscanf(&(*argp)[0], "%d", &unique);
485     ++argp;
486     memset(&fid, 0, sizeof(struct afsFid));
487     fid.Volume.low = 10;        /* XXX */
488     fid.Vnode = vnode;
489     fid.Unique = unique;
490     memset(&InStatus, 0, sizeof(struct afsStoreStatus));
491     sscanf(&(*argp)[0], "%d", &mode);
492     ++argp;
493     sscanf(&(*argp)[0], "%d", &owner);
494     ++argp;
495     sscanf(&(*argp)[0], "%d", &length);
496     ++argp;
497     if (mode != -1) {
498         InStatus.mode = mode;
499         InStatus.mask |= AFS_SETMODE;
500     }
501     if (owner != -1) {
502         InStatus.owner = owner;
503         InStatus.mask |= AFS_SETOWNER;
504     }
505     if (length != -1) {
506         InStatus.length = length;
507         InStatus.mask |= AFS_SETLENGTH;
508     }
509     code =
510         ubik_AFS_StoreStatus(cstruct, 0, &fid, &InStatus, &hyp0, 0,
511                   &OutStatus, &tsync);
512     return (code);
513 }
514
515
516 afs_int32
517 StoreACL(char **argp)
518 {
519     struct afsFetchStatus OutStatus;
520     struct afsACL AccessList;
521     struct afsToken Token;
522     struct afsVolSync tsync;
523     struct afsFid fid;
524     char *string;
525     int vnode, unique;
526     int code;
527
528     sscanf(&(*argp)[0], "%d", &vnode);
529     ++argp;
530     sscanf(&(*argp)[0], "%d", &unique);
531     ++argp;
532     memset(&fid, 0, sizeof(struct afsFid));
533     fid.Volume.low = 10;        /* XXX */
534     fid.Vnode = vnode;
535     fid.Unique = unique;
536     string = &argp[0][0];
537     ++argp;
538     AccessList.afsACL_len = strlen(string) + 1;
539     AccessList.afsACL_val = string;
540     code =
541         ubik_AFS_StoreACL(cstruct, 0, &fid, &AccessList, &hyp0, 0,
542                   &OutStatus, &tsync);
543     return (code);
544 }
545
546
547 afs_int32
548 RemoveFile(char **argp)
549 {
550     struct afsFetchStatus OutDirStatus, OutFidStatus;
551     struct afsVolSync tsync;
552     struct afsFidName nameFid;
553     struct afsFid fid, outFid;
554     char *name;
555     int vnode, unique;
556     int code;
557
558     sscanf(&(*argp)[0], "%d", &vnode);
559     ++argp;
560     sscanf(&(*argp)[0], "%d", &unique);
561     ++argp;
562     memset(&fid, 0, sizeof(struct afsFid));
563     fid.Volume.low = 10;        /* XXX */
564     fid.Vnode = vnode;
565     fid.Unique = unique;
566     name = &argp[0][0];
567     ++argp;
568     memset(&nameFid, 0, sizeof(struct afsFidName));
569     strcpy(nameFid.name, name);
570     code =
571         ubik_AFS_RemoveFile(cstruct, 0, &fid, &nameFid, &hyp0, 0,
572                   &OutDirStatus, &OutFidStatus, &outFid, &tsync);
573     return (code);
574 }
575
576
577 afs_int32
578 CreateFile(char **argp)
579 {
580     struct afsFetchStatus OutDirStatus, OutFidStatus;
581     struct afsStoreStatus InStatus;
582     struct afsVolSync tsync;
583     struct afsFid fid, outFid;
584     struct afsToken Token;
585     char *name;
586     int vnode, unique, mode, owner, length;
587     int code;
588
589     sscanf(&(*argp)[0], "%d", &vnode);
590     ++argp;
591     sscanf(&(*argp)[0], "%d", &unique);
592     ++argp;
593     memset(&fid, 0, sizeof(struct afsFid));
594     fid.Volume.low = 10;        /* XXX */
595     fid.Vnode = vnode;
596     fid.Unique = unique;
597     name = &argp[0][0];
598     ++argp;
599     memset(&InStatus, 0, sizeof(struct afsStoreStatus));
600     sscanf(&(*argp)[0], "%d", &mode);
601     ++argp;
602     sscanf(&(*argp)[0], "%d", &owner);
603     ++argp;
604     sscanf(&(*argp)[0], "%d", &length);
605     ++argp;
606     if (mode != -1) {
607         InStatus.mode = mode;
608         InStatus.mask |= AFS_SETMODE;
609     }
610     if (owner != -1) {
611         InStatus.owner = owner;
612         InStatus.mask |= AFS_SETOWNER;
613     }
614     if (length != -1) {
615         InStatus.length = length;
616         InStatus.mask |= AFS_SETLENGTH;
617     }
618     code =
619         ubik_AFS_CreateFile(cstruct, 0, &fid, name, &InStatus, &hyp0, 0,
620                   &outFid, &OutFidStatus, &OutDirStatus, &Token, &tsync);
621     return (code);
622 }
623
624
625 afs_int32
626 Rename(char **argp)
627 {
628     struct afsFetchStatus OutOldDirStatus, OutNewDirStatus;
629     struct afsFetchStatus OutOldFileStatus, OutNewFileStatus;
630     struct afsVolSync tsync;
631     struct afsFid OldDirFid, NewDirFid, OutOldFileFid, OutNewFileFid;
632     struct afsFidName OldName, NewName;
633     char *oname, *nname;
634     int ovnode, ounique, nvnode, nunique;
635     int code;
636
637     sscanf(&(*argp)[0], "%d", &ovnode);
638     ++argp;
639     sscanf(&(*argp)[0], "%d", &ounique);
640     ++argp;
641     memset(&OldDirFid, 0, sizeof(struct afsFid));
642     OldDirFid.Volume.low = 10;  /* XXX */
643     OldDirFid.Vnode = ovnode;
644     OldDirFid.Unique = ounique;
645     oname = &argp[0][0];
646     ++argp;
647     memset(&OldName, 0, sizeof(struct afsFidName));
648     strcpy(OldName.name, oname);
649     sscanf(&(*argp)[0], "%d", &nvnode);
650     ++argp;
651     sscanf(&(*argp)[0], "%d", &nunique);
652     ++argp;
653     memset(&NewDirFid, 0, sizeof(struct afsFid));
654     NewDirFid.Volume.low = 10;  /* XXX */
655     NewDirFid.Vnode = nvnode;
656     NewDirFid.Unique = nunique;
657     nname = &argp[0][0];
658     ++argp;
659     memset(&NewName, 0, sizeof(struct afsFidName));
660     strcpy(NewName.name, nname);
661     code =
662         ubik_AFS_Rename(cstruct, 0, &OldDirFid, &OldName, &NewDirFid,
663                   &NewName, &hyp0, 0, &OutOldDirStatus, &OutNewDirStatus,
664                   &OutOldFileFid, &OutOldFileStatus, &OutNewFileFid,
665                   &OutNewFileStatus, &tsync);
666     return (code);
667 }
668
669
670 afs_int32
671 Symlink(char **argp)
672 {
673     struct afsFetchStatus OutDirStatus, OutFidStatus;
674     struct afsStoreStatus InStatus;
675     struct afsVolSync tsync;
676     struct afsFid fid, outFid;
677     struct afsToken Token;
678     char *name, *linkcontents;
679     int vnode, unique, mode, owner, length;
680     int code;
681
682     sscanf(&(*argp)[0], "%d", &vnode);
683     ++argp;
684     sscanf(&(*argp)[0], "%d", &unique);
685     ++argp;
686     memset(&fid, 0, sizeof(struct afsFid));
687     fid.Volume.low = 10;        /* XXX */
688     fid.Vnode = vnode;
689     fid.Unique = unique;
690     name = &argp[0][0];
691     ++argp;
692     linkcontents = &argp[0][0];
693     ++argp;
694     memset(&InStatus, 0, sizeof(struct afsStoreStatus));
695     sscanf(&(*argp)[0], "%d", &mode);
696     ++argp;
697     sscanf(&(*argp)[0], "%d", &owner);
698     ++argp;
699     sscanf(&(*argp)[0], "%d", &length);
700     ++argp;
701     if (mode != -1) {
702         InStatus.mode = mode;
703         InStatus.mask |= AFS_SETMODE;
704     }
705     if (owner != -1) {
706         InStatus.owner = owner;
707         InStatus.mask |= AFS_SETOWNER;
708     }
709     if (length != -1) {
710         InStatus.length = length;
711         InStatus.mask |= AFS_SETLENGTH;
712     }
713     code =
714         ubik_AFS_Symlink(cstruct, 0, &fid, name, linkcontents,
715                   &InStatus, &hyp0, 0, &outFid, &OutFidStatus, &OutDirStatus,
716                   &Token, &tsync);
717     return (code);
718 }
719
720
721 afs_int32
722 HardLink(char **argp)
723 {
724     struct afsFetchStatus OutDirStatus, OutFidStatus;
725     struct afsVolSync tsync;
726     struct afsFid fid, existingFid;
727     char *name;
728     int vnode, unique;
729     int code;
730
731     sscanf(&(*argp)[0], "%d", &vnode);
732     ++argp;
733     sscanf(&(*argp)[0], "%d", &unique);
734     ++argp;
735     memset(&fid, 0, sizeof(struct afsFid));
736     fid.Volume.low = 10;        /* XXX */
737     fid.Vnode = vnode;
738     fid.Unique = unique;
739     name = &argp[0][0];
740     ++argp;
741     sscanf(&(*argp)[0], "%d", &vnode);
742     ++argp;
743     sscanf(&(*argp)[0], "%d", &unique);
744     ++argp;
745     memset(&existingFid, 0, sizeof(struct afsFid));
746     existingFid.Volume.low = 10;        /* XXX */
747     existingFid.Vnode = vnode;
748     existingFid.Unique = unique;
749     code =
750         ubik_AFS_HardLink(cstruct, 0, &fid, name, &existingFid, &hyp0,
751                   0, &OutFidStatus, &OutDirStatus, &tsync);
752     return (code);
753 }
754
755
756 afs_int32
757 MakeDir(char **argp)
758 {
759     struct afsFetchStatus OutDirStatus, OutFidStatus;
760     struct afsStoreStatus InStatus;
761     struct afsVolSync tsync;
762     struct afsFid fid, outFid;
763     struct afsToken Token;
764     char *name;
765     int vnode, unique, mode, owner, length;
766     int code;
767
768     sscanf(&(*argp)[0], "%d", &vnode);
769     ++argp;
770     sscanf(&(*argp)[0], "%d", &unique);
771     ++argp;
772     memset(&fid, 0, sizeof(struct afsFid));
773     fid.Volume.low = 10;        /* XXX */
774     fid.Vnode = vnode;
775     fid.Unique = unique;
776     name = &argp[0][0];
777     ++argp;
778     memset(&InStatus, 0, sizeof(struct afsStoreStatus));
779     sscanf(&(*argp)[0], "%d", &mode);
780     ++argp;
781     sscanf(&(*argp)[0], "%d", &owner);
782     ++argp;
783     sscanf(&(*argp)[0], "%d", &length);
784     ++argp;
785     if (mode != -1) {
786         InStatus.mode = mode;
787         InStatus.mask |= AFS_SETMODE;
788     }
789     if (owner != -1) {
790         InStatus.owner = owner;
791         InStatus.mask |= AFS_SETOWNER;
792     }
793     if (length != -1) {
794         InStatus.length = length;
795         InStatus.mask |= AFS_SETLENGTH;
796     }
797     code =
798         ubik_AFS_MakeDir(cstruct, 0, &fid, name, &InStatus, &hyp0, 0,
799                   &outFid, &OutFidStatus, &OutDirStatus, &Token, &tsync);
800     return (code);
801 }
802
803
804 afs_int32
805 RemoveDir(char **argp)
806 {
807     struct afsFetchStatus OutDirStatus;
808     struct afsVolSync tsync;
809     struct afsFid fid, outFid;
810     struct afsFidName nameFid;
811     char *name;
812     int vnode, unique;
813     int code;
814
815     sscanf(&(*argp)[0], "%d", &vnode);
816     ++argp;
817     sscanf(&(*argp)[0], "%d", &unique);
818     ++argp;
819     memset(&fid, 0, sizeof(struct afsFid));
820     fid.Volume.low = 10;        /* XXX */
821     fid.Vnode = vnode;
822     fid.Unique = unique;
823     name = &argp[0][0];
824     ++argp;
825     memset(&nameFid, 0, sizeof(struct afsFidName));
826     strcpy(nameFid.name, name);
827     code =
828         ubik_AFS_RemoveDir(cstruct, 0, &fid, &nameFid, &hyp0, 0,
829                   &OutDirStatus, &outFid, &tsync);
830     return (code);
831 }
832
833
834 afs_int32
835 Readdir(char **argp)
836 {
837     struct afsFetchStatus OutDirStatus;
838     struct afsVolSync tsync;
839     struct afsFid fid;
840     struct afsToken Token;
841     char *name;
842     struct rx_call *tcall;
843     int vnode, unique, offset, length, NextOffset;
844     int code;
845
846     sscanf(&(*argp)[0], "%d", &vnode);
847     ++argp;
848     sscanf(&(*argp)[0], "%d", &unique);
849     ++argp;
850     sscanf(&(*argp)[0], "%d", &offset);
851     ++argp;
852     sscanf(&(*argp)[0], "%d", &length);
853     ++argp;
854     memset(&fid, 0, sizeof(struct afsFid));
855     fid.Volume.low = 10;        /* XXX */
856     fid.Vnode = vnode;
857     fid.Unique = unique;
858     tcall = rx_NewCall(cstruct->conns[0]);
859     code = StartAFS_Readdir(tcall, &fid, offset, length, &hyp0, 0);
860     if (!code) {
861         code = FetchDir(tcall);
862     }
863     if (!code) {
864         code =
865             EndAFS_FetchData(tcall, &NextOffset, &OutDirStatus, &Token,
866                              &tsync);
867     }
868     code = rx_EndCall(tcall, code);
869     return (code);
870 }
871
872
873 static afs_int32
874 FetchDir(register struct rx_call *acall)
875 {
876     extern char *malloc();
877     register char *tbuffer;
878     afs_int32 tlen, length, code;
879     struct dirent *dp;
880
881
882     tbuffer = malloc(256);
883     while (1) {
884         code = rx_Read(acall, &length, sizeof(afs_int32));
885         length = ntohl(length);
886         if (code != sizeof(afs_int32))
887             return -1;
888         if (length == 0)
889             break;
890         tlen = (length > 8192 ? 8192 : length);
891         code = rx_Read(acall, tbuffer, tlen);
892         if (code != tlen) {
893             free(tbuffer);
894             return -1;
895         }
896         length -= tlen;
897     }
898     dp = (struct dirent *)dp;
899     free(tbuffer);
900     return 0;
901 }
902
903
904 afs_int32
905 Lookup(char **argp)
906 {
907     struct afsFetchStatus OutDirStatus, OutFidStatus;
908     struct afsVolSync tsync;
909     struct afsFid fid, outFid;
910     char *name;
911     int vnode, unique;
912     int code;
913
914     sscanf(&(*argp)[0], "%d", &vnode);
915     ++argp;
916     sscanf(&(*argp)[0], "%d", &unique);
917     ++argp;
918     memset(&fid, 0, sizeof(struct afsFid));
919     fid.Volume.low = 10;        /* XXX */
920     fid.Vnode = vnode;
921     fid.Unique = unique;
922     name = &argp[0][0];
923     ++argp;
924     code =
925         ubik_AFS_Lookup(cstruct, 0, &fid, name, &hyp0, 0, &outFid,
926                   &OutFidStatus, &OutDirStatus, &tsync);
927     return (code);
928 }
929
930
931 afs_int32
932 GetToken(char **argp)
933 {
934     struct afsFetchStatus OutStatus;
935     struct afsVolSync tsync;
936     struct afsToken MinToken, RealToken;
937     struct afsFid fid;
938     int vnode, unique, tokenId;
939     int code;
940
941     sscanf(&(*argp)[0], "%d", &vnode);
942     ++argp;
943     sscanf(&(*argp)[0], "%d", &unique);
944     ++argp;
945     memset(&fid, 0, sizeof(struct afsFid));
946     fid.Volume.low = 10;        /* XXX */
947     fid.Vnode = vnode;
948     fid.Unique = unique;
949     sscanf(&(*argp)[0], "%d", &tokenId);
950     ++argp;
951     memset(&MinToken, 0, sizeof(struct afsToken));
952     MinToken.tokenID.low = tokenId;     /* XXX */
953     code =
954         ubik_AFS_GetToken(cstruct, 0, &fid, &MinToken, &hyp0, 0,
955                   &RealToken, &OutStatus, &tsync);
956     return (code);
957 }
958
959
960 afs_int32
961 MakeMountPoint(char **argp)
962 {
963 }
964
965
966 afs_int32
967 ReleaseTokens(char **argp)
968 {
969 }
970
971
972 afs_int32
973 BulkStatus(char **argp)
974 {
975 }
976
977 /*  printf("ka <vol.l> <vnode> <unique> <isExec> <kaTime>\n"); */
978 afs_int32
979 KeepAlive(char **argp)
980 {
981     struct afsBulkFEX fex;
982     afs_uint32 numExec, spare4;
983     struct afsFidExp fx;
984     int code;
985
986     memset(&fx, 0, sizeof(struct afsFidExp));
987     sscanf(&(*argp)[0], "%d", &fx.fid.Volume.low);
988     ++argp;
989     sscanf(&(*argp)[0], "%d", &fx.fid.Vnode);
990     ++argp;
991     sscanf(&(*argp)[0], "%d", &fx.fid.Unique);
992     ++argp;
993     sscanf(&(*argp)[0], "%d", &numExec);
994     ++argp;
995     sscanf(&(*argp)[0], "%d", &fx.keepAliveTime);
996     memset(&fex, 0, sizeof(struct afsBulkFEX));
997     fex.afsBulkFEX_val = &fx;
998     fex.afsBulkFEX_len = 1;
999     code =
1000         ubik_AFS_BulkKeepAlive(cstruct, 0, &fex, numExec, 0, 0, 0,
1001                   &spare4);
1002     return (code);
1003 }
1004 #endif /* notdef */