code: mafs

Download patch

ref: 61ab76ca10766edc8728de5cc6e1d0972c99ebc9
parent: 06bc3a358931f0e6182d636f418a8ad15731c29e
author: 9ferno <gophone2015@gmail.com>
date: Mon Jan 2 19:27:07 EST 2023

renamed /adm to /a to avoid overlap with the existing folder

--- a/9p.c
+++ b/9p.c
@@ -349,6 +349,9 @@
 	}else if(req->fid->qid.path == Qpctl){
 		ctlwrite(req);
 		return;
+	}else if(req->fid->qid.path < Qproot){
+		respond(req, errstring[Eaccess]);
+		return;
 	}
 	if((req->fid->qid.type & QTDIR) != 0){
 		respond(req, errstring[Einval]);
@@ -985,7 +988,7 @@
 /*
 	there are 2 ways to shutdown:
 	1. by unmounting and removing the /srv/mfs_service file (can be rm and unmount too)
-	2. by writing halt to /adm/ctl file. unmount() the file system to keep it clean.
+	2. by writing halt to /a/ctl file. unmount() the file system to keep it clean.
 
 	In the first instance, the srv() process is driving the shutdown. It calls fsend().
 		rm /srv/mfs_service file does not wait for fsend() to finish. Hence, there
--- a/dat.h
+++ b/dat.h
@@ -57,9 +57,9 @@
 	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 = 128,	/* aximum length of a file name, calculated anually */
+	Namelen = 128,	/* maximum length of a file name, calculated anually */
 	Ndblock	= 32,	/* number of direct blocks in a Dentry */
-	Niblock	= 5,	/* aximum 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 */
 
 	/* global block numbers. The bkp contents locations are calculated by ream() */
 	Bdmagic	= 0,	/* block number of first block. Bmagic conflicts with bio.h */
@@ -86,25 +86,24 @@
 	/* Qpnone is the Tag.path of free blocks/extents(Tfree),
 		and zero'ed out dentry blocks */
 	Qpnone		= 0,
-	Qpconfig	= Bdconfig,	/* /adm/config block Tag.qpath */
-	Qpsuper		= Bdsuper,	/* /adm/super block Tag.qpath */
-	Qpadm		= Bdadm,	/* /adm */
-	Qpusers		= Bdusers,	/* /adm/users block Tag.qpath */
+	Qpconfig	= Bdconfig,	/* /a/config block Tag.qpath */
+	Qpsuper		= Bdsuper,	/* /a/super block Tag.qpath */
+	Qpa			= Bda,	/* /a */
+	Qpusers		= Bdusers,	/* /a/users block Tag.qpath */
 
-	Qpbkp		= Bdbkp,	/* /adm/bkp block Tag.qpath */
-	Qpusersinuse	= Bdusersinuse,	/* /adm/users/inuse block Tag.qpath */
-	Qpfrees		= Bdfrees,	/* /adm/frees block Tag.qpath */
+	Qpbkp		= Bdbkp,	/* /a/bkp block Tag.qpath */
+	Qpusersinuse	= Bdusersinuse,	/* /a/users/inuse block Tag.qpath */
+	Qpfrees		= Bdfrees,	/* /a/frees block Tag.qpath */
 
-	Qpctl		= Bdctl,	/* /adm/ctl */
-	Qpusersstaging	= Bdusersstaging,/* /adm/users/staging block Tag.qpath */
-	Qproot		= Bdroot,	/* /, so fscreate() can disallow any create's below */
-
 				/* system qpaths */
-	Qpmagic,	/* magic block Tag.qpath */
-	Qpconfig0,	/* /adm/bkp/config.0 block Tag.qpath */
-	Qpsuper0,	/* /adm/bkp/super.0 block Tag.qpath */
-	Qproot0,	/* /adm/bkp/root.0 block Tag.qpath */
+	Qpmagic		= Bdroot+1,	/* magic block Tag.qpath */
+	Qpconfig0,	/* /a/bkp/config.0 block Tag.qpath */
+	Qpsuper0,	/* /a/bkp/super.0 block Tag.qpath */
+	Qproot0,	/* /a/bkp/root.0 block Tag.qpath */
 
+	Qproot	= 32,	/* /, so fscreate() and fswrite() can disallow any create's below */
+	Qpctl,			/* /a/ctl */
+	Qpusersstaging,	/* /a/users/staging block Tag.qpath */
 	Nqidgen	= 64,
 
 	/* check qpath for overflows - TODO, should be 2^64 */
--- a/dentry.c
+++ b/dentry.c
@@ -639,7 +639,7 @@
 	free(buf);
 }
 
