chiark / gitweb /
volume_id: add OCFS (Oracle Cluster File System) support
authorAndre Masella <andre@masella.no-ip.org>
Sun, 17 Jul 2005 13:54:40 +0000 (09:54 -0400)
committerKay Sievers <kay.sievers@suse.de>
Sun, 17 Jul 2005 13:54:40 +0000 (09:54 -0400)
extras/volume_id/Makefile
extras/volume_id/volume_id/Makefile.inc
extras/volume_id/volume_id/ocfs2.c [new file with mode: 0644]
extras/volume_id/volume_id/ocfs2.h [new file with mode: 0644]
extras/volume_id/volume_id/volume_id.c
extras/volume_id/volume_id/volume_id.h

index eca9cfdbd4c0b6069b6c1e26854cdfa502c9c8ac..014bf8713d79f72a18f9d76ef52c780a72ab11b2 100644 (file)
@@ -33,7 +33,8 @@ override CFLAGS+=-D_FILE_OFFSET_BITS=64
 VOLUME_ID_BASE=volume_id
 include $(VOLUME_ID_BASE)/Makefile.inc
 
-OBJS = vol_id.o $(VOLUME_ID_OBJS) ../../udev.a
+OBJS = vol_id.o $(VOLUME_ID_OBJS)
+LIB_OBJS=../../udev.a
 HEADERS = $(VOLUME_ID_HEADERS)
 
 $(OBJS): $(HEADERS)
index 266d1e4872617fd5b86845c0106732d35d9fbd2e..71f4ea2862790b78c86e9f1f6221e06bc79ee986 100644 (file)
@@ -27,6 +27,7 @@ VOLUME_ID_OBJS=                                       \
        $(VOLUME_ID_BASE)/sysv.o                \
        $(VOLUME_ID_BASE)/minix.o               \
        $(VOLUME_ID_BASE)/luks.o                \
+       $(VOLUME_ID_BASE)/ocfs2.o               \
        $(VOLUME_ID_BASE)/volume_id.o           \
        $(VOLUME_ID_BASE)/util.o
 
@@ -58,5 +59,6 @@ VOLUME_ID_HEADERS=                            \
        $(VOLUME_ID_BASE)/sysv.h                \
        $(VOLUME_ID_BASE)/minix.h               \
        $(VOLUME_ID_BASE)/luks.h                \
+       $(VOLUME_ID_BASE)/ocfs2.h               \
        $(VOLUME_ID_BASE)/volume_id.h           \
        $(VOLUME_ID_BASE)/util.h
