Gitweb:
http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=ddaff5fe...
Commit: ddaff5fecfb523cc6e0be0f36c4cd3fddeb5d807
Parent: 72553fb7cdfa7d69e0d7473cfd388078d7dedae5
Author: Andrew Price <anprice(a)redhat.com>
AuthorDate: Sun Mar 27 03:33:38 2016 +0100
Committer: Andrew Price <anprice(a)redhat.com>
CommitterDate: Tue Mar 29 12:14:29 2016 +0100
libgfs2: New function lgfs2_rindex_read_one()
Add a simple function to read an rindex entry into a set of resource
groups.
Signed-off-by: Andrew Price <anprice(a)redhat.com>
---
gfs2/libgfs2/libgfs2.h | 2 ++
gfs2/libgfs2/rgrp.c | 32 ++++++++++++++++++++++++++++++++
2 files changed, 34 insertions(+), 0 deletions(-)
diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index 7c87884..d6c54b3 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -177,6 +177,7 @@ struct gfs2_bitmap
};
struct gfs2_sbd;
+struct gfs2_inode;
typedef struct _lgfs2_rgrps *lgfs2_rgrps_t;
struct rgrp_tree {
@@ -196,6 +197,7 @@ extern lgfs2_rgrps_t lgfs2_rgrps_init(struct gfs2_sbd *sdp, uint64_t
align, uint
extern void lgfs2_rgrps_free(lgfs2_rgrps_t *rgs);
extern uint64_t lgfs2_rindex_entry_new(lgfs2_rgrps_t rgs, struct gfs2_rindex *entry,
uint64_t addr, uint32_t len);
extern unsigned lgfs2_rindex_read_fd(int fd, lgfs2_rgrps_t rgs);
+extern const struct gfs2_rindex *lgfs2_rindex_read_one(struct gfs2_inode *rip,
lgfs2_rgrps_t rgs, unsigned i);
extern uint64_t lgfs2_rgrp_align_addr(const lgfs2_rgrps_t rgs, uint64_t addr);
extern uint32_t lgfs2_rgrp_align_len(const lgfs2_rgrps_t rgs, uint32_t len);
extern unsigned lgfs2_rgsize_for_data(uint64_t blksreq, unsigned bsize);
diff --git a/gfs2/libgfs2/rgrp.c b/gfs2/libgfs2/rgrp.c
index 766bdfc..7066a5c 100644
--- a/gfs2/libgfs2/rgrp.c
+++ b/gfs2/libgfs2/rgrp.c
@@ -430,6 +430,38 @@ unsigned lgfs2_rindex_read_fd(int fd, lgfs2_rgrps_t rgs)
}
/**
+ * Read a rindex entry into a set of resource groups
+ * rip: The inode of the rindex file
+ * rgs: The set of resource groups.
+ * i: The index of the entry to read from the rindex file
+ * Returns the new rindex entry added to the set or NULL on error with errno
+ * set.
+ */
+const struct gfs2_rindex *lgfs2_rindex_read_one(struct gfs2_inode *rip, lgfs2_rgrps_t
rgs, unsigned i)
+{
+ uint64_t off = i * sizeof(struct gfs2_rindex);
+ char buf[sizeof(struct gfs2_rindex)];
+ struct gfs2_rindex ri;
+ lgfs2_rgrp_t rg;
+ int ret;
+
+ errno = EINVAL;
+ if (rip == NULL || rgs == NULL)
+ return NULL;
+
+ ret = gfs2_readi(rip, buf, off, sizeof(struct gfs2_rindex));
+ if (ret != sizeof(struct gfs2_rindex))
+ return NULL;
+
+ gfs2_rindex_in(&ri, buf);
+ rg = lgfs2_rgrps_append(rgs, &ri);
+ if (rg == NULL)
+ return NULL;
+
+ return &rg->ri;
+}
+
+/**
* Free a set of resource groups created with lgfs2_rgrps_append() etc. This
* does not write any dirty buffers to disk. See lgfs2_rgrp_write().
* rgs: A pointer to the set of resource groups to be freed.