summaryrefslogtreecommitdiffstats
path: root/libglusterfsclient
diff options
context:
space:
mode:
authorRaghavendra G <raghavendra@gluster.com>2009-11-18 01:14:58 +0000
committerAnand V. Avati <avati@dev.gluster.com>2009-11-18 21:13:55 -0800
commit3940cf2fc26ed0d2417caef87ff25d17ec8d3bb4 (patch)
tree0a44e53f936b43895259713656d388eb99eacf51 /libglusterfsclient
parent7894bef2174945af06dceb506d501b8e789342fd (diff)
libglusterfsclient: implement glusterfs_getcwd.
Signed-off-by: Raghavendra G <raghavendra@gluster.com> Signed-off-by: Anand V. Avati <avati@dev.gluster.com> BUG: 369 (Samba does not work with booster.) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=369
Diffstat (limited to 'libglusterfsclient')
-rwxr-xr-xlibglusterfsclient/src/libglusterfsclient.c64
-rwxr-xr-xlibglusterfsclient/src/libglusterfsclient.h14
2 files changed, 78 insertions, 0 deletions
diff --git a/libglusterfsclient/src/libglusterfsclient.c b/libglusterfsclient/src/libglusterfsclient.c
index 58803e8..dcfda77 100755
--- a/libglusterfsclient/src/libglusterfsclient.c
+++ b/libglusterfsclient/src/libglusterfsclient.c
@@ -7843,6 +7843,70 @@ out:
}
+char *
+glusterfs_getcwd (char *buf, size_t size)
+{
+ char *res = NULL;
+ size_t len = 0;
+ loc_t loc = {0, };
+ glusterfs_handle_t handle = NULL;
+ char vpath[PATH_MAX];
+ int32_t op_ret = 0;
+
+ pthread_mutex_lock (&cwdlock);
+ {
+ if (!cwd_inited) {
+ errno = ENODEV;
+ goto unlock;
+ }
+
+ if (buf == NULL) {
+ buf = CALLOC (1, len);
+ if (buf == NULL) {
+ gf_log (LIBGF_XL_NAME, GF_LOG_ERROR,
+ "out of memory");
+ goto unlock;
+ }
+ } else {
+ if (size == 0) {
+ errno = EINVAL;
+ goto unlock;
+ }
+
+ if (len > size) {
+ errno = ERANGE;
+ goto unlock;
+ }
+ }
+
+ strcpy (buf, cwd);
+ res = buf;
+ }
+unlock:
+ pthread_mutex_unlock (&cwdlock);
+
+ if (res != NULL) {
+ handle = libgf_resolved_path_handle (res, vpath);
+
+ if (handle != NULL) {
+ loc.path = strdup (vpath);
+ if (loc.path == NULL) {
+ gf_log (LIBGF_XL_NAME, GF_LOG_ERROR,
+ "strdup failed");
+ } else {
+ op_ret = libgf_client_path_lookup (&loc, handle,
+ 0);
+ if (op_ret == -1) {
+ res = NULL;
+ }
+ }
+ }
+ }
+
+ return res;
+}
+
+
static struct xlator_fops libgf_client_fops = {
};
diff --git a/libglusterfsclient/src/libglusterfsclient.h b/libglusterfsclient/src/libglusterfsclient.h
index 74575fa..1684381 100755
--- a/libglusterfsclient/src/libglusterfsclient.h
+++ b/libglusterfsclient/src/libglusterfsclient.h
@@ -1325,6 +1325,20 @@ glusterfs_chdir (const char *path);
int
glusterfs_fchdir (glusterfs_file_t fd);
+/* copies the current working directory into @buf if it is big enough
+ *
+ * @buf: buffer to copy into it. If @buf is NULL, a buffer will be allocated.
+ * The size of the buffer will be @size if it is not zero, otherwise the
+ * size will be big enough to hold the current working directory.
+ * @size: size of the buffer.
+ *
+ * Returns the pointer to buffer holding current working directory on success
+ * and NULL on failure.
+ */
+
+char *
+glusterfs_getcwd (char *buf, size_t size);
+
/* FIXME: review the need for these apis */
/* added for log related initialization in booster fork implementation */
void