*/
#include "includes.h"
+#include "system/syslog.h"
+#include "system/capability.h"
+#include "system/passwd.h"
+#include "system/filesys.h"
+
+#ifdef HAVE_SYS_SYSCTL_H
+#include <sys/sysctl.h>
+#endif
#ifdef HAVE_SYS_PRCTL_H
#include <sys/prctl.h>
-/*******************************************************************
- A wrapper for memalign
-********************************************************************/
-
-void *sys_memalign( size_t align, size_t size )
-{
-#if defined(HAVE_POSIX_MEMALIGN)
- void *p = NULL;
- int ret = posix_memalign( &p, align, size );
- if ( ret == 0 )
- return p;
-
- return NULL;
-#elif defined(HAVE_MEMALIGN)
- return memalign( align, size );
-#else
- /* On *BSD systems memaligns doesn't exist, but memory will
- * be aligned on allocations of > pagesize. */
-#if defined(SYSCONF_SC_PAGESIZE)
- size_t pagesize = (size_t)sysconf(_SC_PAGESIZE);
-#elif defined(HAVE_GETPAGESIZE)
- size_t pagesize = (size_t)getpagesize();
-#else
- size_t pagesize = (size_t)-1;
-#endif
- if (pagesize == (size_t)-1) {
- DEBUG(0,("memalign functionalaity not available on this platform!\n"));
- return NULL;
- }
- if (size < pagesize) {
- size = pagesize;
- }
- return SMB_MALLOC(size);
-#endif
-}
-
-/*******************************************************************
- A wrapper for usleep in case we don't have one.
-********************************************************************/
-
-int sys_usleep(long usecs)
-{
-#ifndef HAVE_USLEEP
- struct timeval tval;
-#endif
-
- /*
- * We need this braindamage as the glibc usleep
- * is not SPEC1170 complient... grumble... JRA.
- */
-
- if(usecs < 0 || usecs > 999999) {
- errno = EINVAL;
- return -1;
- }
-
-#if HAVE_USLEEP
- usleep(usecs);
- return 0;
-#else /* HAVE_USLEEP */
- /*
- * Fake it with select...
- */
- tval.tv_sec = 0;
- tval.tv_usec = usecs/1000;
- select(0,NULL,NULL,NULL,&tval);
- return 0;
-#endif /* HAVE_USLEEP */
-}
-
/*******************************************************************
A read wrapper that will deal with EINTR.
********************************************************************/
do {
ret = read(fd, buf, count);
- } while (ret == -1 && errno == EINTR);
+#if defined(EWOULDBLOCK)
+ } while (ret == -1 && (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK));
+#else
+ } while (ret == -1 && (errno == EINTR || errno == EAGAIN));
+#endif
return ret;
}
do {
ret = write(fd, buf, count);
- } while (ret == -1 && errno == EINTR);
+#if defined(EWOULDBLOCK)
+ } while (ret == -1 && (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK));
+#else
+ } while (ret == -1 && (errno == EINTR || errno == EAGAIN));
+#endif
return ret;
}
do {
ret = writev(fd, iov, iovcnt);
- } while (ret == -1 && errno == EINTR);
+#if defined(EWOULDBLOCK)
+ } while (ret == -1 && (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK));
+#else
+ } while (ret == -1 && (errno == EINTR || errno == EAGAIN));
+#endif
return ret;
}
/*******************************************************************
-A pread wrapper that will deal with EINTR and 64-bit file offsets.
+A pread wrapper that will deal with EINTR
********************************************************************/
-#if defined(HAVE_PREAD) || defined(HAVE_PREAD64)
+#if defined(HAVE_PREAD)
ssize_t sys_pread(int fd, void *buf, size_t count, SMB_OFF_T off)
{
ssize_t ret;
do {
-#if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_OFF64_T) && defined(HAVE_PREAD64)
- ret = pread64(fd, buf, count, off);
-#else
ret = pread(fd, buf, count, off);
-#endif
} while (ret == -1 && errno == EINTR);
return ret;
}
#endif
/*******************************************************************
-A write wrapper that will deal with EINTR and 64-bit file offsets.
+A write wrapper that will deal with EINTR
********************************************************************/
-#if defined(HAVE_PWRITE) || defined(HAVE_PWRITE64)
+#if defined(HAVE_PWRITE)
ssize_t sys_pwrite(int fd, const void *buf, size_t count, SMB_OFF_T off)
{
ssize_t ret;
do {
-#if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_OFF64_T) && defined(HAVE_PWRITE64)
- ret = pwrite64(fd, buf, count, off);
-#else
ret = pwrite(fd, buf, count, off);
-#endif
} while (ret == -1 && errno == EINTR);
return ret;
}
#endif
/*******************************************************************
-A send wrapper that will deal with EINTR.
+A send wrapper that will deal with EINTR or EAGAIN or EWOULDBLOCK.
********************************************************************/
ssize_t sys_send(int s, const void *msg, size_t len, int flags)
do {
ret = send(s, msg, len, flags);
- } while (ret == -1 && errno == EINTR);
- return ret;
-}
-
-/*******************************************************************
-A sendto wrapper that will deal with EINTR.
-********************************************************************/
-
-ssize_t sys_sendto(int s, const void *msg, size_t len, int flags, const struct sockaddr *to, socklen_t tolen)
-{
- ssize_t ret;
-
- do {
- ret = sendto(s, msg, len, flags, to, tolen);
- } while (ret == -1 && errno == EINTR);
- return ret;
-}
-
-/*******************************************************************
-A recv wrapper that will deal with EINTR.
-********************************************************************/
-
-ssize_t sys_recv(int fd, void *buf, size_t count, int flags)
-{
- ssize_t ret;
-
- do {
- ret = recv(fd, buf, count, flags);
- } while (ret == -1 && errno == EINTR);
+#if defined(EWOULDBLOCK)
+ } while (ret == -1 && (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK));
+#else
+ } while (ret == -1 && (errno == EINTR || errno == EAGAIN));
+#endif
return ret;
}
do {
ret = recvfrom(s, buf, len, flags, from, fromlen);
- } while (ret == -1 && errno == EINTR);
+#if defined(EWOULDBLOCK)
+ } while (ret == -1 && (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK));
+#else
+ } while (ret == -1 && (errno == EINTR || errno == EAGAIN));
+#endif
return ret;
}
return ret;
}
-/*******************************************************************
-A fcntl wrapper that will deal with EINTR.
-********************************************************************/
-
-int sys_fcntl_long(int fd, int cmd, long arg)
-{
- int ret;
-
- do {
- ret = fcntl(fd, cmd, arg);
- } while (ret == -1 && errno == EINTR);
- return ret;
-}
-
/****************************************************************************
Get/Set all the possible time fields from a stat struct as a timespec.
****************************************************************************/
dst->st_ex_calculated_birthtime = false;
}
-#if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_OFF64_T) && defined(HAVE_STAT64)
-static void init_stat_ex_from_stat (struct stat_ex *dst,
- const struct stat64 *src,
- bool fake_dir_create_times)
-#else
-static void init_stat_ex_from_stat (struct stat_ex *dst,
- const struct stat *src,
- bool fake_dir_create_times)
-#endif
+void init_stat_ex_from_stat (struct stat_ex *dst,
+ const struct stat *src,
+ bool fake_dir_create_times)
{
dst->st_ex_dev = src->st_dev;
dst->st_ex_ino = src->st_ino;
#ifdef HAVE_STAT_ST_BLOCKS
dst->st_ex_blocks = src->st_blocks;
#else
- dst->st_ex_blocks = src->st_size % STAT_ST_BLOCKSIZE + 1;
+ dst->st_ex_blocks = src->st_size / dst->st_ex_blksize + 1;
#endif
#ifdef HAVE_STAT_ST_FLAGS
}
/*******************************************************************
-A stat() wrapper that will deal with 64 bit filesizes.
+A stat() wrapper.
********************************************************************/
int sys_stat(const char *fname, SMB_STRUCT_STAT *sbuf,
bool fake_dir_create_times)
{
int ret;
-#if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_OFF64_T) && defined(HAVE_STAT64)
- struct stat64 statbuf;
- ret = stat64(fname, &statbuf);
-#else
struct stat statbuf;
ret = stat(fname, &statbuf);
-#endif
if (ret == 0) {
/* we always want directories to appear zero size */
if (S_ISDIR(statbuf.st_mode)) {
}
/*******************************************************************
- An fstat() wrapper that will deal with 64 bit filesizes.
+ An fstat() wrapper.
********************************************************************/
int sys_fstat(int fd, SMB_STRUCT_STAT *sbuf, bool fake_dir_create_times)
{
int ret;
-#if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_OFF64_T) && defined(HAVE_FSTAT64)
- struct stat64 statbuf;
- ret = fstat64(fd, &statbuf);
-#else
struct stat statbuf;
ret = fstat(fd, &statbuf);
-#endif
if (ret == 0) {
/* we always want directories to appear zero size */
if (S_ISDIR(statbuf.st_mode)) {
}
/*******************************************************************
- An lstat() wrapper that will deal with 64 bit filesizes.
+ An lstat() wrapper.
********************************************************************/
int sys_lstat(const char *fname,SMB_STRUCT_STAT *sbuf,
bool fake_dir_create_times)
{
int ret;
-#if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_OFF64_T) && defined(HAVE_LSTAT64)
- struct stat64 statbuf;
- ret = lstat64(fname, &statbuf);
-#else
struct stat statbuf;
ret = lstat(fname, &statbuf);
-#endif
if (ret == 0) {
/* we always want directories to appear zero size */
if (S_ISDIR(statbuf.st_mode)) {
}
/*******************************************************************
- An posix_fallocate() wrapper that will deal with 64 bit filesizes.
+ An posix_fallocate() wrapper.
********************************************************************/
int sys_posix_fallocate(int fd, SMB_OFF_T offset, SMB_OFF_T len)
{
-#if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_OFF64_T) && defined(HAVE_POSIX_FALLOCATE64) && !defined(HAVE_BROKEN_POSIX_FALLOCATE)
- return posix_fallocate64(fd, offset, len);
-#elif defined(HAVE_POSIX_FALLOCATE) && !defined(HAVE_BROKEN_POSIX_FALLOCATE)
+#if defined(HAVE_POSIX_FALLOCATE) && !defined(HAVE_BROKEN_POSIX_FALLOCATE)
return posix_fallocate(fd, offset, len);
#elif defined(F_RESVSP64)
/* this handles XFS on IRIX */
}
/*******************************************************************
- An ftruncate() wrapper that will deal with 64 bit filesizes.
+ An fallocate() function that matches the semantics of the Linux one.
********************************************************************/
-int sys_ftruncate(int fd, SMB_OFF_T offset)
-{
-#if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_OFF64_T) && defined(HAVE_FTRUNCATE64)
- return ftruncate64(fd, offset);
-#else
- return ftruncate(fd, offset);
+#ifdef HAVE_LINUX_FALLOC_H
+#include <linux/falloc.h>
#endif
-}
-/*******************************************************************
- An lseek() wrapper that will deal with 64 bit filesizes.
-********************************************************************/
-
-SMB_OFF_T sys_lseek(int fd, SMB_OFF_T offset, int whence)
+int sys_fallocate(int fd, enum vfs_fallocate_mode mode, SMB_OFF_T offset, SMB_OFF_T len)
{
-#if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_OFF64_T) && defined(HAVE_LSEEK64)
- return lseek64(fd, offset, whence);
-#else
- return lseek(fd, offset, whence);
-#endif
-}
-
-/*******************************************************************
- An fseek() wrapper that will deal with 64 bit filesizes.
-********************************************************************/
-
-int sys_fseek(FILE *fp, SMB_OFF_T offset, int whence)
-{
-#if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(LARGE_SMB_OFF_T) && defined(HAVE_FSEEK64)
- return fseek64(fp, offset, whence);
-#elif defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(LARGE_SMB_OFF_T) && defined(HAVE_FSEEKO64)
- return fseeko64(fp, offset, whence);
-#else
- return fseek(fp, offset, whence);
-#endif
-}
-
-/*******************************************************************
- An ftell() wrapper that will deal with 64 bit filesizes.
-********************************************************************/
-
-SMB_OFF_T sys_ftell(FILE *fp)
-{
-#if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(LARGE_SMB_OFF_T) && defined(HAVE_FTELL64)
- return (SMB_OFF_T)ftell64(fp);
-#elif defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(LARGE_SMB_OFF_T) && defined(HAVE_FTELLO64)
- return (SMB_OFF_T)ftello64(fp);
-#else
- return (SMB_OFF_T)ftell(fp);
+#if defined(HAVE_LINUX_FALLOCATE64) || defined(HAVE_LINUX_FALLOCATE)
+ int lmode;
+ switch (mode) {
+ case VFS_FALLOCATE_EXTEND_SIZE:
+ lmode = 0;
+ break;
+ case VFS_FALLOCATE_KEEP_SIZE:
+ lmode = FALLOC_FL_KEEP_SIZE;
+ break;
+ default:
+ errno = EINVAL;
+ return -1;
+ }
+#if defined(HAVE_LINUX_FALLOCATE)
+ return fallocate(fd, lmode, offset, len);
#endif
-}
-
-/*******************************************************************
- A creat() wrapper that will deal with 64 bit filesizes.
-********************************************************************/
-
-int sys_creat(const char *path, mode_t mode)
-{
-#if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_CREAT64)
- return creat64(path, mode);
#else
- /*
- * If creat64 isn't defined then ensure we call a potential open64.
- * JRA.
- */
- return sys_open(path, O_WRONLY | O_CREAT | O_TRUNC, mode);
+ /* TODO - plumb in fallocate from other filesysetms like VXFS etc. JRA. */
+ errno = ENOSYS;
+ return -1;
#endif
}
-/*******************************************************************
- An open() wrapper that will deal with 64 bit filesizes.
-********************************************************************/
-
-int sys_open(const char *path, int oflag, mode_t mode)
-{
-#if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_OPEN64)
- return open64(path, oflag, mode);
-#else
- return open(path, oflag, mode);
+#if HAVE_KERNEL_SHARE_MODES
+#ifndef LOCK_MAND
+#define LOCK_MAND 32 /* This is a mandatory flock */
+#define LOCK_READ 64 /* ... Which allows concurrent read operations */
+#define LOCK_WRITE 128 /* ... Which allows concurrent write operations */
+#define LOCK_RW 192 /* ... Which allows concurrent read & write ops */
#endif
-}
-
-/*******************************************************************
- An fopen() wrapper that will deal with 64 bit filesizes.
-********************************************************************/
-
-FILE *sys_fopen(const char *path, const char *type)
-{
-#if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_FOPEN64)
- return fopen64(path, type);
-#else
- return fopen(path, type);
#endif
-}
-
/*******************************************************************
A flock() wrapper that will perform the kernel flock.
/*******************************************************************
- An opendir wrapper that will deal with 64 bit filesizes.
-********************************************************************/
-
-SMB_STRUCT_DIR *sys_opendir(const char *name)
-{
-#if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_OPENDIR64)
- return opendir64(name);
-#else
- return opendir(name);
-#endif
-}
-
-/*******************************************************************
- A readdir wrapper that will deal with 64 bit filesizes.
-********************************************************************/
-
-SMB_STRUCT_DIRENT *sys_readdir(SMB_STRUCT_DIR *dirp)
-{
-#if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_READDIR64)
- return readdir64(dirp);
-#else
- return readdir(dirp);
-#endif
-}
-
-/*******************************************************************
- A seekdir wrapper that will deal with 64 bit filesizes.
-********************************************************************/
-
-void sys_seekdir(SMB_STRUCT_DIR *dirp, long offset)
-{
-#if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_SEEKDIR64)
- seekdir64(dirp, offset);
-#else
- seekdir(dirp, offset);
-#endif
-}
-
-/*******************************************************************
- A telldir wrapper that will deal with 64 bit filesizes.
+ An fdopendir wrapper.
+ Ugly hack - we need dirfd for this to work correctly in the
+ calling code.. JRA.
********************************************************************/
-long sys_telldir(SMB_STRUCT_DIR *dirp)
+DIR *sys_fdopendir(int fd)
{
-#if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_TELLDIR64)
- return (long)telldir64(dirp);
+#if defined(HAVE_FDOPENDIR) && defined(HAVE_DIRFD)
+ return fdopendir(fd);
#else
- return (long)telldir(dirp);
-#endif
-}
-
-/*******************************************************************
- A rewinddir wrapper that will deal with 64 bit filesizes.
-********************************************************************/
-
-void sys_rewinddir(SMB_STRUCT_DIR *dirp)
-{
-#if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_REWINDDIR64)
- rewinddir64(dirp);
-#else
- rewinddir(dirp);
-#endif
-}
-
-/*******************************************************************
- A close wrapper that will deal with 64 bit filesizes.
-********************************************************************/
-
-int sys_closedir(SMB_STRUCT_DIR *dirp)
-{
-#if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_CLOSEDIR64)
- return closedir64(dirp);
-#else
- return closedir(dirp);
+ errno = ENOSYS;
+ return NULL;
#endif
}
/*******************************************************************
- An mknod() wrapper that will deal with 64 bit filesizes.
+ An mknod() wrapper.
********************************************************************/
int sys_mknod(const char *path, mode_t mode, SMB_DEV_T dev)
{
-#if defined(HAVE_MKNOD) || defined(HAVE_MKNOD64)
-#if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_MKNOD64) && defined(HAVE_DEV64_T)
- return mknod64(path, mode, dev);
-#else
+#if defined(HAVE_MKNOD)
return mknod(path, mode, dev);
-#endif
#else
/* No mknod system call. */
errno = ENOSYS;
}
/*******************************************************************
- System wrapper for getwd
+ System wrapper for getwd. Always returns MALLOC'ed memory, or NULL
+ on error (malloc fail usually).
********************************************************************/
-char *sys_getwd(char *s)
+char *sys_getwd(void)
{
- char *wd;
-#ifdef HAVE_GETCWD
- wd = (char *)getcwd(s, PATH_MAX);
+#ifdef GETCWD_TAKES_NULL
+ return getcwd(NULL, 0);
+#elif HAVE_GETCWD
+ char *wd = NULL, *s = NULL;
+ size_t allocated = PATH_MAX;
+
+ while (1) {
+ s = SMB_REALLOC_ARRAY(s, char, allocated);
+ if (s == NULL) {
+ return NULL;
+ }
+ wd = getcwd(s, allocated);
+ if (wd) {
+ break;
+ }
+ if (errno != ERANGE) {
+ SAFE_FREE(s);
+ break;
+ }
+ allocated *= 2;
+ if (allocated < PATH_MAX) {
+ SAFE_FREE(s);
+ break;
+ }
+ }
+ return wd;
#else
- wd = (char *)getwd(s);
+ char *s = SMB_MALLOC_ARRAY(char, PATH_MAX);
+ if (s == NULL) {
+ return NULL;
+ }
+ return getwd(s);
#endif
- return wd;
}
#if defined(HAVE_POSIX_CAPABILITIES)
#endif
}
+#ifndef NGROUPS_MAX
+#define NGROUPS_MAX 32 /* Guess... */
+#endif
+
/**************************************************************************
Returns equivalent to NGROUPS_MAX - using sysconf if needed.
****************************************************************************/
****************************************************************************/
#if defined(HAVE_BROKEN_GETGROUPS)
+
+#ifdef HAVE_BROKEN_GETGROUPS
+#define GID_T int
+#else
+#define GID_T gid_t
+#endif
+
static int sys_broken_getgroups(int setlen, gid_t *gidset)
{
GID_T gid;
#endif
}
-/**************************************************************************
- Wrappers for setpwent(), getpwent() and endpwent()
-****************************************************************************/
-
-void sys_setpwent(void)
-{
- setpwent();
-}
-
-struct passwd *sys_getpwent(void)
-{
- return getpwent();
-}
-
-void sys_endpwent(void)
-{
- endpwent();
-}
-
-/**************************************************************************
- Wrappers for getpwnam(), getpwuid(), getgrnam(), getgrgid()
-****************************************************************************/
-
-
-struct passwd *sys_getpwnam(const char *name)
-{
- return getpwnam(name);
-}
-
-struct passwd *sys_getpwuid(uid_t uid)
-{
- return getpwuid(uid);
-}
-
-struct group *sys_getgrnam(const char *name)
-{
- return getgrnam(name);
-}
-
-struct group *sys_getgrgid(gid_t gid)
-{
- return getgrgid(gid);
-}
-
/**************************************************************************
Extract a command into an arg list.
****************************************************************************/
TALLOC_FREE(trunc_cmd);
- if (!(argl = TALLOC_ARRAY(mem_ctx, char *, argcl + 1))) {
+ if (!(argl = talloc_array(mem_ctx, char *, argcl + 1))) {
goto nomem;
}
if(!(argl = extract_args(NULL, command)))
goto err_exit;
- entry->child_pid = sys_fork();
+ entry->child_pid = fork();
if (entry->child_pid == -1) {
goto err_exit;
err_exit:
SAFE_FREE(entry);
- SAFE_FREE(argl);
+ TALLOC_FREE(argl);
close(pipe_fds[0]);
close(pipe_fds[1]);
return -1;
#endif
}
-ssize_t sys_lgetxattr (const char *path, const char *name, void *value, size_t size)
-{
-#if defined(HAVE_LGETXATTR)
- return lgetxattr(path, name, value, size);
-#elif defined(HAVE_GETXATTR) && defined(XATTR_ADD_OPT)
- int options = XATTR_NOFOLLOW;
- return getxattr(path, name, value, size, 0, options);
-#elif defined(HAVE_LGETEA)
- return lgetea(path, name, value, size);
-#elif defined(HAVE_EXTATTR_GET_LINK)
- char *s;
- ssize_t retval;
- int attrnamespace = (strncmp(name, "system", 6) == 0) ?
- EXTATTR_NAMESPACE_SYSTEM : EXTATTR_NAMESPACE_USER;
- const char *attrname = ((s=strchr_m(name, '.')) == NULL) ? name : s + 1;
-
- if((retval=extattr_get_link(path, attrnamespace, attrname, NULL, 0)) >= 0) {
- if(retval > size) {
- errno = ERANGE;
- return -1;
- }
- if((retval=extattr_get_link(path, attrnamespace, attrname, value, size)) >= 0)
- return retval;
- }
-
- DEBUG(10,("sys_lgetxattr: extattr_get_link() failed with: %s\n", strerror(errno)));
- return -1;
-#elif defined(HAVE_ATTR_GET)
- int retval, flags = ATTR_DONTFOLLOW;
- int valuelength = (int)size;
- char *attrname = strchr(name,'.') + 1;
-
- if (strncmp(name, "system", 6) == 0) flags |= ATTR_ROOT;
-
- retval = attr_get(path, attrname, (char *)value, &valuelength, flags);
-
- return retval ? retval : valuelength;
-#elif defined(HAVE_ATTROPEN)
- ssize_t ret = -1;
- int attrfd = solaris_attropen(path, name, O_RDONLY|AT_SYMLINK_NOFOLLOW, 0);
- if (attrfd >= 0) {
- ret = solaris_read_xattr(attrfd, value, size);
- close(attrfd);
- }
- return ret;
-#else
- errno = ENOSYS;
- return -1;
-#endif
-}
-
ssize_t sys_fgetxattr (int filedes, const char *name, void *value, size_t size)
{
#if defined(HAVE_FGETXATTR)
int i, t, len;
char *buf;
/* Iterate through extattr(2) namespaces */
- for(t = 0; t < (sizeof(extattr)/sizeof(extattr[0])); t++) {
+ for(t = 0; t < ARRAY_SIZE(extattr); t++) {
switch(type) {
#if defined(HAVE_EXTATTR_LIST_FILE)
case 0:
return -1;
}
/* Shift results back, so we can prepend prefixes */
- buf = memmove(list + len, list, list_size);
+ buf = (char *)memmove(list + len, list, list_size);
for(i = 0; i < list_size; i += len + 1) {
len = buf[i];
#endif
}
-ssize_t sys_llistxattr (const char *path, char *list, size_t size)
-{
-#if defined(HAVE_LLISTXATTR)
- return llistxattr(path, list, size);
-#elif defined(HAVE_LISTXATTR) && defined(XATTR_ADD_OPT)
- int options = XATTR_NOFOLLOW;
- return listxattr(path, list, size, options);
-#elif defined(HAVE_LLISTEA)
- return llistea(path, list, size);
-#elif defined(HAVE_EXTATTR_LIST_LINK)
- extattr_arg arg;
- arg.path = path;
- return bsd_attr_list(1, arg, list, size);
-#elif defined(HAVE_ATTR_LIST) && defined(HAVE_SYS_ATTRIBUTES_H)
- return irix_attr_list(path, 0, list, size, ATTR_DONTFOLLOW);
-#elif defined(HAVE_ATTROPEN)
- ssize_t ret = -1;
- int attrdirfd = solaris_attropen(path, ".", O_RDONLY|AT_SYMLINK_NOFOLLOW, 0);
- if (attrdirfd >= 0) {
- ret = solaris_list_xattr(attrdirfd, list, size);
- close(attrdirfd);
- }
- return ret;
-#else
- errno = ENOSYS;
- return -1;
-#endif
-}
-
ssize_t sys_flistxattr (int filedes, char *list, size_t size)
{
#if defined(HAVE_FLISTXATTR)
dirp = fdopendir(newfd);
while ((de = readdir(dirp))) {
- size_t listlen = strlen(de->d_name);
+ size_t listlen = strlen(de->d_name) + 1;
if (!strcmp(de->d_name, ".") || !strcmp(de->d_name, "..")) {
/* we don't want "." and ".." here: */
DEBUG(10,("skipped EA %s\n",de->d_name));
if (size == 0) {
/* return the current size of the list of extended attribute names*/
- len += listlen + 1;
+ len += listlen;
} else {
/* check size and copy entrieѕ + nul into list. */
- if ((len + listlen + 1) > size) {
+ if ((len + listlen) > size) {
errno = ERANGE;
len = -1;
break;
} else {
- safe_strcpy(list + len, de->d_name, listlen);
+ strlcpy(list + len, de->d_name, listlen);
len += listlen;
- list[len] = '\0';
- ++len;
}
}
}
#endif
}
+#if 0
+/*******************************************************************
+ Return the number of CPUs.
+********************************************************************/
+
+int sys_get_number_of_cores(void)
+{
+ int ret = -1;
+
+#if defined(HAVE_SYSCONF)
+#if defined(_SC_NPROCESSORS_ONLN)
+ ret = (int)sysconf(_SC_NPROCESSORS_ONLN);
+#endif
+#if defined(_SC_NPROCESSORS_CONF)
+ if (ret < 1) {
+ ret = (int)sysconf(_SC_NPROCESSORS_CONF);
+ }
+#endif
+#elif defined(HAVE_SYSCTL) && defined(CTL_HW)
+ int name[2];
+ unsigned int len = sizeof(ret);
+
+ name[0] = CTL_HW;
+#if defined(HW_AVAILCPU)
+ name[1] = HW_AVAILCPU;
+
+ if (sysctl(name, 2, &ret, &len, NULL, 0) == -1) {
+ ret = -1;
+ }
+#endif
+#if defined(HW_NCPU)
+ if(ret < 1) {
+ name[0] = CTL_HW;
+ name[1] = HW_NCPU;
+ if (sysctl(nm, 2, &count, &len, NULL, 0) == -1) {
+ ret = -1;
+ }
+ }
+#endif
+#endif
+ if (ret < 1) {
+ ret = 1;
+ }
+ return ret;
+}
+#endif
+
#if defined(WITH_AIO)
/*******************************************************************
- An aio_read wrapper that will deal with 64-bit sizes.
+ An aio_read wrapper.
********************************************************************/
int sys_aio_read(SMB_STRUCT_AIOCB *aiocb)
{
-#if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_AIOCB64) && defined(HAVE_AIO_READ64)
- return aio_read64(aiocb);
-#elif defined(HAVE_AIO_READ)
+#if defined(HAVE_AIO_READ)
return aio_read(aiocb);
#else
errno = ENOSYS;
}
/*******************************************************************
- An aio_write wrapper that will deal with 64-bit sizes.
+ An aio_write wrapper.
********************************************************************/
int sys_aio_write(SMB_STRUCT_AIOCB *aiocb)
{
-#if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_AIOCB64) && defined(HAVE_AIO_WRITE64)
- return aio_write64(aiocb);
-#elif defined(HAVE_AIO_WRITE)
+#if defined(HAVE_AIO_WRITE)
return aio_write(aiocb);
#else
errno = ENOSYS;
}
/*******************************************************************
- An aio_return wrapper that will deal with 64-bit sizes.
+ An aio_return wrapper.
********************************************************************/
ssize_t sys_aio_return(SMB_STRUCT_AIOCB *aiocb)
{
-#if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_AIOCB64) && defined(HAVE_AIO_RETURN64)
- return aio_return64(aiocb);
-#elif defined(HAVE_AIO_RETURN)
+#if defined(HAVE_AIO_RETURN)
return aio_return(aiocb);
#else
errno = ENOSYS;
}
/*******************************************************************
- An aio_cancel wrapper that will deal with 64-bit sizes.
+ An aio_cancel wrapper.
********************************************************************/
int sys_aio_cancel(int fd, SMB_STRUCT_AIOCB *aiocb)
{
-#if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_AIOCB64) && defined(HAVE_AIO_CANCEL64)
- return aio_cancel64(fd, aiocb);
-#elif defined(HAVE_AIO_CANCEL)
+#if defined(HAVE_AIO_CANCEL)
return aio_cancel(fd, aiocb);
#else
errno = ENOSYS;
}
/*******************************************************************
- An aio_error wrapper that will deal with 64-bit sizes.
+ An aio_error wrapper.
********************************************************************/
int sys_aio_error(const SMB_STRUCT_AIOCB *aiocb)
{
-#if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_AIOCB64) && defined(HAVE_AIO_ERROR64)
- return aio_error64(aiocb);
-#elif defined(HAVE_AIO_ERROR)
+#if defined(HAVE_AIO_ERROR)
return aio_error(aiocb);
#else
errno = ENOSYS;
}
/*******************************************************************
- An aio_fsync wrapper that will deal with 64-bit sizes.
+ An aio_fsync wrapper.
********************************************************************/
int sys_aio_fsync(int op, SMB_STRUCT_AIOCB *aiocb)
{
-#if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_AIOCB64) && defined(HAVE_AIO_FSYNC64)
- return aio_fsync64(op, aiocb);
-#elif defined(HAVE_AIO_FSYNC)
+#if defined(HAVE_AIO_FSYNC)
return aio_fsync(op, aiocb);
#else
errno = ENOSYS;
}
/*******************************************************************
- An aio_fsync wrapper that will deal with 64-bit sizes.
+ An aio_fsync wrapper.
********************************************************************/
int sys_aio_suspend(const SMB_STRUCT_AIOCB * const cblist[], int n, const struct timespec *timeout)
{
-#if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_AIOCB64) && defined(HAVE_AIO_SUSPEND64)
- return aio_suspend64(cblist, n, timeout);
-#elif defined(HAVE_AIO_FSYNC)
+#if defined(HAVE_AIO_FSYNC)
return aio_suspend(cblist, n, timeout);
#else
errno = ENOSYS;
return -1;
}
#endif /* WITH_AIO */
-
-int sys_getpeereid( int s, uid_t *uid)
-{
-#if defined(HAVE_PEERCRED)
- struct ucred cred;
- socklen_t cred_len = sizeof(struct ucred);
- int ret;
-
- ret = getsockopt(s, SOL_SOCKET, SO_PEERCRED, (void *)&cred, &cred_len);
- if (ret != 0) {
- return -1;
- }
-
- if (cred_len != sizeof(struct ucred)) {
- errno = EINVAL;
- return -1;
- }
-
- *uid = cred.uid;
- return 0;
-#else
- errno = ENOSYS;
- return -1;
-#endif
-}
-
-int sys_getnameinfo(const struct sockaddr *psa,
- socklen_t salen,
- char *host,
- size_t hostlen,
- char *service,
- size_t servlen,
- int flags)
-{
- /*
- * For Solaris we must make sure salen is the
- * correct length for the incoming sa_family.
- */
-
- if (salen == sizeof(struct sockaddr_storage)) {
- salen = sizeof(struct sockaddr_in);
-#if defined(HAVE_IPV6)
- if (psa->sa_family == AF_INET6) {
- salen = sizeof(struct sockaddr_in6);
- }
-#endif
- }
- return getnameinfo(psa, salen, host, hostlen, service, servlen, flags);
-}
-
-int sys_connect(int fd, const struct sockaddr * addr)
-{
- socklen_t salen = -1;
-
- if (addr->sa_family == AF_INET) {
- salen = sizeof(struct sockaddr_in);
- } else if (addr->sa_family == AF_UNIX) {
- salen = sizeof(struct sockaddr_un);
- }
-#if defined(HAVE_IPV6)
- else if (addr->sa_family == AF_INET6) {
- salen = sizeof(struct sockaddr_in6);
- }
-#endif
-
- return connect(fd, addr, salen);
-}