2 * Copyright 2010, Sine Nomine Associates.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
11 * libuafs SWIG interface file
13 * This file specifies the libuafs interfaces for SWIG, which can then be
14 * used to easily create libuafs bindings to other languages such as Perl.
16 * For each language you want a binding for, there are two typemaps you
17 * must define for that language, since SWIG does not handle them natively.
18 * These are the 'in' typemap for READBUF and LENGTH, and the 'argout'
19 * typemap for READBUF. Search this file for 'SWIGPERL' to see existing ones
20 * for the Perl bindings.
23 %module "AFS::ukernel"
26 #include <afsconfig.h>
27 #include <afs/param.h>
29 #include <afs/afsutil.h>
30 #include <afs/sysincludes.h>
31 #include <afs_usrops.h>
33 #include <afs/afs_args.h>
34 #include <afs/com_err.h>
37 %include "typemaps.i";
39 %apply long { off_t };
41 %rename (uafs_ParseArgs) swig_uafs_ParseArgs;
43 /* SWIG doesn't handle argv-like string arrays too well, so instead have
44 * a wrapper to convert a single string of all arguments into an argv-like
45 * array. Conveniently, libcmd can do this.
47 * We could instead do this with SWIG typemaps, but writing this little
48 * function instead is much more language-neutral. With typemaps, we'd have
49 * to write the converting code for each target language.
52 swig_uafs_ParseArgs(char *line)
58 code = cmd_ParseLine(line, argv, &argc, sizeof(argv)/sizeof(argv[0]));
60 afs_com_err("AFS::ukernel", code, "parsing line: '%s'", line);
64 code = uafs_ParseArgs(argc, argv);
71 extern int uafs_Setup(const char *mount);
72 extern int uafs_Run(void);
75 * Define typemaps for binary read buffers. SWIG natively handles
76 * NUL-terminated strings, but uafs_read could have NULs in the middle of the
77 * string, so we need these typemaps to pay attention to the string length.
79 * (Reading in a binary buffer from e.g. uafs_write is already handled natively
80 * by SWIG. Fancy that.)
83 %typemap(in, numinputs=1) (char *READBUF, int LENGTH) {
85 SWIG_croak("expected an integer");
90 %typemap(argout, numinputs=1) char *READBUF {
91 /* some logic here copied from typemaps.i and/or SWIG itself, since I'm not
98 /* 'result' is the return value from the actual C function call; we assume
99 * it is an int that represents how many bytes of data were actually read into
100 * the buffer if nonnegative */
102 $result = &PL_sv_undef;
104 $result = sv_2mortal(newSVpvn($1, result));
111 # error No READBUF typemap defined for the given language
114 extern int uafs_mkdir(char *path, int mode);
115 extern int uafs_chdir(char *path);
116 extern int uafs_open(char *path, int flags, int mode=0);
117 extern int uafs_creat(char *path, int mode);
118 extern int uafs_write(int fd, char *STRING, int LENGTH);
119 extern int uafs_pwrite(int fd, char *STRING, int LENGTH, off_t offset);
120 extern int uafs_read(int fd, char *READBUF, int LENGTH);
121 extern int uafs_pread(int fd, char *READBUF, int LENGTH, off_t offset);
122 extern int uafs_fsync(int fd);
123 extern int uafs_close(int fd);
126 #define STAT_TYPE long
139 STAT_TYPE *ablksize, \
142 #define STAT_COPYFROM(st) do { \
143 *adev = (st).st_dev; \
144 *aino = (st).st_ino; \
145 *amode = (st).st_mode; \
146 *anlink = (st).st_nlink; \
147 *auid = (st).st_uid; \
148 *agid = (st).st_gid; \
149 *ardev = (st).st_rdev; \
150 *asize = (st).st_size; \
151 *aatime = (st).st_atime; \
152 *amtime = (st).st_mtime; \
153 *actime = (st).st_ctime; \
154 *ablksize = (st).st_blksize; \
155 *ablocks = (st).st_blocks; \
159 swig_uafs_stat(char *path, STAT_ARGS)
163 code = uafs_stat(path, &st);
170 swig_uafs_lstat(char *path, STAT_ARGS)
174 code = uafs_lstat(path, &st);
181 swig_uafs_fstat(int fd, STAT_ARGS)
185 code = uafs_fstat(fd, &st);
200 %define STAT_OUT_ARGS
216 %rename (uafs_stat) swig_uafs_stat;
217 %rename (uafs_lstat) swig_uafs_lstat;
218 %rename (uafs_fstat) swig_uafs_fstat;
220 extern int swig_uafs_stat(char *path, STAT_OUT_ARGS);
221 extern int swig_uafs_lstat(char *path, STAT_OUT_ARGS);
222 extern int swig_uafs_fstat(int fd, STAT_OUT_ARGS);
224 extern int uafs_truncate(char *path, int len);
225 extern int uafs_ftruncate(int fd, int len);
226 extern int uafs_lseek(int fd, int offset, int whence);
227 extern int uafs_chmod(char *path, int mode);
228 extern int uafs_fchmod(int fd, int mode);
229 extern int uafs_symlink(char *target, char *source);
230 extern int uafs_unlink(char *path);
231 extern int uafs_rmdir(char *path);
232 extern int uafs_readlink(char *path, char *READBUF, int LENGTH);
233 extern int uafs_link(char *existing, char *new);
234 extern int uafs_rename(char *old, char *new);
236 extern usr_DIR *uafs_opendir(char *path);
238 %rename (uafs_readdir) swig_uafs_readdir;
241 * Language-neutral wrapper for uafs_readdir. Since the language won't know
242 * what to do with a struct usr_dirent, we could either make a SWIG typemap, or
243 * define a wrapper with multiple return arguments. Making a typemap is
244 * language-specific, so we define a wrapper, and let the typemaps.i library
245 * worry about the language-specific parts of getting multiple return values.
248 swig_uafs_readdir(usr_DIR *dirp, unsigned long *d_ino, unsigned long *d_off, unsigned short *d_reclen)
250 struct usr_dirent *dentry;
252 dentry = uafs_readdir(dirp);
254 *d_ino = *d_off = *d_reclen = 0;
258 *d_ino = dentry->d_ino;
259 *d_off = dentry->d_off;
260 *d_reclen = dentry->d_reclen;
262 return strdup(dentry->d_name);
266 extern char * swig_uafs_readdir(usr_DIR *dirp, unsigned long *OUTPUT, unsigned long *OUTPUT, unsigned short *OUTPUT);
267 extern int uafs_closedir(usr_DIR * dirp);
268 extern void uafs_SetRxPort(int);
269 extern void uafs_Shutdown(void);