简体   繁体   中英

Read raw data from memory card on linux

我想在 Linux 操作系统上使用 c 从存储卡读取分配单元 512b,如何使用 (fopen) 打开存储卡的(原始数据)?

on Linux [...] how can I open (raw data) of the memory card using (fopen)?

Supposing that the operating system recognizes the card's presence, it will present the card to user programs as a device file. On my system, for example, that is typically /dev/sdb , but it could easily be different on yours (and even on mine, for various reasons). Provided that you have sufficient privilege, you can open the appropriate file and read data from it just as you do an ordinary file. Relying only on standard C functions, then, one might do this:

unsigned char data[512];
FILE *card = fopen("/dev/name_of_device", "r");
// if (card == NULL) handle error ...
size_t count = fread(data, sizeof data, 1, card);
// if (count != 1) handle error ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM