* fhandler.cc (check_posix_perm): Moved here from syscalls.cc.

(fhandler_base::fpathconf): New method implementing (f)pathconf.
	* fhandler.h (class fhandler_base): Declare fpathconf method.
	* path.cc (path_conv::check): Replace MAX_LINK_DEPTH with SYMLOOP_MAX.
	* path.h (MAX_LINK_DEPTH): Delete.
	* syscalls.cc (check_posix_perm): Move to fhandler.cc.
	(fpathconf): Call fhandler's fpathconf method.
	(pathconf): Build fhandler and call fhandler's fpathconf method.
	* sysconf.cc (sysconf): Reorder switch according to order of flags
	in sys/unistd.h.  Add handling for some missing flags.
	* include/limits.h: Reorder according to SUSv3 description.  Add some
	missing definitions.  Add comments.
	* include/sys/syslimits.h: New file overriding newlib's syslimits.h
	file.
This commit is contained in:
Corinna Vinschen 2006-11-07 17:59:54 +00:00
parent b1755fe736
commit 86bc8fadff
9 changed files with 323 additions and 163 deletions

View File

@ -1,3 +1,20 @@
2006-11-07 Corinna Vinschen <corinna@vinschen.de>
* fhandler.cc (check_posix_perm): Moved here from syscalls.cc.
(fhandler_base::fpathconf): New method implementing (f)pathconf.
* fhandler.h (class fhandler_base): Declare fpathconf method.
* path.cc (path_conv::check): Replace MAX_LINK_DEPTH with SYMLOOP_MAX.
* path.h (MAX_LINK_DEPTH): Delete.
* syscalls.cc (check_posix_perm): Move to fhandler.cc.
(fpathconf): Call fhandler's fpathconf method.
(pathconf): Build fhandler and call fhandler's fpathconf method.
* sysconf.cc (sysconf): Reorder switch according to order of flags
in sys/unistd.h. Add handling for some missing flags.
* include/limits.h: Reorder according to SUSv3 description. Add some
missing definitions. Add comments.
* include/sys/syslimits.h: New file overriding newlib's syslimits.h
file.
2006-11-06 Corinna Vinschen <corinna@vinschen.de>
* dtable.cc (build_fh_pc): Add missing DEV_SD1_MAJOR case (Thanks to

View File

@ -1713,3 +1713,99 @@ fhandler_base::fsync ()
__seterrno ();
return -1;
}
/* Helper function for Cygwin specific pathconf flags _PC_POSIX_PERMISSIONS
and _PC_POSIX_SECURITY. */
static int
check_posix_perm (const char *fname, int v)
{
/* Windows 95/98/ME don't support file system security at all. */
if (!wincap.has_security ())
return 0;
/* ntea is ok for supporting permission bits but it doesn't support
full POSIX security settings. */
if (v == _PC_POSIX_PERMISSIONS && allow_ntea)
return 1;
if (!allow_ntsec)
return 0;
char *root = rootdir (fname, (char *)alloca (strlen (fname)));
if (!allow_smbntsec
&& ((root[0] == '\\' && root[1] == '\\')
|| GetDriveType (root) == DRIVE_REMOTE))
return 0;
DWORD vsn, len, flags;
if (!GetVolumeInformation (root, NULL, 0, &vsn, &len, &flags, NULL, 16))
{
__seterrno ();
return 0;
}
return (flags & FS_PERSISTENT_ACLS) ? 1 : 0;
}
int
fhandler_base::fpathconf (int v)
{
switch (v)
{
case _PC_LINK_MAX:
return pc.fs_is_ntfs () || pc.fs_is_samba () || pc.fs_is_nfs ()
? LINK_MAX : 1;
case _PC_MAX_CANON:
if (is_tty ())
return MAX_CANON;
set_errno (EINVAL);
break;
case _PC_MAX_INPUT:
if (is_tty ())
return MAX_INPUT;
set_errno (EINVAL);
break;
case _PC_NAME_MAX:
/* NAME_MAX is without trailing \0 */
return pc.isdir () ? PATH_MAX - strlen (get_name ()) - 2 : NAME_MAX;
case _PC_PATH_MAX:
/* PATH_MAX is with trailing \0 */
return pc.isdir () ? PATH_MAX - strlen (get_name ()) - 1 : PATH_MAX;
case _PC_PIPE_BUF:
if (pc.isdir ()
|| get_device () == FH_FIFO || get_device () == FH_PIPE
|| get_device () == FH_PIPER || get_device () == FH_PIPEW)
return PIPE_BUF;
set_errno (EINVAL);
break;
case _PC_CHOWN_RESTRICTED:
return 1;
case _PC_NO_TRUNC:
return 1;
case _PC_VDISABLE:
if (!is_tty ())
set_errno (EINVAL);
break;
case _PC_ASYNC_IO:
case _PC_PRIO_IO:
case _PC_SYNC_IO:
break;
case _PC_FILESIZEBITS:
return FILESIZEBITS;
case _PC_2_SYMLINKS:
return 1;
case _PC_SYMLINK_MAX:
break;
case _PC_POSIX_PERMISSIONS:
case _PC_POSIX_SECURITY:
if (get_device () == FH_FS)
return check_posix_perm (get_win32_name (), v);
set_errno (EINVAL);
break;
default:
set_errno (EINVAL);
break;
}
return -1;
}

