-- filesystem.lua
-- $Id: filesystem.lua,v 1.9 2005/01/22 03:37:33 cpressey Exp $
-- Test of dfuibe_lua's filesystem functionalities.

local booltab = { [false] = "NO", [true] = "YES" }

files = FileSystem.dir("/etc")
for file in files do
	local fullfile = "/etc/" .. files[file]
	local string = fullfile .. "..." ..
	    "  is file? " .. booltab[FileSystem.is_file(fullfile)] ..
	    "  is dir? " .. booltab[FileSystem.is_dir(fullfile)] ..
	    "  is program? " .. booltab[FileSystem.is_program(fullfile)] ..
	    "  size=" .. tostring(FileSystem.size_of(fullfile))
	print(string)
end

path = "/x/y/z"
print("basename of " .. path .. " is " .. FileSystem.basename(path))
print("dirname of  " .. path .. " is " .. FileSystem.dirname(path))

local fh, fname = FileSystem.mkstemp("/tmp/tmp.XXXXXX")
fh:write("hello!\n")
fh:close()
print("Wrote hello! to " .. fname)

local fs_descs = FileSystem.enumerate()
local i, fs_desc
for i, fs_desc in fs_descs do
	print(
	    "mountpoint=", fs_desc.mountpoint,
	    "device=", fs_desc.device,
	    "type=", fs_desc.type,
	    "block_size=", fs_desc.block_size,
	    "blocks_total=", fs_desc.blocks_total,
	    "blocks_free=", fs_desc.blocks_free,
	    "blocks_avail=", fs_desc.blocks_avail
	)
end
