#!/bin/sh
#
#     tiger - A UN*X security checking system
#     Copyright (C) 1993 Douglas Lee Schales, David K. Hess, David R. Safford
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2, or (at your option)
#    any later version.
#
#    This program 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 General Public License for more details.
#
#     Please see the file `COPYING' for the complete copyright notice.
#
# Linux/1/gen_mounts - 04/20/99
# Linux/2/gen_mounts - 04/20/99
# Updated by Advanced Research Corporation (R)
# Linux/2/gen_mounts - 11/19/2003 - Added ext3 and reiserfs as valid 
#     local filesystems (patch from Ryan Bradetich), also added xfs and jfs.
# Linux/2/gen_mounts - 03/21/2005 - Warn if the filesystem is not recognised
#     this is a fix for Tiger bug #7093 
# Linux/2/gen_mounts - 04/14/2005 - Add more filesystems and recognise the 
#     fact that users can define fallback filesystems (Debian Bug #304555 and
#     #302646)
# Linux/2/gen_mounts - 04/18/2005 - Fix to previous patch which introduced typos
# Linux/2/gen_mounts - 05/14/2005 - Added auto (Debian bug #305670), udev when
#     using on /dev (Debian bug #307802), capifs (Debian bug #307887), nfsd
#     (Debian bug #308585)
# Linux/2/gen_mounts - 07/22/2005 - Changed extraction from mount command
#     so it can cope with whitespaces in mount locations, added sanity check
#     and fix a bug that mangled $fs (Debian bug #315435)
# Linux/2/gen_mounts - 08/29/2005 - Added vzfs (VPS filesystem) to local fs,
#     Savannah bug #14299
# Linux/2/gen_mounts - 05/20/2006 - Added cifs to non local FS (Debian bug #329813)
# Linux/2/gen_mounts - 11/16/2006 - Added selinuxfs to local FS (Debian bug #397832)
# Linux/2/gen_mounts - 06/22/2007 - Added fusectl to local FS (Debian bug #409386)
# Linux/2/gen_mounts - 06/26/2007 - Added Vmware's vmblock as non-local FS
# Linux/2/gen_mounts - 09/08/2008 - Added reiser4 as a local FS (Debian bug #498203)
#                                 - Added securityfs as a non-local FS (Ubuntu bug #155211)
#                                 - Added fuse.gvfs-fuse-daemon as a local FS (Ubuntu bug #155211)
#                                 - Added fuseblk as a local FS
#                                 - Added fuse.truecrypt as a local FS
#                                 - Added fuse.encfs as a local FS (Debian bug #483727)
#                                 - Added debugfs as a non-local FS, to skip it from checks (Debian bug #469685)
#                                 - Added afs as a non-local FS (Savannah bug #14028)
#                                 - Added configfs, gfs and gfs2 as a non-local FS (Debian bug #490344)
#                                 - Added inotifyfs, hugetlb and subfs as a non-local FS
#                                 - Make futexfs a non-local FS (Debian bug #490822)
#                                 - Added bind as a non-local FS (Debian bug #451879)
#                                 - Skip udev fs even if its in a tmpfs FS, prevent analysis
#                                   of unexistant symlinks (See Debian bug 434333)
# Linux/2/gen_mounts - 11/27/2008 - Added ecryptfs, used by ecryptfs-utils (See Debian bug 506512)
#                                 - Fix bashism (Debian bug #505939)
# Linux/2/gen_mounts - 05/25/2009 - Added davfs, fuse and ext4 (Debian bug 524722, 498468, 512567)
# Linux/2/gen_mounts - 07/01/2010 - Added fuse.ltspfs (Debian bug 587507)
# Linux/2/gen_mounts - 10/06/2010 - Added btrfs (Debian bug 598792)
# Linux/2/gen_mounts - 14/01/2011 - Added xenfs (Savannah bug 32126) 
#                                   (Debian bug 615052)
# Linux/2/gen_mounts - 28/01/2011 - Added devtmpfs (Debian bug 653416)
#                                   Added sshfs and cgroup (Debian bug 655276)
# Linux/2/gen_mounts - 23/01/2014 - Added pstore  (Debian bug 733832)
#                                 - Fix typo: hugetlbf --> hugetlbfs 
#                                    (Debian bug 729692, Savannah bug 40591)
#                                 - Add fuse.gvfs-fuse-daemon (Savannah patch 7914) and change it to non-LOCAL
# Linux/2/gen_mounts - 14/10/2014 - Fix typo: hugelbfs --> hugetlbfs  (Debian bug 740625)
# Linux/2/gen_mounts - 22/11/2015 - Fix typo in sshfs definition (Debian bug 7680867)
#                                 - Added aufs (Debian bug 781171)
#                                 - Added fuse.s3fs (Debian bug 799753)
# Linux/2/gen_mounts - 05/12/2015 - Added tracefs (Debian bug 791352)
# Linux/2/gen_mounts - 10/06/2016 - Added fuse.lxcfs (Debian bug 829643)
# Linux/2/gen_mounts - 18/12/2016 - Added efivarfs (Debian bug 848377) and cgroup2 (Debian bug 843452)
# Linux/2/gen_mounts - 22/09/2017 - vmblock has been renamed to fuse.vmware-vmblock. (Savannah bug 52087)
# Linux/2/gen_mounts - 06/02/2018 - Added filesystems after reviewing the ones supported in Linux kernel
#                                   documentation including: 9p, befs, bfs, ceph, ocfs2_dlmfs, exofs, f2fs, 
#                                   nilfs2, ocfs2, pvfs2, ubifs, hfsplus, qnx6, pohmel, squashfs, efivars, omfs
#                                   Added links to kernel documentation text files, for further reference.
#                                   Added code to check the filesystems valid in the current kernel, this
#                                   should prevent future false positivies when new filesystems are added to the kernel
# Linux/2/gen_mounts - 07/02/2018 - Added fuse.clamfs (Ubuntu bug 1204527) and fuse.javafs (Ubuntu bug 1305057) 
#                                   filesystems
#------------------------------------------------------------------------------------------------------------------
#