View File

@ -296,6 +296,7 @@ class fhandler_base
virtual _off64_t lseek (_off64_t offset, int whence);
virtual int lock (int, struct __flock64 *);
virtual int dup (fhandler_base *child);
virtual int fpathconf (int);
virtual HANDLE mmap (caddr_t *addr, size_t len, int prot,
int flags, _off64_t off);

View File

@ -1,6 +1,6 @@
/* limits.h
Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005 Red Hat, Inc.
Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 Red Hat, Inc.
This file is part of Cygwin.
@ -18,6 +18,9 @@ details. */
#define _LIMITS_H___
#define _MACH_MACHLIMITS_H_
/* Numerical limits */
/* Number of bits in a `char'. */
#undef CHAR_BIT
#define CHAR_BIT 8
@ -117,27 +120,34 @@ details. */
#undef ULLONG_MAX
#define ULLONG_MAX (LLONG_MAX * 2ULL + 1)
/* Maximum number of iovcnt in a writev (an arbitrary number) */
#undef IOV_MAX
#define IOV_MAX 1024
/* Maximum size of ssize_t */
#undef SSIZE_MAX
#define SSIZE_MAX (__LONG_MAX__)
/* Maximum length of a path */
#define PATH_MAX 260
/* Maximum length of a path component. */
#define NAME_MAX 255
/* Runtime Invariant Values */
/* Max num groups for a user, value taken from NT documentation */
/* Must match <sys/param.h> NGROUPS */
#define NGROUPS_MAX 16
/* Maximum number of bytes in arguments and environment passed in an exec
call. 32000 is the safe value used for Windows processes when called
from Cygwin processes. */
#undef ARG_MAX
#define ARG_MAX 32000
/* WaitForMultipleObjects can't handle waiting for more than 64 objects.
This limits how many children we can fork/spawn off. */
#define CHILD_MAX 63
/* Maximum number of simultaneous processes per real user ID. */
#undef CHILD_MAX
#define CHILD_MAX 256
/* Maximum length of a host name. */
#undef HOST_NAME_MAX
#define HOST_NAME_MAX 255
/* Maximum number of iovcnt in a writev (an arbitrary number) */
#undef IOV_MAX
#define IOV_MAX 1024
/* Maximum number of characters in a login name. */
#undef LOGIN_NAME_MAX
#define LOGIN_NAME_MAX 256 /* equal to UNLEN defined in w32api/lmcons.h */
/* # of open files per process. Actually it can be more since Cygwin
grows the dtable as necessary. We define a reasonable limit here
@ -146,30 +156,126 @@ details. */
#undef OPEN_MAX
#define OPEN_MAX 256
/* # of bytes in a pipe buf. This is the max # of bytes which can be
written to a pipe in one atomic operation. */
#undef PIPE_BUF
#define PIPE_BUF 4096
/* Size in bytes of a page. */
#undef PAGESIZE
#undef PAGE_SIZE
#define PAGESIZE 65536
#define PAGE_SIZE PAGESIZE
/* Maximum number of realtime signals reserved for application use. */
/* FIXME: We only support one realtime signal but _POSIX_RTSIG_MAX is 8. */
#undef RTSIG_MAX
#define RTSIG_MAX 1
/* Number of streams that one process can have open at one time. */
#undef STREAM_MAX
#define STREAM_MAX 20
/* Maximum number of nested symbolic links. */
#undef SYMLOOP_MAX
#define SYMLOOP_MAX 10
/* Maximum number of timer expiration overruns. */
#undef TIMER_MAX
#define TIMER_MAX 32
/* Maximum number of characters in a login name. */
#undef LOGIN_NAME_MAX
#define LOGIN_NAME_MAX 256 /* equal to UNLEN defined in w32api/lmcons.h */
/* Maximum number of characters in a tty name. */
#undef TTY_NAME_MAX
#define TTY_NAME_MAX 12
/* Pathname Variable Values */
/* Minimum bits needed to represent the maximum size of a regular file. */
#undef FILESIZEBITS
#define FILESIZEBITS 64
/* Maximum number of hardlinks to a file. */
#undef LINK_MAX
#define LINK_MAX 1024
/* Maximum number of bytes in a terminal canonical input line. */
#undef MAX_CANON
#define MAX_CANON 255
/* Minimum number of bytes available in a terminal input queue. */
#undef MAX_INPUT
#define MAX_INPUT 255
/* Maximum length of a path component. */
#undef NAME_MAX
#define NAME_MAX 255
/* Maximum length of a path */
#undef PATH_MAX
#define PATH_MAX 260
/* # of bytes in a pipe buf. This is the max # of bytes which can be
written to a pipe in one atomic operation. */
#undef PIPE_BUF
#define PIPE_BUF 4096
/* Runtime Increasable Values */
/* Maximum obase values allowed by the bc utility. */
#undef BC_BASE_MAX
#define BC_BASE_MAX 99
/* Maximum number of elements permitted in an array by the bc utility. */
#undef BC_DIM_MAX
#define BC_DIM_MAX 2048
/* Maximum scale value allowed by the bc utility. */
#undef BC_SCALE_MAX
#define BC_SCALE_MAX 99
/* Maximum length of a string constant accepted by the bc utility. */
#undef BC_STRING_MAX
#define BC_STRING_MAX 1000
/* Maximum number of weights that can be assigned to an entry of the
LC_COLLATE order keyword in the locale definition file. */
/* FIXME: We don't support this at all right now, so this value is
misleading at best. It's also lower than _POSIX2_COLL_WEIGHTS_MAX
which is not good. So, for now we deliberately not define it even
though it was defined in the former syslimits.h file. */
#if 0
#undef COLL_WEIGHTS_MAX
#define COLL_WEIGHTS_MAX 0
#endif
/* Maximum number of expressions that can be nested within parentheses
by the expr utility. */
#undef EXPR_NEST_MAX
#define EXPR_NEST_MAX 32
/* Maximum bytes of a text utility's input line */
#undef LINE_MAX
#define LINE_MAX 2048
/* Max num groups for a user, value taken from NT documentation */
/* Must match <sys/param.h> NGROUPS */
#undef NGROUPS_MAX
#define NGROUPS_MAX 16
/* Maximum number of repeated occurrences of a regular expression when
using the interval notation \{m,n\} */
#undef RE_DUP_MAX
#define RE_DUP_MAX 255
/* Minimum Values */
/* POSIX values */
/* These should never vary from one system type to another */
/* They represent the minimum values that POSIX systems must support.
POSIX-conforming apps must not require larger values. */
#define _POSIX_ARG_MAX 4096
#define _POSIX_CHILD_MAX 6
#define _POSIX_HOST_NAME_MAX 255
#define _POSIX_LINK_MAX 8
#define _POSIX_LOGIN_NAME_MAX 9
#define _POSIX_MAX_CANON 255
#define _POSIX_MAX_INPUT 255
#define _POSIX_NAME_MAX 14
@ -177,16 +283,32 @@ details. */
#define _POSIX_OPEN_MAX 16
#define _POSIX_PATH_MAX 255
#define _POSIX_PIPE_BUF 512
#define _POSIX_RE_DUP_MAX 255
#define _POSIX_RTSIG_MAX 8
#define _POSIX_SSIZE_MAX 32767
#define _POSIX_STREAM_MAX 8
#define _POSIX_TZNAME_MAX 3
#define _POSIX_RTSIG_MAX 8
#define _POSIX_SYMLINK_MAX 255
#define _POSIX_SYMLOOP_MAX 8
#define _POSIX_TIMER_MAX 32
#define _POSIX_TTY_NAME_MAX 9
#define _POSIX_TZNAME_MAX 3
#define RTSIG_MAX _POSIX_RTSIG_MAX
#define _POSIX2_BC_BASE_MAX 99
#define _POSIX2_BC_DIM_MAX 2048
#define _POSIX2_BC_SCALE_MAX 99
#define _POSIX2_BC_STRING_MAX 1000
#if 0 /* See comment about COLL_WEIGHTS_MAX above. */
#define _POSIX2_COLL_WEIGHTS_MAX 2
#endif
#define _POSIX2_EXPR_NEST_MAX 32
#define _POSIX2_LINE_MAX 2048
#define _POSIX2_RE_DUP_MAX 255
/* Used for nice and get/setpriority. */
/* Other Invariant Values */
/* Default process priority. */
#undef NZERO
#define NZERO 20
#endif /* _MACH_MACHLIMITS_H_ */

