public inbox for cluster-cvs@sourceware.org
help / color / mirror / Atom feed
* cluster: STABLE3 - libgfs2: Merge bitmap.c into block_list.c
@ 2009-02-19 10:13 Fabio M. Di Nitto
0 siblings, 0 replies; only message in thread
From: Fabio M. Di Nitto @ 2009-02-19 10:13 UTC (permalink / raw)
To: cluster-cvs-relay
Gitweb: http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=5cbb29ab2a5979ff91f6aa123e12c2c86c0b7912
Commit: 5cbb29ab2a5979ff91f6aa123e12c2c86c0b7912
Parent: ddc73d79ebec29a68c432feb9f4dedb891fca8c6
Author: Steven Whitehouse <swhiteho@redhat.com>
AuthorDate: Mon Jan 26 09:45:24 2009 +0000
Committer: Fabio M. Di Nitto <fdinitto@redhat.com>
CommitterDate: Thu Feb 19 10:59:54 2009 +0100
libgfs2: Merge bitmap.c into block_list.c
The code in bitmap.c was only used internally by the block_list.c
code, so by merging that into block_list.c, we can mark all those
functions static.
Signed-off-by: Steven Whitehouse <swhiteho@redhat.com>
---
gfs2/libgfs2/Makefile | 3 +-
gfs2/libgfs2/bitmap.c | 141 ---------------------------------------------
gfs2/libgfs2/block_list.c | 135 ++++++++++++++++++++++++++++++++++++++++++-
gfs2/libgfs2/libgfs2.h | 6 --
4 files changed, 134 insertions(+), 151 deletions(-)
diff --git a/gfs2/libgfs2/Makefile b/gfs2/libgfs2/Makefile
index 81dcef5..e00e31f 100644
--- a/gfs2/libgfs2/Makefile
+++ b/gfs2/libgfs2/Makefile
@@ -2,8 +2,7 @@ TARGET= libgfs2
MAKESTATICLIB = 1
-OBJS= bitmap.o \
- block_list.o \
+OBJS= block_list.o \
buf.o \
device_geometry.o \
fs_bits.o \
diff --git a/gfs2/libgfs2/bitmap.c b/gfs2/libgfs2/bitmap.c
deleted file mode 100644
index 85c6f95..0000000
--- a/gfs2/libgfs2/bitmap.c
+++ /dev/null
@@ -1,141 +0,0 @@
-/* Basic bitmap manipulation */
-#include <inttypes.h>
-#include <stdint.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-
-#include "libgfs2.h"
-
-#define BITMAP_SIZE(size, cpb) (size / cpb)
-#define BITMAP_SIZE1(size) (size >> 3)
-#define BITMAP_SIZE4(size) (size >> 1)
-
-#define BITMAP_BYTE_OFFSET(x, map) ((x % map->chunks_per_byte) \
- * map->chunksize )
-
-/* BITMAP_BYTE_OFFSET1 is for chunksize==1, which implies chunks_per_byte==8 */
-/* Reducing the math, we get: */
-/* #define BITMAP_BYTE_OFFSET1(x) ((x % 8) * 1) */
-/* #define BITMAP_BYTE_OFFSET1(x) (x % 8) */
-/* #define BITMAP_BYTE_OFFSET1(x) (x & 0x0000000000000007) */
-#define BITMAP_BYTE_OFFSET1(x) (x & 0x0000000000000007)
-
-/* BITMAP_BYTE_OFFSET4 is for chunksize==4, which implies chunks_per_byte==2 */
-/* Reducing the math, we get: */
-/* #define BITMAP_BYTE_OFFSET4(x) ((x % 2) * 4) */
-/* #define BITMAP_BYTE_OFFSET4(x) ((x & 0x0000000000000001) * 4) */
-/* #define BITMAP_BYTE_OFFSET4(x) ((x & 0x0000000000000001) << 2) */
-#define BITMAP_BYTE_OFFSET4(x) ((x & 0x0000000000000001) << 2)
-
-#define BITMAP_MASK(chunksize) ((2 << (chunksize - 1)) - 1)
-/* BITMAP_MASK1 is for chunksize==1 */
-/* Reducing the math, we get: */
-/* #define BITMAP_MASK1(chunksize) ((2 << (1 - 1)) - 1) */
-/* #define BITMAP_MASK1(chunksize) ((2 << 0) - 1) */
-/* #define BITMAP_MASK1(chunksize) ((2) - 1) */
-#define BITMAP_MASK1(chunksize) (1)
-
-/* BITMAP_MASK4 is for chunksize==4 */
-/* #define BITMAP_MASK(chunksize) ((2 << (4 - 1)) - 1) */
-/* #define BITMAP_MASK(chunksize) ((2 << 3) - 1) */
-/* #define BITMAP_MASK(chunksize) (0x10 - 1) */
-#define BITMAP_MASK4(chunksize) (0xf)
-
-int gfs2_bitmap_create(struct gfs2_bmap *bmap, uint64_t size,
- uint8_t chunksize)
-{
- if((((chunksize >> 1) << 1) != chunksize) && chunksize != 1)
- return -1;
- if(chunksize > 8)
- return -1;
- bmap->chunksize = chunksize;
- bmap->chunks_per_byte = 8 / chunksize;
-
- bmap->size = size;
-
- /* Have to add 1 to BITMAP_SIZE since it's 0-based and mallocs
- * must be 1-based */
- bmap->mapsize = BITMAP_SIZE(size, bmap->chunks_per_byte)+1;
-
- if(!(bmap->map = malloc(sizeof(char) * bmap->mapsize)))
- return -ENOMEM;
- if(!memset(bmap->map, 0, sizeof(char) * bmap->mapsize)) {
- free(bmap->map);
- bmap->map = NULL;
- return -ENOMEM;
- }
- return 0;
-}
-
-int gfs2_bitmap_set(struct gfs2_bmap *bmap, uint64_t offset, uint8_t val)
-{
- static char *byte;
- static uint64_t b;
-
- if(offset < bmap->size) {
- if (bmap->chunksize == 1) {
- byte = bmap->map + BITMAP_SIZE1(offset);
- b = BITMAP_BYTE_OFFSET1(offset);
- *byte |= (val & BITMAP_MASK1(bmap->chunksize));
- } else {
- byte = bmap->map + BITMAP_SIZE4(offset);
- b = BITMAP_BYTE_OFFSET4(offset);
- *byte |= (val & BITMAP_MASK4(bmap->chunksize)) << b;
- }
- return 0;
- }
- return -1;
-}
-
-int gfs2_bitmap_get(struct gfs2_bmap *bmap, uint64_t bit, uint8_t *val)
-{
- static char *byte;
- static uint64_t b;
-
- if(bit < bmap->size) {
- if (bmap->chunksize == 1) {
- byte = bmap->map + BITMAP_SIZE1(bit);
- b = BITMAP_BYTE_OFFSET1(bit);
- *val = (*byte & (BITMAP_MASK1(bmap->chunksize) << b )) >> b;
- } else {
- byte = bmap->map + BITMAP_SIZE4(bit);
- b = BITMAP_BYTE_OFFSET4(bit);
- *val = (*byte & (BITMAP_MASK4(bmap->chunksize) << b )) >> b;
- }
- return 0;
- }
- return -1;
-}
-
-int gfs2_bitmap_clear(struct gfs2_bmap *bmap, uint64_t offset)
-{
- static char *byte;
- static uint64_t b;
-
- if(offset < bmap->size) {
- if (bmap->chunksize == 1) {
- byte = bmap->map + BITMAP_SIZE1(offset);
- b = BITMAP_BYTE_OFFSET1(offset);
- *byte &= ~(BITMAP_MASK1(bmap->chunksize) << b);
- } else {
- byte = bmap->map + BITMAP_SIZE4(offset);
- b = BITMAP_BYTE_OFFSET4(offset);
- *byte &= ~(BITMAP_MASK4(bmap->chunksize) << b);
- }
- return 0;
- }
- return -1;
-
-}
-
-void gfs2_bitmap_destroy(struct gfs2_bmap *bmap)
-{
- if(bmap->map)
- free(bmap->map);
- bmap->size = 0;
- bmap->mapsize = 0;
- bmap->chunksize = 0;
- bmap->chunks_per_byte = 0;
-}
diff --git a/gfs2/libgfs2/block_list.c b/gfs2/libgfs2/block_list.c
index c7c7342..4e51226 100644
--- a/gfs2/libgfs2/block_list.c
+++ b/gfs2/libgfs2/block_list.c
@@ -8,8 +8,7 @@
#include "libgfs2.h"
-/* Must be kept in sync with mark_block enum in block_list.h */
-/* FIXME: Fragile */
+/* Must be kept in sync with mark_block enum in libgfs2.h */
static int mark_to_gbmap[16] = {
FREE, BLOCK_IN_USE, DIR_INDIR_BLK, DIR_INODE, FILE_INODE,
LNK_INODE, BLK_INODE, CHR_INODE, FIFO_INODE, SOCK_INODE,
@@ -17,6 +16,138 @@ static int mark_to_gbmap[16] = {
INVALID_META, INVALID_META
};
+#define BITMAP_SIZE(size, cpb) (size / cpb)
+#define BITMAP_SIZE1(size) (size >> 3)
+#define BITMAP_SIZE4(size) (size >> 1)
+
+#define BITMAP_BYTE_OFFSET(x, map) ((x % map->chunks_per_byte) \
+ * map->chunksize )
+
+/* BITMAP_BYTE_OFFSET1 is for chunksize==1, which implies chunks_per_byte==8 */
+/* Reducing the math, we get: */
+/* #define BITMAP_BYTE_OFFSET1(x) ((x % 8) * 1) */
+/* #define BITMAP_BYTE_OFFSET1(x) (x % 8) */
+/* #define BITMAP_BYTE_OFFSET1(x) (x & 0x0000000000000007) */
+#define BITMAP_BYTE_OFFSET1(x) (x & 0x0000000000000007)
+
+/* BITMAP_BYTE_OFFSET4 is for chunksize==4, which implies chunks_per_byte==2 */
+/* Reducing the math, we get: */
+/* #define BITMAP_BYTE_OFFSET4(x) ((x % 2) * 4) */
+/* #define BITMAP_BYTE_OFFSET4(x) ((x & 0x0000000000000001) * 4) */
+/* #define BITMAP_BYTE_OFFSET4(x) ((x & 0x0000000000000001) << 2) */
+#define BITMAP_BYTE_OFFSET4(x) ((x & 0x0000000000000001) << 2)
+
+#define BITMAP_MASK(chunksize) ((2 << (chunksize - 1)) - 1)
+/* BITMAP_MASK1 is for chunksize==1 */
+/* Reducing the math, we get: */
+/* #define BITMAP_MASK1(chunksize) ((2 << (1 - 1)) - 1) */
+/* #define BITMAP_MASK1(chunksize) ((2 << 0) - 1) */
+/* #define BITMAP_MASK1(chunksize) ((2) - 1) */
+#define BITMAP_MASK1(chunksize) (1)
+
+/* BITMAP_MASK4 is for chunksize==4 */
+/* #define BITMAP_MASK(chunksize) ((2 << (4 - 1)) - 1) */
+/* #define BITMAP_MASK(chunksize) ((2 << 3) - 1) */
+/* #define BITMAP_MASK(chunksize) (0x10 - 1) */
+#define BITMAP_MASK4(chunksize) (0xf)
+
+static int gfs2_bitmap_create(struct gfs2_bmap *bmap, uint64_t size,
+ uint8_t chunksize)
+{
+ if((((chunksize >> 1) << 1) != chunksize) && chunksize != 1)
+ return -1;
+ if(chunksize > 8)
+ return -1;
+ bmap->chunksize = chunksize;
+ bmap->chunks_per_byte = 8 / chunksize;
+
+ bmap->size = size;
+
+ /* Have to add 1 to BITMAP_SIZE since it's 0-based and mallocs
+ * must be 1-based */
+ bmap->mapsize = BITMAP_SIZE(size, bmap->chunks_per_byte)+1;
+
+ if(!(bmap->map = malloc(sizeof(char) * bmap->mapsize)))
+ return -ENOMEM;
+ if(!memset(bmap->map, 0, sizeof(char) * bmap->mapsize)) {
+ free(bmap->map);
+ bmap->map = NULL;
+ return -ENOMEM;
+ }
+ return 0;
+}
+
+static int gfs2_bitmap_set(struct gfs2_bmap *bmap, uint64_t offset, uint8_t val)
+{
+ static char *byte;
+ static uint64_t b;
+
+ if(offset < bmap->size) {
+ if (bmap->chunksize == 1) {
+ byte = bmap->map + BITMAP_SIZE1(offset);
+ b = BITMAP_BYTE_OFFSET1(offset);
+ *byte |= (val & BITMAP_MASK1(bmap->chunksize));
+ } else {
+ byte = bmap->map + BITMAP_SIZE4(offset);
+ b = BITMAP_BYTE_OFFSET4(offset);
+ *byte |= (val & BITMAP_MASK4(bmap->chunksize)) << b;
+ }
+ return 0;
+ }
+ return -1;
+}
+
+static int gfs2_bitmap_get(struct gfs2_bmap *bmap, uint64_t bit, uint8_t *val)
+{
+ static char *byte;
+ static uint64_t b;
+
+ if(bit < bmap->size) {
+ if (bmap->chunksize == 1) {
+ byte = bmap->map + BITMAP_SIZE1(bit);
+ b = BITMAP_BYTE_OFFSET1(bit);
+ *val = (*byte & (BITMAP_MASK1(bmap->chunksize) << b )) >> b;
+ } else {
+ byte = bmap->map + BITMAP_SIZE4(bit);
+ b = BITMAP_BYTE_OFFSET4(bit);
+ *val = (*byte & (BITMAP_MASK4(bmap->chunksize) << b )) >> b;
+ }
+ return 0;
+ }
+ return -1;
+}
+
+static int gfs2_bitmap_clear(struct gfs2_bmap *bmap, uint64_t offset)
+{
+ static char *byte;
+ static uint64_t b;
+
+ if(offset < bmap->size) {
+ if (bmap->chunksize == 1) {
+ byte = bmap->map + BITMAP_SIZE1(offset);
+ b = BITMAP_BYTE_OFFSET1(offset);
+ *byte &= ~(BITMAP_MASK1(bmap->chunksize) << b);
+ } else {
+ byte = bmap->map + BITMAP_SIZE4(offset);
+ b = BITMAP_BYTE_OFFSET4(offset);
+ *byte &= ~(BITMAP_MASK4(bmap->chunksize) << b);
+ }
+ return 0;
+ }
+ return -1;
+
+}
+
+static void gfs2_bitmap_destroy(struct gfs2_bmap *bmap)
+{
+ if(bmap->map)
+ free(bmap->map);
+ bmap->size = 0;
+ bmap->mapsize = 0;
+ bmap->chunksize = 0;
+ bmap->chunks_per_byte = 0;
+}
+
struct gfs2_block_list *gfs2_block_list_create(struct gfs2_sbd *sdp,
uint64_t size,
uint64_t *addl_mem_needed)
diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index b4a1c05..509712a 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -285,12 +285,6 @@ struct gfs2_bmap {
char *map;
};
-extern int gfs2_bitmap_create(struct gfs2_bmap *bmap, uint64_t size, uint8_t bitsize);
-extern int gfs2_bitmap_set(struct gfs2_bmap *bmap, uint64_t offset, uint8_t val);
-extern int gfs2_bitmap_get(struct gfs2_bmap *bmap, uint64_t bit, uint8_t *val);
-extern int gfs2_bitmap_clear(struct gfs2_bmap *bmap, uint64_t offset);
-extern void gfs2_bitmap_destroy(struct gfs2_bmap *bmap);
-
/* block_list.c */
#define FREE (0x0) /* 0000 */
#define BLOCK_IN_USE (0x1) /* 0001 */
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2009-02-19 10:13 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-02-19 10:13 cluster: STABLE3 - libgfs2: Merge bitmap.c into block_list.c Fabio M. Di Nitto
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).