dirname()
{
  _path="$1"

  saveifs=$IFS
  IFS=/
  set X $_path
  IFS=$saveifs

  shift

  if [ $# -eq 1 ]; then
    _dirname='/'
  else
    _dirname=
    while [ $# -ne 1 ]
    do
      _dirname="$_dirname/$1"
      shift
    done
  fi
  
  echo "$_dirname"
}
  
LOCAL_ONLY=$1
CHKRO=$2

ronly()
{
  RO=1
  case "$1" in
    *[!a-zA-Z]ro[!a-zA-Z]*) RO=0
      ;;
  esac
  return $RO
}

localfs()
{
# Determine which filesystem is local, for filesystems valid for Linux
# read the mount(5), fstab(5) or Documentation/filesystems in the Linux
# kernel or check the values in /proc/filesystems
  LOCAL=2
  # Valid local filesystems
  [ "$1" = "ext" ] && LOCAL=0         # First extended filesystem
  [ "$1" = "ext2" ] && LOCAL=0        # Second extended filesystem, see https://www.kernel.org/doc/Documentation/filesystems/ext2.txt
  [ "$1" = "ext3" ] && LOCAL=0        # Third extended filesystem, see https://www.kernel.org/doc/Documentation/filesystems/ext3.txt
  [ "$1" = "ext4" ] && LOCAL=0        # Fourth extended filesystem https://www.kernel.org/doc/Documentation/filesystems/ext4.txt
  [ "$1" = "auto" ] && LOCAL=0
  [ "$1" = "vzfs" ] && LOCAL=0        # VPS virtual partition
  [ "$1" = "simfs" ] && LOCAL=0       # OpenVZ virtual partition
  [ "$1" = "reiserfs" ] && LOCAL=0
  [ "$1" = "reiser4" ] && LOCAL=0
  [ "$1" = "xfs" ] && LOCAL=0                   # Silicon Grafics filesystem, see
                                                # https://www.kernel.org/doc/Documentation/filesystems/xfs.txt
  [ "$1" = "jfs" ] && LOCAL=0                   # IBM's Journalling Filesystem, see
                                                # https://www.kernel.org/doc/Documentation/filesystems/jfs.txt
  [ "$1" = "minix" ] && LOCAL=0
  [ "$1" = "xiafs" ] && LOCAL=0
  [ "$1" = "sysv" ] && LOCAL=0                  # Implementation of Xenix, System V and Coherent FS, see
                                                # https://www.kernel.org/doc/Documentation/filesystems/sysv-fs.txt
  [ "$1" = "ufs" ] && LOCAL=0                   # Filesystem used in FreeBSD, NetBSD, OpenBSD, Nexstep, OpenStep and Solaris, see
                                                # https://www.kernel.org/doc/Documentation/filesystems/ufs.txt
  [ "$1" = "aufs" ] && LOCAL=0                    # Aufs (Docker) - advanced multi layered unification filesystem version
  [ "$1" = "coherent" ] && LOCAL=0
  [ "$1" = "hpfs" ] && LOCAL=0                  # Read/write hpfs, see
                                                # https://www.kernel.org/doc/Documentation/filesystems/hpfs.txt
  [ "$1" = "btrfs" ] && LOCAL=0                 # Copy on write filesystem, see
                                                # https://www.kernel.org/doc/Documentation/filesystems/btrfs.txt
  [ "$1" = "rootfs" ] && LOCAL=0                # Provides an empty root directory for the bootstrap phase
  [ "$1" = "exofs" ] && LOCAL=0                 # Exofs, see:
                                                # https://www.kernel.org/doc/Documentation/filesystems/exofs.txt
  [ "$1" = "f2fs" ] && LOCAL=0                  # Flash friendly file system, see:
                                                # https://www.kernel.org/doc/Documentation/filesystems/f2fs.txt
  [ "$1" = "nilfs2" ] && LOCAL=0                # log-structured file system, see
                                                # https://www.kernel.org/doc/Documentation/filesystems/nilfs2.txt
  [ "$1" = "ocfs2" ] && LOCAL=0                 # Virtual filesystem for Oracle Virtual Machine Clusters, see
                                                # https://www.kernel.org/doc/Documentation/filesystems/ocfs2.txt
  [ "$1" = "pvfs2" ] && LOCAL=0                 # Parallel storage filesystem, see
                                                # https://www.kernel.org/doc/Documentation/filesystems/orangefs.txt

  # Special filesystems which are also valid locally
  [ "$1" = "shm" ] && LOCAL=0                   # IPC-shared memory regions
  [ "$1" = "tmpfs" ] && LOCAL=0                 # Temporary files (kept in RAM unless swapped), see
                                                # https://www.kernel.org/doc/Documentation/filesystems/tmpfs.txt
  # Exception: udev uses a tmpfs and it has many symlinks that point nowhere, it should be skipped
  [ "$1" = "tmpfs" ] && [ "$2" = "udev" ] && LOCAL=1 
  [ "$1" = "auto" ] && LOCAL=0
  [ "$1" = "selinuxfs" ] && LOCAL=0
  [ "$1" = "fusectl" ] && LOCAL=0               # Userspce filesystem, see:
                                                # https://www.kernel.org/doc/Documentation/filesystems/fuse.txt
  [ "$1" = "fuseblk" ] && LOCAL=0               # Used in Ubuntu 'hardy'
  [ "$1" = "fuse.truecrypt" ] && LOCAL=0        # Encrypted filesystem, used in Ubuntu 'hardy'
  [ "$1" = "fuse.encfs" ] && LOCAL=0            # Encrypted filesystem
  [ "$1" = "fuse.gvfs-fuse-daemon" ] && LOCAL=1 # Used in Ubuntu 'hardy'
  [ "$1" = "fuse.gvfsd-fuse" ] && LOCAL=1       # Used in Ubuntu 13.10 (Saucy Salamander) replaces fuse.gvfs-fuse-daemon
  [ "$1" = "fuse.ltspfs" ] && LOCAL=0 		# Used by LTSP 5.x
  [ "$1" = "fuse.lxcfs" ] && LOCAL=0
  [ "$1" = "fuse.clamfs" ] && LOCAL=0           # ClamFS anti-virus protected file system
  [ "$1" = "fuse.javafs" ] && LOCAL=0           # Java FS, used by Wuala secure online storage, see:
                                                # https://github.com/puniverse/javafs
  [ "$1" = "ecryptfs" ] && LOCAL=0              # Encrypted filesystem used by ecryptfs-utils, see
                                                # https://www.kernel.org/doc/Documentation/filesystems/ecryptfs.txt
  [ "$1" = "xenfs" ] && LOCAL=0                 # Virtual fs for Xen
  [ "$1" = "cgroup" ] && LOCAL=0                # General access point to Kernel Control Groups
  [ "$1" = "cgroup2" ] && LOCAL=0               # General access point to Kernel Control Groups - see
                                                # https://www.kernel.org/doc/Documentation/cgroup-v2.txt
  [ "$1" = "fuse.s3fs" ] && LOCAL=1 		# Amazon S3 buckets mounted through fuse

  [ "$1" = "ubifs" ] && LOCAL=1 		# Flash filesystem for MTP devices, see
                                                # https://www.kernel.org/doc/Documentation/filesystems/ubifs.txt


  # Filesystems of other OS
  [ "$1" = "xenix" ] && LOCAL=0
  [ "$1" = "msdos" ] && LOCAL=1
  [ "$1" = "umsdos" ] && LOCAL=1
  [ "$1" = "vfat" ] && LOCAL=1                  # Windows filesystem, see
                                                # https://www.kernel.org/doc/Documentation/filesystems/vfat.txt
  [ "$1" = "ntfs" ] && LOCAL=1                  # Windows NT filesystem, see
                                                # https://www.kernel.org/doc/Documentation/filesystems/ntfs.txt
  [ "$1" = "hfs" ] && LOCAL=1                   # Macintosh Hierarchical File System, see
                                                # https://www.kernel.org/doc/Documentation/filesystems/hfs.txt
  [ "$1" = "hfsplus" ] && LOCAL=1               # Macintosh Hierarchical File System used in MacOS 8.1 see
                                                # https://www.kernel.org/doc/Documentation/filesystems/hfsplus.txt
  [ "$1" = "qnx4" ] && LOCAL=1
  [ "$1" = "qnx6" ] && LOCAL=1                  # Filesystem for QNX 6.4.1 and later versions, see
                                                # https://www.kernel.org/doc/Documentation/filesystems/qnx6.txt
  [ "$1" = "udf" ] && LOCAL=1                   # See https://www.kernel.org/doc/Documentation/filesystems/udf.txt
  [ "$1" = "befs" ] && LOCAL=1                  # Filesystem for BeOS, see
                                                # https://www.kernel.org/doc/Documentation/filesystems/befs.txt
  [ "$1" = "bfs" ] && LOCAL=1                   # Filesystem for SCO Uniware, see
                                                # https://www.kernel.org/doc/Documentation/filesystems/bfs.txt
  [ "$1" = "9p" ] && LOCAL=1                    # Plan 9 filesystem see 
                                                # https://www.kernel.org/doc/Documentation/filesystems/9p.txt
  # Remotely mounted fs
  [ "$1" = "nfs" ] && LOCAL=1                   # Network Filesystem, see
                                                # https://www.kernel.org/doc/Documentation/filesystems/nfs/
  [ "$1" = "nfs4" ] && LOCAL=1
  [ "$1" = "nfsd" ] && LOCAL=1
  [ "$1" = "ncpfs" ] && LOCAL=1                 # Netware Control Procolo, see
                                                # https://www.kernel.org/doc/Documentation/filesystems/ncpfs.txt
  [ "$1" = "fuse.sshfs" ] && LOCAL=1            # Remote SSH mounted filesystem through fuse
  [ "$1" = "smbfs" ] && LOCAL=1                 # Samba File system
  [ "$1" = "cifs" ] && LOCAL=1                  # SMB3 and Common Internet File System (CIFS), see
                                                # https://www.kernel.org/doc/Documentation/filesystems/cifs/cifs.txt
  [ "$1" = "coda" ] && LOCAL=1      # Coda filesystem, see https://www.kernel.org/doc/Documentation/filesystems/coda.txt
  [ "$1" = "AFS" ] && LOCAL=1       # Andrew Filesystem
  [ "$1" = "afs" ] && LOCAL=1       # Andrew Filesystem
  [ "$1" = "rpc_pipefs" ] && LOCAL=1
  [ "$1" = "gfs" ] && LOCAL=1       # Red Hat's Global Filesystem
                                    # http://sources.redhat.com/cluster/wiki/
  [ "$1" = "gfs2" ] && LOCAL=1      # Red Hat's Global Filesystem, see:
                                    # https://www.kernel.org/doc/Documentation/filesystems/gfs2.txt
  # Note: gfs is considered non-local even though remoutely mounted in a SAN as this filesystem could
  # be used exclusively, if your system uses gfs or gfs2 and you want to scan the filesystem
  # set it at Tiger_FSScan_Local

  [ "$1" = "ceph" ] && LOCAL=1      # Distributed network filesystem, see
                                    # https://www.kernel.org/doc/Documentation/filesystems/ceph.txt
  [ "$1" = "pohmel" ] && LOCAL=1    # Pohmel filesystem, see
                                    # https://www.kernel.org/doc/Documentation/filesystems/pohmelfs/info.txt


  # Special filesystems
  [ "$1" = "proc" ] && LOCAL=1                  # General access point to kernel data structures, see
                                                # https://www.kernel.org/doc/Documentation/filesystems/proc.txt
  [ "$1" = "bind" ] && LOCAL=1                  # Used to remount directories, define as virtual
                                                # as otherwise files would be checked twice
  [ "$1" = "devpts" ] && LOCAL=1                # Pseudoterminal support (Open Group's Unix98 standard), see
                                                # https://www.kernel.org/doc/Documentation/filesystems/devpts.txt
  [ "$1" = "usbfs" ] && LOCAL=1                 # USB devices
  [ "$1" = "usbdevfs" ] && LOCAL=1
  [ "$1" = "devfs" ] && LOCAL=1
  [ "$1" = "devtmpfs" ] && LOCAL=1
  [ "$1" = "sysfs" ] && LOCAL=1                 # General access point to system data, see
                                                # https://www.kernel.org/doc/Documentation/filesystems/sysfs.txt
  [ "$1" = "securityfs" ] && LOCAL=1            # Used by Ubuntu, see http://lwn.net/Articles/153366/ 
  [ "$1" = "none" ] && LOCAL=1
  [ "$1" = "autofs" ] && LOCAL=1                # Filesystem for on-demand mounting, see
                                                # https://www.kernel.org/doc/Documentation/filesystems/autofs4.txt
  [ "$1" = "binfmt_misc" ] && LOCAL=1           # Miscellaneous executable formats
  [ "$1" = "cramfs" ] && LOCAL=1                # Simple filesystem for ROM, see
                                                # https://www.kernel.org/doc/Documentation/filesystems/cramfs.txt
  [ "$1" = "ramfs" ] && LOCAL=1                 # Simple RAM filesystem, see
                                                # https://www.kernel.org/doc/Documentation/filesystems/ramfs-rootfs-initramfs.txt
  [ "$1" = "squashfs" ] && LOCAL=1              # Compressed read only filesystem
                                                # https://www.kernel.org/doc/Documentation/filesystems/squashfs.txt
  [ "$1" = "romfs" ] && LOCAL=1                 # Simple read only filesystem, see
                                                # https://www.kernel.org/doc/Documentation/filesystems/romfs.txt
  [ "$1" = "mqueue" ] && LOCAL=1                # POSIX message queues
  [ "$1" = "sockfs" ] && LOCAL=1                # Sockets
  [ "$1" = "bdev" ] && LOCAL=1                  # Block devices
  [ "$1" = "pipefs" ] && LOCAL=1
  [ "$1" = "eventpollfs" ] && LOCAL=1           # Efficient event polling mechanism
  [ "$1" = "inotifyfs" ] && LOCAL=1 
  [ "$1" = "hugetlbfs" ] && LOCAL=1 
  [ "$1" = "subfs" ] && LOCAL=1 
  [ "$1" = "futexfs" ] && LOCAL=1               # futex (Fast Userspace Locking) mechanism
  [ "$1" = "fuse" ] && LOCAL=1
  [ "$1" = "fuse.vmware-vmblock" ] && LOCAL=1   # Vmware filesystem
  [ "$1" = "vmblock" ] && LOCAL=1               # Vmware filesystem
  [ "$1" = "debugfs" ] && LOCAL=1               # Debugging filesystem see 
                                                # http://lwn.net/Articles/115405/
                                                # https://www.kernel.org/doc/Documentation/filesystems/debugfs.txt
  [ "$1" = "tracefs" ] && LOCAL=1               # Debugging filesystem see
                                                # https://lwn.net/Articles/630526/ and https://www.usenix.org/legacy/publications/library/proceedings/fast04/tech/full_papers/aranya/aranya_html/index.html
  [ "$1" = "efivarfs" ] && LOCAL=1              # Linux  EFI variables filesystem see 
                                                # https://www.kernel.org/doc/Documentation/filesystems/efivarfs.txt
  [ "$1" = "configfs" ] && LOCAL=1
  [ "$1" = "davfs" ] && LOCAL=1
  [ "$1" = "pstore" ] && LOCAL=1                # Platform dependen persistent storage
  [ "$1" = "ocfs2_dlmfs" ] && LOCAL=1           # Virtual filesystem for Oracle Virtual Machine Clusters, see
                                                # https://www.kernel.org/doc/Documentation/filesystems/dlmfs.txt
                                                # https://blogs.oracle.com/wim/dlmfs
  [ "$1" = "spufs" ] && LOCAL=1                 # Filesystem to access Synergistic  Processor Units (SPUs) in PowerPC, see
                                                # https://www.kernel.org/doc/Documentation/filesystems/spufs.txt

  # Other filesystems we don't support
  [ "$1" = "adfs" ] && LOCAL=1                  # ADFS filesystem, see
                                                # https://www.kernel.org/doc/Documentation/filesystems/adfs.txt
  [ "$1" = "affs" ] && LOCAL=1                  # AFFS filesystem, see
                                                # https://www.kernel.org/doc/Documentation/filesystems/affs.txt
  [ "$1" = "afs" ] && LOCAL=1                   # AFS filesystem, see
                                                # https://www.kernel.org/doc/Documentation/filesystems/afs.txt
  [ "$1" = "efs" ] && LOCAL=1
  [ "$1" = "iso9660" ] && LOCAL=1               # ISO Filesystem, see 
                                                # https://www.kernel.org/doc/Documentation/filesystems/isofs.txt
  [ "$1" = "omfs" ] && LOCAL=1                  # SonicBlue filesytem for MP3 devices, see
                                                # https://www.kernel.org/doc/Documentation/filesystems/omfs.txt
  [ "$1" = "capifs" ] && LOCAL=1
  # Some special filesystems
  [ "$1" = "unknown" ] && [ "$2" = "/dev" ] && LOCAL=1

  # Handle the Tiger_FSScan_Local and Tiger_FSScan_Nonlocal variables, if defined
  if [ ! -z "$Tiger_FSScan_Local" ] ; then
    # List of known filesystems the admin considers to be local to the system
    if echo $1 | $EGREP -q $Tiger_FSScan_Local; then
        LOCAL=0
    fi
  fi
  if [ ! -z "$Tiger_FSScan_NonLocal" ] ; then
    # List of known filesystems the admin considers to be not local to the system
    if echo $1 | $EGREP -q $Tiger_FSScan_NonLocal; then
        LOCAL=1
    fi
  fi

  # Check filesystems that are known to the current kernel
  # First check /proc/filesystems which should list the filesystems known to the current kernel
  if [ "$LOCAL" -eq 2 ] && [ -r /proc/filesystems ] ; then
    if  cat /proc/filesystems  | awk '{if ($2 == "") print $1; else print $2}' | grep -q "$1" ; then
        LOCAL=0
    fi
  fi

  # If this still fails then check the directories in /lib/modules/<current_running_kernel>/
  if [ "$LOCAL" -eq 2 ] ; then
    KERNEL=`uname -r`
    if [ -e "/lib/modules/$KERNEL/kernel/fs/$1" ]; then
        LOCAL=0
    fi
  fi

  # The rest we warn about
  if [ "$LOCAL" -eq 2 ] ; then
    if [ -z "$Tiger_FSScan_WarnUnknown" ] || [ "$Tiger_FSScan_WarnUnknown" = "Y" ] ; then
        echo "--CONFIG-- [con010c] Filesystem '$1' used by '$2' is not recognised as a valid filesystem" >&2
    fi
    LOCAL=1
  fi
  return $LOCAL
}

# If run directly do this, just in case:
[ -z "$GETFS" ] && GETFS=`which mount`
[ -z "$SED" ] && SED=`which sed`
[ -z "$BASENAME" ] && BASENAME=`which basename`
[ -z "$EGREP" ] && EGREP=`which egrep`

$GETFS  |
while read line
do
# $fs on $mtpoint type $fstype ($opts)
  PRINT=1
  fs=`echo $line | sed -e 's/ on.*$//'`
  mtpoint=`echo $line | sed -e 's/^.* on //' | sed -e 's/ type.*$//'`
  # Indent spaces in case we found any in the mount point
  mtpoint=`echo $mtpoint | sed -e 's/\([[:space:]]\)/\\\\\1/g'`
  fstype=`echo $line | sed -e 's/.* type \(.*\) (.*/\1/'`
  # Strip fallback filesystems
  fstype=`echo $fstype | $SED -e 's/,.*$//'`
  opts=`echo $line | sed -e 's/.* (\(.*\))$/\1/'`
  # Sanity check, do not proceed if the values are empty or if
  # we have not been able to parse the information properly
  [ -z "$fs" ] || [ -z "$mtpoint" ] || [ -z "$fstype" ] || [ -z "$opts" ] || \
  [ "$fs" = "$line" ] || [ "$mtpoint" = "$line" ] || \
  [ "$fstype" = "$line" ] || [ "$opts" = "$line" ] && \
  continue
  # TODO: warn in continuing?
  [ "$CHKRO" = "rw" ] && { ronly "$opts" && PRINT=0; }
  [ "$LOCAL_ONLY" = "local" ] && { localfs "$fstype" "$fs" || PRINT=0; }
  [ "$PRINT" = "1" ] && {
    dir=`dirname $fs`
    file=`$BASENAME $fs`
    rfs="$dir/r$file"
    echo "$mtpoint $fstype $fs"
  }
done

