2 Unix SMB/CIFS implementation.
4 Copyright (C) Andrew Tridgell 1992-1998
5 Copyright (C) Jeremy Allison 1998-2005
6 Copyright (C) Timur Bakeyev 2005
7 Copyright (C) Bjoern Jacke 2006-2007
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #include "system/syslog.h"
25 #include "system/capability.h"
26 #include "system/passwd.h"
27 #include "system/filesys.h"
28 #include "lib/uid_wrapper/uid_wrapper.h"
30 #ifdef HAVE_SYS_PRCTL_H
31 #include <sys/prctl.h>
35 The idea is that this file will eventually have wrappers around all
36 important system calls in samba. The aims are:
38 - to enable easier porting by putting OS dependent stuff in here
40 - to allow for hooks into other "pseudo-filesystems"
42 - to allow easier integration of things like the japanese extensions
44 - to support the philosophy of Samba to expose the features of
45 the OS within the SMB model. In general whatever file/printer/variable
46 expansions/etc make sense to the OS should be acceptable to Samba.
51 /*******************************************************************
52 A wrapper for usleep in case we don't have one.
53 ********************************************************************/
55 int sys_usleep(long usecs)
62 * We need this braindamage as the glibc usleep
63 * is not SPEC1170 complient... grumble... JRA.
66 if(usecs < 0 || usecs > 999999) {
74 #else /* HAVE_USLEEP */
76 * Fake it with select...
79 tval.tv_usec = usecs/1000;
80 select(0,NULL,NULL,NULL,&tval);
82 #endif /* HAVE_USLEEP */
85 /*******************************************************************
86 A read wrapper that will deal with EINTR.
87 ********************************************************************/
89 ssize_t sys_read(int fd, void *buf, size_t count)
94 ret = read(fd, buf, count);
95 #if defined(EWOULDBLOCK)
96 } while (ret == -1 && (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK));
98 } while (ret == -1 && (errno == EINTR || errno == EAGAIN));
103 /*******************************************************************
104 A write wrapper that will deal with EINTR.
105 ********************************************************************/
107 ssize_t sys_write(int fd, const void *buf, size_t count)
112 ret = write(fd, buf, count);
113 #if defined(EWOULDBLOCK)
114 } while (ret == -1 && (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK));
116 } while (ret == -1 && (errno == EINTR || errno == EAGAIN));
121 /*******************************************************************
122 A writev wrapper that will deal with EINTR.
123 ********************************************************************/
125 ssize_t sys_writev(int fd, const struct iovec *iov, int iovcnt)
130 /* Try to confuse write_data_iov a bit */
131 if ((random() % 5) == 0) {
132 return sys_write(fd, iov[0].iov_base, iov[0].iov_len);
134 if (iov[0].iov_len > 1) {
135 return sys_write(fd, iov[0].iov_base,
136 (random() % (iov[0].iov_len-1)) + 1);
141 ret = writev(fd, iov, iovcnt);
142 #if defined(EWOULDBLOCK)
143 } while (ret == -1 && (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK));
145 } while (ret == -1 && (errno == EINTR || errno == EAGAIN));
150 /*******************************************************************
151 A pread wrapper that will deal with EINTR and 64-bit file offsets.
152 ********************************************************************/
154 #if defined(HAVE_PREAD) || defined(HAVE_PREAD64)
155 ssize_t sys_pread(int fd, void *buf, size_t count, SMB_OFF_T off)
160 #if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_OFF64_T) && defined(HAVE_PREAD64)
161 ret = pread64(fd, buf, count, off);
163 ret = pread(fd, buf, count, off);
165 } while (ret == -1 && errno == EINTR);
170 /*******************************************************************
171 A write wrapper that will deal with EINTR and 64-bit file offsets.
172 ********************************************************************/
174 #if defined(HAVE_PWRITE) || defined(HAVE_PWRITE64)
175 ssize_t sys_pwrite(int fd, const void *buf, size_t count, SMB_OFF_T off)
180 #if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_OFF64_T) && defined(HAVE_PWRITE64)
181 ret = pwrite64(fd, buf, count, off);
183 ret = pwrite(fd, buf, count, off);
185 } while (ret == -1 && errno == EINTR);
190 /*******************************************************************
191 A send wrapper that will deal with EINTR or EAGAIN or EWOULDBLOCK.
192 ********************************************************************/
194 ssize_t sys_send(int s, const void *msg, size_t len, int flags)
199 ret = send(s, msg, len, flags);
200 #if defined(EWOULDBLOCK)
201 } while (ret == -1 && (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK));
203 } while (ret == -1 && (errno == EINTR || errno == EAGAIN));
208 /*******************************************************************
209 A sendto wrapper that will deal with EINTR or EAGAIN or EWOULDBLOCK.
210 ********************************************************************/
212 ssize_t sys_sendto(int s, const void *msg, size_t len, int flags, const struct sockaddr *to, socklen_t tolen)
217 ret = sendto(s, msg, len, flags, to, tolen);
218 #if defined(EWOULDBLOCK)
219 } while (ret == -1 && (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK));
221 } while (ret == -1 && (errno == EINTR || errno == EAGAIN));
226 /*******************************************************************
227 A recv wrapper that will deal with EINTR or EAGAIN or EWOULDBLOCK.
228 ********************************************************************/
230 ssize_t sys_recv(int fd, void *buf, size_t count, int flags)
235 ret = recv(fd, buf, count, flags);
236 #if defined(EWOULDBLOCK)
237 } while (ret == -1 && (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK));
239 } while (ret == -1 && (errno == EINTR || errno == EAGAIN));
244 /*******************************************************************
245 A recvfrom wrapper that will deal with EINTR.
246 ********************************************************************/
248 ssize_t sys_recvfrom(int s, void *buf, size_t len, int flags, struct sockaddr *from, socklen_t *fromlen)
253 ret = recvfrom(s, buf, len, flags, from, fromlen);
254 #if defined(EWOULDBLOCK)
255 } while (ret == -1 && (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK));
257 } while (ret == -1 && (errno == EINTR || errno == EAGAIN));
262 /*******************************************************************
263 A fcntl wrapper that will deal with EINTR.
264 ********************************************************************/
266 int sys_fcntl_ptr(int fd, int cmd, void *arg)
271 ret = fcntl(fd, cmd, arg);
272 } while (ret == -1 && errno == EINTR);
276 /*******************************************************************
277 A fcntl wrapper that will deal with EINTR.
278 ********************************************************************/
280 int sys_fcntl_long(int fd, int cmd, long arg)
285 ret = fcntl(fd, cmd, arg);
286 } while (ret == -1 && errno == EINTR);
290 /****************************************************************************
291 Get/Set all the possible time fields from a stat struct as a timespec.
292 ****************************************************************************/
294 static struct timespec get_atimespec(const struct stat *pst)
296 #if !defined(HAVE_STAT_HIRES_TIMESTAMPS)
299 /* Old system - no ns timestamp. */
300 ret.tv_sec = pst->st_atime;
304 #if defined(HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC)
306 #elif defined(HAVE_STRUCT_STAT_ST_MTIMENSEC)
308 ret.tv_sec = pst->st_atime;
309 ret.tv_nsec = pst->st_atimensec;
311 #elif defined(HAVE_STRUCT_STAT_ST_MTIME_N)
313 ret.tv_sec = pst->st_atime;
314 ret.tv_nsec = pst->st_atime_n;
316 #elif defined(HAVE_STRUCT_STAT_ST_UMTIME)
318 ret.tv_sec = pst->st_atime;
319 ret.tv_nsec = pst->st_uatime * 1000;
321 #elif defined(HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC)
322 return pst->st_atimespec;
324 #error CONFIGURE_ERROR_IN_DETECTING_TIMESPEC_IN_STAT
329 static struct timespec get_mtimespec(const struct stat *pst)
331 #if !defined(HAVE_STAT_HIRES_TIMESTAMPS)
334 /* Old system - no ns timestamp. */
335 ret.tv_sec = pst->st_mtime;
339 #if defined(HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC)
341 #elif defined(HAVE_STRUCT_STAT_ST_MTIMENSEC)
343 ret.tv_sec = pst->st_mtime;
344 ret.tv_nsec = pst->st_mtimensec;
346 #elif defined(HAVE_STRUCT_STAT_ST_MTIME_N)
348 ret.tv_sec = pst->st_mtime;
349 ret.tv_nsec = pst->st_mtime_n;
351 #elif defined(HAVE_STRUCT_STAT_ST_UMTIME)
353 ret.tv_sec = pst->st_mtime;
354 ret.tv_nsec = pst->st_umtime * 1000;
356 #elif defined(HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC)
357 return pst->st_mtimespec;
359 #error CONFIGURE_ERROR_IN_DETECTING_TIMESPEC_IN_STAT
364 static struct timespec get_ctimespec(const struct stat *pst)
366 #if !defined(HAVE_STAT_HIRES_TIMESTAMPS)
369 /* Old system - no ns timestamp. */
370 ret.tv_sec = pst->st_ctime;
374 #if defined(HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC)
376 #elif defined(HAVE_STRUCT_STAT_ST_MTIMENSEC)
378 ret.tv_sec = pst->st_ctime;
379 ret.tv_nsec = pst->st_ctimensec;
381 #elif defined(HAVE_STRUCT_STAT_ST_MTIME_N)
383 ret.tv_sec = pst->st_ctime;
384 ret.tv_nsec = pst->st_ctime_n;
386 #elif defined(HAVE_STRUCT_STAT_ST_UMTIME)
388 ret.tv_sec = pst->st_ctime;
389 ret.tv_nsec = pst->st_uctime * 1000;
391 #elif defined(HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC)
392 return pst->st_ctimespec;
394 #error CONFIGURE_ERROR_IN_DETECTING_TIMESPEC_IN_STAT
399 /****************************************************************************
400 Return the best approximation to a 'create time' under UNIX from a stat
402 ****************************************************************************/
404 static struct timespec calc_create_time_stat(const struct stat *st)
406 struct timespec ret, ret1;
407 struct timespec c_time = get_ctimespec(st);
408 struct timespec m_time = get_mtimespec(st);
409 struct timespec a_time = get_atimespec(st);
411 ret = timespec_compare(&c_time, &m_time) < 0 ? c_time : m_time;
412 ret1 = timespec_compare(&ret, &a_time) < 0 ? ret : a_time;
414 if(!null_timespec(ret1)) {
419 * One of ctime, mtime or atime was zero (probably atime).
420 * Just return MIN(ctime, mtime).
425 /****************************************************************************
426 Return the best approximation to a 'create time' under UNIX from a stat_ex
428 ****************************************************************************/
430 static struct timespec calc_create_time_stat_ex(const struct stat_ex *st)
432 struct timespec ret, ret1;
433 struct timespec c_time = st->st_ex_ctime;
434 struct timespec m_time = st->st_ex_mtime;
435 struct timespec a_time = st->st_ex_atime;
437 ret = timespec_compare(&c_time, &m_time) < 0 ? c_time : m_time;
438 ret1 = timespec_compare(&ret, &a_time) < 0 ? ret : a_time;
440 if(!null_timespec(ret1)) {
445 * One of ctime, mtime or atime was zero (probably atime).
446 * Just return MIN(ctime, mtime).
451 /****************************************************************************
452 Return the 'create time' from a stat struct if it exists (birthtime) or else
453 use the best approximation.
454 ****************************************************************************/
456 static void make_create_timespec(const struct stat *pst, struct stat_ex *dst,
457 bool fake_dir_create_times)
459 if (S_ISDIR(pst->st_mode) && fake_dir_create_times) {
460 dst->st_ex_btime.tv_sec = 315493200L; /* 1/1/1980 */
461 dst->st_ex_btime.tv_nsec = 0;
464 dst->st_ex_calculated_birthtime = false;
466 #if defined(HAVE_STRUCT_STAT_ST_BIRTHTIMESPEC_TV_NSEC)
467 dst->st_ex_btime = pst->st_birthtimespec;
468 #elif defined(HAVE_STRUCT_STAT_ST_BIRTHTIMENSEC)
469 dst->st_ex_btime.tv_sec = pst->st_birthtime;
470 dst->st_ex_btime.tv_nsec = pst->st_birthtimenspec;
471 #elif defined(HAVE_STRUCT_STAT_ST_BIRTHTIME)
472 dst->st_ex_btime.tv_sec = pst->st_birthtime;
473 dst->st_ex_btime.tv_nsec = 0;
475 dst->st_ex_btime = calc_create_time_stat(pst);
476 dst->st_ex_calculated_birthtime = true;
479 /* Deal with systems that don't initialize birthtime correctly.
480 * Pointed out by SATOH Fumiyasu <fumiyas@osstech.jp>.
482 if (null_timespec(dst->st_ex_btime)) {
483 dst->st_ex_btime = calc_create_time_stat(pst);
484 dst->st_ex_calculated_birthtime = true;
488 /****************************************************************************
489 If we update a timestamp in a stat_ex struct we may have to recalculate
490 the birthtime. For now only implement this for write time, but we may
491 also need to do it for atime and ctime. JRA.
492 ****************************************************************************/
494 void update_stat_ex_mtime(struct stat_ex *dst,
495 struct timespec write_ts)
497 dst->st_ex_mtime = write_ts;
499 /* We may have to recalculate btime. */
500 if (dst->st_ex_calculated_birthtime) {
501 dst->st_ex_btime = calc_create_time_stat_ex(dst);
505 void update_stat_ex_create_time(struct stat_ex *dst,
506 struct timespec create_time)
508 dst->st_ex_btime = create_time;
509 dst->st_ex_calculated_birthtime = false;
512 #if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_OFF64_T) && defined(HAVE_STAT64)
513 void init_stat_ex_from_stat (struct stat_ex *dst,
514 const struct stat64 *src,
515 bool fake_dir_create_times)
517 void init_stat_ex_from_stat (struct stat_ex *dst,
518 const struct stat *src,
519 bool fake_dir_create_times)
522 dst->st_ex_dev = src->st_dev;
523 dst->st_ex_ino = src->st_ino;
524 dst->st_ex_mode = src->st_mode;
525 dst->st_ex_nlink = src->st_nlink;
526 dst->st_ex_uid = src->st_uid;
527 dst->st_ex_gid = src->st_gid;
528 dst->st_ex_rdev = src->st_rdev;
529 dst->st_ex_size = src->st_size;
530 dst->st_ex_atime = get_atimespec(src);
531 dst->st_ex_mtime = get_mtimespec(src);
532 dst->st_ex_ctime = get_ctimespec(src);
533 make_create_timespec(src, dst, fake_dir_create_times);
534 #ifdef HAVE_STAT_ST_BLKSIZE
535 dst->st_ex_blksize = src->st_blksize;
537 dst->st_ex_blksize = STAT_ST_BLOCKSIZE;
540 #ifdef HAVE_STAT_ST_BLOCKS
541 dst->st_ex_blocks = src->st_blocks;
543 dst->st_ex_blocks = src->st_size / dst->st_ex_blksize + 1;
546 #ifdef HAVE_STAT_ST_FLAGS
547 dst->st_ex_flags = src->st_flags;
549 dst->st_ex_flags = 0;
553 /*******************************************************************
554 A stat() wrapper that will deal with 64 bit filesizes.
555 ********************************************************************/
557 int sys_stat(const char *fname, SMB_STRUCT_STAT *sbuf,
558 bool fake_dir_create_times)
561 #if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_OFF64_T) && defined(HAVE_STAT64)
562 struct stat64 statbuf;
563 ret = stat64(fname, &statbuf);
566 ret = stat(fname, &statbuf);
569 /* we always want directories to appear zero size */
570 if (S_ISDIR(statbuf.st_mode)) {
573 init_stat_ex_from_stat(sbuf, &statbuf, fake_dir_create_times);
578 /*******************************************************************
579 An fstat() wrapper that will deal with 64 bit filesizes.
580 ********************************************************************/
582 int sys_fstat(int fd, SMB_STRUCT_STAT *sbuf, bool fake_dir_create_times)
585 #if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_OFF64_T) && defined(HAVE_FSTAT64)
586 struct stat64 statbuf;
587 ret = fstat64(fd, &statbuf);
590 ret = fstat(fd, &statbuf);
593 /* we always want directories to appear zero size */
594 if (S_ISDIR(statbuf.st_mode)) {
597 init_stat_ex_from_stat(sbuf, &statbuf, fake_dir_create_times);
602 /*******************************************************************
603 An lstat() wrapper that will deal with 64 bit filesizes.
604 ********************************************************************/
606 int sys_lstat(const char *fname,SMB_STRUCT_STAT *sbuf,
607 bool fake_dir_create_times)
610 #if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_OFF64_T) && defined(HAVE_LSTAT64)
611 struct stat64 statbuf;
612 ret = lstat64(fname, &statbuf);
615 ret = lstat(fname, &statbuf);
618 /* we always want directories to appear zero size */
619 if (S_ISDIR(statbuf.st_mode)) {
622 init_stat_ex_from_stat(sbuf, &statbuf, fake_dir_create_times);
627 /*******************************************************************
628 An posix_fallocate() wrapper that will deal with 64 bit filesizes.
629 ********************************************************************/
630 int sys_posix_fallocate(int fd, SMB_OFF_T offset, SMB_OFF_T len)
632 #if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_OFF64_T) && defined(HAVE_POSIX_FALLOCATE64) && !defined(HAVE_BROKEN_POSIX_FALLOCATE)
633 return posix_fallocate64(fd, offset, len);
634 #elif defined(HAVE_POSIX_FALLOCATE) && !defined(HAVE_BROKEN_POSIX_FALLOCATE)
635 return posix_fallocate(fd, offset, len);
636 #elif defined(F_RESVSP64)
637 /* this handles XFS on IRIX */
639 SMB_OFF_T new_len = offset + len;
643 /* unlikely to get a too large file on a 64bit system but ... */
647 fl.l_whence = SEEK_SET;
651 ret=fcntl(fd, F_RESVSP64, &fl);
656 /* Make sure the file gets enlarged after we allocated space: */
658 if (new_len > sbuf.st_size)
659 ftruncate64(fd, new_len);
666 /*******************************************************************
667 An fallocate() function that matches the semantics of the Linux one.
668 ********************************************************************/
670 #ifdef HAVE_LINUX_FALLOC_H
671 #include <linux/falloc.h>
674 int sys_fallocate(int fd, enum vfs_fallocate_mode mode, SMB_OFF_T offset, SMB_OFF_T len)
676 #if defined(HAVE_LINUX_FALLOCATE64) || defined(HAVE_LINUX_FALLOCATE)
679 case VFS_FALLOCATE_EXTEND_SIZE:
682 case VFS_FALLOCATE_KEEP_SIZE:
683 lmode = FALLOC_FL_KEEP_SIZE;
689 #if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_OFF64_T) && defined(HAVE_LINUX_FALLOCATE64)
690 return fallocate64(fd, lmode, offset, len);
691 #elif defined(HAVE_LINUX_FALLOCATE)
692 return fallocate(fd, lmode, offset, len);
695 /* TODO - plumb in fallocate from other filesysetms like VXFS etc. JRA. */
701 /*******************************************************************
702 An ftruncate() wrapper that will deal with 64 bit filesizes.
703 ********************************************************************/
705 int sys_ftruncate(int fd, SMB_OFF_T offset)
707 #if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_OFF64_T) && defined(HAVE_FTRUNCATE64)
708 return ftruncate64(fd, offset);
710 return ftruncate(fd, offset);
714 /*******************************************************************
715 An lseek() wrapper that will deal with 64 bit filesizes.
716 ********************************************************************/
718 SMB_OFF_T sys_lseek(int fd, SMB_OFF_T offset, int whence)
720 #if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_OFF64_T) && defined(HAVE_LSEEK64)
721 return lseek64(fd, offset, whence);
723 return lseek(fd, offset, whence);
727 /*******************************************************************
728 An fseek() wrapper that will deal with 64 bit filesizes.
729 ********************************************************************/
731 int sys_fseek(FILE *fp, SMB_OFF_T offset, int whence)
733 #if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(LARGE_SMB_OFF_T) && defined(HAVE_FSEEK64)
734 return fseek64(fp, offset, whence);
735 #elif defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(LARGE_SMB_OFF_T) && defined(HAVE_FSEEKO64)
736 return fseeko64(fp, offset, whence);
738 return fseek(fp, offset, whence);
742 /*******************************************************************
743 An ftell() wrapper that will deal with 64 bit filesizes.
744 ********************************************************************/
746 SMB_OFF_T sys_ftell(FILE *fp)
748 #if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(LARGE_SMB_OFF_T) && defined(HAVE_FTELL64)
749 return (SMB_OFF_T)ftell64(fp);
750 #elif defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(LARGE_SMB_OFF_T) && defined(HAVE_FTELLO64)
751 return (SMB_OFF_T)ftello64(fp);
753 return (SMB_OFF_T)ftell(fp);
757 /*******************************************************************
758 A creat() wrapper that will deal with 64 bit filesizes.
759 ********************************************************************/
761 int sys_creat(const char *path, mode_t mode)
763 #if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_CREAT64)
764 return creat64(path, mode);
767 * If creat64 isn't defined then ensure we call a potential open64.
770 return sys_open(path, O_WRONLY | O_CREAT | O_TRUNC, mode);
774 /*******************************************************************
775 An open() wrapper that will deal with 64 bit filesizes.
776 ********************************************************************/
778 int sys_open(const char *path, int oflag, mode_t mode)
780 #if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_OPEN64)
781 return open64(path, oflag, mode);
783 return open(path, oflag, mode);
787 /*******************************************************************
788 An fopen() wrapper that will deal with 64 bit filesizes.
789 ********************************************************************/
791 FILE *sys_fopen(const char *path, const char *type)
793 #if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_FOPEN64)
794 return fopen64(path, type);
796 return fopen(path, type);
801 #if HAVE_KERNEL_SHARE_MODES
803 #define LOCK_MAND 32 /* This is a mandatory flock */
804 #define LOCK_READ 64 /* ... Which allows concurrent read operations */
805 #define LOCK_WRITE 128 /* ... Which allows concurrent write operations */
806 #define LOCK_RW 192 /* ... Which allows concurrent read & write ops */
810 /*******************************************************************
811 A flock() wrapper that will perform the kernel flock.
812 ********************************************************************/
814 void kernel_flock(int fd, uint32 share_mode, uint32 access_mask)
816 #if HAVE_KERNEL_SHARE_MODES
818 if (share_mode == FILE_SHARE_WRITE) {
819 kernel_mode = LOCK_MAND|LOCK_WRITE;
820 } else if (share_mode == FILE_SHARE_READ) {
821 kernel_mode = LOCK_MAND|LOCK_READ;
822 } else if (share_mode == FILE_SHARE_NONE) {
823 kernel_mode = LOCK_MAND;
826 flock(fd, kernel_mode);
834 /*******************************************************************
835 An opendir wrapper that will deal with 64 bit filesizes.
836 ********************************************************************/
838 SMB_STRUCT_DIR *sys_opendir(const char *name)
840 #if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_OPENDIR64)
841 return opendir64(name);
843 return opendir(name);
847 /*******************************************************************
848 An fdopendir wrapper that will deal with 64 bit filesizes.
849 Ugly hack - we need dirfd for this to work correctly in the
851 ********************************************************************/
853 SMB_STRUCT_DIR *sys_fdopendir(int fd)
855 #if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_FDOPENDIR64) && defined(HAVE_DIRFD)
856 return fdopendir64(fd);
857 #elif defined(HAVE_FDOPENDIR) && defined(HAVE_DIRFD)
858 return fdopendir(fd);
865 /*******************************************************************
866 A readdir wrapper that will deal with 64 bit filesizes.
867 ********************************************************************/
869 SMB_STRUCT_DIRENT *sys_readdir(SMB_STRUCT_DIR *dirp)
871 #if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_READDIR64)
872 return readdir64(dirp);
874 return readdir(dirp);
878 /*******************************************************************
879 A seekdir wrapper that will deal with 64 bit filesizes.
880 ********************************************************************/
882 void sys_seekdir(SMB_STRUCT_DIR *dirp, long offset)
884 #if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_SEEKDIR64)
885 seekdir64(dirp, offset);
887 seekdir(dirp, offset);
891 /*******************************************************************
892 A telldir wrapper that will deal with 64 bit filesizes.
893 ********************************************************************/
895 long sys_telldir(SMB_STRUCT_DIR *dirp)
897 #if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_TELLDIR64)
898 return (long)telldir64(dirp);
900 return (long)telldir(dirp);
904 /*******************************************************************
905 A rewinddir wrapper that will deal with 64 bit filesizes.
906 ********************************************************************/
908 void sys_rewinddir(SMB_STRUCT_DIR *dirp)
910 #if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_REWINDDIR64)
917 /*******************************************************************
918 A close wrapper that will deal with 64 bit filesizes.
919 ********************************************************************/
921 int sys_closedir(SMB_STRUCT_DIR *dirp)
923 #if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_CLOSEDIR64)
924 return closedir64(dirp);
926 return closedir(dirp);
930 /*******************************************************************
931 An mknod() wrapper that will deal with 64 bit filesizes.
932 ********************************************************************/
934 int sys_mknod(const char *path, mode_t mode, SMB_DEV_T dev)
936 #if defined(HAVE_MKNOD) || defined(HAVE_MKNOD64)
937 #if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_MKNOD64) && defined(HAVE_DEV64_T)
938 return mknod64(path, mode, dev);
940 return mknod(path, mode, dev);
943 /* No mknod system call. */
949 /*******************************************************************
950 The wait() calls vary between systems
951 ********************************************************************/
953 int sys_waitpid(pid_t pid,int *status,int options)
956 return waitpid(pid,status,options);
957 #else /* HAVE_WAITPID */
958 return wait4(pid, status, options, NULL);
959 #endif /* HAVE_WAITPID */
962 /*******************************************************************
963 System wrapper for getwd. Always returns MALLOC'ed memory, or NULL
964 on error (malloc fail usually).
965 ********************************************************************/
967 char *sys_getwd(void)
969 #ifdef GETCWD_TAKES_NULL
970 return getcwd(NULL, 0);
972 char *wd = NULL, *s = NULL;
973 size_t allocated = PATH_MAX;
976 s = SMB_REALLOC_ARRAY(s, char, allocated);
980 wd = getcwd(s, allocated);
984 if (errno != ERANGE) {
989 if (allocated < PATH_MAX) {
996 char *s = SMB_MALLOC_ARRAY(char, PATH_MAX);
1004 #if defined(HAVE_POSIX_CAPABILITIES)
1006 /**************************************************************************
1007 Try and abstract process capabilities (for systems that have them).
1008 ****************************************************************************/
1010 /* Set the POSIX capabilities needed for the given purpose into the effective
1011 * capability set of the current process. Make sure they are always removed
1012 * from the inheritable set, because there is no circumstance in which our
1013 * children should inherit our elevated privileges.
1015 static bool set_process_capability(enum smbd_capability capability,
1018 cap_value_t cap_vals[2] = {0};
1019 int num_cap_vals = 0;
1023 #if defined(HAVE_PRCTL) && defined(PR_GET_KEEPCAPS) && defined(PR_SET_KEEPCAPS)
1024 /* On Linux, make sure that any capabilities we grab are sticky
1025 * across UID changes. We expect that this would allow us to keep both
1026 * the effective and permitted capability sets, but as of circa 2.6.16,
1027 * only the permitted set is kept. It is a bug (which we work around)
1028 * that the effective set is lost, but we still require the effective
1031 if (!prctl(PR_GET_KEEPCAPS)) {
1032 prctl(PR_SET_KEEPCAPS, 1);
1036 cap = cap_get_proc();
1038 DEBUG(0,("set_process_capability: cap_get_proc failed: %s\n",
1043 switch (capability) {
1044 case KERNEL_OPLOCK_CAPABILITY:
1045 #ifdef CAP_NETWORK_MGT
1046 /* IRIX has CAP_NETWORK_MGT for oplocks. */
1047 cap_vals[num_cap_vals++] = CAP_NETWORK_MGT;
1050 case DMAPI_ACCESS_CAPABILITY:
1051 #ifdef CAP_DEVICE_MGT
1052 /* IRIX has CAP_DEVICE_MGT for DMAPI access. */
1053 cap_vals[num_cap_vals++] = CAP_DEVICE_MGT;
1055 /* Linux has CAP_MKNOD for DMAPI access. */
1056 cap_vals[num_cap_vals++] = CAP_MKNOD;
1059 case LEASE_CAPABILITY:
1061 cap_vals[num_cap_vals++] = CAP_LEASE;
1066 SMB_ASSERT(num_cap_vals <= ARRAY_SIZE(cap_vals));
1068 if (num_cap_vals == 0) {
1073 cap_set_flag(cap, CAP_EFFECTIVE, num_cap_vals, cap_vals,
1074 enable ? CAP_SET : CAP_CLEAR);
1076 /* We never want to pass capabilities down to our children, so make
1077 * sure they are not inherited.
1079 cap_set_flag(cap, CAP_INHERITABLE, num_cap_vals, cap_vals, CAP_CLEAR);
1081 if (cap_set_proc(cap) == -1) {
1082 DEBUG(0, ("set_process_capability: cap_set_proc failed: %s\n",
1092 #endif /* HAVE_POSIX_CAPABILITIES */
1094 /****************************************************************************
1095 Gain the oplock capability from the kernel if possible.
1096 ****************************************************************************/
1098 void set_effective_capability(enum smbd_capability capability)
1100 #if defined(HAVE_POSIX_CAPABILITIES)
1101 set_process_capability(capability, True);
1102 #endif /* HAVE_POSIX_CAPABILITIES */
1105 void drop_effective_capability(enum smbd_capability capability)
1107 #if defined(HAVE_POSIX_CAPABILITIES)
1108 set_process_capability(capability, False);
1109 #endif /* HAVE_POSIX_CAPABILITIES */
1112 /**************************************************************************
1113 Wrapper for random().
1114 ****************************************************************************/
1116 long sys_random(void)
1118 #if defined(HAVE_RANDOM)
1119 return (long)random();
1120 #elif defined(HAVE_RAND)
1121 return (long)rand();
1123 DEBUG(0,("Error - no random function available !\n"));
1128 /**************************************************************************
1129 Wrapper for srandom().
1130 ****************************************************************************/
1132 void sys_srandom(unsigned int seed)
1134 #if defined(HAVE_SRANDOM)
1136 #elif defined(HAVE_SRAND)
1139 DEBUG(0,("Error - no srandom function available !\n"));
1145 #define NGROUPS_MAX 32 /* Guess... */
1148 /**************************************************************************
1149 Returns equivalent to NGROUPS_MAX - using sysconf if needed.
1150 ****************************************************************************/
1152 int groups_max(void)
1154 #if defined(SYSCONF_SC_NGROUPS_MAX)
1155 int ret = sysconf(_SC_NGROUPS_MAX);
1156 return (ret == -1) ? NGROUPS_MAX : ret;
1162 /**************************************************************************
1163 Wrap setgroups and getgroups for systems that declare getgroups() as
1164 returning an array of gid_t, but actuall return an array of int.
1165 ****************************************************************************/
1167 #if defined(HAVE_BROKEN_GETGROUPS)
1169 #ifdef HAVE_BROKEN_GETGROUPS
1175 static int sys_broken_getgroups(int setlen, gid_t *gidset)
1182 return getgroups(setlen, &gid);
1186 * Broken case. We need to allocate a
1187 * GID_T array of size setlen.
1196 setlen = groups_max();
1198 if((group_list = SMB_MALLOC_ARRAY(GID_T, setlen)) == NULL) {
1199 DEBUG(0,("sys_getgroups: Malloc fail.\n"));
1203 if((ngroups = getgroups(setlen, group_list)) < 0) {
1204 int saved_errno = errno;
1205 SAFE_FREE(group_list);
1206 errno = saved_errno;
1210 for(i = 0; i < ngroups; i++)
1211 gidset[i] = (gid_t)group_list[i];
1213 SAFE_FREE(group_list);
1217 static int sys_broken_setgroups(int setlen, gid_t *gidset)
1225 if (setlen < 0 || setlen > groups_max()) {
1231 * Broken case. We need to allocate a
1232 * GID_T array of size setlen.
1235 if((group_list = SMB_MALLOC_ARRAY(GID_T, setlen)) == NULL) {
1236 DEBUG(0,("sys_setgroups: Malloc fail.\n"));
1240 for(i = 0; i < setlen; i++)
1241 group_list[i] = (GID_T) gidset[i];
1243 if(setgroups(setlen, group_list) != 0) {
1244 int saved_errno = errno;
1245 SAFE_FREE(group_list);
1246 errno = saved_errno;
1250 SAFE_FREE(group_list);
1254 #endif /* HAVE_BROKEN_GETGROUPS */
1256 /* This is a list of systems that require the first GID passed to setgroups(2)
1257 * to be the effective GID. If your system is one of these, add it here.
1259 #if defined (FREEBSD) || defined (DARWINOS)
1260 #define USE_BSD_SETGROUPS
1263 #if defined(USE_BSD_SETGROUPS)
1264 /* Depending on the particular BSD implementation, the first GID that is
1265 * passed to setgroups(2) will either be ignored or will set the credential's
1266 * effective GID. In either case, the right thing to do is to guarantee that
1267 * gidset[0] is the effective GID.
1269 static int sys_bsd_setgroups(gid_t primary_gid, int setlen, const gid_t *gidset)
1271 gid_t *new_gidset = NULL;
1275 /* setgroups(2) will fail with EINVAL if we pass too many groups. */
1278 /* No group list, just make sure we are setting the efective GID. */
1280 return setgroups(1, &primary_gid);
1283 /* If the primary gid is not the first array element, grow the array
1284 * and insert it at the front.
1286 if (gidset[0] != primary_gid) {
1287 new_gidset = SMB_MALLOC_ARRAY(gid_t, setlen + 1);
1288 if (new_gidset == NULL) {
1292 memcpy(new_gidset + 1, gidset, (setlen * sizeof(gid_t)));
1293 new_gidset[0] = primary_gid;
1298 DEBUG(3, ("forced to truncate group list from %d to %d\n",
1303 #if defined(HAVE_BROKEN_GETGROUPS)
1304 ret = sys_broken_setgroups(setlen, new_gidset ? new_gidset : gidset);
1306 ret = setgroups(setlen, new_gidset ? new_gidset : gidset);
1311 SAFE_FREE(new_gidset);
1318 #endif /* USE_BSD_SETGROUPS */
1320 /**************************************************************************
1321 Wrapper for getgroups. Deals with broken (int) case.
1322 ****************************************************************************/
1324 int sys_getgroups(int setlen, gid_t *gidset)
1326 #if defined(HAVE_BROKEN_GETGROUPS)
1327 return sys_broken_getgroups(setlen, gidset);
1329 return getgroups(setlen, gidset);
1333 /**************************************************************************
1334 Wrapper for setgroups. Deals with broken (int) case and BSD case.
1335 ****************************************************************************/
1337 int sys_setgroups(gid_t UNUSED(primary_gid), int setlen, gid_t *gidset)
1339 #if !defined(HAVE_SETGROUPS)
1342 #endif /* HAVE_SETGROUPS */
1344 #if defined(USE_BSD_SETGROUPS)
1345 return sys_bsd_setgroups(primary_gid, setlen, gidset);
1346 #elif defined(HAVE_BROKEN_GETGROUPS)
1347 return sys_broken_setgroups(setlen, gidset);
1349 return setgroups(setlen, gidset);
1353 /**************************************************************************
1354 Extract a command into an arg list.
1355 ****************************************************************************/
1357 static char **extract_args(TALLOC_CTX *mem_ctx, const char *command)
1366 if (!(trunc_cmd = talloc_strdup(mem_ctx, command))) {
1367 DEBUG(0, ("talloc failed\n"));
1371 if(!(ptr = strtok_r(trunc_cmd, " \t", &saveptr))) {
1372 TALLOC_FREE(trunc_cmd);
1381 for( argcl = 1; ptr; ptr = strtok_r(NULL, " \t", &saveptr))
1384 TALLOC_FREE(trunc_cmd);
1386 if (!(argl = talloc_array(mem_ctx, char *, argcl + 1))) {
1391 * Now do the extraction.
1394 if (!(trunc_cmd = talloc_strdup(mem_ctx, command))) {
1398 ptr = strtok_r(trunc_cmd, " \t", &saveptr);
1401 if (!(argl[i++] = talloc_strdup(argl, ptr))) {
1405 while((ptr = strtok_r(NULL, " \t", &saveptr)) != NULL) {
1407 if (!(argl[i++] = talloc_strdup(argl, ptr))) {
1413 TALLOC_FREE(trunc_cmd);
1417 DEBUG(0, ("talloc failed\n"));
1418 TALLOC_FREE(trunc_cmd);
1424 /**************************************************************************
1425 Wrapper for popen. Safer as it doesn't search a path.
1426 Modified from the glibc sources.
1427 modified by tridge to return a file descriptor. We must kick our FILE* habit
1428 ****************************************************************************/
1430 typedef struct _popen_list
1434 struct _popen_list *next;
1437 static popen_list *popen_chain;
1439 int sys_popen(const char *command)
1441 int parent_end, child_end;
1443 popen_list *entry = NULL;
1446 if (pipe(pipe_fds) < 0)
1449 parent_end = pipe_fds[0];
1450 child_end = pipe_fds[1];
1457 if((entry = SMB_MALLOC_P(popen_list)) == NULL)
1460 ZERO_STRUCTP(entry);
1463 * Extract the command and args into a NULL terminated array.
1466 if(!(argl = extract_args(NULL, command)))
1469 entry->child_pid = sys_fork();
1471 if (entry->child_pid == -1) {
1475 if (entry->child_pid == 0) {
1481 int child_std_end = STDOUT_FILENO;
1485 if (child_end != child_std_end) {
1486 dup2 (child_end, child_std_end);
1491 * POSIX.2: "popen() shall ensure that any streams from previous
1492 * popen() calls that remain open in the parent process are closed
1493 * in the new child process."
1496 for (p = popen_chain; p; p = p->next)
1499 execv(argl[0], argl);
1510 /* Link into popen_chain. */
1511 entry->next = popen_chain;
1512 popen_chain = entry;
1513 entry->fd = parent_end;
1526 /**************************************************************************
1527 Wrapper for pclose. Modified from the glibc sources.
1528 ****************************************************************************/
1530 int sys_pclose(int fd)
1533 popen_list **ptr = &popen_chain;
1534 popen_list *entry = NULL;
1538 /* Unlink from popen_chain. */
1539 for ( ; *ptr != NULL; ptr = &(*ptr)->next) {
1540 if ((*ptr)->fd == fd) {
1542 *ptr = (*ptr)->next;
1548 if (status < 0 || close(entry->fd) < 0)
1552 * As Samba is catching and eating child process
1553 * exits we don't really care about the child exit
1554 * code, a -1 with errno = ECHILD will do fine for us.
1558 wait_pid = sys_waitpid (entry->child_pid, &wstatus, 0);
1559 } while (wait_pid == -1 && errno == EINTR);
1568 /**************************************************************************
1569 Wrapper for Admin Logs.
1570 ****************************************************************************/
1572 void sys_adminlog(int priority, const char *format_str, ...)
1576 char *msgbuf = NULL;
1578 va_start( ap, format_str );
1579 ret = vasprintf( &msgbuf, format_str, ap );
1585 #if defined(HAVE_SYSLOG)
1586 syslog( priority, "%s", msgbuf );
1588 DEBUG(0,("%s", msgbuf ));
1593 /******** Solaris EA helper function prototypes ********/
1594 #ifdef HAVE_ATTROPEN
1595 #define SOLARIS_ATTRMODE S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP
1596 static int solaris_write_xattr(int attrfd, const char *value, size_t size);
1597 static ssize_t solaris_read_xattr(int attrfd, void *value, size_t size);
1598 static ssize_t solaris_list_xattr(int attrdirfd, char *list, size_t size);
1599 static int solaris_unlinkat(int attrdirfd, const char *name);
1600 static int solaris_attropen(const char *path, const char *attrpath, int oflag, mode_t mode);
1601 static int solaris_openat(int fildes, const char *path, int oflag, mode_t mode);
1604 /**************************************************************************
1605 Wrappers for extented attribute calls. Based on the Linux package with
1606 support for IRIX and (Net|Free)BSD also. Expand as other systems have them.
1607 ****************************************************************************/
1609 ssize_t sys_getxattr (const char *path, const char *name, void *value, size_t size)
1611 #if defined(HAVE_GETXATTR)
1612 #ifndef XATTR_ADD_OPT
1613 return getxattr(path, name, value, size);
1616 return getxattr(path, name, value, size, 0, options);
1618 #elif defined(HAVE_GETEA)
1619 return getea(path, name, value, size);
1620 #elif defined(HAVE_EXTATTR_GET_FILE)
1623 int attrnamespace = (strncmp(name, "system", 6) == 0) ?
1624 EXTATTR_NAMESPACE_SYSTEM : EXTATTR_NAMESPACE_USER;
1625 const char *attrname = ((s=strchr_m(name, '.')) == NULL) ? name : s + 1;
1627 * The BSD implementation has a nasty habit of silently truncating
1628 * the returned value to the size of the buffer, so we have to check
1629 * that the buffer is large enough to fit the returned value.
1631 if((retval=extattr_get_file(path, attrnamespace, attrname, NULL, 0)) >= 0) {
1636 if((retval=extattr_get_file(path, attrnamespace, attrname, value, size)) >= 0)
1640 DEBUG(10,("sys_getxattr: extattr_get_file() failed with: %s\n", strerror(errno)));
1642 #elif defined(HAVE_ATTR_GET)
1643 int retval, flags = 0;
1644 int valuelength = (int)size;
1645 char *attrname = strchr(name,'.') + 1;
1647 if (strncmp(name, "system", 6) == 0) flags |= ATTR_ROOT;
1649 retval = attr_get(path, attrname, (char *)value, &valuelength, flags);
1651 return retval ? retval : valuelength;
1652 #elif defined(HAVE_ATTROPEN)
1654 int attrfd = solaris_attropen(path, name, O_RDONLY, 0);
1656 ret = solaris_read_xattr(attrfd, value, size);
1666 ssize_t sys_lgetxattr (const char *path, const char *name, void *value, size_t size)
1668 #if defined(HAVE_LGETXATTR)
1669 return lgetxattr(path, name, value, size);
1670 #elif defined(HAVE_GETXATTR) && defined(XATTR_ADD_OPT)
1671 int options = XATTR_NOFOLLOW;
1672 return getxattr(path, name, value, size, 0, options);
1673 #elif defined(HAVE_LGETEA)
1674 return lgetea(path, name, value, size);
1675 #elif defined(HAVE_EXTATTR_GET_LINK)
1678 int attrnamespace = (strncmp(name, "system", 6) == 0) ?
1679 EXTATTR_NAMESPACE_SYSTEM : EXTATTR_NAMESPACE_USER;
1680 const char *attrname = ((s=strchr_m(name, '.')) == NULL) ? name : s + 1;
1682 if((retval=extattr_get_link(path, attrnamespace, attrname, NULL, 0)) >= 0) {
1687 if((retval=extattr_get_link(path, attrnamespace, attrname, value, size)) >= 0)
1691 DEBUG(10,("sys_lgetxattr: extattr_get_link() failed with: %s\n", strerror(errno)));
1693 #elif defined(HAVE_ATTR_GET)
1694 int retval, flags = ATTR_DONTFOLLOW;
1695 int valuelength = (int)size;
1696 char *attrname = strchr(name,'.') + 1;
1698 if (strncmp(name, "system", 6) == 0) flags |= ATTR_ROOT;
1700 retval = attr_get(path, attrname, (char *)value, &valuelength, flags);
1702 return retval ? retval : valuelength;
1703 #elif defined(HAVE_ATTROPEN)
1705 int attrfd = solaris_attropen(path, name, O_RDONLY|AT_SYMLINK_NOFOLLOW, 0);
1707 ret = solaris_read_xattr(attrfd, value, size);
1717 ssize_t sys_fgetxattr (int filedes, const char *name, void *value, size_t size)
1719 #if defined(HAVE_FGETXATTR)
1720 #ifndef XATTR_ADD_OPT
1721 return fgetxattr(filedes, name, value, size);
1724 return fgetxattr(filedes, name, value, size, 0, options);
1726 #elif defined(HAVE_FGETEA)
1727 return fgetea(filedes, name, value, size);
1728 #elif defined(HAVE_EXTATTR_GET_FD)
1731 int attrnamespace = (strncmp(name, "system", 6) == 0) ?
1732 EXTATTR_NAMESPACE_SYSTEM : EXTATTR_NAMESPACE_USER;
1733 const char *attrname = ((s=strchr_m(name, '.')) == NULL) ? name : s + 1;
1735 if((retval=extattr_get_fd(filedes, attrnamespace, attrname, NULL, 0)) >= 0) {
1740 if((retval=extattr_get_fd(filedes, attrnamespace, attrname, value, size)) >= 0)
1744 DEBUG(10,("sys_fgetxattr: extattr_get_fd() failed with: %s\n", strerror(errno)));
1746 #elif defined(HAVE_ATTR_GETF)
1747 int retval, flags = 0;
1748 int valuelength = (int)size;
1749 char *attrname = strchr(name,'.') + 1;
1751 if (strncmp(name, "system", 6) == 0) flags |= ATTR_ROOT;
1753 retval = attr_getf(filedes, attrname, (char *)value, &valuelength, flags);
1755 return retval ? retval : valuelength;
1756 #elif defined(HAVE_ATTROPEN)
1758 int attrfd = solaris_openat(filedes, name, O_RDONLY|O_XATTR, 0);
1760 ret = solaris_read_xattr(attrfd, value, size);
1770 #if defined(HAVE_EXTATTR_LIST_FILE)
1772 #define EXTATTR_PREFIX(s) (s), (sizeof((s))-1)
1780 { EXTATTR_NAMESPACE_SYSTEM, EXTATTR_PREFIX("system.") },
1781 { EXTATTR_NAMESPACE_USER, EXTATTR_PREFIX("user.") },
1789 static ssize_t bsd_attr_list (int type, extattr_arg arg, char *list, size_t size)
1791 ssize_t list_size, total_size = 0;
1794 /* Iterate through extattr(2) namespaces */
1795 for(t = 0; t < (sizeof(extattr)/sizeof(extattr[0])); t++) {
1797 #if defined(HAVE_EXTATTR_LIST_FILE)
1799 list_size = extattr_list_file(arg.path, extattr[t].space, list, size);
1802 #if defined(HAVE_EXTATTR_LIST_LINK)
1804 list_size = extattr_list_link(arg.path, extattr[t].space, list, size);
1807 #if defined(HAVE_EXTATTR_LIST_FD)
1809 list_size = extattr_list_fd(arg.filedes, extattr[t].space, list, size);
1816 /* Some error happend. Errno should be set by the previous call */
1822 /* XXX: Call with an empty buffer may be used to calculate
1823 necessary buffer size. Unfortunately, we can't say, how
1824 many attributes were returned, so here is the potential
1825 problem with the emulation.
1828 /* Take the worse case of one char attribute names -
1829 two bytes per name plus one more for sanity.
1831 total_size += list_size + (list_size/2 + 1)*extattr[t].len;
1834 /* Count necessary offset to fit namespace prefixes */
1836 for(i = 0; i < list_size; i += list[i] + 1)
1837 len += extattr[t].len;
1839 total_size += list_size + len;
1840 /* Buffer is too small to fit the results */
1841 if(total_size > size) {
1845 /* Shift results back, so we can prepend prefixes */
1846 buf = (char *)memmove(list + len, list, list_size);
1848 for(i = 0; i < list_size; i += len + 1) {
1850 strncpy(list, extattr[t].name, extattr[t].len + 1);
1851 list += extattr[t].len;
1852 strncpy(list, buf + i + 1, len);
1863 #if defined(HAVE_ATTR_LIST) && defined(HAVE_SYS_ATTRIBUTES_H)
1864 static char attr_buffer[ATTR_MAX_VALUELEN];
1866 static ssize_t irix_attr_list(const char *path, int filedes, char *list, size_t size, int flags)
1868 int retval = 0, index;
1869 attrlist_cursor_t *cursor = 0;
1871 attrlist_t * al = (attrlist_t *)attr_buffer;
1873 size_t ent_size, left = size;
1878 retval = attr_listf(filedes, attr_buffer, ATTR_MAX_VALUELEN, flags, cursor);
1880 retval = attr_list(path, attr_buffer, ATTR_MAX_VALUELEN, flags, cursor);
1882 for (index = 0; index < al->al_count; index++) {
1883 ae = ATTR_ENTRY(attr_buffer, index);
1884 ent_size = strlen(ae->a_name) + sizeof("user.");
1885 if (left >= ent_size) {
1886 strncpy(bp, "user.", sizeof("user."));
1887 strncat(bp, ae->a_name, ent_size - sizeof("user."));
1895 total_size += ent_size;
1897 if (al->al_more == 0) break;
1904 retval = attr_listf(filedes, attr_buffer, ATTR_MAX_VALUELEN, flags, cursor);
1906 retval = attr_list(path, attr_buffer, ATTR_MAX_VALUELEN, flags, cursor);
1908 for (index = 0; index < al->al_count; index++) {
1909 ae = ATTR_ENTRY(attr_buffer, index);
1910 ent_size = strlen(ae->a_name) + sizeof("system.");
1911 if (left >= ent_size) {
1912 strncpy(bp, "system.", sizeof("system."));
1913 strncat(bp, ae->a_name, ent_size - sizeof("system."));
1921 total_size += ent_size;
1923 if (al->al_more == 0) break;
1926 return (ssize_t)(retval ? retval : total_size);
1931 ssize_t sys_listxattr (const char *path, char *list, size_t size)
1933 #if defined(HAVE_LISTXATTR)
1934 #ifndef XATTR_ADD_OPT
1935 return listxattr(path, list, size);
1938 return listxattr(path, list, size, options);
1940 #elif defined(HAVE_LISTEA)
1941 return listea(path, list, size);
1942 #elif defined(HAVE_EXTATTR_LIST_FILE)
1945 return bsd_attr_list(0, arg, list, size);
1946 #elif defined(HAVE_ATTR_LIST) && defined(HAVE_SYS_ATTRIBUTES_H)
1947 return irix_attr_list(path, 0, list, size, 0);
1948 #elif defined(HAVE_ATTROPEN)
1950 int attrdirfd = solaris_attropen(path, ".", O_RDONLY, 0);
1951 if (attrdirfd >= 0) {
1952 ret = solaris_list_xattr(attrdirfd, list, size);
1962 ssize_t sys_llistxattr (const char *path, char *list, size_t size)
1964 #if defined(HAVE_LLISTXATTR)
1965 return llistxattr(path, list, size);
1966 #elif defined(HAVE_LISTXATTR) && defined(XATTR_ADD_OPT)
1967 int options = XATTR_NOFOLLOW;
1968 return listxattr(path, list, size, options);
1969 #elif defined(HAVE_LLISTEA)
1970 return llistea(path, list, size);
1971 #elif defined(HAVE_EXTATTR_LIST_LINK)
1974 return bsd_attr_list(1, arg, list, size);
1975 #elif defined(HAVE_ATTR_LIST) && defined(HAVE_SYS_ATTRIBUTES_H)
1976 return irix_attr_list(path, 0, list, size, ATTR_DONTFOLLOW);
1977 #elif defined(HAVE_ATTROPEN)
1979 int attrdirfd = solaris_attropen(path, ".", O_RDONLY|AT_SYMLINK_NOFOLLOW, 0);
1980 if (attrdirfd >= 0) {
1981 ret = solaris_list_xattr(attrdirfd, list, size);
1991 ssize_t sys_flistxattr (int filedes, char *list, size_t size)
1993 #if defined(HAVE_FLISTXATTR)
1994 #ifndef XATTR_ADD_OPT
1995 return flistxattr(filedes, list, size);
1998 return flistxattr(filedes, list, size, options);
2000 #elif defined(HAVE_FLISTEA)
2001 return flistea(filedes, list, size);
2002 #elif defined(HAVE_EXTATTR_LIST_FD)
2004 arg.filedes = filedes;
2005 return bsd_attr_list(2, arg, list, size);
2006 #elif defined(HAVE_ATTR_LISTF)
2007 return irix_attr_list(NULL, filedes, list, size, 0);
2008 #elif defined(HAVE_ATTROPEN)
2010 int attrdirfd = solaris_openat(filedes, ".", O_RDONLY|O_XATTR, 0);
2011 if (attrdirfd >= 0) {
2012 ret = solaris_list_xattr(attrdirfd, list, size);
2022 int sys_removexattr (const char *path, const char *name)
2024 #if defined(HAVE_REMOVEXATTR)
2025 #ifndef XATTR_ADD_OPT
2026 return removexattr(path, name);
2029 return removexattr(path, name, options);
2031 #elif defined(HAVE_REMOVEEA)
2032 return removeea(path, name);
2033 #elif defined(HAVE_EXTATTR_DELETE_FILE)
2035 int attrnamespace = (strncmp(name, "system", 6) == 0) ?
2036 EXTATTR_NAMESPACE_SYSTEM : EXTATTR_NAMESPACE_USER;
2037 const char *attrname = ((s=strchr_m(name, '.')) == NULL) ? name : s + 1;
2039 return extattr_delete_file(path, attrnamespace, attrname);
2040 #elif defined(HAVE_ATTR_REMOVE)
2042 char *attrname = strchr(name,'.') + 1;
2044 if (strncmp(name, "system", 6) == 0) flags |= ATTR_ROOT;
2046 return attr_remove(path, attrname, flags);
2047 #elif defined(HAVE_ATTROPEN)
2049 int attrdirfd = solaris_attropen(path, ".", O_RDONLY, 0);
2050 if (attrdirfd >= 0) {
2051 ret = solaris_unlinkat(attrdirfd, name);
2061 int sys_lremovexattr (const char *path, const char *name)
2063 #if defined(HAVE_LREMOVEXATTR)
2064 return lremovexattr(path, name);
2065 #elif defined(HAVE_REMOVEXATTR) && defined(XATTR_ADD_OPT)
2066 int options = XATTR_NOFOLLOW;
2067 return removexattr(path, name, options);
2068 #elif defined(HAVE_LREMOVEEA)
2069 return lremoveea(path, name);
2070 #elif defined(HAVE_EXTATTR_DELETE_LINK)
2072 int attrnamespace = (strncmp(name, "system", 6) == 0) ?
2073 EXTATTR_NAMESPACE_SYSTEM : EXTATTR_NAMESPACE_USER;
2074 const char *attrname = ((s=strchr_m(name, '.')) == NULL) ? name : s + 1;
2076 return extattr_delete_link(path, attrnamespace, attrname);
2077 #elif defined(HAVE_ATTR_REMOVE)
2078 int flags = ATTR_DONTFOLLOW;
2079 char *attrname = strchr(name,'.') + 1;
2081 if (strncmp(name, "system", 6) == 0) flags |= ATTR_ROOT;
2083 return attr_remove(path, attrname, flags);
2084 #elif defined(HAVE_ATTROPEN)
2086 int attrdirfd = solaris_attropen(path, ".", O_RDONLY|AT_SYMLINK_NOFOLLOW, 0);
2087 if (attrdirfd >= 0) {
2088 ret = solaris_unlinkat(attrdirfd, name);
2098 int sys_fremovexattr (int filedes, const char *name)
2100 #if defined(HAVE_FREMOVEXATTR)
2101 #ifndef XATTR_ADD_OPT
2102 return fremovexattr(filedes, name);
2105 return fremovexattr(filedes, name, options);
2107 #elif defined(HAVE_FREMOVEEA)
2108 return fremoveea(filedes, name);
2109 #elif defined(HAVE_EXTATTR_DELETE_FD)
2111 int attrnamespace = (strncmp(name, "system", 6) == 0) ?
2112 EXTATTR_NAMESPACE_SYSTEM : EXTATTR_NAMESPACE_USER;
2113 const char *attrname = ((s=strchr_m(name, '.')) == NULL) ? name : s + 1;
2115 return extattr_delete_fd(filedes, attrnamespace, attrname);
2116 #elif defined(HAVE_ATTR_REMOVEF)
2118 char *attrname = strchr(name,'.') + 1;
2120 if (strncmp(name, "system", 6) == 0) flags |= ATTR_ROOT;
2122 return attr_removef(filedes, attrname, flags);
2123 #elif defined(HAVE_ATTROPEN)
2125 int attrdirfd = solaris_openat(filedes, ".", O_RDONLY|O_XATTR, 0);
2126 if (attrdirfd >= 0) {
2127 ret = solaris_unlinkat(attrdirfd, name);
2137 int sys_setxattr (const char *path, const char *name, const void *value, size_t size, int flags)
2139 #if defined(HAVE_SETXATTR)
2140 #ifndef XATTR_ADD_OPT
2141 return setxattr(path, name, value, size, flags);
2144 return setxattr(path, name, value, size, 0, options);
2146 #elif defined(HAVE_SETEA)
2147 return setea(path, name, value, size, flags);
2148 #elif defined(HAVE_EXTATTR_SET_FILE)
2151 int attrnamespace = (strncmp(name, "system", 6) == 0) ?
2152 EXTATTR_NAMESPACE_SYSTEM : EXTATTR_NAMESPACE_USER;
2153 const char *attrname = ((s=strchr_m(name, '.')) == NULL) ? name : s + 1;
2155 /* Check attribute existence */
2156 retval = extattr_get_file(path, attrnamespace, attrname, NULL, 0);
2158 /* REPLACE attribute, that doesn't exist */
2159 if (flags & XATTR_REPLACE && errno == ENOATTR) {
2163 /* Ignore other errors */
2166 /* CREATE attribute, that already exists */
2167 if (flags & XATTR_CREATE) {
2173 retval = extattr_set_file(path, attrnamespace, attrname, value, size);
2174 return (retval < 0) ? -1 : 0;
2175 #elif defined(HAVE_ATTR_SET)
2177 char *attrname = strchr(name,'.') + 1;
2179 if (strncmp(name, "system", 6) == 0) myflags |= ATTR_ROOT;
2180 if (flags & XATTR_CREATE) myflags |= ATTR_CREATE;
2181 if (flags & XATTR_REPLACE) myflags |= ATTR_REPLACE;
2183 return attr_set(path, attrname, (const char *)value, size, myflags);
2184 #elif defined(HAVE_ATTROPEN)
2186 int myflags = O_RDWR;
2188 if (flags & XATTR_CREATE) myflags |= O_EXCL;
2189 if (!(flags & XATTR_REPLACE)) myflags |= O_CREAT;
2190 attrfd = solaris_attropen(path, name, myflags, (mode_t) SOLARIS_ATTRMODE);
2192 ret = solaris_write_xattr(attrfd, value, size);
2202 int sys_lsetxattr (const char *path, const char *name, const void *value, size_t size, int flags)
2204 #if defined(HAVE_LSETXATTR)
2205 return lsetxattr(path, name, value, size, flags);
2206 #elif defined(HAVE_SETXATTR) && defined(XATTR_ADD_OPT)
2207 int options = XATTR_NOFOLLOW;
2208 return setxattr(path, name, value, size, 0, options);
2209 #elif defined(LSETEA)
2210 return lsetea(path, name, value, size, flags);
2211 #elif defined(HAVE_EXTATTR_SET_LINK)
2214 int attrnamespace = (strncmp(name, "system", 6) == 0) ?
2215 EXTATTR_NAMESPACE_SYSTEM : EXTATTR_NAMESPACE_USER;
2216 const char *attrname = ((s=strchr_m(name, '.')) == NULL) ? name : s + 1;
2218 /* Check attribute existence */
2219 retval = extattr_get_link(path, attrnamespace, attrname, NULL, 0);
2221 /* REPLACE attribute, that doesn't exist */
2222 if (flags & XATTR_REPLACE && errno == ENOATTR) {
2226 /* Ignore other errors */
2229 /* CREATE attribute, that already exists */
2230 if (flags & XATTR_CREATE) {
2237 retval = extattr_set_link(path, attrnamespace, attrname, value, size);
2238 return (retval < 0) ? -1 : 0;
2239 #elif defined(HAVE_ATTR_SET)
2240 int myflags = ATTR_DONTFOLLOW;
2241 char *attrname = strchr(name,'.') + 1;
2243 if (strncmp(name, "system", 6) == 0) myflags |= ATTR_ROOT;
2244 if (flags & XATTR_CREATE) myflags |= ATTR_CREATE;
2245 if (flags & XATTR_REPLACE) myflags |= ATTR_REPLACE;
2247 return attr_set(path, attrname, (const char *)value, size, myflags);
2248 #elif defined(HAVE_ATTROPEN)
2250 int myflags = O_RDWR | AT_SYMLINK_NOFOLLOW;
2252 if (flags & XATTR_CREATE) myflags |= O_EXCL;
2253 if (!(flags & XATTR_REPLACE)) myflags |= O_CREAT;
2254 attrfd = solaris_attropen(path, name, myflags, (mode_t) SOLARIS_ATTRMODE);
2256 ret = solaris_write_xattr(attrfd, value, size);
2266 int sys_fsetxattr (int filedes, const char *name, const void *value, size_t size, int flags)
2268 #if defined(HAVE_FSETXATTR)
2269 #ifndef XATTR_ADD_OPT
2270 return fsetxattr(filedes, name, value, size, flags);
2273 return fsetxattr(filedes, name, value, size, 0, options);
2275 #elif defined(HAVE_FSETEA)
2276 return fsetea(filedes, name, value, size, flags);
2277 #elif defined(HAVE_EXTATTR_SET_FD)
2280 int attrnamespace = (strncmp(name, "system", 6) == 0) ?
2281 EXTATTR_NAMESPACE_SYSTEM : EXTATTR_NAMESPACE_USER;
2282 const char *attrname = ((s=strchr_m(name, '.')) == NULL) ? name : s + 1;
2284 /* Check attribute existence */
2285 retval = extattr_get_fd(filedes, attrnamespace, attrname, NULL, 0);
2287 /* REPLACE attribute, that doesn't exist */
2288 if (flags & XATTR_REPLACE && errno == ENOATTR) {
2292 /* Ignore other errors */
2295 /* CREATE attribute, that already exists */
2296 if (flags & XATTR_CREATE) {
2302 retval = extattr_set_fd(filedes, attrnamespace, attrname, value, size);
2303 return (retval < 0) ? -1 : 0;
2304 #elif defined(HAVE_ATTR_SETF)
2306 char *attrname = strchr(name,'.') + 1;
2308 if (strncmp(name, "system", 6) == 0) myflags |= ATTR_ROOT;
2309 if (flags & XATTR_CREATE) myflags |= ATTR_CREATE;
2310 if (flags & XATTR_REPLACE) myflags |= ATTR_REPLACE;
2312 return attr_setf(filedes, attrname, (const char *)value, size, myflags);
2313 #elif defined(HAVE_ATTROPEN)
2315 int myflags = O_RDWR | O_XATTR;
2317 if (flags & XATTR_CREATE) myflags |= O_EXCL;
2318 if (!(flags & XATTR_REPLACE)) myflags |= O_CREAT;
2319 attrfd = solaris_openat(filedes, name, myflags, (mode_t) SOLARIS_ATTRMODE);
2321 ret = solaris_write_xattr(attrfd, value, size);
2331 /**************************************************************************
2332 helper functions for Solaris' EA support
2333 ****************************************************************************/
2334 #ifdef HAVE_ATTROPEN
2335 static ssize_t solaris_read_xattr(int attrfd, void *value, size_t size)
2339 if (fstat(attrfd, &sbuf) == -1) {
2344 /* This is to return the current size of the named extended attribute */
2346 return sbuf.st_size;
2349 /* check size and read xattr */
2350 if (sbuf.st_size > size) {
2355 return read(attrfd, value, sbuf.st_size);
2358 static ssize_t solaris_list_xattr(int attrdirfd, char *list, size_t size)
2363 int newfd = dup(attrdirfd);
2364 /* CAUTION: The originating file descriptor should not be
2365 used again following the call to fdopendir().
2366 For that reason we dup() the file descriptor
2367 here to make things more clear. */
2368 dirp = fdopendir(newfd);
2370 while ((de = readdir(dirp))) {
2371 size_t listlen = strlen(de->d_name) + 1;
2372 if (!strcmp(de->d_name, ".") || !strcmp(de->d_name, "..")) {
2373 /* we don't want "." and ".." here: */
2374 DEBUG(10,("skipped EA %s\n",de->d_name));
2379 /* return the current size of the list of extended attribute names*/
2382 /* check size and copy entrieѕ + nul into list. */
2383 if ((len + listlen) > size) {
2388 strlcpy(list + len, de->d_name, listlen);
2394 if (closedir(dirp) == -1) {
2395 DEBUG(0,("closedir dirp failed: %s\n",strerror(errno)));
2401 static int solaris_unlinkat(int attrdirfd, const char *name)
2403 if (unlinkat(attrdirfd, name, 0) == -1) {
2404 if (errno == ENOENT) {
2412 static int solaris_attropen(const char *path, const char *attrpath, int oflag, mode_t mode)
2414 int filedes = attropen(path, attrpath, oflag, mode);
2415 if (filedes == -1) {
2416 DEBUG(10,("attropen FAILED: path: %s, name: %s, errno: %s\n",path,attrpath,strerror(errno)));
2417 if (errno == EINVAL) {
2426 static int solaris_openat(int fildes, const char *path, int oflag, mode_t mode)
2428 int filedes = openat(fildes, path, oflag, mode);
2429 if (filedes == -1) {
2430 DEBUG(10,("openat FAILED: fd: %d, path: %s, errno: %s\n",filedes,path,strerror(errno)));
2431 if (errno == EINVAL) {
2440 static int solaris_write_xattr(int attrfd, const char *value, size_t size)
2442 if ((ftruncate(attrfd, 0) == 0) && (write(attrfd, value, size) == size)) {
2445 DEBUG(10,("solaris_write_xattr FAILED!\n"));
2449 #endif /*HAVE_ATTROPEN*/
2452 /****************************************************************************
2453 Return the major devicenumber for UNIX extensions.
2454 ****************************************************************************/
2456 uint32 unix_dev_major(SMB_DEV_T dev)
2458 #if defined(HAVE_DEVICE_MAJOR_FN)
2459 return (uint32)major(dev);
2461 return (uint32)(dev >> 8);
2465 /****************************************************************************
2466 Return the minor devicenumber for UNIX extensions.
2467 ****************************************************************************/
2469 uint32 unix_dev_minor(SMB_DEV_T dev)
2471 #if defined(HAVE_DEVICE_MINOR_FN)
2472 return (uint32)minor(dev);
2474 return (uint32)(dev & 0xff);
2478 #if defined(WITH_AIO)
2480 /*******************************************************************
2481 An aio_read wrapper that will deal with 64-bit sizes.
2482 ********************************************************************/
2484 int sys_aio_read(SMB_STRUCT_AIOCB *aiocb)
2486 #if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_AIOCB64) && defined(HAVE_AIO_READ64)
2487 return aio_read64(aiocb);
2488 #elif defined(HAVE_AIO_READ)
2489 return aio_read(aiocb);
2496 /*******************************************************************
2497 An aio_write wrapper that will deal with 64-bit sizes.
2498 ********************************************************************/
2500 int sys_aio_write(SMB_STRUCT_AIOCB *aiocb)
2502 #if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_AIOCB64) && defined(HAVE_AIO_WRITE64)
2503 return aio_write64(aiocb);
2504 #elif defined(HAVE_AIO_WRITE)
2505 return aio_write(aiocb);
2512 /*******************************************************************
2513 An aio_return wrapper that will deal with 64-bit sizes.
2514 ********************************************************************/
2516 ssize_t sys_aio_return(SMB_STRUCT_AIOCB *aiocb)
2518 #if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_AIOCB64) && defined(HAVE_AIO_RETURN64)
2519 return aio_return64(aiocb);
2520 #elif defined(HAVE_AIO_RETURN)
2521 return aio_return(aiocb);
2528 /*******************************************************************
2529 An aio_cancel wrapper that will deal with 64-bit sizes.
2530 ********************************************************************/
2532 int sys_aio_cancel(int fd, SMB_STRUCT_AIOCB *aiocb)
2534 #if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_AIOCB64) && defined(HAVE_AIO_CANCEL64)
2535 return aio_cancel64(fd, aiocb);
2536 #elif defined(HAVE_AIO_CANCEL)
2537 return aio_cancel(fd, aiocb);
2544 /*******************************************************************
2545 An aio_error wrapper that will deal with 64-bit sizes.
2546 ********************************************************************/
2548 int sys_aio_error(const SMB_STRUCT_AIOCB *aiocb)
2550 #if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_AIOCB64) && defined(HAVE_AIO_ERROR64)
2551 return aio_error64(aiocb);
2552 #elif defined(HAVE_AIO_ERROR)
2553 return aio_error(aiocb);
2560 /*******************************************************************
2561 An aio_fsync wrapper that will deal with 64-bit sizes.
2562 ********************************************************************/
2564 int sys_aio_fsync(int op, SMB_STRUCT_AIOCB *aiocb)
2566 #if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_AIOCB64) && defined(HAVE_AIO_FSYNC64)
2567 return aio_fsync64(op, aiocb);
2568 #elif defined(HAVE_AIO_FSYNC)
2569 return aio_fsync(op, aiocb);
2576 /*******************************************************************
2577 An aio_fsync wrapper that will deal with 64-bit sizes.
2578 ********************************************************************/
2580 int sys_aio_suspend(const SMB_STRUCT_AIOCB * const cblist[], int n, const struct timespec *timeout)
2582 #if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_AIOCB64) && defined(HAVE_AIO_SUSPEND64)
2583 return aio_suspend64(cblist, n, timeout);
2584 #elif defined(HAVE_AIO_FSYNC)
2585 return aio_suspend(cblist, n, timeout);
2591 #else /* !WITH_AIO */
2593 int sys_aio_read(SMB_STRUCT_AIOCB *aiocb)
2599 int sys_aio_write(SMB_STRUCT_AIOCB *aiocb)
2605 ssize_t sys_aio_return(SMB_STRUCT_AIOCB *aiocb)
2611 int sys_aio_cancel(int fd, SMB_STRUCT_AIOCB *aiocb)
2617 int sys_aio_error(const SMB_STRUCT_AIOCB *aiocb)
2623 int sys_aio_fsync(int op, SMB_STRUCT_AIOCB *aiocb)
2629 int sys_aio_suspend(const SMB_STRUCT_AIOCB * const cblist[], int n, const struct timespec *timeout)
2634 #endif /* WITH_AIO */