[Ocfs-tools-commits] khackel commits r18 - in trunk/format: . inc

svn-commits at oss.oracle.com svn-commits at oss.oracle.com
Fri Apr 23 20:04:56 CDT 2004


Author: khackel
Date: 2004-04-23 19:04:54 -0500 (Fri, 23 Apr 2004)
New Revision: 18

Added:
   trunk/format/inc/jfs_compat.h
   trunk/format/inc/kernel-list.h
   trunk/format/journal.c
   trunk/format/system.c
Modified:
   trunk/format/Makefile
   trunk/format/format.c
   trunk/format/inc/format.h
Log:
big change to get mkfs.ocfs to do full filesystem formatting, 
including creation of all the system files and the root directory.
this involves some kernel changes in ocfs2, but none so far in v1.



Modified: trunk/format/Makefile
===================================================================
--- trunk/format/Makefile	2004-04-22 22:15:49 UTC (rev 17)
+++ trunk/format/Makefile	2004-04-24 00:04:54 UTC (rev 18)
@@ -55,7 +55,7 @@
 
 vpath ocfsheartbeat.c $(TOPDIR)/libocfs/Common
 
-mkfs.ocfs: format.o frmtport.o
+mkfs.ocfs: format.o frmtport.o journal.o system.o
 	$(LINK) -L$(TOPDIR)/libocfs -locfs
 
 mounted.ocfs: mounted.o frmtport.o

Modified: trunk/format/format.c
===================================================================
--- trunk/format/format.c	2004-04-22 22:15:49 UTC (rev 17)
+++ trunk/format/format.c	2004-04-24 00:04:54 UTC (rev 18)
@@ -28,6 +28,10 @@
 #include <signal.h>
 #include <libgen.h>
 
+ocfs_alloc_bm global_bm;
+char *bm_buf = NULL;
+int bm_size = 0;
+
 bool in_data_blocks = false;
 bool format_intr = false;
 
@@ -289,6 +293,32 @@
 	goto bail;
     fsync(file);
 
+    /* Create the root directory */
+    PRINT_VERBOSE("Writing root directory and system files...");
+    fflush(stdout);
+    if (!ocfs_create_root_directory (file, volhdr))
+        goto bail;
+    fsync(file);
+    PRINT_PROGRESS();
+    PRINT_VERBOSE("\rWrote root directory and system files       \n");
+
+    /* Write the changes to the global bitmap */    
+    PRINT_VERBOSE("Updating global bitmap...");
+    fflush(stdout);
+    if (!SetSeek(file, volhdr->bitmap_off))
+	goto bail;
+    if (!Write(file, bm_size, bm_buf))
+        goto bail;
+    fsync(file);
+    PRINT_PROGRESS();
+    PRINT_VERBOSE("\rUpdated global bitmap                       \n");
+
+    /* Write corresponding change to bitmap lock (for statfs) */
+    if (!ocfs_update_bm_lock_stats(file))
+        goto bail;
+    fsync(file);
+	
+
     /* Write volume header */
     PRINT_VERBOSE("Writing volume header...");
     fflush(stdout);
@@ -303,6 +333,7 @@
     fflush(stdout);
 
   bail:
+    safefree(bm_buf);
     safefree(volhdr);
     safeclose(file);
     unbind_raw(rawminor);
@@ -868,7 +899,8 @@
 
     volhdr->num_clusters = num_blocks;
 
-    return 1;
+    // don't bother reading from disk
+    return ocfs_init_global_alloc_bm ((__u32)num_blocks, file, NULL);
 }				/* InitVolumeDiskHeader */
 
 
@@ -999,3 +1031,4 @@
 	}
 } /* HandleSignal */
 
+

Modified: trunk/format/inc/format.h
===================================================================
--- trunk/format/inc/format.h	2004-04-22 22:15:49 UTC (rev 17)
+++ trunk/format/inc/format.h	2004-04-24 00:04:54 UTC (rev 18)
@@ -49,6 +49,54 @@
 
 #define  OCFS_HBT_WAIT			10
 
