I want to read allocation unit 512b from memory card using c on Linux os, how can I open (raw data) of the memory card using (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 ...