0

I need to compute the sha1sum of an emmc partition and obviously this involves reading the contents of the partition (if at all it is relevant - the partition is ext4-formatted).

I am performing the read operation on /dev/mmcblkp** just like any other fd:

while ((ret = read(blk_dev_fd, buffer, BLOCKSIZE))) > 0) {
    printf("Read %zd bytes from source_fd\n", ret);
    // do something
}

Is this correct? Can I expect read to return 0 on EOF or is there no such thing as EOF on block devices?

sg1993
  • 335
  • 2
  • 19
  • 1
    Yes, this is fine. You won't read off the end of the block device or the partition. – that other guy Jul 18 '18 at 16:57
  • Thanks, my'observations were the same, just wanted a confirmation to be safe (`BLOCKSIZE * num_of_iterations` were exactly equal to the partition size(which was aligned to `BLOCKSIZE` to begin with)). – sg1993 Jul 18 '18 at 17:34

0 Answers0