+// TODO: need to add version 2 stuff to headers
+// BEGIN VERSION 2
+enum {
+	OCFS_VOL_BM_SYSFILE = OCFS_CLEANUP_LOG_SYSFILE+1,
+	OCFS_ORPHAN_DIR_SYSFILE,
+	OCFS_JOURNAL_SYSFILE
+};
+#define OCFS_VOL_BITMAP_FILE         (OCFS_VOL_BM_SYSFILE         * OCFS_MAXIMUM_NODES)
+#define OCFS_ORPHAN_DIR              (OCFS_ORPHAN_DIR_SYSFILE     * OCFS_MAXIMUM_NODES)
+#define OCFS_JOURNAL_FILE            (OCFS_JOURNAL_SYSFILE        * OCFS_MAXIMUM_NODES)
+
+#define OCFS_JOURNAL_DEFAULT_SIZE       (8 * ONE_MEGA_BYTE)
+#define  OCFS_ORPHAN_DIR_FILENAME          "OrphanDir"
+#define  OCFS_JOURNAL_FILENAME         	   "JournalFile"
+#define  OCFS_LOCAL_ALLOC_SIGNATURE          "LCLBMP"
+#define  DIR_NODE_FLAG_ORPHAN         0x02
+
+#define OCFS_JOURNAL_CURRENT_VERSION 1
+
+typedef struct _ocfs_local_alloc
+{
+	ocfs_disk_lock disk_lock;
+	__u8 signature[8];        /* "LCLBMP"                           */
+	__u32 alloc_size;         /* num bits taken from main bitmap    */
+	__u32 num_used;           /* num bits used (is this needed?)    */
+	__u32 bitmap_start;       /* starting bit offset in main bitmap */
+	__u32 node_num;           /* which node owns me                 */
+	__u64 this_sector;        /* disk offset of this structure      */
+	__u8 padding[176];        /* pad out to 256                     */
+	__u8 bitmap[256];
+}
+ocfs_local_alloc;
+
+typedef struct _ocfs_disk_node_config_info2              // CLASS
+{
+	ocfs_disk_lock disk_lock;                       // DISKLOCK
+	__u8 node_name[MAX_NODE_NAME_LENGTH+1];         // CHAR[MAX_NODE_NAME_LENGTH+1]
+	ocfs_guid guid;                                 // GUID
+	ocfs_ipc_config_info ipc_config;                // IPCONFIG
+	__u8 journal_version;
+}
+ocfs_disk_node_config_info2;                             // END CLASS
+
+// END VERSION 2
+
+
+
+
 #define  OCFS_BUFFER_ALIGN(buf, secsz)  ((__u64)buf +                 \
                                          (((__u64)buf % secsz) ?      \
                                           (secsz - ((__u64)buf % secsz)) : 0))
@@ -147,4 +195,16 @@
 void ShowDiskHdrVals(ocfs_vol_disk_hdr * voldiskhdr);
 
 void HandleSignal(int sig);
+
+/* journal.c */
+int ocfs_replacement_journal_create(int file, __u64 journal_off);
+
+/* system.c */
+int ocfs_init_sysfile (int file, ocfs_vol_disk_hdr *volhdr, __u32 file_id, ocfs_file_entry *fe, __u64 data);
+int ocfs_create_root_directory (int file, ocfs_vol_disk_hdr *volhdr);
+__u32 ocfs_alloc_from_global_bitmap (__u64 file_size, ocfs_vol_disk_hdr *volhdr);
+int ocfs_update_bm_lock_stats(int file);
+int ocfs_init_global_alloc_bm (__u32 num_bits, int file, ocfs_vol_disk_hdr *volhdr);
+void ocfs_init_dirnode(ocfs_dir_node *dir, __u64 disk_off, __u32 bit_off);
+
 #endif /* _FORMAT_H_ */

Added: trunk/format/inc/jfs_compat.h
===================================================================
--- trunk/format/inc/jfs_compat.h	2004-04-22 22:15:49 UTC (rev 17)
+++ trunk/format/inc/jfs_compat.h	2004-04-24 00:04:54 UTC (rev 18)
@@ -0,0 +1,69 @@
+
+#ifndef _JFS_COMPAT_H
+#define _JFS_COMPAT_H
+
+#include "kernel-list.h"
+#include <errno.h>
+#ifdef HAVE_NETINET_IN_H
+#include <netinet/in.h>
+#endif
+
+// libocfs.h has these
+//#define printk printf
+//#define KERN_ERR ""
+#define KERN_DEBUG ""
+#define KERN_EMERG ""
+
+#define READ 0
+#define WRITE 1
+
+#define cpu_to_be32(n) htonl(n)
+#define be32_to_cpu(n) ntohl(n)
+
+typedef int tid_t;
+typedef struct journal_s journal_t;
+
+struct buffer_head;
+struct inode;
+
+struct journal_s
+{
+	unsigned long		j_flags;
+	int			j_errno;
+	struct buffer_head *	j_sb_buffer;
+	struct journal_superblock_s *j_superblock;
+	int			j_format_version;
+	unsigned long		j_head;
+	unsigned long		j_tail;
+	unsigned long		j_free;
+	unsigned long		j_first, j_last;
+	kdev_t			j_dev;
+	kdev_t			j_fs_dev;
+	int			j_blocksize;
+	unsigned int		j_blk_offset;
+	unsigned int		j_maxlen;
+	struct inode *		j_inode;
+	tid_t			j_tail_sequence;
+	tid_t			j_transaction_sequence;
+	__u8			j_uuid[16];
+	struct jbd_revoke_table_s *j_revoke;
+};
+
+#define J_ASSERT(assert)						\
+	do { if (!(assert)) {						\
+		printf ("Assertion failure in %s() at %s line %d: "	\
+			"\"%s\"\n",					\
+			__FUNCTION__, __FILE__, __LINE__, # assert);	\
+		fatal_error(e2fsck_global_ctx, 0);			\
+	} } while (0)
+
+#define is_journal_abort(x) 0
+
+#define BUFFER_TRACE(bh, info)	do {} while (0)
+
+/* Need this so we can compile with configure --enable-gcc-wall */
+#ifdef NO_INLINE_FUNCS
+#define inline
+#endif
+
+#endif /* _JFS_COMPAT_H */

Added: trunk/format/inc/kernel-list.h
===================================================================
--- trunk/format/inc/kernel-list.h	2004-04-22 22:15:49 UTC (rev 17)
+++ trunk/format/inc/kernel-list.h	2004-04-24 00:04:54 UTC (rev 18)
@@ -0,0 +1,112 @@
+#ifndef _LINUX_LIST_H
+#define _LINUX_LIST_H
+
+/*
+ * Simple doubly linked list implementation.
+ *
+ * Some of the internal functions ("__xxx") are useful when
+ * manipulating whole lists rather than single entries, as
+ * sometimes we already know the next/prev entries and we can
+ * generate better code by using them directly rather than
+ * using the generic single-entry routines.
+ */
+
+struct list_head {
+	struct list_head *next, *prev;
+};
+
+#define LIST_HEAD_INIT(name) { &(name), &(name) }
+
+#define LIST_HEAD(name) \
+	struct list_head name = { &name, &name }
+
+#define INIT_LIST_HEAD(ptr) do { \
+	(ptr)->next = (ptr); (ptr)->prev = (ptr); \
+} while (0)
+
+#if (!defined(__GNUC__) && !defined(__WATCOMC__))
+#define __inline__
+#endif
+
+/*
+ * Insert a new entry between two known consecutive entries. 
+ *
+ * This is only for internal list manipulation where we know
+ * the prev/next entries already!
+ */
+static __inline__ void __list_add(struct list_head * new,
+	struct list_head * prev,
+	struct list_head * next)
+{
+	next->prev = new;
+	new->next = next;
+	new->prev = prev;
+	prev->next = new;
+}
+
+/*
+ * Insert a new entry after the specified head..
+ */
+static __inline__ void list_add(struct list_head *new, struct list_head *head)
+{
+	__list_add(new, head, head->next);
+}
+
+/*
+ * Insert a new entry at the tail
+ */
+static __inline__ void list_add_tail(struct list_head *new, struct list_head *head)
+{
+	__list_add(new, head->prev, head);
+}
+
+/*
+ * Delete a list entry by making the prev/next entries
+ * point to each other.
+ *
+ * This is only for internal list manipulation where we know
+ * the prev/next entries already!
+ */
+static __inline__ void __list_del(struct list_head * prev,
+				  struct list_head * next)
+{
+	next->prev = prev;
+	prev->next = next;
+}
+
+static __inline__ void list_del(struct list_head *entry)
+{
+	__list_del(entry->prev, entry->next);
+}
+
+static __inline__ int list_empty(struct list_head *head)
+{
+	return head->next == head;
+}
+
+/*
+ * Splice in "list" into "head"
+ */
+static __inline__ void list_splice(struct list_head *list, struct list_head *head)
+{
+	struct list_head *first = list->next;
+
+	if (first != list) {
+		struct list_head *last = list->prev;
+		struct list_head *at = head->next;
+
+		first->prev = head;
+		head->next = first;
+
+		last->next = at;
+		at->prev = last;
+	}
+}
+
+#define list_entry(ptr, type, member) \
+	((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))
+
+#define list_for_each(pos, head) \
+        for (pos = (head)->next; pos != (head); pos = pos->next)
+
+#endif