diff --git a/extras/volume_id/volume_id/ocfs2.c b/extras/volume_id/volume_id/ocfs2.c
new file mode 100644 (file)
index 0000000..1f2819c
--- /dev/null
@@ -0,0 +1,125 @@
+/*
+ * volume_id - reads filesystem label and uuid
+ *
+ * Copyright (C) Andre Masella <andre@masella.no-ip.org>
+ *
+ *     This library is free software; you can redistribute it and/or
+ *     modify it under the terms of the GNU Lesser General Public
+ *     License as published by the Free Software Foundation; either
+ *     version 2.1 of the License, or (at your option) any later version.
+ *
+ *     This library is distributed in the hope that it will be useful,
+ *     but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ *     Lesser General Public License for more details.
+ *
+ *     You should have received a copy of the GNU Lesser General Public
+ *     License along with this library; if not, write to the Free Software
+ *     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE 1
+#endif
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+#include <ctype.h>
+#include <asm/types.h>
+
+#include "volume_id.h"
+#include "logging.h"
+#include "util.h"
+#include "ocfs2.h"
+
+
+/* All these values are taken from ocfs2-tools's ocfs2_fs.h */
+#define OCFS2_VOL_UUID_LEN                     16
+#define OCFS2_MAX_VOL_LABEL_LEN                        64
+#define OCFS2_SUPERBLOCK_OFFSET                        0x2000
+
+
+/* This is the superblock. The OCFS2 header files have structs in structs.
+This is one has been simplified since we only care about the superblock.
+*/
+
+struct ocfs2_super_block {
+       __u8 i_signature[8];                    /* Signature for validation */
+       __u32 i_generation;                     /* Generation number */
+       __s16 i_suballoc_slot;                  /* Slot suballocator this inode belongs to */
+       __u16 i_suballoc_bit;                   /* Bit offset in suballocator block group */
+       __u32 i_reserved0;
+       __u32 i_clusters;                       /* Cluster count */
+       __u32 i_uid;                            /* Owner UID */
+       __u32 i_gid;                            /* Owning GID */
+       __u64 i_size;                           /* Size in bytes */
+       __u16 i_mode;                           /* File mode */
+       __u16 i_links_count;                    /* Links count */
+       __u32 i_flags;                          /* File flags */
+       __u64 i_atime;                          /* Access time */
+       __u64 i_ctime;                          /* Creation time */
+       __u64 i_mtime;                          /* Modification time */
+       __u64 i_dtime;                          /* Deletion time */
+       __u64 i_blkno;                          /* Offset on disk, in blocks */
+       __u64 i_last_eb_blk;                    /* Pointer to last extent block */
+       __u32 i_fs_generation;                  /* Generation per fs-instance */
+       __u32 i_atime_nsec;
+       __u32 i_ctime_nsec;
+       __u32 i_mtime_nsec;
+       __u64 i_reserved1[9];
+       __u64 i_pad1;                           /* Generic way to refer to this 64bit union */
+       /* Normally there is a union of the different block types, but we only care about the superblock. */
+       __u16 s_major_rev_level;
+       __u16 s_minor_rev_level;
+       __u16 s_mnt_count;
+       __s16 s_max_mnt_count;
+       __u16 s_state;                          /* File system state */
+       __u16 s_errors;                         /* Behaviour when detecting errors */
+       __u32 s_checkinterval;                  /* Max time between checks */
+       __u64 s_lastcheck;                      /* Time of last check */
+       __u32 s_creator_os;                     /* OS */
+       __u32 s_feature_compat;                 /* Compatible feature set */
+       __u32 s_feature_incompat;               /* Incompatible feature set */
+       __u32 s_feature_ro_compat;              /* Readonly-compatible feature set */
+       __u64 s_root_blkno;                     /* Offset, in blocks, of root directory dinode */
+       __u64 s_system_dir_blkno;               /* Offset, in blocks, of system directory dinode */
+       __u32 s_blocksize_bits;                 /* Blocksize for this fs */
+       __u32 s_clustersize_bits;               /* Clustersize for this fs */
+       __u16 s_max_slots;                      /* Max number of simultaneous mounts before tunefs required */
+       __u16 s_reserved1;
+       __u32 s_reserved2;
+       __u64 s_first_cluster_group;            /* Block offset of 1st cluster group header */
+       __u8  s_label[OCFS2_MAX_VOL_LABEL_LEN]; /* Label for mounting, etc. */
+       __u8  s_uuid[OCFS2_VOL_UUID_LEN];       /* 128-bit uuid */
+} __attribute__((__packed__));
+
+int volume_id_probe_ocfs2(struct volume_id *id, __u64 off)
+{
+       struct ocfs2_super_block *os;
+
+       dbg("probing at offset 0x%llx", (unsigned long long) off);
+
+       os = (struct ocsf2_super_block *) volume_id_get_buffer(id, off + OCFS2_SUPERBLOCK_OFFSET, 0x200);
+       if (os == NULL)
+               return -1;
+
+       if (strcmp(os->i_signature, "OCFSV2") != 0) {
+               return -1;
+       }
+
+       volume_id_set_usage(id, VOLUME_ID_FILESYSTEM);
+       volume_id_set_label_raw(id, os->s_label, OCFS2_MAX_VOL_LABEL_LEN < VOLUME_ID_LABEL_SIZE ?
+                                       OCFS2_MAX_VOL_LABEL_LEN : VOLUME_ID_LABEL_SIZE);
+       volume_id_set_label_string(id, os->s_label, OCFS2_MAX_VOL_LABEL_LEN < VOLUME_ID_LABEL_SIZE ?
+                                       OCFS2_MAX_VOL_LABEL_LEN : VOLUME_ID_LABEL_SIZE);
+       volume_id_set_uuid(id, os->s_uuid, UUID_DCE);
+       id->type = "ocfs2";
+       return 0;
+}
diff --git a/extras/volume_id/volume_id/ocfs2.h b/extras/volume_id/volume_id/ocfs2.h
new file mode 100644 (file)
index 0000000..1283481
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * volume_id - reads filesystem label and uuid
+ *
+ * Copyright (C) Andre Masella <andre@masella.no-ip.org>
+ *
+ *     This library is free software; you can redistribute it and/or
+ *     modify it under the terms of the GNU Lesser General Public
+ *     License as published by the Free Software Foundation; either
+ *     version 2.1 of the License, or (at your option) any later version.
+ *
+ *     This library is distributed in the hope that it will be useful,
+ *     but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ *     Lesser General Public License for more details.
+ *
+ *     You should have received a copy of the GNU Lesser General Public
+ *     License along with this library; if not, write to the Free Software
+ *     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef _VOLUME_ID_OCFS2_
+#define _VOLUME_ID_OCFS2_
+
+extern int volume_id_probe_ocfs2(struct volume_id *id, __u64 off);
+
+#endif
index 3fe8562e33590a489b582a69738d2c93ae29c985..8e944be0b12cf9116c97fc19275d810bc6da6931 100644 (file)
@@ -69,6 +69,7 @@
 #include "minix.h"
 #include "mac.h"
 #include "msdos.h"
+#include "ocfs2.h"
 
 int volume_id_probe_all(struct volume_id *id, unsigned long long off, unsigned long long size)
 {
@@ -169,6 +170,9 @@ int volume_id_probe_all(struct volume_id *id, unsigned long long off, unsigned l
        if (volume_id_probe_minix(id, off) == 0)
                goto exit;
 
+       if (volume_id_probe_ocfs2(id, off) == 0)
+               goto exit;
+
        return -1;
 
 exit:
index c6aef508760a50fd8b7e19dc5f497d91d769b178..4e0defdadd3164e2c84f5e4a6e3571b96a5ec142 100644 (file)
@@ -21,7 +21,7 @@
 #ifndef _VOLUME_ID_H_
 #define _VOLUME_ID_H_
 
-#define VOLUME_ID_VERSION              45
+#define VOLUME_ID_VERSION              46
 
 #define VOLUME_ID_LABEL_SIZE           64
 #define VOLUME_ID_UUID_SIZE            36