From: David Bartley Date: Mon, 9 Feb 2009 01:13:00 +0000 (+0000) Subject: Re-add linux-style getmntent X-Git-Url: http://git.csclub.uwaterloo.ca/?p=kopensolaris-gnu%2Fglibc.git;a=commitdiff_plain;h=b14cb63b486b3f99011aef58951116150bcfa924 Re-add linux-style getmntent --- diff --git a/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/Makefile b/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/Makefile index f4f6fc5f7b..210614c256 100644 --- a/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/Makefile +++ b/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/Makefile @@ -59,7 +59,6 @@ sysdep_headers += sys/feature_tests.h sys/dirent.h sys/utime.h sys/machelf.h \ sysdep_headers += rtld_db.h pcsample.h atomic.h bits/machtypes.h door.h \ ucred.h priv.h zone.h port.h deflt.h procfs.h rctl.h headers := $(filter-out sys/sysinfo.h sys/xattr.h, $(headers)) -headers := $(filter-out fstab.h mntent.h, $(headers)) endif ifeq ($(subdir),dirent) diff --git a/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/Versions b/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/Versions index 51eee66692..1549d754c7 100644 --- a/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/Versions +++ b/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/Versions @@ -45,11 +45,14 @@ libc { getacct; _getauuserent; _getauusernam; _getauthattr; _getauthnam; getcpuid; _getexecattr; getexecname; _getexecprof; getextmntent; gethrtime; gethrvtime; getipnodebyaddr; getipnodebyname; getipsecalgbyname; - getipsecalgbynum; getmntany; getpagesizes; getpagesizes2; getpeerucred; - getpflags; getppriv; getprivimplinfo; _getprofattr; _getprofnam; getprojid; - getrctl; gettaskid; _getuserattr; _getusernam; getustack; getvfsany; - getvfsent; getvfsfile; getvfsspec; getvmusage; getzoneid; getzoneidbyname; - getzonenamebyid; + getipsecalgbynum; getmntany; __getmntent_sun; getpagesizes; getpagesizes2; + getpeerucred; getpflags; getppriv; getprivimplinfo; _getprofattr; + _getprofnam; getprojid; getrctl; gettaskid; _getuserattr; _getusernam; + getustack; getvfsany; getvfsent; getvfsfile; getvfsspec; getvmusage; + getzoneid; getzoneidbyname; getzonenamebyid; + + # h + __hasmntopt_sun; # i idmap_reg; idmap_unreg; inet_ntoa_r; __init_daemon_priv; __init_suid_priv; diff --git a/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/mntent.c b/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/mntent.c deleted file mode 100644 index ed7e5c70c4..0000000000 --- a/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/mntent.c +++ /dev/null @@ -1 +0,0 @@ -/* OpenSolaris supports sys/mnttab.h instead of mntent.h. */ diff --git a/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/mntent.h b/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/mntent.h new file mode 100644 index 0000000000..bf9b756c0b --- /dev/null +++ b/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/mntent.h @@ -0,0 +1,100 @@ +/* Utilities for reading/writing fstab, mtab, etc. + Copyright (C) 1995, 1996, 1997, 1998, 1999 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 _SYS_MNTTAB_H +#ifndef _MNTENT_H +#define _MNTENT_H 1 + +#include +#define __need_FILE +#include +#include + + +/* File listing canonical interesting mount points. */ +#define MNTTAB _PATH_MNTTAB /* Deprecated alias. */ + +/* File listing currently active mount points. */ +#define MOUNTED _PATH_MOUNTED /* Deprecated alias. */ + + +/* General filesystem types. */ +#define MNTTYPE_IGNORE "ignore" /* Ignore this entry. */ +#define MNTTYPE_NFS "nfs" /* Network file system. */ +#define MNTTYPE_SWAP "swap" /* Swap device. */ + + +/* Generic mount options. */ +#define MNTOPT_DEFAULTS "defaults" /* Use all default options. */ +#define MNTOPT_RO "ro" /* Read only. */ +#define MNTOPT_RW "rw" /* Read/write. */ +#define MNTOPT_SUID "suid" /* Set uid allowed. */ +#define MNTOPT_NOSUID "nosuid" /* No set uid allowed. */ +#define MNTOPT_NOAUTO "noauto" /* Do not auto mount. */ + + +__BEGIN_DECLS + +/* Structure describing a mount table entry. */ +struct mntent + { + char *mnt_fsname; /* Device or server for filesystem. */ + char *mnt_dir; /* Directory mounted on. */ + char *mnt_type; /* Type of filesystem: ufs, nfs, etc. */ + char *mnt_opts; /* Comma-separated options for fs. */ + int mnt_freq; /* Dump frequency (in days). */ + int mnt_passno; /* Pass number for `fsck'. */ + }; + + +/* Prepare to begin reading and/or writing mount table entries from the + beginning of FILE. MODE is as for `fopen'. */ +extern FILE *setmntent (__const char *__file, __const char *__mode) __THROW; + +/* 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). */ +extern struct mntent *getmntent (FILE *__stream) __THROW; + +#ifdef __USE_MISC +/* Reentrant version of the above function. */ +extern struct mntent *getmntent_r (FILE *__restrict __stream, + struct mntent *__restrict __result, + char *__restrict __buffer, + int __bufsize) __THROW; +#endif + +/* Write the mount table entry described by MNT to STREAM. + Return zero on success, nonzero on failure. */ +extern int addmntent (FILE *__restrict __stream, + __const struct mntent *__restrict __mnt) __THROW; + +/* Close a stream opened with `setmntent'. */ +extern int endmntent (FILE *__stream) __THROW; + +/* Search MNT->mnt_opts for an option matching OPT. + Returns the address of the substring, or null if none found. */ +extern char *hasmntopt (__const struct mntent *__mnt, + __const char *__opt) __THROW; + + +__END_DECLS + +#endif /* mntent.h */ +#endif diff --git a/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/mntent_r.c b/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/mntent_r.c deleted file mode 100644 index ed7e5c70c4..0000000000 --- a/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/mntent_r.c +++ /dev/null @@ -1 +0,0 @@ -/* OpenSolaris supports sys/mnttab.h instead of mntent.h. */ diff --git a/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/mntent_sun.c b/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/mntent_sun.c new file mode 100644 index 0000000000..820b115286 --- /dev/null +++ b/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/mntent_sun.c @@ -0,0 +1,119 @@ +/* Copyright (C) 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by David Bartley , 2008. + + 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 + +/* Docs: http://docs.sun.com/app/docs/doc/816-5168/resetmnttab-3c */ + +#define _MNT_CMP(x, y, f) \ + (!y->f || (y->f && strcmp (x->f, y->f) == 0)) + + +int getmntent (FILE *fp, struct mnttab *mt) +{ + struct extmnttab emt; + int res = ioctl (fileno (fp), MNTIOC_GETMNTENT, &emt); + if (res != 0) + return -1; + + mt->mnt_special = emt.mnt_special; + mt->mnt_mountp = emt.mnt_mountp; + mt->mnt_fstype = emt.mnt_fstype; + mt->mnt_mntopts = emt.mnt_mntopts; + mt->mnt_time = emt.mnt_time; + + return 0; +} + +int getmntany (FILE *fp, struct mnttab *mt, struct mnttab *mtpref) +{ + int res; + while ((res = getmntent (fp, mt)) == 0) + { + if (_MNT_CMP (mt, mtpref, mnt_special) && + _MNT_CMP (mt, mtpref, mnt_mountp) && + _MNT_CMP (mt, mtpref, mnt_fstype) && + _MNT_CMP (mt, mtpref, mnt_mntopts) && + _MNT_CMP (mt, mtpref, mnt_time)) + return 0; + } + + return res; +} + + +int getextmntent(FILE *fp, struct extmnttab *emt, int len) +{ + int res = ioctl (fileno (fp), MNTIOC_GETMNTENT, emt); + if (res != 0) + return -1; + return 0; +} + + +char *mntopt (char **opts) +{ + char *optsp = *opts; + + /* Strip leading spaces. */ + while (*optsp == ' ') + optsp++; + + /* Find comma. */ + char *ret = optsp; + while (*optsp != ',' && *optsp != '\0') + optsp++; + + /* Replace comma with null terminator. */ + if (*optsp == ',') + optsp++; + *opts = optsp; + + return ret; +} + + +char * hasmntopt (struct mnttab *mt, char *opt) +{ + /* We make a copy of mnt_mntopts since we modify it. */ + char buf[MNT_LINE_MAX + 1]; + strncpy (buf, mt->mnt_mntopts, sizeof (buf))[MNT_LINE_MAX] = '\0'; + + char *opts = buf; + char *optp; + size_t len = strlen (opt); + while (*(optp = mntopt (&opts))) + { + /* Check if opt matched, taking into account delimiters (e.g. '='). */ + if (strncmp (optp, opt, len) == 0 && !isalnum (optp[len])) + return mt->mnt_mntopts + (optp - buf); + } + + return NULL; +} + + +void resetmnttab (FILE *fp) +{ + rewind (fp); +} diff --git a/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/mnttab.c b/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/mnttab.c index 2ce9727579..5f0a07b386 100644 --- a/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/mnttab.c +++ b/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/mnttab.c @@ -30,7 +30,7 @@ (!y->f || (y->f && strcmp (x->f, y->f) == 0)) -int getmntent (FILE *fp, struct mnttab *mt) +int __getmntent_sun (FILE *fp, struct mnttab *mt) { struct extmnttab emt; int res = ioctl (fileno (fp), MNTIOC_GETMNTENT, &emt); @@ -95,7 +95,7 @@ char *mntopt (char **opts) } -char * hasmntopt (struct mnttab *mt, char *opt) +char * __hasmntopt_sun (struct mnttab *mt, char *opt) { /* We make a copy of mnt_mntopts since we modify it. */ char buf[MNT_LINE_MAX + 1]; diff --git a/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/sys/mnttab.h b/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/sys/mnttab.h index c81ef3a69a..be5ae5930d 100644 --- a/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/sys/mnttab.h +++ b/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/sys/mnttab.h @@ -17,12 +17,11 @@ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ +#ifndef _MNTENT_H #ifndef _SYS_MNTTAB_H #define _SYS_MNTTAB_H #include -#include -#include #include #define MNTTAB _PATH_MOUNTED @@ -58,13 +57,26 @@ struct extmnttab __BEGIN_DECLS -extern void resetmnttab (FILE *); -extern int getmntent (FILE *, struct mnttab *); +extern void resetmnttab (FILE *); +# ifdef __REDIRECT_NTH +extern int __getmntent_sun (FILE *, struct mnttab *); +extern int __REDIRECT_NTH (getmntent, (FILE *, struct mnttab *), + __getmntent_sun); +# else +# define getmntent __getmntent_sun +# endif extern int getextmntent (FILE *, struct extmnttab *, size_t); extern int getmntany (FILE *, struct mnttab *, struct mnttab *); -extern char * hasmntopt (struct mnttab *, char *); -extern char * mntopt (char **); +# ifdef __REDIRECT_NTH +extern char * __hasmntopt_sun (struct mnttab *, char *); +extern char * __REDIRECT_NTH (hasmntopt, (struct mnttab *, char *), + __hasmntopt_sun); +# else +# define hasmntopt __hasmntopt_sun +# endif +extern char *mntopt (char **); __END_DECLS #endif /* _SYS_MNTTAB_H */ +#endif