Artifact [854a591c0e]
Not logged in

Artifact 854a591c0e7a3a54b66916c1345aa04283dd0385:


     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
   100
   101
   102
   103
   104
   105
   106
   107
   108
   109
   110
   111
   112
   113
   114
   115
   116
   117
   118
   119
   120
   121
   122
   123
   124
   125
   126
   127
   128
   129
   130
   131
   132
   133
   134
   135
   136
   137
   138
   139
   140
   141
   142
   143
   144
   145
   146
   147
   148
   149
   150
   151
   152
   153
   154
   155
   156
   157
   158
   159
   160
   161
   162
   163
   164
   165
   166
   167
   168
   169
   170
   171
   172
   173
   174
   175
   176
   177
   178
   179
   180
   181
   182
   183
   184
   185
   186
   187
   188
   189
   190
   191
   192
   193
   194
   195
   196
   197
   198
   199
   200
   201
   202
   203
   204
   205
   206
   207
   208
   209
   210
   211
   212
   213
   214
   215
   216
   217
   218
   219
   220
   221
   222
   223
   224
   225
   226
   227
   228
   229
   230
   231
   232
   233
   234
   235
   236
   237
   238
   239
   240
   241
   242
   243
#include "nfs.h"

int iflag 0;
int xflag 0;
struct stk *xsp stack;
char *nxt &end;
char *last &end;

char *terr "snt\0\0";
char *stat1 "f rwxrwxrwx";
char *ng ".\0";

main(argc,argv)
int argc;
char **argv;
	{
	extern fout;
	int i;
	int compar();

	flush();
	fout = 2;
	sbrk(16);
	if (argc<2) ex(1); eargv=argv+argc;

	if((fn = open("/dev/tiu/d1",2)) < 0)
		{
		printf("Spider busy\n"); ex(2);
		}
	getpw(getuid(),nam);		/*  get login name  */
	for(np = nam; *np != ':'; np++);	/* find the ':' delimiter  */
	*np = '\0';
	name(nam);	/* put login name in buf to send to File Store */
	*bp++ = LOGIN;
	if(sendc(OK))ex(1);

	argv++;

		/* interpret command */

	if (*argv[0] != '-')
		{
		bp = buf;
		for (; argv != eargv; argv++)
			{
			for (tp = *argv; *tp; tp++)
				{
				*bp++ = *tp;
				if (bp == &buf[510]) {printf("too many args\n"); ex(1);}
				}
			*bp++ = ' ';
			}
		*bp++ = '\n';
		ff = 1;
		rd('r');
		qt(0);
		}

		/* break out functions and set flags for key args */

	for (tp = *argv++ + 1 ; *tp; tp++) switch(*tp)
		{
	case 't':
	case 'l':
	case 'm':
	case 'w':
	case 'u':
	case 'd':
	case 'r':
	case 's':
		if(op != 0){printf("illegal function\n"); qt(1);}
		op = *tp;
		continue;

	case 'v':
		vflag++;
		continue;

	case 'i':
		iflag++;
		continue;
	case 'x':
		xflag++;
		continue;

	case 'c':	/* another directory in File Store is used  */
		if (argv == eargv) 
			{
			printf("directory required with 'c' function\n");
			qt(1);
			}
		np = nam; bp = *argv;
		while (*np++ = *bp++);
		name(*argv++);
		*bp++ = CDIR;
		if (sendc(OK)) ex(1);
		argc--;
		continue;
	default:
		printf("illegal function\n"); qt(1);
		}


	if (argv == eargv)		/* no file is named use current directory */
		{ argv= &ng; eargv=argv+1;}
	sp = stack;
	for (;;)
		{
		tp = gen();
		if (!tp)	/* pick up next arg from cmd line */
			{
			if (argv == eargv) qt(0);
			tp = *argv++; np = nam;
			while(*np++ = *tp++);
			sp[spos] = --np;
			tp = nam;
			}
		fsp = tp;
		name(fsp);
		switch(op)
			{
		case 'm':
			if (ask()) break;
		mdir:
			*bp++ = UNLESS;
			*bp++ = DCREATE;
			*bp++ = FI;
			goto single;
		case 'w':
		case 'u':
			if (ask()) break;
			ff = open(tp,0);
			if (ff<0) goto erf;
			if (dir()) goto mdir;
			if(op == 'u')	/* test if file has been updated  */
				{
				tme[0] = dirbuf[16]; tme[1] = dirbuf[17];
				i = gstat();
				if (i == 0)
					{
					/* file exists */
				if(dbcmp(tme,dirbuf->i_modtime) < 0)
					 	{ close(ff); break;}
					}
				else if (i != -1) break;
				name(fsp);
				}
			*bp++ = FCREATE; *bp++ = WRITE; *bp++ = CLOSE;
			if(sendc(WRITE))break;		/* send the command  */
			sum=0; length=0;
			do	{
				nchar = read(ff,buf,512);
/*
				sum =+ addup(nchar); length =+ nchar;
*/
				if (nchar==0) code=2; else code=1;
				if (send(nchar,code) < 0) trouble();
				} while(nchar > 0);
			if(check(OK) < 0)		 /* error */
				{
				exx(); qt(1);
				}
			goto knxt;
		case 'r':
			if(xflag ||ask()) break;
			if(xdir(1))		/* extract a directory */
				{
				/* is it an existing directory */
				if(((i = stat(tp,dirbuf)) >= 0))break;
				if((i = fork()) == 0)
					execl("/bin/mkdir","mkdir",tp,0);
				if((i < 0) || ((wait(&i)) < 0) || ((stat(tp,dirbuf)) < 0))
					{
					printf("directory %s cannot be created\n",nam);qt(1);
					}
				break;
				}
			if((ff = creat(tp,0666)) < 0)goto erf;
			*bp++ = itype; *bp++ = 0; *bp++ = 0;
			*bp++ = OPEN; *bp++ = READ; *bp++ = CLOSE;
			if(rd(op))		/* read data and put in file  */
				goto cnxt1;		/* an error */
		knxt:
/*
			bp = buf; *bp++ = 'K';
			*bp++ = (sum >> 8); *bp++ = (sum & 0377);
			*bp++ = (length >> 8); *bp++ = (length & 0377);
			if(sendc(OK))goto cnxt1;
*/
		cnxt:
			if(vflag)printf("%c %s\n",op,nam);
		cnxt1:
			close(ff);
			break;
		case 'd':
			if (argc < 3) ex(0);
			xflag = 1;
			if ((xdir(1) == 1) || (ask())) break;
			*bp++ = DELETE;
		single:
			if((!sendc(OK)) && (vflag))		/* send just a command -no data  */
			printf("%c %s\n",op,nam);
			break;
		case 's':
			fout = 1;
			spstat();		/* get status from file store  */
			fout = 2;
			break;

		case 't':
		case 'l':
			nxt = &end;
			i = xdir(0);
			if ((i == 0) || (i == 2))
				{
				fout = 1;
				astat(op);
				fout = 2;
				break;
				}
			if (i > 0)
				{
				qsort(&end,(nxt - &end)/14,14,compar);
				for(tp = &end; tp < nxt; tp =+ 14)
					{
					append(tp,sp[spos]);name(fsp);
					fout = 1;
					if (op == 't') printf("%s\n",tp);
					else astat(op);
					fout = 2;
					}
				}
			break;
		default:
			printf("illegal op-code\n");
			qt(1);
			}
	nxtarg:;
		}
erf:
	printf("%s : cannot open ",tp); perror(""); printf("\n");
	goto nxtarg;
	}