LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Hardware (https://www.linuxquestions.org/questions/linux-hardware-18/)
-   -   How can I detect USB flash disc with programming in C? (https://www.linuxquestions.org/questions/linux-hardware-18/how-can-i-detect-usb-flash-disc-with-programming-in-c-457497/)

kasimtasdemir 06-23-2006 03:59 AM

How can I detect USB flash disc with programming in C?
 
Hi,
I try to write a C program that can detect whether usb flash disc is enable as a non-root user. Consequently, it will copy some files from the hard disc to the USB flash.
I tried this code in C:
Code:

system("mount /dev/sda1 /mnt/usb");
Shell has warned me like:
Code:

mount: Only root can do this.
(sorry about bad translation)
It failed until I log in as root. In order to allow all users to mount, I inserted this code in fstab:
/dev/sda1 /mnt/usb vfat noauto,users,rw,umask=0 0 0
It did not work,it gave same result.
I would be happy if anyone can solve my problem or give an idea. Thanks

bathory 06-23-2006 09:24 AM

You should use either:
Code:

mount /dev/sda1 or
mount /mnt/usb

in your code.
Also remove that "umask=0" from /etc/fstab

kasimtasdemir 06-24-2006 03:40 AM

Quote:

Originally Posted by bathory
You should use either:
Code:

mount /dev/sda1 or
mount /mnt/usb

in your code.
Also remove that "umask=0" from /etc/fstab

Thank you for your respond. Unfortunately this would not useful for me. I want to do this in C as a non-root user. I found something that may be a solution for me:
Quote:

Originally Posted by logularjason
...I worked it out for myself in the end. The SCSI kernel driver returns a "no medium" code when an open() call is made and removable media (e.g. flash card) is not present. So all I need to do is make an open() call, and see what the return code is.

However I did not understand that how can I call "open()" in C in order to see the existance of USB flash drive? If you understand the way, could you give an samle code block,please? Thanks.


All times are GMT -5. The time now is 05:24 PM.