Jump to content
  • Advertisement
Sign in to follow this  
fathom88

UNIX Programming Question: Check Mount

This topic is 3686 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I need to check if a drive has been mounted. I use struct stat Data; bool CD_ROM_Mounted = false; if(stat("/mnt/cdrom", &Data) >= 0) { CD_ROM_Mounted = true; } This bit of code seems to work on the 1st attempt. When the user removes the drive, I make the following call system("umount /mnt/cdrom"); Then I insert a USB HD. I make the same call. if(stat("/mnt/cdrom", &Data) >= 0) { CD_ROM_Mounted = true; } I would expect the stat call to return an error and not set my flag. However, it sets mt CD Rom flag to true even though the folder should have been unmounted. Am I doing something obviously wrong? Should I use a different call to check if a folder is mounted? Thanks.

Share this post


Link to post
Share on other sites
Advertisement
The stat function is probably not what you want. And, anyway, that will return zero so long as the directory (or file, or whatever) exists, whether anything's mounted on it or not. (That stat returns zero doesn't tell you much anyway, you've got to look at the struct stat that it fills in.)

See the stat man page (type "man 2 stat")

But, to find what's mounted, you probably want getmntent, not stat. (so, type "man getmntent")

You probably do not want to read /etc/mtab directly, You probably want to use getmntent() to do it. Beware of system specific differences though, HPUX, SYS V, Digital unix, etc have differences (being a game oriented site, I'm guessing you likely don't care about those too much, probably only linux, Mac OS X, and FreeBSD -- but that's a guess.)

Share this post


Link to post
Share on other sites
Thank you for the suggestions. Sorry for putting this post in the wrong place. I should have put it in general programming.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!