View File

@ -0,0 +1,20 @@
/* sys/syslimits.h
Copyright 2006 Red Hat, Inc.
This file is part of Cygwin.
This software is a copyrighted work licensed under the terms of the
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
details. */
#ifndef _SYS_SYSLIMITS_H
#define _SYS_SYSLIMITS_H
#ifdef _COMPILING_NEWLIB
# include <limits.h>
#else
# error "Do not include sys/syslimits.h from applications directly."
#endif
#endif /*_SYS_SYSLIMITS_H */

View File

@ -907,7 +907,7 @@ virtual_component_retry:
}
/* Arrive here if above loop detected a symlink. */
if (++loop > MAX_LINK_DEPTH)
if (++loop > SYMLOOP_MAX)
{
error = ELOOP; // Eep.
return;

View File

@ -272,8 +272,6 @@ class path_conv
/* Socket marker */
#define SOCKET_COOKIE "!<socket >"
/* Maximum depth of symlinks (after which ELOOP is issued). */
#define MAX_LINK_DEPTH 10
int __stdcall slash_unc_prefix_p (const char *path) __attribute__ ((regparm(1)));
enum fe_types

View File

@ -1,7 +1,7 @@
/* syscalls.cc: syscalls
Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
2005 Red Hat, Inc.
2005, 2006 Red Hat, Inc.
This file is part of Cygwin.
@ -1460,38 +1460,6 @@ getsystempagesize ()
return (size_t) system_info.dwPageSize;
}
static int
check_posix_perm (const char *fname, int v)
{
/* Windows 95/98/ME don't support file system security at all. */
if (!wincap.has_security ())
return 0;
/* ntea is ok for supporting permission bits but it doesn't support
full POSIX security settings. */
if (v == _PC_POSIX_PERMISSIONS && allow_ntea)
return 1;
if (!allow_ntsec)
return 0;
char *root = rootdir (fname, (char *)alloca (strlen (fname)));
if (!allow_smbntsec
&& ((root[0] == '\\' && root[1] == '\\')
|| GetDriveType (root) == DRIVE_REMOTE))
return 0;
DWORD vsn, len, flags;
if (!GetVolumeInformation (root, NULL, 0, &vsn, &len, &flags, NULL, 16))
{
__seterrno ();
return 0;
}
return (flags & FS_PERSISTENT_ACLS) ? 1 : 0;
}
/* FIXME: not all values are correct... */
extern "C" long int
fpathconf (int fd, int v)
@ -1499,50 +1467,14 @@ fpathconf (int fd, int v)
cygheap_fdget cfd (fd);
if (cfd < 0)
return -1;
switch (v)
{
case _PC_LINK_MAX:
return _POSIX_LINK_MAX;
case _PC_MAX_CANON:
case _PC_MAX_INPUT:
if (isatty (fd))
return _POSIX_MAX_CANON;
else
{
set_errno (EBADF);
return -1;
}
case _PC_NAME_MAX:
case _PC_PATH_MAX:
return PATH_MAX;
case _PC_PIPE_BUF:
return PIPE_BUF;
case _PC_CHOWN_RESTRICTED:
case _PC_NO_TRUNC:
return -1;
case _PC_VDISABLE:
if (cfd->is_tty ())
return -1;
else
{
set_errno (EBADF);
return -1;
}
case _PC_POSIX_PERMISSIONS:
case _PC_POSIX_SECURITY:
if (cfd->get_device () == FH_FS)
return check_posix_perm (cfd->get_win32_name (), v);
set_errno (EINVAL);
return -1;
default:
set_errno (EINVAL);
return -1;
}
return cfd->fpathconf (v);
}
extern "C" long int
pathconf (const char *file, int v)
{
fhandler_base *fh;
myfault efault;
if (efault.faulted (EFAULT))
return -1;
@ -1551,45 +1483,15 @@ pathconf (const char *file, int v)
set_errno (ENOENT);
return -1;
}
switch (v)
if (!(fh = build_fh_name (file, NULL, PC_SYM_FOLLOW,
transparent_exe ? stat_suffixes : NULL)))
return -1;
if (!fh->exists ())
{
case _PC_PATH_MAX:
return PATH_MAX - strlen (file);
case _PC_NAME_MAX:
return PATH_MAX;
case _PC_LINK_MAX:
return _POSIX_LINK_MAX;
case _PC_MAX_CANON:
case _PC_MAX_INPUT:
return _POSIX_MAX_CANON;
case _PC_PIPE_BUF:
return PIPE_BUF;
case _PC_CHOWN_RESTRICTED:
case _PC_NO_TRUNC:
return -1;
case _PC_VDISABLE:
return -1;
case _PC_POSIX_PERMISSIONS:
case _PC_POSIX_SECURITY:
{
path_conv full_path (file, PC_SYM_FOLLOW,
transparent_exe ? stat_suffixes : NULL);
if (full_path.error)
{
set_errno (full_path.error);
return -1;
}
if (full_path.is_auto_device ())
{
set_errno (EINVAL);
return -1;
}
return check_posix_perm (full_path, v);
}
default:
set_errno (EINVAL);
set_errno (ENOENT);
return -1;
}
return fh->fpathconf (v);
}
extern "C" int