-/* clear out /adm/frees data contents after starting up
+/* clear out /a/frees data contents after starting up
 	I cannot use truncatefile() below as it would
 	bfree() the blocks (which are already in the Extents frees)
 	and that would cause an inconsistency/panic */
--- a/docs/mafs.ms
+++ b/docs/mafs.ms
@@ -545,26 +545,26 @@
 =
 Block	Description
 0	magic dir entry and data
-1	/adm/config dir entry
-2	/adm/super dir entry
+1	/a/config dir entry
+2	/a/super dir entry
 _
-3	/adm/ dir entry
-4	/adm/users/ dir entry
-5	/adm/bkp/ dir entry
+3	/a/ dir entry
+4	/a/users/ dir entry
+5	/a/bkp/ dir entry
 _
-6	/adm/users/inuse dir entry
-7	/adm/frees dir entry
-8	/adm/ctl dir entry -- virtual file, empty contents
+6	/a/users/inuse dir entry
+7	/a/frees dir entry
+8	/a/ctl dir entry -- virtual file, empty contents
 _
-9	/adm/users/staging dir entry
+9	/a/users/staging dir entry
 10	/ direntry
 _
 .TE
 .ta 5n 10n 15n 20n 25n 30n 35n 40n 45n 50n 55n 60n 65n 70n 75n 80n
 .sp
-The /adm/ctl file is used to halt or sync the file system. /adm/users is a r/w file that will reload users when written to it. The owner of the /adm/ctl file or any user belonging to the sys group can ream the disk.
+The /a/ctl file is used to halt or sync the file system. /a/users is a r/w file that will reload users when written to it. The owner of the /a/ctl file or any user belonging to the sys group can ream the disk.
 .sp
-There is no /adm/magic directory entry as the block number of the magic block is zero and zero block in a directory entry signifies the end of the directory contents.
+There is no /a/magic directory entry as the block number of the magic block is zero and zero block in a directory entry signifies the end of the directory contents.
 .sp
 .sp
 .ne 4
@@ -580,8 +580,8 @@
 l a a .
 Block	Description	Backup Block
 _
-1	/adm/config	last block number -1
-2	/adm/super	last block number -2
+1	/a/config	last block number -1
+2	/a/super	last block number -2
 10	/	last block number -3
 .TE
 .ta 5n 10n 15n 20n 25n 30n 35n 40n 45n 50n 55n 60n 65n 70n 75n 80n
@@ -595,11 +595,11 @@
 .ne 4
 Users
 .sp
-Users are defined in /adm/users/inuse file. Any changes to it are made through the /adm/users/staging file. All changes are written to the staging file and then inuse file is updated by writing the command users to the /adm/ctl file.
+Users are defined in /a/users/inuse file. Any changes to it are made through the /a/users/staging file. All changes are written to the staging file and then inuse file is updated by writing the command users to the /a/ctl file.
 .sp
-Either all changes to /adm/users/inuse are installed or nothing is installed from the /adm/users/staging file.
+Either all changes to /a/users/inuse are installed or nothing is installed from the /a/users/staging file.
 .sp
-The format of /adm/users/inuse is described in users(6).
+The format of /a/users/inuse is described in users(6).
 .sp
 .sp
 .ft B
@@ -720,7 +720,7 @@
 .sp
 Free blocks are managed using Extents. The list of free blocks is stored to the disk when shutting down. If this state is not written, then the file system needs to be checked and the list of free blocks should be updated.
 .sp
-When shutting down, the Extents are written to free blocks. This information can be accessed from /adm/frees. Also, fsok in the super block is set to 1. Mafs does not start until fsok is 1. When fsok = 0, run the sanity check that the unused blocks and the free blocks in /adm/frees match up. disk/reconcile identifies any missing blocks or blocks that are marked as both used and free.
+When shutting down, the Extents are written to free blocks. This information can be accessed from /a/frees. Also, fsok in the super block is set to 1. Mafs does not start until fsok is 1. When fsok = 0, run the sanity check that the unused blocks and the free blocks in /a/frees match up. disk/reconcile identifies any missing blocks or blocks that are marked as both used and free.
 .sp
 This process of fixing issues and setting fsok to 1 is manual. There is no automatic file system checker as in other file systems. This document aims to empower you with the knowledge to fix your file system issues instead of entrusting your precious data to an arbitrary decision maker such as the file system checker.
 .sp
