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