To test whether a ramdisk has been mounted I have created a file in the mount point directory. I then test whether that file exists and if not I presume a ramdisk has been mounted there. Is there a more elegant method without needing a test file?

That test just check if anything was mounted on the moint point directory. Of course, it will be false negative once the mounted filesystem contains a file with the same name as the test file. jcb's stat test Re: Check that a ramdisk is mounted does that better, without false negative results.

None of the tests checks for a ramdisk, both just check for any filesystem mounted. Detecting a ramdisk is highly specific for the operating system. The device number of the file system (the first value in stat's return value) may be a clue. With knowledge about how device numbers are allocated, you may at least be able to identify disk- or flash-backed block devices. Linux has a file named "Documentation/devices.txt", "Documentation/admin-guide/devices.txt" in newer versions, that contains major and minor device numbers. Some major device numbers are used for RAM disks, floppies, various hard disk interfaces, cdrom drives, and so on, they are quite obvious. Other block devices are in-between: Loop devices create a block device from a file that may or may not exist on a ramdisk. Network block devices import other computer's block devices that may or may not be ramdisks. Then there are experimental, local and dynamically allocated block devices, the latter for virtual filesystems like tmpfs that need just a dummy block device number, but no real block device. And ramdisks implemented as real, physical peripherals plugged into some system bus, or simply appearing as a SCSI disk. And that's just Linux. Feel free to explore OSX and the *BSDs ...

Alexander

--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

In reply to Re: Check that a ramdisk is mounted by afoken
in thread Check that a ramdisk is mounted by pmilne

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.