diff --git a/newlib/ChangeLog b/newlib/ChangeLog index c7dddf91a..75d38961a 100644 --- a/newlib/ChangeLog +++ b/newlib/ChangeLog @@ -1,3 +1,20 @@ +2002-07-24 Jeff Johnston + + * libc/sys/linux/Makefile.am: Add new files. + * libc/sys/linux/Makefile.in: Regenerated. + * libc/sys/linux/fstab.c: New file. + * libc/sys/linux/fstatvfs.c: Ditto. + * libc/sys/linux/fstatvfs64.c: Ditto. + * libc/sys/linux/internal_statvfs.c: Ditto. + * libc/sys/linux/mntent.c: Ditto. + * libc/sys/linux/mntent_r.c: Ditto. + * libc/sys/linux/statvfs.c: Ditto. + * libc/sys/linux/statvfs64.c: Ditto. + * libc/sys/linux/include/paths.h: Ditto. + * libc/sys/linux/inode.c (statfs, fstatfs): New syscalls + with double-underscore weak-aliases. + * libc/sys/linux/sys/stat.h: Add *stat64 prototypes. + 2002-07-24 Jeff Johnston * libc/include/signal.h (SIG_IGN, SIG_DFL, SIG_ERR): Change diff --git a/newlib/libc/sys/linux/Makefile.am b/newlib/libc/sys/linux/Makefile.am index 3635b43c2..d48e5da04 100644 --- a/newlib/libc/sys/linux/Makefile.am +++ b/newlib/libc/sys/linux/Makefile.am @@ -24,6 +24,9 @@ LIB_SOURCES = \ fpathconf.c \ free.c \ freer.c \ + fstab.c \ + fstatvfs.c \ + fstatvfs64.c \ ftok.c \ funlockfile.c \ getdate.c \ @@ -45,6 +48,8 @@ LIB_SOURCES = \ malloptr.c \ mallstatsr.c \ mmap.c \ + mntent.c \ + mntent_r.c \ mq_close.c \ mq_getattr.c \ mq_notify.c \ @@ -91,6 +96,8 @@ LIB_SOURCES = \ socket.c \ sleep.c \ stack.c \ + statvfs.c \ + statvfs64.c \ strsignal.c \ sysconf.c \ sysctl.c \ diff --git a/newlib/libc/sys/linux/Makefile.in b/newlib/libc/sys/linux/Makefile.in index bad3db1d1..a3e484534 100644 --- a/newlib/libc/sys/linux/Makefile.in +++ b/newlib/libc/sys/linux/Makefile.in @@ -1,6 +1,6 @@ -# Makefile.in generated automatically by automake 1.4 from Makefile.am +# Makefile.in generated automatically by automake 1.4-p5 from Makefile.am -# Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc. +# Copyright (C) 1994, 1995-8, 1999, 2001 Free Software Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. @@ -121,6 +121,9 @@ LIB_SOURCES = \ fpathconf.c \ free.c \ freer.c \ + fstab.c \ + fstatvfs.c \ + fstatvfs64.c \ ftok.c \ funlockfile.c \ getdate.c \ @@ -142,6 +145,8 @@ LIB_SOURCES = \ malloptr.c \ mallstatsr.c \ mmap.c \ + mntent.c \ + mntent_r.c \ mq_close.c \ mq_getattr.c \ mq_notify.c \ @@ -188,6 +193,8 @@ LIB_SOURCES = \ socket.c \ sleep.c \ stack.c \ + statvfs.c \ + statvfs64.c \ strsignal.c \ sysconf.c \ sysctl.c \ @@ -247,21 +254,23 @@ LIBS = @LIBS@ @USE_LIBTOOL_FALSE@clock_gettime.$(OBJEXT) clock_settime.$(OBJEXT) \ @USE_LIBTOOL_FALSE@ctermid.$(OBJEXT) flockfile.$(OBJEXT) \ @USE_LIBTOOL_FALSE@fpathconf.$(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@fstab.$(OBJEXT) fstatvfs.$(OBJEXT) \ +@USE_LIBTOOL_FALSE@fstatvfs64.$(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) \ -@USE_LIBTOOL_FALSE@mq_getattr.$(OBJEXT) mq_notify.$(OBJEXT) \ -@USE_LIBTOOL_FALSE@mq_open.$(OBJEXT) mq_receive.$(OBJEXT) \ -@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@mmap.$(OBJEXT) mntent.$(OBJEXT) mntent_r.$(OBJEXT) \ +@USE_LIBTOOL_FALSE@mq_close.$(OBJEXT) mq_getattr.$(OBJEXT) \ +@USE_LIBTOOL_FALSE@mq_notify.$(OBJEXT) mq_open.$(OBJEXT) \ +@USE_LIBTOOL_FALSE@mq_receive.$(OBJEXT) mq_send.$(OBJEXT) \ +@USE_LIBTOOL_FALSE@mq_setattr.$(OBJEXT) mq_unlink.$(OBJEXT) \ +@USE_LIBTOOL_FALSE@msize.$(OBJEXT) msizer.$(OBJEXT) mstats.$(OBJEXT) \ +@USE_LIBTOOL_FALSE@mtrim.$(OBJEXT) mtrimr.$(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) \ @@ -275,7 +284,8 @@ LIBS = @LIBS@ @USE_LIBTOOL_FALSE@sig.$(OBJEXT) sigaction.$(OBJEXT) sigqueue.$(OBJEXT) \ @USE_LIBTOOL_FALSE@signal.$(OBJEXT) siglongjmp.$(OBJEXT) \ @USE_LIBTOOL_FALSE@sigset.$(OBJEXT) sigwait.$(OBJEXT) socket.$(OBJEXT) \ -@USE_LIBTOOL_FALSE@sleep.$(OBJEXT) stack.$(OBJEXT) strsignal.$(OBJEXT) \ +@USE_LIBTOOL_FALSE@sleep.$(OBJEXT) stack.$(OBJEXT) statvfs.$(OBJEXT) \ +@USE_LIBTOOL_FALSE@statvfs64.$(OBJEXT) strsignal.$(OBJEXT) \ @USE_LIBTOOL_FALSE@sysconf.$(OBJEXT) sysctl.$(OBJEXT) systat.$(OBJEXT) \ @USE_LIBTOOL_FALSE@system.$(OBJEXT) tcdrain.$(OBJEXT) \ @USE_LIBTOOL_FALSE@tcsendbrk.$(OBJEXT) termios.$(OBJEXT) time.$(OBJEXT) \ @@ -286,23 +296,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 ctermid.lo \ -@USE_LIBTOOL_TRUE@flockfile.lo fpathconf.lo free.lo freer.lo ftok.lo \ -@USE_LIBTOOL_TRUE@funlockfile.lo getdate.lo getdate_err.lo \ -@USE_LIBTOOL_TRUE@gethostname.lo getoptlong.lo getreent.lo \ -@USE_LIBTOOL_TRUE@getrlimit64.lo ids.lo inode.lo io.lo io64.lo ipc.lo \ -@USE_LIBTOOL_TRUE@linux.lo malign.lo malignr.lo mallinfor.lo mallocr.lo \ -@USE_LIBTOOL_TRUE@malloptr.lo mallstatsr.lo mmap.lo mq_close.lo \ -@USE_LIBTOOL_TRUE@mq_getattr.lo mq_notify.lo mq_open.lo mq_receive.lo \ -@USE_LIBTOOL_TRUE@mq_send.lo mq_setattr.lo mq_unlink.lo msize.lo \ -@USE_LIBTOOL_TRUE@msizer.lo 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 \ -@USE_LIBTOOL_TRUE@readdir64.lo realloc.lo reallocr.lo realpath.lo \ -@USE_LIBTOOL_TRUE@rename.lo resource.lo sched.lo select.lo seteuid.lo \ -@USE_LIBTOOL_TRUE@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@flockfile.lo fpathconf.lo free.lo freer.lo fstab.lo \ +@USE_LIBTOOL_TRUE@fstatvfs.lo fstatvfs64.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 mntent.lo mntent_r.lo \ +@USE_LIBTOOL_TRUE@mq_close.lo mq_getattr.lo mq_notify.lo mq_open.lo \ +@USE_LIBTOOL_TRUE@mq_receive.lo mq_send.lo mq_setattr.lo mq_unlink.lo \ +@USE_LIBTOOL_TRUE@msize.lo msizer.lo mstats.lo mtrim.lo mtrimr.lo \ +@USE_LIBTOOL_TRUE@ntp_gettime.lo pathconf.lo pread.lo pread64.lo \ +@USE_LIBTOOL_TRUE@process.lo psignal.lo pvallocr.lo pwrite.lo \ +@USE_LIBTOOL_TRUE@pwrite64.lo raise.lo readdir64.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@statvfs.lo statvfs64.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 ttyname_r.lo usleep.lo utimes.lo \ @USE_LIBTOOL_TRUE@vallocr.lo wait.lo @@ -444,7 +456,7 @@ maintainer-clean-recursive: dot_seen=no; \ rev=''; list='$(SUBDIRS)'; for subdir in $$list; do \ rev="$$subdir $$rev"; \ - test "$$subdir" = "." && dot_seen=yes; \ + test "$$subdir" != "." || dot_seen=yes; \ done; \ test "$$dot_seen" = "no" && rev=". $$rev"; \ target=`echo $@ | sed s/-recursive//`; \ diff --git a/newlib/libc/sys/linux/fstab.c b/newlib/libc/sys/linux/fstab.c new file mode 100644 index 000000000..f98f4b740 --- /dev/null +++ b/newlib/libc/sys/linux/fstab.c @@ -0,0 +1,195 @@ +/* Copyright (C) 1995, 1996, 1997, 1998, 2000 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. */ + +#include +#include +#include +#include +#include +#include +#include + +#define BUFFER_SIZE 0x1fc0 + +struct fstab_state +{ + FILE *fs_fp; + char *fs_buffer; + struct mntent fs_mntres; + struct fstab fs_ret; +}; + +static struct fstab_state *fstab_init (int opt_rewind); +static struct mntent *fstab_fetch (struct fstab_state *state); +static struct fstab *fstab_convert (struct fstab_state *state); + +static struct fstab_state fstab_state; + + +int +setfsent (void) +{ + return fstab_init (1) != NULL; +} + + +struct fstab * +getfsent (void) +{ + struct fstab_state *state; + + state = fstab_init (0); + if (state == NULL) + return NULL; + if (fstab_fetch (state) == NULL) + return NULL; + return fstab_convert (state); +} + + +struct fstab * +getfsspec (name) + const char *name; +{ + struct fstab_state *state; + struct mntent *m; + + state = fstab_init (1); + if (state == NULL) + return NULL; + while ((m = fstab_fetch (state)) != NULL) + if (strcmp (m->mnt_fsname, name) == 0) + return fstab_convert (state); + return NULL; +} + + +struct fstab * +getfsfile (name) + const char *name; +{ + struct fstab_state *state; + struct mntent *m; + + state = fstab_init (1); + if (state == NULL) + return NULL; + while ((m = fstab_fetch (state)) != NULL) + if (strcmp (m->mnt_dir, name) == 0) + return fstab_convert (state); + return NULL; +} + + +void +endfsent () +{ + struct fstab_state *state; + + state = &fstab_state; + if (state->fs_fp != NULL) + { + (void) __endmntent (state->fs_fp); + state->fs_fp = NULL; + } +} + + +static struct fstab_state * +fstab_init (int opt_rewind) +{ + struct fstab_state *state; + char *buffer; + FILE *fp; + + state = &fstab_state; + + buffer = state->fs_buffer; + if (buffer == NULL) + { + buffer = (char *) malloc (BUFFER_SIZE); + if (buffer == NULL) + return NULL; + state->fs_buffer = buffer; + } + + fp = state->fs_fp; + if (fp != NULL) + { + if (opt_rewind) + rewind (fp); + } + else + { + fp = __setmntent (_PATH_FSTAB, "r"); + if (fp == NULL) + return NULL; + state->fs_fp = fp; + } + + return state; +} + + +static struct mntent * +fstab_fetch (struct fstab_state *state) +{ + return __getmntent_r (state->fs_fp, &state->fs_mntres, + state->fs_buffer, BUFFER_SIZE); +} + + +static struct fstab * +fstab_convert (struct fstab_state *state) +{ + struct mntent *m; + struct fstab *f; + + m = &state->fs_mntres; + f = &state->fs_ret; + + f->fs_spec = m->mnt_fsname; + f->fs_file = m->mnt_dir; + f->fs_vfstype = m->mnt_type; + f->fs_mntops = m->mnt_opts; + f->fs_type = (__hasmntopt (m, FSTAB_RW) ? FSTAB_RW : + __hasmntopt (m, FSTAB_RQ) ? FSTAB_RQ : + __hasmntopt (m, FSTAB_RO) ? FSTAB_RO : + __hasmntopt (m, FSTAB_SW) ? FSTAB_SW : + __hasmntopt (m, FSTAB_XX) ? FSTAB_XX : + "??"); + f->fs_freq = m->mnt_freq; + f->fs_passno = m->mnt_passno; + return f; +} + + +/* Make sure the memory is freed if the programs ends while in + memory-debugging mode and something actually was allocated. */ +static void +__attribute__ ((unused)) +fstab_free (void) +{ + char *buffer; + + buffer = fstab_state.fs_buffer; + if (buffer != NULL) + free ((void *) buffer); +} + +text_set_element (__libc_subfreeres, fstab_free); diff --git a/newlib/libc/sys/linux/fstatvfs.c b/newlib/libc/sys/linux/fstatvfs.c new file mode 100644 index 000000000..e1a12603a --- /dev/null +++ b/newlib/libc/sys/linux/fstatvfs.c @@ -0,0 +1,47 @@ +/* Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Ulrich Drepper , 1998. + + 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. */ + +#define _GNU_SOURCE + +#include +#include +#include +#include +#include +#include +#include +#include + + +int +fstatvfs (int fd, struct statvfs *buf) +{ + struct statfs fsbuf; + struct stat64 st; + + /* Get as much information as possible from the system. */ + if (__fstatfs (fd, &fsbuf) < 0) + return -1; + +#define STAT(st) fstat64 (fd, st) +#include "internal_statvfs.c" + + /* We signal success if the statfs call succeeded. */ + return 0; +} diff --git a/newlib/libc/sys/linux/fstatvfs64.c b/newlib/libc/sys/linux/fstatvfs64.c new file mode 100644 index 000000000..65c9e609b --- /dev/null +++ b/newlib/libc/sys/linux/fstatvfs64.c @@ -0,0 +1,49 @@ +/* Return information about the filesystem on which FD resides. + Copyright (C) 1996, 1997, 1998, 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. */ + +#include +#include +#include +#include + +/* Return information about the filesystem on which FD resides. */ +int +__fstatvfs64 (int fd, struct statvfs64 *buf) +{ + struct statvfs buf32; + + if (fstatvfs (fd, &buf32) < 0) + return -1; + + buf->f_bsize = buf32.f_bsize; + buf->f_frsize = buf32.f_frsize; + buf->f_blocks = buf32.f_blocks; + buf->f_bfree = buf32.f_bfree; + buf->f_bavail = buf32.f_bavail; + buf->f_files = buf32.f_files; + buf->f_ffree = buf32.f_ffree; + buf->f_favail = buf32.f_favail; + buf->f_fsid = buf32.f_fsid; + buf->f_flag = buf32.f_flag; + buf->f_namemax = buf32.f_namemax; + memcpy (buf->__f_spare, buf32.__f_spare, sizeof (buf32.__f_spare)); + + return 0; +} +weak_alias (__fstatvfs64, fstatvfs64) diff --git a/newlib/libc/sys/linux/include/paths.h b/newlib/libc/sys/linux/include/paths.h new file mode 100644 index 000000000..a87831e74 --- /dev/null +++ b/newlib/libc/sys/linux/include/paths.h @@ -0,0 +1,74 @@ +/* + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)paths.h 8.1 (Berkeley) 6/2/93 + */ + +#ifndef _PATHS_H_ +#define _PATHS_H_ + +/* Default search path. */ +#define _PATH_DEFPATH "/usr/bin:/bin" +/* All standard utilities path. */ +#define _PATH_STDPATH \ + "/usr/bin:/bin:/usr/sbin:/sbin" + +#define _PATH_BSHELL "/bin/sh" +#define _PATH_CONSOLE "/dev/console" +#define _PATH_CSHELL "/bin/csh" +#define _PATH_DEVDB "/var/run/dev.db" +#define _PATH_DEVNULL "/dev/null" +#define _PATH_DRUM "/dev/drum" +#define _PATH_KLOG "/proc/kmsg" +#define _PATH_KMEM "/dev/kmem" +#define _PATH_LASTLOG "/var/log/lastlog" +#define _PATH_MAILDIR "/var/mail" +#define _PATH_MAN "/usr/share/man" +#define _PATH_MEM "/dev/mem" +#define _PATH_MNTTAB "/etc/fstab" +#define _PATH_MOUNTED "/etc/mtab" +#define _PATH_NOLOGIN "/etc/nologin" +#define _PATH_PRESERVE "/var/lib" +#define _PATH_RWHODIR "/var/spool/rwho" +#define _PATH_SENDMAIL "/usr/sbin/sendmail" +#define _PATH_SHADOW "/etc/shadow" +#define _PATH_SHELLS "/etc/shells" +#define _PATH_TTY "/dev/tty" +#define _PATH_UNIX "/boot/vmlinux" +#define _PATH_UTMP "/var/run/utmp" +#define _PATH_VI "/bin/vi" +#define _PATH_WTMP "/var/log/wtmp" + +/* Provide trailing slash, since mostly used for building pathnames. */ +#define _PATH_DEV "/dev/" +#define _PATH_TMP "/tmp/" +#define _PATH_VARDB "/var/db/" +#define _PATH_VARRUN "/var/run/" +#define _PATH_VARTMP "/var/tmp/" + +#endif /* !_PATHS_H_ */ diff --git a/newlib/libc/sys/linux/inode.c b/newlib/libc/sys/linux/inode.c index fc8124381..6b2a2571f 100644 --- a/newlib/libc/sys/linux/inode.c +++ b/newlib/libc/sys/linux/inode.c @@ -34,11 +34,16 @@ _syscall1(int,chroot,const char *,path) _syscall2(int,symlink,const char *,oldpath,const char *,newpath) _syscall3(int,readlink,const char *,path,char *,buf,size_t,bufsiz) _syscall2(int,stat,const char *,file_name,struct stat *,buf) +_syscall2(int,statfs,const char *,file_name,struct statfs *,buf) _syscall2(int,lstat,const char *,file_name,struct stat *,buf) _syscall2(int,fstat,int,filedes,struct stat *,buf) +_syscall2(int,fstatfs,int,filedes,struct statfs *,buf) _syscall3(int,getdents,int,fd,struct dirent *,dirp,unsigned int,count) _syscall1(mode_t,__umask,mode_t,mask) +weak_alias(__libc_statfs,__statfs) +weak_alias(__libc_fstatfs,__fstatfs) + static _syscall3(int,fchown32,int,fd,uid_t,owner,gid_t,group) int diff --git a/newlib/libc/sys/linux/internal_statvfs.c b/newlib/libc/sys/linux/internal_statvfs.c new file mode 100644 index 000000000..9efb7c227 --- /dev/null +++ b/newlib/libc/sys/linux/internal_statvfs.c @@ -0,0 +1,109 @@ +/* Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Ulrich Drepper , 1998. + + 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. */ + + /* Now fill in the fields we have information for. */ + buf->f_bsize = fsbuf.f_bsize; + /* Linux does not support f_frsize, so set it to the full block size. */ + buf->f_frsize = fsbuf.f_bsize; + buf->f_blocks = fsbuf.f_blocks; + buf->f_bfree = fsbuf.f_bfree; + buf->f_bavail = fsbuf.f_bavail; + buf->f_files = fsbuf.f_files; + buf->f_ffree = fsbuf.f_ffree; + if (sizeof (buf->f_fsid) == sizeof (fsbuf.f_fsid)) + buf->f_fsid = (fsbuf.f_fsid.__val[0] + | ((unsigned long int) fsbuf.f_fsid.__val[1] + << (8 * (sizeof (buf->f_fsid) + - sizeof (fsbuf.f_fsid.__val[0]))))); + else + /* We cannot help here. The statvfs element is not large enough to + contain both words of the statfs f_fsid field. */ + buf->f_fsid = fsbuf.f_fsid.__val[0]; +#ifdef _STATVFSBUF_F_UNUSED + buf->__f_unused = 0; +#endif + buf->f_namemax = fsbuf.f_namelen; + memset (buf->__f_spare, '\0', 6 * sizeof (int)); + + /* What remains to do is to fill the fields f_favail and f_flag. */ + + /* XXX I have no idea how to compute f_favail. Any idea??? */ + buf->f_favail = buf->f_ffree; + + /* Determining the flags is tricky. We have to read /proc/mounts or + the /etc/mtab file and search for the entry which matches the given + file. The way we can test for matching filesystem is using the + device number. */ + buf->f_flag = 0; + if (STAT (&st) >= 0) + { + int save_errno = errno; + struct mntent mntbuf; + FILE *mtab; + + mtab = __setmntent ("/proc/mounts", "r"); + if (mtab == NULL) + mtab = __setmntent (_PATH_MOUNTED, "r"); + + if (mtab != NULL) + { + char tmpbuf[1024]; + + while (__getmntent_r (mtab, &mntbuf, tmpbuf, sizeof (tmpbuf))) + { + struct stat64 fsst; + + /* Find out about the device the current entry is for. */ + if (stat64 (mntbuf.mnt_dir, &fsst) >= 0 + && st.st_dev == fsst.st_dev) + { + /* Bingo, we found the entry for the device FD is on. + Now interpret the option string. */ + char *cp = mntbuf.mnt_opts; + char *opt; + + while ((opt = strsep (&cp, ",")) != NULL) + if (strcmp (opt, "ro") == 0) + buf->f_flag |= ST_RDONLY; + else if (strcmp (opt, "nosuid") == 0) + buf->f_flag |= ST_NOSUID; + else if (strcmp (opt, "noexec") == 0) + buf->f_flag |= ST_NOEXEC; + else if (strcmp (opt, "nodev") == 0) + buf->f_flag |= ST_NODEV; + else if (strcmp (opt, "sync") == 0) + buf->f_flag |= ST_SYNCHRONOUS; + else if (strcmp (opt, "mand") == 0) + buf->f_flag |= ST_MANDLOCK; + else if (strcmp (opt, "noatime") == 0) + buf->f_flag |= ST_NOATIME; + else if (strcmp (opt, "nodiratime") == 0) + buf->f_flag |= ST_NODIRATIME; + + /* We can stop looking for more entries. */ + break; + } + } + + /* Close the file. */ + __endmntent (mtab); + } + + errno = (save_errno); + } diff --git a/newlib/libc/sys/linux/mntent.c b/newlib/libc/sys/linux/mntent.c new file mode 100644 index 000000000..ecd223f50 --- /dev/null +++ b/newlib/libc/sys/linux/mntent.c @@ -0,0 +1,76 @@ +/* Utilities for reading/writing fstab, mtab, etc. + Copyright (C) 1995, 1996, 1997, 2000 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. */ + +#include +#include +#include +#include + +/* We don't want to allocate the static buffer all the time since it + is not always used (in fact, rather infrequently). Accept the + extra cost of a `malloc'. */ +static char *getmntent_buffer; + +/* This is the size of the buffer. This is really big. */ +#define BUFFER_SIZE 4096 + + +static void +allocate (void) +{ + getmntent_buffer = (char *) malloc (BUFFER_SIZE); +} + + +struct mntent * +getmntent (FILE *stream) +{ + static struct mntent m; + static int once; + + do { + if (__pthread_once != NULL) + __pthread_once (&once, allocate); + else if (once == 0) { + allocate (); + once = !(0); + } + } while (0); + + + if (getmntent_buffer == NULL) + /* If no core is available we don't have a chance to run the + program successfully and so returning NULL is an acceptable + result. */ + return NULL; + + return __getmntent_r (stream, &m, getmntent_buffer, BUFFER_SIZE); +} + + +/* Make sure the memory is freed if the programs ends while in + memory-debugging mode and something actually was allocated. */ +static void +__attribute__ ((unused)) +free_mem (void) +{ + free (getmntent_buffer); +} + +text_set_element (__libc_subfreeres, free_mem); diff --git a/newlib/libc/sys/linux/mntent_r.c b/newlib/libc/sys/linux/mntent_r.c new file mode 100644 index 000000000..b534fb69d --- /dev/null +++ b/newlib/libc/sys/linux/mntent_r.c @@ -0,0 +1,256 @@ +/* Utilities for reading/writing fstab, mtab, etc. + Copyright (C) 1995-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. */ + +#include +#include +#include +#include +#include +#include + +/* Prepare to begin reading and/or writing mount table entries from the + beginning of FILE. MODE is as for `fopen'. */ +FILE * +__setmntent (const char *file, const char *mode) +{ + FILE *result = fopen (file, mode); + + return result; +} +weak_alias (__setmntent, setmntent) + + +/* Close a stream opened with `setmntent'. */ +int +__endmntent (FILE *stream) +{ + if (stream) /* SunOS 4.x allows for NULL stream */ + fclose (stream); + return 1; /* SunOS 4.x says to always return 1 */ +} +weak_alias (__endmntent, endmntent) + + +/* Since the values in a line are separated by spaces, a name cannot + contain a space. Therefore some programs encode spaces in names + by the strings "\040". We undo the encoding when reading an entry. + The decoding happens in place. */ +static char * +decode_name (char *buf) +{ + char *rp = buf; + char *wp = buf; + + do + if (rp[0] == '\\' && rp[1] == '0' && rp[2] == '4' && rp[3] == '0') + { + /* \040 is a SPACE. */ + *wp++ = ' '; + rp += 3; + } + else if (rp[0] == '\\' && rp[1] == '0' && rp[2] == '1' && rp[3] == '2') + { + /* \012 is a TAB. */ + *wp++ = '\t'; + rp += 3; + } + else if (rp[0] == '\\' && rp[1] == '\\') + { + /* We have to escape \\ to be able to represent all characters. */ + *wp++ = '\\'; + rp += 1; + } + else + *wp++ = *rp; + while (*rp++ != '\0'); + + return buf; +} + + +/* Read one mount table entry from STREAM. Returns a pointer to storage + reused on the next call, or null for EOF or error (use feof/ferror to + check). */ +struct mntent * +__getmntent_r (FILE *stream, struct mntent *mp, char *buffer, int bufsiz) +{ + char *cp; + char *head; + + flockfile (stream); + do + { + char *end_ptr; + + if (fgets (buffer, bufsiz, stream) == NULL) + { + funlockfile (stream); + return NULL; + } + + end_ptr = strchr (buffer, '\n'); + if (end_ptr != NULL) /* chop newline */ + *end_ptr = '\0'; + else + { + /* Not the whole line was read. Do it now but forget it. */ + char tmp[1024]; + while (fgets (tmp, sizeof tmp, stream) != NULL) + if (strchr (tmp, '\n') != NULL) + break; + } + + head = buffer + strspn (buffer, " \t"); + /* skip empty lines and comment lines: */ + } + while (head[0] == '\0' || head[0] == '#'); + + cp = strsep (&head, " \t"); + mp->mnt_fsname = cp != NULL ? decode_name (cp) : (char *) ""; + if (head) + head += strspn (head, " \t"); + cp = strsep (&head, " \t"); + mp->mnt_dir = cp != NULL ? decode_name (cp) : (char *) ""; + if (head) + head += strspn (head, " \t"); + cp = strsep (&head, " \t"); + mp->mnt_type = cp != NULL ? decode_name (cp) : (char *) ""; + if (head) + head += strspn (head, " \t"); + cp = strsep (&head, " \t"); + mp->mnt_opts = cp != NULL ? decode_name (cp) : (char *) ""; + switch (head ? sscanf (head, " %d %d ", &mp->mnt_freq, &mp->mnt_passno) : 0) + { + case 0: + mp->mnt_freq = 0; + case 1: + mp->mnt_passno = 0; + case 2: + break; + } + funlockfile (stream); + + return mp; +} +weak_alias (__getmntent_r, getmntent_r) + + +/* We have to use an encoding for names if they contain spaces or tabs. + To be able to represent all characters we also have to escape the + backslash itself. This "function" must be a macro since we use + `alloca'. */ +#define encode_name(name) \ + do { \ + const char *rp = name; \ + \ + while (*rp != '\0') \ + if (*rp == ' ' || *rp == '\t' || *rp == '\\') \ + break; \ + else \ + ++rp; \ + \ + if (*rp != '\0') \ + { \ + /* In the worst case the length of the string can increase to \ + founr times the current length. */ \ + char *wp; \ + \ + rp = name; \ + name = wp = (char *) alloca (strlen (name) * 4 + 1); \ + \ + do \ + if (*rp == ' ') \ + { \ + *wp++ = '\\'; \ + *wp++ = '0'; \ + *wp++ = '4'; \ + *wp++ = '0'; \ + } \ + else if (*rp == '\t') \ + { \ + *wp++ = '\\'; \ + *wp++ = '0'; \ + *wp++ = '1'; \ + *wp++ = '2'; \ + } \ + else if (*rp == '\\') \ + { \ + *wp++ = '\\'; \ + *wp++ = '\\'; \ + } \ + else \ + *wp++ = *rp; \ + while (*rp++ != '\0'); \ + } \ + } while (0) + + +/* Write the mount table entry described by MNT to STREAM. + Return zero on success, nonzero on failure. */ +int +__addmntent (FILE *stream, const struct mntent *mnt) +{ + struct mntent mntcopy = *mnt; + if (fseek (stream, 0, SEEK_END)) + return 1; + + /* Encode spaces and tabs in the names. */ + encode_name (mntcopy.mnt_fsname); + encode_name (mntcopy.mnt_dir); + encode_name (mntcopy.mnt_type); + encode_name (mntcopy.mnt_opts); + + return (fprintf (stream, "%s %s %s %s %d %d\n", + mntcopy.mnt_fsname, + mntcopy.mnt_dir, + mntcopy.mnt_type, + mntcopy.mnt_opts, + mntcopy.mnt_freq, + mntcopy.mnt_passno) + < 0 ? 1 : 0); +} +weak_alias (__addmntent, addmntent) + + +/* Search MNT->mnt_opts for an option matching OPT. + Returns the address of the substring, or null if none found. */ +char * +__hasmntopt (const struct mntent *mnt, const char *opt) +{ + const size_t optlen = strlen (opt); + char *rest = mnt->mnt_opts, *p; + + while ((p = strstr (rest, opt)) != NULL) + { + if (p == rest + || (p[-1] == ',' + && (p[optlen] == '\0' || + p[optlen] == '=' || + p[optlen] == ','))) + return p; + + rest = strchr (rest, ','); + if (rest == NULL) + break; + ++rest; + } + + return NULL; +} +weak_alias (__hasmntopt, hasmntopt) diff --git a/newlib/libc/sys/linux/statvfs.c b/newlib/libc/sys/linux/statvfs.c new file mode 100644 index 000000000..4b0d51abd --- /dev/null +++ b/newlib/libc/sys/linux/statvfs.c @@ -0,0 +1,47 @@ +/* Copyright (C) 1998, 2000 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Ulrich Drepper , 1998. + + 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. */ + +#define _GNU_SOURCE + +#include +#include +#include +#include +#include +#include +#include +#include + + +int +statvfs (const char *file, struct statvfs *buf) +{ + struct statfs fsbuf; + struct stat64 st; + + /* Get as much information as possible from the system. */ + if (__statfs (file, &fsbuf) < 0) + return -1; + +#define STAT(st) stat64 (file, st) +#include "internal_statvfs.c" + + /* We signal success if the statfs call succeeded. */ + return 0; +} diff --git a/newlib/libc/sys/linux/statvfs64.c b/newlib/libc/sys/linux/statvfs64.c new file mode 100644 index 000000000..f612b991d --- /dev/null +++ b/newlib/libc/sys/linux/statvfs64.c @@ -0,0 +1,50 @@ +/* Return information about the filesystem on which FILE resides. + Copyright (C) 1998, 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. */ + +#include +#include +#include +#include +#include + +/* Return information about the filesystem on which FILE resides. */ +int +__statvfs64 (const char *file, struct statvfs64 *buf) +{ + struct statvfs buf32; + + if (statvfs (file, &buf32) < 0) + return -1; + + buf->f_bsize = buf32.f_bsize; + buf->f_frsize = buf32.f_frsize; + buf->f_blocks = buf32.f_blocks; + buf->f_bfree = buf32.f_bfree; + buf->f_bavail = buf32.f_bavail; + buf->f_files = buf32.f_files; + buf->f_ffree = buf32.f_ffree; + buf->f_favail = buf32.f_favail; + buf->f_fsid = buf32.f_fsid; + buf->f_flag = buf32.f_flag; + buf->f_namemax = buf32.f_namemax; + memcpy (buf->__f_spare, buf32.__f_spare, sizeof (buf32.__f_spare)); + + return 0; +} +weak_alias (__statvfs64, statvfs64) diff --git a/newlib/libc/sys/linux/sys/stat.h b/newlib/libc/sys/linux/sys/stat.h index bac6a1174..ce20cb684 100644 --- a/newlib/libc/sys/linux/sys/stat.h +++ b/newlib/libc/sys/linux/sys/stat.h @@ -17,13 +17,16 @@ #include int _EXFUN(fstat,( int __fd, struct stat *__sbuf )); +int _EXFUN(fstat64,( int __fd, struct stat64 *__sbuf )); int _EXFUN(mkdir,( const char *_path, mode_t __mode )); int _EXFUN(mkfifo,( const char *__path, mode_t __mode )); int _EXFUN(stat,( const char *__path, struct stat *__sbuf )); +int _EXFUN(stat64,( const char *__path, struct stat64 *__sbuf )); mode_t _EXFUN(umask,( mode_t __mask )); #ifndef _POSIX_SOURCE int _EXFUN(lstat,( const char *file_name, struct stat *buf)); +int _EXFUN(lstat64,( const char *file_name, struct stat64 *buf)); #endif /* _POSIX_SOURCE */ #endif /* _SYS_STAT_H */