code: mafs

Download patch

ref: e5f9915142d9e34a015fa4e184ab7331aad412da
parent: e5fae21d7c28103cbd4d5414538f18a448a60766
author: 9ferno <gophone2015@gmail.com>
date: Thu Dec 1 13:52:42 EST 2022

updated document

--- a/dat.h
+++ b/dat.h
@@ -144,7 +144,6 @@
 	u8 unused;	/* for alignment and future use */
 	u16 len;
 	u64 dblkno;	/* block number of the directory entry */
-	// u64 path;	/* same as qid.path */
 };
 #pragma pack off
 
--- a/docs/mafs.ms
+++ b/docs/mafs.ms
@@ -110,7 +110,7 @@
 	Tfree  = 0,	/* free block */
 	Tnone  = 0,
 	Tdata,		/* actual file contents */
-	Tdentry,	/* directory entry, size = Dentrysize */
+	Tdentry,		/* directory entry, size = Dentrysize */
 				/* Tdata & indirect blocks are last, to allow for greater depth */
 	Tind0,		/* contains a list of Tdata block numbers for files
 					and Tdentry block numbers for directories.*/
@@ -120,7 +120,7 @@
 	Tind4,		/* contains a list of Tind1 block numbers */
 				/* gap for more indirect block depth in future.
 					It can be put upto Tind7 without needing any code changes */
-	Maxtind,	/* should be Tind0+Niblock */
+	Maxtind,		/* should be Tind0+Niblock */
 	MAXTAG = Maxtind,
 
 	Tmaxind = Maxtind - 1,
@@ -142,8 +142,7 @@
 .sp
 A directory entry is defined as:
 .nf
-enum {
-	Blocksize	= 512ULL,	/* minimum data unit size */
+enum {	Blocksize	= 512ULL,	/* minimum data unit size */
 
 	Metadataunits	= 2,
 	Metadatablocksize = Metadataunits*Blocksize, /* Keep the original and a copy together */
@@ -150,10 +149,12 @@
 
 	Maxdatablockunits = 2048,
 	Nindperblock= (Blocksize-3*sizeof(u64))/sizeof(u64),/* number of pointers per block */
+	Nu64perblock= (Blocksize/sizeof(u64)),		/* number of u64's in a block */
+	Dpathidx	= (Blocksize/sizeof(u64) -1),		/* index of path in the last data block, last u64 */
 
 	Namelen = 127,	/* maximum length of a file name, calculated manually */
 	Ndblock	= 32,	/* number of direct blocks in a Dentry */
-	Niblock	= 5,	/* maximum depth of indirect blocks, can increase it to 8 without issues */
+	Niblock	= 5,		/* maximum depth of indirect blocks, can increase it to 8 without issues */
 };
 struct Dentryhdr
 {
@@ -165,11 +166,11 @@
 	u64 size;		/* 0 for directories. For files, size in bytes of the content - 16 */
 	u64 pdblkno; 	/* block number of the parent directory entry. Will be 0 for root. - 24 */
 	u64 pqpath; 	/* parent path - 32 */
-	u64 mtime;		/* modified time in nano seconds from epoch - 40 */
-	u64 qpath;		/* unique identifier Qid.path 48 */
+	u64 mtime;	/* modified time in nano seconds from epoch - 40 */
+	u64 qpath;	/* unique identifier Qid.path 48 */
 	u32 version;	/* Qid.version 52 */
-	u32 mode;		/* same bits as defined in /sys/include/libc.h:/Dir\.mode/ - 56 */
-	u8 namelen;		/* store name as a counted string 57 */
+	u32 mode;	/* same bits as defined in /sys/include/libc.h:/Dir\.mode/ - 56 */
+	u8 namelen;	/* store name as a counted string 57 */
 	s8 name[Namelen]; /* Namelen = 127 - 184*/
 };
 struct Datahdr
@@ -178,7 +179,6 @@
 	u8 unused;	/* for alignment and future use */
 	u16 len;
 	u64 dblkno;	/* block number of the directory entry */
-	u64 path;	/* same as path */
 };
 
 enum {
@@ -197,8 +197,8 @@
 		struct
 		{
 			u64 dblocks[Ndblock];	/* direct blocks. */
-									/* List of Tdata block numbers for files and
-										Tdentry block numbers for directories */
+								/* List of Tdata block numbers for files and
+									Tdentry block numbers for directories */
 			u64 iblocks[Niblock];	/* indirect blocks */
 		};
 		Super;
@@ -206,16 +206,16 @@
 		/* when size <= Dentrysize-184-sizeof(Tag), store the data here itself */
 		s8 buf[Ddatasize];
 	};
