⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 getfsent.c

📁 开源备份软件源码 AMANDA, the Advanced Maryland Automatic Network Disk Archiver, is a backup system that a
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * Amanda, The Advanced Maryland Automatic Network Disk Archiver * Copyright (c) 1991-1998, 2001 University of Maryland at College Park * All Rights Reserved. * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that * the above copyright notice appear in all copies and that both that * copyright notice and this permission notice appear in supporting * documentation, and that the name of U.M. not be used in advertising or * publicity pertaining to distribution of the software without specific, * written prior permission.  U.M. makes no representations about the * suitability of this software for any purpose.  It is provided "as is" * without express or implied warranty. * * U.M. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL U.M. * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * * Authors: the Amanda Development Team.  Its members are listed in a * file named AUTHORS, in the root directory of this distribution. *//* * $Id: getfsent.c,v 1.38 2006/07/19 17:41:14 martinea Exp $ * * generic version of code to read fstab */#include "amanda.h"#include "util.h"#ifdef TEST#  include <stdio.h>#  include <sys/types.h>#endif#include "getfsent.h"static char *dev2rdev(char *);/* * You are in a twisty maze of passages, all alike. * Geesh. */#if defined(HAVE_FSTAB_H) && !defined(HAVE_MNTENT_H) /* { *//*** BSD (GETFSENT_BSD)*/#define GETFSENT_TYPE "BSD (Ultrix, AIX)"#include <fstab.h>intopen_fstab(void){    return setfsent();}voidclose_fstab(void){    endfsent();}intget_fstab_nextentry(    generic_fsent_t *	fsent){    struct fstab *sys_fsent = getfsent();    static char *xfsname = NULL, *xmntdir = NULL;    static char *xfstype = NULL, *xmntopts = NULL;    if(!sys_fsent)	return 0;    fsent->fsname  = xfsname  = newstralloc(xfsname,  sys_fsent->fs_spec);    fsent->mntdir  = xmntdir  = newstralloc(xmntdir,  sys_fsent->fs_file);    fsent->freq    = sys_fsent->fs_freq;    fsent->passno  = sys_fsent->fs_passno;#ifdef STATFS_ULTRIX    fsent->fstype  = xfstype  = newstralloc(xfstype,  sys_fsent->fs_name);    fsent->mntopts = xmntopts = newstralloc(xmntopts, sys_fsent->fs_opts);#else#if defined(_AIX)    fsent->fstype  = xfstype  = newstralloc(xfstype,  _("unknown"));    fsent->mntopts = xmntopts = newstralloc(xmntopts, sys_fsent->fs_type);#else    fsent->fstype  = xfstype  = newstralloc(xfstype,  sys_fsent->fs_vfstype);    fsent->mntopts = xmntopts = newstralloc(xmntopts, sys_fsent->fs_mntops);#endif#endif    return 1;}#else#if defined(HAVE_SYS_VFSTAB_H) /* } { *//*** SVR4 (GETFSENT_SOLARIS)*/#define GETFSENT_TYPE "SVR4 (Solaris)"#include <sys/vfstab.h>static FILE *fstabf = NULL;intopen_fstab(void){    close_fstab();    return (fstabf = fopen(VFSTAB, "r")) != NULL;}voidclose_fstab(void){    if(fstabf)	afclose(fstabf);    fstabf = NULL;}intget_fstab_nextentry(    generic_fsent_t *	fsent){    struct vfstab sys_fsent;    memset(&sys_fsent, 0, SIZEOF(sys_fsent));    if(getvfsent(fstabf, &sys_fsent) != 0)	return 0;    fsent->fsname  = sys_fsent.vfs_special;    fsent->fstype  = sys_fsent.vfs_fstype;    fsent->mntdir  = sys_fsent.vfs_mountp;    fsent->mntopts = sys_fsent.vfs_mntopts;    fsent->freq    = 1;	/* N/A */    fsent->passno  = sys_fsent.vfs_fsckpass? atoi(sys_fsent.vfs_fsckpass) : 0;    return 1;}#else#  if defined(HAVE_MNTENT_H) /* } { *//*** System V.3 (GETFSENT_SVR3, GETFSENT_LINUX)*/#define GETFSENT_TYPE "SVR3 (NeXTstep, Irix, Linux, HP-UX)"#include <mntent.h>#if defined(HAVE_ENDMNTENT)#define AMCLOSE_MNTENT(x)	endmntent(x)#else#define AMCLOSE_MNTENT(x)	fclose(x)#endifstatic FILE *fstabf1 = NULL;		/* /proc/mounts */static FILE *fstabf2 = NULL;		/* MOUNTED */static FILE *fstabf3 = NULL;		/* MNTTAB */intopen_fstab(void){    close_fstab();#if defined(HAVE_SETMNTENT)    fstabf1 = setmntent("/proc/mounts", "r");# if defined(MOUNTED)    fstabf2 = setmntent(MOUNTED, "r");# endif# if defined(MNTTAB)    fstabf3 = setmntent(MNTTAB, "r");# endif#else# if defined(MNTTAB)    fstabf3 = fopen(MNTTAB, "r");# endif#endif    return (fstabf1 != NULL || fstabf2 != NULL || fstabf3 != NULL);}voidclose_fstab(void){    if (fstabf1) {	AMCLOSE_MNTENT(fstabf1);	fstabf1 = NULL;    }    if (fstabf2) {	AMCLOSE_MNTENT(fstabf2);	fstabf2 = NULL;    }    if (fstabf3) {	AMCLOSE_MNTENT(fstabf3);	fstabf3 = NULL;    }}intget_fstab_nextentry(    generic_fsent_t *	fsent){    struct mntent *sys_fsent = NULL;    if(fstabf1) {	sys_fsent = getmntent(fstabf1);	if(!sys_fsent) {	    AMCLOSE_MNTENT(fstabf1);	    fstabf1 = NULL;	}    }    if(!sys_fsent && fstabf2) {	sys_fsent = getmntent(fstabf2);	if(!sys_fsent) {	    AMCLOSE_MNTENT(fstabf2);	    fstabf2 = NULL;	}    }    if(!sys_fsent && fstabf3) {	sys_fsent = getmntent(fstabf3);	if(!sys_fsent) {	    AMCLOSE_MNTENT(fstabf3);	    fstabf3 = NULL;	}    }    if(!sys_fsent) {	return 0;    }    fsent->fsname  = sys_fsent->mnt_fsname;    fsent->fstype  = sys_fsent->mnt_type;    fsent->mntdir  = sys_fsent->mnt_dir;    fsent->mntopts = sys_fsent->mnt_opts;    fsent->freq    = sys_fsent->mnt_freq;    fsent->passno  = sys_fsent->mnt_passno;    return 1;}#  else#    if defined(HAVE_SYS_MNTTAB_H) || defined(STATFS_SCO_OS5) /* } { *//* we won't actually include mnttab.h, since it contains nothing useful.. */#define GETFSENT_TYPE "SVR3 (Interactive UNIX)"#include <stdio.h>#include <string.h>#include <ctype.h>#define FSTAB "/etc/fstab"static FILE *fstabf = NULL;intopen_fstab(void){    close_fstab();    return (fstabf = fopen(FSTAB, "r")) != NULL;}voidclose_fstab(void){    if(fstabf)	afclose(fstabf);    fstabf = NULL;}static generic_fsent_t _fsent;intget_fstab_nextentry(    generic_fsent_t *	fsent){    static char *lfsnam = NULL;    static char *opts = NULL;    static char *cp = NULL;    char *s;    int ch;    amfree(cp);    for (; (cp = agets(fstabf)) != NULL; free(cp)) {	if (cp[0] == '\0')	    continue;	fsent->fsname = strtok(cp, " \t");	if ( fsent->fsname && *fsent->fsname != '#' )	    break;    }    if (cp == NULL) return 0;    fsent->mntdir = strtok((char *)NULL, " \t");    fsent->mntopts = strtok((char *)NULL, " \t");    if ( *fsent->mntopts != '-' )  {	fsent->fstype = fsent->mntopts;	fsent->mntopts = "rw";    } else {	fsent->fstype = "";	if (strcmp(fsent->mntopts, "-r") == 0) {	    fsent->mntopts = "ro";	}    }    if ((s = strchr(fsent->fstype, ',')) != NULL) {	*s++ = '\0';	strappend(fsent->mntopts, ",");	strappend(fsent->mntopts, s);    }    lfsnam = newstralloc(lfsnam, fsent->fstype);    s = lfsnam;    while((ch = *s++) != '\0') {	if(isupper(ch)) ch = tolower(ch);	s[-1] = ch;    }    fsent->fstype = lfsnam;    if (strncmp_const(fsent->fstype, "hs") == 0)	fsent->fstype = "iso9660";    fsent->freq = 0;    fsent->passno = 0;    return 1;}#    else#      if defined(HAVE_MNTTAB_H) /* } { */#define GETFSENT_TYPE "SVR3 (SCO UNIX)"#include <mnttab.h>#include <sys/fstyp.h>#include <sys/statfs.h>#define MNTTAB "/etc/mnttab"/* * If these are defined somewhere please let me know. */#define MNT_READONLY 0101#define MNT_READWRITE 0100static FILE *fstabf = NULL;intopen_fstab(void){    close_fstab();    return (fstabf = fopen(MNTTAB, "r")) != NULL;}voidclose_fstab(void){    if(fstabf)	afclose(fstabf);    fstabf = NULL;}static generic_fsent_t _fsent;intget_fstab_nextentry(    generic_fsent_t *fsent){    struct statfs fsd;    char typebuf[FSTYPSZ];    static struct mnttab mnt;    char *dp, *ep;    if(!fread (&mnt, SIZEOF(mnt), 1, fstabf))      return 0;    fsent->fsname  = mnt.mt_dev;    fsent->mntdir  = mnt.mt_filsys;    fsent->fstype = "";    if (statfs (fsent->mntdir, &fsd, SIZEOF(fsd), 0) != -1

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -