lkml.org 
[lkml]   [2009]   [Sep]   [22]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: (un)mount ramfs from C code
On Tue, Sep 22, 2009 at 09:04:15AM -0700, Brian McGrew wrote:
> Good morning all!
>
> So I'm using a ramfs for temporary files, thank you whoever designed that,
> it works great!
>
> I can mkdir, mount, chmoud, readand write and then umount the thing from the
> command line just fine.
>
> What I need now is some method from within my C/C++ code to determine if the
> ramfs is mounted, if not, then mount it so I can use it and unmount it when
> I'm done, without making a system call.

You mean without using system(3), right? System call is how your program
interacts with the outside world.

The relevant system calls are:
- mount(2): mount("none", "/mnt", "ramfs", 0, NULL);
- umount(2): umount("/mnt");

The function(section) is the standard Unix way of specifying the manual
section of the function. Use it like this:
$ man 2 mount

About checking whether it is already mounted, you could parse the file
/proc/mounts, or check the result of statfs(2).

Regards,
Luciano Rocha

--
Luciano Rocha <luciano@eurotux.com>
Eurotux Informática, S.A. <http://www.eurotux.com/>
[unhandled content-type:application/pgp-signature]
\
 
 \ /
  Last update: 2009-09-22 18:29    [W:0.764 / U:0.040 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site