2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 #include <afsconfig.h>
11 #include <afs/param.h>
16 #include <afs/afsint.h>
17 #include <rx/rx_globals.h>
20 struct ubik_client *cstruct;
21 struct rx_connection *serverconns[MAXSERVERS];
25 pxclient_Initialize(int auth, afs_int32 serverAddr)
28 rx_securityIndex scIndex;
29 struct rx_securityClass *sc;
31 code = rx_Init(htons(2115) /*0 */ );
33 fprintf(stderr, "pxclient_Initialize: Could not initialize rx.\n");
36 scIndex = RX_SECIDX_NULL;
38 sc = rxnull_NewClientSecurityObject();
40 rx_NewConnection(serverAddr, htons(7000), 1, sc, scIndex);
42 code = ubik_ClientInit(serverconns, &cstruct);
45 fprintf(stderr, "pxclient_Initialize: ubik client init failed.\n");
53 #include "AFS_component_version_number.c"
56 main(int argc, char **argv)
59 struct sockaddr_in host;
64 int noAuth = 1; /* Default is authenticated connections */
68 printf("usage: fsprobe <serverHost>\n");
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);
77 if (host.sin_addr.s_addr != -1) {
78 strcpy(hnamebuf, av[0]);
80 hp = gethostbyname(av[0]);
82 host.sin_family = hp->h_addrtype;
83 memcpy((caddr_t) & host.sin_addr, hp->h_addr, hp->h_length);
85 printf("unknown server host %s\n", av[0]);
89 if ((code = pxclient_Initialize(noAuth, host.sin_addr.s_addr)) != 0) {
90 printf("Couldn't initialize fs library (code=%d).\n", code);
94 code = RXAFS_GetTime(cstruct->conns[0], (afs_uint32 *)&tv.tv_sec, (afs_uint32 *)&tv.tv_usec);
96 printf("AFS_GetTime on %s sec=%ld, usec=%ld\n", av[0], tv.tv_sec,
97 (long int)tv.tv_usec);
99 printf("return code is %d\n", code);
107 if (fgets(line, 499, stdin) != NULL) {
110 GetArgs(line, argp, &nargs);
113 if (!strcmp(oper, "probe")) {
115 ubik_Call(RXAFS_GetTime, cstruct, 0, &tv.tv_sec,
117 printf("return code is %d\n", code);
119 printf("sec=%d\n", tv.tv_sec);
120 } else if (!strcmp(oper, "fsstats")) {
121 struct afsStatistics stats;
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")) {
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")) {
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"))
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");
193 ("sd <vnode> <unique> <pos> <len> <flen> [<mode>|-1] [<owner>|-1] [<length>|-1] <string>\n");
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");
199 ("cf <vnode> <unique> <name> [<mode>|-1] [<owner>|-1] [<length>|-1]\n");
201 ("rn <ovnode> <ounique> <oname> <nvnode> <nunique> <nname>\n");
203 ("sl <vnode> <unique> <name> <contents> [<mode>|-1] [<owner>|-1] [<length>|-1]\n");
204 printf("hl <dvnode> <dunique> <name> <evnode> <eunique>\n");
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");
221 GetArgs(char *line, char **args, int *nargs)
232 *args++ = line, (*nargs)++;
233 while (*line && *line != ' ')
240 FetchData(char **argp)
242 struct afsFetchStatus OutStatus;
243 struct afsToken Token;
244 struct afsVolSync tsync;
246 int vnode, unique, position, length;
248 struct rx_call *tcall;
250 sscanf(&(*argp)[0], "%d", &vnode);
252 sscanf(&(*argp)[0], "%d", &unique);
254 memset(&fid, 0, sizeof(struct afsFid));
255 fid.Volume.low = 10; /* XXX */
258 sscanf(&(*argp)[0], "%d", &position);
260 sscanf(&(*argp)[0], "%d", &length);
262 tcall = rx_NewCall(cstruct->conns[0]);
263 code = StartAFS_FetchData(tcall, &fid, &hyp0, position, length, 0);
265 code = FetchProc(tcall);
268 code = EndAFS_FetchData(tcall, &OutStatus, &Token, &tsync);
270 code = rx_EndCall(tcall, code);
276 FetchProc(struct rx_call *acall)
278 extern char *malloc();
280 afs_int32 tlen, length, code;
282 code = rx_Read(acall, &length, sizeof(afs_int32));
283 length = ntohl(length);
284 if (code != sizeof(afs_int32))
286 tbuffer = malloc(256);
288 tlen = (length > 256 ? 256 : length);
289 code = rx_Read(acall, tbuffer, tlen);
302 FetchStatus(char **argp)
304 struct afsFetchStatus OutStatus;
305 struct afsToken Token;
306 struct afsVolSync tsync;
311 sscanf(&(*argp)[0], "%d", &vnode);
313 sscanf(&(*argp)[0], "%d", &unique);
315 memset(&fid, 0, sizeof(struct afsFid));
316 fid.Volume.low = 10; /* XXX */
320 ubik_AFS_FetchStatus(cstruct, 0, &fid, &hyp0, 0, &OutStatus,
327 FetchACL(char **argp)
329 struct afsFetchStatus OutStatus;
330 struct afsACL AccessList;
331 struct afsToken Token;
332 struct afsVolSync tsync;
337 sscanf(&(*argp)[0], "%d", &vnode);
339 sscanf(&(*argp)[0], "%d", &unique);
341 memset(&fid, 0, sizeof(struct afsFid));
342 fid.Volume.low = 10; /* XXX */
346 ubik_AFS_FetchACL(cstruct, 0, &fid, &hyp0, 0, &AccessList,
353 StoreData(char **argp)
355 struct afsStoreStatus InStatus;
356 struct afsFetchStatus OutStatus;
357 struct afsVolSync tsync;
359 int vnode, unique, position, length, filelength;
360 int mode, owner, len;
363 struct rx_call *tcall;
365 sscanf(&(*argp)[0], "%d", &vnode);
367 sscanf(&(*argp)[0], "%d", &unique);
369 memset(&fid, 0, sizeof(struct afsFid));
370 fid.Volume.low = 10; /* XXX */
373 sscanf(&(*argp)[0], "%d", &position);
375 sscanf(&(*argp)[0], "%d", &length);
377 sscanf(&(*argp)[0], "%d", &filelength);
379 memset(&InStatus, 0, sizeof(struct afsStoreStatus));
380 sscanf(&(*argp)[0], "%d", &mode);
382 sscanf(&(*argp)[0], "%d", &owner);
384 sscanf(&(*argp)[0], "%d", &len);
387 InStatus.mode = mode;
388 InStatus.mask |= AFS_SETMODE;
391 InStatus.owner = owner;
392 InStatus.mask |= AFS_SETOWNER;
395 InStatus.length = length;
396 InStatus.mask |= AFS_SETLENGTH;
398 string = &argp[0][0];
401 tcall = rx_NewCall(cstruct->conns[0]);
403 StartAFS_StoreData(tcall, &fid, &InStatus, position, length,
404 filelength, &hyp0, 0);
406 code = StoreProc(tcall, string, length);
409 code = EndAFS_StoreData(tcall, &OutStatus, &tsync);
411 code = rx_EndCall(tcall, code);
417 StoreProc(struct rx_call *acall, char *string, int length)
419 afs_int32 tlen, code;
422 tlen = (length > 256 ? 256 : length);
423 code = rx_Write(acall, string, tlen);
434 StoreStatus(char **argp)
436 struct afsStoreStatus InStatus;
437 struct afsFetchStatus OutStatus;
438 struct afsVolSync tsync;
440 int vnode, unique, mode, owner, length;
443 sscanf(&(*argp)[0], "%d", &vnode);
445 sscanf(&(*argp)[0], "%d", &unique);
447 memset(&fid, 0, sizeof(struct afsFid));
448 fid.Volume.low = 10; /* XXX */
451 memset(&InStatus, 0, sizeof(struct afsStoreStatus));
452 sscanf(&(*argp)[0], "%d", &mode);
454 sscanf(&(*argp)[0], "%d", &owner);
456 sscanf(&(*argp)[0], "%d", &length);
459 InStatus.mode = mode;
460 InStatus.mask |= AFS_SETMODE;
463 InStatus.owner = owner;
464 InStatus.mask |= AFS_SETOWNER;
467 InStatus.length = length;
468 InStatus.mask |= AFS_SETLENGTH;
471 ubik_AFS_StoreStatus(cstruct, 0, &fid, &InStatus, &hyp0, 0,
478 StoreACL(char **argp)
480 struct afsFetchStatus OutStatus;
481 struct afsACL AccessList;
482 struct afsToken Token;
483 struct afsVolSync tsync;
489 sscanf(&(*argp)[0], "%d", &vnode);
491 sscanf(&(*argp)[0], "%d", &unique);
493 memset(&fid, 0, sizeof(struct afsFid));
494 fid.Volume.low = 10; /* XXX */
497 string = &argp[0][0];
499 AccessList.afsACL_len = strlen(string) + 1;
500 AccessList.afsACL_val = string;
502 ubik_AFS_StoreACL(cstruct, 0, &fid, &AccessList, &hyp0, 0,
509 RemoveFile(char **argp)
511 struct afsFetchStatus OutDirStatus, OutFidStatus;
512 struct afsVolSync tsync;
513 struct afsFidName nameFid;
514 struct afsFid fid, outFid;
519 sscanf(&(*argp)[0], "%d", &vnode);
521 sscanf(&(*argp)[0], "%d", &unique);
523 memset(&fid, 0, sizeof(struct afsFid));
524 fid.Volume.low = 10; /* XXX */
529 memset(&nameFid, 0, sizeof(struct afsFidName));
530 strcpy(nameFid.name, name);
532 ubik_AFS_RemoveFile(cstruct, 0, &fid, &nameFid, &hyp0, 0,
533 &OutDirStatus, &OutFidStatus, &outFid, &tsync);
539 CreateFile(char **argp)
541 struct afsFetchStatus OutDirStatus, OutFidStatus;
542 struct afsStoreStatus InStatus;
543 struct afsVolSync tsync;
544 struct afsFid fid, outFid;
545 struct afsToken Token;
547 int vnode, unique, mode, owner, length;
550 sscanf(&(*argp)[0], "%d", &vnode);
552 sscanf(&(*argp)[0], "%d", &unique);
554 memset(&fid, 0, sizeof(struct afsFid));
555 fid.Volume.low = 10; /* XXX */
560 memset(&InStatus, 0, sizeof(struct afsStoreStatus));
561 sscanf(&(*argp)[0], "%d", &mode);
563 sscanf(&(*argp)[0], "%d", &owner);
565 sscanf(&(*argp)[0], "%d", &length);
568 InStatus.mode = mode;
569 InStatus.mask |= AFS_SETMODE;
572 InStatus.owner = owner;
573 InStatus.mask |= AFS_SETOWNER;
576 InStatus.length = length;
577 InStatus.mask |= AFS_SETLENGTH;
580 ubik_AFS_CreateFile(cstruct, 0, &fid, name, &InStatus, &hyp0, 0,
581 &outFid, &OutFidStatus, &OutDirStatus, &Token, &tsync);
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;
595 int ovnode, ounique, nvnode, nunique;
598 sscanf(&(*argp)[0], "%d", &ovnode);
600 sscanf(&(*argp)[0], "%d", &ounique);
602 memset(&OldDirFid, 0, sizeof(struct afsFid));
603 OldDirFid.Volume.low = 10; /* XXX */
604 OldDirFid.Vnode = ovnode;
605 OldDirFid.Unique = ounique;
608 memset(&OldName, 0, sizeof(struct afsFidName));
609 strcpy(OldName.name, oname);
610 sscanf(&(*argp)[0], "%d", &nvnode);
612 sscanf(&(*argp)[0], "%d", &nunique);
614 memset(&NewDirFid, 0, sizeof(struct afsFid));
615 NewDirFid.Volume.low = 10; /* XXX */
616 NewDirFid.Vnode = nvnode;
617 NewDirFid.Unique = nunique;
620 memset(&NewName, 0, sizeof(struct afsFidName));
621 strcpy(NewName.name, nname);
623 ubik_AFS_Rename(cstruct, 0, &OldDirFid, &OldName, &NewDirFid,
624 &NewName, &hyp0, 0, &OutOldDirStatus, &OutNewDirStatus,
625 &OutOldFileFid, &OutOldFileStatus, &OutNewFileFid,
626 &OutNewFileStatus, &tsync);
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;
643 sscanf(&(*argp)[0], "%d", &vnode);
645 sscanf(&(*argp)[0], "%d", &unique);
647 memset(&fid, 0, sizeof(struct afsFid));
648 fid.Volume.low = 10; /* XXX */
653 linkcontents = &argp[0][0];
655 memset(&InStatus, 0, sizeof(struct afsStoreStatus));
656 sscanf(&(*argp)[0], "%d", &mode);
658 sscanf(&(*argp)[0], "%d", &owner);
660 sscanf(&(*argp)[0], "%d", &length);
663 InStatus.mode = mode;
664 InStatus.mask |= AFS_SETMODE;
667 InStatus.owner = owner;
668 InStatus.mask |= AFS_SETOWNER;
671 InStatus.length = length;
672 InStatus.mask |= AFS_SETLENGTH;
675 ubik_AFS_Symlink(cstruct, 0, &fid, name, linkcontents,
676 &InStatus, &hyp0, 0, &outFid, &OutFidStatus, &OutDirStatus,
683 HardLink(char **argp)
685 struct afsFetchStatus OutDirStatus, OutFidStatus;
686 struct afsVolSync tsync;
687 struct afsFid fid, existingFid;
692 sscanf(&(*argp)[0], "%d", &vnode);
694 sscanf(&(*argp)[0], "%d", &unique);
696 memset(&fid, 0, sizeof(struct afsFid));
697 fid.Volume.low = 10; /* XXX */
702 sscanf(&(*argp)[0], "%d", &vnode);
704 sscanf(&(*argp)[0], "%d", &unique);
706 memset(&existingFid, 0, sizeof(struct afsFid));
707 existingFid.Volume.low = 10; /* XXX */
708 existingFid.Vnode = vnode;
709 existingFid.Unique = unique;
711 ubik_AFS_HardLink(cstruct, 0, &fid, name, &existingFid, &hyp0,
712 0, &OutFidStatus, &OutDirStatus, &tsync);
720 struct afsFetchStatus OutDirStatus, OutFidStatus;
721 struct afsStoreStatus InStatus;
722 struct afsVolSync tsync;
723 struct afsFid fid, outFid;
724 struct afsToken Token;
726 int vnode, unique, mode, owner, length;
729 sscanf(&(*argp)[0], "%d", &vnode);
731 sscanf(&(*argp)[0], "%d", &unique);
733 memset(&fid, 0, sizeof(struct afsFid));
734 fid.Volume.low = 10; /* XXX */
739 memset(&InStatus, 0, sizeof(struct afsStoreStatus));
740 sscanf(&(*argp)[0], "%d", &mode);
742 sscanf(&(*argp)[0], "%d", &owner);
744 sscanf(&(*argp)[0], "%d", &length);
747 InStatus.mode = mode;
748 InStatus.mask |= AFS_SETMODE;
751 InStatus.owner = owner;
752 InStatus.mask |= AFS_SETOWNER;
755 InStatus.length = length;
756 InStatus.mask |= AFS_SETLENGTH;
759 ubik_AFS_MakeDir(cstruct, 0, &fid, name, &InStatus, &hyp0, 0,
760 &outFid, &OutFidStatus, &OutDirStatus, &Token, &tsync);
766 RemoveDir(char **argp)
768 struct afsFetchStatus OutDirStatus;
769 struct afsVolSync tsync;
770 struct afsFid fid, outFid;
771 struct afsFidName nameFid;
776 sscanf(&(*argp)[0], "%d", &vnode);
778 sscanf(&(*argp)[0], "%d", &unique);
780 memset(&fid, 0, sizeof(struct afsFid));
781 fid.Volume.low = 10; /* XXX */
786 memset(&nameFid, 0, sizeof(struct afsFidName));
787 strcpy(nameFid.name, name);
789 ubik_AFS_RemoveDir(cstruct, 0, &fid, &nameFid, &hyp0, 0,
790 &OutDirStatus, &outFid, &tsync);
798 struct afsFetchStatus OutDirStatus;
799 struct afsVolSync tsync;
801 struct afsToken Token;
803 struct rx_call *tcall;
804 int vnode, unique, offset, length, NextOffset;
807 sscanf(&(*argp)[0], "%d", &vnode);
809 sscanf(&(*argp)[0], "%d", &unique);
811 sscanf(&(*argp)[0], "%d", &offset);
813 sscanf(&(*argp)[0], "%d", &length);
815 memset(&fid, 0, sizeof(struct afsFid));
816 fid.Volume.low = 10; /* XXX */
819 tcall = rx_NewCall(cstruct->conns[0]);
820 code = StartAFS_Readdir(tcall, &fid, offset, length, &hyp0, 0);
822 code = FetchDir(tcall);
826 EndAFS_FetchData(tcall, &NextOffset, &OutDirStatus, &Token,
829 code = rx_EndCall(tcall, code);
835 FetchDir(struct rx_call *acall)
837 extern char *malloc();
839 afs_int32 tlen, length, code;
843 tbuffer = malloc(256);
845 code = rx_Read(acall, &length, sizeof(afs_int32));
846 length = ntohl(length);
847 if (code != sizeof(afs_int32))
851 tlen = (length > 8192 ? 8192 : length);
852 code = rx_Read(acall, tbuffer, tlen);
859 dp = (struct dirent *)dp;
868 struct afsFetchStatus OutDirStatus, OutFidStatus;
869 struct afsVolSync tsync;
870 struct afsFid fid, outFid;
875 sscanf(&(*argp)[0], "%d", &vnode);
877 sscanf(&(*argp)[0], "%d", &unique);
879 memset(&fid, 0, sizeof(struct afsFid));
880 fid.Volume.low = 10; /* XXX */
886 ubik_AFS_Lookup(cstruct, 0, &fid, name, &hyp0, 0, &outFid,
887 &OutFidStatus, &OutDirStatus, &tsync);
893 GetToken(char **argp)
895 struct afsFetchStatus OutStatus;
896 struct afsVolSync tsync;
897 struct afsToken MinToken, RealToken;
899 int vnode, unique, tokenId;
902 sscanf(&(*argp)[0], "%d", &vnode);
904 sscanf(&(*argp)[0], "%d", &unique);
906 memset(&fid, 0, sizeof(struct afsFid));
907 fid.Volume.low = 10; /* XXX */
910 sscanf(&(*argp)[0], "%d", &tokenId);
912 memset(&MinToken, 0, sizeof(struct afsToken));
913 MinToken.tokenID.low = tokenId; /* XXX */
915 ubik_AFS_GetToken(cstruct, 0, &fid, &MinToken, &hyp0, 0,
916 &RealToken, &OutStatus, &tsync);
922 MakeMountPoint(char **argp)
928 ReleaseTokens(char **argp)
934 BulkStatus(char **argp)
938 /* printf("ka <vol.l> <vnode> <unique> <isExec> <kaTime>\n"); */
940 KeepAlive(char **argp)
942 struct afsBulkFEX fex;
943 afs_uint32 numExec, spare4;
947 memset(&fx, 0, sizeof(struct afsFidExp));
948 sscanf(&(*argp)[0], "%d", &fx.fid.Volume.low);
950 sscanf(&(*argp)[0], "%d", &fx.fid.Vnode);
952 sscanf(&(*argp)[0], "%d", &fx.fid.Unique);
954 sscanf(&(*argp)[0], "%d", &numExec);
956 sscanf(&(*argp)[0], "%d", &fx.keepAliveTime);
957 memset(&fex, 0, sizeof(struct afsBulkFEX));
958 fex.afsBulkFEX_val = &fx;
959 fex.afsBulkFEX_len = 1;
961 ubik_AFS_BulkKeepAlive(cstruct, 0, &fex, numExec, 0, 0, 0,