cgpt/cgpt_common.c
/*
 * Query drive size and bytes per sector. Return zero on success. On error,
 * -1 is returned and errno is set appropriately.
 */
Query drive size and bytes per sector. Return zero on success. On error,
-1 is returned and errno is set appropriately.
Query drive size and bytes per sector . Return zero on success . On error - 1 is returned and errno is set appropriately .
static int ObtainDriveSize(int fd, uint64_t* size, uint32_t* sector_bytes) {
  struct stat stat;
  if (fstat(fd, &stat) == -1) {
    return -1;
  }
#if !defined(HAVE_MACOS) && !defined(__FreeBSD__) && !defined(__OpenBSD__)
  if ((stat.st_mode & S_IFMT) != S_IFREG) {
    if (ioctl(fd, BLKGETSIZE64, size) < 0) {
      return -1;
    }
    if (ioctl(fd, BLKSSZGET, sector_bytes) < 0) {
      return -1;
    }
  } else {
    *sector_bytes = 512;  
    *size = stat.st_size;
  }
#else
  *sector_bytes = 512;  
  *size = stat.st_size;
#endif
  return 0;
}
static int ObtainDriveSize ( int fd , uint64_t * size , uint32_t * sector_bytes ) { struct stat stat ; if ( fstat ( fd , & stat ) == -1 ) { return -1 ; } #if ! defined ( HAVE_MACOS ) && ! defined ( __FreeBSD__ ) && ! defined ( __OpenBSD__ ) if ( ( stat . st_mode & S_IFMT ) != S_IFREG ) { if ( ioctl ( fd , BLKGETSIZE64 , size ) < 0 ) { return -1 ; } if ( ioctl ( fd , BLKSSZGET , sector_bytes ) < 0 ) { return -1 ; } } else { * sector_bytes = 512 ; * size = stat . st_size ; } #else * sector_bytes = 512 ; * size = stat . st_size ; #endif return 0 ; }
Query drive size and bytes per sector.
Query drive size and bytes per sector .
/* bytes */ /* bytes */