shithub: riscv

Download patch

ref: 4a634d21024ee8d24e60d5414ee879cf61ea3275
parent: 9fe137733670fbd5249f96ed62f0f2f92514d8b6
author: cinap_lenrek <[email protected]>
date: Sat Dec 22 15:49:24 EST 2018

dossrv: use 64 bit vlong for sectors

--- a/sys/src/cmd/dossrv/dat.h
+++ b/sys/src/cmd/dossrv/dat.h
@@ -123,18 +123,18 @@
 	int	nresrv;			/* sectors */
 	int	nfats;			/* usually 2; modified to 1 if fat mirroring disabled */
 	int	rootsize;		/* number of entries, for fat12 and fat16 */
-	long	volsize;		/* in sectors */
+	vlong	volsize;		/* in sectors */
 	int	mediadesc;
-	long	fatsize;		/* in sectors */
-	int	fatclusters;
+	vlong	fatsize;		/* in sectors */
+	long	fatclusters;
 	int	fatbits;		/* 12, 16, or 32 */
-	long	fataddr;		/* sector number of first valid fat entry */
-	long	rootaddr;		/* for fat16 or fat12, sector of root dir */
+	vlong	fataddr;		/* sector number of first valid fat entry */
+	vlong	rootaddr;		/* for fat16 or fat12, sector of root dir */
+	vlong	dataaddr;		/* initial sector of data clusters */
 	long	rootstart;		/* for fat32, cluster of root dir */
-	long	dataaddr;		/* initial sector of data clusters */
 	long	freeptr;		/* next free cluster candidate */
 	long	freeclusters;		/* count of free clusters, for fat32 */
-	int	fatinfo;		/* fat info sector location; 0 => none */
+	vlong	fatinfo;		/* fat info sector location; 0 => none */
 };
 
 enum
@@ -178,14 +178,14 @@
 #define PLONG(p,v)	((p)[0]=(v),(p)[1]=(v)>>8,(p)[2]=(v)>>16,(p)[3]=(v)>>24)
 
 struct Dosptr{
-	ulong	addr;		/* sector & entry within of file's directory entry */
+	vlong	addr;		/* sector & entry within of file's directory entry */
+	vlong	paddr;		/* of parent's directory entry */
 	ulong	offset;
-	ulong	paddr;		/* of parent's directory entry */
 	ulong	poffset;
 	ulong	iclust;		/* ordinal within file */
 	ulong	clust;
-	ulong	naddr;		/* next block in directory (for writing multi entry elements) */
-	ulong	prevaddr;
+	vlong	naddr;		/* next block in directory (for writing multi entry elements) */
+	vlong	prevaddr;
 	Iosect *p;
 	Dosdir *d;
 };
@@ -203,7 +203,7 @@
 	uchar	isfat32;	/* is a fat 32 file system? */
 	short	dev;
 	short	fmt;
-	long	offset;
+	vlong	offset;
 	void	*ptr;
 };
 
--- a/sys/src/cmd/dossrv/devio.c
+++ b/sys/src/cmd/dossrv/devio.c
@@ -21,13 +21,13 @@
 }
 
 int
-devread(Xfs *xf, long addr, void *buf, long n)
+devread(Xfs *xf, vlong addr, void *buf, long n)
 {
 	long nread;
 
 	if(xf->dev < 0)
 		return -1;
-	nread = pread(xf->dev, buf, n, xf->offset+(vlong)addr*Sectorsize);
+	nread = pread(xf->dev, buf, n, xf->offset+addr*Sectorsize);
 	if (nread == n)
 		return 0;
 	return deverror("read", xf, addr, n, nread);
@@ -34,7 +34,7 @@
 }
 
 int
