Share your knowledge at the LQ Wiki.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


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

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

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)
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
Thanks in advance,
Old 07-05-2010, 08:58 PM   #2
LQ Guru
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 124Reputation: 124
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, 04:04 PM   #3
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.



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 12:18 PM
USB Harddrive Boot Sector Choice Adriann Mandriva 2 03-24-2010 11:09 PM
Boot sector not recognized on USB HDD Liam123 Linux - Hardware 1 12-29-2007 12:03 AM
write an iso boot sector and all to HDD partition Person_1873 Linux - General 18 12-20-2007 09:16 AM
How i can write to device /dev/usb/hiddev0 ? njel Programming 2 08-17-2004 03:16 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:23 AM.

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