cephfs: add wrapper for ceph_lchown

Signed-off-by: RAJAT SINGH <rajasing@redhat.com>
This commit is contained in:
RAJAT SINGH 2021-05-04 22:33:28 +05:30 committed by mergify[bot]
parent d37951f7cd
commit 290fbb6ed1
2 changed files with 38 additions and 0 deletions

View File

@ -29,3 +29,12 @@ func (mount *MountInfo) Chown(path string, user uint32, group uint32) error {
ret := C.ceph_chown(mount.mount, cPath, C.int(user), C.int(group)) ret := C.ceph_chown(mount.mount, cPath, C.int(user), C.int(group))
return getError(ret) return getError(ret)
} }
// Lchown changes the ownership of a file/directory/etc without following symbolic links
func (mount *MountInfo) Lchown(path string, user uint32, group uint32) error {
cPath := C.CString(path)
defer C.free(unsafe.Pointer(cPath))
ret := C.ceph_lchown(mount.mount, cPath, C.int(user), C.int(group))
return getError(ret)
}

View File

@ -64,3 +64,32 @@ func TestChown(t *testing.T) {
assert.Equal(t, uint32(sx.Uid), bob) assert.Equal(t, uint32(sx.Uid), bob)
assert.Equal(t, uint32(sx.Gid), bob) assert.Equal(t, uint32(sx.Gid), bob)
} }
func TestLchown(t *testing.T) {
dirname := "four"
var bob uint32 = 1010
var root uint32
mount := fsConnect(t)
defer fsDisconnect(t, mount)
err := mount.MakeDir(dirname, 0755)
assert.NoError(t, err)
defer mount.RemoveDir(dirname)
err = mount.SyncFs()
assert.NoError(t, err)
err = mount.Symlink(dirname, "symlnk")
assert.NoError(t, err)
defer mount.Unlink("symlnk")
err = mount.Lchown("symlnk", bob, bob)
sx, err := mount.Statx("symlnk", StatxBasicStats, AtSymlinkNofollow)
assert.NoError(t, err)
assert.Equal(t, uint32(sx.Uid), bob)
assert.Equal(t, uint32(sx.Gid), bob)
sx, err = mount.Statx(dirname, StatxBasicStats, AtSymlinkNofollow)
assert.Equal(t, uint32(sx.Uid), root)
assert.Equal(t, uint32(sx.Gid), root)
}