[27520] in Source-Commits
python-afs commit: Redefine pioctl_write(); avoid namespace conflict
daemon@ATHENA.MIT.EDU (Jonathan D Reed)
Tue Nov 12 18:27:54 2013
Date: Tue, 12 Nov 2013 18:27:47 -0500
From: Jonathan D Reed <jdreed@MIT.EDU>
Message-Id: <201311122327.rACNRlV1018604@drugstore.mit.edu>
To: source-commits@MIT.EDU
https://github.com/mit-athena/python-afs/commits/fbe098de9b7fbc4c15617ba2d5cb879bfc3e4d85
commit fbe098de9b7fbc4c15617ba2d5cb879bfc3e4d85
Author: Jonathan Reed <jdreed@mit.edu>
Date: Tue Oct 29 13:55:37 2013 -0400
Redefine pioctl_write(); avoid namespace conflict
- Change the definition of pioctl_write to take an extra void *
into which data can be written. Some pioctls return data
(e.g. VIOC_AFS_STAT_MT_PT), others don't (like VIOCSETAL).
For those that don't, pass NULL for the new argument.
- Update the call to pioctl_write in _acl.pyx to support
the new function signature.
- Import AFS_PIOCTL_MAXSIZE from afs_consts.h
- Add some comments
- Change "buffer" to "inbuffer" in pioctl_read() to avoid conflicting
with the Python type of that name.
- Change "dir" to "path" in both pioctl_read() and pioctl_write() to
avoid conflicting with the Python function of that name.
These last two changes are not strictly speaking necessary, but they
help avoid confusing error messages when you make typos.
afs/_acl.pyx | 2 +-
afs/_util.pxd | 8 +++++++-
afs/_util.pyx | 28 ++++++++++++++++++++--------
3 files changed, 28 insertions(+), 10 deletions(-)
diff --git a/afs/_acl.pyx b/afs/_acl.pyx
index bf1b1f9..a57bd07 100644
--- a/afs/_acl.pyx
+++ b/afs/_acl.pyx
@@ -45,4 +45,4 @@ def getCallerAccess(char *dir, int follow=1):
return stat.callerAccess
def setAcl(char* dir, char* acl, int follow=1):
- pioctl_write(dir, VIOCSETAL, acl, follow)
+ pioctl_write(dir, VIOCSETAL, acl, NULL, follow)
diff --git a/afs/_util.pxd b/afs/_util.pxd
index aacba3b..22f991e 100644
--- a/afs/_util.pxd
+++ b/afs/_util.pxd
@@ -24,6 +24,8 @@ cdef extern from "netinet/in.h":
in_addr sin_addr
char sin_zero[8]
+# Note that even on 64-bit platforms, Pyrex/Cython's long is 4 bytes,
+# and unsigned long is 8, so this works.
cdef extern from "afs/stds.h":
ctypedef unsigned long afs_uint32
ctypedef long afs_int32
@@ -31,6 +33,10 @@ cdef extern from "afs/stds.h":
cdef extern from "afs/dirpath.h":
char * AFSDIR_CLIENT_ETC_DIRPATH
+cdef extern from "afs/afs_consts.h":
+ enum:
+ AFS_PIOCTL_MAXSIZE
+
cdef extern from "afs/cellconfig.h":
enum:
MAXCELLCHARS
@@ -163,5 +169,5 @@ cdef extern from "afs/venus.h":
# pioctl doesn't actually have a header, so we have to define it here
cdef extern int pioctl(char *, afs_int32, ViceIoctl *, afs_int32)
cdef int pioctl_read(char *, afs_int32, void *, unsigned short, afs_int32) except -1
-cdef int pioctl_write(char *, afs_int32, char *, afs_int32) except -1
+cdef int pioctl_write(char *, afs_int32, char *, void *, afs_int32) except -1
diff --git a/afs/_util.pyx b/afs/_util.pyx
index 932bdf0..8ddd721 100644
--- a/afs/_util.pyx
+++ b/afs/_util.pyx
@@ -12,13 +12,16 @@ cdef int _init = 0
# pioctl convenience wrappers
-cdef extern int pioctl_read(char *dir, afs_int32 op, void *buffer, unsigned short size, afs_int32 follow) except -1:
+# Function for "reading" data from a pioctl
+# "outbuffer" will get populated with the data in question
+cdef extern int pioctl_read(char *path, afs_int32 op, void *outbuffer,
+ unsigned short size, afs_int32 follow) except -1:
cdef ViceIoctl blob
cdef afs_int32 code
blob.in_size = 0
blob.out_size = size
- blob.out = buffer
- code = pioctl(dir, op, &blob, follow)
+ blob.out = outbuffer
+ code = pioctl(path, op, &blob, follow)
# This might work with the rest of OpenAFS, but I'm not convinced
# the rest of it is consistent
if code == -1:
@@ -26,13 +29,22 @@ cdef extern int pioctl_read(char *dir, afs_int32 op, void *buffer, unsigned shor
pyafs_error(code)
return code
-cdef extern int pioctl_write(char *dir, afs_int32 op, char *buffer, afs_int32 follow) except -1:
+# Function for "writing" data to a pioctl
+# "outbuffer" will get populated with the data in question
+# Pass NULL for outbuffer in cases where we don't get anything
+# back (e.g. VIOCSETAL)
+cdef extern int pioctl_write(char *path, afs_int32 op, char *inbuffer,
+ void *outbuffer, afs_int32 follow) except -1:
cdef ViceIoctl blob
cdef afs_int32 code
- blob.cin = buffer
- blob.in_size = 1 + strlen(buffer)
- blob.out_size = 0
- code = pioctl(dir, op, &blob, follow)
+ blob.cin = inbuffer
+ blob.in_size = 1 + strlen(inbuffer)
+ if outbuffer == NULL:
+ blob.out_size = 0
+ else:
+ blob.out_size = AFS_PIOCTL_MAXSIZE
+ blob.out = outbuffer
+ code = pioctl(path, op, &blob, follow)
# This might work with the rest of OpenAFS, but I'm not convinced
# the rest of it is consistent
if code == -1: