Costa Mirkin
Costa Mirkin

Reputation: 977

Open physical drive from Linux

I'd like to open SD card as physical drive on Linux. Somethink like: CreateFile("PHYSICALDRIVE0",...) On MS Windows. How can I do it?

Upvotes: 0

Views: 918

Answers (3)

MarkR
MarkR

Reputation: 63616

You open the block device special file (typically something like /dev/sdb) and then you can read/write blocks from it.

The interface is not clearly documented, it is a bug that there is no block(4) man page.

The sd(4) man page does help a bit though. The ioctls described there are probably valid for (some) other block devices as well.

Nowadays nearly all block devices appear as a "scsi drive" regardless of whether they are actually attached by scsi or not. This includes USB and (most) ATA drives.

Finding the right device to open may be a big part of the problem though, particularly if you have hotplug devices. You might be able to interrogate some things in /sys to find out what devices there are.

Upvotes: 0

dmeister
dmeister

Reputation: 35654

All devices are represented as files under the /dev directory. These files can be opened exactly like regular files, e.g. open(/dev/sdb, ...).

Disk-like devices are also symlinked in the directories /dev/disk/by-id/, /dev/disk/by-path, and /dev/disk/by-uuid, which makes it much easier to find to matching device file.

Upvotes: 4

Austin
Austin

Reputation: 85

Type df, to list all your filesystems mounted or unmounted. Once you know its address(everything in Linux is a file, so it will look like /dev/sda# or something like that) you can mount it with the mount command:

mount /path/to/drive /folder/to/mount/to

Upvotes: 0

Related Questions