summaryrefslogtreecommitdiff
path: root/kernel/fs.h
diff options
context:
space:
mode:
authorRobert Morris <[email protected]>2019-06-11 09:57:14 -0400
committerRobert Morris <[email protected]>2019-06-11 09:57:14 -0400
commit5753553213df8f9de851adb68377db43faecb91f (patch)
tree3b629ff54897fca414146677532cb459a2ed11ba /kernel/fs.h
parent91ba81110acd3163f7de3580b677eece0c57f5e7 (diff)
downloadxv6-labs-5753553213df8f9de851adb68377db43faecb91f.tar.gz
xv6-labs-5753553213df8f9de851adb68377db43faecb91f.tar.bz2
xv6-labs-5753553213df8f9de851adb68377db43faecb91f.zip
separate source into kernel/ user/ mkfs/
Diffstat (limited to 'kernel/fs.h')
-rw-r--r--kernel/fs.h60
1 files changed, 60 insertions, 0 deletions
diff --git a/kernel/fs.h b/kernel/fs.h
new file mode 100644
index 0000000..bc0805f
--- /dev/null
+++ b/kernel/fs.h
@@ -0,0 +1,60 @@
+// On-disk file system format.
+// Both the kernel and user programs use this header file.
+
+
+#define ROOTINO 1 // root i-number
+#define BSIZE 1024 // block size
+
+// Disk layout:
+// [ boot block | super block | log | inode blocks |
+// free bit map | data blocks]
+//
+// mkfs computes the super block and builds an initial file system. The
+// super block describes the disk layout:
+struct superblock {
+ uint magic; // Must be FSMAGIC
+ uint size; // Size of file system image (blocks)
+ uint nblocks; // Number of data blocks
+ uint ninodes; // Number of inodes.
+ uint nlog; // Number of log blocks
+ uint logstart; // Block number of first log block
+ uint inodestart; // Block number of first inode block
+ uint bmapstart; // Block number of first free map block
+};
+
+#define FSMAGIC 0x10203040
+
+#define NDIRECT 12
+#define NINDIRECT (BSIZE / sizeof(uint))
+#define MAXFILE (NDIRECT + NINDIRECT)
+
+// On-disk inode structure
+struct dinode {
+ short type; // File type
+ short major; // Major device number (T_DEV only)
+ short minor; // Minor device number (T_DEV only)
+ short nlink; // Number of links to inode in file system
+ uint size; // Size of file (bytes)
+ uint addrs[NDIRECT+1]; // Data block addresses
+};
+
+// Inodes per block.
+#define IPB (BSIZE / sizeof(struct dinode))
+
+// Block containing inode i
+#define IBLOCK(i, sb) ((i) / IPB + sb.inodestart)
+
+// Bitmap bits per block
+#define BPB (BSIZE*8)
+
+// Block of free map containing bit for block b
+#define BBLOCK(b, sb) ((b)/BPB + sb.bmapstart)
+
+// Directory is a file containing a sequence of dirent structures.
+#define DIRSIZ 14
+
+struct dirent {
+ ushort inum;
+ char name[DIRSIZ];
+};
+