summaryrefslogtreecommitdiffstats
path: root/glusterfs
diff options
context:
space:
mode:
Diffstat (limited to 'glusterfs')
-rwxr-xr-xglusterfs/api.py9
-rwxr-xr-xglusterfs/gfapi.py46
2 files changed, 53 insertions, 2 deletions
diff --git a/glusterfs/api.py b/glusterfs/api.py
index 037c893..7848448 100755
--- a/glusterfs/api.py
+++ b/glusterfs/api.py
@@ -126,6 +126,15 @@ glfs_stat = ctypes.CFUNCTYPE(ctypes.c_int, ctypes.c_void_p, ctypes.c_char_p,
glfs_fstat = ctypes.CFUNCTYPE(ctypes.c_int, ctypes.c_void_p, ctypes.POINTER(
Stat))(('glfs_fstat', client))
+glfs_chmod = ctypes.CFUNCTYPE(ctypes.c_int,
+ ctypes.c_void_p,
+ ctypes.c_char_p,
+ ctypes.c_ushort)(('glfs_chmod', client))
+
+glfs_fchmod = ctypes.CFUNCTYPE(ctypes.c_int,
+ ctypes.c_void_p,
+ ctypes.c_ushort)(('glfs_fchmod', client))
+
glfs_chown = ctypes.CFUNCTYPE(ctypes.c_int,
ctypes.c_void_p,
ctypes.c_char_p,
diff --git a/glusterfs/gfapi.py b/glusterfs/gfapi.py
index 16929df..42c4aef 100755
--- a/glusterfs/gfapi.py
+++ b/glusterfs/gfapi.py
@@ -65,6 +65,19 @@ class File(object):
raise OSError(err, os.strerror(err))
return ret
+ def fchmod(self, mode):
+ """
+ Change this file's mode
+
+ :param mode: new mode
+ :returns: 0 if success, raises OSError if it fails
+ """
+ ret = api.glfs_fchmod(self.fd, mode)
+ if ret < 0:
+ err = ctypes.get_errno()
+ raise OSError(err, os.strerror(err))
+ return ret
+
def fchown(self, uid, gid):
"""
Change this file's owner and group id
@@ -91,6 +104,12 @@ class File(object):
raise OSError(err, os.strerror(err))
return ret
+ def fgetsize(self):
+ """
+ Return the size of a file, reported by fstat()
+ """
+ return self.fstat().st_size
+
def fstat(self):
"""
Returns Stat object for this file.
@@ -124,9 +143,18 @@ class File(object):
"""
return api.glfs_lseek(self.fd, pos, how)
- def read(self, buflen, flags=0):
+ def read(self, buflen=-1):
+ """
+ read file
+
+ :param buflen: length of read buffer. If less than 0, then whole
+ file is read. Default is -1.
+ :returns: buffer of size buflen
+ """
+ if buflen < 0:
+ buflen = self.fgetsize()
rbuf = ctypes.create_string_buffer(buflen)
- ret = api.glfs_read(self.fd, rbuf, buflen, flags)
+ ret = api.glfs_read(self.fd, rbuf, buflen, 0)
if ret > 0:
return rbuf
elif ret < 0:
@@ -194,6 +222,20 @@ class Volume(object):
def mount(self):
return api.glfs_init(self.fs)
+ def chmod(self, path, mode):
+ """
+ Change mode of path
+
+ :param path: the item to be modified
+ :mode: new mode
+ :returns: 0 if success, raises OSError if it fails
+ """
+ ret = api.glfs_chmod(self.fs, path, mode)
+ if ret < 0:
+ err = ctypes.get_errno()
+ raise OSError(err, os.strerror(err))
+ return ret
+
def chown(self, path, uid, gid):
"""
Change owner and group id of path