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>
15 #include <afs/afsint.h>
16 #include <sys/socket.h>
17 #include <rx/rx_globals.h>
18 #include <netinet/in.h>
19 #include <arpa/inet.h>
24 struct ubik_client *cstruct;
25 struct rx_connection *serverconns[MAXSERVERS];
29 pxclient_Initialize(int auth, afs_int32 serverAddr)
33 struct rx_securityClass *sc;
35 code = rx_Init(htons(2115) /*0 */ );
37 fprintf(stderr, "pxclient_Initialize: Could not initialize rx.\n");
42 sc = rxnull_NewClientSecurityObject();
44 rx_NewConnection(serverAddr, htons(7000), 1, sc, scIndex);
46 code = ubik_ClientInit(serverconns, &cstruct);
49 fprintf(stderr, "pxclient_Initialize: ubik client init failed.\n");
57 #include "AFS_component_version_number.c"
60 main(int argc, char **argv)
63 struct sockaddr_in host;
64 register afs_int32 code;
69 int noAuth = 1; /* Default is authenticated connections */
73 printf("usage: pxclient <serverHost>\n");
76 memset(&host, 0, sizeof(struct sockaddr_in));
77 host.sin_family = AF_INET;
78 host.sin_addr.s_addr = inet_addr(av[0]);
79 #ifdef STRUCT_SOCKADDR_HAS_SA_LEN
80 host.sin_len = sizeof(struct sockaddr_in);
82 if (host.sin_addr.s_addr != -1) {
83 strcpy(hnamebuf, av[0]);
86 hp = gethostbyname(av[0]);
88 host.sin_family = hp->h_addrtype;
89 memcpy((caddr_t) & host.sin_addr, hp->h_addr, hp->h_length);
90 hostname = hp->h_name;
92 printf("unknown server host %s\n", av[0]);
96 if ((code = pxclient_Initialize(noAuth, host.sin_addr.s_addr)) != 0) {
97 printf("Couldn't initialize fs library (code=%d).\n", code);
101 code = ubik_Call(RXAFS_GetTime, cstruct, 0, &tv.tv_sec, &tv.tv_usec);
103 printf("AFS_GetTime on %s sec=%ld, usec=%ld\n", av[0], tv.tv_sec,
104 (long int)tv.tv_usec);
106 printf("return code is %d\n", code);
114 if (fgets(line, 499, stdin) != NULL) {
116 register char **argp = args;
117 GetArgs(line, argp, &nargs);
120 if (!strcmp(oper, "probe")) {
122 ubik_Call(RXAFS_GetTime, cstruct, 0, &tv.tv_sec,
124 printf("return code is %d\n", code);
126 printf("sec=%d\n", tv.tv_sec);
127 } else if (!strcmp(oper, "fsstats")) {
128 struct afsStatistics stats;
130 code = ubik_AFS_GetStatistics(cstruct, 0, &stats);
131 printf("return code is %d\n", code);
132 } else if (!strcmp(oper, "fd")) {
133 code = FetchData(argp);
134 printf("return code is %d\n", code);
135 } else if (!strcmp(oper, "fs")) {
136 code = FetchStatus(argp);
137 printf("return code is %d\n", code);
138 } else if (!strcmp(oper, "fa")) {
139 code = FetchACL(argp);
140 printf("return code is %d\n", code);
141 } else if (!strcmp(oper, "sd")) {
142 code = StoreData(argp);
143 printf("return code is %d\n", code);
144 } else if (!strcmp(oper, "ss")) {
145 code = StoreStatus(argp);
146 printf("return code is %d\n", code);
147 } else if (!strcmp(oper, "sa")) {
148 code = StoreACL(argp);
149 printf("return code is %d\n", code);
150 } else if (!strcmp(oper, "cf")) {
151 code = CreateFile(argp);
152 printf("return code is %d\n", code);
153 } else if (!strcmp(oper, "rf")) {
154 code = RemoveFile(argp);
155 printf("return code is %d\n", code);
156 } else if (!strcmp(oper, "rn")) {
158 printf("return code is %d\n", code);
159 } else if (!strcmp(oper, "sl")) {
160 code = Symlink(argp);
161 printf("return code is %d\n", code);
162 } else if (!strcmp(oper, "hl")) {
163 code = HardLink(argp);
164 printf("return code is %d\n", code);
165 } else if (!strcmp(oper, "md")) {
166 code = MakeDir(argp);
167 printf("return code is %d\n", code);
168 } else if (!strcmp(oper, "rd")) {
169 code = RemoveDir(argp);
170 printf("return code is %d\n", code);
171 } else if (!strcmp(oper, "rdd")) {
172 code = Readdir(argp);
173 printf("return code is %d\n", code);
174 } else if (!strcmp(oper, "mm")) {
175 code = MakeMountPoint(argp);
176 printf("return code is %d\n", code);
177 } else if (!strcmp(oper, "rt")) {
178 code = ReleaseTokens(argp);
179 printf("return code is %d\n", code);
180 } else if (!strcmp(oper, "bs")) {
181 code = BulkStatus(argp);
182 printf("return code is %d\n", code);
183 } else if (!strcmp(oper, "lk")) {
185 printf("return code is %d\n", code);
186 } else if (!strcmp(oper, "gt")) {
187 code = GetToken(argp);
188 printf("return code is %d\n", code);
189 } else if (!strcmp(oper, "ka")) {
190 code = KeepAlive(argp);
191 printf("return code is %d\n", code);
192 } else if ((!strcmp(oper, "q")) || !strcmp(oper, "quit"))
195 printf("Unknown oper! Available operations: \n\n");
196 printf("fd <vnode> <unique> <pos> <len>\n");
197 printf("fs <vnode> <unique>\n");
198 printf("fa <vnode> <unique>\n");
200 ("sd <vnode> <unique> <pos> <len> <flen> [<mode>|-1] [<owner>|-1] [<length>|-1] <string>\n");
202 ("ss <vnode> <unique> [<mode>|-1] [<owner>|-1] [<length>|-1]\n");
203 printf("sa <vnode> <unique> <string>\n");
204 printf("rf <vnode> <unique> <name>\n");
206 ("cf <vnode> <unique> <name> [<mode>|-1] [<owner>|-1] [<length>|-1]\n");
208 ("rn <ovnode> <ounique> <oname> <nvnode> <nunique> <nname>\n");
210 ("sl <vnode> <unique> <name> <contents> [<mode>|-1] [<owner>|-1] [<length>|-1]\n");
211 printf("hl <dvnode> <dunique> <name> <evnode> <eunique>\n");
213 ("md <vnode> <unique> <name> [<mode>|-1] [<owner>|-1] [<length>|-1]\n");
214 printf("rd <vnode> <unique> <name>\n");
215 printf("rdd <vnode> <unique> <pos> <len>\n");
216 printf("lk <vnode> <unique> <name>\n");
217 printf("gt <vnode> <unique> <tokenID>\n");
218 printf("ka <vol.l> <vnode> <unique> <isExec> <kaTime>\n");
228 GetArgs(register char *line, register char **args, register int *nargs)
232 register char *last = line;
239 *args++ = line, (*nargs)++;
240 while (*line && *line != ' ')
247 FetchData(char **argp)
249 struct afsFetchStatus OutStatus;
250 struct afsToken Token;
251 struct afsVolSync tsync;
253 int vnode, unique, position, length;
255 struct rx_call *tcall;
257 sscanf(&(*argp)[0], "%d", &vnode);
259 sscanf(&(*argp)[0], "%d", &unique);
261 memset(&fid, 0, sizeof(struct afsFid));
262 fid.Volume.low = 10; /* XXX */
265 sscanf(&(*argp)[0], "%d", &position);
267 sscanf(&(*argp)[0], "%d", &length);
269 tcall = rx_NewCall(cstruct->conns[0]);
270 code = StartAFS_FetchData(tcall, &fid, &hyp0, position, length, 0);
272 code = FetchProc(tcall);
275 code = EndAFS_FetchData(tcall, &OutStatus, &Token, &tsync);
277 code = rx_EndCall(tcall, code);
283 FetchProc(register struct rx_call *acall)
285 extern char *malloc();
286 register char *tbuffer;
287 afs_int32 tlen, length, code;
289 code = rx_Read(acall, &length, sizeof(afs_int32));
290 length = ntohl(length);
291 if (code != sizeof(afs_int32))
293 tbuffer = malloc(256);
295 tlen = (length > 256 ? 256 : length);
296 code = rx_Read(acall, tbuffer, tlen);
309 FetchStatus(char **argp)
311 struct afsFetchStatus OutStatus;
312 struct afsToken Token;
313 struct afsVolSync tsync;
318 sscanf(&(*argp)[0], "%d", &vnode);
320 sscanf(&(*argp)[0], "%d", &unique);
322 memset(&fid, 0, sizeof(struct afsFid));
323 fid.Volume.low = 10; /* XXX */
327 ubik_AFS_FetchStatus(cstruct, 0, &fid, &hyp0, 0, &OutStatus,
334 FetchACL(char **argp)
336 struct afsFetchStatus OutStatus;
337 struct afsACL AccessList;
338 struct afsToken Token;
339 struct afsVolSync tsync;
344 sscanf(&(*argp)[0], "%d", &vnode);
346 sscanf(&(*argp)[0], "%d", &unique);
348 memset(&fid, 0, sizeof(struct afsFid));
349 fid.Volume.low = 10; /* XXX */
353 ubik_AFS_FetchACL(cstruct, 0, &fid, &hyp0, 0, &AccessList,
360 StoreData(char **argp)
362 struct afsStoreStatus InStatus;
363 struct afsFetchStatus OutStatus;
364 struct afsVolSync tsync;
366 int vnode, unique, position, length, filelength;
367 int mode, owner, len;
370 struct rx_call *tcall;
372 sscanf(&(*argp)[0], "%d", &vnode);
374 sscanf(&(*argp)[0], "%d", &unique);
376 memset(&fid, 0, sizeof(struct afsFid));
377 fid.Volume.low = 10; /* XXX */
380 sscanf(&(*argp)[0], "%d", &position);
382 sscanf(&(*argp)[0], "%d", &length);
384 sscanf(&(*argp)[0], "%d", &filelength);
386 memset(&InStatus, 0, sizeof(struct afsStoreStatus));
387 sscanf(&(*argp)[0], "%d", &mode);
389 sscanf(&(*argp)[0], "%d", &owner);
391 sscanf(&(*argp)[0], "%d", &len);
394 InStatus.mode = mode;
395 InStatus.mask |= AFS_SETMODE;
398 InStatus.owner = owner;
399 InStatus.mask |= AFS_SETOWNER;
402 InStatus.length = length;
403 InStatus.mask |= AFS_SETLENGTH;
405 string = &argp[0][0];
408 tcall = rx_NewCall(cstruct->conns[0]);
410 StartAFS_StoreData(tcall, &fid, &InStatus, position, length,
411 filelength, &hyp0, 0);
413 code = StoreProc(tcall, string, length);
416 code = EndAFS_StoreData(tcall, &OutStatus, &tsync);
418 code = rx_EndCall(tcall, code);
424 StoreProc(register struct rx_call *acall, char *string, int length)
426 afs_int32 tlen, code;
429 tlen = (length > 256 ? 256 : length);
430 code = rx_Write(acall, string, tlen);
441 StoreStatus(char **argp)
443 struct afsStoreStatus InStatus;
444 struct afsFetchStatus OutStatus;
445 struct afsVolSync tsync;
447 int vnode, unique, mode, owner, length;
450 sscanf(&(*argp)[0], "%d", &vnode);
452 sscanf(&(*argp)[0], "%d", &unique);
454 memset(&fid, 0, sizeof(struct afsFid));
455 fid.Volume.low = 10; /* XXX */
458 memset(&InStatus, 0, sizeof(struct afsStoreStatus));
459 sscanf(&(*argp)[0], "%d", &mode);
461 sscanf(&(*argp)[0], "%d", &owner);
463 sscanf(&(*argp)[0], "%d", &length);
466 InStatus.mode = mode;
467 InStatus.mask |= AFS_SETMODE;
470 InStatus.owner = owner;
471 InStatus.mask |= AFS_SETOWNER;
474 InStatus.length = length;
475 InStatus.mask |= AFS_SETLENGTH;
478 ubik_AFS_StoreStatus(cstruct, 0, &fid, &InStatus, &hyp0, 0,
485 StoreACL(char **argp)
487 struct afsFetchStatus OutStatus;
488 struct afsACL AccessList;
489 struct afsToken Token;
490 struct afsVolSync tsync;
496 sscanf(&(*argp)[0], "%d", &vnode);
498 sscanf(&(*argp)[0], "%d", &unique);
500 memset(&fid, 0, sizeof(struct afsFid));
501 fid.Volume.low = 10; /* XXX */
504 string = &argp[0][0];
506 AccessList.afsACL_len = strlen(string) + 1;
507 AccessList.afsACL_val = string;
509 ubik_AFS_StoreACL(cstruct, 0, &fid, &AccessList, &hyp0, 0,
516 RemoveFile(char **argp)
518 struct afsFetchStatus OutDirStatus, OutFidStatus;
519 struct afsVolSync tsync;
520 struct afsFidName nameFid;
521 struct afsFid fid, outFid;
526 sscanf(&(*argp)[0], "%d", &vnode);
528 sscanf(&(*argp)[0], "%d", &unique);
530 memset(&fid, 0, sizeof(struct afsFid));
531 fid.Volume.low = 10; /* XXX */
536 memset(&nameFid, 0, sizeof(struct afsFidName));
537 strcpy(nameFid.name, name);
539 ubik_AFS_RemoveFile(cstruct, 0, &fid, &nameFid, &hyp0, 0,
540 &OutDirStatus, &OutFidStatus, &outFid, &tsync);
546 CreateFile(char **argp)
548 struct afsFetchStatus OutDirStatus, OutFidStatus;
549 struct afsStoreStatus InStatus;
550 struct afsVolSync tsync;
551 struct afsFid fid, outFid;
552 struct afsToken Token;
554 int vnode, unique, mode, owner, length;
557 sscanf(&(*argp)[0], "%d", &vnode);
559 sscanf(&(*argp)[0], "%d", &unique);
561 memset(&fid, 0, sizeof(struct afsFid));
562 fid.Volume.low = 10; /* XXX */
567 memset(&InStatus, 0, sizeof(struct afsStoreStatus));
568 sscanf(&(*argp)[0], "%d", &mode);
570 sscanf(&(*argp)[0], "%d", &owner);
572 sscanf(&(*argp)[0], "%d", &length);
575 InStatus.mode = mode;
576 InStatus.mask |= AFS_SETMODE;
579 InStatus.owner = owner;
580 InStatus.mask |= AFS_SETOWNER;
583 InStatus.length = length;
584 InStatus.mask |= AFS_SETLENGTH;
587 ubik_AFS_CreateFile(cstruct, 0, &fid, name, &InStatus, &hyp0, 0,
588 &outFid, &OutFidStatus, &OutDirStatus, &Token, &tsync);
596 struct afsFetchStatus OutOldDirStatus, OutNewDirStatus;
597 struct afsFetchStatus OutOldFileStatus, OutNewFileStatus;
598 struct afsVolSync tsync;
599 struct afsFid OldDirFid, NewDirFid, OutOldFileFid, OutNewFileFid;
600 struct afsFidName OldName, NewName;
602 int ovnode, ounique, nvnode, nunique;
605 sscanf(&(*argp)[0], "%d", &ovnode);
607 sscanf(&(*argp)[0], "%d", &ounique);
609 memset(&OldDirFid, 0, sizeof(struct afsFid));
610 OldDirFid.Volume.low = 10; /* XXX */
611 OldDirFid.Vnode = ovnode;
612 OldDirFid.Unique = ounique;
615 memset(&OldName, 0, sizeof(struct afsFidName));
616 strcpy(OldName.name, oname);
617 sscanf(&(*argp)[0], "%d", &nvnode);
619 sscanf(&(*argp)[0], "%d", &nunique);
621 memset(&NewDirFid, 0, sizeof(struct afsFid));
622 NewDirFid.Volume.low = 10; /* XXX */
623 NewDirFid.Vnode = nvnode;
624 NewDirFid.Unique = nunique;
627 memset(&NewName, 0, sizeof(struct afsFidName));
628 strcpy(NewName.name, nname);
630 ubik_AFS_Rename(cstruct, 0, &OldDirFid, &OldName, &NewDirFid,
631 &NewName, &hyp0, 0, &OutOldDirStatus, &OutNewDirStatus,
632 &OutOldFileFid, &OutOldFileStatus, &OutNewFileFid,
633 &OutNewFileStatus, &tsync);
641 struct afsFetchStatus OutDirStatus, OutFidStatus;
642 struct afsStoreStatus InStatus;
643 struct afsVolSync tsync;
644 struct afsFid fid, outFid;
645 struct afsToken Token;
646 char *name, *linkcontents;
647 int vnode, unique, mode, owner, length;
650 sscanf(&(*argp)[0], "%d", &vnode);
652 sscanf(&(*argp)[0], "%d", &unique);
654 memset(&fid, 0, sizeof(struct afsFid));
655 fid.Volume.low = 10; /* XXX */
660 linkcontents = &argp[0][0];
662 memset(&InStatus, 0, sizeof(struct afsStoreStatus));
663 sscanf(&(*argp)[0], "%d", &mode);
665 sscanf(&(*argp)[0], "%d", &owner);
667 sscanf(&(*argp)[0], "%d", &length);
670 InStatus.mode = mode;
671 InStatus.mask |= AFS_SETMODE;
674 InStatus.owner = owner;
675 InStatus.mask |= AFS_SETOWNER;
678 InStatus.length = length;
679 InStatus.mask |= AFS_SETLENGTH;
682 ubik_AFS_Symlink(cstruct, 0, &fid, name, linkcontents,
683 &InStatus, &hyp0, 0, &outFid, &OutFidStatus, &OutDirStatus,
690 HardLink(char **argp)
692 struct afsFetchStatus OutDirStatus, OutFidStatus;
693 struct afsVolSync tsync;
694 struct afsFid fid, existingFid;
699 sscanf(&(*argp)[0], "%d", &vnode);
701 sscanf(&(*argp)[0], "%d", &unique);
703 memset(&fid, 0, sizeof(struct afsFid));
704 fid.Volume.low = 10; /* XXX */
709 sscanf(&(*argp)[0], "%d", &vnode);
711 sscanf(&(*argp)[0], "%d", &unique);
713 memset(&existingFid, 0, sizeof(struct afsFid));
714 existingFid.Volume.low = 10; /* XXX */
715 existingFid.Vnode = vnode;
716 existingFid.Unique = unique;
718 ubik_AFS_HardLink(cstruct, 0, &fid, name, &existingFid, &hyp0,
719 0, &OutFidStatus, &OutDirStatus, &tsync);
727 struct afsFetchStatus OutDirStatus, OutFidStatus;
728 struct afsStoreStatus InStatus;
729 struct afsVolSync tsync;
730 struct afsFid fid, outFid;
731 struct afsToken Token;
733 int vnode, unique, mode, owner, length;
736 sscanf(&(*argp)[0], "%d", &vnode);
738 sscanf(&(*argp)[0], "%d", &unique);
740 memset(&fid, 0, sizeof(struct afsFid));
741 fid.Volume.low = 10; /* XXX */
746 memset(&InStatus, 0, sizeof(struct afsStoreStatus));
747 sscanf(&(*argp)[0], "%d", &mode);
749 sscanf(&(*argp)[0], "%d", &owner);
751 sscanf(&(*argp)[0], "%d", &length);
754 InStatus.mode = mode;
755 InStatus.mask |= AFS_SETMODE;
758 InStatus.owner = owner;
759 InStatus.mask |= AFS_SETOWNER;
762 InStatus.length = length;
763 InStatus.mask |= AFS_SETLENGTH;
766 ubik_AFS_MakeDir(cstruct, 0, &fid, name, &InStatus, &hyp0, 0,
767 &outFid, &OutFidStatus, &OutDirStatus, &Token, &tsync);
773 RemoveDir(char **argp)
775 struct afsFetchStatus OutDirStatus;
776 struct afsVolSync tsync;
777 struct afsFid fid, outFid;
778 struct afsFidName nameFid;
783 sscanf(&(*argp)[0], "%d", &vnode);
785 sscanf(&(*argp)[0], "%d", &unique);
787 memset(&fid, 0, sizeof(struct afsFid));
788 fid.Volume.low = 10; /* XXX */
793 memset(&nameFid, 0, sizeof(struct afsFidName));
794 strcpy(nameFid.name, name);
796 ubik_AFS_RemoveDir(cstruct, 0, &fid, &nameFid, &hyp0, 0,
797 &OutDirStatus, &outFid, &tsync);
805 struct afsFetchStatus OutDirStatus;
806 struct afsVolSync tsync;
808 struct afsToken Token;
810 struct rx_call *tcall;
811 int vnode, unique, offset, length, NextOffset;
814 sscanf(&(*argp)[0], "%d", &vnode);
816 sscanf(&(*argp)[0], "%d", &unique);
818 sscanf(&(*argp)[0], "%d", &offset);
820 sscanf(&(*argp)[0], "%d", &length);
822 memset(&fid, 0, sizeof(struct afsFid));
823 fid.Volume.low = 10; /* XXX */
826 tcall = rx_NewCall(cstruct->conns[0]);
827 code = StartAFS_Readdir(tcall, &fid, offset, length, &hyp0, 0);
829 code = FetchDir(tcall);
833 EndAFS_FetchData(tcall, &NextOffset, &OutDirStatus, &Token,
836 code = rx_EndCall(tcall, code);
842 FetchDir(register struct rx_call *acall)
844 extern char *malloc();
845 register char *tbuffer;
846 afs_int32 tlen, length, code;
850 tbuffer = malloc(256);
852 code = rx_Read(acall, &length, sizeof(afs_int32));
853 length = ntohl(length);
854 if (code != sizeof(afs_int32))
858 tlen = (length > 8192 ? 8192 : length);
859 code = rx_Read(acall, tbuffer, tlen);
866 dp = (struct dirent *)dp;
875 struct afsFetchStatus OutDirStatus, OutFidStatus;
876 struct afsVolSync tsync;
877 struct afsFid fid, outFid;
882 sscanf(&(*argp)[0], "%d", &vnode);
884 sscanf(&(*argp)[0], "%d", &unique);
886 memset(&fid, 0, sizeof(struct afsFid));
887 fid.Volume.low = 10; /* XXX */
893 ubik_AFS_Lookup(cstruct, 0, &fid, name, &hyp0, 0, &outFid,
894 &OutFidStatus, &OutDirStatus, &tsync);
900 GetToken(char **argp)
902 struct afsFetchStatus OutStatus;
903 struct afsVolSync tsync;
904 struct afsToken MinToken, RealToken;
906 int vnode, unique, tokenId;
909 sscanf(&(*argp)[0], "%d", &vnode);
911 sscanf(&(*argp)[0], "%d", &unique);
913 memset(&fid, 0, sizeof(struct afsFid));
914 fid.Volume.low = 10; /* XXX */
917 sscanf(&(*argp)[0], "%d", &tokenId);
919 memset(&MinToken, 0, sizeof(struct afsToken));
920 MinToken.tokenID.low = tokenId; /* XXX */
922 ubik_AFS_GetToken(cstruct, 0, &fid, &MinToken, &hyp0, 0,
923 &RealToken, &OutStatus, &tsync);
929 MakeMountPoint(char **argp)
935 ReleaseTokens(char **argp)
941 BulkStatus(char **argp)
945 /* printf("ka <vol.l> <vnode> <unique> <isExec> <kaTime>\n"); */
947 KeepAlive(char **argp)
949 struct afsBulkFEX fex;
950 afs_uint32 numExec, spare4;
954 memset(&fx, 0, sizeof(struct afsFidExp));
955 sscanf(&(*argp)[0], "%d", &fx.fid.Volume.low);
957 sscanf(&(*argp)[0], "%d", &fx.fid.Vnode);
959 sscanf(&(*argp)[0], "%d", &fx.fid.Unique);
961 sscanf(&(*argp)[0], "%d", &numExec);
963 sscanf(&(*argp)[0], "%d", &fx.keepAliveTime);
964 memset(&fex, 0, sizeof(struct afsBulkFEX));
965 fex.afsBulkFEX_val = &fx;
966 fex.afsBulkFEX_len = 1;
968 ubik_AFS_BulkKeepAlive(cstruct, 0, &fex, numExec, 0, 0, 0,