Added: trunk/format/journal.c
===================================================================
--- trunk/format/journal.c	2004-04-22 22:15:49 UTC (rev 17)
+++ trunk/format/journal.c	2004-04-24 00:04:54 UTC (rev 18)
@@ -0,0 +1,39 @@
+#include <format.h>
+#include <signal.h>
+#include <libgen.h>
+
+#define CONFIG_JBD 1
+
+#include <linux/jbd.h>
+#include <netinet/in.h>
+
+int ocfs_replacement_journal_create(int file, __u64 journal_off)
+{
+	int status = 0;
+	journal_superblock_t *sb;
+
+	/* zero out all 8mb and stamp this little sb header on it */
+	sb = (journal_superblock_t *) MemAlloc(OCFS_JOURNAL_DEFAULT_SIZE);
+	if (sb == NULL)
+		return 0;
+	
+	memset(sb, 0, OCFS_JOURNAL_DEFAULT_SIZE);
+
+	sb->s_header.h_magic	 = htonl(JFS_MAGIC_NUMBER);
+	sb->s_header.h_blocktype = htonl(JFS_SUPERBLOCK_V2);
+	sb->s_blocksize	= htonl(512);
+	sb->s_maxlen	= htonl(OCFS_JOURNAL_DEFAULT_SIZE / 512);
+	sb->s_first	= htonl(1);
+	sb->s_start     = htonl(1);
+	sb->s_sequence  = htonl(1);
+	sb->s_errno     = htonl(0);
+
+	if (SetSeek(file, journal_off)) {
+                if (Write(file, OCFS_JOURNAL_DEFAULT_SIZE, (void *) sb)) {
+			status = 1;
+			fsync(file);
+		}
+	}
+	safefree(sb);
+	return status;
+}