-	u64 path;	/* same as path */
+	u64 path;	/* same as qid.path */
 };
 struct Indirect
 {
-	u8 tagi;	/* the suffix i to avoid union complaining about ambiguous fields */
+	u8 tagi;		/* the suffix i to avoid union complaining about ambiguous fields */
 	u8 veri;
-	u8 pad[6];	/* unused, to align to a multiple of 8 */
+	u8 pad[6];		/* unused, to align to a multiple of 8 */
 	u64 dblkno;	/* block number of the directory entry */
 	u64 bufa[Nindperblock];
-	u64 path;	/* same as path */
+	u64 path;		/* same as qid.path */
 };
 struct Metadataunit
 {
@@ -252,28 +252,29 @@
 		Blocksize 512 Metadataunits 2 Maxdatablockunits 2048
 		Dentryhdr size 184 Ddatasize 320
 		Dentry size 512 Namelen 127
+		Datahdr size 12 Ddataidssize 20 Maxdatablocksize 1048556
 		Namelen 127 Ndblock 32 Niblock 5
-		Nindperblock 61 Maxdatablocksize 1048548
-		A Tind0 unit points to 1 data blocks (1048548 bytes)
+		Nindperblock 61 Maxdatablocksize 1048556
+		A Tind0 unit points to 1 data blocks (1048556 bytes)
 				block points to 61 data blocks
 				reli start 32	max 92
-				max size 93*Maxdatablocksize = 97514964 bytes	= 92 MiB
-		A Tind1 unit points to 61 data blocks (63961428 bytes)
+				max size 93*Maxdatablocksize = 97515708 bytes	= 92 MiB
+		A Tind1 unit points to 61 data blocks (63961916 bytes)
 				block points to 3721 data blocks
 				reli start 93	max 3813
-				max size 3814*Maxdatablocksize = 3999162072 bytes	= 3 GiB
-		A Tind2 unit points to 3721 data blocks (3901647108 bytes)
+				max size 3814*Maxdatablocksize = 3999192584 bytes	= 3 GiB
+		A Tind2 unit points to 3721 data blocks (3901676876 bytes)
 				block points to 226981 data blocks
 				reli start 3814	max 230794
-				max size 230795*Maxdatablocksize = 241999635660 bytes	= 225 GiB
-		A Tind3 unit points to 226981 data blocks (238000473588 bytes)
+				max size 230795*Maxdatablocksize = 242001482020 bytes	= 225 GiB
+		A Tind3 unit points to 226981 data blocks (238002289436 bytes)
 				block points to 13845841 data blocks
 				reli start 230795	max 14076635
-				max size 14076636*Maxdatablocksize = 14760028524528 bytes	= 13 TiB
-		A Tind4 unit points to 13845841 data blocks (14518028888868 bytes)
+				max size 14076636*Maxdatablocksize = 14760141137616 bytes	= 13 TiB
+		A Tind4 unit points to 13845841 data blocks (14518139655596 bytes)
 				block points to 844596301 data blocks
 				reli start 14076636	max 858672936
-				max size 858672937*Maxdatablocksize = 900359790745476 bytes	= 818 TiB
+				max size 858672937*Maxdatablocksize = 900366660128972 bytes	= 818 TiB
 .fi
 .ne 30
 .sp
@@ -372,8 +373,8 @@
 	box height fieldht invis "version 0"
 	box height fieldht invis "path 66"
 	box height fieldht invis "size 0"
-	box height fieldht invis "pdblkno 10"
-	box height fieldht invis "pqpath 10"
+	box height fieldht invis "pdblkno 20"
+	box height fieldht invis "pqpath 20"
 	box height fieldht invis "mtime 1653302180819962729"
 	box height fieldht invis "mode 20000000777"
 	box height fieldht invis "uid 10006"
@@ -403,7 +404,7 @@
 	box height fieldht invis "version 0"
 	box height fieldht invis "path 67"
 	box height fieldht invis "size 5"
-	box height fieldht invis "pdblkno 13"
+	box height fieldht invis "pdblkno 26"
 	box height fieldht invis "pqpath 66"
 	box height fieldht invis "mtime 1653302180823455071"
 	box height fieldht invis "mode 666"
@@ -424,7 +425,7 @@
 	box height fieldht invis "version 0"
 	box height fieldht invis "path 68"
 	box height fieldht invis "size 5"
-	box height fieldht invis "pdblkno 13"
+	box height fieldht invis "pdblkno 26"
 	box height fieldht invis "pqpath 66"
 	box height fieldht invis "mtime 1653302180823455071"
 	box height fieldht invis "mode 666"
@@ -486,7 +487,7 @@
 	box height fieldht invis "version 0"
 	box height fieldht invis "path 70"
 	box height fieldht invis "size 2056192"
-	box height fieldht invis "pdblkno 16"
+	box height fieldht invis "pdblkno 32"
 	box height fieldht invis "pqpath 69"
 	box height fieldht invis "mtime 1653302180819962729"
 	box height fieldht invis "mode 20000000777"
@@ -495,7 +496,7 @@
 	box height fieldht invis "muid 10006"
 	box height fieldht invis "direct blocks"
 	box height fieldht invis "        0 36"
-	box height fieldht invis "        1 41000"
+	box height fieldht invis "        1 2084"
 	box height fieldht invis "        2 0"
 	box height fieldht invis "."
 	box height fieldht invis "."
@@ -503,7 +504,7 @@
 	box height fieldht invis "       0 0"
 	box height fieldht invis "       1 0"
 	box height fieldht invis "       2 0"
-	"Block 35 contents" at Bound.nw + 0,0.1i ljust
+	"Block 34 contents" at Bound.nw + 0,0.1i ljust
 	"Representation of a 2 MiB file (/dir3/2MB.file)" ljust at Bound.n + 0,0.3i
 }
 move 4*boxwid
