summaryrefslogtreecommitdiffstats
path: root/libglusterfsclient/src/libglusterfsclient.c
diff options
context:
space:
mode:
authorShehjar Tikoo <shehjart@zresearch.com>2009-05-05 15:58:56 +0530
committerAnand V. Avati <avati@amp.gluster.com>2009-05-05 17:31:45 +0530
commitb48df70c58f52878d58f3e1a0adc870688cdfcdc (patch)
treecead90462f7cb4e0fadb7da5f4da4f4abe6abd7f /libglusterfsclient/src/libglusterfsclient.c
parentdec408299ea7a2cb9aa9aa3ea3a3c72ee79169de (diff)
libglusterfsclient: Add VMP-based lchown
Signed-off-by: Anand V. Avati <avati@amp.gluster.com>
Diffstat (limited to 'libglusterfsclient/src/libglusterfsclient.c')
-rwxr-xr-xlibglusterfsclient/src/libglusterfsclient.c62
1 files changed, 59 insertions, 3 deletions
diff --git a/libglusterfsclient/src/libglusterfsclient.c b/libglusterfsclient/src/libglusterfsclient.c
index c36d9b4db..e34474982 100755
--- a/libglusterfsclient/src/libglusterfsclient.c
+++ b/libglusterfsclient/src/libglusterfsclient.c
@@ -4314,14 +4314,19 @@ out:
return op_ret;
}
+#define LIBGF_DO_CHOWN 1
+#define LIBGF_DO_LCHOWN 2
+
int
-glusterfs_glh_chown (glusterfs_handle_t handle, const char *path, uid_t owner,
- gid_t group)
+__glusterfs_chown (glusterfs_handle_t handle, const char *path, uid_t owner,
+ gid_t group, int whichop)
{
int op_ret = -1;
libglusterfs_client_ctx_t *ctx = handle;
loc_t loc = {0, };
char *name = NULL;
+ loc_t *oploc = NULL;
+ loc_t targetloc = {0, };
GF_VALIDATE_OR_GOTO (LIBGF_XL_NAME, ctx, out);
GF_VALIDATE_ABSOLUTE_PATH_OR_GOTO (LIBGF_XL_NAME, path, out);
@@ -4342,15 +4347,36 @@ glusterfs_glh_chown (glusterfs_handle_t handle, const char *path, uid_t owner,
goto out;
}
- op_ret = libgf_client_chown (ctx, &loc, owner, group);
+ oploc = &loc;
+ if (whichop == LIBGF_DO_LCHOWN)
+ goto do_lchown;
+
+ if (!S_ISLNK (loc.inode->st_mode))
+ goto do_lchown;
+
+ op_ret = libgf_realpath_loc_fill (ctx, (char *)loc.path, &targetloc);
+ if (op_ret == -1)
+ goto out;
+
+ oploc = &targetloc;
+do_lchown:
+ op_ret = libgf_client_chown (ctx, oploc, owner, group);
out:
if (name)
FREE (name);
libgf_client_loc_wipe (&loc);
+ libgf_client_loc_wipe (&targetloc);
return op_ret;
}
int
+glusterfs_glh_chown (glusterfs_handle_t handle, const char *path, uid_t owner,
+ gid_t group)
+{
+ return __glusterfs_chown (handle, path, owner, group, LIBGF_DO_CHOWN);
+}
+
+int
glusterfs_chown (const char *path, uid_t owner, gid_t group)
{
struct vmp_entry *entry = NULL;
@@ -4373,6 +4399,36 @@ out:
return op_ret;
}
+int
+glusterfs_glh_lchown (glusterfs_handle_t handle, const char *path, uid_t owner,
+ gid_t group)
+{
+ return __glusterfs_chown (handle, path, owner, group, LIBGF_DO_LCHOWN);
+}
+
+int
+glusterfs_lchown (const char *path, uid_t owner, gid_t group)
+{
+ struct vmp_entry *entry = NULL;
+ int op_ret = -1;
+ char *vpath = NULL;
+
+ GF_VALIDATE_OR_GOTO (LIBGF_XL_NAME, path, out);
+
+ entry = libgf_vmp_search_entry ((char *)path);
+ if (!entry) {
+ errno = ENODEV;
+ goto out;
+ }
+
+ vpath = libgf_vmp_virtual_path (entry, path);
+ op_ret = glusterfs_glh_lchown (entry->handle, vpath, owner, group);
+out:
+ if (vpath)
+ free (vpath);
+ return op_ret;
+}
+
glusterfs_dir_t
glusterfs_glh_opendir (glusterfs_handle_t handle, const char *path)
{