// compare MAJOR/MINOR in environment with the device // / is mounted on // // Author: Matthias Schwarzott #include #include #include #include #include // Getting major/minor #include int main(int argc, char **argv) { struct stat stat_buf; unsigned int root_major=0, root_minor=0; unsigned int dev_major=0, dev_minor=0; char *t; t=getenv("MAJOR"); if (!t) return EXIT_FAILURE; else dev_major=strtol(t, NULL, 10); t=getenv("MINOR"); if (!t) return EXIT_FAILURE; else dev_minor=strtol(t, NULL, 10); if (stat("/", &stat_buf)<0) return EXIT_FAILURE; root_major=major(stat_buf.st_dev); root_minor=minor(stat_buf.st_dev); // printf("ROOT: %d / %d \n", root_major, root_minor); // printf("DEV: %d / %d \n", dev_major, dev_minor); if (!root_major || !dev_major) { printf("MAJOR==0\n"); return EXIT_FAILURE; } if ( (root_major==dev_major) && (root_minor==dev_minor)) return EXIT_SUCCESS; return EXIT_FAILURE; }