cgpt/cgpt_find.c
// Given basename "foo", see if we can find a whole, real device by that name.
// This is copied from the logic in the linux utility 'findfs', although that
// does more exhaustive searching.
Given basename "foo", see if we can find a whole, real device by that name.
This is copied from the logic in the linux utility 'findfs', although that
does more exhaustive searching.
Given basename " foo " see if we can find a whole real device by that name . This is copied from the logic in the linux utility ' findfs ' although that does more exhaustive searching .
static char *is_wholedev(const char *basename) {
  int i;
  struct stat statbuf;
  static char pathname[BUFSIZE];        
  char tmpname[BUFSIZE];
  for (i = 0; devdirs[i]; i++) {
    sprintf(pathname, "%s/%s", devdirs[i], basename);
    if (0 != stat(pathname, &statbuf))
      continue;
    if (!S_ISBLK(statbuf.st_mode))
      continue;
    sprintf(tmpname, "%s/%s/device", SYS_BLOCK_DIR, basename);
    if (0 != lstat(tmpname, &statbuf))
      continue;
    if (!S_ISLNK(statbuf.st_mode))
      continue;
    return pathname;
  }
  return 0;
}
static char * is_wholedev ( const char * basename ) { int i ; struct stat statbuf ; static char pathname [ BUFSIZE ] ; char tmpname [ BUFSIZE ] ; for ( i = 0 ; devdirs [ i ] ; i ++ ) { sprintf ( pathname , " " , devdirs [ i ] , basename ) ; if ( 0 != stat ( pathname , & statbuf ) ) continue ; if ( ! S_ISBLK ( statbuf . st_mode ) ) continue ; sprintf ( tmpname , " " , SYS_BLOCK_DIR , basename ) ; if ( 0 != lstat ( tmpname , & statbuf ) ) continue ; if ( ! S_ISLNK ( statbuf . st_mode ) ) continue ; return pathname ; } return 0 ; }
Given basename "foo", see if we can find a whole, real device by that name.
Given basename " foo " see if we can find a whole real device by that name .
// we'll return this. // It should be a block device under /dev/, // It should have a symlink called /sys/block/*/device // found it