stattest.c:
// compile: gcc -o stattest stattest.c
#include <stdio.h>
#include <sys/stat.h>
int main(int argc, char *argv[]) {
struct stat stats;
stat(argv[1], &stats);
printf("%lli\n", (long long)stats.st_dev);
return 0;
}
Usage:
stat -f "%r" /dev/disk0 => 234881024 (Value that I'm looking for.) ./teststat /dev/disk0 => 44921876 python -c 'import os,sys; print os.stat(sys.argv[1]).st_dev' /dev/disk0 => 44921876
Why doesn't my code give me the value the stat
command gives me?
Update 1
Extracting the major number of 44921876 gives me 2 which is /dev/tty
.
Update 2
Specifying a file on the filesystem works. (I'm only using python here because it's faster.)
python -c "import sys,os; print os.stat(sys.argv[1]).st_dev" /path/to/file => 234881024