@@ -1015,7 +1015,7 @@
 { "Extents after" above ljust at After.nw }
 .PE
 .sp
-Kfs stores the list of free blocks in a Tfrees block and the Superblock. Instead we use block management routines, similar to pool.h, to allocate and monitor free blocks. On shutdown(), the block management routines (extents.[ch]) store state into the free blocks. This can be read from /adm/frees. On startup, this is read back by the block management routines. On a crash, the fsck can walk the directory structure to identify the free blocks and recreate /adm/frees.
+Kfs stores the list of free blocks in a Tfrees block and the Superblock. Instead we use block management routines, similar to pool.h, to allocate and monitor free blocks. On shutdown(), the block management routines (extents.[ch]) store state into the free blocks. This can be read from /a/frees. On startup, this is read back by the block management routines. On a crash, the fsck can walk the directory structure to identify the free blocks and recreate /a/frees.
 .sp
 .sp
 .ne 12
@@ -1031,11 +1031,11 @@
 _
 disk/mafs	Start mafs on a disk.
 disk/fsck	Check file system on an improper shutdown.
-disk/free	List the free blocks. It reads the contents of /adm/frees.
+disk/free	List the free blocks. It reads the contents of /a/frees.
 disk/used	List the used blocks by traversing all directory entries.
 disk/block	Show the contents of a block.
 disk/unused	Lists the unused blocks when given extents of used blocks.
-disk/updatefrees	Update the contents of /adm/frees.
+disk/updatefrees	Update the contents of /a/frees.
 .TE
 .sp
 .TS
@@ -1046,8 +1046,8 @@
 _
 9p.c	9p transactions	2
 blk.c	routines to show blocks.
-console.c	obsolete. /adm/ctl is the console.
-ctl.c	/adm/ctl operations.
+console.c	obsolete. /a/ctl is the console.
+ctl.c	/a/ctl operations.
 dentry.c	encode/decode the file system abstraction into block operations.	3
 extents.[ch]	routines to manage the free blocks.	6
 iobuf.c	routines on Iobuf's. The bkp() routines operate on Iobuf's.	5
@@ -1134,7 +1134,7 @@
 .sp
 Sync Mafs. This command does not return until all the writes are written to the disk. So, could take a long time if you have a long writer queue.
 .sp
-	echo sync >> /n/mafs_myservice/adm/ctl
+	echo sync >> /n/mafs_myservice/a/ctl
 .sp
 .sp
 .ne 4
@@ -1143,7 +1143,7 @@
 .in 3n
 1. Unmount and remove the /srv/mfs_service file (can be rm and unmount too).
 .br
-2. Write halt into the /adm/ctl file. Unmount() the mafs file system to keep it clean.
+2. Write halt into the /a/ctl file. Unmount() the mafs file system to keep it clean.
 .in 0
 .sp
 In the first instance, the srv() process is driving the shutdown. It calls fsend(). rm /srv/mfs_service file does not wait for fsend() to finish. Hence, there is no way to ensure that memory contents have been flushed to the disk. If the system is shutdown or restarted immediately, there is a very high possibility that the filesystem will be in an inconsistent state.
@@ -1154,7 +1154,7 @@
 .sp
 The below command does not return until all the writes are written to the disk. So, could take a long time if you have a long writer queue. This is the proper way to shutdown the mafs file system.
 .sp
-	echo halt >> /n/mafs_myservice/adm/ctl
+	echo halt >> /n/mafs_myservice/a/ctl
 .sp
 Interpret the contents of a block based on the tag and write out a single formatted block based on the tag
 .sp
@@ -1164,7 +1164,7 @@
 .sp
 	disk/used  tests/test.0/disk
 .sp
-From the contents of /adm/frees show the list of free blocks. disk/reconcile uses the output of this to reconcile the list of used blocks with the list of free blocks.
+From the contents of /a/frees show the list of free blocks. disk/reconcile uses the output of this to reconcile the list of used blocks with the list of free blocks.
 .sp
 	disk/free  tests/test.0/disk
 .sp
@@ -1190,7 +1190,7 @@
 .fi
 .sp
 .ne 5
-Build the list of free blocks. This should match the contents of /adm/frees.
+Build the list of free blocks. This should match the contents of /a/frees.
 .sp
 .nf
 	disk/unused 11721040049 <{disk/used /dev/sdF1/fs} # 11721040049 = total number of disk blocks
@@ -1198,7 +1198,7 @@
 .fi
 .sp
 .ne 5
-Change the contents of /adm/frees.
+Change the contents of /a/frees.
 .sp
 .nf
 	disk/updatefrees tests/test.0/disk <{disk/unused 32 <{disk/used tests/test.0/disk}}
@@ -1432,7 +1432,7 @@
 		122.13 MB/s
 		122.27 MB/s
 		122.28 MB/s
-	echo halt >> /n/mafs_ramfs_file/adm/ctl; lc /srv
+	echo halt >> /n/mafs_ramfs_file/a/ctl; lc /srv
 	unmount /n/mafs_ramfs_file
 
 	dd -if /dev/zero -of /n/ramfs/file -count 700 -bs 1m
@@ -1470,7 +1470,7 @@
 		57.94 MB/s
 		55.27 MB/s
 		46.67 MB/s
-	echo halt >> /n/mafs_ramfs_file/adm/ctl; lc /srv
+	echo halt >> /n/mafs_ramfs_file/a/ctl; lc /srv
 .fi
 .sp
 .sp
--- a/sub.c
+++ b/sub.c
@@ -230,7 +230,7 @@
 					"10001:upas:upas:\n"	/* what is this for? */
 					"10006:%s:%s:\n", user, user, user);
 
-	/* cannot show this in /adm though as the block number is 0 */
+	/* cannot show this in /a though as the block number is 0 */
 	b = getmeta(Bdmagic, Bwritable, Bfreshalloc);
 	settag(b, Tdentry, Qpmagic);
 	d = b->d;
@@ -244,24 +244,24 @@
 	d->qpath = Qpmagic;
 	d->version = 0;
 	d->mtime = nsec();
-	d->pdblkno = Bdadm;
-	d->pqpath = Qpadm;
+	d->pdblkno = Bda;
+	d->pqpath = Qpa;
 	n = snprint((s8*)d->buf, Ddatasize, "%s%llud\n",
 			magic, Blocksize);
 	d->size = n;
 	putbuf(b, 1);
 
-	b = getmeta(Bdadm, Bwritable, Bfreshalloc);
-	settag(b, Tdentry, Qpadm);
+	b = getmeta(Bda, Bwritable, Bfreshalloc);
+	settag(b, Tdentry, Qpa);
 	d = b->d;
 	d->namelen = 3;
-	strncpy(d->name, "adm", 4);
+	strncpy(d->name, "a", 4);
 	d->uid = d->muid = d->gid = -1;
 	d->mode = DMDIR |
 		((DMREAD|DMWRITE|DMEXEC) << 6) |
 		((DMREAD|DMWRITE|DMEXEC) << 3) |
 		((DMREAD|DMWRITE|DMEXEC) << 0);
-	d->qpath = Qpadm;
+	d->qpath = Qpa;
 	d->version = 0;
 	d->mtime = nsec();
 	d->pdblkno = Bdroot;
@@ -288,8 +288,8 @@
 	d->version = 0;
 	d->mtime = nsec();
 	d->size = strlen(users)+1;
-	d->pdblkno = Bdadm;
-	d->pqpath = Qpadm;
+	d->pdblkno = Bda;
+	d->pqpath = Qpa;
 	d->dblocks[0] = bdconfig0;
 	d->dblocks[1] = bdsuper0;
 	d->dblocks[2] = bdroot0;
@@ -309,8 +309,8 @@
 	d->version = 0;
 	d->mtime = nsec();
 	d->size = strlen(users)+1;
-	d->pdblkno = Bdadm;
-	d->pqpath = Qpadm;
+	d->pdblkno = Bda;
+	d->pqpath = Qpa;
 	d->dblocks[0] = Bdusersinuse;
 	d->dblocks[1] = Bdusersstaging;
 	putbuf(b, 1);
