LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 07-04-2010, 05:21 AM   #1
wiener
LQ Newbie
 
Registered: Jun 2009
Posts: 22

Rep: Reputation: 0
fail to write to USB device boot sector


Hi,
I'm writing a C program that reads the boot sector of a USB disk. (it is mounted as /dev/sda1). I'm able to read the sector, by the calls:
fd = open("/dev/sda1", O_RDWR)
and
bytesRead = read(fd, (void*)buf, 512)
And I get the expected value of 512 back from the 'read' call.

The problem is when I wish to write. I use the call:
bytesWrite = write(fd, buf, 512)
The 'write' returns the value of 512, which looks as if the write was successful, yet
when I read again the /dev/sda1 device, I see that no writing was actually made.

Can anybody tell me what do I need to do in order to allow an actual write to the
device?
Thanks in advance,
Moshe
 
Old 07-05-2010, 09:58 PM   #2
Matir
Moderator
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 118Reputation: 118
Moved: This thread is more suitable in Programming and has been moved accordingly to help your thread/question get the exposure it deserves.
 
Old 07-07-2010, 05:04 PM   #3
TimothyEBaldwin
Member
 
Registered: Mar 2009
Posts: 249

Rep: Reputation: 27
Did you write to the second sector? You need to reset the offset using lseek, or use pwrite.
 
  


Reply

Tags
sector


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Problem in write permissions in USB Device BlueSkull Linux - Newbie 2 04-02-2010 01:18 PM
USB Harddrive Boot Sector Choice Adriann Mandriva 2 03-25-2010 12:09 AM
Boot sector not recognized on USB HDD Liam123 Linux - Hardware 1 12-29-2007 01:03 AM
write an iso boot sector and all to HDD partition Person_1873 Linux - General 18 12-20-2007 10:16 AM
How i can write to device /dev/usb/hiddev0 ? njel Programming 2 08-17-2004 04:16 AM


All times are GMT -5. The time now is 10:30 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration