Browse Source

Plan 9 from Bell Labs 2010-08-19

David du Colombier 13 years ago
parent
commit
b67575fca5
2 changed files with 29 additions and 22 deletions
  1. 14 16
      sys/src/cmd/aquarela/smbcomwrite.c
  2. 15 6
      sys/src/cmd/aquarela/smbtrans2query.c

+ 14 - 16
sys/src/cmd/aquarela/smbcomwrite.c

@@ -163,7 +163,7 @@ smbcomwriteandx(SmbSession *s, SmbHeader *h, uchar *pdata, SmbBuffer *b)
 	SmbTree *t;
 	SmbFile *f;
 	ushort dataoff, fid, count;
-	ulong offset;
+	vlong offset;
 	long nb;
 
 	if (h->wordcount != 12 && h->wordcount != 14)
@@ -174,21 +174,21 @@ smbcomwriteandx(SmbSession *s, SmbHeader *h, uchar *pdata, SmbBuffer *b)
 	andxoffset = smbnhgets(pdata); pdata += 2;	// andx offset
 	fid = smbnhgets(pdata); pdata += 2;		// fid
 	offset = smbnhgetl(pdata); pdata += 4;		// offset in file
-	pdata += 4;					// reserved
+	pdata += 4;					// timeout
 	pdata += 2;					// write mode
-	pdata += 2;					// bytes waiting to be written
-	count = ((long)smbnhgets(pdata) << 16); pdata += 2; // MSBs of length or zero 
-	count |= smbnhgets(pdata); pdata += 2;		// LSBs of length
+	pdata += 2;					// (Remaining) bytes waiting to be written
+	pdata += 2;					// Reserved
+	count = smbnhgets(pdata); pdata += 2;		// LSBs of length
 	dataoff = smbnhgets(pdata); pdata += 2;		// offset to data in packet
-	if (h->wordcount == 14)
-		offset = ((long)smbnhgets(pdata) << 16); pdata += 2; // MSBs of offset in file, if long pkt 
-	pdata += 4;					// data bytes to write (including those not sent yet)
-
-	USED(pdata);
+	if (dataoff + count > smbbufferwriteoffset(b))
+		return SmbProcessResultFormat;
+	if(h->wordcount == 14)
+		offset |= (vlong)smbnhgetl(pdata)<<32;
 
-	smblogprint(SMB_COM_WRITE_ANDX, "smbcomwriteandx: fid 0x%.4ux count 0x%.4ux offset 0x%.8lux\n",
+	smblogprint(SMB_COM_WRITE_ANDX, "smbcomwriteandx: fid 0x%.4ux count 0x%.4ux offset 0x%.llux\n",
 		fid, count, offset);
 
+
 	t = smbidmapfind(s->tidmap, h->tid);
 	if (t == nil) {
 		smbseterror(s, ERRSRV, ERRinvtid);
@@ -216,14 +216,12 @@ smbcomwriteandx(SmbSession *s, SmbHeader *h, uchar *pdata, SmbBuffer *b)
 	if (!smbbufferputandxheader(s->response, h, &s->peerinfo, andxcommand, &andxoffsetfixup))
 		return SmbProcessResultMisc;
 
-	if (!smbbufferputs(s->response, nb)			// count
-		|| !smbbufferputs(s->response, 0)		// datacompactionmode
-		|| !smbbufferputs(s->response, 0)		// remaining
-		|| !smbbufferputl(s->response, 0)		// reserved
+	if (!smbbufferputs(s->response, nb)			// Count
+		|| !smbbufferputs(s->response, 0)		// Available
+		|| !smbbufferputl(s->response, 0)		// Reserved
 		|| !smbbufferputs(s->response, 0))		// byte count in reply
 		return SmbProcessResultMisc;
 
-
 	if (andxcommand != SMB_COM_NO_ANDX_COMMAND)
 		return smbchaincommand(s, h, andxoffsetfixup, andxcommand, andxoffset, b);
 

+ 15 - 6
sys/src/cmd/aquarela/smbtrans2query.c

@@ -30,7 +30,6 @@ query(SmbSession *s, char *cmdname, char *filename, ushort infolevel, vlong cbo,
 			|| !smbbufferputv(s->transaction.out.data, ntmtime)
 			|| !smbbufferputv(s->transaction.out.data, ntmtime)
 			|| !smbbufferputl(s->transaction.out.data, dosmode))
-//			|| !smbbufferputl(s->transaction.out.data, 0))
 			return SmbProcessResultMisc;
 		break;
 	case SMB_QUERY_FILE_ALL_INFO:
@@ -153,6 +152,7 @@ smbtrans2queryfileinformation(SmbSession *s, SmbHeader *h)
 	SmbProcessResult pr;
 	ushort fid;
 	ushort infolevel;
+	vlong o;
 	Dir *d;
 
 	t = smbidmapfind(s->tidmap, h->tid);
@@ -174,8 +174,18 @@ smbtrans2queryfileinformation(SmbSession *s, SmbHeader *h)
 		pr = SmbProcessResultError;
 		goto done;
 	}
-	d = dirfstat(f->fd);
-	pr = query(s, "file", f->name, infolevel, seek(f->fd, 0, 1), d);
+	if(f->fd >= 0){
+		o = seek(f->fd, 0, 1);
+		d = dirfstat(f->fd);
+	} else {
+		char *fullpath = nil;
+
+		o = 0;
+		smbstringprint(&fullpath, "%s%s", f->t->serv->path, f->name);
+		d = dirstat(fullpath);
+		free(fullpath);
+	}
+	pr = query(s, "file", f->name, infolevel, o, d);
 	free(d);
 done:
 	smbbufferfree(&b);
@@ -238,9 +248,8 @@ smbtrans2queryfsinformation(SmbSession *s, SmbHeader *h)
 		break;
 	case SMB_QUERY_FS_SIZE_INFO:
 		translogprint(s->transaction.in.setup[0], "SMB_QUERY_FS_SIZE_INFO\n");
-		if (!smbbufferputv(s->transaction.out.data, 0xffffffffffffffffLL)
-                        /* Windows sees 0xffffffffffffffffLL as "Nnot enough space" */
-			|| !smbbufferputv(s->transaction.out.data, 0x0000ffffffffffffLL)
+		if (!smbbufferputv(s->transaction.out.data, 0LL)
+			|| !smbbufferputv(s->transaction.out.data, 0LL)
 			|| !smbbufferputl(s->transaction.out.data, 1 << (smbglobals.l2allocationsize - smbglobals.l2sectorsize))
 			|| !smbbufferputl(s->transaction.out.data, 1 << smbglobals.l2sectorsize))
 			goto misc;