View File

@ -30,9 +30,17 @@ sysconf (int in)
{
switch (in)
{
/* Keep order as in sys/unistd.h */
case _SC_ARG_MAX:
/* FIXME: what's the right value? _POSIX_ARG_MAX is only 4K */
/* FIXME: what's the right value? _POSIX_ARG_MAX is only 4K.
FIXME: Wouldn't it be more correct to return ARG_MAX here? */
return 1048576;
case _SC_CHILD_MAX:
return CHILD_MAX;
case _SC_CLK_TCK:
return CLOCKS_PER_SEC;
case _SC_NGROUPS_MAX:
return NGROUPS_MAX;
case _SC_OPEN_MAX:
{
long max = getdtablesize ();
@ -40,31 +48,14 @@ sysconf (int in)
max = OPEN_MAX;
return max;
}
case _SC_PAGESIZE:
return getpagesize ();
case _SC_CLK_TCK:
return CLOCKS_PER_SEC;
case _SC_JOB_CONTROL:
return _POSIX_JOB_CONTROL;
case _SC_CHILD_MAX:
return CHILD_MAX;
case _SC_NGROUPS_MAX:
return NGROUPS_MAX;
case _SC_SAVED_IDS:
return _POSIX_SAVED_IDS;
case _SC_LOGIN_NAME_MAX:
return LOGIN_NAME_MAX;
case _SC_GETPW_R_SIZE_MAX:
case _SC_GETGR_R_SIZE_MAX:
return 16*1024;
case _SC_VERSION:
return _POSIX_VERSION;
#if 0 /* FIXME -- unimplemented */
case _SC_TZNAME_MAX:
return _POSIX_TZNAME_MAX;
case _SC_STREAM_MAX:
return _POSIX_STREAM_MAX;
#endif
case _SC_PAGESIZE:
return getpagesize ();
case _SC_NPROCESSORS_CONF:
case _SC_NPROCESSORS_ONLN:
if (!wincap.supports_smp ())
@ -122,12 +113,20 @@ sysconf (int in)
}
case _SC_RTSIG_MAX:
return RTSIG_MAX;
case _SC_TTY_NAME_MAX:
return TTY_NAME_MAX;
case _SC_TIMER_MAX:
return TIMER_MAX;
#if 0 /* FIXME -- unimplemented */
case _SC_TZNAME_MAX:
return _POSIX_TZNAME_MAX;
#endif
case _SC_MEMLOCK_RANGE:
return _POSIX_MEMLOCK_RANGE;
case _SC_SEMAPHORES:
return _POSIX_SEMAPHORES;
return _POSIX_SEMAPHORES;
case _SC_TIMERS:
return _POSIX_TIMERS;
case _SC_TTY_NAME_MAX:
return TTY_NAME_MAX;
case _SC_THREADS:
return _POSIX_THREADS;
case _SC_THREAD_ATTR_STACKSIZE:
@ -138,8 +137,13 @@ sysconf (int in)
return _POSIX_THREAD_PROCESS_SHARED;
case _SC_THREAD_SAFE_FUNCTIONS:
return _POSIX_THREAD_SAFE_FUNCTIONS;
case _SC_TIMERS:
return _POSIX_TIMERS;
case _SC_GETPW_R_SIZE_MAX:
case _SC_GETGR_R_SIZE_MAX:
return 16*1024;
case _SC_LOGIN_NAME_MAX:
return LOGIN_NAME_MAX;
case _SC_STREAM_MAX:
return STREAM_MAX;
}
/* Invalid input or unimplemented sysconf name */