From e8337269eec5eefe7888a0cecc530febfb47bad2 Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Tue, 6 Feb 1996 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 1996-02-06 --- port/devtinyfs.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/port/devtinyfs.c b/port/devtinyfs.c index 9f12616f9cd80d1e8fe45275597bd866a04e068c..035364e5977c2bc0de79845844be6e23cd91323e 100644 --- a/port/devtinyfs.c +++ b/port/devtinyfs.c @@ -55,6 +55,7 @@ struct Mdata { typedef struct Tfile Tfile; struct Tfile { + Lock; int r; char name[NAMELEN]; ushort bno; @@ -182,6 +183,17 @@ validdata(Tfs *fs, uchar *p) return md; } +static Mdata* +readdata(Tfs *fs, ulong bno, uchar *buf) +{ + if(bno >= fs->nblocks) + return 0; + n = devtab[fs->c->type].read(fs->c, buf, Blen, Blen*bno); + if(n != Blen) + return 0; + return validdata(fs, buf); +} + static int writedir(Tfs *fs, Tfile *f) { @@ -603,6 +615,9 @@ tinyfsread(Chan *c, void *a, long n, ulong offset) Tfs *fs; Tfile *f; int sofar, i; + ulong bno, tbno; + Mdata *md; + uchar buf[Blen]; if(c->qid.path & CHDIR) return devdirread(c, a, n, tinyfstab, Ntinyfstab, tinyfsgen); @@ -614,6 +629,22 @@ tinyfsread(Chan *c, void *a, long n, ulong offset) if(n + offset >= f->length) n = f->length - offset; + /* walk to first data block */ + bno = f->dbno; + for(sofar = 0; sofar < offset; sofar += Blen){ + md = readdata(fs, bno, buf); + if(md == 0) + error(Eio); + bno = GETS(md->bno); + } + + /* read first block */ + i = offset%Blen; + + /* read data */ + for(sofar = 0; sofar+Blen < offset; sofar += Blen){ + + return n; }