@@ -3,4 +3,4 @@
# Makefile for persistent kernel filesystem
#
-obj-$(CONFIG_PKERNFS_FS) += pkernfs.o inode.o dir.o
+obj-$(CONFIG_PKERNFS_FS) += pkernfs.o inode.o allocator.o dir.o
new file mode 100644
@@ -0,0 +1,27 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#include "pkernfs.h"
+
+/**
+ * For allocating blocks from the pkernfs filesystem.
+ * The first two blocks are special:
+ * - the first block is persitent filesystme metadata and
+ * a bitmap of allocated blocks
+ * - the second block is an array of persisted inodes; the
+ * inode store.
+ */
+
+void *pkernfs_allocations_bitmap(struct super_block *sb)
+{
+ /* Allocations is 2nd half of first block */
+ return pkernfs_mem + (1 << 20);
+}
+
+void pkernfs_zero_allocations(struct super_block *sb)
+{
+ memset(pkernfs_allocations_bitmap(sb), 0, (1 << 20));
+ /* First page is persisted super block and allocator bitmap */
+ set_bit(0, pkernfs_allocations_bitmap(sb));
+ /* Second page is inode store */
+ set_bit(1, pkernfs_allocations_bitmap(sb));
+}
@@ -25,6 +25,7 @@ static int pkernfs_fill_super(struct super_block *sb, struct fs_context *fc)
} else {
pr_info("pkernfs: Clean super block; initialising\n");
pkernfs_initialise_inode_store(sb);
+ pkernfs_zero_allocations(sb);
psb->magic_number = PKERNFS_MAGIC_NUMBER;
pkernfs_get_persisted_inode(sb, 1)->flags = PKERNFS_INODE_FLAG_DIR;
strscpy(pkernfs_get_persisted_inode(sb, 1)->filename, ".", PKERNFS_FILENAME_LEN);
@@ -34,6 +34,7 @@ struct pkernfs_inode {
};
void pkernfs_initialise_inode_store(struct super_block *sb);
+void pkernfs_zero_allocations(struct super_block *sb);
struct inode *pkernfs_inode_get(struct super_block *sb, unsigned long ino);
struct pkernfs_inode *pkernfs_get_persisted_inode(struct super_block *sb, int ino);