Added: trunk/format/system.c
===================================================================
--- trunk/format/system.c	2004-04-22 22:15:49 UTC (rev 17)
+++ trunk/format/system.c	2004-04-24 00:04:54 UTC (rev 18)
@@ -0,0 +1,280 @@
+#include <format.h>
+#include <signal.h>
+#include <libgen.h>
+
+extern ocfs_alloc_bm global_bm;
+extern char *bm_buf;
+extern int bm_size;
+extern int major_version;
+extern int minor_version;
+
+
+int ocfs_init_global_alloc_bm (__u32 num_bits, int file, ocfs_vol_disk_hdr *volhdr)
+{
+	int ret = 0;
+
+	bm_size = (__u32) OCFS_SECTOR_ALIGN (num_bits / 8);
+	bm_buf = MemAlloc(bm_size);
+	if (bm_buf == NULL)
+		return 0;
+	memset(bm_buf, 0, bm_size);
+	ocfs_initialize_bitmap (&global_bm, bm_buf, num_bits);
+
+	ret = 1;
+	if (volhdr) {
+    		if (!SetSeek(file, volhdr->bitmap_off) ||
+		    !Read(file, bm_size, bm_buf))
+			ret = 0;
+	}
+
+	return ret;
+}
+
+int ocfs_update_bm_lock_stats(int file)
+{
+	int status = 0;
+	ocfs_bitmap_lock *bm_lock = NULL;
+
+	bm_lock = (ocfs_bitmap_lock *) MemAlloc(512);
+	if (bm_lock == NULL)
+		return 0;
+	
+	memset((char *)bm_lock, 0, OCFS_SECTOR_SIZE);
+        bm_lock->used_bits = ocfs_count_bits(&global_bm);
+	if (SetSeek(file, OCFS_BITMAP_LOCK_OFFSET))
+		if (Write(file, OCFS_SECTOR_SIZE, (void *) bm_lock)) {
+			status = 1;
+    			fsync(file);
+		}
+	
+	safefree(bm_lock);
+	return status;
+}
+
+__u32 ocfs_alloc_from_global_bitmap (__u64 file_size, ocfs_vol_disk_hdr *volhdr)
+{
+	__u32 startbit = 0, numbits = 0;
+
+	file_size = OCFS_ALIGN(file_size, volhdr->cluster_size);
+	numbits = (__u32) (file_size / volhdr->cluster_size);
+
+	startbit = ocfs_find_clear_bits (&global_bm, numbits, 0, 0);
+	if (startbit != (__u32)-1)
+		ocfs_set_bits (&global_bm, startbit, numbits);
+	return startbit;
+}
+
+
+int ocfs_create_root_directory (int file, ocfs_vol_disk_hdr * volhdr)
+{
+	int status = 0;
+	__u64 orphan_off = 0ULL, journal_off = 0ULL;
+	__u32 i, j, fileid, bit, root_bit;
+       	__u32 max = (major_version == OCFS2_MAJOR_VERSION) ? 
+		OCFS_JOURNAL_SYSFILE : OCFS_CLEANUP_LOG_SYSFILE;
+	ocfs_dir_node *dir = NULL;
+	ocfs_file_entry *fe = NULL;
+	__u64 data_off;
+
+	fe = MemAlloc(512);
+	if (fe == NULL)
+		goto bail;
+
+	dir = MemAlloc(OCFS_DEFAULT_DIR_NODE_SIZE);
+	if (dir == NULL)
+		goto bail;
+
+	/* reserve system file bits in global */
+	bit = ocfs_alloc_from_global_bitmap (ONE_MEGA_BYTE, volhdr);
+	if (bit == (__u32) -1)
+		goto bail;
+
+	volhdr->internal_off = (bit * volhdr->cluster_size) + volhdr->data_start_off;
+
+	/* reserve root dir bits in global */
+	root_bit = ocfs_alloc_from_global_bitmap (OCFS_DEFAULT_DIR_NODE_SIZE, volhdr);
+	if (root_bit == (__u32)-1)
+		goto bail;
+	
+	volhdr->root_off = (root_bit * volhdr->cluster_size) + volhdr->data_start_off;
+	ocfs_init_dirnode(dir, volhdr->root_off, root_bit);
+	dir->dir_node_flags |= DIR_NODE_FLAG_ROOT;
+
+	if (!SetSeek(file, volhdr->root_off))
+		goto bail;
+	if (!Write(file, OCFS_DEFAULT_DIR_NODE_SIZE, (void *) dir))
+		goto bail;
+	fsync(file);
+
+	/* for v2, need to reserve space for orphan dirs: 32 x 128k */
+	/* and space for first 4 journals: 4 x 8mb */
+	if (major_version == OCFS2_MAJOR_VERSION) {
+		bit = ocfs_alloc_from_global_bitmap (32*OCFS_DEFAULT_DIR_NODE_SIZE, volhdr);
+		if (bit == (__u32)-1)
+			goto bail;
+		orphan_off = (bit * volhdr->cluster_size) + volhdr->data_start_off;
+		bit = ocfs_alloc_from_global_bitmap (4*OCFS_JOURNAL_DEFAULT_SIZE, volhdr);
+		if (bit == (__u32)-1)
+			goto bail;
+		journal_off = (bit * volhdr->cluster_size) + volhdr->data_start_off;
+	}
+
+	/* create all appropriate system file types for this ocfs version */
+	/* v2 will create orphan, journal, and local alloc + v1 types */
+	for (i = 0; i < OCFS_MAXIMUM_NODES; i++) {
+		for (j = OCFS_VOL_MD_SYSFILE; j <= max; j++) {
+			fileid = (j*OCFS_MAXIMUM_NODES) + i;
+			data_off = 0ULL;
+
+			// only first 4 journals allocated
+			// all others must use tuneocfs
+			if (j == OCFS_JOURNAL_SYSFILE) {
+				if (i < 4)
+					data_off = journal_off;
+			} else if (j == OCFS_ORPHAN_DIR_SYSFILE)
+				data_off = orphan_off;
+
+			if (!ocfs_init_sysfile (file, volhdr, fileid, fe, data_off))
+				goto bail;
+		}
+		orphan_off += OCFS_DEFAULT_DIR_NODE_SIZE;
+		journal_off += OCFS_JOURNAL_DEFAULT_SIZE;
+	}
+
+	status = 1;
+
+bail:
+	safefree (dir);
+	safefree (fe);
+	return status;
+}
+
+void ocfs_init_dirnode(ocfs_dir_node *dir, __u64 disk_off, __u32 bit_off)
+{
+	memset(dir, 0, OCFS_DEFAULT_DIR_NODE_SIZE);
+	strcpy (dir->signature, OCFS_DIR_NODE_SIGNATURE);
+	dir->num_ents = 254;
+	dir->node_disk_off = disk_off;
+	dir->alloc_file_off = bit_off;
+	dir->alloc_node = OCFS_INVALID_NODE_NUM;
+	dir->free_node_ptr = INVALID_NODE_POINTER;
+	dir->next_node_ptr = INVALID_NODE_POINTER;
+	dir->indx_node_ptr = INVALID_NODE_POINTER;
+	dir->next_del_ent_node = INVALID_NODE_POINTER;
+	dir->head_del_ent_node = INVALID_NODE_POINTER;
+	dir->first_del = INVALID_DIR_NODE_INDEX;
+	dir->index_dirty = 0;
+	DISK_LOCK_CURRENT_MASTER (dir) = OCFS_INVALID_NODE_NUM;
+}
+
+int ocfs_init_sysfile (int file, ocfs_vol_disk_hdr *volhdr, __u32 file_id, 
+			      ocfs_file_entry *fe, __u64 data)
+{
+	int status = 0;
+	char *filename;
+	ocfs_local_alloc *alloc;
+	__u64 off;
+	__u32 orphan_bit;
+	ocfs_dir_node *orphan_dir = NULL;
+	__u8 next_free_ext = 0;
+
+	memset (fe, 0, 512);
+	filename = &(fe->filename[0]);	
+	off = (file_id * OCFS_SECTOR_SIZE) + volhdr->internal_off;
+
+	if ((file_id >= OCFS_FILE_DIR_ALLOC) &&
+	    (file_id < (OCFS_FILE_DIR_ALLOC + 32))) {
+		sprintf (filename, "%s%d", OCFS_DIR_FILENAME, file_id);
+	} else if ((file_id >= OCFS_FILE_DIR_ALLOC_BITMAP) &&
+		   (file_id < (OCFS_FILE_DIR_ALLOC_BITMAP + 32))) {
+		sprintf (filename, "%s%d", OCFS_DIR_BITMAP_FILENAME, file_id);
+	} else if ((file_id >= OCFS_FILE_FILE_ALLOC) &&
+		   (file_id < (OCFS_FILE_FILE_ALLOC + 32))) {
+		sprintf (filename, "%s%d", OCFS_FILE_EXTENT_FILENAME, file_id);
+	} else if ((file_id >= OCFS_FILE_FILE_ALLOC_BITMAP) &&
+		   (file_id < (OCFS_FILE_FILE_ALLOC_BITMAP + 32))) {
+		sprintf (filename, "%s%d", OCFS_FILE_EXTENT_BITMAP_FILENAME,
+			 file_id);
+	} else if ((file_id >= LOG_FILE_BASE_ID)
+		   && (file_id < (LOG_FILE_BASE_ID + 32))) {
+		sprintf (filename, "%s%d", OCFS_RECOVER_LOG_FILENAME, file_id);
+	} else if ((file_id >= CLEANUP_FILE_BASE_ID) &&
+		   (file_id < (CLEANUP_FILE_BASE_ID + 32))) {
+		sprintf (filename, "%s%d", OCFS_CLEANUP_LOG_FILENAME, file_id);
+	} else if ((file_id >= OCFS_FILE_VOL_META_DATA) &&
+		   (file_id < (OCFS_FILE_VOL_META_DATA + 32))) {
+		sprintf (filename, "%s", "VolMetaDataFile");
+	} else if ((file_id >= OCFS_FILE_VOL_LOG_FILE) &&
+		   (file_id < (OCFS_FILE_VOL_LOG_FILE + 32))) {
+		sprintf (filename, "%s", "VolMetaDataLogFile");
+	} else if ((file_id >= OCFS_VOL_BITMAP_FILE) &&
+		   (file_id < (OCFS_VOL_BITMAP_FILE + 32))) {
+		// markf likes to be special ;-)
+		alloc = (ocfs_local_alloc *) fe;
+	        strcpy (alloc->signature, OCFS_LOCAL_ALLOC_SIGNATURE);
+	        alloc->this_sector = off;
+	        alloc->node_num = file_id - OCFS_VOL_BITMAP_FILE;
+		goto do_write;
+	} else if ((file_id >= OCFS_ORPHAN_DIR) &&
+		   (file_id < (OCFS_ORPHAN_DIR + 32))) {
+		sprintf(filename, "%s%d", OCFS_ORPHAN_DIR_FILENAME, file_id);
+	        fe->attribs = OCFS_ATTRIB_DIRECTORY;
+	        fe->alloc_size = OCFS_DEFAULT_DIR_NODE_SIZE;
+	        fe->file_size = OCFS_DEFAULT_DIR_NODE_SIZE;
+	        fe->next_del = INVALID_DIR_NODE_INDEX;
+	        fe->extents[0].disk_off = data;
+
+		orphan_dir = (ocfs_dir_node *) MemAlloc(OCFS_DEFAULT_DIR_NODE_SIZE);
+		if (orphan_dir == NULL)
+			return 0;
+		orphan_bit = (__u32)((data - volhdr->data_start_off) / volhdr->cluster_size);
+		ocfs_init_dirnode(orphan_dir, data, orphan_bit);
+		DISK_LOCK_CURRENT_MASTER (orphan_dir) = file_id - OCFS_ORPHAN_DIR;
+		DISK_LOCK_FILE_LOCK (orphan_dir) = OCFS_DLM_ENABLE_CACHE_LOCK;
+		orphan_dir->dir_node_flags |= DIR_NODE_FLAG_ORPHAN;
+		
+		if (SetSeek(file, data))
+	                if (Write(file, OCFS_DEFAULT_DIR_NODE_SIZE, (void *) orphan_dir)) {
+				status = 1;
+				fsync(file);
+			}
+		safefree(orphan_dir);
+		if (!status)
+			return status;
+	} else if ((file_id >= OCFS_JOURNAL_FILE) && 
+		   (file_id < (OCFS_JOURNAL_FILE + 32))) {
+		sprintf(filename, "%s%d", OCFS_JOURNAL_FILENAME, file_id);
+		
+		// first 4 will have 8mb, rest will have nothing yet
+		if (data) {
+			fe->alloc_size = OCFS_JOURNAL_DEFAULT_SIZE;
+			fe->file_size = OCFS_JOURNAL_DEFAULT_SIZE;
+	        	fe->extents[0].disk_off = data;
+	        	fe->extents[0].file_off = 0ULL;
+	        	fe->extents[0].num_bytes = OCFS_JOURNAL_DEFAULT_SIZE;
+			next_free_ext = 1;
+			if (!ocfs_replacement_journal_create(file, data))
+				return 0;
+		}
+	} else {
+		fprintf(stderr, "eeeeek! fileid=%d\n", file_id);
+		exit(1);
+	}
+
+	fe->local_ext = true;
+	fe->granularity = -1;
+	strcpy (fe->signature, OCFS_FILE_ENTRY_SIGNATURE);
+	SET_VALID_BIT (fe->sync_flags);
+	fe->sync_flags &= ~(OCFS_SYNC_FLAG_CHANGE);
+	fe->last_ext_ptr = 0;
+	fe->this_sector = off;
+	fe->next_free_ext = next_free_ext;
+
+do_write:
+	if (SetSeek(file, off))
+		if (Write(file, OCFS_SECTOR_SIZE, (void *) fe)) {
+			status = 1;
+			fsync(file);
+		}
+	return status;
+}



More information about the Ocfs-tools-commits mailing list