diff options
Diffstat (limited to 'newlib')
-rw-r--r-- | newlib/ChangeLog | 11 | ||||
-rw-r--r-- | newlib/libc/sys/linux/Makefile.am | 2 | ||||
-rw-r--r-- | newlib/libc/sys/linux/Makefile.in | 60 | ||||
-rw-r--r-- | newlib/libc/sys/linux/fpathconf.c | 305 | ||||
-rw-r--r-- | newlib/libc/sys/linux/inode.c | 2 | ||||
-rw-r--r-- | newlib/libc/sys/linux/io.c | 2 | ||||
-rw-r--r-- | newlib/libc/sys/linux/linux_fsinfo.h | 114 | ||||
-rw-r--r-- | newlib/libc/sys/linux/pathconf.c | 302 | ||||
-rw-r--r-- | newlib/libc/sys/linux/sys/unistd.h | 168 |
9 files changed, 937 insertions, 29 deletions
diff --git a/newlib/ChangeLog b/newlib/ChangeLog index eaa0214..c93a2bf 100644 --- a/newlib/ChangeLog +++ b/newlib/ChangeLog @@ -1,5 +1,16 @@ 2002-07-19 Jeff Johnston <jjohnstn@redhat.com> + * libc/sys/linux/Makefile.am: Add pathconf.c and fpathconf.c. + * libc/sys/linux/Makefile.in: Regenerated. + * libc/sys/linux/inode.c: Add chmod, fchmod, and chown syscalls. + * libc/sys/linux/io.c: Add ftruncate syscall. + * libc/sys/linux/fpathconf.c: New file. + * libc/sys/linux/pathconf.c: Ditto. + * libc/sys/linux/linux_fsinfo.h: Ditto. + * libc/sys/linux/sys/unistd.h: Ditto. + +2002-07-19 Jeff Johnston <jjohnstn@redhat.com> + * libc/stdio64/Makefile.am: Remove missing files. * libc/stdio64/Makefile.in: Regenerated. diff --git a/newlib/libc/sys/linux/Makefile.am b/newlib/libc/sys/linux/Makefile.am index 7c162b7..f79e262 100644 --- a/newlib/libc/sys/linux/Makefile.am +++ b/newlib/libc/sys/linux/Makefile.am @@ -20,6 +20,7 @@ LIB_SOURCES = \ clock_gettime.c \ clock_settime.c \ flockfile.c \ + fpathconf.c \ free.c \ freer.c \ ftok.c \ @@ -57,6 +58,7 @@ LIB_SOURCES = \ mtrim.c \ mtrimr.c \ ntp_gettime.c \ + pathconf.c \ pread.c \ pread64.c \ process.c \ diff --git a/newlib/libc/sys/linux/Makefile.in b/newlib/libc/sys/linux/Makefile.in index 5260ff0..6709641 100644 --- a/newlib/libc/sys/linux/Makefile.in +++ b/newlib/libc/sys/linux/Makefile.in @@ -117,6 +117,7 @@ LIB_SOURCES = \ clock_gettime.c \ clock_settime.c \ flockfile.c \ + fpathconf.c \ free.c \ freer.c \ ftok.c \ @@ -154,6 +155,7 @@ LIB_SOURCES = \ mtrim.c \ mtrimr.c \ ntp_gettime.c \ + pathconf.c \ pread.c \ pread64.c \ process.c \ @@ -240,14 +242,14 @@ LIBS = @LIBS@ @USE_LIBTOOL_FALSE@calloc.$(OBJEXT) callocr.$(OBJEXT) cfreer.$(OBJEXT) \ @USE_LIBTOOL_FALSE@cfspeed.$(OBJEXT) clock_getres.$(OBJEXT) \ @USE_LIBTOOL_FALSE@clock_gettime.$(OBJEXT) clock_settime.$(OBJEXT) \ -@USE_LIBTOOL_FALSE@flockfile.$(OBJEXT) free.$(OBJEXT) freer.$(OBJEXT) \ -@USE_LIBTOOL_FALSE@ftok.$(OBJEXT) funlockfile.$(OBJEXT) \ -@USE_LIBTOOL_FALSE@getdate.$(OBJEXT) getdate_err.$(OBJEXT) \ -@USE_LIBTOOL_FALSE@gethostname.$(OBJEXT) getoptlong.$(OBJEXT) \ -@USE_LIBTOOL_FALSE@getreent.$(OBJEXT) getrlimit64.$(OBJEXT) \ -@USE_LIBTOOL_FALSE@ids.$(OBJEXT) inode.$(OBJEXT) io.$(OBJEXT) \ -@USE_LIBTOOL_FALSE@io64.$(OBJEXT) ipc.$(OBJEXT) linux.$(OBJEXT) \ -@USE_LIBTOOL_FALSE@malign.$(OBJEXT) malignr.$(OBJEXT) \ +@USE_LIBTOOL_FALSE@flockfile.$(OBJEXT) fpathconf.$(OBJEXT) \ +@USE_LIBTOOL_FALSE@free.$(OBJEXT) freer.$(OBJEXT) ftok.$(OBJEXT) \ +@USE_LIBTOOL_FALSE@funlockfile.$(OBJEXT) getdate.$(OBJEXT) \ +@USE_LIBTOOL_FALSE@getdate_err.$(OBJEXT) gethostname.$(OBJEXT) \ +@USE_LIBTOOL_FALSE@getoptlong.$(OBJEXT) getreent.$(OBJEXT) \ +@USE_LIBTOOL_FALSE@getrlimit64.$(OBJEXT) ids.$(OBJEXT) inode.$(OBJEXT) \ +@USE_LIBTOOL_FALSE@io.$(OBJEXT) io64.$(OBJEXT) ipc.$(OBJEXT) \ +@USE_LIBTOOL_FALSE@linux.$(OBJEXT) malign.$(OBJEXT) malignr.$(OBJEXT) \ @USE_LIBTOOL_FALSE@mallinfor.$(OBJEXT) mallocr.$(OBJEXT) \ @USE_LIBTOOL_FALSE@malloptr.$(OBJEXT) mallstatsr.$(OBJEXT) \ @USE_LIBTOOL_FALSE@mmap.$(OBJEXT) mq_close.$(OBJEXT) \ @@ -256,8 +258,8 @@ LIBS = @LIBS@ @USE_LIBTOOL_FALSE@mq_send.$(OBJEXT) mq_setattr.$(OBJEXT) \ @USE_LIBTOOL_FALSE@mq_unlink.$(OBJEXT) msize.$(OBJEXT) msizer.$(OBJEXT) \ @USE_LIBTOOL_FALSE@mstats.$(OBJEXT) mtrim.$(OBJEXT) mtrimr.$(OBJEXT) \ -@USE_LIBTOOL_FALSE@ntp_gettime.$(OBJEXT) pread.$(OBJEXT) \ -@USE_LIBTOOL_FALSE@pread64.$(OBJEXT) process.$(OBJEXT) \ +@USE_LIBTOOL_FALSE@ntp_gettime.$(OBJEXT) pathconf.$(OBJEXT) \ +@USE_LIBTOOL_FALSE@pread.$(OBJEXT) pread64.$(OBJEXT) process.$(OBJEXT) \ @USE_LIBTOOL_FALSE@psignal.$(OBJEXT) pvallocr.$(OBJEXT) \ @USE_LIBTOOL_FALSE@pwrite.$(OBJEXT) pwrite64.$(OBJEXT) raise.$(OBJEXT) \ @USE_LIBTOOL_FALSE@realloc.$(OBJEXT) reallocr.$(OBJEXT) \ @@ -280,25 +282,25 @@ LTLIBRARIES = $(noinst_LTLIBRARIES) @USE_LIBTOOL_TRUE@liblinux_la_OBJECTS = aio.lo brk.lo calloc.lo \ @USE_LIBTOOL_TRUE@callocr.lo cfreer.lo cfspeed.lo clock_getres.lo \ @USE_LIBTOOL_TRUE@clock_gettime.lo clock_settime.lo flockfile.lo \ -@USE_LIBTOOL_TRUE@free.lo freer.lo ftok.lo funlockfile.lo getdate.lo \ -@USE_LIBTOOL_TRUE@getdate_err.lo gethostname.lo getoptlong.lo \ -@USE_LIBTOOL_TRUE@getreent.lo getrlimit64.lo ids.lo inode.lo io.lo \ -@USE_LIBTOOL_TRUE@io64.lo ipc.lo linux.lo malign.lo malignr.lo \ -@USE_LIBTOOL_TRUE@mallinfor.lo mallocr.lo malloptr.lo mallstatsr.lo \ -@USE_LIBTOOL_TRUE@mmap.lo mq_close.lo mq_getattr.lo mq_notify.lo \ -@USE_LIBTOOL_TRUE@mq_open.lo mq_receive.lo mq_send.lo mq_setattr.lo \ -@USE_LIBTOOL_TRUE@mq_unlink.lo msize.lo msizer.lo mstats.lo mtrim.lo \ -@USE_LIBTOOL_TRUE@mtrimr.lo ntp_gettime.lo pread.lo pread64.lo \ -@USE_LIBTOOL_TRUE@process.lo psignal.lo pvallocr.lo pwrite.lo \ -@USE_LIBTOOL_TRUE@pwrite64.lo raise.lo realloc.lo reallocr.lo \ -@USE_LIBTOOL_TRUE@realpath.lo rename.lo resource.lo sched.lo select.lo \ -@USE_LIBTOOL_TRUE@seteuid.lo sethostname.lo setrlimit64.lo shm_open.lo \ -@USE_LIBTOOL_TRUE@shm_unlink.lo sig.lo sigaction.lo sigqueue.lo \ -@USE_LIBTOOL_TRUE@signal.lo siglongjmp.lo sigset.lo sigwait.lo \ -@USE_LIBTOOL_TRUE@socket.lo sleep.lo stack.lo strsignal.lo sysconf.lo \ -@USE_LIBTOOL_TRUE@sysctl.lo systat.lo system.lo tcdrain.lo tcsendbrk.lo \ -@USE_LIBTOOL_TRUE@termios.lo time.lo usleep.lo utimes.lo vallocr.lo \ -@USE_LIBTOOL_TRUE@wait.lo +@USE_LIBTOOL_TRUE@fpathconf.lo free.lo freer.lo ftok.lo funlockfile.lo \ +@USE_LIBTOOL_TRUE@getdate.lo getdate_err.lo gethostname.lo \ +@USE_LIBTOOL_TRUE@getoptlong.lo getreent.lo getrlimit64.lo ids.lo \ +@USE_LIBTOOL_TRUE@inode.lo io.lo io64.lo ipc.lo linux.lo malign.lo \ +@USE_LIBTOOL_TRUE@malignr.lo mallinfor.lo mallocr.lo malloptr.lo \ +@USE_LIBTOOL_TRUE@mallstatsr.lo mmap.lo mq_close.lo mq_getattr.lo \ +@USE_LIBTOOL_TRUE@mq_notify.lo mq_open.lo mq_receive.lo mq_send.lo \ +@USE_LIBTOOL_TRUE@mq_setattr.lo mq_unlink.lo msize.lo msizer.lo \ +@USE_LIBTOOL_TRUE@mstats.lo mtrim.lo mtrimr.lo ntp_gettime.lo \ +@USE_LIBTOOL_TRUE@pathconf.lo pread.lo pread64.lo process.lo psignal.lo \ +@USE_LIBTOOL_TRUE@pvallocr.lo pwrite.lo pwrite64.lo raise.lo realloc.lo \ +@USE_LIBTOOL_TRUE@reallocr.lo realpath.lo rename.lo resource.lo \ +@USE_LIBTOOL_TRUE@sched.lo select.lo seteuid.lo sethostname.lo \ +@USE_LIBTOOL_TRUE@setrlimit64.lo shm_open.lo shm_unlink.lo sig.lo \ +@USE_LIBTOOL_TRUE@sigaction.lo sigqueue.lo signal.lo siglongjmp.lo \ +@USE_LIBTOOL_TRUE@sigset.lo sigwait.lo socket.lo sleep.lo stack.lo \ +@USE_LIBTOOL_TRUE@strsignal.lo sysconf.lo sysctl.lo systat.lo system.lo \ +@USE_LIBTOOL_TRUE@tcdrain.lo tcsendbrk.lo termios.lo time.lo usleep.lo \ +@USE_LIBTOOL_TRUE@utimes.lo vallocr.lo wait.lo CFLAGS = @CFLAGS@ COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) diff --git a/newlib/libc/sys/linux/fpathconf.c b/newlib/libc/sys/linux/fpathconf.c new file mode 100644 index 0000000..63b95f9 --- /dev/null +++ b/newlib/libc/sys/linux/fpathconf.c @@ -0,0 +1,305 @@ +/* Linux specific extensions to fpathconf. + Copyright (C) 1991,95,96,98,99,2000,2001 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +/* Modified for newlib July 19, 2002 by Jeff Johnston */ + +#include <errno.h> +#include <stddef.h> +#include <unistd.h> +#include <limits.h> +#include <sys/stat.h> +#include <sys/statfs.h> +#include <sys/statvfs.h> +#include <machine/weakalias.h> +#include "linux_fsinfo.h" + +#define __set_errno(x) errno=(x) + +/* The Linux kernel header mentioned this as a kind of generic value. */ +#define LINUX_LINK_MAX 127 + +static long int posix_fpathconf (int fd, int name); + +/* Get file-specific information about descriptor FD. */ +long int +__fpathconf (fd, name) + int fd; + int name; +{ + if (name == _PC_LINK_MAX) + { + struct statfs fsbuf; + + /* Determine the filesystem type. */ + if (__fstatfs (fd, &fsbuf) < 0) + { + if (errno == ENOSYS) + /* not possible, return the default value. */ + return LINUX_LINK_MAX; + + /* Some error occured. */ + return -1; + } + + switch (fsbuf.f_type) + { + case EXT2_SUPER_MAGIC: + return EXT2_LINK_MAX; + + case MINIX_SUPER_MAGIC: + case MINIX_SUPER_MAGIC2: + return MINIX_LINK_MAX; + + case MINIX2_SUPER_MAGIC: + case MINIX2_SUPER_MAGIC2: + return MINIX2_LINK_MAX; + + case XENIX_SUPER_MAGIC: + return XENIX_LINK_MAX; + + case SYSV4_SUPER_MAGIC: + case SYSV2_SUPER_MAGIC: + return SYSV_LINK_MAX; + + case COH_SUPER_MAGIC: + return COH_LINK_MAX; + + case UFS_MAGIC: + case UFS_CIGAM: + return UFS_LINK_MAX; + + case REISERFS_SUPER_MAGIC: + return REISERFS_LINK_MAX; + + default: + return LINUX_LINK_MAX; + } + } + + return posix_fpathconf (fd, name); +} + +/* Get file-specific information about descriptor FD. */ +static long int +posix_fpathconf (fd, name) + int fd; + int name; +{ + if (fd < 0) + { + __set_errno (EBADF); + return -1; + } + + switch (name) + { + default: + __set_errno (EINVAL); + return -1; + + case _PC_LINK_MAX: +#ifdef LINK_MAX + return LINK_MAX; +#else + return -1; +#endif + + case _PC_MAX_CANON: +#ifdef MAX_CANON + return MAX_CANON; +#else + return -1; +#endif + + case _PC_MAX_INPUT: +#ifdef MAX_INPUT + return MAX_INPUT; +#else + return -1; +#endif + + case _PC_NAME_MAX: +#ifdef NAME_MAX + { + struct statfs buf; + int save_errno = errno; + + if (__fstatfs (fd, &buf) < 0) + { + if (errno == ENOSYS) + { + __set_errno (save_errno); + return NAME_MAX; + } + else if (errno == ENODEV) + __set_errno (EINVAL); + + return -1; + } + else + { +#ifdef _STATFS_F_NAMELEN + return buf.f_namelen; +#else +# ifdef _STATFS_F_NAME_MAX + return buf.f_name_max; +# else + return NAME_MAX; +# endif +#endif + } + } +#else + return -1; +#endif + + case _PC_PATH_MAX: +#ifdef PATH_MAX + return PATH_MAX; +#else + return -1; +#endif + + case _PC_PIPE_BUF: +#ifdef PIPE_BUF + return PIPE_BUF; +#else + return -1; +#endif + + case _PC_CHOWN_RESTRICTED: +#ifdef _POSIX_CHOWN_RESTRICTED + return _POSIX_CHOWN_RESTRICTED; +#else + return -1; +#endif + + case _PC_NO_TRUNC: +#ifdef _POSIX_NO_TRUNC + return _POSIX_NO_TRUNC; +#else + return -1; +#endif + + case _PC_VDISABLE: +#ifdef _POSIX_VDISABLE + return _POSIX_VDISABLE; +#else + return -1; +#endif + + case _PC_SYNC_IO: +#ifdef _POSIX_SYNC_IO + return _POSIX_SYNC_IO; +#else + return -1; +#endif + + case _PC_ASYNC_IO: +#ifdef _POSIX_ASYNC_IO + { + /* AIO is only allowed on regular files and block devices. */ + struct stat64 st; + + if (__fxstat64 (_STAT_VER, fd, &st) < 0 + || (! S_ISREG (st.st_mode) && ! S_ISBLK (st.st_mode))) + return -1; + else + return 1; + } +#else + return -1; +#endif + + case _PC_PRIO_IO: +#ifdef _POSIX_PRIO_IO + return _POSIX_PRIO_IO; +#else + return -1; +#endif + + case _PC_SOCK_MAXBUF: +#ifdef SOCK_MAXBUF + return SOCK_MAXBUF; +#else + return -1; +#endif + + case _PC_FILESIZEBITS: +#ifdef FILESIZEBITS + return FILESIZEBITS; +#else + /* We let platforms with larger file sizes overwrite this value. */ + return 32; +#endif + + case _PC_REC_INCR_XFER_SIZE: + /* XXX It is not entirely clear what the limit is supposed to do. + What is incremented? */ + return -1; + + case _PC_REC_MAX_XFER_SIZE: + /* XXX It is not entirely clear what the limit is supposed to do. + In general there is no top limit of the number of bytes which + case be transported at once. */ + return -1; + + case _PC_REC_MIN_XFER_SIZE: + { + /* XXX It is not entirely clear what the limit is supposed to do. + I assume this is the block size of the filesystem. */ + struct statvfs64 sv; + + if (__fstatvfs64 (fd, &sv) < 0) + return -1; + return sv.f_bsize; + } + + case _PC_REC_XFER_ALIGN: + { + /* XXX It is not entirely clear what the limit is supposed to do. + I assume that the number should reflect the minimal block + alignment. */ + struct statvfs64 sv; + + if (__fstatvfs64 (fd, &sv) < 0) + return -1; + return sv.f_frsize; + } + + case _PC_ALLOC_SIZE_MIN: + { + /* XXX It is not entirely clear what the limit is supposed to do. + I assume that the number should reflect the minimal block + alignment. */ + struct statvfs64 sv; + + if (__fstatvfs64 (fd, &sv) < 0) + return -1; + return sv.f_frsize; + } + + case _PC_SYMLINK_MAX: + /* In general there are no limits. If a system has one it should + overwrite this case. */ + return -1; + } +} + +weak_alias (__fpathconf, fpathconf) diff --git a/newlib/libc/sys/linux/inode.c b/newlib/libc/sys/linux/inode.c index 0820ec8..fc81243 100644 --- a/newlib/libc/sys/linux/inode.c +++ b/newlib/libc/sys/linux/inode.c @@ -23,6 +23,8 @@ _syscall1(int,unlink,const char *,pathname) _syscall1(int,chdir,const char *,path) _syscall3(int,mknod,const char *,pathname,mode_t,mode,dev_t,dev) _syscall2(int,chmod,const char *,path,mode_t,mode) +_syscall2(int,fchmod,int,filedes,mode_t,mode) +_syscall3(int,chown,const char *,path,uid_t,owner,gid_t,group) _syscall2(int,utime,const char *,filename,const struct utimbuf *,buf) _syscall2(int,access,const char *,filename,int,mode) _syscall2(int,mkdir,const char *,pathname,mode_t,mode) diff --git a/newlib/libc/sys/linux/io.c b/newlib/libc/sys/linux/io.c index 8da724e..c33461f 100644 --- a/newlib/libc/sys/linux/io.c +++ b/newlib/libc/sys/linux/io.c @@ -32,6 +32,8 @@ _syscall1(int,dup,int,fd) _syscall2(int,dup2,int,oldfd,int,newfd) _syscall3(int,fcntl,int,fd,int,cmd,long,arg) _syscall1(int,fdatasync,int,fd) +_syscall2(int,ftruncate,int,fd,off_t,len) +_syscall2(int,truncate,const char *,path,off_t,len) _syscall1(int,fsync,int,fd) _syscall3(int,poll,struct pollfd *,fds,nfds_t,nfds,int,timeout) diff --git a/newlib/libc/sys/linux/linux_fsinfo.h b/newlib/libc/sys/linux/linux_fsinfo.h new file mode 100644 index 0000000..692abe5 --- /dev/null +++ b/newlib/libc/sys/linux/linux_fsinfo.h @@ -0,0 +1,114 @@ +/* Constants from kernel header for various FSes. + Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#ifndef _LINUX_FSINFO_H +#define _LINUX_FSINFO_H 1 + +/* These definitions come from the kernel headers. But we cannot + include the headers here because of type clashes. If new + filesystem types will become available we have to add the + appropriate definitions here.*/ + +/* Constants that identify the `adfs' filesystem. */ +#define ADFS_SUPER_MAGIC 0xadf5 + +/* Constants that identify the `affs' filesystem. */ +#define AFFS_SUPER_MAGIC 0xadff + +/* Constants that identify the `bfs' filesystem. */ +#define BFS_MAGIC 0x1BADFACE + +/* Constants that identify the `coda' filesystem. */ +#define CODA_SUPER_MAGIC 0x73757245 + +/* Constants that identify the `coherent' filesystem. */ +#define COH_SUPER_MAGIC 0x012ff7b7 + +/* Constant that identifies the `devfs' filesystem. */ +#define DEVFS_SUPER_MAGIC 0x1373 + +/* Constant that identifies the `devpts' filesystem. */ +#define DEVPTS_SUPER_MAGIC 0x1cd1 + +/* Constant that identifies the `efs' filesystem. */ +#define EFS_SUPER_MAGIC 0x414A53 + +/* Constant that identifies the `ext2' and `ext3' filesystems. */ +#define EXT2_SUPER_MAGIC 0xef53 + +/* Constant that identifies the `hpfs' filesystem. */ +#define HPFS_SUPER_MAGIC 0xf995e849 + +/* Constant that identifies the `iso9660' filesystem. */ +#define ISOFS_SUPER_MAGIC 0x9660 + +/* Constants that identify the `minix2' filesystem. */ +#define MINIX2_SUPER_MAGIC 0x2468 +#define MINIX2_SUPER_MAGIC2 0x2478 + +/* Constants that identify the `minix' filesystem. */ +#define MINIX_SUPER_MAGIC 0x137f +#define MINIX_SUPER_MAGIC2 0x138F + +/* Constants that identify the `msdos' filesystem. */ +#define MSDOS_SUPER_MAGIC 0x4d44 + +/* Constants that identify the `ncp' filesystem. */ +#define NCP_SUPER_MAGIC 0x564c + +/* Constants that identify the `nfs' filesystem. */ +#define NFS_SUPER_MAGIC 0x6969 + +/* Constants that identify the `proc' filesystem. */ +#define PROC_SUPER_MAGIC 0x9fa0 + +/* Constants that identify the `qnx4' filesystem. */ +#define QNX4_SUPER_MAGIC 0x002f + +/* Constants that identify the `reiser' filesystem. */ +#define REISERFS_SUPER_MAGIC 0x52654973 + +/* Constants that identify the `smb' filesystem. */ +#define SMB_SUPER_MAGIC 0x517b + +/* Constants that identify the `sysV' filesystem. */ +#define SYSV2_SUPER_MAGIC 0x012ff7b6 +#define SYSV4_SUPER_MAGIC 0x012ff7b5 + +/* Constants that identify the `ufs' filesystem. */ +#define UFS_MAGIC 0x00011954 +#define UFS_CIGAM 0x54190100 /* byteswapped MAGIC */ + +/* Constants that identify the `xenix' filesystem. */ +#define XENIX_SUPER_MAGIC 0x012ff7b4 + +/* Constant that identifies the `shm' filesystem. */ +#define SHMFS_SUPER_MAGIC 0x01021994 + +/* Maximum link counts. */ +#define COH_LINK_MAX 10000 +#define EXT2_LINK_MAX 32000 +#define MINIX2_LINK_MAX 65530 +#define MINIX_LINK_MAX 250 +#define REISERFS_LINK_MAX 64535 +#define SYSV_LINK_MAX 126 /* 127? 251? */ +#define UFS_LINK_MAX EXT2_LINK_MAX +#define XENIX_LINK_MAX 126 /* ?? */ + +#endif /* linux_fsinfo.h */ diff --git a/newlib/libc/sys/linux/pathconf.c b/newlib/libc/sys/linux/pathconf.c new file mode 100644 index 0000000..6ce77d3 --- /dev/null +++ b/newlib/libc/sys/linux/pathconf.c @@ -0,0 +1,302 @@ +/* Linux specific extensions to pathconf. + Copyright (C) 1991,95,96,98,99,2000,2001 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +/* Modified for newlib July 19, 2002 - Jeff Johnston */ + +#include <errno.h> +#include <stddef.h> +#include <unistd.h> +#include <limits.h> +#include <fcntl.h> +#include <sys/stat.h> +#include <sys/statfs.h> +#include <sys/statvfs.h> +#include <machine/weakalias.h> +#include "linux_fsinfo.h" + +#define __set_errno(x) errno=(x) + +/* The Linux kernel header mentioned this as a kind of generic value. */ +#define LINUX_LINK_MAX 127 + +static long int posix_pathconf (const char *path, int name); + + +/* Get file-specific information about descriptor FD. */ +long int +__pathconf (path, name) + const char *path; + int name; +{ + if (name == _PC_LINK_MAX) + { + struct statfs fsbuf; + + /* Determine the filesystem type. */ + if (__statfs (path, &fsbuf) < 0) + { + if (errno == ENOSYS) + /* not possible, return the default value. */ + return LINUX_LINK_MAX; + + /* Some error occured. */ + return -1; + } + + switch (fsbuf.f_type) + { + case EXT2_SUPER_MAGIC: + return EXT2_LINK_MAX; + + case MINIX_SUPER_MAGIC: + case MINIX_SUPER_MAGIC2: + return MINIX_LINK_MAX; + + case MINIX2_SUPER_MAGIC: + case MINIX2_SUPER_MAGIC2: + return MINIX2_LINK_MAX; + + case XENIX_SUPER_MAGIC: + return XENIX_LINK_MAX; + + case SYSV4_SUPER_MAGIC: + case SYSV2_SUPER_MAGIC: + return SYSV_LINK_MAX; + + case COH_SUPER_MAGIC: + return COH_LINK_MAX; + + case UFS_MAGIC: + case UFS_CIGAM: + return UFS_LINK_MAX; + + case REISERFS_SUPER_MAGIC: + return REISERFS_LINK_MAX; + + default: + return LINUX_LINK_MAX; + } + } + + return posix_pathconf (path, name); +} + +/* Get file-specific information about PATH. */ +static long int +posix_pathconf (const char *path, int name) +{ + if (path[0] == '\0') + { + __set_errno (ENOENT); + return -1; + } + + switch (name) + { + default: + __set_errno (EINVAL); + return -1; + + case _PC_LINK_MAX: +#ifdef LINK_MAX + return LINK_MAX; +#else + return -1; +#endif + + case _PC_MAX_CANON: +#ifdef MAX_CANON + return MAX_CANON; +#else + return -1; +#endif + + case _PC_MAX_INPUT: +#ifdef MAX_INPUT + return MAX_INPUT; +#else + return -1; +#endif + + case _PC_NAME_MAX: +#ifdef NAME_MAX + { + struct statfs buf; + int save_errno = errno; + + if (__statfs (path, &buf) < 0) + { + if (errno == ENOSYS) + { + errno = save_errno; + return NAME_MAX; + } + return -1; + } + else + { +#ifdef _STATFS_F_NAMELEN + return buf.f_namelen; +#else +# ifdef _STATFS_F_NAME_MAX + return buf.f_name_max; +# else + return NAME_MAX; +# endif +#endif + } + } +#else + return -1; +#endif + + case _PC_PATH_MAX: +#ifdef PATH_MAX + return PATH_MAX; +#else + return -1; +#endif + + case _PC_PIPE_BUF: +#ifdef PIPE_BUF + return PIPE_BUF; +#else + return -1; +#endif + + case _PC_CHOWN_RESTRICTED: +#ifdef _POSIX_CHOWN_RESTRICTED + return _POSIX_CHOWN_RESTRICTED; +#else + return -1; +#endif + + case _PC_NO_TRUNC: +#ifdef _POSIX_NO_TRUNC + return _POSIX_NO_TRUNC; +#else + return -1; +#endif + + case _PC_VDISABLE: +#ifdef _POSIX_VDISABLE + return _POSIX_VDISABLE; +#else + return -1; +#endif + + case _PC_SYNC_IO: +#ifdef _POSIX_SYNC_IO + return _POSIX_SYNC_IO; +#else + return -1; +#endif + + case _PC_ASYNC_IO: +#ifdef _POSIX_ASYNC_IO + { + /* AIO is only allowed on regular files and block devices. */ + struct stat64 st; + + if (__xstat64 (_STAT_VER, path, &st) < 0 + || (! S_ISREG (st.st_mode) && ! S_ISBLK (st.st_mode))) + return -1; + else + return 1; + } +#else + return -1; +#endif + + case _PC_PRIO_IO: +#ifdef _POSIX_PRIO_IO + return _POSIX_PRIO_IO; +#else + return -1; +#endif + + case _PC_SOCK_MAXBUF: +#ifdef SOCK_MAXBUF + return SOCK_MAXBUF; +#else + return -1; +#endif + + case _PC_FILESIZEBITS: +#ifdef FILESIZEBITS + return FILESIZEBITS; +#else + /* We let platforms with larger file sizes overwrite this value. */ + return 32; +#endif + + case _PC_REC_INCR_XFER_SIZE: + /* XXX It is not entirely clear what the limit is supposed to do. + What is incremented? */ + return -1; + + case _PC_REC_MAX_XFER_SIZE: + /* XXX It is not entirely clear what the limit is supposed to do. + In general there is no top limit of the number of bytes which + case be transported at once. */ + return -1; + + case _PC_REC_MIN_XFER_SIZE: + { + /* XXX It is not entirely clear what the limit is supposed to do. + I assume this is the block size of the filesystem. */ + struct statvfs64 sv; + + if (__statvfs64 (path, &sv) < 0) + return -1; + return sv.f_bsize; + } + + case _PC_REC_XFER_ALIGN: + { + /* XXX It is not entirely clear what the limit is supposed to do. + I assume that the number should reflect the minimal block + alignment. */ + struct statvfs64 sv; + + if (__statvfs64 (path, &sv) < 0) + return -1; + return sv.f_frsize; + } + + case _PC_ALLOC_SIZE_MIN: + { + /* XXX It is not entirely clear what the limit is supposed to do. + I assume that the number should reflect the minimal block + alignment. */ + struct statvfs64 sv; + + if (__statvfs64 (path, &sv) < 0) + return -1; + return sv.f_frsize; + } + + case _PC_SYMLINK_MAX: + /* In general there are no limits. If a system has one it should + overwrite this case. */ + return -1; + } +} + +weak_alias (__pathconf, pathconf) diff --git a/newlib/libc/sys/linux/sys/unistd.h b/newlib/libc/sys/linux/sys/unistd.h new file mode 100644 index 0000000..24e8135 --- /dev/null +++ b/newlib/libc/sys/linux/sys/unistd.h @@ -0,0 +1,168 @@ +#ifndef _UNISTD_H +#define _UNISTD_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include <_ansi.h> +#include <sys/types.h> +#include <sys/_types.h> +#define __need_size_t +#define __need_ptrdiff_t +#include <stddef.h> + +extern char **environ; + +void _EXFUN(_exit, (int __status ) _ATTRIBUTE ((noreturn))); + +int _EXFUN(access,(const char *__path, int __amode )); +unsigned _EXFUN(alarm, (unsigned __secs )); +int _EXFUN(chdir, (const char *__path )); +int _EXFUN(chmod, (const char *__path, mode_t __mode )); +int _EXFUN(chown, (const char *__path, uid_t __owner, gid_t __group )); +#if defined(__CYGWIN__) || defined(__rtems__) +int _EXFUN(chroot, (const char *__path )); +#endif +int _EXFUN(close, (int __fildes )); +char _EXFUN(*ctermid, (char *__s )); +char _EXFUN(*cuserid, (char *__s )); +int _EXFUN(dup, (int __fildes )); +int _EXFUN(dup2, (int __fildes, int __fildes2 )); +#if defined(__CYGWIN__) +void _EXFUN(endusershell, (void)); +#endif +int _EXFUN(execl, (const char *__path, const char *, ... )); +int _EXFUN(execle, (const char *__path, const char *, ... )); +int _EXFUN(execlp, (const char *__file, const char *, ... )); +int _EXFUN(execv, (const char *__path, char * const __argv[] )); +int _EXFUN(execve, (const char *__path, char * const __argv[], char * const __envp[] )); +int _EXFUN(execvp, (const char *__file, char * const __argv[] )); +#if defined(__CYGWIN__) || defined(__rtems__) +int _EXFUN(fchdir, (int __fildes)); +#endif +int _EXFUN(fchmod, (int __fildes, mode_t __mode )); +int _EXFUN(fchown, (int __fildes, uid_t __owner, gid_t __group )); +pid_t _EXFUN(fork, (void )); +long _EXFUN(fpathconf, (int __fd, int __name )); +int _EXFUN(fsync, (int __fd)); +char _EXFUN(*getcwd, (char *__buf, size_t __size )); +#if defined(__CYGWIN__) +int _EXFUN(getdomainname ,(char *__name, size_t __len)); +#endif +gid_t _EXFUN(getegid, (void )); +uid_t _EXFUN(geteuid, (void )); +gid_t _EXFUN(getgid, (void )); +int _EXFUN(getgroups, (int __gidsetsize, gid_t __grouplist[] )); +char _EXFUN(*getlogin, (void )); +#if defined(_POSIX_THREAD_SAFE_FUNCTIONS) +int _EXFUN(getlogin_r, (char *name, size_t namesize) ); +#endif +char _EXFUN(*getpass, (__const char *__prompt)); +size_t _EXFUN(getpagesize, (void)); +pid_t _EXFUN(getpgid, (pid_t)); +pid_t _EXFUN(getpgrp, (void )); +pid_t _EXFUN(getpid, (void )); +pid_t _EXFUN(getppid, (void )); +uid_t _EXFUN(getuid, (void )); +#ifdef __CYGWIN__ +char * _EXFUN(getusershell, (void)); +char _EXFUN(*getwd, (char *__buf )); +int _EXFUN(iruserok, (unsigned long raddr, int superuser, const char *ruser, const char *luser)); +#endif +int _EXFUN(isatty, (int __fildes )); +int _EXFUN(lchown, (const char *__path, uid_t __owner, gid_t __group )); +int _EXFUN(link, (const char *__path1, const char *__path2 )); +int _EXFUN(nice, (int __nice_value )); +off_t _EXFUN(lseek, (int __fildes, off_t __offset, int __whence )); +long _EXFUN(pathconf, (const char *__path, int __name )); +int _EXFUN(pause, (void )); +#ifdef __CYGWIN__ +int _EXFUN(pthread_atfork, (void (*)(void), void (*)(void), void (*)(void))); +#endif +int _EXFUN(pipe, (int __fildes[2] )); +ssize_t _EXFUN(pread, (int __fd, void *__buf, size_t __nbytes, off_t __offset)); +ssize_t _EXFUN(pwrite, (int __fd, const void *__buf, size_t __nbytes, off_t __offset)); +_READ_WRITE_RETURN_TYPE _EXFUN(read, (int __fd, void *__buf, size_t __nbyte )); +#if defined(__CYGWIN__) +int _EXFUN(revoke, (char *path)); +#endif +int _EXFUN(rmdir, (const char *__path )); +#if defined(__CYGWIN__) +int _EXFUN(ruserok, (const char *rhost, int superuser, const char *ruser, const char *luser)); +#endif +#if defined(__rtems__) +void * _EXFUN(sbrk, (ptrdiff_t __incr)); +#else +void * _EXFUN(sbrk, (size_t __incr)); +#endif +#if defined(__CYGWIN__) +int _EXFUN(setegid, (gid_t __gid )); +int _EXFUN(seteuid, (uid_t __uid )); +#endif +int _EXFUN(setgid, (gid_t __gid )); +int _EXFUN(setpgid, (pid_t __pid, pid_t __pgid )); +int _EXFUN(setpgrp, (void )); +pid_t _EXFUN(setsid, (void )); +int _EXFUN(setuid, (uid_t __uid )); +#if defined(__CYGWIN__) +void _EXFUN(setusershell, (void)); +#endif +unsigned _EXFUN(sleep, (unsigned int __seconds )); +void _EXFUN(swab, (const void *, void *, ssize_t)); +long _EXFUN(sysconf, (int __name )); +pid_t _EXFUN(tcgetpgrp, (int __fildes )); +int _EXFUN(tcsetpgrp, (int __fildes, pid_t __pgrp_id )); +char _EXFUN(*ttyname, (int __fildes )); +int _EXFUN(unlink, (const char *__path )); +int _EXFUN(vhangup, (void )); +_READ_WRITE_RETURN_TYPE _EXFUN(write, (int __fd, const void *__buf, size_t __nbyte )); + +extern char *optarg; /* getopt(3) external variables */ +extern int optind, opterr, optopt; +int getopt(int, char * const [], const char *); +extern int optreset; /* getopt(3) external variable */ + +#ifndef _POSIX_SOURCE +pid_t _EXFUN(vfork, (void )); + +extern char *suboptarg; /* getsubopt(3) external variable */ +int getsubopt(char **, char * const *, char **); +#endif /* _POSIX_SOURCE */ + +/* Provide prototypes for most of the _<systemcall> names that are + provided in newlib for some compilers. */ +int _EXFUN(_close, (int __fildes )); +pid_t _EXFUN(_fork, (void )); +pid_t _EXFUN(_getpid, (void )); +int _EXFUN(_link, (const char *__path1, const char *__path2 )); +off_t _EXFUN(_lseek, (int __fildes, off_t __offset, int __whence )); +_READ_WRITE_RETURN_TYPE _EXFUN(_read, (int __fd, void *__buf, size_t __nbyte )); +void * _EXFUN(_sbrk, (size_t __incr)); +int _EXFUN(_unlink, (const char *__path )); +_READ_WRITE_RETURN_TYPE _EXFUN(_write, (int __fd, const void *__buf, size_t __nbyte )); +int _EXFUN(_execve, (const char *__path, char * const __argv[], char * const __envp[] )); + +#define F_OK 0 +#define R_OK 4 +#define W_OK 2 +#define X_OK 1 + +# define SEEK_SET 0 +# define SEEK_CUR 1 +# define SEEK_END 2 + +#include <sys/features.h> + +#define STDIN_FILENO 0 /* standard input file descriptor */ +#define STDOUT_FILENO 1 /* standard output file descriptor */ +#define STDERR_FILENO 2 /* standard error file descriptor */ + +#include <bits/confname.h> + +# define MAXPATHLEN 1024 + +#ifdef __cplusplus +} +#endif +#endif /* _SYS_UNISTD_H */ |