dgelessus 26 Posted February 4, 2015 Share Posted February 4, 2015 (edited) This is a short boot/rc script that automatically mounts all new file systems under a mount point named after their label, in addition to the normal name assigned by the OS. Special characters in the label are replaced by an underscore and a conflicting name gets the start of its address appended, so the obvious tricky situations should not cause any problems. I wouldn't be surprised if someone else had already written this kind of thing or if it was integrated in some of the non-default operating systems, but I couldn't find anything on the forums or OpenPrograms, so here it is. (Yes, half of this is copied from OpenOS's automatic mounting code.) -- NamedMount, a short boot script that gives labelled file systems named mount -- points in /mnt. For example a floppy disk labelled "floppy" would get mounted -- at /mnt/floppy in addition to the normal mount point assigned by the OS. -- -- All non-alphanumeric characters except the underscore are replaced with -- an underscore to ensure that the name is usable in a shell. -- If a conflicting mount point already exists, the start of the address is -- appended to the label to prevent overwriting other mount points. -------------------------------------------------------------------------------- local component = require("component") local event = require("event") local fs = require("filesystem") local function doNamedMount(name, address, componentType) if componentType == "filesystem" then local proxy = component.proxy(address) if proxy and proxy:getLabel() then local path = fs.concat("/mnt", (proxy:getLabel():gsub("[^%w_]+", "_"))) if fs.exists(path) then -- Mount point exists already, start appending address local addrlen = 3 local path = path .. "-" .. address:sub(1, addrlen) while fs.exists(path) and addrlen < address:len() -- just to be on the safe side do path = path .. address:sub(addrlen, addrlen) end end fs.mount(proxy, path) end end end function start(...) event.listen("component_added", doNamedMount) end -- Uncomment when placing this in /boot instead of using rc -- start() Edit: Added start function for use as a rc script. Edited February 5, 2015 by dgelessus Quote Link to post Share on other sites