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)
279 afs_int32 tlen, length, code;
281 code = rx_Read(acall, &length, sizeof(afs_int32));
282 length = ntohl(length);
283 if (code != sizeof(afs_int32))
285 tbuffer = malloc(256);
287 tlen = (length > 256 ? 256 : length);
288 code = rx_Read(acall, tbuffer, tlen);
301 FetchStatus(char **argp)
303 struct afsFetchStatus OutStatus;
304 struct afsToken Token;
305 struct afsVolSync tsync;
310 sscanf(&(*argp)[0], "%d", &vnode);
312 sscanf(&(*argp)[0], "%d", &unique);
314 memset(&fid, 0, sizeof(struct afsFid));
315 fid.Volume.low = 10; /* XXX */
319 ubik_AFS_FetchStatus(cstruct, 0, &fid, &hyp0, 0, &OutStatus,
326 FetchACL(char **argp)
328 struct afsFetchStatus OutStatus;
329 struct afsACL AccessList;
330 struct afsToken Token;
331 struct afsVolSync tsync;
336 sscanf(&(*argp)[0], "%d", &vnode);
338 sscanf(&(*argp)[0], "%d", &unique);
340 memset(&fid, 0, sizeof(struct afsFid));
341 fid.Volume.low = 10; /* XXX */
345 ubik_AFS_FetchACL(cstruct, 0, &fid, &hyp0, 0, &AccessList,
352 StoreData(char **argp)
354 struct afsStoreStatus InStatus;
355 struct afsFetchStatus OutStatus;
356 struct afsVolSync tsync;
358 int vnode, unique, position, length, filelength;
359 int mode, owner, len;
362 struct rx_call *tcall;
364 sscanf(&(*argp)[0], "%d", &vnode);
366 sscanf(&(*argp)[0], "%d", &unique);
368 memset(&fid, 0, sizeof(struct afsFid));
369 fid.Volume.low = 10; /* XXX */
372 sscanf(&(*argp)[0], "%d", &position);
374 sscanf(&(*argp)[0], "%d", &length);
376 sscanf(&(*argp)[0], "%d", &filelength);
378 memset(&InStatus, 0, sizeof(struct afsStoreStatus));
379 sscanf(&(*argp)[0], "%d", &mode);
381 sscanf(&(*argp)[0], "%d", &owner);
383 sscanf(&(*argp)[0], "%d", &len);
386 InStatus.mode = mode;
387 InStatus.mask |= AFS_SETMODE;
390 InStatus.owner = owner;
391 InStatus.mask |= AFS_SETOWNER;
394 InStatus.length = length;
395 InStatus.mask |= AFS_SETLENGTH;
397 string = &argp[0][0];
400 tcall = rx_NewCall(cstruct->conns[0]);
402 StartAFS_StoreData(tcall, &fid, &InStatus, position, length,
403 filelength, &hyp0, 0);
405 code = StoreProc(tcall, string, length);
408 code = EndAFS_StoreData(tcall, &OutStatus, &tsync);
410 code = rx_EndCall(tcall, code);
416 StoreProc(struct rx_call *acall, char *string, int length)
418 afs_int32 tlen, code;
421 tlen = (length > 256 ? 256 : length);
422 code = rx_Write(acall, string, tlen);
433 StoreStatus(char **argp)
435 struct afsStoreStatus InStatus;
436 struct afsFetchStatus OutStatus;
437 struct afsVolSync tsync;
439 int vnode, unique, mode, owner, length;
442 sscanf(&(*argp)[0], "%d", &vnode);
444 sscanf(&(*argp)[0], "%d", &unique);
446 memset(&fid, 0, sizeof(struct afsFid));
447 fid.Volume.low = 10; /* XXX */
450 memset(&InStatus, 0, sizeof(struct afsStoreStatus));
451 sscanf(&(*argp)[0], "%d", &mode);
453 sscanf(&(*argp)[0], "%d", &owner);
455 sscanf(&(*argp)[0], "%d", &length);
458 InStatus.mode = mode;
459 InStatus.mask |= AFS_SETMODE;
462 InStatus.owner = owner;
463 InStatus.mask |= AFS_SETOWNER;
466 InStatus.length = length;
467 InStatus.mask |= AFS_SETLENGTH;
470 ubik_AFS_StoreStatus(cstruct, 0, &fid, &InStatus, &hyp0, 0,
477 StoreACL(char **argp)
479 struct afsFetchStatus OutStatus;
480 struct afsACL AccessList;
481 struct afsToken Token;
482 struct afsVolSync tsync;
488 sscanf(&(*argp)[0], "%d", &vnode);
490 sscanf(&(*argp)[0], "%d", &unique);
492 memset(&fid, 0, sizeof(struct afsFid));
493 fid.Volume.low = 10; /* XXX */
496 string = &argp[0][0];
498 AccessList.afsACL_len = strlen(string) + 1;
499 AccessList.afsACL_val = string;
501 ubik_AFS_StoreACL(cstruct, 0, &fid, &AccessList, &hyp0, 0,
508 RemoveFile(char **argp)
510 struct afsFetchStatus OutDirStatus, OutFidStatus;
511 struct afsVolSync tsync;
512 struct afsFidName nameFid;
513 struct afsFid fid, outFid;
518 sscanf(&(*argp)[0], "%d", &vnode);
520 sscanf(&(*argp)[0], "%d", &unique);
522 memset(&fid, 0, sizeof(struct afsFid));
523 fid.Volume.low = 10; /* XXX */
528 memset(&nameFid, 0, sizeof(struct afsFidName));
529 strcpy(nameFid.name, name);
531 ubik_AFS_RemoveFile(cstruct, 0, &fid, &nameFid, &hyp0, 0,
532 &OutDirStatus, &OutFidStatus, &outFid, &tsync);
538 CreateFile(char **argp)
540 struct afsFetchStatus OutDirStatus, OutFidStatus;
541 struct afsStoreStatus InStatus;
542 struct afsVolSync tsync;
543 struct afsFid fid, outFid;
544 struct afsToken Token;
546 int vnode, unique, mode, owner, length;
549 sscanf(&(*argp)[0], "%d", &vnode);
551 sscanf(&(*argp)[0], "%d", &unique);
553 memset(&fid, 0, sizeof(struct afsFid));
554 fid.Volume.low = 10; /* XXX */
559 memset(&InStatus, 0, sizeof(struct afsStoreStatus));
560 sscanf(&(*argp)[0], "%d", &mode);
562 sscanf(&(*argp)[0], "%d", &owner);
564 sscanf(&(*argp)[0], "%d", &length);
567 InStatus.mode = mode;
568 InStatus.mask |= AFS_SETMODE;
571 InStatus.owner = owner;
572 InStatus.mask |= AFS_SETOWNER;
575 InStatus.length = length;
576 InStatus.mask |= AFS_SETLENGTH;
579 ubik_AFS_CreateFile(cstruct, 0, &fid, name, &InStatus, &hyp0, 0,
580 &outFid, &OutFidStatus, &OutDirStatus, &Token, &tsync);
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;
594 int ovnode, ounique, nvnode, nunique;
597 sscanf(&(*argp)[0], "%d", &ovnode);
599 sscanf(&(*argp)[0], "%d", &ounique);
601 memset(&OldDirFid, 0, sizeof(struct afsFid));
602 OldDirFid.Volume.low = 10; /* XXX */
603 OldDirFid.Vnode = ovnode;
604 OldDirFid.Unique = ounique;
607 memset(&OldName, 0, sizeof(struct afsFidName));
608 strcpy(OldName.name, oname);
609 sscanf(&(*argp)[0], "%d", &nvnode);
611 sscanf(&(*argp)[0], "%d", &nunique);
613 memset(&NewDirFid, 0, sizeof(struct afsFid));
614 NewDirFid.Volume.low = 10; /* XXX */
615 NewDirFid.Vnode = nvnode;
616 NewDirFid.Unique = nunique;
619 memset(&NewName, 0, sizeof(struct afsFidName));
620 strcpy(NewName.name, nname);
622 ubik_AFS_Rename(cstruct, 0, &OldDirFid, &OldName, &NewDirFid,
623 &NewName, &hyp0, 0, &OutOldDirStatus, &OutNewDirStatus,
624 &OutOldFileFid, &OutOldFileStatus, &OutNewFileFid,
625 &OutNewFileStatus, &tsync);
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;
642 sscanf(&(*argp)[0], "%d", &vnode);
644 sscanf(&(*argp)[0], "%d", &unique);
646 memset(&fid, 0, sizeof(struct afsFid));
647 fid.Volume.low = 10; /* XXX */
652 linkcontents = &argp[0][0];
654 memset(&InStatus, 0, sizeof(struct afsStoreStatus));
655 sscanf(&(*argp)[0], "%d", &mode);
657 sscanf(&(*argp)[0], "%d", &owner);
659 sscanf(&(*argp)[0], "%d", &length);
662 InStatus.mode = mode;
663 InStatus.mask |= AFS_SETMODE;
666 InStatus.owner = owner;
667 InStatus.mask |= AFS_SETOWNER;
670 InStatus.length = length;
671 InStatus.mask |= AFS_SETLENGTH;
674 ubik_AFS_Symlink(cstruct, 0, &fid, name, linkcontents,
675 &InStatus, &hyp0, 0, &outFid, &OutFidStatus, &OutDirStatus,
682 HardLink(char **argp)
684 struct afsFetchStatus OutDirStatus, OutFidStatus;
685 struct afsVolSync tsync;
686 struct afsFid fid, existingFid;
691 sscanf(&(*argp)[0], "%d", &vnode);
693 sscanf(&(*argp)[0], "%d", &unique);
695 memset(&fid, 0, sizeof(struct afsFid));
696 fid.Volume.low = 10; /* XXX */
701 sscanf(&(*argp)[0], "%d", &vnode);
703 sscanf(&(*argp)[0], "%d", &unique);
705 memset(&existingFid, 0, sizeof(struct afsFid));
706 existingFid.Volume.low = 10; /* XXX */
707 existingFid.Vnode = vnode;
708 existingFid.Unique = unique;
710 ubik_AFS_HardLink(cstruct, 0, &fid, name, &existingFid, &hyp0,
711 0, &OutFidStatus, &OutDirStatus, &tsync);
719 struct afsFetchStatus OutDirStatus, OutFidStatus;
720 struct afsStoreStatus InStatus;
721 struct afsVolSync tsync;
722 struct afsFid fid, outFid;
723 struct afsToken Token;
725 int vnode, unique, mode, owner, length;
728 sscanf(&(*argp)[0], "%d", &vnode);
730 sscanf(&(*argp)[0], "%d", &unique);
732 memset(&fid, 0, sizeof(struct afsFid));
733 fid.Volume.low = 10; /* XXX */
738 memset(&InStatus, 0, sizeof(struct afsStoreStatus));
739 sscanf(&(*argp)[0], "%d", &mode);
741 sscanf(&(*argp)[0], "%d", &owner);
743 sscanf(&(*argp)[0], "%d", &length);
746 InStatus.mode = mode;
747 InStatus.mask |= AFS_SETMODE;
750 InStatus.owner = owner;
751 InStatus.mask |= AFS_SETOWNER;
754 InStatus.length = length;
755 InStatus.mask |= AFS_SETLENGTH;
758 ubik_AFS_MakeDir(cstruct, 0, &fid, name, &InStatus, &hyp0, 0,
759 &outFid, &OutFidStatus, &OutDirStatus, &Token, &tsync);
765 RemoveDir(char **argp)
767 struct afsFetchStatus OutDirStatus;
768 struct afsVolSync tsync;
769 struct afsFid fid, outFid;
770 struct afsFidName nameFid;
775 sscanf(&(*argp)[0], "%d", &vnode);
777 sscanf(&(*argp)[0], "%d", &unique);
779 memset(&fid, 0, sizeof(struct afsFid));
780 fid.Volume.low = 10; /* XXX */
785 memset(&nameFid, 0, sizeof(struct afsFidName));
786 strcpy(nameFid.name, name);
788 ubik_AFS_RemoveDir(cstruct, 0, &fid, &nameFid, &hyp0, 0,
789 &OutDirStatus, &outFid, &tsync);
797 struct afsFetchStatus OutDirStatus;
798 struct afsVolSync tsync;
800 struct afsToken Token;
802 struct rx_call *tcall;
803 int vnode, unique, offset, length, NextOffset;
806 sscanf(&(*argp)[0], "%d", &vnode);
808 sscanf(&(*argp)[0], "%d", &unique);
810 sscanf(&(*argp)[0], "%d", &offset);
812 sscanf(&(*argp)[0], "%d", &length);
814 memset(&fid, 0, sizeof(struct afsFid));
815 fid.Volume.low = 10; /* XXX */
818 tcall = rx_NewCall(cstruct->conns[0]);
819 code = StartAFS_Readdir(tcall, &fid, offset, length, &hyp0, 0);
821 code = FetchDir(tcall);
825 EndAFS_FetchData(tcall, &NextOffset, &OutDirStatus, &Token,
828 code = rx_EndCall(tcall, code);
834 FetchDir(struct rx_call *acall)
837 afs_int32 tlen, length, code;
841 tbuffer = malloc(256);
843 code = rx_Read(acall, &length, sizeof(afs_int32));
844 length = ntohl(length);
845 if (code != sizeof(afs_int32))
849 tlen = (length > 8192 ? 8192 : length);
850 code = rx_Read(acall, tbuffer, tlen);
857 dp = (struct dirent *)dp;
866 struct afsFetchStatus OutDirStatus, OutFidStatus;
867 struct afsVolSync tsync;
868 struct afsFid fid, outFid;
873 sscanf(&(*argp)[0], "%d", &vnode);
875 sscanf(&(*argp)[0], "%d", &unique);
877 memset(&fid, 0, sizeof(struct afsFid));
878 fid.Volume.low = 10; /* XXX */
884 ubik_AFS_Lookup(cstruct, 0, &fid, name, &hyp0, 0, &outFid,
885 &OutFidStatus, &OutDirStatus, &tsync);
891 GetToken(char **argp)
893 struct afsFetchStatus OutStatus;
894 struct afsVolSync tsync;
895 struct afsToken MinToken, RealToken;
897 int vnode, unique, tokenId;
900 sscanf(&(*argp)[0], "%d", &vnode);
902 sscanf(&(*argp)[0], "%d", &unique);
904 memset(&fid, 0, sizeof(struct afsFid));
905 fid.Volume.low = 10; /* XXX */
908 sscanf(&(*argp)[0], "%d", &tokenId);
910 memset(&MinToken, 0, sizeof(struct afsToken));
911 MinToken.tokenID.low = tokenId; /* XXX */
913 ubik_AFS_GetToken(cstruct, 0, &fid, &MinToken, &hyp0, 0,
914 &RealToken, &OutStatus, &tsync);
920 MakeMountPoint(char **argp)
926 ReleaseTokens(char **argp)
932 BulkStatus(char **argp)
936 /* printf("ka <vol.l> <vnode> <unique> <isExec> <kaTime>\n"); */
938 KeepAlive(char **argp)
940 struct afsBulkFEX fex;
941 afs_uint32 numExec, spare4;
945 memset(&fx, 0, sizeof(struct afsFidExp));
946 sscanf(&(*argp)[0], "%d", &fx.fid.Volume.low);
948 sscanf(&(*argp)[0], "%d", &fx.fid.Vnode);
950 sscanf(&(*argp)[0], "%d", &fx.fid.Unique);
952 sscanf(&(*argp)[0], "%d", &numExec);
954 sscanf(&(*argp)[0], "%d", &fx.keepAliveTime);
955 memset(&fex, 0, sizeof(struct afsBulkFEX));
956 fex.afsBulkFEX_val = &fx;
957 fex.afsBulkFEX_len = 1;
959 ubik_AFS_BulkKeepAlive(cstruct, 0, &fex, numExec, 0, 0, 0,