X-Git-Url: http://xvm.mit.edu/gitweb/invirt/packages/python-afs.git/blobdiff_plain/08f6a8aabbbcd153085773683b29e6796b3b9767..09b4d45674f9d37d44c68f52c9a965b14b7e336f:/afs/afs.pyx diff --git a/afs/afs.pyx b/afs/afs.pyx index 8f51c16..4fe9e1c 100644 --- a/afs/afs.pyx +++ b/afs/afs.pyx @@ -4,8 +4,44 @@ General PyAFS utilities, such as error handling import sys +# otherwise certain headers are unhappy +cdef import from "netinet/in.h": pass +cdef import from "afs/vice.h": pass + 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: + cdef ViceIoctl blob + cdef afs_int32 code + blob.in_size = 0 + blob.out_size = size + blob.out = buffer + code = pioctl(dir, 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: + raise OSError(errno, strerror(errno)) + pyafs_error(code) + return code + +cdef extern int pioctl_write(char *dir, afs_int32 op, char *buffer, 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) + # This might work with the rest of OpenAFS, but I'm not convinced + # the rest of it is consistent + if code == -1: + raise OSError(errno, strerror(errno)) + pyafs_error(code) + return code + +# Error handling + class AFSException(Exception): def __init__(self, errno): self.errno = errno