I know how to use the libblkid library to analyze existing block devices. I'd like to use it to analyze a memory extent before I write it to the block device. Something like that:

char block[4096];
... writing into the block 
blkid_probe pr = blkid_new_probe_from_address(block);
... calling usual libblkid function on the pr

Of course, the blkid_new_probe_from_address doesn't exist - is it any way to create this kind of function using existing libblkid functions and without getting much into guts of this library?

Or, may be some other toolkit can achieve that?

1 Answer 1


I'm answering my own question. I was able to do what I wanted using a couple of functions from libblkid and the mkstemp function. This function creates and opens a temporary file (actually, in memory). We need to write the block into this file and then call the blkid_probe_set_device function with the file descriptor of this file. It looks like the library is happy to work with this artificial file. The code is below (I'm omitting all the error checks for simplicity):

    char block[4096];
    char filename[] = "/tmp/fileXXXXXX";
    const int fd = mkstemp(filename);
    write(fd, block, sizeof(block));
    blkid_probe pr = blkid_new_probe();
    blkid_probe_set_device(pr, fd, 0, 0);
    ... (analysis using various libblkid functions)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .