Initial import
[samba] / examples / libsmbclient / smbwrapper / wrapper.h
1 /* 
2    Unix SMB/Netbios implementation.
3    Version 2.0
4    SMB wrapper functions
5    Copyright (C) Derrell Lipman 2003-2005
6    
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
11    
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16    
17    You should have received a copy of the GNU General Public License
18    along with this program; if not, write to the Free Software
19    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22 #ifndef __WRAPPER_H__
23 #define __WRAPPER_H__
24
25 #include <sys/stat.h>
26 #include <sys/select.h>
27 #include <sys/time.h>
28 #include <sys/types.h>
29 #include <unistd.h>
30 #include <dirent.h>
31 #include <utime.h>
32 #include <signal.h>
33 #include <stdio.h>
34
35 #ifndef __FD_SETSIZE
36 #  define __FD_SETSIZE  256
37 #endif
38
39 extern int smbw_fd_map[__FD_SETSIZE];
40 extern int smbw_ref_count[__FD_SETSIZE];
41 extern char smbw_cwd[PATH_MAX];
42 extern char smbw_prefix[];
43
44 typedef struct SMBW_stat {
45         unsigned long           s_dev;     /* device */
46         unsigned long           s_ino;     /* inode */
47         unsigned long           s_mode;    /* protection */
48         unsigned long           s_nlink;   /* number of hard links */
49         unsigned long           s_uid;     /* user ID of owner */
50         unsigned long           s_gid;     /* group ID of owner */
51         unsigned long           s_rdev;    /* device type (if inode device) */
52         unsigned long long      s_size;    /* total size, in bytes */
53         unsigned long           s_blksize; /* blocksize for filesystem I/O */
54         unsigned long           s_blocks;  /* number of blocks allocated */
55         unsigned long           s_atime;   /* time of last access */
56         unsigned long           s_mtime;   /* time of last modification */
57         unsigned long           s_ctime;   /* time of last change */
58 } SMBW_stat;
59
60 typedef struct SMBW_dirent {
61         unsigned long           d_ino;      /* inode number */
62         unsigned long long      d_off;      /* offset to the next dirent */
63         unsigned long           d_reclen;   /* length of this record */
64         unsigned long           d_type;     /* type of file */
65         char                    d_name[256]; /* filename */
66         char                    d_comment[256]; /* comment */
67 } SMBW_dirent;
68
69 struct kernel_sigaction {
70         __sighandler_t k_sa_handler;
71         unsigned long sa_flags;
72         sigset_t sa_mask;
73 };
74
75 typedef struct SMBW_libc
76 {
77         /* write() is first, to allow debugging */
78         ssize_t (* write)(int fd, void *buf, size_t count);
79         int (* open)(char *name, int flags, mode_t mode);
80         int (* _open)(char *name, int flags, mode_t mode) ;
81         int (* __open)(char *name, int flags, mode_t mode) ;
82         int (* open64)(char *name, int flags, mode_t mode);
83         int (* _open64)(char *name, int flags, mode_t mode) ;
84         int (* __open64)(char *name, int flags, mode_t mode) ;
85         ssize_t (* pread)(int fd, void *buf, size_t size, off_t ofs);
86         ssize_t (* pread64)(int fd, void *buf, size_t size, off64_t ofs);
87         ssize_t (* pwrite)(int fd, void *buf, size_t size, off_t ofs);
88         ssize_t (* pwrite64)(int fd, void *buf, size_t size, off64_t ofs);
89         int (* close)(int fd);
90         int (* __close)(int fd);
91         int (* _close)(int fd);
92         int (* fcntl)(int fd, int cmd, long arg);
93         int (* __fcntl)(int fd, int cmd, long arg);
94         int (* _fcntl)(int fd, int cmd, long arg);
95         int (* getdents)(int fd, struct dirent *dirp, unsigned int count);
96         int (* __getdents)(int fd, struct dirent *dirp, unsigned int count);
97         int (* _getdents)(int fd, struct dirent *dirp, unsigned int count);
98         int (* getdents64)(int fd, struct dirent64 *dirp, unsigned int count);
99         off_t (* lseek)(int fd, off_t offset, int whence);
100         off_t (* __lseek)(int fd, off_t offset, int whence);
101         off_t (* _lseek)(int fd, off_t offset, int whence);
102         off64_t (* lseek64)(int fd, off64_t offset, int whence);
103         off64_t (* __lseek64)(int fd, off64_t offset, int whence);
104         off64_t (* _lseek64)(int fd, off64_t offset, int whence);
105         ssize_t (* read)(int fd, void *buf, size_t count);
106         ssize_t (* __read)(int fd, void *buf, size_t count);
107         ssize_t (* _read)(int fd, void *buf, size_t count);
108         ssize_t (* __write)(int fd, void *buf, size_t count);
109         ssize_t (* _write)(int fd, void *buf, size_t count);
110         int (* access)(char *name, int mode);
111         int (* chmod)(char *name, mode_t mode);
112         int (* fchmod)(int fd, mode_t mode);
113         int (* chown)(char *name, uid_t owner, gid_t group);
114         int (* fchown)(int fd, uid_t owner, gid_t group);
115         int (* __xstat)(int vers, char *name, struct stat *st);
116         char * ( *getcwd)(char *buf, size_t size);
117         int (* mkdir)(char *name, mode_t mode);
118         int (* __fxstat)(int vers, int fd, struct stat *st);
119         int (* __lxstat)(int vers, char *name, struct stat *st);
120         int (* stat)(char *name, struct stat *st);
121         int (* lstat)(char *name, struct stat *st);
122         int (* fstat)(int fd, struct stat *st);
123         int (* unlink)(char *name);
124         int (* utime)(char *name, struct utimbuf *tvp);
125         int (* utimes)(char *name, struct timeval *tvp);
126         int (* readlink)(char *path, char *buf, size_t bufsize);
127         int (* rename)(char *oldname, char *newname);
128         int (* rmdir)(char *name);
129         int (* symlink)(char *topath, char *frompath);
130         int (* dup)(int fd);
131         int (* dup2)(int oldfd, int newfd);
132         DIR * (* opendir)(char *name);
133         struct dirent * (* readdir)(DIR *dir);
134         int (* closedir)(DIR *dir);
135         off_t (* telldir)(DIR *dir);
136         void (* seekdir)(DIR *dir, off_t offset);
137         int (* creat)(char *path, mode_t mode);
138         int (* creat64)(char *path, mode_t mode);
139         int (* __xstat64)(int ver, char *name, struct stat64 *st64);
140         int (* stat64)(char *name, struct stat64 *st64);
141         int (* __fxstat64)(int ver, int fd, struct stat64 *st64);
142         int (* fstat64)(int fd, struct stat64 *st64);
143         int (* __lxstat64)(int ver, char *name, struct stat64 *st64);
144         int (* lstat64)(char *name, struct stat64 *st64);
145         int (* _llseek)(unsigned int fd,  unsigned  long  offset_high, unsigned  long  offset_low,  loff_t  *result, unsigned int whence);
146         struct dirent64 * (* readdir64)(DIR *dir);
147         int (* readdir_r)(DIR *dir, struct dirent *entry, struct dirent **result);
148         int (* readdir64_r)(DIR *dir, struct dirent64 *entry, struct dirent64 **result);
149         int (* setxattr)(const char *fname,
150                          const char *name,
151                          const void *value,
152                          size_t size,
153                          int flags);
154         int (* lsetxattr)(const char *fname,
155                           const char *name,
156                           const void *value,
157                           size_t size,
158                           int flags);
159         int (* fsetxattr)(int smbw_fd,
160                           const char *name,
161                           const void *value,
162                           size_t size,
163                           int flags);
164         int (* getxattr)(const char *fname,
165                          const char *name,
166                          const void *value,
167                          size_t size);
168         int (* lgetxattr)(const char *fname,
169                           const char *name,
170                           const void *value,
171                           size_t size);
172         int (* fgetxattr)(int smbw_fd,
173                           const char *name,
174                           const void *value,
175                           size_t size);
176         int (* removexattr)(const char *fname,
177                             const char *name);
178         int (* lremovexattr)(const char *fname,
179                              const char *name);
180         int (* fremovexattr)(int smbw_fd,
181                              const char *name);
182         int (* listxattr)(const char *fname,
183                           char *list,
184                           size_t size);
185         int (* llistxattr)(const char *fname,
186                            char *list,
187                            size_t size);
188         int (* flistxattr)(int smbw_fd,
189                            char *list,
190                            size_t size);
191         int (* chdir)(const char *path);
192         int (* fchdir)(int fd);
193         pid_t (* fork)(void);
194         int (* select)(int n,
195                        fd_set *readfds,
196                        fd_set *writefds,
197                        fd_set *exceptfds,
198                        struct timeval *timeout);
199         int (* _select)(int n,
200                         fd_set *readfds,
201                         fd_set *writefds,
202                         fd_set *exceptfds,
203                         struct timeval *timeout);
204         int (* __select)(int n,
205                          fd_set *readfds,
206                          fd_set *writefds,
207                          fd_set *exceptfds,
208                          struct timeval *timeout);
209 } SMBW_libc_pointers;
210
211 extern SMBW_libc_pointers smbw_libc;
212
213 #endif /* __WRAPPER_H__ */