It seems, that you can't use inotify to watch /proc/mounts for changes:
http://stackoverflow.com/questions/1113176/how-could-i-detect-when-a-directory-is-mounted-with-inotify
But I was also wrong, when I said you can use dio alone to detect
mounted partitions.
The only way, it could work with dio alone, is displaying only active
partitions, where io is above 0.

Zveroy's idea of parsing /proc/mounts is maybe the best option.
I attach an example, which can be run externally. You can glue this
together with dio.
I think some other guys would be interested in this solution too.
So you might share your code, If you get something interesting done.
#!/usr/bin/env lua
require("socket")
local function parse_mounts()
  local mounts = {}
  for l in io.lines("/proc/mounts") do
    local mount = string.match(l, "^/dev/(%w+)%s")
    if mount ~= nil then
            mounts[mount] = true
    end
  end
  return mounts
end

local function sleep(sec)
        return socket.select(nil, nil, sec)
end
local function dump_mounts(t)
        for k, v in pairs(parse_mounts()) do
                print(k, v)
        end
end

while(true) do
        dump_mounts(parse_mounts)
        sleep(1)
end

Reply via email to