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;
63 int noAuth = 1; /* Default is authenticated connections */
67 printf("usage: fsprobe <serverHost>\n");
70 memset(&host, 0, sizeof(struct sockaddr_in));
71 host.sin_family = AF_INET;
72 host.sin_addr.s_addr = inet_addr(av[0]);
73 #ifdef STRUCT_SOCKADDR_HAS_SA_LEN
74 host.sin_len = sizeof(struct sockaddr_in);
76 if (host.sin_addr.s_addr == -1) {
77 hp = gethostbyname(av[0]);
79 host.sin_family = hp->h_addrtype;
80 memcpy((caddr_t) & host.sin_addr, hp->h_addr, hp->h_length);
82 printf("unknown server host %s\n", av[0]);
86 if ((code = pxclient_Initialize(noAuth, host.sin_addr.s_addr)) != 0) {
87 printf("Couldn't initialize fs library (code=%d).\n", code);
91 code = RXAFS_GetTime(cstruct->conns[0], (afs_uint32 *)&tv.tv_sec, (afs_uint32 *)&tv.tv_usec);
93 printf("AFS_GetTime on %s sec=%ld, usec=%ld\n", av[0], (long)tv.tv_sec,
96 printf("return code is %d\n", code);
104 if (fgets(line, 499, stdin) != NULL) {
107 GetArgs(line, argp, &nargs);
110 if (!strcmp(oper, "probe")) {
112 ubik_Call(RXAFS_GetTime, cstruct, 0, &tv.tv_sec,
114 printf("return code is %d\n", code);
116 printf("sec=%d\n", tv.tv_sec);
117 } else if (!strcmp(oper, "fsstats")) {
118 struct afsStatistics stats;
120 code = ubik_AFS_GetStatistics(cstruct, 0, &stats);
121 printf("return code is %d\n", code);
122 } else if (!strcmp(oper, "fd")) {
123 code = FetchData(argp);
124 printf("return code is %d\n", code);
125 } else if (!strcmp(oper, "fs")) {
126 code = FetchStatus(argp);
127 printf("return code is %d\n", code);
128 } else if (!strcmp(oper, "fa")) {
129 code = FetchACL(argp);
130 printf("return code is %d\n", code);
131 } else if (!strcmp(oper, "sd")) {
132 code = StoreData(argp);
133 printf("return code is %d\n", code);
134 } else if (!strcmp(oper, "ss")) {
135 code = StoreStatus(argp);
136 printf("return code is %d\n", code);
137 } else if (!strcmp(oper, "sa")) {
138 code = StoreACL(argp);
139 printf("return code is %d\n", code);
140 } else if (!strcmp(oper, "cf")) {
141 code = CreateFile(argp);
142 printf("return code is %d\n", code);
143 } else if (!strcmp(oper, "rf")) {
144 code = RemoveFile(argp);
145 printf("return code is %d\n", code);
146 } else if (!strcmp(oper, "rn")) {
148 printf("return code is %d\n", code);
149 } else if (!strcmp(oper, "sl")) {
150 code = Symlink(argp);
151 printf("return code is %d\n", code);
152 } else if (!strcmp(oper, "hl")) {
153 code = HardLink(argp);
154 printf("return code is %d\n", code);
155 } else if (!strcmp(oper, "md")) {
156 code = MakeDir(argp);
157 printf("return code is %d\n", code);
158 } else if (!strcmp(oper, "rd")) {
159 code = RemoveDir(argp);
160 printf("return code is %d\n", code);
161 } else if (!strcmp(oper, "rdd")) {
162 code = Readdir(argp);
163 printf("return code is %d\n", code);
164 } else if (!strcmp(oper, "mm")) {
165 code = MakeMountPoint(argp);
166 printf("return code is %d\n", code);
167 } else if (!strcmp(oper, "rt")) {
168 code = ReleaseTokens(argp);
169 printf("return code is %d\n", code);
170 } else if (!strcmp(oper, "bs")) {
171 code = BulkStatus(argp);
172 printf("return code is %d\n", code);
173 } else if (!strcmp(oper, "lk")) {
175 printf("return code is %d\n", code);
176 } else if (!strcmp(oper, "gt")) {
177 code = GetToken(argp);
178 printf("return code is %d\n", code);
179 } else if (!strcmp(oper, "ka")) {
180 code = KeepAlive(argp);
181 printf("return code is %d\n", code);
182 } else if ((!strcmp(oper, "q")) || !strcmp(oper, "quit"))
185 printf("Unknown oper! Available operations: \n\n");
186 printf("fd <vnode> <unique> <pos> <len>\n");
187 printf("fs <vnode> <unique>\n");
188 printf("fa <vnode> <unique>\n");
190 ("sd <vnode> <unique> <pos> <len> <flen> [<mode>|-1] [<owner>|-1] [<length>|-1] <string>\n");
192 ("ss <vnode> <unique> [<mode>|-1] [<owner>|-1] [<length>|-1]\n");
193 printf("sa <vnode> <unique> <string>\n");
194 printf("rf <vnode> <unique> <name>\n");
196 ("cf <vnode> <unique> <name> [<mode>|-1] [<owner>|-1] [<length>|-1]\n");
198 ("rn <ovnode> <ounique> <oname> <nvnode> <nunique> <nname>\n");
200 ("sl <vnode> <unique> <name> <contents> [<mode>|-1] [<owner>|-1] [<length>|-1]\n");
201 printf("hl <dvnode> <dunique> <name> <evnode> <eunique>\n");
203 ("md <vnode> <unique> <name> [<mode>|-1] [<owner>|-1] [<length>|-1]\n");
204 printf("rd <vnode> <unique> <name>\n");
205 printf("rdd <vnode> <unique> <pos> <len>\n");
206 printf("lk <vnode> <unique> <name>\n");
207 printf("gt <vnode> <unique> <tokenID>\n");
208 printf("ka <vol.l> <vnode> <unique> <isExec> <kaTime>\n");
218 GetArgs(char *line, char **args, int *nargs)
229 *args++ = line, (*nargs)++;
230 while (*line && *line != ' ')
237 FetchData(char **argp)
239 struct afsFetchStatus OutStatus;
240 struct afsToken Token;
241 struct afsVolSync tsync;
243 int vnode, unique, position, length;
245 struct rx_call *tcall;
247 sscanf(&(*argp)[0], "%d", &vnode);
249 sscanf(&(*argp)[0], "%d", &unique);
251 memset(&fid, 0, sizeof(struct afsFid));
252 fid.Volume.low = 10; /* XXX */
255 sscanf(&(*argp)[0], "%d", &position);
257 sscanf(&(*argp)[0], "%d", &length);
259 tcall = rx_NewCall(cstruct->conns[0]);
260 code = StartAFS_FetchData(tcall, &fid, &hyp0, position, length, 0);
262 code = FetchProc(tcall);
265 code = EndAFS_FetchData(tcall, &OutStatus, &Token, &tsync);
267 code = rx_EndCall(tcall, code);
273 FetchProc(struct rx_call *acall)
276 afs_int32 tlen, length, code;
278 code = rx_Read(acall, &length, sizeof(afs_int32));
279 length = ntohl(length);
280 if (code != sizeof(afs_int32))
282 tbuffer = malloc(256);
284 tlen = (length > 256 ? 256 : length);
285 code = rx_Read(acall, tbuffer, tlen);
298 FetchStatus(char **argp)
300 struct afsFetchStatus OutStatus;
301 struct afsToken Token;
302 struct afsVolSync tsync;
307 sscanf(&(*argp)[0], "%d", &vnode);
309 sscanf(&(*argp)[0], "%d", &unique);
311 memset(&fid, 0, sizeof(struct afsFid));
312 fid.Volume.low = 10; /* XXX */
316 ubik_AFS_FetchStatus(cstruct, 0, &fid, &hyp0, 0, &OutStatus,
323 FetchACL(char **argp)
325 struct afsFetchStatus OutStatus;
326 struct afsACL AccessList;
327 struct afsToken Token;
328 struct afsVolSync tsync;
333 sscanf(&(*argp)[0], "%d", &vnode);
335 sscanf(&(*argp)[0], "%d", &unique);
337 memset(&fid, 0, sizeof(struct afsFid));
338 fid.Volume.low = 10; /* XXX */
342 ubik_AFS_FetchACL(cstruct, 0, &fid, &hyp0, 0, &AccessList,
349 StoreData(char **argp)
351 struct afsStoreStatus InStatus;
352 struct afsFetchStatus OutStatus;
353 struct afsVolSync tsync;
355 int vnode, unique, position, length, filelength;
356 int mode, owner, len;
359 struct rx_call *tcall;
361 sscanf(&(*argp)[0], "%d", &vnode);
363 sscanf(&(*argp)[0], "%d", &unique);
365 memset(&fid, 0, sizeof(struct afsFid));
366 fid.Volume.low = 10; /* XXX */
369 sscanf(&(*argp)[0], "%d", &position);
371 sscanf(&(*argp)[0], "%d", &length);
373 sscanf(&(*argp)[0], "%d", &filelength);
375 memset(&InStatus, 0, sizeof(struct afsStoreStatus));
376 sscanf(&(*argp)[0], "%d", &mode);
378 sscanf(&(*argp)[0], "%d", &owner);
380 sscanf(&(*argp)[0], "%d", &len);
383 InStatus.mode = mode;
384 InStatus.mask |= AFS_SETMODE;
387 InStatus.owner = owner;
388 InStatus.mask |= AFS_SETOWNER;
391 InStatus.length = length;
392 InStatus.mask |= AFS_SETLENGTH;
394 string = &argp[0][0];
397 tcall = rx_NewCall(cstruct->conns[0]);
399 StartAFS_StoreData(tcall, &fid, &InStatus, position, length,
400 filelength, &hyp0, 0);
402 code = StoreProc(tcall, string, length);
405 code = EndAFS_StoreData(tcall, &OutStatus, &tsync);
407 code = rx_EndCall(tcall, code);
413 StoreProc(struct rx_call *acall, char *string, int length)
415 afs_int32 tlen, code;
418 tlen = (length > 256 ? 256 : length);
419 code = rx_Write(acall, string, tlen);
430 StoreStatus(char **argp)
432 struct afsStoreStatus InStatus;
433 struct afsFetchStatus OutStatus;
434 struct afsVolSync tsync;
436 int vnode, unique, mode, owner, length;
439 sscanf(&(*argp)[0], "%d", &vnode);
441 sscanf(&(*argp)[0], "%d", &unique);
443 memset(&fid, 0, sizeof(struct afsFid));
444 fid.Volume.low = 10; /* XXX */
447 memset(&InStatus, 0, sizeof(struct afsStoreStatus));
448 sscanf(&(*argp)[0], "%d", &mode);
450 sscanf(&(*argp)[0], "%d", &owner);
452 sscanf(&(*argp)[0], "%d", &length);
455 InStatus.mode = mode;
456 InStatus.mask |= AFS_SETMODE;
459 InStatus.owner = owner;
460 InStatus.mask |= AFS_SETOWNER;
463 InStatus.length = length;
464 InStatus.mask |= AFS_SETLENGTH;
467 ubik_AFS_StoreStatus(cstruct, 0, &fid, &InStatus, &hyp0, 0,
474 StoreACL(char **argp)
476 struct afsFetchStatus OutStatus;
477 struct afsACL AccessList;
478 struct afsToken Token;
479 struct afsVolSync tsync;
485 sscanf(&(*argp)[0], "%d", &vnode);
487 sscanf(&(*argp)[0], "%d", &unique);
489 memset(&fid, 0, sizeof(struct afsFid));
490 fid.Volume.low = 10; /* XXX */
493 string = &argp[0][0];
495 AccessList.afsACL_len = strlen(string) + 1;
496 AccessList.afsACL_val = string;
498 ubik_AFS_StoreACL(cstruct, 0, &fid, &AccessList, &hyp0, 0,
505 RemoveFile(char **argp)
507 struct afsFetchStatus OutDirStatus, OutFidStatus;
508 struct afsVolSync tsync;
509 struct afsFidName nameFid;
510 struct afsFid fid, outFid;
515 sscanf(&(*argp)[0], "%d", &vnode);
517 sscanf(&(*argp)[0], "%d", &unique);
519 memset(&fid, 0, sizeof(struct afsFid));
520 fid.Volume.low = 10; /* XXX */
525 memset(&nameFid, 0, sizeof(struct afsFidName));
526 strcpy(nameFid.name, name);
528 ubik_AFS_RemoveFile(cstruct, 0, &fid, &nameFid, &hyp0, 0,
529 &OutDirStatus, &OutFidStatus, &outFid, &tsync);
535 CreateFile(char **argp)
537 struct afsFetchStatus OutDirStatus, OutFidStatus;
538 struct afsStoreStatus InStatus;
539 struct afsVolSync tsync;
540 struct afsFid fid, outFid;
541 struct afsToken Token;
543 int vnode, unique, mode, owner, length;
546 sscanf(&(*argp)[0], "%d", &vnode);
548 sscanf(&(*argp)[0], "%d", &unique);
550 memset(&fid, 0, sizeof(struct afsFid));
551 fid.Volume.low = 10; /* XXX */
556 memset(&InStatus, 0, sizeof(struct afsStoreStatus));
557 sscanf(&(*argp)[0], "%d", &mode);
559 sscanf(&(*argp)[0], "%d", &owner);
561 sscanf(&(*argp)[0], "%d", &length);
564 InStatus.mode = mode;
565 InStatus.mask |= AFS_SETMODE;
568 InStatus.owner = owner;
569 InStatus.mask |= AFS_SETOWNER;
572 InStatus.length = length;
573 InStatus.mask |= AFS_SETLENGTH;
576 ubik_AFS_CreateFile(cstruct, 0, &fid, name, &InStatus, &hyp0, 0,
577 &outFid, &OutFidStatus, &OutDirStatus, &Token, &tsync);
585 struct afsFetchStatus OutOldDirStatus, OutNewDirStatus;
586 struct afsFetchStatus OutOldFileStatus, OutNewFileStatus;
587 struct afsVolSync tsync;
588 struct afsFid OldDirFid, NewDirFid, OutOldFileFid, OutNewFileFid;
589 struct afsFidName OldName, NewName;
591 int ovnode, ounique, nvnode, nunique;
594 sscanf(&(*argp)[0], "%d", &ovnode);
596 sscanf(&(*argp)[0], "%d", &ounique);
598 memset(&OldDirFid, 0, sizeof(struct afsFid));
599 OldDirFid.Volume.low = 10; /* XXX */
600 OldDirFid.Vnode = ovnode;
601 OldDirFid.Unique = ounique;
604 memset(&OldName, 0, sizeof(struct afsFidName));
605 strcpy(OldName.name, oname);
606 sscanf(&(*argp)[0], "%d", &nvnode);
608 sscanf(&(*argp)[0], "%d", &nunique);
610 memset(&NewDirFid, 0, sizeof(struct afsFid));
611 NewDirFid.Volume.low = 10; /* XXX */
612 NewDirFid.Vnode = nvnode;
613 NewDirFid.Unique = nunique;
616 memset(&NewName, 0, sizeof(struct afsFidName));
617 strcpy(NewName.name, nname);
619 ubik_AFS_Rename(cstruct, 0, &OldDirFid, &OldName, &NewDirFid,
620 &NewName, &hyp0, 0, &OutOldDirStatus, &OutNewDirStatus,
621 &OutOldFileFid, &OutOldFileStatus, &OutNewFileFid,
622 &OutNewFileStatus, &tsync);
630 struct afsFetchStatus OutDirStatus, OutFidStatus;
631 struct afsStoreStatus InStatus;
632 struct afsVolSync tsync;
633 struct afsFid fid, outFid;
634 struct afsToken Token;
635 char *name, *linkcontents;
636 int vnode, unique, mode, owner, length;
639 sscanf(&(*argp)[0], "%d", &vnode);
641 sscanf(&(*argp)[0], "%d", &unique);
643 memset(&fid, 0, sizeof(struct afsFid));
644 fid.Volume.low = 10; /* XXX */
649 linkcontents = &argp[0][0];
651 memset(&InStatus, 0, sizeof(struct afsStoreStatus));
652 sscanf(&(*argp)[0], "%d", &mode);
654 sscanf(&(*argp)[0], "%d", &owner);
656 sscanf(&(*argp)[0], "%d", &length);
659 InStatus.mode = mode;
660 InStatus.mask |= AFS_SETMODE;
663 InStatus.owner = owner;
664 InStatus.mask |= AFS_SETOWNER;
667 InStatus.length = length;
668 InStatus.mask |= AFS_SETLENGTH;
671 ubik_AFS_Symlink(cstruct, 0, &fid, name, linkcontents,
672 &InStatus, &hyp0, 0, &outFid, &OutFidStatus, &OutDirStatus,
679 HardLink(char **argp)
681 struct afsFetchStatus OutDirStatus, OutFidStatus;
682 struct afsVolSync tsync;
683 struct afsFid fid, existingFid;
688 sscanf(&(*argp)[0], "%d", &vnode);
690 sscanf(&(*argp)[0], "%d", &unique);
692 memset(&fid, 0, sizeof(struct afsFid));
693 fid.Volume.low = 10; /* XXX */
698 sscanf(&(*argp)[0], "%d", &vnode);
700 sscanf(&(*argp)[0], "%d", &unique);
702 memset(&existingFid, 0, sizeof(struct afsFid));
703 existingFid.Volume.low = 10; /* XXX */
704 existingFid.Vnode = vnode;
705 existingFid.Unique = unique;
707 ubik_AFS_HardLink(cstruct, 0, &fid, name, &existingFid, &hyp0,
708 0, &OutFidStatus, &OutDirStatus, &tsync);
716 struct afsFetchStatus OutDirStatus, OutFidStatus;
717 struct afsStoreStatus InStatus;
718 struct afsVolSync tsync;
719 struct afsFid fid, outFid;
720 struct afsToken Token;
722 int vnode, unique, mode, owner, length;
725 sscanf(&(*argp)[0], "%d", &vnode);
727 sscanf(&(*argp)[0], "%d", &unique);
729 memset(&fid, 0, sizeof(struct afsFid));
730 fid.Volume.low = 10; /* XXX */
735 memset(&InStatus, 0, sizeof(struct afsStoreStatus));
736 sscanf(&(*argp)[0], "%d", &mode);
738 sscanf(&(*argp)[0], "%d", &owner);
740 sscanf(&(*argp)[0], "%d", &length);
743 InStatus.mode = mode;
744 InStatus.mask |= AFS_SETMODE;
747 InStatus.owner = owner;
748 InStatus.mask |= AFS_SETOWNER;
751 InStatus.length = length;
752 InStatus.mask |= AFS_SETLENGTH;
755 ubik_AFS_MakeDir(cstruct, 0, &fid, name, &InStatus, &hyp0, 0,
756 &outFid, &OutFidStatus, &OutDirStatus, &Token, &tsync);
762 RemoveDir(char **argp)
764 struct afsFetchStatus OutDirStatus;
765 struct afsVolSync tsync;
766 struct afsFid fid, outFid;
767 struct afsFidName nameFid;
772 sscanf(&(*argp)[0], "%d", &vnode);
774 sscanf(&(*argp)[0], "%d", &unique);
776 memset(&fid, 0, sizeof(struct afsFid));
777 fid.Volume.low = 10; /* XXX */
782 memset(&nameFid, 0, sizeof(struct afsFidName));
783 strcpy(nameFid.name, name);
785 ubik_AFS_RemoveDir(cstruct, 0, &fid, &nameFid, &hyp0, 0,
786 &OutDirStatus, &outFid, &tsync);
794 struct afsFetchStatus OutDirStatus;
795 struct afsVolSync tsync;
797 struct afsToken Token;
799 struct rx_call *tcall;
800 int vnode, unique, offset, length, NextOffset;
803 sscanf(&(*argp)[0], "%d", &vnode);
805 sscanf(&(*argp)[0], "%d", &unique);
807 sscanf(&(*argp)[0], "%d", &offset);
809 sscanf(&(*argp)[0], "%d", &length);
811 memset(&fid, 0, sizeof(struct afsFid));
812 fid.Volume.low = 10; /* XXX */
815 tcall = rx_NewCall(cstruct->conns[0]);
816 code = StartAFS_Readdir(tcall, &fid, offset, length, &hyp0, 0);
818 code = FetchDir(tcall);
822 EndAFS_FetchData(tcall, &NextOffset, &OutDirStatus, &Token,
825 code = rx_EndCall(tcall, code);
831 FetchDir(struct rx_call *acall)
834 afs_int32 tlen, length, code;
838 tbuffer = malloc(256);
840 code = rx_Read(acall, &length, sizeof(afs_int32));
841 length = ntohl(length);
842 if (code != sizeof(afs_int32))
846 tlen = (length > 8192 ? 8192 : length);
847 code = rx_Read(acall, tbuffer, tlen);
854 dp = (struct dirent *)dp;
863 struct afsFetchStatus OutDirStatus, OutFidStatus;
864 struct afsVolSync tsync;
865 struct afsFid fid, outFid;
870 sscanf(&(*argp)[0], "%d", &vnode);
872 sscanf(&(*argp)[0], "%d", &unique);
874 memset(&fid, 0, sizeof(struct afsFid));
875 fid.Volume.low = 10; /* XXX */
881 ubik_AFS_Lookup(cstruct, 0, &fid, name, &hyp0, 0, &outFid,
882 &OutFidStatus, &OutDirStatus, &tsync);
888 GetToken(char **argp)
890 struct afsFetchStatus OutStatus;
891 struct afsVolSync tsync;
892 struct afsToken MinToken, RealToken;
894 int vnode, unique, tokenId;
897 sscanf(&(*argp)[0], "%d", &vnode);
899 sscanf(&(*argp)[0], "%d", &unique);
901 memset(&fid, 0, sizeof(struct afsFid));
902 fid.Volume.low = 10; /* XXX */
905 sscanf(&(*argp)[0], "%d", &tokenId);
907 memset(&MinToken, 0, sizeof(struct afsToken));
908 MinToken.tokenID.low = tokenId; /* XXX */
910 ubik_AFS_GetToken(cstruct, 0, &fid, &MinToken, &hyp0, 0,
911 &RealToken, &OutStatus, &tsync);
917 MakeMountPoint(char **argp)
923 ReleaseTokens(char **argp)
929 BulkStatus(char **argp)
933 /* printf("ka <vol.l> <vnode> <unique> <isExec> <kaTime>\n"); */
935 KeepAlive(char **argp)
937 struct afsBulkFEX fex;
938 afs_uint32 numExec, spare4;
942 memset(&fx, 0, sizeof(struct afsFidExp));
943 sscanf(&(*argp)[0], "%d", &fx.fid.Volume.low);
945 sscanf(&(*argp)[0], "%d", &fx.fid.Vnode);
947 sscanf(&(*argp)[0], "%d", &fx.fid.Unique);
949 sscanf(&(*argp)[0], "%d", &numExec);
951 sscanf(&(*argp)[0], "%d", &fx.keepAliveTime);
952 memset(&fex, 0, sizeof(struct afsBulkFEX));
953 fex.afsBulkFEX_val = &fx;
954 fex.afsBulkFEX_len = 1;
956 ubik_AFS_BulkKeepAlive(cstruct, 0, &fex, numExec, 0, 0, 0,