From 4991e72186e64152ea32286a8e2e73ebf651f30f Mon Sep 17 00:00:00 2001 From: Michael Hanselmann Date: Fri, 27 Jul 2018 17:00:27 +0200 Subject: Support mknod API Gluster supports the mknod(2) API to create special files such as character and block devices. Add it to the "gfapi.Volume" class. Change-Id: Ie62245441997111b0cf6e44b2a14a1ad7b6d7d56 Signed-off-by: Michael Hanselmann --- gluster/gfapi/api.py | 6 ++++++ gluster/gfapi/gfapi.py | 17 +++++++++++++++++ 2 files changed, 23 insertions(+) (limited to 'gluster/gfapi') diff --git a/gluster/gfapi/api.py b/gluster/gfapi/api.py index 971e98c..e4f0b14 100644 --- a/gluster/gfapi/api.py +++ b/gluster/gfapi/api.py @@ -515,3 +515,9 @@ glfs_get_volumeid = gfapi_prototype('glfs_get_volumeid', ctypes.c_int, ctypes.c_void_p, ctypes.c_char_p, ctypes.c_size_t) + +glfs_mknod = gfapi_prototype('glfs_mknod', ctypes.c_int, + ctypes.c_void_p, + ctypes.c_char_p, + ctypes.c_uint32, + ctypes.c_uint32) diff --git a/gluster/gfapi/gfapi.py b/gluster/gfapi/gfapi.py index 5078c00..ee1fd36 100644 --- a/gluster/gfapi/gfapi.py +++ b/gluster/gfapi/gfapi.py @@ -1823,3 +1823,20 @@ class Volume(object): if errors: raise Error(errors) + + @validate_mount + def mknod(self, path, mode, dev): + """ + Create special or ordinary file; see mknod(2) for more details. + + :param path: Path of file to be created. + :param mode: Operation to be performed on the given range + :param dev: Major and minor numbers for newly created device special + file; use os.makedev to build value. Ignored for other + types. + :raises: OSError on failure + """ + ret = api.glfs_mknod(self.fs, decode_to_bytes(path), mode, dev) + if ret < 0: + err = ctypes.get_errno() + raise OSError(err, os.strerror(err)) -- cgit