From: Andras Elso Date: Tue, 26 Feb 2013 23:20:39 +0000 (+0100) Subject: client: allow change file owner or group only X-Git-Tag: v0.59~94^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=ac9ed33a075e1464cfc954f0069f0a7fb97e54f6;p=ceph.git client: allow change file owner or group only Signed-off-by: Andras Elso --- diff --git a/src/client/Client.cc b/src/client/Client.cc index 71bb5d92143..eee7fdd6c1f 100644 --- a/src/client/Client.cc +++ b/src/client/Client.cc @@ -4435,7 +4435,7 @@ int Client::fchmod(int fd, mode_t mode) return _setattr(f->inode, &attr, CEPH_SETATTR_MODE); } -int Client::chown(const char *relpath, uid_t uid, gid_t gid) +int Client::chown(const char *relpath, int uid, int gid) { Mutex::Locker lock(client_lock); tout(cct) << "chown" << std::endl; @@ -4450,10 +4450,13 @@ int Client::chown(const char *relpath, uid_t uid, gid_t gid) struct stat attr; attr.st_uid = uid; attr.st_gid = gid; - return _setattr(in, &attr, CEPH_SETATTR_UID|CEPH_SETATTR_GID); + int mask = 0; + if (uid != -1) mask |= CEPH_SETATTR_UID; + if (gid != -1) mask |= CEPH_SETATTR_GID; + return _setattr(in, &attr, mask); } -int Client::fchown(int fd, uid_t uid, gid_t gid) +int Client::fchown(int fd, int uid, int gid) { Mutex::Locker lock(client_lock); tout(cct) << "fchown" << std::endl; @@ -4466,10 +4469,13 @@ int Client::fchown(int fd, uid_t uid, gid_t gid) struct stat attr; attr.st_uid = uid; attr.st_gid = gid; - return _setattr(f->inode, &attr, CEPH_SETATTR_UID|CEPH_SETATTR_GID); + int mask = 0; + if (uid != -1) mask |= CEPH_SETATTR_UID; + if (gid != -1) mask |= CEPH_SETATTR_GID; + return _setattr(f->inode, &attr, mask); } -int Client::lchown(const char *relpath, uid_t uid, gid_t gid) +int Client::lchown(const char *relpath, int uid, int gid) { Mutex::Locker lock(client_lock); tout(cct) << "lchown" << std::endl; @@ -4485,7 +4491,10 @@ int Client::lchown(const char *relpath, uid_t uid, gid_t gid) struct stat attr; attr.st_uid = uid; attr.st_gid = gid; - return _setattr(in, &attr, CEPH_SETATTR_UID|CEPH_SETATTR_GID); + int mask = 0; + if (uid != -1) mask |= CEPH_SETATTR_UID; + if (gid != -1) mask |= CEPH_SETATTR_GID; + return _setattr(in, &attr, mask); } int Client::utime(const char *relpath, struct utimbuf *buf) diff --git a/src/client/Client.h b/src/client/Client.h index 3fcdf481ad1..3ebf27fd0a9 100644 --- a/src/client/Client.h +++ b/src/client/Client.h @@ -622,9 +622,9 @@ public: int setattr(const char *relpath, struct stat *attr, int mask); int chmod(const char *path, mode_t mode); int fchmod(int fd, mode_t mode); - int chown(const char *path, uid_t uid, gid_t gid); - int fchown(int fd, uid_t uid, gid_t gid); - int lchown(const char *path, uid_t uid, gid_t gid); + int chown(const char *path, int uid, int gid); + int fchown(int fd, int uid, int gid); + int lchown(const char *path, int uid, int gid); int utime(const char *path, struct utimbuf *buf); int truncate(const char *path, loff_t size); diff --git a/src/include/cephfs/libcephfs.h b/src/include/cephfs/libcephfs.h index adcdb39e600..abfd25cfd7e 100644 --- a/src/include/cephfs/libcephfs.h +++ b/src/include/cephfs/libcephfs.h @@ -530,7 +530,7 @@ int ceph_fchmod(struct ceph_mount_info *cmount, int fd, mode_t mode); * @param gid the group id to set on the file/directory. * @returns 0 on success or negative error code on failure. */ -int ceph_chown(struct ceph_mount_info *cmount, const char *path, uid_t uid, gid_t gid); +int ceph_chown(struct ceph_mount_info *cmount, const char *path, int uid, int gid); /** * Change the ownership of a file from an open file descriptor. @@ -541,7 +541,7 @@ int ceph_chown(struct ceph_mount_info *cmount, const char *path, uid_t uid, gid_ * @param gid the group id to set on the file/directory. * @returns 0 on success or negative error code on failure. */ -int ceph_fchown(struct ceph_mount_info *cmount, int fd, uid_t uid, gid_t gid); +int ceph_fchown(struct ceph_mount_info *cmount, int fd, int uid, int gid); /** * Change the ownership of a file/directory, don't follow symlinks. @@ -552,7 +552,7 @@ int ceph_fchown(struct ceph_mount_info *cmount, int fd, uid_t uid, gid_t gid); * @param gid the group id to set on the file/directory. * @returns 0 on success or negative error code on failure. */ -int ceph_lchown(struct ceph_mount_info *cmount, const char *path, uid_t uid, gid_t gid); +int ceph_lchown(struct ceph_mount_info *cmount, const char *path, int uid, int gid); /** * Change file/directory last access and modification times. diff --git a/src/libcephfs.cc b/src/libcephfs.cc index 75937586cb0..d2fe0dac861 100644 --- a/src/libcephfs.cc +++ b/src/libcephfs.cc @@ -574,21 +574,21 @@ extern "C" int ceph_fchmod(struct ceph_mount_info *cmount, int fd, mode_t mode) return cmount->get_client()->fchmod(fd, mode); } extern "C" int ceph_chown(struct ceph_mount_info *cmount, const char *path, - uid_t uid, gid_t gid) + int uid, int gid) { if (!cmount->is_mounted()) return -ENOTCONN; return cmount->get_client()->chown(path, uid, gid); } extern "C" int ceph_fchown(struct ceph_mount_info *cmount, int fd, - uid_t uid, gid_t gid) + int uid, int gid) { if (!cmount->is_mounted()) return -ENOTCONN; return cmount->get_client()->fchown(fd, uid, gid); } extern "C" int ceph_lchown(struct ceph_mount_info *cmount, const char *path, - uid_t uid, gid_t gid) + int uid, int gid) { if (!cmount->is_mounted()) return -ENOTCONN;