Advertisement
jow-

Untitled

Mar 22nd, 2015
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.54 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <dirent.h>
  3. #include <sys/stat.h>
  4.  
  5. int main(int argc, char **argv)
  6. {
  7.     struct stat root, block;
  8.     char path[128];
  9.     struct dirent *e;
  10.     DIR *d;
  11.  
  12.     if (stat(argv[1], &root))
  13.         return 1;
  14.  
  15.     if (!(d = opendir("/dev")))
  16.         return 1;
  17.  
  18.     while ((e = readdir(d)) != NULL)
  19.     {
  20.         snprintf(path, sizeof(path), "/dev/%s", e->d_name);
  21.  
  22.         if (lstat(path, &block) || !S_ISBLK(block.st_mode) || block.st_rdev != root.st_dev)
  23.             continue;
  24.  
  25.         printf("Rootdev is %s\n", path);
  26.         break;
  27.     }
  28.  
  29.     closedir(d);
  30.     return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement