wm: teppich

Download patch

ref: 8b8814e4df3e370608da903e6cdb96ba33aacdad
parent: 7c9bbdbfffed3dd83a2e8b494c841af0956edf46
author: mkf <mkf@cloud9p.org>
date: Tue Nov 28 08:24:07 EST 2023

fs/rootfs.c: import

--- /dev/null
+++ b/fs/rootfs.c
@@ -1,0 +1,78 @@
+#include <u.h>
+#include <libc.h>
+
+#include <mem.h>
+
+#include <vfs.h>
+#include <user.h>
+#include "fstab.h"
+
+static fs_t *rootfs;
+
+fs_t*
+rootfs_init(void)
+{
+	char* path;
+	ll_t *ulist, *flist, *t;
+	file_t *f, *root;
+
+	if(rootfs->state == READY)
+		return rootfs;
+		
+	path = "/";
+	rootfs = (fs_t*)malloc(sizeof(fs_t));
+	
+	ulist = malloc(sizeof(ll_t*));
+	flist = malloc(sizeof(ll_t*));
+
+	lladd(ulist, &uroot);
+	
+	rootfs->fid = 1;
+	rootfs->state = READY;
+	/* cmdfs.type = INTERFACE; */
+	rootfs->users = ulist;
+	
+	root->fid = 0;
+	root->size = 0;
+
+	root->owner = adam.id;
+	root->perms = 0444; /* u=r, o=r */
+	
+	root->path = "/";
+	root->name = "";
+
+	flist->val = root;
+	flist->next = nil;
+	t = flist;
+	
+	/* 
+		fstab[0] is /
+		TODO: call create() instead 
+	*/
+	
+	for(int i = 1 ; i < sizeof(fstab) / sizeof(mnt_t) ; i++)
+	{	
+		f = (file_t*)malloc(sizeof(file_t));
+		
+		f->fid = rootfs->fid++;
+		f->size = 0;
+		
+		f->owner = adam.id;
+		f->perms = 0444;
+
+		f->name = fstab[i].name;
+
+		f->path = malloc(sizeof(char));
+		strncpy(f->path, path, strlen(path));
+		
+		/* f.buf = */
+		lladd(t, f);
+		
+		t = (ll_t*)t->next;
+	}
+
+	rootfs->files = flist;
+	
+	return rootfs;
+}
+