cfile-iofilesystemsext2

Using open() on a thumb drive


I have an EXT2 partition on my usb thumb drive and I can't get the C function open() to return anything other than -1.

Partition manager says that the partition is located at /dev/sdb2 and my code says

int fd = open("/dev/sdb2", O_RDONLY);

But after debugging, (fd == -1) and my usb notifier says that it isn't mounted before or after.

Side Note: the super-block and boot section seem to populate with values...


Solution

  • The code to open the thumb drive is correct in my question, but the program either needs to be run as super-user or chmod 777 /dev/sdb2

    To see if this is your issue use the code above printf("Error: %s\n", strerror(errno));