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