LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware
User Name
Password
Linux - Hardware This forum is for Hardware issues.
Having trouble installing a piece of hardware? Want to know if that peripheral is compatible with Linux?

Notices


Reply
  Search this Thread
Old 06-23-2006, 03:59 AM   #1
kasimtasdemir
LQ Newbie
 
Registered: Jun 2006
Posts: 3

Rep: Reputation: 0
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
 
Old 06-23-2006, 09:24 AM   #2
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,163
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
You should use either:
Code:
mount /dev/sda1 or
mount /mnt/usb
in your code.
Also remove that "umask=0" from /etc/fstab
 
Old 06-24-2006, 03:40 AM   #3
kasimtasdemir
LQ Newbie
 
Registered: Jun 2006
Posts: 3

Original Poster
Rep: Reputation: 0
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to detect insertion/removal of flash card in usb reader? logularjason Linux - Hardware 9 06-24-2006 03:11 AM
How to detect USB Flash drive in C program? kr123 Programming 1 12-06-2005 02:56 PM
kinoppix 3.7 doesnot detect the usb flash drive nirVaan Linux - Newbie 2 06-02-2005 01:16 AM
Mounting usb flash disc in Fedora Core 3 suro Fedora 6 04-14-2005 06:46 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware

All times are GMT -5. The time now is 07:34 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration