ref: 7c1b7019f8e0281bf511174839520716bebbc8fb
parent: bcab1344b36df26aa0508e65eafd0d7b9626a0b5
author: 9ferno <[email protected]>
date: Thu Oct 20 16:40:03 EDT 2022
working tag and reli calculations
--- a/chktag.c
+++ /dev/null
@@ -1,67 +1,0 @@
-#include <u.h>
-#include <libc.h>
-#include "dat.h"
-#include "fns.h"
-
-/*
- write out a single formatted block based on the tag
- ./6.chktag 23; ./6.chktag 24; ./6.chktag 74
- ./6.chktag 75; ./6.chktag 3100 '
- */
-
-int debug = 0;
-char *devfile = nil;
-
-static void
-usage(void)
-{
- fprint(2, "usage: chktag [-D] reli\n");
- exits("usage");
-}
-
-void
-drilldown(u8 tag, u64 reli)
-{
- print("%s reli %llud is at [%llud]\n", tagnames[tag], reli, reli/nperindunit(tag));
- if(tag > Tind0)
- drilldown(tag-1, reli%nperindunit(tag));
-}
-
-void
-main(int argc, char *argv[])
-{
- u64 reli;
- u8 tag;
-
- ARGBEGIN{
- default: usage();
- case 'D': debug++; break;
- }ARGEND
-
- if(argc != 1)
- usage();
-
- reli = atoll(argv[0]);
- print("--- reli %llud ---\n", reli);
- if(reli < Ndblock){
- print("Direct span %llud\n", reli);
- }else{
- tag = rel2tind(reli);
- if(tag >= Tmaxind)
- panic("invalid reli %llud rel2tind(reli) %d > Tmaxind %d\n",
- reli, rel2tind(reli), Tmaxind);
-
- print("%d %s\n", tag, tagnames[tag]);
- print("nperindunit(%s) %llud\n", tagnames[tag], nperindunit(tag));
- print("nperiblock(%s) %llud\n", tagnames[tag], nperiblock(tag));
-
- print("indirect block %d\n", tag-Tind0);
- drilldown(tag, reli-tagstartreli(tag));
- }
- print("---\n");
- for(tag=Tind0; tag < Maxtind; tag++){
- print("%s reli start %llud max %llud\n",
- tagnames[tag], tagstartreli(tag), maxreli(tag));
- }
- exits(0);
-}
--- a/dat.c
+++ b/dat.c
@@ -12,6 +12,8 @@
[Tind1] "Tind1",
[Tind2] "Tind2",
[Tind3] "Tind3",
+ [Tind4] "Tind4",
+ [Tind5] "Tind5",
/* add more Tind tags here ... */
};
--- a/dentry.c
+++ b/dentry.c
@@ -94,7 +94,7 @@
n = nperindunit(tag);
if(reli/n >= Nindperblock){
panic("updateindblock invalid reli: indblkno %llud reli %llud tag %s"
- " directblkno %llud reli/n %llud nperindunit(tag) %d\n",
+ " directblkno %llud reli/n %llud nperindunit(tag) %llud\n",
indblkno, reli, tagnames[tag], blkno, reli/n, Nindperblock);
dprint("%s",errstring[Ephase]);
return 0;
@@ -106,7 +106,7 @@
}else{
if(reli >= Nindperblock){
panic("updateindblock invalid reli: indblkno %llud reli %llud tag %s"
- " directblkno %llud Nindperblock %d\n",
+ " directblkno %llud Nindperblock %llud\n",
indblkno, reli, tagnames[tag], blkno, Nindperblock);
dprint("%s",errstring[Ephase]);
return 0;
--- a/fns.h
+++ b/fns.h
@@ -3,8 +3,8 @@
u64 nperindunit(u16 tag);
u8 rel2tind(u64 reli);
u64 tagstartreli(u8 tag);
-u64 maxn(u8 tag);
u64 maxreli(u8 tag);
+u64 maxblocks(u8 tag);
/* actual device i/o routines */
u64 devinit(char *devfile);
--- a/tag.c
+++ b/tag.c
@@ -34,8 +34,7 @@
v = 1;
for(i = 1; i <= n; i++)
- v = mulu64ov(v,base);
-// v = v*base;
+ v = v*base;
return v;
}
@@ -46,12 +45,16 @@
if(tag < Tind0 || tag > Tmaxind+1)
return 0;
- if(tag == Tind0)
- return 1;
- return Nindperblock*power(Blocksize/sizeof(u64), tag-Tind1);
+ return power(Nindperblock, tag-Tind0);
}
+/*
+ * compute BUFSIZE*(Ndblock+INDPERBUF+INDPERBUF²+INDPERBUF³+INDPERBUF⁴ .. upto ^Niblock)
+ * while watching for overflow; in that case, return 0.
+ */
+/* extern double pow(double x, double y); *//* return x ^ y (exponentiation) */
/* Each u64 address in the indirect block links to n Tdata/Tdentry blocks */
+/* Each u64 address in the indirect block links to n Tdata/Tdentry blocks */
u64
nperiblock(u16 tag)
{
@@ -95,18 +98,13 @@
}
u64
-maxn(u8 tag)
+maxreli(u8 tag)
{
- if(tag >= Maxtind || tag < Tind0)
- panic("maxn: invalid tag %d\n", tag);;
- if(tag == Tind0)
- return Ndblock+Nindperblock;
- else
- return nperiblock(tag) + tagstartreli(tag);
+ return tagstartreli(tag+1)-1;
}
u64
-maxreli(u8 tag)
+maxblocks(u8 tag)
{
- return maxn(tag)-1;
+ return maxreli(tag)+1;
}
--- a/tests/chkextents.rc
+++ b/tests/chkextents.rc
@@ -6,8 +6,7 @@
# checker.rc
for(b in extents/*){
- echo $b
diff $b^/output \
- <{cat $b^/input | 6.testextents} &&
- echo ' 'passed
+ <{cat $b^/input | 6.testextents} ||
+ echo ' '$b failed
}
--- /dev/null
+++ b/tests/chkreli.rc
@@ -1,0 +1,12 @@
+#!/bin/rc
+
+# tests the reli
+
+# cd /mnt/term/home/j/local/plan9/custom/mafs/tests/reli
+# checker.rc
+
+for(b in reli/*){
+ diff $b \
+ <{6.reli `{basename $b}} ||
+ echo ' '$b failed
+}
--- a/tests/mkfile
+++ b/tests/mkfile
@@ -2,11 +2,12 @@
BIN=/$objtype/bin/disk
-TARG=sizes offsets testextents pwrites # mfsck
+TARG=sizes offsets testextents pwrites reli # mfsck
OFILES=\
../dat.$O\
../misc.$O\
+ ../tag.$O\
HFILES=\
--- /dev/null
+++ b/tests/reli.c
@@ -1,0 +1,58 @@
+#include <u.h>
+#include <libc.h>
+#include "../dat.h"
+#include "../fns.h"
+
+/*
+ write out a single formatted block based on the tag
+ ./6.reli 23; ./6.reli 24; ./6.reli 74
+ ./6.reli 75; ./6.reli 3100 '
+ */
+
+int debug = 0;
+char *devfile = nil;
+
+static void
+usage(void)
+{
+ fprint(2, "usage: reli [-D] reli\n");
+ exits("usage");
+}
+
+void
+drilldown(u8 tag, u64 reli)
+{
+ print("%s reli %llud is at [%llud]\n", tagnames[tag], reli, reli/nperindunit(tag));
+ if(tag > Tind0)
+ drilldown(tag-1, reli%nperindunit(tag));
+}
+
+void
+main(int argc, char *argv[])
+{
+ u64 reli;
+ u8 tag;
+
+ ARGBEGIN{
+ default: usage();
+ case 'D': debug++; break;
+ }ARGEND
+
+ if(argc != 1)
+ usage();
+
+ reli = atoll(argv[0]);
+ print("reli %llud\n", reli);
+
+ if(reli > maxreli(Maxtind-1) || reli > 57731387017ULL)
+ exits("invalid reli");
+
+ if(reli < Ndblock){
+ print("dblock[%llud]\n", reli);
+ }else{
+ tag = rel2tind(reli);
+ print("iblock[%d]\n", tag-Tind0);
+ drilldown(tag, reli-tagstartreli(tag));
+ }
+ exits(0);
+}
--- /dev/null
+++ b/tests/reli/0
@@ -1,0 +1,2 @@
+reli 0
+dblock[0]
--- /dev/null
+++ b/tests/reli/1
@@ -1,0 +1,2 @@
+reli 1
+dblock[1]
--- /dev/null
+++ b/tests/reli/15018600
@@ -1,0 +1,6 @@
+reli 15018600
+iblock[3]
+Tind3 reli 14776334 is at [61]
+Tind2 reli 238326 is at [61]
+Tind1 reli 3842 is at [61]
+Tind0 reli 60 is at [60]
--- /dev/null
+++ b/tests/reli/15018601
@@ -1,0 +1,6 @@
+reli 15018601
+iblock[3]
+Tind3 reli 14776335 is at [61]
+Tind2 reli 238327 is at [61]
+Tind1 reli 3843 is at [61]
+Tind0 reli 61 is at [61]
--- /dev/null
+++ b/tests/reli/15018602
@@ -1,0 +1,7 @@
+reli 15018602
+iblock[4]
+Tind4 reli 0 is at [0]
+Tind3 reli 0 is at [0]
+Tind2 reli 0 is at [0]
+Tind1 reli 0 is at [0]
+Tind0 reli 0 is at [0]
--- /dev/null
+++ b/tests/reli/242264
@@ -1,0 +1,5 @@
+reli 242264
+iblock[2]
+Tind2 reli 238326 is at [61]
+Tind1 reli 3842 is at [61]
+Tind0 reli 60 is at [60]
--- /dev/null
+++ b/tests/reli/242265
@@ -1,0 +1,5 @@
+reli 242265
+iblock[2]
+Tind2 reli 238327 is at [61]
+Tind1 reli 3843 is at [61]
+Tind0 reli 61 is at [61]
--- /dev/null
+++ b/tests/reli/242266
@@ -1,0 +1,6 @@
+reli 242266
+iblock[3]
+Tind3 reli 0 is at [0]
+Tind2 reli 0 is at [0]
+Tind1 reli 0 is at [0]
+Tind0 reli 0 is at [0]
--- /dev/null
+++ b/tests/reli/31
@@ -1,0 +1,2 @@
+reli 31
+dblock[31]
--- /dev/null
+++ b/tests/reli/3100
@@ -1,0 +1,4 @@
+reli 3100
+iblock[1]
+Tind1 reli 3006 is at [48]
+Tind0 reli 30 is at [30]
--- /dev/null
+++ b/tests/reli/32
@@ -1,0 +1,3 @@
+reli 32
+iblock[0]
+Tind0 reli 0 is at [0]
--- /dev/null
+++ b/tests/reli/3936
@@ -1,0 +1,4 @@
+reli 3936
+iblock[1]
+Tind1 reli 3842 is at [61]
+Tind0 reli 60 is at [60]
--- /dev/null
+++ b/tests/reli/3937
@@ -1,0 +1,4 @@
+reli 3937
+iblock[1]
+Tind1 reli 3843 is at [61]
+Tind0 reli 61 is at [61]
--- /dev/null
+++ b/tests/reli/3938
@@ -1,0 +1,5 @@
+reli 3938
+iblock[2]
+Tind2 reli 0 is at [0]
+Tind1 reli 0 is at [0]
+Tind0 reli 0 is at [0]
--- /dev/null
+++ b/tests/reli/57731387017
@@ -1,0 +1,8 @@
+reli 57731387017
+iblock[5]
+Tind5 reli 56800235583 is at [61]
+Tind4 reli 916132831 is at [61]
+Tind3 reli 14776335 is at [61]
+Tind2 reli 238327 is at [61]
+Tind1 reli 3843 is at [61]
+Tind0 reli 61 is at [61]
--- /dev/null
+++ b/tests/reli/57731387018
@@ -1,0 +1,1 @@
+reli 57731387018
--- /dev/null
+++ b/tests/reli/74
@@ -1,0 +1,3 @@
+reli 74
+iblock[0]
+Tind0 reli 42 is at [42]
--- /dev/null
+++ b/tests/reli/93
@@ -1,0 +1,3 @@
+reli 93
+iblock[0]
+Tind0 reli 61 is at [61]
--- /dev/null
+++ b/tests/reli/931151433
@@ -1,0 +1,7 @@
+reli 931151433
+iblock[4]
+Tind4 reli 916132831 is at [61]
+Tind3 reli 14776335 is at [61]
+Tind2 reli 238327 is at [61]
+Tind1 reli 3843 is at [61]
+Tind0 reli 61 is at [61]
--- /dev/null
+++ b/tests/reli/931151434
@@ -1,0 +1,8 @@
+reli 931151434
+iblock[5]
+Tind5 reli 0 is at [0]
+Tind4 reli 0 is at [0]
+Tind3 reli 0 is at [0]
+Tind2 reli 0 is at [0]
+Tind1 reli 0 is at [0]
+Tind0 reli 0 is at [0]
--- /dev/null
+++ b/tests/reli/94
@@ -1,0 +1,4 @@
+reli 94
+iblock[1]
+Tind1 reli 0 is at [0]
+Tind0 reli 0 is at [0]
--- a/tests/sizes.c
+++ b/tests/sizes.c
@@ -1,27 +1,39 @@
#include <u.h>
#include <libc.h>
#include "../dat.h"
+#include "../fns.h"
-static uvlong
-adduvlongov(uvlong a, uvlong b)
+void
+main(int, void**)
{
- uvlong r = a + b;
+ int t;
+ u64 n;
- if (r < a || r < b)
- return 0;
- return r;
-}
+ print("Namelen %llud Ndblock %d Niblock %d\n", Namelen, Ndblock, Niblock);
+ print("Blocksize %llud Nindperblock %llud\n",
+ Blocksize, Nindperblock);
-static uvlong
-muluvlongov(uvlong a, uvlong b)
-{
- uvlong r = a * b;
-
- if (a != 0 && r/a != b || r < a || r < b)
- return 0;
- return r;
+ for (t = Tind0; t < Maxtind; t++) {
+ n = nperindunit(t);
+ print("A %s unit points to %lld data blocks (%llud bytes)\n",
+ tagnames[t], n, n*Blocksize);
+ print(" block points to %llud data blocks\n", nperiblock(t));
+ print(" reli start %llud max %llud\n",
+ tagstartreli(t), maxreli(t));
+ print(" max size %llud*Blocksize = %llud bytes",
+ maxblocks(t),
+ maxblocks(t)*Blocksize);
+ if(maxblocks(t)*Blocksize/(GiB) > 0)
+ print(" = %llud GiB\n",maxblocks(t)*Blocksize/(GiB));
+ else if(maxblocks(t)*Blocksize/(MiB) > 0)
+ print(" = %llud MiB\n",maxblocks(t)*Blocksize/(MiB));
+ else
+ print("\n");
+ }
+ exits(nil);
}
+/*
static uvlong
maxsize1(void)
{
@@ -29,7 +41,7 @@
uvlong max = Ndblock, ind = 1;
for (i = 0; i < Niblock; i++) {
- ind = muluvlongov(ind, Nindperblock); /* power of Nindperblock */
+ ind = muluvlongov(ind, Nindperblock); \/* power of Nindperblock *\/
if (ind == 0)
return 0;
max = adduvlongov(max, ind);
@@ -40,46 +52,6 @@
return muluvlongov(max, Blocksize);
}
-/* could use muluvlongov() here but it does not add any value for us
- raise base to n-th power; n >= 0
- */
-u64
-power( u64 base, int n)
-{
- int i;
- u64 v;
-
- v = 1;
- for(i = 1; i <= n; i++){
- v = v*base;
- }
- return v;
-}
-
-/* Each u64 address in this indirect block links to n Tdata/Tdentry blocks */
-u64
-nperindunit(u16 tag)
-{
- if(tag < Tind0 || tag > Tmaxind+1)
- return 0;
-
- if(tag == Tind0)
- return 1;
- return Nindperblock*power(Blocksize/sizeof(u64), tag-Tind1);
-}
-
-/*
- * compute BUFSIZE*(Ndblock+INDPERBUF+INDPERBUF²+INDPERBUF³+INDPERBUF⁴ .. upto ^Niblock)
- * while watching for overflow; in that case, return 0.
- */
-/* extern double pow(double x, double y); *//* return x ^ y (exponentiation) */
-/* Each u64 address in the indirect block links to n Tdata/Tdentry blocks */
-u64
-nperiblock(u16 tag)
-{
- return nperindunit(tag+1);
-}
-
static uvlong
maxsize(void)
{
@@ -94,28 +66,4 @@
}
return max;
}
-
-void
-main(int, void**)
-{
- int i;
- u64 max, n;
-
- print("Namelen %llud Ndblock %d Niblock %d\n", Namelen, Ndblock, Niblock);
- print("Blocksize %llud Nindperblock %llud\n",
- Blocksize, Nindperblock);
-
- for (i = Tind0; i < Maxtind; i++) {
- n = nperindunit(i);
- print("A %s unit points to %lld blocks (%llud bytes)\n",
- tagnames[i], n, n*Blocksize);
- print(" block points to %llud blocks\n", nperiblock(i));
- }
- print("sizeof(Dentry1) %d Namelen %llud\n",
- sizeof(Dentry1), Namelen);
- max = maxsize();
- print("maximum possible blocks %llud\n", max);
- print(" (%llud*Rawblocksize = %llud bytes = %llud GiB)\n",
- max, max*Rawblocksize, (max*Rawblocksize)/(GiB));
- exits(0);
-}
+*/
\ No newline at end of file
--- a/used.c
+++ b/used.c
@@ -136,7 +136,6 @@
u64 cblkno;
int i;
u8 isdir;
- u16 len;
devread(blkno, buf);
t = (Tag*)buf;