Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save tuxillo/8216747 to your computer and use it in GitHub Desktop.
Save tuxillo/8216747 to your computer and use it in GitHub Desktop.
From 025c7794f89c68e80fe75c041b74b475388b1e2e Mon Sep 17 00:00:00 2001
From: Antonio Huete Jimenez <[email protected]>
Date: Sun, 29 Dec 2013 21:45:34 +0100
Subject: [PATCH] libhammer - Add a function to calculate PFS paths.
---
lib/libhammer/libhammer.h | 1 +
lib/libhammer/misc.c | 20 ++++++++++++++++++++
2 files changed, 21 insertions(+)
diff --git a/lib/libhammer/libhammer.h b/lib/libhammer/libhammer.h
index 712abc0..5271466 100644
--- a/lib/libhammer/libhammer.h
+++ b/lib/libhammer/libhammer.h
@@ -168,6 +168,7 @@ int libhammer_io_stats(struct libhammer_io_stats *);
char *libhammer_find_pfs_mount(int, uuid_t, int);
void *_libhammer_malloc(size_t);
+void libhammer_get_pfspath(libhammer_pfsinfo_t, char *);
__END_DECLS
static __inline libhammer_pfsinfo_t
diff --git a/lib/libhammer/misc.c b/lib/libhammer/misc.c
index 03751ab..6b7fec6 100644
--- a/lib/libhammer/misc.c
+++ b/lib/libhammer/misc.c
@@ -140,3 +140,23 @@ _libhammer_malloc(size_t len)
return (m);
}
+
+/*
+ * Identify the type of PFS (slave, master) and determine a
+ * valid path to open(2).
+ * Useful when trying to get a file-descriptor to issue an
+ * ioctl(2) on a specific PFS.
+ */
+void
+libhammer_get_pfspath(libhammer_pfsinfo_t pfi, char *path)
+{
+
+ /* In the case beg_tid and end_tid is 1 it means it's
+ * a manually created PFS and it's unlikely the calculated
+ * path below will be resolved by the VFS code.
+ */
+ if (pfi->ismaster)
+ sprintf(path, "@@-1:%05d", pfi->pfs_id);
+ else
+ sprintf(path, "@@0x%016jx:%05d", pfi->end_tid, pfi->pfs_id);
+}
--
1.8.4.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment