Checking if device is mounted..


 
Thread Tools Search this Thread
Top Forums Programming Checking if device is mounted..
# 1  
Old 02-10-2009
Checking if device is mounted..

Hi,
I want to check if a device is mounted before performing actual mount. I was able to check that using the below C code. But in C++ it is throwing the following error:
" error: invalid conversion from `int' to `const char*' "

C program just generated a warning message, but C++ throws error..

Please let me know if there is any other way to find the mount devices using C++.

Code:
int main()
{
if (system('mount | grep "home" >/dev/null') != 0)
     printf("home is mounted\n");
else
     printf("home is not mounted\n");

}

# 2  
Old 02-10-2009
Code:
int main()
{
if (system("mount | grep \"home\" >/dev/null") != 0)
     printf("home is mounted\n");
else
     printf("home is not mounted\n");

}

Strings in C/C++ are never single quotes, they're always double-quotes. Try it now.
# 3  
Old 02-10-2009
I believe the return value of 'system(whatever)' signifies a success/failure of 'whatever' being spawned - which is not the same as the return value of 'whatever'.
# 4  
Old 02-10-2009
Manpage on my system says it returns -1 if it can't fork, and returns the return value of the command otherwise.
Login or Register to Ask a Question

Previous Thread | Next Thread

5 More Discussions You Might Find Interesting

1. HP-UX

Failed to open tape device /dev/rmt/0mn:Device busy (errno = 16)

Hi, Unable to make tape backup, please help. /opt/ignite/bin/make_tape_recovery -a /dev/rmt/?mn -I -v -m tar -x inc_entire=vg00 * Creating local directories for configuration files and archive. ======= 04/25/16 16:28:08 IST Started /opt/ignite/bin/make_tape_recovery. (Mon... (4 Replies)
Discussion started by: anuragr
4 Replies

2. Red Hat

Unable To Activate Ethernet Network Device in RHEL 5.5 - e100 device eth0 does not seem to be presen

Hi All, Could anyone please help to resolve the below problem. I installed RHEL5.5 in my desktop.But when i try to activate the ethernet connection then it gives me the error. I spent 2 days for the above and go through with several suggestion found by googling. But no luck. ... (0 Replies)
Discussion started by: Tanmoy
0 Replies

3. UNIX for Advanced & Expert Users

Which system calls to move data on a device with mounted partitions?

I need to be able to move data around a disk that has mounted partitions. I am not touching the data on the mounted partition, the MBR or any other disk metadata, only the freespace and unmounted partitions. At the moment I am using libparted but it causes data corruption sometimes although there... (1 Reply)
Discussion started by: vstrom
1 Replies

4. UNIX for Dummies Questions & Answers

lvrename to a mounted device

Hi, I wanted to rename a filesystem but I forgot to unmount it before running lvrename and now it is still visible when doing df -k old name device: /dev/mapper/vg01-MGRSTR3 mounted as /MGRSTR3 new name: /dev/mapper/vg01-mgrusr3 mounted as /mgrusr3 when trying to unmount the old one... (2 Replies)
Discussion started by: galuzan
2 Replies

5. OS X (Apple)

Not mounted, no-driver USB device in terminal (how to access?)

hi, i am on a quest to access and even mount if possible a drive on os x. there is no driver for the device, but it lists fine in the system profiler. can i access its location from the terminal? how? here is what i get on the system profiler: Speed: Up to 480 Mb/sec Manufacturer: SAMSUNG ... (3 Replies)
Discussion started by: sontarieh
3 Replies
Login or Register to Ask a Question