summaryrefslogtreecommitdiffstats
path: root/disk-utils/minix.h
diff options
context:
space:
mode:
authorDavidlohr Bueso2011-06-02 00:32:56 +0200
committerKarel Zak2011-06-02 13:27:18 +0200
commit7bf1425a6302c054dc86e23151072f8c69006fc9 (patch)
tree2ac213b2bede09eeccff233b1198b3229263cc2f /disk-utils/minix.h
parentlibmount: use mnt_table_get_fs_root() in utab code (diff)
downloadkernel-qcow2-util-linux-7bf1425a6302c054dc86e23151072f8c69006fc9.tar.gz
kernel-qcow2-util-linux-7bf1425a6302c054dc86e23151072f8c69006fc9.tar.xz
kernel-qcow2-util-linux-7bf1425a6302c054dc86e23151072f8c69006fc9.zip
minix: add common functionality
Unite common features and code present in mkfs.minix and fsck.minix into a single minix.h header. This eases the reading and modification of both programs. Futhermore: - Replace version2 variable with fs_version (handy when v3 support comes along) - For superblock attributes and inode information, use small inline functions instead of ugly macros. Signed-off-by: Davidlohr Bueso <dave@gnu.org>
Diffstat (limited to 'disk-utils/minix.h')
-rw-r--r--disk-utils/minix.h81
1 files changed, 81 insertions, 0 deletions
diff --git a/disk-utils/minix.h b/disk-utils/minix.h
index 638565ef0..4e670ba00 100644
--- a/disk-utils/minix.h
+++ b/disk-utils/minix.h
@@ -1,3 +1,6 @@
+#ifndef __MINIX_H__
+#define __MINIX_H__
+
#ifdef KERNEL_INCLUDES_ARE_CLEAN
#include <linux/fs.h>
@@ -61,3 +64,81 @@ struct minix_super_block {
#define MINIX2_SUPER_MAGIC2 0x2478 /* minix V2 fs, 30 char names */
#endif /* KERNEL_INCLUDES_ARE_CLEAN */
+
+#define Inode (((struct minix_inode *) inode_buffer)-1)
+#define Inode2 (((struct minix2_inode *) inode_buffer)-1)
+
+#define INODE_SIZE (sizeof(struct minix_inode))
+#define INODE2_SIZE (sizeof(struct minix2_inode))
+
+int fs_version = 1;
+char *super_block_buffer, *inode_buffer = NULL;
+
+static char *inode_map;
+static char *zone_map;
+
+#define BITS_PER_BLOCK (BLOCK_SIZE<<3)
+
+#define UPPER(size,n) ((size+((n)-1))/(n))
+
+/*
+ * wrappers to different superblock attributes
+ */
+#define Super (*(struct minix_super_block *)super_block_buffer)
+
+static inline unsigned long get_ninodes(void)
+{
+ return (unsigned long) Super.s_ninodes;
+}
+
+static inline unsigned long get_nzones(void)
+{
+ return (unsigned long) fs_version == 2 ? Super.s_zones : Super.s_nzones;
+}
+
+static inline unsigned long get_nimaps(void)
+{
+ return (unsigned long)Super.s_imap_blocks;
+}
+
+static inline unsigned long get_nzmaps(void)
+{
+ return (unsigned long)Super.s_zmap_blocks;
+}
+
+static inline unsigned long get_first_zone(void)
+{
+ return (unsigned long)Super.s_firstdatazone;
+}
+
+static inline unsigned long get_zone_size(void)
+{
+ return (unsigned long)Super.s_log_zone_size;
+}
+
+static inline unsigned long get_max_size(void)
+{
+ return (unsigned long)Super.s_max_size;
+}
+
+static unsigned long inode_blocks(void)
+{
+ unsigned long ret;
+
+ if (fs_version == 2)
+ return UPPER(get_ninodes(), MINIX2_INODES_PER_BLOCK);
+ else
+ return UPPER(get_ninodes(), MINIX_INODES_PER_BLOCK);
+}
+
+static inline unsigned long first_zone_data(void)
+{
+ return 2 + get_nimaps() + get_nzmaps() + inode_blocks();
+}
+
+static inline unsigned long get_inode_buffer_size(void)
+{
+ return inode_blocks() * BLOCK_SIZE;
+}
+
+#endif /* __MINIX_H__ */