-devwrite(Xfs *xf, long addr, void *buf, long n)
+devwrite(Xfs *xf, vlong addr, void *buf, long n)
 {
 	long nwrite;
 
@@ -43,7 +43,7 @@
 
 	if(xf->dev < 0)
 		return -1;
-	nwrite = pwrite(xf->dev, buf, n, xf->offset+(vlong)addr*Sectorsize);
+	nwrite = pwrite(xf->dev, buf, n, xf->offset+addr*Sectorsize);
 	if (nwrite == n)
 		return 0;
 	return deverror("write", xf, addr, n, nwrite);
--- a/sys/src/cmd/dossrv/dosfs.c
+++ b/sys/src/cmd/dossrv/dosfs.c
@@ -705,7 +705,8 @@
 	Iosect *parp;
 	Dosdir *pard, *d, od;
 	char sname[13];
-	ulong oaddr, ooffset, length;
+	ulong ooffset, length;
+	vlong oaddr;
 	long start;
 	int i, longtype, changes, attr;
 
--- a/sys/src/cmd/dossrv/dossubs.c
+++ b/sys/src/cmd/dossrv/dossubs.c
@@ -168,11 +168,11 @@
 	else
 		bp->fatbits = 16;
 
-	chat("fatbits=%d (%d clusters)...", bp->fatbits, bp->fatclusters);
+	chat("fatbits=%d (%ld clusters)...", bp->fatbits, bp->fatclusters);
 	for(i=0; i<b->nfats; i++)
-		chat("fat %d: %ld...", i, bp->fataddr+i*bp->fatsize);
-	chat("root: %ld...", bp->rootaddr);
-	chat("data: %ld...", bp->dataaddr);
+		chat("fat %d: %lld...", i, bp->fataddr+i*bp->fatsize);
+	chat("root: %lld...", bp->rootaddr);
+	chat("data: %lld...", bp->dataaddr);
 	putsect(p);
 	return 0;
 }
@@ -193,7 +193,7 @@
 }
 
 int
-isroot(ulong addr)
+isroot(vlong addr)
 {
 	return addr == 0;
 }