@@ -523,7 +524,7 @@
 	down
 	{ Bound: box height 9*bigboxht width 3.3*boxwid }
 	move 0.1i
-	box height fieldht invis "Tdentry 64 104"
+	box height fieldht invis "Tdentry 64 106"
 	box height fieldht invis "name big.file"
 	box height fieldht invis "version 0"
 	box height fieldht invis "path 64"
@@ -581,7 +582,7 @@
 	{ Bound: box height 3*bigboxht width 3.3*boxwid }
 	move 0.1i
 	box height fieldht invis "Tdata 64 22 2048"
-	box height fieldht invis "+06 0123456789"; {"more content" at last box.e + 1i,0 ljust}
+	box height fieldht invis " 0123456789"; {"more content" at last box.e + 1i,0 ljust}
 	box height fieldht invis "."; {"of big.file" at last box.e + 1i,0 ljust}
 	box height fieldht invis "."
 	"Block 65560 contents" at Bound.nw + 0,0.1i ljust
@@ -632,9 +633,9 @@
 l a a .
 Block	Description	Backup Block
 _
-1	/adm/config	last block number -2
-2	/adm/super	last block number -4
-10	/	last block number -6
+2	/adm/config	last block number -2
+4	/adm/super	last block number -4
+20	/	last block number -6
 .TE
 .ta 5n 10n 15n 20n 25n 30n 35n 40n 45n 50n 55n 60n 65n 70n 75n 80n
 .sp
