?
Solved

How to read or write to a specific LBA on a SCSI harddisk?

Posted on 2005-03-09
14
Medium Priority
?
536 Views
Last Modified: 2013-12-27
Hi people,

I need to read and write a block of data (512B) to a specific LBA on a SCSI harddisk, anyone has any idea how to do that???

Thanks!
0
Comment
Question by:kwseow
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
  • 3
  • +1
14 Comments
 
LVL 10

Expert Comment

by:neteducation
ID: 13503639
You can use the "dd" on slice 2 of that disc with the option iseek/oseek (see manpages of dd for more detail)
0
 

Author Comment

by:kwseow
ID: 13503759
is there a API that i can use? I would like to access it through a low level program.
0
 
LVL 10

Expert Comment

by:neteducation
ID: 13503850
I see... in this case it's even easier... open /dev/dsk/c0t0d0s2 (or whatever disk you want to access), just like a normal file, seek to the apopriate sector and read/write to it.

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:kwseow
ID: 13508017
Hmm... sorry... I'm really new to this... can you give a example code?
0
 
LVL 10

Expert Comment

by:neteducation
ID: 13508090
what programming language do you use ?
0
 

Author Comment

by:kwseow
ID: 13508984
C
0
 
LVL 10

Accepted Solution

by:
neteducation earned 1800 total points
ID: 13509151
Well my C-know-how is kind of old, but it will work more or less like this

#include <stdio.h>
void main()
{
FILE *fp;
int block=37; /* or whichever you want */
char n1[512]; /* buffer where you can put what yo want to write */
fp = fopen( "/dev/rdsk/c0t0d0s2", "r+" );
     fseek(fp,512*block,SEEK_SET);
     fprintf( fp, "%s", &n1);  /* respcetifly some binary write */
     fclose( fp );
   }

0
 
LVL 10

Expert Comment

by:Nukfror
ID: 13509174
I assume this block is being written to an unformatted partition and not a formatted file system - just a comment.
0
 
LVL 10

Expert Comment

by:neteducation
ID: 13509295
right... to the raw disk as asked
0
 
LVL 10

Expert Comment

by:Nukfror
ID: 13513396
Well, I was just made my comment because the original request didn't specifically say "raw".
0
 
LVL 12

Assisted Solution

by:stefan73
stefan73 earned 200 total points
ID: 13521539
Hi neteducation,
Watch out for large files. You'll for sure need 64 bit I/O if you want to write directly to a disk beyond the 2GB boundary.

And you're probably better off using unbuffered I/O. Check open(), seek(), write() and close().

(untried) Example:
#include <unistd.h>

int f;
off_t block = 37;
f=open("/dev/rdsk/c0t0d0s2",O_WRONLY); /* Check for returned errors */
seek(f,block << 9,SEEK_SET); /* Check for returned errors */
write(f,&buffer,512); /* Check for returned errors */
close(f);

Make sure yoU#RE ALWAYS ON BLOCK BOUNDARIES:

Cheers!

Stefan
0
 
LVL 12

Expert Comment

by:stefan73
ID: 13521547
bloody wireless keyboard needs new batteries :-/
0
 
LVL 10

Expert Comment

by:neteducation
ID: 13522281
stefan73: good point.... missed that one... as said... my C-nowledge is kind of old.... will say from a time where harddrives still had capacities of 100 MB
0
 
LVL 12

Expert Comment

by:stefan73
ID: 13524085
It's easy to check: sizeof(off_t) must be 8.

Stefan
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tech tip describes how to install the Solaris Operating System from a tape backup that was created using the Solaris flash archive utility. I have used this procedure on the Solaris 8 and 9 OS, and it shoudl also work well on the Solaris 10 rel…
Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Suggested Courses

741 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question