fileserver & friends: Don't cast from malloc()
[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     char *tbuffer;
279     afs_int32 tlen, length, code;
280
281     code = rx_Read(acall, &length, sizeof(afs_int32));
282     length = ntohl(length);
283     if (code != sizeof(afs_int32))
284         return -1;
285     tbuffer = malloc(256);
286     while (length > 0) {
287         tlen = (length > 256 ? 256 : length);
288         code = rx_Read(acall, tbuffer, tlen);
289         if (code != tlen) {
290             free(tbuffer);
291             return -1;
292         }
293         length -= tlen;
294     }
295     free(tbuffer);
296     return 0;
297 }
298
299
300 afs_int32
301 FetchStatus(char **argp)
302 {
303     struct afsFetchStatus OutStatus;
304     struct afsToken Token;
305     struct afsVolSync tsync;
306     struct afsFid fid;
307     int vnode, unique;
308     int code;
309
310     sscanf(&(*argp)[0], "%d", &vnode);
311     ++argp;
312     sscanf(&(*argp)[0], "%d", &unique);
313     ++argp;
314     memset(&fid, 0, sizeof(struct afsFid));
315     fid.Volume.low = 10;        /* XXX */
316     fid.Vnode = vnode;
317     fid.Unique = unique;
318     code =
319         ubik_AFS_FetchStatus(cstruct, 0, &fid, &hyp0, 0, &OutStatus,
320                   &Token, &tsync);
321     return (code);
322 }
323
324
325 afs_int32
326 FetchACL(char **argp)
327 {
328     struct afsFetchStatus OutStatus;
329     struct afsACL AccessList;
330     struct afsToken Token;
331     struct afsVolSync tsync;
332     struct afsFid fid;
333     int vnode, unique;
334     int code;
335
336     sscanf(&(*argp)[0], "%d", &vnode);
337     ++argp;
338     sscanf(&(*argp)[0], "%d", &unique);
339     ++argp;
340     memset(&fid, 0, sizeof(struct afsFid));
341     fid.Volume.low = 10;        /* XXX */
342     fid.Vnode = vnode;
343     fid.Unique = unique;
344     code =
345         ubik_AFS_FetchACL(cstruct, 0, &fid, &hyp0, 0, &AccessList,
346                   &OutStatus, &tsync);
347     return (code);
348 }
349
350
351 afs_int32
352 StoreData(char **argp)
353 {
354     struct afsStoreStatus InStatus;
355     struct afsFetchStatus OutStatus;
356     struct afsVolSync tsync;
357     struct afsFid fid;
358     int vnode, unique, position, length, filelength;
359     int mode, owner, len;
360     int code;
361     char *string;
362     struct rx_call *tcall;
363
364     sscanf(&(*argp)[0], "%d", &vnode);
365     ++argp;
366     sscanf(&(*argp)[0], "%d", &unique);
367     ++argp;
368     memset(&fid, 0, sizeof(struct afsFid));
369     fid.Volume.low = 10;        /* XXX */
370     fid.Vnode = vnode;
371     fid.Unique = unique;
372     sscanf(&(*argp)[0], "%d", &position);
373     ++argp;
374     sscanf(&(*argp)[0], "%d", &length);
375     ++argp;
376     sscanf(&(*argp)[0], "%d", &filelength);
377     ++argp;
378     memset(&InStatus, 0, sizeof(struct afsStoreStatus));
379     sscanf(&(*argp)[0], "%d", &mode);
380     ++argp;
381     sscanf(&(*argp)[0], "%d", &owner);
382     ++argp;
383     sscanf(&(*argp)[0], "%d", &len);
384     ++argp;
385     if (mode != -1) {
386         InStatus.mode = mode;
387         InStatus.mask |= AFS_SETMODE;
388     }
389     if (owner != -1) {
390         InStatus.owner = owner;
391         InStatus.mask |= AFS_SETOWNER;
392     }
393     if (length != -1) {
394         InStatus.length = length;
395         InStatus.mask |= AFS_SETLENGTH;
396     }
397     string = &argp[0][0];
398     ++argp;
399
400     tcall = rx_NewCall(cstruct->conns[0]);
401     code =
402         StartAFS_StoreData(tcall, &fid, &InStatus, position, length,
403                            filelength, &hyp0, 0);
404     if (!code) {
405         code = StoreProc(tcall, string, length);
406     }
407     if (!code) {
408         code = EndAFS_StoreData(tcall, &OutStatus, &tsync);
409     }
410     code = rx_EndCall(tcall, code);
411     return (code);
412 }
413
414
415 static afs_int32
416 StoreProc(struct rx_call *acall, char *string, int length)
417 {
418     afs_int32 tlen, code;
419
420     while (length > 0) {
421         tlen = (length > 256 ? 256 : length);
422         code = rx_Write(acall, string, tlen);
423         if (code != tlen) {
424             return -1;
425         }
426         length -= tlen;
427     }
428     return 0;
429 }
430
431
432 afs_int32
433 StoreStatus(char **argp)
434 {
435     struct afsStoreStatus InStatus;
436     struct afsFetchStatus OutStatus;
437     struct afsVolSync tsync;
438     struct afsFid fid;
439     int vnode, unique, mode, owner, length;
440     int code;
441
442     sscanf(&(*argp)[0], "%d", &vnode);
443     ++argp;
444     sscanf(&(*argp)[0], "%d", &unique);
445     ++argp;
446     memset(&fid, 0, sizeof(struct afsFid));
447     fid.Volume.low = 10;        /* XXX */
448     fid.Vnode = vnode;
449     fid.Unique = unique;
450     memset(&InStatus, 0, sizeof(struct afsStoreStatus));
451     sscanf(&(*argp)[0], "%d", &mode);
452     ++argp;
453     sscanf(&(*argp)[0], "%d", &owner);
454     ++argp;
455     sscanf(&(*argp)[0], "%d", &length);
456     ++argp;
457     if (mode != -1) {
458         InStatus.mode = mode;
459         InStatus.mask |= AFS_SETMODE;
460     }
461     if (owner != -1) {
462         InStatus.owner = owner;
463         InStatus.mask |= AFS_SETOWNER;
464     }
465     if (length != -1) {
466         InStatus.length = length;
467         InStatus.mask |= AFS_SETLENGTH;
468     }
469     code =
470         ubik_AFS_StoreStatus(cstruct, 0, &fid, &InStatus, &hyp0, 0,
471                   &OutStatus, &tsync);
472     return (code);
473 }
474
475
476 afs_int32
477 StoreACL(char **argp)
478 {
479     struct afsFetchStatus OutStatus;
480     struct afsACL AccessList;
481     struct afsToken Token;
482     struct afsVolSync tsync;
483     struct afsFid fid;
484     char *string;
485     int vnode, unique;
486     int code;
487
488     sscanf(&(*argp)[0], "%d", &vnode);
489     ++argp;
490     sscanf(&(*argp)[0], "%d", &unique);
491     ++argp;
492     memset(&fid, 0, sizeof(struct afsFid));
493     fid.Volume.low = 10;        /* XXX */
494     fid.Vnode = vnode;
495     fid.Unique = unique;
496     string = &argp[0][0];
497     ++argp;
498     AccessList.afsACL_len = strlen(string) + 1;
499     AccessList.afsACL_val = string;
500     code =
501         ubik_AFS_StoreACL(cstruct, 0, &fid, &AccessList, &hyp0, 0,
502                   &OutStatus, &tsync);
503     return (code);
504 }
505
506
507 afs_int32
508 RemoveFile(char **argp)
509 {
510     struct afsFetchStatus OutDirStatus, OutFidStatus;
511     struct afsVolSync tsync;
512     struct afsFidName nameFid;
513     struct afsFid fid, outFid;
514     char *name;
515     int vnode, unique;
516     int code;
517
518     sscanf(&(*argp)[0], "%d", &vnode);
519     ++argp;
520     sscanf(&(*argp)[0], "%d", &unique);
521     ++argp;
522     memset(&fid, 0, sizeof(struct afsFid));
523     fid.Volume.low = 10;        /* XXX */
524     fid.Vnode = vnode;
525     fid.Unique = unique;
526     name = &argp[0][0];
527     ++argp;
528     memset(&nameFid, 0, sizeof(struct afsFidName));
529     strcpy(nameFid.name, name);
530     code =
531         ubik_AFS_RemoveFile(cstruct, 0, &fid, &nameFid, &hyp0, 0,
532                   &OutDirStatus, &OutFidStatus, &outFid, &tsync);
533     return (code);
534 }
535
536
537 afs_int32
538 CreateFile(char **argp)
539 {
540     struct afsFetchStatus OutDirStatus, OutFidStatus;
541     struct afsStoreStatus InStatus;
542     struct afsVolSync tsync;
543     struct afsFid fid, outFid;
544     struct afsToken Token;
545     char *name;
546     int vnode, unique, mode, owner, length;
547     int code;
548
549     sscanf(&(*argp)[0], "%d", &vnode);
550     ++argp;
551     sscanf(&(*argp)[0], "%d", &unique);
552     ++argp;
553     memset(&fid, 0, sizeof(struct afsFid));
554     fid.Volume.low = 10;        /* XXX */
555     fid.Vnode = vnode;
556     fid.Unique = unique;
557     name = &argp[0][0];
558     ++argp;
559     memset(&InStatus, 0, sizeof(struct afsStoreStatus));
560     sscanf(&(*argp)[0], "%d", &mode);
561     ++argp;
562     sscanf(&(*argp)[0], "%d", &owner);
563     ++argp;
564     sscanf(&(*argp)[0], "%d", &length);
565     ++argp;
566     if (mode != -1) {
567         InStatus.mode = mode;
568         InStatus.mask |= AFS_SETMODE;
569     }
570     if (owner != -1) {
571         InStatus.owner = owner;
572         InStatus.mask |= AFS_SETOWNER;
573     }
574     if (length != -1) {
575         InStatus.length = length;
576         InStatus.mask |= AFS_SETLENGTH;
577     }
578     code =
579         ubik_AFS_CreateFile(cstruct, 0, &fid, name, &InStatus, &hyp0, 0,
580                   &outFid, &OutFidStatus, &OutDirStatus, &Token, &tsync);
581     return (code);
582 }
583
584
585 afs_int32
586 Rename(char **argp)
587 {
588     struct afsFetchStatus OutOldDirStatus, OutNewDirStatus;
589     struct afsFetchStatus OutOldFileStatus, OutNewFileStatus;
590     struct afsVolSync tsync;
591     struct afsFid OldDirFid, NewDirFid, OutOldFileFid, OutNewFileFid;
592     struct afsFidName OldName, NewName;
593     char *oname, *nname;
594     int ovnode, ounique, nvnode, nunique;
595     int code;
596
597     sscanf(&(*argp)[0], "%d", &ovnode);
598     ++argp;
599     sscanf(&(*argp)[0], "%d", &ounique);
600     ++argp;
601     memset(&OldDirFid, 0, sizeof(struct afsFid));
602     OldDirFid.Volume.low = 10;  /* XXX */
603     OldDirFid.Vnode = ovnode;
604     OldDirFid.Unique = ounique;
605     oname = &argp[0][0];
606     ++argp;
607     memset(&OldName, 0, sizeof(struct afsFidName));
608     strcpy(OldName.name, oname);
609     sscanf(&(*argp)[0], "%d", &nvnode);
610     ++argp;
611     sscanf(&(*argp)[0], "%d", &nunique);
612     ++argp;
613     memset(&NewDirFid, 0, sizeof(struct afsFid));
614     NewDirFid.Volume.low = 10;  /* XXX */
615     NewDirFid.Vnode = nvnode;
616     NewDirFid.Unique = nunique;
617     nname = &argp[0][0];
618     ++argp;
619     memset(&NewName, 0, sizeof(struct afsFidName));
620     strcpy(NewName.name, nname);
621     code =
622         ubik_AFS_Rename(cstruct, 0, &OldDirFid, &OldName, &NewDirFid,
623                   &NewName, &hyp0, 0, &OutOldDirStatus, &OutNewDirStatus,
624                   &OutOldFileFid, &OutOldFileStatus, &OutNewFileFid,
625                   &OutNewFileStatus, &tsync);
626     return (code);
627 }
628
629
630 afs_int32
631 Symlink(char **argp)
632 {
633     struct afsFetchStatus OutDirStatus, OutFidStatus;
634     struct afsStoreStatus InStatus;
635     struct afsVolSync tsync;
636     struct afsFid fid, outFid;
637     struct afsToken Token;
638     char *name, *linkcontents;
639     int vnode, unique, mode, owner, length;
640     int code;
641
642     sscanf(&(*argp)[0], "%d", &vnode);
643     ++argp;
644     sscanf(&(*argp)[0], "%d", &unique);
645     ++argp;
646     memset(&fid, 0, sizeof(struct afsFid));
647     fid.Volume.low = 10;        /* XXX */
648     fid.Vnode = vnode;
649     fid.Unique = unique;
650     name = &argp[0][0];
651     ++argp;
652     linkcontents = &argp[0][0];
653     ++argp;
654     memset(&InStatus, 0, sizeof(struct afsStoreStatus));
655     sscanf(&(*argp)[0], "%d", &mode);
656     ++argp;
657     sscanf(&(*argp)[0], "%d", &owner);
658     ++argp;
659     sscanf(&(*argp)[0], "%d", &length);
660     ++argp;
661     if (mode != -1) {
662         InStatus.mode = mode;
663         InStatus.mask |= AFS_SETMODE;
664     }
665     if (owner != -1) {
666         InStatus.owner = owner;
667         InStatus.mask |= AFS_SETOWNER;
668     }
669     if (length != -1) {
670         InStatus.length = length;
671         InStatus.mask |= AFS_SETLENGTH;
672     }
673     code =
674         ubik_AFS_Symlink(cstruct, 0, &fid, name, linkcontents,
675                   &InStatus, &hyp0, 0, &outFid, &OutFidStatus, &OutDirStatus,
676                   &Token, &tsync);
677     return (code);
678 }
679
680
681 afs_int32
682 HardLink(char **argp)
683 {
684     struct afsFetchStatus OutDirStatus, OutFidStatus;
685     struct afsVolSync tsync;
686     struct afsFid fid, existingFid;
687     char *name;
688     int vnode, unique;
689     int code;
690
691     sscanf(&(*argp)[0], "%d", &vnode);
692     ++argp;
693     sscanf(&(*argp)[0], "%d", &unique);
694     ++argp;
695     memset(&fid, 0, sizeof(struct afsFid));
696     fid.Volume.low = 10;        /* XXX */
697     fid.Vnode = vnode;
698     fid.Unique = unique;
699     name = &argp[0][0];
700     ++argp;
701     sscanf(&(*argp)[0], "%d", &vnode);
702     ++argp;
703     sscanf(&(*argp)[0], "%d", &unique);
704     ++argp;
705     memset(&existingFid, 0, sizeof(struct afsFid));
706     existingFid.Volume.low = 10;        /* XXX */
707     existingFid.Vnode = vnode;
708     existingFid.Unique = unique;
709     code =
710         ubik_AFS_HardLink(cstruct, 0, &fid, name, &existingFid, &hyp0,
711                   0, &OutFidStatus, &OutDirStatus, &tsync);
712     return (code);
713 }
714
715
716 afs_int32
717 MakeDir(char **argp)
718 {
719     struct afsFetchStatus OutDirStatus, OutFidStatus;
720     struct afsStoreStatus InStatus;
721     struct afsVolSync tsync;
722     struct afsFid fid, outFid;
723     struct afsToken Token;
724     char *name;
725     int vnode, unique, mode, owner, length;
726     int code;
727
728     sscanf(&(*argp)[0], "%d", &vnode);
729     ++argp;
730     sscanf(&(*argp)[0], "%d", &unique);
731     ++argp;
732     memset(&fid, 0, sizeof(struct afsFid));
733     fid.Volume.low = 10;        /* XXX */
734     fid.Vnode = vnode;
735     fid.Unique = unique;
736     name = &argp[0][0];
737     ++argp;
738     memset(&InStatus, 0, sizeof(struct afsStoreStatus));
739     sscanf(&(*argp)[0], "%d", &mode);
740     ++argp;
741     sscanf(&(*argp)[0], "%d", &owner);
742     ++argp;
743     sscanf(&(*argp)[0], "%d", &length);
744     ++argp;
745     if (mode != -1) {
746         InStatus.mode = mode;
747         InStatus.mask |= AFS_SETMODE;
748     }
749     if (owner != -1) {
750         InStatus.owner = owner;
751         InStatus.mask |= AFS_SETOWNER;
752     }
753     if (length != -1) {
754         InStatus.length = length;
755         InStatus.mask |= AFS_SETLENGTH;
756     }
757     code =
758         ubik_AFS_MakeDir(cstruct, 0, &fid, name, &InStatus, &hyp0, 0,
759                   &outFid, &OutFidStatus, &OutDirStatus, &Token, &tsync);
760     return (code);
761 }
762
763
764 afs_int32
765 RemoveDir(char **argp)
766 {
767     struct afsFetchStatus OutDirStatus;
768     struct afsVolSync tsync;
769     struct afsFid fid, outFid;
770     struct afsFidName nameFid;
771     char *name;
772     int vnode, unique;
773     int code;
774
775     sscanf(&(*argp)[0], "%d", &vnode);
776     ++argp;
777     sscanf(&(*argp)[0], "%d", &unique);
778     ++argp;
779     memset(&fid, 0, sizeof(struct afsFid));
780     fid.Volume.low = 10;        /* XXX */
781     fid.Vnode = vnode;
782     fid.Unique = unique;
783     name = &argp[0][0];
784     ++argp;
785     memset(&nameFid, 0, sizeof(struct afsFidName));
786     strcpy(nameFid.name, name);
787     code =
788         ubik_AFS_RemoveDir(cstruct, 0, &fid, &nameFid, &hyp0, 0,
789                   &OutDirStatus, &outFid, &tsync);
790     return (code);
791 }
792
793
794 afs_int32
795 Readdir(char **argp)
796 {
797     struct afsFetchStatus OutDirStatus;
798     struct afsVolSync tsync;
799     struct afsFid fid;
800     struct afsToken Token;
801     char *name;
802     struct rx_call *tcall;
803     int vnode, unique, offset, length, NextOffset;
804     int code;
805
806     sscanf(&(*argp)[0], "%d", &vnode);
807     ++argp;
808     sscanf(&(*argp)[0], "%d", &unique);
809     ++argp;
810     sscanf(&(*argp)[0], "%d", &offset);
811     ++argp;
812     sscanf(&(*argp)[0], "%d", &length);
813     ++argp;
814     memset(&fid, 0, sizeof(struct afsFid));
815     fid.Volume.low = 10;        /* XXX */
816     fid.Vnode = vnode;
817     fid.Unique = unique;
818     tcall = rx_NewCall(cstruct->conns[0]);
819     code = StartAFS_Readdir(tcall, &fid, offset, length, &hyp0, 0);
820     if (!code) {
821         code = FetchDir(tcall);
822     }
823     if (!code) {
824         code =
825             EndAFS_FetchData(tcall, &NextOffset, &OutDirStatus, &Token,
826                              &tsync);
827     }
828     code = rx_EndCall(tcall, code);
829     return (code);
830 }
831
832
833 static afs_int32
834 FetchDir(struct rx_call *acall)
835 {
836     char *tbuffer;
837     afs_int32 tlen, length, code;
838     struct dirent *dp;
839
840
841     tbuffer = malloc(256);
842     while (1) {
843         code = rx_Read(acall, &length, sizeof(afs_int32));
844         length = ntohl(length);
845         if (code != sizeof(afs_int32))
846             return -1;
847         if (length == 0)
848             break;
849         tlen = (length > 8192 ? 8192 : length);
850         code = rx_Read(acall, tbuffer, tlen);
851         if (code != tlen) {
852             free(tbuffer);
853             return -1;
854         }
855         length -= tlen;
856     }
857     dp = (struct dirent *)dp;
858     free(tbuffer);
859     return 0;
860 }
861
862
863 afs_int32
864 Lookup(char **argp)
865 {
866     struct afsFetchStatus OutDirStatus, OutFidStatus;
867     struct afsVolSync tsync;
868     struct afsFid fid, outFid;
869     char *name;
870     int vnode, unique;
871     int code;
872
873     sscanf(&(*argp)[0], "%d", &vnode);
874     ++argp;
875     sscanf(&(*argp)[0], "%d", &unique);
876     ++argp;
877     memset(&fid, 0, sizeof(struct afsFid));
878     fid.Volume.low = 10;        /* XXX */
879     fid.Vnode = vnode;
880     fid.Unique = unique;
881     name = &argp[0][0];
882     ++argp;
883     code =
884         ubik_AFS_Lookup(cstruct, 0, &fid, name, &hyp0, 0, &outFid,
885                   &OutFidStatus, &OutDirStatus, &tsync);
886     return (code);
887 }
888
889
890 afs_int32
891 GetToken(char **argp)
892 {
893     struct afsFetchStatus OutStatus;
894     struct afsVolSync tsync;
895     struct afsToken MinToken, RealToken;
896     struct afsFid fid;
897     int vnode, unique, tokenId;
898     int code;
899
900     sscanf(&(*argp)[0], "%d", &vnode);
901     ++argp;
902     sscanf(&(*argp)[0], "%d", &unique);
903     ++argp;
904     memset(&fid, 0, sizeof(struct afsFid));
905     fid.Volume.low = 10;        /* XXX */
906     fid.Vnode = vnode;
907     fid.Unique = unique;
908     sscanf(&(*argp)[0], "%d", &tokenId);
909     ++argp;
910     memset(&MinToken, 0, sizeof(struct afsToken));
911     MinToken.tokenID.low = tokenId;     /* XXX */
912     code =
913         ubik_AFS_GetToken(cstruct, 0, &fid, &MinToken, &hyp0, 0,
914                   &RealToken, &OutStatus, &tsync);
915     return (code);
916 }
917
918
919 afs_int32
920 MakeMountPoint(char **argp)
921 {
922 }
923
924
925 afs_int32
926 ReleaseTokens(char **argp)
927 {
928 }
929
930
931 afs_int32
932 BulkStatus(char **argp)
933 {
934 }
935
936 /*  printf("ka <vol.l> <vnode> <unique> <isExec> <kaTime>\n"); */
937 afs_int32
938 KeepAlive(char **argp)
939 {
940     struct afsBulkFEX fex;
941     afs_uint32 numExec, spare4;
942     struct afsFidExp fx;
943     int code;
944
945     memset(&fx, 0, sizeof(struct afsFidExp));
946     sscanf(&(*argp)[0], "%d", &fx.fid.Volume.low);
947     ++argp;
948     sscanf(&(*argp)[0], "%d", &fx.fid.Vnode);
949     ++argp;
950     sscanf(&(*argp)[0], "%d", &fx.fid.Unique);
951     ++argp;
952     sscanf(&(*argp)[0], "%d", &numExec);
953     ++argp;
954     sscanf(&(*argp)[0], "%d", &fx.keepAliveTime);
955     memset(&fex, 0, sizeof(struct afsBulkFEX));
956     fex.afsBulkFEX_val = &fx;
957     fex.afsBulkFEX_len = 1;
958     code =
959         ubik_AFS_BulkKeepAlive(cstruct, 0, &fex, numExec, 0, 0, 0,
960                   &spare4);
961     return (code);
962 }
963 #endif /* notdef */