@@ -676,6 +677,7 @@
 {
 	Iobuf* link;	/* least recently used Iobuf in the circular linked list */
 	QLock;		/* controls access to this hash bucket */
+	u64	n;		/* count of Iobuf's in the circular list */
 };
 struct Iobuf
 {
@@ -1078,7 +1080,7 @@
 disk/free	List the free blocks. It reads the contents of /adm/frees.
 disk/used	List the used blocks by traversing all directory entries.
 disk/block	Show the contents of a block.
-disk/unused	Given a list of used blocks, lists the unused blocks.
+disk/unused	Lists the unused blocks when given extents of used blocks.
 disk/updatefrees	Update the contents of /adm/frees.
 .TE
 .sp
@@ -1256,37 +1258,48 @@
 .nf
 	diff <{disk/unused -l <{disk/used tests/test.0/disk} 32}} <{disk/free tests/test.0/disk}
 .fi
-.sp
-Changing the service name without a ream.
-.sp
-.nf
-	disk/block /dev/sdF1/fs 1 | wc
-	Tdata 2
-	size 6001172505088
-	nblocks 11721040049
-	backup config 1 to 11721040048
-	backup super 2 to 11721040046
-	backup root 3 to 117210400464
-	service mafs_ddf_1
-
-	dd -if /dev/sdF1/fs -count 10 -skip 682 -bs 1
-	mafs_ddf_110+0 records in
-	10+0 records out
-
-	dd -if <{echo m_ddf_1; cat /dev/zero} -of /dev/sdF1/fs -count 11 -oseek 682 -bs 1
-	7+0 records in
-	7+0 records out
-
-	disk/block /dev/sdF1/fs 1
-	Tdata 2
-	size 6001172505088
-	nblocks 11721040049
-	backup config 1 to 11721040048
-	backup super 2 to 11721040046
-	backup root 3 to 11721040044
-	service m_ddf_1
-.fi
 \".sp
+\"Changing the service name without a ream.
+\".sp
+\".nf
+\"	disk/block /dev/sdF1/fs 2 | wc
+\"	Tdentry 2 2
+\"	name config
+\"	uid -1
+\"	gid -1
+\"	muid -1
+\"	size 146
+\"	pdblkno 6
+\"	pqpath 6
+\"	mtime 1669916563259999461
+\"	path 2
+\"	version 0
+\"	mode 444
+\"	size 6001172505088
+\"	nblocks 11721040049
+\"	backup config 2 to 11721040047
+\"	backup super 4 to 11721040045
+\"	backup root 20 to 11721040043
+\"	service m_ddf_1
+\"
+\"	dd -if /dev/sdF1/fs -count 10 -skip 682 -bs 1
+\"	mafs_ddf_110+0 records in
+\"	10+0 records out
+\"
+\"	dd -if <{echo m_ddf_1; cat /dev/zero} -of /dev/sdF1/fs -count 11 -oseek 682 -bs 1
+\"	7+0 records in
+\"	7+0 records out
+\"
+\"	disk/block /dev/sdF1/fs 1
+\"	Tdata 2
+\"	size 6001172505088
+\"	nblocks 11721040049
+\"	backup config 1 to 11721040048
+\"	backup super 2 to 11721040046
+\"	backup root 3 to 11721040044
+\"	service m_ddf_1
+\".fi
+\".sp
 \"Changing the magic phrase in the magic block. - the offsets and the block output format has changed.
 \".sp
 \".nf
@@ -1332,6 +1345,7 @@
 tests/regress.rc	All regression tests
 tests/chkextents.rc	Unit tests on extents
 tests/chkreli.rc	Unit tests on relative index lookups
+tests/chknlastdatablocks.rc	Unit tests on the number of blocks in the last Tdata block
 _
 tests/6.offsets	Write file using different offsets to test mafswrite()
 tests/6.sizes	Show the effects of the different parameters