home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 15 / 15.iso / s / s053 / 5.ddi / sbin / fstyp < prev    next >
Encoding:
Text File  |  1990-12-08  |  1.6 KB  |  105 lines

  1. #!/sbin/sh
  2. #    Copyright (c) 1990 UNIX System Laboratories, Inc.
  3. #    Copyright (c) 1984, 1986, 1987, 1988, 1989, 1990 AT&T
  4. #      All Rights Reserved
  5.  
  6. #    THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF
  7. #    UNIX System Laboratories, Inc.
  8. #    The copyright notice above does not evidence any
  9. #    actual or intended publication of such source code.
  10.  
  11.  
  12. #ident    "@(#)/sbin/fstyp.sl 1.1 4.0 12/08/90 29913 AT&T-USL"
  13. #
  14. #    Determine the fs identifier of a file system.
  15. #
  16. #!    chmod +x ${file}
  17. USAGE="Usage: fstyp [-v] special"
  18. NARGS=`echo $#`
  19.  
  20. if [ $NARGS -eq 0 ]
  21. then
  22.     echo "$USAGE" >&2
  23.     exit 2
  24. fi
  25. while getopts v? c
  26. do
  27.     case $c in
  28.      v) VFLAG="-"$c;;
  29.     \?) echo "$USAGE" >&2
  30.         exit 2;;
  31.     esac
  32. done
  33. shift `expr $OPTIND - 1`
  34.  
  35. if [ "$VFLAG" ]
  36. then
  37.     if [ $NARGS -gt 2 ]
  38.     then
  39.         echo "$USAGE" >&2
  40.         exit 2
  41.     fi
  42. else
  43.     if [ $NARGS -gt 1 ]
  44.     then
  45.         echo "$USAGE" >&2
  46.         exit 2
  47.     fi
  48. fi
  49.     
  50.  
  51.  
  52. SPEC=$1
  53. if [ "$SPEC" = "" ]
  54. then
  55.     echo "$USAGE" >&2
  56.     exit 2
  57. fi
  58. if [ ! -r $SPEC ]
  59. then
  60.     echo "fstyp: cannot stat or open <$SPEC>" >&2
  61.     exit 1
  62. fi
  63.  
  64. if [ \( ! -b $SPEC \) -a \( ! -c $SPEC \) ]
  65. then
  66.     echo "fstyp: <$SPEC> not block or character special device" >&2
  67.     exit 1
  68. fi
  69.  
  70. #
  71. #    Execute all heuristic functions /etc/fs/*/fstype 
  72. #    or /usr/lib/fs/*/fstyp and
  73. #    return the fs identifier of the specified file system.
  74. #
  75.  
  76. CNT=0 
  77.  
  78. if [ -d /usr/lib/fs ]
  79. then
  80.     DIR=/usr/lib/fs
  81. else
  82.     DIR=/etc
  83. fi
  84.  
  85. for f in $DIR/*/fstyp
  86. do
  87.     $f $VFLAG $SPEC >&1
  88.     if [ $? -eq 0 ]
  89.     then
  90.         CNT=`expr ${CNT} + 1`
  91.     fi
  92. done
  93.  
  94. if [ ${CNT} -gt 1 ]
  95. then
  96.     echo "Unknown_fstyp (multiple matches)" >&2
  97.     exit 2
  98. elif    [ ${CNT} -eq 0 ]
  99. then
  100.     echo "Unknown_fstyp (no matches)" >&2
  101.     exit 1
  102. else
  103.     exit 0
  104. fi
  105.