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
>
36 %include
"typemaps.i";
38 %apply long
{ off_t
};
40 %rename
(uafs_ParseArgs
) swig_uafs_ParseArgs
;
42 /* SWIG doesn't handle argv-like string arrays too well
, so instead have
43 * a wrapper to convert a single string of all arguments into an argv-like
44 * array. Conveniently
, libcmd can do this.
46 * We could instead do this with SWIG typemaps
, but writing this little
47 * function instead is much more language-neutral. With typemaps
, we'd have
48 * to write the converting code for each target language.
51 swig_uafs_ParseArgs
(char
*line
)
57 code
= cmd_ParseLine
(line
, argv
, &argc, sizeof(argv)/sizeof(argv[0]));
59 afs_com_err
("AFS::ukernel", code
, "parsing line: '%s'", line
);
63 code
= uafs_ParseArgs
(argc
, argv
);
70 extern int uafs_Setup
(const char
*mount
);
71 extern int uafs_Run
(void
);
74 * Define typemaps for binary read buffers. SWIG natively handles
75 * NUL-terminated strings
, but uafs_read could have NULs in the middle of the
76 * string
, so we need these typemaps to pay attention to the string length.
78 * (Reading in a binary buffer from e.g. uafs_write is already handled natively
79 * by SWIG. Fancy that.
)
82 %typemap
(in
, numinputs
=1) (char
*READBUF
, int
LENGTH) {
84 SWIG_croak
("expected an integer");
89 %typemap
(argout
, numinputs
=1) char
*READBUF
{
90 /* some logic here copied from typemaps.i and
/or SWIG itself
, since I'm not
97 /* 'result' is the return value from the actual C function call
; we assume
98 * it is an int that represents how many bytes of data were actually read into
99 * the buffer if nonnegative
*/
101 $result
= &PL_sv_undef;
103 $result
= sv_2mortal
(newSVpvn
($
1, result
));
110 # error No READBUF typemap defined for the given language
113 extern int uafs_mkdir
(char
*path
, int mode
);
114 extern int uafs_chdir
(char
*path
);
115 extern int uafs_open
(char
*path
, int flags
, int mode
=0);
116 extern int uafs_creat
(char
*path
, int mode
);
117 extern int uafs_write
(int fd
, char
*STRING, int
LENGTH);
118 extern int uafs_pwrite
(int fd
, char
*STRING, int
LENGTH, off_t offset
);
119 extern int uafs_read
(int fd
, char
*READBUF
, int
LENGTH);
120 extern int uafs_pread
(int fd
, char
*READBUF
, int
LENGTH, off_t offset
);
121 extern int uafs_fsync
(int fd
);
122 extern int uafs_close
(int fd
);
125 #define STAT_TYPE long
138 STAT_TYPE
*ablksize
, \
141 #define STAT_COPYFROM
(st
) do
{ \
142 *adev
= (st
).st_dev
; \
143 *aino
= (st
).st_ino
; \
144 *amode
= (st
).st_mode
; \
145 *anlink
= (st
).st_nlink
; \
146 *auid
= (st
).st_uid
; \
147 *agid
= (st
).st_gid
; \
148 *ardev
= (st
).st_rdev
; \
149 *asize
= (st
).st_size
; \
150 *aatime
= (st
).st_atime
; \
151 *amtime
= (st
).st_mtime
; \
152 *actime
= (st
).st_ctime
; \
153 *ablksize
= (st
).st_blksize
; \
154 *ablocks
= (st
).st_blocks
; \
158 swig_uafs_stat
(char
*path
, STAT_ARGS
)
162 code
= uafs_stat
(path
, &st);
169 swig_uafs_lstat
(char
*path
, STAT_ARGS
)
173 code
= uafs_lstat
(path
, &st);
180 swig_uafs_fstat
(int fd
, STAT_ARGS
)
184 code
= uafs_fstat
(fd
, &st);
199 %define STAT_OUT_ARGS
215 %rename
(uafs_stat
) swig_uafs_stat
;
216 %rename
(uafs_lstat
) swig_uafs_lstat
;
217 %rename
(uafs_fstat
) swig_uafs_fstat
;
219 extern int swig_uafs_stat
(char
*path
, STAT_OUT_ARGS
);
220 extern int swig_uafs_lstat
(char
*path
, STAT_OUT_ARGS
);
221 extern int swig_uafs_fstat
(int fd
, STAT_OUT_ARGS
);
223 extern int uafs_truncate
(char
*path
, int len
);
224 extern int uafs_ftruncate
(int fd
, int len
);
225 extern int uafs_lseek
(int fd
, int offset
, int whence
);
226 extern int uafs_chmod
(char
*path
, int mode
);
227 extern int uafs_fchmod
(int fd
, int mode
);
228 extern int uafs_symlink
(char
*target
, char
*source
);
229 extern int uafs_unlink
(char
*path
);
230 extern int uafs_rmdir
(char
*path
);
231 extern int uafs_readlink
(char
*path
, char
*READBUF
, int
LENGTH);
232 extern int uafs_link
(char
*existing
, char
*new
);
233 extern int uafs_rename
(char
*old
, char
*new
);
235 extern usr_DIR
*uafs_opendir
(char
*path
);
237 %rename
(uafs_readdir
) swig_uafs_readdir
;
240 * Language-neutral wrapper for uafs_readdir. Since the language won't know
241 * what to do with a struct usr_dirent
, we could either make a SWIG typemap
, or
242 * define a wrapper with multiple return arguments. Making a typemap is
243 * language-specific
, so we define a wrapper
, and let the typemaps.i library
244 * worry about the language-specific parts of getting multiple return values.
247 swig_uafs_readdir
(usr_DIR
*dirp
, unsigned long
*d_ino
, unsigned long
*d_off
, unsigned short
*d_reclen
)
249 struct usr_dirent
*dentry
;
251 dentry
= uafs_readdir
(dirp
);
253 *d_ino
= *d_off
= *d_reclen
= 0;
257 *d_ino
= dentry-
>d_ino
;
258 *d_off
= dentry-
>d_off
;
259 *d_reclen
= dentry-
>d_reclen
;
261 return strdup
(dentry-
>d_name
);
265 extern char
* swig_uafs_readdir
(usr_DIR
*dirp
, unsigned long
*OUTPUT, unsigned long
*OUTPUT, unsigned short
*OUTPUT);
266 extern int uafs_closedir
(usr_DIR
* dirp
);
267 extern void uafs_SetRxPort
(int
);
268 extern void uafs_Shutdown
(void
);