summaryrefslogtreecommitdiff
path: root/lib/facter/mountpoints.rb
blob: da2f2a9d63b183b3bd8b7ef7e83f83267a873323 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
begin

  mountpoints = []
  # we show devices, but we avoid outputing duplicate devices
  devices = []
  Facter.add("mountpoints") do
    ignorefs = ["NFS", "nfs", "nfs4", "nfsd", "afs", "binfmt_misc", "proc", "smbfs", 
                "autofs", "iso9660", "ncpfs", "coda", "devpts", "ftpfs", "devfs", 
                "mfs", "shfs", "sysfs", "cifs", "lustre_lite", "tmpfs", "usbfs", "udf",
                "fusectl", "fuse.snapshotfs", "rpc_pipefs"]
    begin
      require 'filesystem'
    rescue Exception => e
      confine :kernel => :linux
      setcode do
        ENV["PATH"]="/bin:/sbin:/usr/bin:/usr/sbin"
        fs_source = nil
        if FileTest.exists?("/etc/mtab")
          fs_source = "/etc/mtab"
        elsif FileTest.exists?("/proc/mounts")
          fs_source = "/proc/mounts"
        end

        mounts = File.read(fs_source).split("\n")
        mounts.each do |mount|
          mount = mount.split(" ")
          if ((not ignorefs.include?(mount[2])) && (mount[3] !~ /bind/) && (not devices.include?(mount[0])) && (not mountpoints.include?(mount[1])))
	                mountpoints.push(mount[1])
          end
          devices.push(mount[0]) if not devices.include?(mount[0])
        end
      end
    else
      FileSystem.mounts.each do |m| 
        if ((not ignorefs.include?(m.fstype)) && (m.options !~ /bind/) && !devices.include?(mount[0]))
          mountpoints.push(m.mount)
        end
        devices.push(m.mount) if not devices.include?(m.mount)
      end
    end
    setcode do
      mountpoints.join(",")
    end
  end
  Facter.add("devices") do
    setcode do
      devices.join(",")
    end
  end

rescue Exception => e
end