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"
29 #ifdef HAVE_SYS_SYSCTL_H
30 #include <sys/sysctl.h>
33 #ifdef HAVE_SYS_PRCTL_H
34 #include <sys/prctl.h>
38 The idea is that this file will eventually have wrappers around all
39 important system calls in samba. The aims are:
41 - to enable easier porting by putting OS dependent stuff in here
43 - to allow for hooks into other "pseudo-filesystems"
45 - to allow easier integration of things like the japanese extensions
47 - to support the philosophy of Samba to expose the features of
48 the OS within the SMB model. In general whatever file/printer/variable
49 expansions/etc make sense to the OS should be acceptable to Samba.
54 /*******************************************************************
55 A wrapper for usleep in case we don't have one.
56 ********************************************************************/
58 int sys_usleep(long usecs)
65 * We need this braindamage as the glibc usleep
66 * is not SPEC1170 complient... grumble... JRA.
69 if(usecs < 0 || usecs > 999999) {
77 #else /* HAVE_USLEEP */
79 * Fake it with select...
82 tval.tv_usec = usecs/1000;
83 select(0,NULL,NULL,NULL,&tval);
85 #endif /* HAVE_USLEEP */
88 /*******************************************************************
89 A read wrapper that will deal with EINTR.
90 ********************************************************************/
92 ssize_t sys_read(int fd, void *buf, size_t count)
97 ret = read(fd, buf, count);
98 #if defined(EWOULDBLOCK)
99 } while (ret == -1 && (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK));
101 } while (ret == -1 && (errno == EINTR || errno == EAGAIN));
106 /*******************************************************************
107 A write wrapper that will deal with EINTR.
108 ********************************************************************/
110 ssize_t sys_write(int fd, const void *buf, size_t count)
115 ret = write(fd, buf, count);
116 #if defined(EWOULDBLOCK)
117 } while (ret == -1 && (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK));
119 } while (ret == -1 && (errno == EINTR || errno == EAGAIN));
124 /*******************************************************************
125 A writev wrapper that will deal with EINTR.
126 ********************************************************************/
128 ssize_t sys_writev(int fd, const struct iovec *iov, int iovcnt)
133 /* Try to confuse write_data_iov a bit */
134 if ((random() % 5) == 0) {
135 return sys_write(fd, iov[0].iov_base, iov[0].iov_len);
137 if (iov[0].iov_len > 1) {
138 return sys_write(fd, iov[0].iov_base,
139 (random() % (iov[0].iov_len-1)) + 1);
144 ret = writev(fd, iov, iovcnt);
145 #if defined(EWOULDBLOCK)
146 } while (ret == -1 && (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK));
148 } while (ret == -1 && (errno == EINTR || errno == EAGAIN));
153 /*******************************************************************
154 A pread wrapper that will deal with EINTR and 64-bit file offsets.
155 ********************************************************************/
157 #if defined(HAVE_PREAD) || defined(HAVE_PREAD64)
158 ssize_t sys_pread(int fd, void *buf, size_t count, SMB_OFF_T off)
163 #if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_OFF64_T) && defined(HAVE_PREAD64)
164 ret = pread64(fd, buf, count, off);
166 ret = pread(fd, buf, count, off);
168 } while (ret == -1 && errno == EINTR);
173 /*******************************************************************
174 A write wrapper that will deal with EINTR and 64-bit file offsets.
175 ********************************************************************/
177 #if defined(HAVE_PWRITE) || defined(HAVE_PWRITE64)
178 ssize_t sys_pwrite(int fd, const void *buf, size_t count, SMB_OFF_T off)
183 #if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_OFF64_T) && defined(HAVE_PWRITE64)
184 ret = pwrite64(fd, buf, count, off);
186 ret = pwrite(fd, buf, count, off);
188 } while (ret == -1 && errno == EINTR);
193 /*******************************************************************
194 A send wrapper that will deal with EINTR or EAGAIN or EWOULDBLOCK.
195 ********************************************************************/
197 ssize_t sys_send(int s, const void *msg, size_t len, int flags)
202 ret = send(s, msg, len, flags);
203 #if defined(EWOULDBLOCK)
204 } while (ret == -1 && (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK));
206 } while (ret == -1 && (errno == EINTR || errno == EAGAIN));
211 /*******************************************************************
212 A sendto wrapper that will deal with EINTR or EAGAIN or EWOULDBLOCK.
213 ********************************************************************/
215 ssize_t sys_sendto(int s, const void *msg, size_t len, int flags, const struct sockaddr *to, socklen_t tolen)
220 ret = sendto(s, msg, len, flags, to, tolen);
221 #if defined(EWOULDBLOCK)
222 } while (ret == -1 && (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK));
224 } while (ret == -1 && (errno == EINTR || errno == EAGAIN));
229 /*******************************************************************
230 A recv wrapper that will deal with EINTR or EAGAIN or EWOULDBLOCK.
231 ********************************************************************/
233 ssize_t sys_recv(int fd, void *buf, size_t count, int flags)
238 ret = recv(fd, buf, count, flags);
239 #if defined(EWOULDBLOCK)
240 } while (ret == -1 && (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK));
242 } while (ret == -1 && (errno == EINTR || errno == EAGAIN));
247 /*******************************************************************
248 A recvfrom wrapper that will deal with EINTR.
249 ********************************************************************/
251 ssize_t sys_recvfrom(int s, void *buf, size_t len, int flags, struct sockaddr *from, socklen_t *fromlen)
256 ret = recvfrom(s, buf, len, flags, from, fromlen);
257 #if defined(EWOULDBLOCK)
258 } while (ret == -1 && (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK));
260 } while (ret == -1 && (errno == EINTR || errno == EAGAIN));
265 /*******************************************************************
266 A fcntl wrapper that will deal with EINTR.
267 ********************************************************************/
269 int sys_fcntl_ptr(int fd, int cmd, void *arg)
274 ret = fcntl(fd, cmd, arg);
275 } while (ret == -1 && errno == EINTR);
279 /*******************************************************************
280 A fcntl wrapper that will deal with EINTR.
281 ********************************************************************/
283 int sys_fcntl_long(int fd, int cmd, long arg)
288 ret = fcntl(fd, cmd, arg);
289 } while (ret == -1 && errno == EINTR);
293 /****************************************************************************
294 Get/Set all the possible time fields from a stat struct as a timespec.
295 ****************************************************************************/
297 static struct timespec get_atimespec(const struct stat *pst)
299 #if !defined(HAVE_STAT_HIRES_TIMESTAMPS)
302 /* Old system - no ns timestamp. */
303 ret.tv_sec = pst->st_atime;
307 #if defined(HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC)
309 #elif defined(HAVE_STRUCT_STAT_ST_MTIMENSEC)
311 ret.tv_sec = pst->st_atime;
312 ret.tv_nsec = pst->st_atimensec;
314 #elif defined(HAVE_STRUCT_STAT_ST_MTIME_N)
316 ret.tv_sec = pst->st_atime;
317 ret.tv_nsec = pst->st_atime_n;
319 #elif defined(HAVE_STRUCT_STAT_ST_UMTIME)
321 ret.tv_sec = pst->st_atime;
322 ret.tv_nsec = pst->st_uatime * 1000;
324 #elif defined(HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC)
325 return pst->st_atimespec;
327 #error CONFIGURE_ERROR_IN_DETECTING_TIMESPEC_IN_STAT
332 static struct timespec get_mtimespec(const struct stat *pst)
334 #if !defined(HAVE_STAT_HIRES_TIMESTAMPS)
337 /* Old system - no ns timestamp. */
338 ret.tv_sec = pst->st_mtime;
342 #if defined(HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC)
344 #elif defined(HAVE_STRUCT_STAT_ST_MTIMENSEC)
346 ret.tv_sec = pst->st_mtime;
347 ret.tv_nsec = pst->st_mtimensec;
349 #elif defined(HAVE_STRUCT_STAT_ST_MTIME_N)
351 ret.tv_sec = pst->st_mtime;
352 ret.tv_nsec = pst->st_mtime_n;
354 #elif defined(HAVE_STRUCT_STAT_ST_UMTIME)
356 ret.tv_sec = pst->st_mtime;
357 ret.tv_nsec = pst->st_umtime * 1000;
359 #elif defined(HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC)
360 return pst->st_mtimespec;
362 #error CONFIGURE_ERROR_IN_DETECTING_TIMESPEC_IN_STAT
367 static struct timespec get_ctimespec(const struct stat *pst)
369 #if !defined(HAVE_STAT_HIRES_TIMESTAMPS)
372 /* Old system - no ns timestamp. */
373 ret.tv_sec = pst->st_ctime;
377 #if defined(HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC)
379 #elif defined(HAVE_STRUCT_STAT_ST_MTIMENSEC)
381 ret.tv_sec = pst->st_ctime;
382 ret.tv_nsec = pst->st_ctimensec;
384 #elif defined(HAVE_STRUCT_STAT_ST_MTIME_N)
386 ret.tv_sec = pst->st_ctime;
387 ret.tv_nsec = pst->st_ctime_n;
389 #elif defined(HAVE_STRUCT_STAT_ST_UMTIME)
391 ret.tv_sec = pst->st_ctime;
392 ret.tv_nsec = pst->st_uctime * 1000;
394 #elif defined(HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC)
395 return pst->st_ctimespec;
397 #error CONFIGURE_ERROR_IN_DETECTING_TIMESPEC_IN_STAT
402 /****************************************************************************
403 Return the best approximation to a 'create time' under UNIX from a stat
405 ****************************************************************************/
407 static struct timespec calc_create_time_stat(const struct stat *st)
409 struct timespec ret, ret1;
410 struct timespec c_time = get_ctimespec(st);
411 struct timespec m_time = get_mtimespec(st);
412 struct timespec a_time = get_atimespec(st);
414 ret = timespec_compare(&c_time, &m_time) < 0 ? c_time : m_time;
415 ret1 = timespec_compare(&ret, &a_time) < 0 ? ret : a_time;
417 if(!null_timespec(ret1)) {
422 * One of ctime, mtime or atime was zero (probably atime).
423 * Just return MIN(ctime, mtime).
428 /****************************************************************************
429 Return the best approximation to a 'create time' under UNIX from a stat_ex
431 ****************************************************************************/
433 static struct timespec calc_create_time_stat_ex(const struct stat_ex *st)
435 struct timespec ret, ret1;
436 struct timespec c_time = st->st_ex_ctime;
437 struct timespec m_time = st->st_ex_mtime;
438 struct timespec a_time = st->st_ex_atime;
440 ret = timespec_compare(&c_time, &m_time) < 0 ? c_time : m_time;
441 ret1 = timespec_compare(&ret, &a_time) < 0 ? ret : a_time;
443 if(!null_timespec(ret1)) {
448 * One of ctime, mtime or atime was zero (probably atime).
449 * Just return MIN(ctime, mtime).
454 /****************************************************************************
455 Return the 'create time' from a stat struct if it exists (birthtime) or else
456 use the best approximation.
457 ****************************************************************************/
459 static void make_create_timespec(const struct stat *pst, struct stat_ex *dst,
460 bool fake_dir_create_times)
462 if (S_ISDIR(pst->st_mode) && fake_dir_create_times) {
463 dst->st_ex_btime.tv_sec = 315493200L; /* 1/1/1980 */
464 dst->st_ex_btime.tv_nsec = 0;
467 dst->st_ex_calculated_birthtime = false;
469 #if defined(HAVE_STRUCT_STAT_ST_BIRTHTIMESPEC_TV_NSEC)
470 dst->st_ex_btime = pst->st_birthtimespec;
471 #elif defined(HAVE_STRUCT_STAT_ST_BIRTHTIMENSEC)
472 dst->st_ex_btime.tv_sec = pst->st_birthtime;
473 dst->st_ex_btime.tv_nsec = pst->st_birthtimenspec;
474 #elif defined(HAVE_STRUCT_STAT_ST_BIRTHTIME)
475 dst->st_ex_btime.tv_sec = pst->st_birthtime;
476 dst->st_ex_btime.tv_nsec = 0;
478 dst->st_ex_btime = calc_create_time_stat(pst);
479 dst->st_ex_calculated_birthtime = true;
482 /* Deal with systems that don't initialize birthtime correctly.
483 * Pointed out by SATOH Fumiyasu <fumiyas@osstech.jp>.
485 if (null_timespec(dst->st_ex_btime)) {
486 dst->st_ex_btime = calc_create_time_stat(pst);
487 dst->st_ex_calculated_birthtime = true;
491 /****************************************************************************
492 If we update a timestamp in a stat_ex struct we may have to recalculate
493 the birthtime. For now only implement this for write time, but we may
494 also need to do it for atime and ctime. JRA.
495 ****************************************************************************/
497 void update_stat_ex_mtime(struct stat_ex *dst,
498 struct timespec write_ts)
500 dst->st_ex_mtime = write_ts;
502 /* We may have to recalculate btime. */
503 if (dst->st_ex_calculated_birthtime) {
504 dst->st_ex_btime = calc_create_time_stat_ex(dst);
508 void update_stat_ex_create_time(struct stat_ex *dst,
509 struct timespec create_time)
511 dst->st_ex_btime = create_time;
512 dst->st_ex_calculated_birthtime = false;
515 #if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_OFF64_T) && defined(HAVE_STAT64)
516 void init_stat_ex_from_stat (struct stat_ex *dst,
517 const struct stat64 *src,
518 bool fake_dir_create_times)
520 void init_stat_ex_from_stat (struct stat_ex *dst,
521 const struct stat *src,
522 bool fake_dir_create_times)
525 dst->st_ex_dev = src->st_dev;
526 dst->st_ex_ino = src->st_ino;
527 dst->st_ex_mode = src->st_mode;
528 dst->st_ex_nlink = src->st_nlink;
529 dst->st_ex_uid = src->st_uid;
530 dst->st_ex_gid = src->st_gid;
531 dst->st_ex_rdev = src->st_rdev;
532 dst->st_ex_size = src->st_size;
533 dst->st_ex_atime = get_atimespec(src);
534 dst->st_ex_mtime = get_mtimespec(src);
535 dst->st_ex_ctime = get_ctimespec(src);
536 make_create_timespec(src, dst, fake_dir_create_times);
537 #ifdef HAVE_STAT_ST_BLKSIZE
538 dst->st_ex_blksize = src->st_blksize;
540 dst->st_ex_blksize = STAT_ST_BLOCKSIZE;
543 #ifdef HAVE_STAT_ST_BLOCKS
544 dst->st_ex_blocks = src->st_blocks;
546 dst->st_ex_blocks = src->st_size / dst->st_ex_blksize + 1;
549 #ifdef HAVE_STAT_ST_FLAGS
550 dst->st_ex_flags = src->st_flags;
552 dst->st_ex_flags = 0;
556 /*******************************************************************
557 A stat() wrapper that will deal with 64 bit filesizes.
558 ********************************************************************/
560 int sys_stat(const char *fname, SMB_STRUCT_STAT *sbuf,
561 bool fake_dir_create_times)
564 #if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_OFF64_T) && defined(HAVE_STAT64)
565 struct stat64 statbuf;
566 ret = stat64(fname, &statbuf);
569 ret = stat(fname, &statbuf);
572 /* we always want directories to appear zero size */
573 if (S_ISDIR(statbuf.st_mode)) {
576 init_stat_ex_from_stat(sbuf, &statbuf, fake_dir_create_times);
581 /*******************************************************************
582 An fstat() wrapper that will deal with 64 bit filesizes.
583 ********************************************************************/
585 int sys_fstat(int fd, SMB_STRUCT_STAT *sbuf, bool fake_dir_create_times)
588 #if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_OFF64_T) && defined(HAVE_FSTAT64)
589 struct stat64 statbuf;
590 ret = fstat64(fd, &statbuf);
593 ret = fstat(fd, &statbuf);
596 /* we always want directories to appear zero size */
597 if (S_ISDIR(statbuf.st_mode)) {
600 init_stat_ex_from_stat(sbuf, &statbuf, fake_dir_create_times);
605 /*******************************************************************
606 An lstat() wrapper that will deal with 64 bit filesizes.
607 ********************************************************************/
609 int sys_lstat(const char *fname,SMB_STRUCT_STAT *sbuf,
610 bool fake_dir_create_times)
613 #if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_OFF64_T) && defined(HAVE_LSTAT64)
614 struct stat64 statbuf;
615 ret = lstat64(fname, &statbuf);
618 ret = lstat(fname, &statbuf);
621 /* we always want directories to appear zero size */
622 if (S_ISDIR(statbuf.st_mode)) {
625 init_stat_ex_from_stat(sbuf, &statbuf, fake_dir_create_times);
630 /*******************************************************************
631 An posix_fallocate() wrapper that will deal with 64 bit filesizes.
632 ********************************************************************/
633 int sys_posix_fallocate(int fd, SMB_OFF_T offset, SMB_OFF_T len)
635 #if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_OFF64_T) && defined(HAVE_POSIX_FALLOCATE64) && !defined(HAVE_BROKEN_POSIX_FALLOCATE)
636 return posix_fallocate64(fd, offset, len);
637 #elif defined(HAVE_POSIX_FALLOCATE) && !defined(HAVE_BROKEN_POSIX_FALLOCATE)
638 return posix_fallocate(fd, offset, len);
639 #elif defined(F_RESVSP64)
640 /* this handles XFS on IRIX */
642 SMB_OFF_T new_len = offset + len;
646 /* unlikely to get a too large file on a 64bit system but ... */
650 fl.l_whence = SEEK_SET;
654 ret=fcntl(fd, F_RESVSP64, &fl);
659 /* Make sure the file gets enlarged after we allocated space: */
661 if (new_len > sbuf.st_size)
662 ftruncate64(fd, new_len);
669 /*******************************************************************
670 An fallocate() function that matches the semantics of the Linux one.
671 ********************************************************************/
673 #ifdef HAVE_LINUX_FALLOC_H
674 #include <linux/falloc.h>
677 int sys_fallocate(int fd, enum vfs_fallocate_mode mode, SMB_OFF_T offset, SMB_OFF_T len)
679 #if defined(HAVE_LINUX_FALLOCATE64) || defined(HAVE_LINUX_FALLOCATE)
682 case VFS_FALLOCATE_EXTEND_SIZE:
685 case VFS_FALLOCATE_KEEP_SIZE:
686 lmode = FALLOC_FL_KEEP_SIZE;
692 #if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_OFF64_T) && defined(HAVE_LINUX_FALLOCATE64)
693 return fallocate64(fd, lmode, offset, len);
694 #elif defined(HAVE_LINUX_FALLOCATE)
695 return fallocate(fd, lmode, offset, len);
698 /* TODO - plumb in fallocate from other filesysetms like VXFS etc. JRA. */
704 /*******************************************************************
705 An ftruncate() wrapper that will deal with 64 bit filesizes.
706 ********************************************************************/
708 int sys_ftruncate(int fd, SMB_OFF_T offset)
710 #if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_OFF64_T) && defined(HAVE_FTRUNCATE64)
711 return ftruncate64(fd, offset);
713 return ftruncate(fd, offset);
717 /*******************************************************************
718 An lseek() wrapper that will deal with 64 bit filesizes.
719 ********************************************************************/
721 SMB_OFF_T sys_lseek(int fd, SMB_OFF_T offset, int whence)
723 #if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_OFF64_T) && defined(HAVE_LSEEK64)
724 return lseek64(fd, offset, whence);
726 return lseek(fd, offset, whence);
730 /*******************************************************************
731 An fseek() wrapper that will deal with 64 bit filesizes.
732 ********************************************************************/
734 int sys_fseek(FILE *fp, SMB_OFF_T offset, int whence)
736 #if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(LARGE_SMB_OFF_T) && defined(HAVE_FSEEK64)
737 return fseek64(fp, offset, whence);
738 #elif defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(LARGE_SMB_OFF_T) && defined(HAVE_FSEEKO64)
739 return fseeko64(fp, offset, whence);
740 #elif defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(LARGE_SMB_OFF_T) && defined(HAVE_FSEEKO)
741 return fseeko(fp, offset, whence);
743 return fseek(fp, offset, whence);
747 /*******************************************************************
748 An ftell() wrapper that will deal with 64 bit filesizes.
749 ********************************************************************/
751 SMB_OFF_T sys_ftell(FILE *fp)
753 #if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(LARGE_SMB_OFF_T) && defined(HAVE_FTELL64)
754 return (SMB_OFF_T)ftell64(fp);
755 #elif defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(LARGE_SMB_OFF_T) && defined(HAVE_FTELLO64)
756 return (SMB_OFF_T)ftello64(fp);
758 return (SMB_OFF_T)ftell(fp);
762 /*******************************************************************
763 A creat() wrapper that will deal with 64 bit filesizes.
764 ********************************************************************/
766 int sys_creat(const char *path, mode_t mode)
768 #if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_CREAT64)
769 return creat64(path, mode);
772 * If creat64 isn't defined then ensure we call a potential open64.
775 return sys_open(path, O_WRONLY | O_CREAT | O_TRUNC, mode);
779 /*******************************************************************
780 An open() wrapper that will deal with 64 bit filesizes.
781 ********************************************************************/
783 int sys_open(const char *path, int oflag, mode_t mode)
785 #if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_OPEN64)
786 return open64(path, oflag, mode);
788 return open(path, oflag, mode);
792 /*******************************************************************
793 An fopen() wrapper that will deal with 64 bit filesizes.
794 ********************************************************************/
796 FILE *sys_fopen(const char *path, const char *type)
798 #if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_FOPEN64)
799 return fopen64(path, type);
801 return fopen(path, type);
806 #if HAVE_KERNEL_SHARE_MODES
808 #define LOCK_MAND 32 /* This is a mandatory flock */
809 #define LOCK_READ 64 /* ... Which allows concurrent read operations */
810 #define LOCK_WRITE 128 /* ... Which allows concurrent write operations */
811 #define LOCK_RW 192 /* ... Which allows concurrent read & write ops */
815 /*******************************************************************
816 A flock() wrapper that will perform the kernel flock.
817 ********************************************************************/
819 void kernel_flock(int fd, uint32 share_mode, uint32 access_mask)
821 #if HAVE_KERNEL_SHARE_MODES
823 if (share_mode == FILE_SHARE_WRITE) {
824 kernel_mode = LOCK_MAND|LOCK_WRITE;
825 } else if (share_mode == FILE_SHARE_READ) {
826 kernel_mode = LOCK_MAND|LOCK_READ;
827 } else if (share_mode == FILE_SHARE_NONE) {
828 kernel_mode = LOCK_MAND;
831 flock(fd, kernel_mode);
839 /*******************************************************************
840 An opendir wrapper that will deal with 64 bit filesizes.
841 ********************************************************************/
843 SMB_STRUCT_DIR *sys_opendir(const char *name)
845 #if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_OPENDIR64)
846 return opendir64(name);
848 return opendir(name);
852 /*******************************************************************
853 An fdopendir wrapper that will deal with 64 bit filesizes.
854 Ugly hack - we need dirfd for this to work correctly in the
856 ********************************************************************/
858 SMB_STRUCT_DIR *sys_fdopendir(int fd)
860 #if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_FDOPENDIR64) && defined(HAVE_DIRFD)
861 return fdopendir64(fd);
862 #elif defined(HAVE_FDOPENDIR) && defined(HAVE_DIRFD)
863 return fdopendir(fd);
870 /*******************************************************************
871 A readdir wrapper that will deal with 64 bit filesizes.
872 ********************************************************************/
874 SMB_STRUCT_DIRENT *sys_readdir(SMB_STRUCT_DIR *dirp)
876 #if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_READDIR64)
877 return readdir64(dirp);
879 return readdir(dirp);
883 /*******************************************************************
884 A seekdir wrapper that will deal with 64 bit filesizes.
885 ********************************************************************/
887 void sys_seekdir(SMB_STRUCT_DIR *dirp, long offset)
889 #if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_SEEKDIR64)
890 seekdir64(dirp, offset);
892 seekdir(dirp, offset);
896 /*******************************************************************
897 A telldir wrapper that will deal with 64 bit filesizes.
898 ********************************************************************/
900 long sys_telldir(SMB_STRUCT_DIR *dirp)
902 #if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_TELLDIR64)
903 return (long)telldir64(dirp);
905 return (long)telldir(dirp);
909 /*******************************************************************
910 A rewinddir wrapper that will deal with 64 bit filesizes.
911 ********************************************************************/
913 void sys_rewinddir(SMB_STRUCT_DIR *dirp)
915 #if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_REWINDDIR64)
922 /*******************************************************************
923 A close wrapper that will deal with 64 bit filesizes.
924 ********************************************************************/
926 int sys_closedir(SMB_STRUCT_DIR *dirp)
928 #if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_CLOSEDIR64)
929 return closedir64(dirp);
931 return closedir(dirp);
935 /*******************************************************************
936 An mknod() wrapper that will deal with 64 bit filesizes.
937 ********************************************************************/
939 int sys_mknod(const char *path, mode_t mode, SMB_DEV_T dev)
941 #if defined(HAVE_MKNOD) || defined(HAVE_MKNOD64)
942 #if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_MKNOD64) && defined(HAVE_DEV64_T)
943 return mknod64(path, mode, dev);
945 return mknod(path, mode, dev);
948 /* No mknod system call. */
954 /*******************************************************************
955 The wait() calls vary between systems
956 ********************************************************************/
958 int sys_waitpid(pid_t pid,int *status,int options)
961 return waitpid(pid,status,options);
962 #else /* HAVE_WAITPID */
963 return wait4(pid, status, options, NULL);
964 #endif /* HAVE_WAITPID */
967 /*******************************************************************
968 System wrapper for getwd. Always returns MALLOC'ed memory, or NULL
969 on error (malloc fail usually).
970 ********************************************************************/
972 char *sys_getwd(void)
974 #ifdef GETCWD_TAKES_NULL
975 return getcwd(NULL, 0);
977 char *wd = NULL, *s = NULL;
978 size_t allocated = PATH_MAX;
981 s = SMB_REALLOC_ARRAY(s, char, allocated);
985 wd = getcwd(s, allocated);
989 if (errno != ERANGE) {
994 if (allocated < PATH_MAX) {
1001 char *s = SMB_MALLOC_ARRAY(char, PATH_MAX);
1009 #if defined(HAVE_POSIX_CAPABILITIES)
1011 /**************************************************************************
1012 Try and abstract process capabilities (for systems that have them).
1013 ****************************************************************************/
1015 /* Set the POSIX capabilities needed for the given purpose into the effective
1016 * capability set of the current process. Make sure they are always removed
1017 * from the inheritable set, because there is no circumstance in which our
1018 * children should inherit our elevated privileges.
1020 static bool set_process_capability(enum smbd_capability capability,
1023 cap_value_t cap_vals[2] = {0};
1024 int num_cap_vals = 0;
1028 #if defined(HAVE_PRCTL) && defined(PR_GET_KEEPCAPS) && defined(PR_SET_KEEPCAPS)
1029 /* On Linux, make sure that any capabilities we grab are sticky
1030 * across UID changes. We expect that this would allow us to keep both
1031 * the effective and permitted capability sets, but as of circa 2.6.16,
1032 * only the permitted set is kept. It is a bug (which we work around)
1033 * that the effective set is lost, but we still require the effective
1036 if (!prctl(PR_GET_KEEPCAPS)) {
1037 prctl(PR_SET_KEEPCAPS, 1);
1041 cap = cap_get_proc();
1043 DEBUG(0,("set_process_capability: cap_get_proc failed: %s\n",
1048 switch (capability) {
1049 case KERNEL_OPLOCK_CAPABILITY:
1050 #ifdef CAP_NETWORK_MGT
1051 /* IRIX has CAP_NETWORK_MGT for oplocks. */
1052 cap_vals[num_cap_vals++] = CAP_NETWORK_MGT;
1055 case DMAPI_ACCESS_CAPABILITY:
1056 #ifdef CAP_DEVICE_MGT
1057 /* IRIX has CAP_DEVICE_MGT for DMAPI access. */
1058 cap_vals[num_cap_vals++] = CAP_DEVICE_MGT;
1060 /* Linux has CAP_MKNOD for DMAPI access. */
1061 cap_vals[num_cap_vals++] = CAP_MKNOD;
1064 case LEASE_CAPABILITY:
1066 cap_vals[num_cap_vals++] = CAP_LEASE;
1071 SMB_ASSERT(num_cap_vals <= ARRAY_SIZE(cap_vals));
1073 if (num_cap_vals == 0) {
1078 cap_set_flag(cap, CAP_EFFECTIVE, num_cap_vals, cap_vals,
1079 enable ? CAP_SET : CAP_CLEAR);
1081 /* We never want to pass capabilities down to our children, so make
1082 * sure they are not inherited.
1084 cap_set_flag(cap, CAP_INHERITABLE, num_cap_vals, cap_vals, CAP_CLEAR);
1086 if (cap_set_proc(cap) == -1) {
1087 DEBUG(0, ("set_process_capability: cap_set_proc failed: %s\n",
1097 #endif /* HAVE_POSIX_CAPABILITIES */
1099 /****************************************************************************
1100 Gain the oplock capability from the kernel if possible.
1101 ****************************************************************************/
1103 void set_effective_capability(enum smbd_capability capability)
1105 #if defined(HAVE_POSIX_CAPABILITIES)
1106 set_process_capability(capability, True);
1107 #endif /* HAVE_POSIX_CAPABILITIES */
1110 void drop_effective_capability(enum smbd_capability capability)
1112 #if defined(HAVE_POSIX_CAPABILITIES)
1113 set_process_capability(capability, False);
1114 #endif /* HAVE_POSIX_CAPABILITIES */
1117 /**************************************************************************
1118 Wrapper for random().
1119 ****************************************************************************/
1121 long sys_random(void)
1123 #if defined(HAVE_RANDOM)
1124 return (long)random();
1125 #elif defined(HAVE_RAND)
1126 return (long)rand();
1128 DEBUG(0,("Error - no random function available !\n"));
1133 /**************************************************************************
1134 Wrapper for srandom().
1135 ****************************************************************************/
1137 void sys_srandom(unsigned int seed)
1139 #if defined(HAVE_SRANDOM)
1141 #elif defined(HAVE_SRAND)
1144 DEBUG(0,("Error - no srandom function available !\n"));
1150 #define NGROUPS_MAX 32 /* Guess... */
1153 /**************************************************************************
1154 Returns equivalent to NGROUPS_MAX - using sysconf if needed.
1155 ****************************************************************************/
1157 int groups_max(void)
1159 #if defined(SYSCONF_SC_NGROUPS_MAX)
1160 int ret = sysconf(_SC_NGROUPS_MAX);
1161 return (ret == -1) ? NGROUPS_MAX : ret;
1167 /**************************************************************************
1168 Wrap setgroups and getgroups for systems that declare getgroups() as
1169 returning an array of gid_t, but actuall return an array of int.
1170 ****************************************************************************/
1172 #if defined(HAVE_BROKEN_GETGROUPS)
1174 #ifdef HAVE_BROKEN_GETGROUPS
1180 static int sys_broken_getgroups(int setlen, gid_t *gidset)
1187 return getgroups(setlen, &gid);
1191 * Broken case. We need to allocate a
1192 * GID_T array of size setlen.
1201 setlen = groups_max();
1203 if((group_list = SMB_MALLOC_ARRAY(GID_T, setlen)) == NULL) {
1204 DEBUG(0,("sys_getgroups: Malloc fail.\n"));
1208 if((ngroups = getgroups(setlen, group_list)) < 0) {
1209 int saved_errno = errno;
1210 SAFE_FREE(group_list);
1211 errno = saved_errno;
1215 for(i = 0; i < ngroups; i++)
1216 gidset[i] = (gid_t)group_list[i];
1218 SAFE_FREE(group_list);
1222 static int sys_broken_setgroups(int setlen, gid_t *gidset)
1230 if (setlen < 0 || setlen > groups_max()) {
1236 * Broken case. We need to allocate a
1237 * GID_T array of size setlen.
1240 if((group_list = SMB_MALLOC_ARRAY(GID_T, setlen)) == NULL) {
1241 DEBUG(0,("sys_setgroups: Malloc fail.\n"));
1245 for(i = 0; i < setlen; i++)
1246 group_list[i] = (GID_T) gidset[i];
1248 if(setgroups(setlen, group_list) != 0) {
1249 int saved_errno = errno;
1250 SAFE_FREE(group_list);
1251 errno = saved_errno;
1255 SAFE_FREE(group_list);
1259 #endif /* HAVE_BROKEN_GETGROUPS */
1261 /* This is a list of systems that require the first GID passed to setgroups(2)
1262 * to be the effective GID. If your system is one of these, add it here.
1264 #if defined (FREEBSD) || defined (DARWINOS)
1265 #define USE_BSD_SETGROUPS
1268 #if defined(USE_BSD_SETGROUPS)
1269 /* Depending on the particular BSD implementation, the first GID that is
1270 * passed to setgroups(2) will either be ignored or will set the credential's
1271 * effective GID. In either case, the right thing to do is to guarantee that
1272 * gidset[0] is the effective GID.
1274 static int sys_bsd_setgroups(gid_t primary_gid, int setlen, const gid_t *gidset)
1276 gid_t *new_gidset = NULL;
1280 /* setgroups(2) will fail with EINVAL if we pass too many groups. */
1283 /* No group list, just make sure we are setting the efective GID. */
1285 return setgroups(1, &primary_gid);
1288 /* If the primary gid is not the first array element, grow the array
1289 * and insert it at the front.
1291 if (gidset[0] != primary_gid) {
1292 new_gidset = SMB_MALLOC_ARRAY(gid_t, setlen + 1);
1293 if (new_gidset == NULL) {
1297 memcpy(new_gidset + 1, gidset, (setlen * sizeof(gid_t)));
1298 new_gidset[0] = primary_gid;
1303 DEBUG(3, ("forced to truncate group list from %d to %d\n",
1308 #if defined(HAVE_BROKEN_GETGROUPS)
1309 ret = sys_broken_setgroups(setlen, new_gidset ? new_gidset : gidset);
1311 ret = setgroups(setlen, new_gidset ? new_gidset : gidset);
1316 SAFE_FREE(new_gidset);
1323 #endif /* USE_BSD_SETGROUPS */
1325 /**************************************************************************
1326 Wrapper for getgroups. Deals with broken (int) case.
1327 ****************************************************************************/
1329 int sys_getgroups(int setlen, gid_t *gidset)
1331 #if defined(HAVE_BROKEN_GETGROUPS)
1332 return sys_broken_getgroups(setlen, gidset);
1334 return getgroups(setlen, gidset);
1338 /**************************************************************************
1339 Wrapper for setgroups. Deals with broken (int) case and BSD case.
1340 ****************************************************************************/
1342 int sys_setgroups(gid_t UNUSED(primary_gid), int setlen, gid_t *gidset)
1344 #if !defined(HAVE_SETGROUPS)
1347 #endif /* HAVE_SETGROUPS */
1349 #if defined(USE_BSD_SETGROUPS)
1350 return sys_bsd_setgroups(primary_gid, setlen, gidset);
1351 #elif defined(HAVE_BROKEN_GETGROUPS)
1352 return sys_broken_setgroups(setlen, gidset);
1354 return setgroups(setlen, gidset);
1358 /**************************************************************************
1359 Extract a command into an arg list.
1360 ****************************************************************************/
1362 static char **extract_args(TALLOC_CTX *mem_ctx, const char *command)
1371 if (!(trunc_cmd = talloc_strdup(mem_ctx, command))) {
1372 DEBUG(0, ("talloc failed\n"));
1376 if(!(ptr = strtok_r(trunc_cmd, " \t", &saveptr))) {
1377 TALLOC_FREE(trunc_cmd);
1386 for( argcl = 1; ptr; ptr = strtok_r(NULL, " \t", &saveptr))
1389 TALLOC_FREE(trunc_cmd);
1391 if (!(argl = talloc_array(mem_ctx, char *, argcl + 1))) {
1396 * Now do the extraction.
1399 if (!(trunc_cmd = talloc_strdup(mem_ctx, command))) {
1403 ptr = strtok_r(trunc_cmd, " \t", &saveptr);
1406 if (!(argl[i++] = talloc_strdup(argl, ptr))) {
1410 while((ptr = strtok_r(NULL, " \t", &saveptr)) != NULL) {
1412 if (!(argl[i++] = talloc_strdup(argl, ptr))) {
1418 TALLOC_FREE(trunc_cmd);
1422 DEBUG(0, ("talloc failed\n"));
1423 TALLOC_FREE(trunc_cmd);
1429 /**************************************************************************
1430 Wrapper for popen. Safer as it doesn't search a path.
1431 Modified from the glibc sources.
1432 modified by tridge to return a file descriptor. We must kick our FILE* habit
1433 ****************************************************************************/
1435 typedef struct _popen_list
1439 struct _popen_list *next;
1442 static popen_list *popen_chain;
1444 int sys_popen(const char *command)
1446 int parent_end, child_end;
1448 popen_list *entry = NULL;
1451 if (pipe(pipe_fds) < 0)
1454 parent_end = pipe_fds[0];
1455 child_end = pipe_fds[1];
1462 if((entry = SMB_MALLOC_P(popen_list)) == NULL)
1465 ZERO_STRUCTP(entry);
1468 * Extract the command and args into a NULL terminated array.
1471 if(!(argl = extract_args(NULL, command)))
1474 entry->child_pid = sys_fork();
1476 if (entry->child_pid == -1) {
1480 if (entry->child_pid == 0) {
1486 int child_std_end = STDOUT_FILENO;
1490 if (child_end != child_std_end) {
1491 dup2 (child_end, child_std_end);
1496 * POSIX.2: "popen() shall ensure that any streams from previous
1497 * popen() calls that remain open in the parent process are closed
1498 * in the new child process."
1501 for (p = popen_chain; p; p = p->next)
1504 execv(argl[0], argl);
1515 /* Link into popen_chain. */
1516 entry->next = popen_chain;
1517 popen_chain = entry;
1518 entry->fd = parent_end;
1531 /**************************************************************************
1532 Wrapper for pclose. Modified from the glibc sources.
1533 ****************************************************************************/
1535 int sys_pclose(int fd)
1538 popen_list **ptr = &popen_chain;
1539 popen_list *entry = NULL;
1543 /* Unlink from popen_chain. */
1544 for ( ; *ptr != NULL; ptr = &(*ptr)->next) {
1545 if ((*ptr)->fd == fd) {
1547 *ptr = (*ptr)->next;
1553 if (status < 0 || close(entry->fd) < 0)
1557 * As Samba is catching and eating child process
1558 * exits we don't really care about the child exit
1559 * code, a -1 with errno = ECHILD will do fine for us.
1563 wait_pid = sys_waitpid (entry->child_pid, &wstatus, 0);
1564 } while (wait_pid == -1 && errno == EINTR);
1573 /**************************************************************************
1574 Wrapper for Admin Logs.
1575 ****************************************************************************/
1577 void sys_adminlog(int priority, const char *format_str, ...)
1581 char *msgbuf = NULL;
1583 va_start( ap, format_str );
1584 ret = vasprintf( &msgbuf, format_str, ap );
1590 #if defined(HAVE_SYSLOG)
1591 syslog( priority, "%s", msgbuf );
1593 DEBUG(0,("%s", msgbuf ));
1598 /******** Solaris EA helper function prototypes ********/
1599 #ifdef HAVE_ATTROPEN
1600 #define SOLARIS_ATTRMODE S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP
1601 static int solaris_write_xattr(int attrfd, const char *value, size_t size);
1602 static ssize_t solaris_read_xattr(int attrfd, void *value, size_t size);
1603 static ssize_t solaris_list_xattr(int attrdirfd, char *list, size_t size);
1604 static int solaris_unlinkat(int attrdirfd, const char *name);
1605 static int solaris_attropen(const char *path, const char *attrpath, int oflag, mode_t mode);
1606 static int solaris_openat(int fildes, const char *path, int oflag, mode_t mode);
1609 /**************************************************************************
1610 Wrappers for extented attribute calls. Based on the Linux package with
1611 support for IRIX and (Net|Free)BSD also. Expand as other systems have them.
1612 ****************************************************************************/
1614 ssize_t sys_getxattr (const char *path, const char *name, void *value, size_t size)
1616 #if defined(HAVE_GETXATTR)
1617 #ifndef XATTR_ADD_OPT
1618 return getxattr(path, name, value, size);
1621 return getxattr(path, name, value, size, 0, options);
1623 #elif defined(HAVE_GETEA)
1624 return getea(path, name, value, size);
1625 #elif defined(HAVE_EXTATTR_GET_FILE)
1628 int attrnamespace = (strncmp(name, "system", 6) == 0) ?
1629 EXTATTR_NAMESPACE_SYSTEM : EXTATTR_NAMESPACE_USER;
1630 const char *attrname = ((s=strchr_m(name, '.')) == NULL) ? name : s + 1;
1632 * The BSD implementation has a nasty habit of silently truncating
1633 * the returned value to the size of the buffer, so we have to check
1634 * that the buffer is large enough to fit the returned value.
1636 if((retval=extattr_get_file(path, attrnamespace, attrname, NULL, 0)) >= 0) {
1641 if((retval=extattr_get_file(path, attrnamespace, attrname, value, size)) >= 0)
1645 DEBUG(10,("sys_getxattr: extattr_get_file() failed with: %s\n", strerror(errno)));
1647 #elif defined(HAVE_ATTR_GET)
1648 int retval, flags = 0;
1649 int valuelength = (int)size;
1650 char *attrname = strchr(name,'.') + 1;
1652 if (strncmp(name, "system", 6) == 0) flags |= ATTR_ROOT;
1654 retval = attr_get(path, attrname, (char *)value, &valuelength, flags);
1656 return retval ? retval : valuelength;
1657 #elif defined(HAVE_ATTROPEN)
1659 int attrfd = solaris_attropen(path, name, O_RDONLY, 0);
1661 ret = solaris_read_xattr(attrfd, value, size);
1671 ssize_t sys_lgetxattr (const char *path, const char *name, void *value, size_t size)
1673 #if defined(HAVE_LGETXATTR)
1674 return lgetxattr(path, name, value, size);
1675 #elif defined(HAVE_GETXATTR) && defined(XATTR_ADD_OPT)
1676 int options = XATTR_NOFOLLOW;
1677 return getxattr(path, name, value, size, 0, options);
1678 #elif defined(HAVE_LGETEA)
1679 return lgetea(path, name, value, size);
1680 #elif defined(HAVE_EXTATTR_GET_LINK)
1683 int attrnamespace = (strncmp(name, "system", 6) == 0) ?
1684 EXTATTR_NAMESPACE_SYSTEM : EXTATTR_NAMESPACE_USER;
1685 const char *attrname = ((s=strchr_m(name, '.')) == NULL) ? name : s + 1;
1687 if((retval=extattr_get_link(path, attrnamespace, attrname, NULL, 0)) >= 0) {
1692 if((retval=extattr_get_link(path, attrnamespace, attrname, value, size)) >= 0)
1696 DEBUG(10,("sys_lgetxattr: extattr_get_link() failed with: %s\n", strerror(errno)));
1698 #elif defined(HAVE_ATTR_GET)
1699 int retval, flags = ATTR_DONTFOLLOW;
1700 int valuelength = (int)size;
1701 char *attrname = strchr(name,'.') + 1;
1703 if (strncmp(name, "system", 6) == 0) flags |= ATTR_ROOT;
1705 retval = attr_get(path, attrname, (char *)value, &valuelength, flags);
1707 return retval ? retval : valuelength;
1708 #elif defined(HAVE_ATTROPEN)
1710 int attrfd = solaris_attropen(path, name, O_RDONLY|AT_SYMLINK_NOFOLLOW, 0);
1712 ret = solaris_read_xattr(attrfd, value, size);
1722 ssize_t sys_fgetxattr (int filedes, const char *name, void *value, size_t size)
1724 #if defined(HAVE_FGETXATTR)
1725 #ifndef XATTR_ADD_OPT
1726 return fgetxattr(filedes, name, value, size);
1729 return fgetxattr(filedes, name, value, size, 0, options);
1731 #elif defined(HAVE_FGETEA)
1732 return fgetea(filedes, name, value, size);
1733 #elif defined(HAVE_EXTATTR_GET_FD)
1736 int attrnamespace = (strncmp(name, "system", 6) == 0) ?
1737 EXTATTR_NAMESPACE_SYSTEM : EXTATTR_NAMESPACE_USER;
1738 const char *attrname = ((s=strchr_m(name, '.')) == NULL) ? name : s + 1;
1740 if((retval=extattr_get_fd(filedes, attrnamespace, attrname, NULL, 0)) >= 0) {
1745 if((retval=extattr_get_fd(filedes, attrnamespace, attrname, value, size)) >= 0)
1749 DEBUG(10,("sys_fgetxattr: extattr_get_fd() failed with: %s\n", strerror(errno)));
1751 #elif defined(HAVE_ATTR_GETF)
1752 int retval, flags = 0;
1753 int valuelength = (int)size;
1754 char *attrname = strchr(name,'.') + 1;
1756 if (strncmp(name, "system", 6) == 0) flags |= ATTR_ROOT;
1758 retval = attr_getf(filedes, attrname, (char *)value, &valuelength, flags);
1760 return retval ? retval : valuelength;
1761 #elif defined(HAVE_ATTROPEN)
1763 int attrfd = solaris_openat(filedes, name, O_RDONLY|O_XATTR, 0);
1765 ret = solaris_read_xattr(attrfd, value, size);
1775 #if defined(HAVE_EXTATTR_LIST_FILE)
1777 #define EXTATTR_PREFIX(s) (s), (sizeof((s))-1)
1785 { EXTATTR_NAMESPACE_SYSTEM, EXTATTR_PREFIX("system.") },
1786 { EXTATTR_NAMESPACE_USER, EXTATTR_PREFIX("user.") },
1794 static ssize_t bsd_attr_list (int type, extattr_arg arg, char *list, size_t size)
1796 ssize_t list_size, total_size = 0;
1799 /* Iterate through extattr(2) namespaces */
1800 for(t = 0; t < ARRAY_SIZE(extattr); t++) {
1802 #if defined(HAVE_EXTATTR_LIST_FILE)
1804 list_size = extattr_list_file(arg.path, extattr[t].space, list, size);
1807 #if defined(HAVE_EXTATTR_LIST_LINK)
1809 list_size = extattr_list_link(arg.path, extattr[t].space, list, size);
1812 #if defined(HAVE_EXTATTR_LIST_FD)
1814 list_size = extattr_list_fd(arg.filedes, extattr[t].space, list, size);
1821 /* Some error happend. Errno should be set by the previous call */
1827 /* XXX: Call with an empty buffer may be used to calculate
1828 necessary buffer size. Unfortunately, we can't say, how
1829 many attributes were returned, so here is the potential
1830 problem with the emulation.
1833 /* Take the worse case of one char attribute names -
1834 two bytes per name plus one more for sanity.
1836 total_size += list_size + (list_size/2 + 1)*extattr[t].len;
1839 /* Count necessary offset to fit namespace prefixes */
1841 for(i = 0; i < list_size; i += list[i] + 1)
1842 len += extattr[t].len;
1844 total_size += list_size + len;
1845 /* Buffer is too small to fit the results */
1846 if(total_size > size) {
1850 /* Shift results back, so we can prepend prefixes */
1851 buf = (char *)memmove(list + len, list, list_size);
1853 for(i = 0; i < list_size; i += len + 1) {
1855 strncpy(list, extattr[t].name, extattr[t].len + 1);
1856 list += extattr[t].len;
1857 strncpy(list, buf + i + 1, len);
1868 #if defined(HAVE_ATTR_LIST) && defined(HAVE_SYS_ATTRIBUTES_H)
1869 static char attr_buffer[ATTR_MAX_VALUELEN];
1871 static ssize_t irix_attr_list(const char *path, int filedes, char *list, size_t size, int flags)
1873 int retval = 0, index;
1874 attrlist_cursor_t *cursor = 0;
1876 attrlist_t * al = (attrlist_t *)attr_buffer;
1878 size_t ent_size, left = size;
1883 retval = attr_listf(filedes, attr_buffer, ATTR_MAX_VALUELEN, flags, cursor);
1885 retval = attr_list(path, attr_buffer, ATTR_MAX_VALUELEN, flags, cursor);
1887 for (index = 0; index < al->al_count; index++) {
1888 ae = ATTR_ENTRY(attr_buffer, index);
1889 ent_size = strlen(ae->a_name) + sizeof("user.");
1890 if (left >= ent_size) {
1891 strncpy(bp, "user.", sizeof("user."));
1892 strncat(bp, ae->a_name, ent_size - sizeof("user."));
1900 total_size += ent_size;
1902 if (al->al_more == 0) break;
1909 retval = attr_listf(filedes, attr_buffer, ATTR_MAX_VALUELEN, flags, cursor);
1911 retval = attr_list(path, attr_buffer, ATTR_MAX_VALUELEN, flags, cursor);
1913 for (index = 0; index < al->al_count; index++) {
1914 ae = ATTR_ENTRY(attr_buffer, index);
1915 ent_size = strlen(ae->a_name) + sizeof("system.");
1916 if (left >= ent_size) {
1917 strncpy(bp, "system.", sizeof("system."));
1918 strncat(bp, ae->a_name, ent_size - sizeof("system."));
1926 total_size += ent_size;
1928 if (al->al_more == 0) break;
1931 return (ssize_t)(retval ? retval : total_size);
1936 ssize_t sys_listxattr (const char *path, char *list, size_t size)
1938 #if defined(HAVE_LISTXATTR)
1939 #ifndef XATTR_ADD_OPT
1940 return listxattr(path, list, size);
1943 return listxattr(path, list, size, options);
1945 #elif defined(HAVE_LISTEA)
1946 return listea(path, list, size);
1947 #elif defined(HAVE_EXTATTR_LIST_FILE)
1950 return bsd_attr_list(0, arg, list, size);
1951 #elif defined(HAVE_ATTR_LIST) && defined(HAVE_SYS_ATTRIBUTES_H)
1952 return irix_attr_list(path, 0, list, size, 0);
1953 #elif defined(HAVE_ATTROPEN)
1955 int attrdirfd = solaris_attropen(path, ".", O_RDONLY, 0);
1956 if (attrdirfd >= 0) {
1957 ret = solaris_list_xattr(attrdirfd, list, size);
1967 ssize_t sys_llistxattr (const char *path, char *list, size_t size)
1969 #if defined(HAVE_LLISTXATTR)
1970 return llistxattr(path, list, size);
1971 #elif defined(HAVE_LISTXATTR) && defined(XATTR_ADD_OPT)
1972 int options = XATTR_NOFOLLOW;
1973 return listxattr(path, list, size, options);
1974 #elif defined(HAVE_LLISTEA)
1975 return llistea(path, list, size);
1976 #elif defined(HAVE_EXTATTR_LIST_LINK)
1979 return bsd_attr_list(1, arg, list, size);
1980 #elif defined(HAVE_ATTR_LIST) && defined(HAVE_SYS_ATTRIBUTES_H)
1981 return irix_attr_list(path, 0, list, size, ATTR_DONTFOLLOW);
1982 #elif defined(HAVE_ATTROPEN)
1984 int attrdirfd = solaris_attropen(path, ".", O_RDONLY|AT_SYMLINK_NOFOLLOW, 0);
1985 if (attrdirfd >= 0) {
1986 ret = solaris_list_xattr(attrdirfd, list, size);
1996 ssize_t sys_flistxattr (int filedes, char *list, size_t size)
1998 #if defined(HAVE_FLISTXATTR)
1999 #ifndef XATTR_ADD_OPT
2000 return flistxattr(filedes, list, size);
2003 return flistxattr(filedes, list, size, options);
2005 #elif defined(HAVE_FLISTEA)
2006 return flistea(filedes, list, size);
2007 #elif defined(HAVE_EXTATTR_LIST_FD)
2009 arg.filedes = filedes;
2010 return bsd_attr_list(2, arg, list, size);
2011 #elif defined(HAVE_ATTR_LISTF)
2012 return irix_attr_list(NULL, filedes, list, size, 0);
2013 #elif defined(HAVE_ATTROPEN)
2015 int attrdirfd = solaris_openat(filedes, ".", O_RDONLY|O_XATTR, 0);
2016 if (attrdirfd >= 0) {
2017 ret = solaris_list_xattr(attrdirfd, list, size);
2027 int sys_removexattr (const char *path, const char *name)
2029 #if defined(HAVE_REMOVEXATTR)
2030 #ifndef XATTR_ADD_OPT
2031 return removexattr(path, name);
2034 return removexattr(path, name, options);
2036 #elif defined(HAVE_REMOVEEA)
2037 return removeea(path, name);
2038 #elif defined(HAVE_EXTATTR_DELETE_FILE)
2040 int attrnamespace = (strncmp(name, "system", 6) == 0) ?
2041 EXTATTR_NAMESPACE_SYSTEM : EXTATTR_NAMESPACE_USER;
2042 const char *attrname = ((s=strchr_m(name, '.')) == NULL) ? name : s + 1;
2044 return extattr_delete_file(path, attrnamespace, attrname);
2045 #elif defined(HAVE_ATTR_REMOVE)
2047 char *attrname = strchr(name,'.') + 1;
2049 if (strncmp(name, "system", 6) == 0) flags |= ATTR_ROOT;
2051 return attr_remove(path, attrname, flags);
2052 #elif defined(HAVE_ATTROPEN)
2054 int attrdirfd = solaris_attropen(path, ".", O_RDONLY, 0);
2055 if (attrdirfd >= 0) {
2056 ret = solaris_unlinkat(attrdirfd, name);
2066 int sys_lremovexattr (const char *path, const char *name)
2068 #if defined(HAVE_LREMOVEXATTR)
2069 return lremovexattr(path, name);
2070 #elif defined(HAVE_REMOVEXATTR) && defined(XATTR_ADD_OPT)
2071 int options = XATTR_NOFOLLOW;
2072 return removexattr(path, name, options);
2073 #elif defined(HAVE_LREMOVEEA)
2074 return lremoveea(path, name);
2075 #elif defined(HAVE_EXTATTR_DELETE_LINK)
2077 int attrnamespace = (strncmp(name, "system", 6) == 0) ?
2078 EXTATTR_NAMESPACE_SYSTEM : EXTATTR_NAMESPACE_USER;
2079 const char *attrname = ((s=strchr_m(name, '.')) == NULL) ? name : s + 1;
2081 return extattr_delete_link(path, attrnamespace, attrname);
2082 #elif defined(HAVE_ATTR_REMOVE)
2083 int flags = ATTR_DONTFOLLOW;
2084 char *attrname = strchr(name,'.') + 1;
2086 if (strncmp(name, "system", 6) == 0) flags |= ATTR_ROOT;
2088 return attr_remove(path, attrname, flags);
2089 #elif defined(HAVE_ATTROPEN)
2091 int attrdirfd = solaris_attropen(path, ".", O_RDONLY|AT_SYMLINK_NOFOLLOW, 0);
2092 if (attrdirfd >= 0) {
2093 ret = solaris_unlinkat(attrdirfd, name);
2103 int sys_fremovexattr (int filedes, const char *name)
2105 #if defined(HAVE_FREMOVEXATTR)
2106 #ifndef XATTR_ADD_OPT
2107 return fremovexattr(filedes, name);
2110 return fremovexattr(filedes, name, options);
2112 #elif defined(HAVE_FREMOVEEA)
2113 return fremoveea(filedes, name);
2114 #elif defined(HAVE_EXTATTR_DELETE_FD)
2116 int attrnamespace = (strncmp(name, "system", 6) == 0) ?
2117 EXTATTR_NAMESPACE_SYSTEM : EXTATTR_NAMESPACE_USER;
2118 const char *attrname = ((s=strchr_m(name, '.')) == NULL) ? name : s + 1;
2120 return extattr_delete_fd(filedes, attrnamespace, attrname);
2121 #elif defined(HAVE_ATTR_REMOVEF)
2123 char *attrname = strchr(name,'.') + 1;
2125 if (strncmp(name, "system", 6) == 0) flags |= ATTR_ROOT;
2127 return attr_removef(filedes, attrname, flags);
2128 #elif defined(HAVE_ATTROPEN)
2130 int attrdirfd = solaris_openat(filedes, ".", O_RDONLY|O_XATTR, 0);
2131 if (attrdirfd >= 0) {
2132 ret = solaris_unlinkat(attrdirfd, name);
2142 int sys_setxattr (const char *path, const char *name, const void *value, size_t size, int flags)
2144 #if defined(HAVE_SETXATTR)
2145 #ifndef XATTR_ADD_OPT
2146 return setxattr(path, name, value, size, flags);
2149 return setxattr(path, name, value, size, 0, options);
2151 #elif defined(HAVE_SETEA)
2152 return setea(path, name, value, size, flags);
2153 #elif defined(HAVE_EXTATTR_SET_FILE)
2156 int attrnamespace = (strncmp(name, "system", 6) == 0) ?
2157 EXTATTR_NAMESPACE_SYSTEM : EXTATTR_NAMESPACE_USER;
2158 const char *attrname = ((s=strchr_m(name, '.')) == NULL) ? name : s + 1;
2160 /* Check attribute existence */
2161 retval = extattr_get_file(path, attrnamespace, attrname, NULL, 0);
2163 /* REPLACE attribute, that doesn't exist */
2164 if (flags & XATTR_REPLACE && errno == ENOATTR) {
2168 /* Ignore other errors */
2171 /* CREATE attribute, that already exists */
2172 if (flags & XATTR_CREATE) {
2178 retval = extattr_set_file(path, attrnamespace, attrname, value, size);
2179 return (retval < 0) ? -1 : 0;
2180 #elif defined(HAVE_ATTR_SET)
2182 char *attrname = strchr(name,'.') + 1;
2184 if (strncmp(name, "system", 6) == 0) myflags |= ATTR_ROOT;
2185 if (flags & XATTR_CREATE) myflags |= ATTR_CREATE;
2186 if (flags & XATTR_REPLACE) myflags |= ATTR_REPLACE;
2188 return attr_set(path, attrname, (const char *)value, size, myflags);
2189 #elif defined(HAVE_ATTROPEN)
2191 int myflags = O_RDWR;
2193 if (flags & XATTR_CREATE) myflags |= O_EXCL;
2194 if (!(flags & XATTR_REPLACE)) myflags |= O_CREAT;
2195 attrfd = solaris_attropen(path, name, myflags, (mode_t) SOLARIS_ATTRMODE);
2197 ret = solaris_write_xattr(attrfd, value, size);
2207 int sys_lsetxattr (const char *path, const char *name, const void *value, size_t size, int flags)
2209 #if defined(HAVE_LSETXATTR)
2210 return lsetxattr(path, name, value, size, flags);
2211 #elif defined(HAVE_SETXATTR) && defined(XATTR_ADD_OPT)
2212 int options = XATTR_NOFOLLOW;
2213 return setxattr(path, name, value, size, 0, options);
2214 #elif defined(LSETEA)
2215 return lsetea(path, name, value, size, flags);
2216 #elif defined(HAVE_EXTATTR_SET_LINK)
2219 int attrnamespace = (strncmp(name, "system", 6) == 0) ?
2220 EXTATTR_NAMESPACE_SYSTEM : EXTATTR_NAMESPACE_USER;
2221 const char *attrname = ((s=strchr_m(name, '.')) == NULL) ? name : s + 1;
2223 /* Check attribute existence */
2224 retval = extattr_get_link(path, attrnamespace, attrname, NULL, 0);
2226 /* REPLACE attribute, that doesn't exist */
2227 if (flags & XATTR_REPLACE && errno == ENOATTR) {
2231 /* Ignore other errors */
2234 /* CREATE attribute, that already exists */
2235 if (flags & XATTR_CREATE) {
2242 retval = extattr_set_link(path, attrnamespace, attrname, value, size);
2243 return (retval < 0) ? -1 : 0;
2244 #elif defined(HAVE_ATTR_SET)
2245 int myflags = ATTR_DONTFOLLOW;
2246 char *attrname = strchr(name,'.') + 1;
2248 if (strncmp(name, "system", 6) == 0) myflags |= ATTR_ROOT;
2249 if (flags & XATTR_CREATE) myflags |= ATTR_CREATE;
2250 if (flags & XATTR_REPLACE) myflags |= ATTR_REPLACE;
2252 return attr_set(path, attrname, (const char *)value, size, myflags);
2253 #elif defined(HAVE_ATTROPEN)
2255 int myflags = O_RDWR | AT_SYMLINK_NOFOLLOW;
2257 if (flags & XATTR_CREATE) myflags |= O_EXCL;
2258 if (!(flags & XATTR_REPLACE)) myflags |= O_CREAT;
2259 attrfd = solaris_attropen(path, name, myflags, (mode_t) SOLARIS_ATTRMODE);
2261 ret = solaris_write_xattr(attrfd, value, size);
2271 int sys_fsetxattr (int filedes, const char *name, const void *value, size_t size, int flags)
2273 #if defined(HAVE_FSETXATTR)
2274 #ifndef XATTR_ADD_OPT
2275 return fsetxattr(filedes, name, value, size, flags);
2278 return fsetxattr(filedes, name, value, size, 0, options);
2280 #elif defined(HAVE_FSETEA)
2281 return fsetea(filedes, name, value, size, flags);
2282 #elif defined(HAVE_EXTATTR_SET_FD)
2285 int attrnamespace = (strncmp(name, "system", 6) == 0) ?
2286 EXTATTR_NAMESPACE_SYSTEM : EXTATTR_NAMESPACE_USER;
2287 const char *attrname = ((s=strchr_m(name, '.')) == NULL) ? name : s + 1;
2289 /* Check attribute existence */
2290 retval = extattr_get_fd(filedes, attrnamespace, attrname, NULL, 0);
2292 /* REPLACE attribute, that doesn't exist */
2293 if (flags & XATTR_REPLACE && errno == ENOATTR) {
2297 /* Ignore other errors */
2300 /* CREATE attribute, that already exists */
2301 if (flags & XATTR_CREATE) {
2307 retval = extattr_set_fd(filedes, attrnamespace, attrname, value, size);
2308 return (retval < 0) ? -1 : 0;
2309 #elif defined(HAVE_ATTR_SETF)
2311 char *attrname = strchr(name,'.') + 1;
2313 if (strncmp(name, "system", 6) == 0) myflags |= ATTR_ROOT;
2314 if (flags & XATTR_CREATE) myflags |= ATTR_CREATE;
2315 if (flags & XATTR_REPLACE) myflags |= ATTR_REPLACE;
2317 return attr_setf(filedes, attrname, (const char *)value, size, myflags);
2318 #elif defined(HAVE_ATTROPEN)
2320 int myflags = O_RDWR | O_XATTR;
2322 if (flags & XATTR_CREATE) myflags |= O_EXCL;
2323 if (!(flags & XATTR_REPLACE)) myflags |= O_CREAT;
2324 attrfd = solaris_openat(filedes, name, myflags, (mode_t) SOLARIS_ATTRMODE);
2326 ret = solaris_write_xattr(attrfd, value, size);
2336 /**************************************************************************
2337 helper functions for Solaris' EA support
2338 ****************************************************************************/
2339 #ifdef HAVE_ATTROPEN
2340 static ssize_t solaris_read_xattr(int attrfd, void *value, size_t size)
2344 if (fstat(attrfd, &sbuf) == -1) {
2349 /* This is to return the current size of the named extended attribute */
2351 return sbuf.st_size;
2354 /* check size and read xattr */
2355 if (sbuf.st_size > size) {
2360 return read(attrfd, value, sbuf.st_size);
2363 static ssize_t solaris_list_xattr(int attrdirfd, char *list, size_t size)
2368 int newfd = dup(attrdirfd);
2369 /* CAUTION: The originating file descriptor should not be
2370 used again following the call to fdopendir().
2371 For that reason we dup() the file descriptor
2372 here to make things more clear. */
2373 dirp = fdopendir(newfd);
2375 while ((de = readdir(dirp))) {
2376 size_t listlen = strlen(de->d_name) + 1;
2377 if (!strcmp(de->d_name, ".") || !strcmp(de->d_name, "..")) {
2378 /* we don't want "." and ".." here: */
2379 DEBUG(10,("skipped EA %s\n",de->d_name));
2384 /* return the current size of the list of extended attribute names*/
2387 /* check size and copy entrieѕ + nul into list. */
2388 if ((len + listlen) > size) {
2393 strlcpy(list + len, de->d_name, listlen);
2399 if (closedir(dirp) == -1) {
2400 DEBUG(0,("closedir dirp failed: %s\n",strerror(errno)));
2406 static int solaris_unlinkat(int attrdirfd, const char *name)
2408 if (unlinkat(attrdirfd, name, 0) == -1) {
2409 if (errno == ENOENT) {
2417 static int solaris_attropen(const char *path, const char *attrpath, int oflag, mode_t mode)
2419 int filedes = attropen(path, attrpath, oflag, mode);
2420 if (filedes == -1) {
2421 DEBUG(10,("attropen FAILED: path: %s, name: %s, errno: %s\n",path,attrpath,strerror(errno)));
2422 if (errno == EINVAL) {
2431 static int solaris_openat(int fildes, const char *path, int oflag, mode_t mode)
2433 int filedes = openat(fildes, path, oflag, mode);
2434 if (filedes == -1) {
2435 DEBUG(10,("openat FAILED: fd: %d, path: %s, errno: %s\n",filedes,path,strerror(errno)));
2436 if (errno == EINVAL) {
2445 static int solaris_write_xattr(int attrfd, const char *value, size_t size)
2447 if ((ftruncate(attrfd, 0) == 0) && (write(attrfd, value, size) == size)) {
2450 DEBUG(10,("solaris_write_xattr FAILED!\n"));
2454 #endif /*HAVE_ATTROPEN*/
2457 /****************************************************************************
2458 Return the major devicenumber for UNIX extensions.
2459 ****************************************************************************/
2461 uint32 unix_dev_major(SMB_DEV_T dev)
2463 #if defined(HAVE_DEVICE_MAJOR_FN)
2464 return (uint32)major(dev);
2466 return (uint32)(dev >> 8);
2470 /****************************************************************************
2471 Return the minor devicenumber for UNIX extensions.
2472 ****************************************************************************/
2474 uint32 unix_dev_minor(SMB_DEV_T dev)
2476 #if defined(HAVE_DEVICE_MINOR_FN)
2477 return (uint32)minor(dev);
2479 return (uint32)(dev & 0xff);
2484 /*******************************************************************
2485 Return the number of CPUs.
2486 ********************************************************************/
2488 int sys_get_number_of_cores(void)
2492 #if defined(HAVE_SYSCONF)
2493 #if defined(_SC_NPROCESSORS_ONLN)
2494 ret = (int)sysconf(_SC_NPROCESSORS_ONLN);
2496 #if defined(_SC_NPROCESSORS_CONF)
2498 ret = (int)sysconf(_SC_NPROCESSORS_CONF);
2501 #elif defined(HAVE_SYSCTL) && defined(CTL_HW)
2503 unsigned int len = sizeof(ret);
2506 #if defined(HW_AVAILCPU)
2507 name[1] = HW_AVAILCPU;
2509 if (sysctl(name, 2, &ret, &len, NULL, 0) == -1) {
2513 #if defined(HW_NCPU)
2517 if (sysctl(nm, 2, &count, &len, NULL, 0) == -1) {
2530 #if defined(WITH_AIO)
2532 /*******************************************************************
2533 An aio_read wrapper that will deal with 64-bit sizes.
2534 ********************************************************************/
2536 int sys_aio_read(SMB_STRUCT_AIOCB *aiocb)
2538 #if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_AIOCB64) && defined(HAVE_AIO_READ64)
2539 return aio_read64(aiocb);
2540 #elif defined(HAVE_AIO_READ)
2541 return aio_read(aiocb);
2548 /*******************************************************************
2549 An aio_write wrapper that will deal with 64-bit sizes.
2550 ********************************************************************/
2552 int sys_aio_write(SMB_STRUCT_AIOCB *aiocb)
2554 #if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_AIOCB64) && defined(HAVE_AIO_WRITE64)
2555 return aio_write64(aiocb);
2556 #elif defined(HAVE_AIO_WRITE)
2557 return aio_write(aiocb);
2564 /*******************************************************************
2565 An aio_return wrapper that will deal with 64-bit sizes.
2566 ********************************************************************/
2568 ssize_t sys_aio_return(SMB_STRUCT_AIOCB *aiocb)
2570 #if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_AIOCB64) && defined(HAVE_AIO_RETURN64)
2571 return aio_return64(aiocb);
2572 #elif defined(HAVE_AIO_RETURN)
2573 return aio_return(aiocb);
2580 /*******************************************************************
2581 An aio_cancel wrapper that will deal with 64-bit sizes.
2582 ********************************************************************/
2584 int sys_aio_cancel(int fd, SMB_STRUCT_AIOCB *aiocb)
2586 #if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_AIOCB64) && defined(HAVE_AIO_CANCEL64)
2587 return aio_cancel64(fd, aiocb);
2588 #elif defined(HAVE_AIO_CANCEL)
2589 return aio_cancel(fd, aiocb);
2596 /*******************************************************************
2597 An aio_error wrapper that will deal with 64-bit sizes.
2598 ********************************************************************/
2600 int sys_aio_error(const SMB_STRUCT_AIOCB *aiocb)
2602 #if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_AIOCB64) && defined(HAVE_AIO_ERROR64)
2603 return aio_error64(aiocb);
2604 #elif defined(HAVE_AIO_ERROR)
2605 return aio_error(aiocb);
2612 /*******************************************************************
2613 An aio_fsync wrapper that will deal with 64-bit sizes.
2614 ********************************************************************/
2616 int sys_aio_fsync(int op, SMB_STRUCT_AIOCB *aiocb)
2618 #if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_AIOCB64) && defined(HAVE_AIO_FSYNC64)
2619 return aio_fsync64(op, aiocb);
2620 #elif defined(HAVE_AIO_FSYNC)
2621 return aio_fsync(op, aiocb);
2628 /*******************************************************************
2629 An aio_fsync wrapper that will deal with 64-bit sizes.
2630 ********************************************************************/
2632 int sys_aio_suspend(const SMB_STRUCT_AIOCB * const cblist[], int n, const struct timespec *timeout)
2634 #if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_AIOCB64) && defined(HAVE_AIO_SUSPEND64)
2635 return aio_suspend64(cblist, n, timeout);
2636 #elif defined(HAVE_AIO_FSYNC)
2637 return aio_suspend(cblist, n, timeout);
2643 #else /* !WITH_AIO */
2645 int sys_aio_read(SMB_STRUCT_AIOCB *aiocb)
2651 int sys_aio_write(SMB_STRUCT_AIOCB *aiocb)
2657 ssize_t sys_aio_return(SMB_STRUCT_AIOCB *aiocb)
2663 int sys_aio_cancel(int fd, SMB_STRUCT_AIOCB *aiocb)
2669 int sys_aio_error(const SMB_STRUCT_AIOCB *aiocb)
2675 int sys_aio_fsync(int op, SMB_STRUCT_AIOCB *aiocb)
2681 int sys_aio_suspend(const SMB_STRUCT_AIOCB * const cblist[], int n, const struct timespec *timeout)
2686 #endif /* WITH_AIO */