@@ -217,7 +217,7 @@
 	dp->d = nil;
 	if(!isroot(dp->addr)){
 		if(f->qid.path != QIDPATH(dp)){
-			chat("qid mismatch f=%#llux d=%#lux...", f->qid.path, QIDPATH(dp));
+			chat("qid mismatch f=%#llux d=%#llux...", f->qid.path, QIDPATH(dp));
 			putsect(p);
 			errno = Enonexist;
 			return -1;
@@ -351,7 +351,7 @@
 /*
  * return the disk sector for the isect disk sector in f 
  */
-long
+vlong
 fileaddr(Xfile *f, long isect, int cflag)
 {
 	Dosbpb *bp;
@@ -516,7 +516,8 @@
 	Dosbpb *bp;
 	Dosdir *d;
 	char buf[261], *bname;
-	int isect, addr, o, addr1, addr2, prevaddr, prevaddr1, o1, islong, have, need, sum;
+	int isect, o, o1, islong, have, need, sum;
+	vlong addr, addr1, addr2, prevaddr, prevaddr1;
 
 	xf = f->xf;
 	bp = xf->ptr;
@@ -642,7 +643,8 @@
 {
 	Xfs *xf = f->xf;
 	Dosbpb *bp = xf->ptr;
-	int isect, addr, o;
+	int isect, o;
+	vlong addr;
 	Iosect *p;
 	Dosdir *d;
 
@@ -679,7 +681,8 @@
 	Xfs *xf;
 	Dosbpb *bp;
 	Dir dir;
-	int isect, addr, o, islong, sum;
+	int isect, o, islong, sum;
+	vlong addr;
 	Iosect *p;
 	Dosdir *d;
 	long rcnt, n;
@@ -765,7 +768,8 @@
 	Dosptr *dp;
 	Dosdir *xd;
 	Iosect *p;
-	long k, o, so, start, pstart, ppstart, st, ppclust;
+	long o, so, start, pstart, ppstart, st, ppclust;
+	vlong k;
 
 	bp = f->xf->ptr;
 	dp = f->ptr;
@@ -775,7 +779,7 @@
 	ndp->addr = dp->paddr;
 	ndp->offset = dp->poffset;
 
-	chat("walkup: paddr=%#lx...", dp->paddr);
+	chat("walkup: paddr=%#llx...", dp->paddr);
 
 	/*
 	 * root's paddr is always itself
@@ -861,7 +865,7 @@
 	k = ppclust ? clust2sect(bp, ppclust) : bp->rootaddr;
 	p = getsect(f->xf, k);
 	if(p == nil){
-		chat("getsect %ld failed\n", k);
+		chat("getsect %lld failed\n", k);
 		goto error;
 	}
 	xd = (Dosdir *)p->iobuf;
@@ -904,7 +908,7 @@
 		putsect(p);
 		p = getsect(f->xf, k);
 		if(p == 0){
-			chat("getsect %ld failed\n", k);
+			chat("getsect %lld failed\n", k);
 			goto error;
 		}
 	}
@@ -927,7 +931,8 @@
 	Dosbpb *bp = xf->ptr;
 	Dosptr *dp = f->ptr;
 	Dosdir *d = dp->d;
-	int isect, addr, o, c;
+	int isect, o, c;
+	vlong addr;
 	Iosect *p;
 	uchar *buf;
 	ulong length, rcnt;
@@ -972,7 +977,8 @@
 	Dosbpb *bp = xf->ptr;
 	Dosptr *dp = f->ptr;
 	Dosdir *d = dp->d;
-	int isect, addr, o, c;
+	int isect, o, c;
+	vlong addr;
 	Iosect *p;
 	uchar *buf;
 	ulong length, rcnt, dlen;
@@ -1018,7 +1024,7 @@
 	else if(dp->addr && dp->clust){
 		c = bp->clustsize*bp->sectsize;
 		if(dp->iclust > (dlen+c-1)/c)
-			length = c*dp->iclust;
+			length = (ulong)c*dp->iclust;
 	}
 	if(length > dlen)
 		PLONG(d->length, length);
@@ -1085,7 +1091,7 @@
  * creation and access dates
  */
 void
-getdir(Xfs *xfs, Dir *dp, Dosdir *d, int addr, int offset)
+getdir(Xfs *xfs, Dir *dp, Dosdir *d, vlong addr, int offset)
 {
 	if(d == nil || addr == 0)
 		panic("getdir on root");
@@ -1352,12 +1358,13 @@
 }
 
 long
-getfat(Xfs *xf, int n)
+getfat(Xfs *xf, long n)
 {
 	Dosbpb *bp = xf->ptr;
 	Iosect *p;
-	ulong k, sect;
-	int o, fb;
+	ulong k, o;
+	vlong sect;
+	int fb;
 
 	if(n < FATRESRV || n >= bp->fatclusters)
 		return -1;
@@ -1393,7 +1400,7 @@
 			k &= 0xfff;
 	}
 	if(chatty > 1)
-		chat("fat(%#x)=%#lx...", n, k);
+		chat("fat(%#lx)=%#lux...", n, k);
 
 	/*
 	 * This is a very strange check for out of range.
@@ -1401,7 +1408,7 @@
 	 * FFF8 through FFFF all signify ``end of cluster chain.''
 	 * This generalizes to other-sized FATs.
 	 */
-	if(k >= (1 << fb) - 8)
+	if(k >= (1UL << fb) - 8)
 		return -1;
 
 	return k;
@@ -1413,7 +1420,8 @@
 	Fatinfo *fi;
 	Dosbpb *bp;
 	Iosect *p;
-	ulong k, sect, esect;
+	ulong k;
+	vlong sect, esect;
 	int o;
 
 	bp = xf->ptr;
@@ -1543,7 +1551,8 @@
 	Xfs *xf;
 	Iosect *wp, *rp;
 	long clust, next, last, start, rclust, wclust, eclust, ostart;
-	int isok, i, n, nclust, nrun, rs, ws;
+	int isok, i, n, nclust, nrun;
+	vlong rs, ws;
 
 	xf = f->xf;
 	bp = xf->ptr;
@@ -1707,20 +1716,16 @@
 	putfat(xf, start, 0);
 }
 
-long
+vlong
 clust2sect(Dosbpb *bp, long clust)
 {
-	return bp->dataaddr + (clust - FATRESRV) * bp->clustsize;
+	return bp->dataaddr + ((vlong)(clust - FATRESRV) * bp->clustsize);
 }
 
 long
-sect2clust(Dosbpb *bp, long sect)
+sect2clust(Dosbpb *bp, vlong sect)
 {
-	long c;
-
-	c = (sect - bp->dataaddr) / bp->clustsize + FATRESRV;
-	assert(sect == clust2sect(bp, c));
-	return c;
+	return ((sect - bp->dataaddr) / bp->clustsize) + FATRESRV;
 }
 
 void
--- a/sys/src/cmd/dossrv/fns.h
+++ b/sys/src/cmd/dossrv/fns.h
@@ -8,18 +8,18 @@
 int	cistrcmp(char*, char*);
 int	classifyname(char*);
 Xfile	*clean(Xfile*);
-long	clust2sect(Dosbpb*, long);
+vlong	clust2sect(Dosbpb*, long);
 void	dirdump(void*);
 int	dosfs(Xfs*);
-void	dosptrreloc(Xfile *f, Dosptr *dp, ulong addr, ulong offset);
+void	dosptrreloc(Xfile *f, Dosptr *dp, vlong addr, ulong offset);
 int	emptydir(Xfile*);
 int	eqqid(Qid, Qid);
 int	falloc(Xfs*);
 void	ffree(Xfs *xf, long start);
-long	fileaddr(Xfile*, long, int);
+vlong	fileaddr(Xfile*, long, int);
 void	fixname(char*);
-void	getdir(Xfs*, Dir*, Dosdir*, int, int);
-long	getfat(Xfs*, int);
+void	getdir(Xfs*, Dir*, Dosdir*, vlong, int);
+long	getfat(Xfs*, long);
 int	getfile(Xfile*);
 void	getname(char*, Dosdir*);
 char	*getnamesect(char*, char*, uchar*, int*, int*, int);
@@ -28,7 +28,7 @@
 long	gtime(Dosdir *d);
 void	io(int srvfd);
 int	iscontig(Xfs *xf, Dosdir *d);
-int	isroot(ulong addr);
+int	isroot(vlong addr);
 int	makecontig(Xfile*, int);
 void	mkalias(char*, char*, int);
 int	nameok(char*);
@@ -60,7 +60,7 @@
 void	rwstat(void);
 void	rversion(void);
 int	searchdir(Xfile*, char*, Dosptr*, int, int);
-long	sect2clust(Dosbpb*, long);
+long	sect2clust(Dosbpb*, vlong);
 int	truncfile(Xfile*, vlong length);
 int	utftorunes(Rune*, char*, int);
 int	walkup(Xfile*, Dosptr*);
--- a/sys/src/cmd/dossrv/iotrack.c
+++ b/sys/src/cmd/dossrv/iotrack.c
@@ -20,22 +20,22 @@
 #define	TOFRONT(h, p)	((h)->next  != (p) && (UNLINK(p, next, prev), LINK(h,p, next, prev)))
 
 Iosect *
-getsect(Xfs *xf, long addr)
+getsect(Xfs *xf, vlong addr)
 {
 	return getiosect(xf, addr, 1);
 }
 
 Iosect *
-getosect(Xfs *xf, long addr)
+getosect(Xfs *xf, vlong addr)
 {
 	return getiosect(xf, addr, 0);
 }
 
 Iosect *
-getiosect(Xfs *xf, long addr, int rflag)
+getiosect(Xfs *xf, vlong addr, int rflag)
 {
 	Iotrack *t;
-	long taddr;
+	vlong taddr;
 	int toff;
 	Iosect *p;
 
@@ -86,7 +86,7 @@
 }
 
 Iotrack *
-getiotrack(Xfs *xf, long addr)
+getiotrack(Xfs *xf, vlong addr)
 {
 	Iotrack *hp, *p;
 	Iotrack *mp = &hiob[HIOB];
@@ -94,7 +94,7 @@
 /*
  *	chat("iotrack %d,%d...", dev, addr);
  */
-	h = (xf->dev<<24) ^ addr;
+	h = (xf->dev<<24) ^ (long)addr;
 	if(h < 0)
 		h = ~h;
 	h %= HIOB;
@@ -180,7 +180,7 @@
 {
 	int i, ref;
 
-	chat("[twrite %ld...", t->addr);
+	chat("[twrite %lld...", t->addr);
 	if(t->flags & BSTALE){
 		for(ref=0,i=0; i<Sect2trk; i++)
 			if(t->tp->p[i])
@@ -210,7 +210,7 @@
 	for(i=0; i<Sect2trk; i++)
 		if(t->tp->p[i])
 			++ref;
-	chat("[tread %ld+%ld...", t->addr, t->xf->offset);
+	chat("[tread %lld+%lld...", t->addr, t->xf->offset);
 	if(ref == 0){
 		if(devread(t->xf, t->addr, t->tp->buf, Trksize) < 0){
 			chat("error]");
--- a/sys/src/cmd/dossrv/iotrack.h
+++ b/sys/src/cmd/dossrv/iotrack.h
@@ -22,7 +22,7 @@
 {
 	short	flags;
 	Xfs *	xf;
-	long	addr;
+	vlong	addr;
 	Iotrack	*next;		/* in lru list */
 	Iotrack	*prev;
 	Iotrack	*hnext;		/* in hash list */
@@ -48,15 +48,15 @@
 #define	BIMM		(1<<1)
 #define	BSTALE		(1<<2)
 
-Iosect*	getiosect(Xfs*, long, int);
-Iosect*	getosect(Xfs*, long);
-Iosect*	getsect(Xfs*, long);
+Iosect*	getiosect(Xfs*, vlong, int);
+Iosect*	getosect(Xfs*, vlong);
+Iosect*	getsect(Xfs*, vlong);
 Iosect*	newsect(void);
-Iotrack*	getiotrack(Xfs*, long);
+Iotrack*	getiotrack(Xfs*, vlong);
 int	canmlock(MLock*);
 int	devcheck(Xfs*);
-int	devread(Xfs*, long, void*, long);
-int	devwrite(Xfs*, long, void*, long);
+int	devread(Xfs*, vlong, void*, long);
+int	devwrite(Xfs*, vlong, void*, long);
 int	tread(Iotrack*);
 int	twrite(Iotrack*);
 void	freesect(Iosect*);
--- a/sys/src/cmd/dossrv/xfile.c
+++ b/sys/src/cmd/dossrv/xfile.c
@@ -17,7 +17,7 @@
 	Dir *dir;
 	Qid dqid;
 	char *p, *q;
-	long offset;
+	vlong offset;
 	int fd, omode;
 
 	USED(user);
@@ -38,8 +38,8 @@
 	offset = 0;
 	if(p = strrchr(name, ':')){
 		*p++ = 0;
-		offset = strtol(p, &q, 0);
-		chat("name %s, offset %ld\n", p, offset);
+		offset = strtoll(p, &q, 0);
+		chat("name %s, offset %lld\n", p, offset);
 		if(offset < 0 || p == q){
 			errno = Enofilsys;
 			return 0;
@@ -225,7 +225,7 @@
  * relocate the dos entries of all fids in the same file
  */
 void
-dosptrreloc(Xfile *f, Dosptr *dp, ulong addr, ulong offset)
+dosptrreloc(Xfile *f, Dosptr *dp, vlong addr, ulong offset)
 {
 	int i;
 	Xfile *p;