Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / September 2007

Tip: Looking for answers? Try searching our database.

Accessing raw devices (hard drives) with Java ?

Thread view: 
Sébastien de Mapias - 10 Sep 2007 15:33 GMT
Hi,
Let's I have (under Solaris for example) a device /dev/[r]dsk/c0t2d0s0
that's not mounted (so I can't performe any 'ls' etc.), and I'd like
to
traverse its bytes: is there a way to access this data from Java ?
Has anyone already tried to write such a program ?

Thanks !
Regards,
Seb
Mike Baranczak - 10 Sep 2007 16:00 GMT
> Hi,
> Let's I have (under Solaris for example) a device /dev/[r]dsk/c0t2d0s0
> that's not mounted (so I can't performe any 'ls' etc.), and I'd like
> to
> traverse its bytes: is there a way to access this data from Java ?

Short answer: no.

Long answer: Java only gives you a very high-level view of the file
system. If you want to access an unmounted partition from Java, you'll
either have to write some JNI code or use Runtime.exec() to call a
native command which reads the partition data (dd if=/dev/dsk/c0t2d0s0
of=whatever etc...)

-MB

Signature

http://www.pocketgorilla.com - search engine for freelance programmers

Andreas Leitgeb - 10 Sep 2007 17:00 GMT
>> Let's I have (under Solaris for example) a device /dev/[r]dsk/c0t2d0s0
>> that's not mounted (so I can't performe any 'ls' etc.), and I'd like
>> to traverse its bytes: is there a way to access this data from Java ?

> Short answer: no.
Really?

Sebastien, did you try to just simply open /dev/dsk/c0t2d0s0
and read from it?  (You need to be running as root, of course!)
Mike Baranczak - 11 Sep 2007 17:47 GMT
> >> Let's I have (under Solaris for example) a device /dev/[r]dsk/c0t2d0s0
> >> that's not mounted (so I can't performe any 'ls' etc.), and I'd like
[quoted text clipped - 5 lines]
> Sebastien, did you try to just simply open /dev/dsk/c0t2d0s0
> and read from it?  (You need to be running as root, of course!)

OK, that does make more sense.

-MB

Signature

http://www.pocketgorilla.com - search engine for freelance programmers

Nigel Wade - 10 Sep 2007 17:34 GMT
> Hi,
> Let's I have (under Solaris for example) a device /dev/[r]dsk/c0t2d0s0
> that's not mounted (so I can't performe any 'ls' etc.), and I'd like
> to
> traverse its bytes: is there a way to access this data from Java ?
> Has anyone already tried to write such a program ?

Have /you/ tried to write such a program?

In UNIX a device special file is pretty much like any other file. That's one of
the simplicities of UNIX. The device driver for that device should provide the
basic open/close/read/write functions to the kernel, so that higher level
languages can perform those operations. I presume Java only makes uses of those
native methods to access a file.

Try writing a program to read from it just like you would any binary file. Of
course, you most likely need root permission to open a block special file even
for read because you are bypassing all the filesystem level permissions on
contents of that device. And you need to be able to make sense of what you
read...

Signature

Nigel Wade, System Administrator, Space Plasma Physics Group,
           University of Leicester, Leicester, LE1 7RH, UK
E-mail :    nmw@ion.le.ac.uk
Phone :     +44 (0)116 2523548, Fax : +44 (0)116 2523555

Roedy Green - 13 Sep 2007 01:37 GMT
On Mon, 10 Sep 2007 07:33:38 -0700, Sébastien de Mapias
<sglrigaud@gmail.com> wrote, quoted or indirectly quoted someone who
said :

>traverse its bytes: is there a way to access this data from Java ?
>Has anyone already tried to write such a program ?

You need to write some low level accessing code in C with JNI glue..
With every passing year this gets harder and harder to write as
security in OSes tightens.

Basically all you need is a read( offset, length ) and write(offset,
length).

Keep in mind there will be many parts of the disk the OS will not let
you touch, e.g. the paging file or the bootsector. To do this sort of
thing properly, you need to use the Boot-It approach where you boot to
a very simple OS without security from CD.  Then you can do anything
you want without OS interference.

see http://mindprod.com/bgloss/bootit.html
http://mindprod.com/jgloss/jni.html
Signature

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com

Gordon Beaton - 13 Sep 2007 07:51 GMT
> On Mon, 10 Sep 2007 07:33:38 -0700, Sébastien de Mapias
><sglrigaud@gmail.com> wrote, quoted or indirectly quoted someone who
[quoted text clipped - 3 lines]
>
> You need to write some low level accessing code in C with JNI glue..

No you don't, you can use e.g. FileInputStream or RandomAccessFile.

On Unix, those devices look and behave just like files to any process.

/gordon

--
Roedy Green - 13 Sep 2007 08:02 GMT
>No you don't, you can use e.g. FileInputStream or RandomAccessFile.

what's to stop you from reading other people's files?  You must need
some special privilege to use this access, no?

Signature

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com

Gordon Beaton - 13 Sep 2007 08:11 GMT
> what's to stop you from reading other people's files?  You must need
> some special privilege to use this access, no?

Yes, you need appropriate permissions, and that's true no matter what
special device or regular file you choose to open (they are
conceptually the same thing).

But the permissions have nothing whatsoever to do with the technique
you choose; the two issues are orthogonal.

/gordon

--
Arne Vajhøj - 15 Sep 2007 01:50 GMT
>> No you don't, you can use e.g. FileInputStream or RandomAccessFile.
>
> what's to stop you from reading other people's files?  You must need
> some special privilege to use this access, no?

I don't think the term "other people's files" make much sense
in the context of a raw device.

"other peoples bytes" or "other peoples blocks" maybe.

:-)

Typical you have stuff like databases in raw partitions. And
then the database and often also an application provides a
different type of security.

Arne
Nigel Wade - 13 Sep 2007 13:12 GMT
> On Mon, 10 Sep 2007 07:33:38 -0700, Sébastien de Mapias
> <sglrigaud@gmail.com> wrote, quoted or indirectly quoted someone who
[quoted text clipped - 4 lines]
>
> You need to write some low level accessing code in C with JNI glue..

You shouldn't need to with Solaris.

> With every passing year this gets harder and harder to write as
> security in OSes tightens.

The only security on a device special file in Solaris is the basic filesystem
permissions on the device special file itself. If you have read permission on
that file you can open it and read the contents.

> Basically all you need is a read( offset, length ) and write(offset,
> length).
>
> Keep in mind there will be many parts of the disk the OS will not let
> you touch, e.g. the paging file or the bootsector.

Not in Solaris. A device special file provides you with read (and/or write)
access to the raw disk/partition. If you read direct from the device special
file Solaris makes no interpretation of the contents of that raw
disk/partition, it is simply a stream of bytes just as any other binary file.

> To do this sort of
> thing properly, you need to use the Boot-It approach where you boot to
> a very simple OS without security from CD.  Then you can do anything
> you want without OS interference.

Alternatively, just use the facilities provided by the OS you already have
installed...

Signature

Nigel Wade, System Administrator, Space Plasma Physics Group,
           University of Leicester, Leicester, LE1 7RH, UK
E-mail :    nmw@ion.le.ac.uk
Phone :     +44 (0)116 2523548, Fax : +44 (0)116 2523555



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.