@@ -348,7 +348,7 @@
 	d->qpath = Qproot;
 	d->version = 0;
 	d->mtime = nsec();
-	d->dblocks[0] = Bdadm;
+	d->dblocks[0] = Bda;
 	putbuf(b, 1);
 
 	b = getmeta(Bdconfig, Bwritable, Bfreshalloc);
@@ -366,13 +366,13 @@
 	d->mtime = nsec();
 	memset(cbuf, 0, Ddatasize);
 	d->size = configstr(cbuf, Ddatasize);
-	d->pdblkno = Bdadm;
-	d->pqpath = Qpadm;
+	d->pdblkno = Bda;
+	d->pqpath = Qpa;
 	strncpy((s8*)d->buf, cbuf, d->size);
 	putbuf(b, 1);
 
-	reamfile(Bdctl, Qpctl, "ctl", 0, Bdadm, Qpadm);
-	reamfile(Bdfrees, Qpfrees, "frees", 0, Bdadm, Qpadm);
+	reamfile(Bdctl, Qpctl, "ctl", 0, Bda, Qpa);
+	reamfile(Bdfrees, Qpfrees, "frees", 0, Bda, Qpa);
 
 	reamfile(Bdusersstaging, Qpusersstaging, "staging",
 			 0, Bdusers, Qpusers);
@@ -400,8 +400,8 @@
 	s->version = 0;
 	s->mtime = nsec();
 	s->size = sizeof(Super);
-	s->pdblkno = Bdadm;
-	s->pqpath = Qpadm;
+	s->pdblkno = Bda;
+	s->pqpath = Qpa;
 	s->qidgen = Nqidgen;
 	s->fsok = 1;
 
--- a/unused.c
+++ b/unused.c
@@ -6,7 +6,7 @@
 
 /*
 	indentify block numbers that are not used.
-	These blocks can be used to update /adm/frees as they are free to use.
+	These blocks can be used to update /a/frees as they are free to use.
 
 	watch -e '6\.unused' 'date; ./6.unused -D 7 <{seq 1 1 3; seq 5 1 6} '
 
--- a/updatefrees.c
+++ b/updatefrees.c
@@ -5,7 +5,7 @@
 #include "extents.h"
 
 /*
-	update /adm/frees
+	update /a/frees
 
 	disk/unused <{disk/used tests/test.0/disk} 32 | tr -d '	' > /mnt/term/tmp/unused.blocks
 	cat /mnt/term/tmp/unused.blocks
--- a/used.c
+++ b/used.c
@@ -160,7 +160,7 @@
 		// print("%llud\n", blkno);
 		add(&useds, blkno, 1);
 	}
-	/* do not list the data blocks used by /adm/frees
+	/* do not list the data blocks used by /a/frees
 		as they are considered to be free blocks */
 	if(blkno == Bdfrees)
 		return;
@@ -216,7 +216,7 @@
 		// print("%llud\n", blkno);
 		add(&useds, blkno, 1);
 	}
-	/* do not list the data blocks used by /adm/frees
+	/* do not list the data blocks used by /a/frees
 		as they are considered to be free blocks */
 	if(blkno == Bdfrees)
 		return;
--- a/user.c
+++ b/user.c
@@ -430,17 +430,17 @@
 
 	readfile(Bdusersinuse, Qpusersinuse, buf, usize, 0);
 	if((rv=parseusers(&us, buf, usize)) != 0)
-		panic("could not parse /adm/users/inuse rv %d\n", rv);
+		panic("could not parse /a/users/inuse rv %d\n", rv);
 	free(buf);
 	lruuser = us;
 }
 
 /*
-	read from /adm/user/staging
+	read from /a/user/staging
 	check that the contents are valid
 		check that -1 is the first entry TODO
 		check that 0 is the next entry TODO
-	write the contents to /adm/users/inuse
+	write the contents to /a/users/inuse
 	lruuser points to these new contents
  */
 void
@@ -458,7 +458,7 @@
 
 	readfile(Bdusersstaging, Qpusersstaging, buf, usize, 0);
 	if(parseusers(&us, buf, usize) != 0)
-		panic("could not parse /adm/users/staging\n");
+		panic("could not parse /a/users/staging\n");
 
 	wlock(&userslock);
 	old = lruuser;