Exemplo n.º 1
0
static uint64_t
_get_num_sectors(int fd)
{
	unsigned long long bytes=0;

	if (blkdev_get_size(fd, &bytes) == -1)
		return 0;
	return bytes / _get_sector_size(fd);
}
Exemplo n.º 2
0
static uint64_t
_get_num_sectors(int fd)
{
	int version = _get_linux_version();
	unsigned long	size;
	uint64_t bytes=0;

	if (version >= KERNEL_VERSION(2,5,4) ||
		(version <  KERNEL_VERSION(2,5,0) &&
		 version >= KERNEL_VERSION (2,4,18)))
	{
                if (ioctl(fd, BLKGETSIZE64, &bytes) == 0)
                        return bytes / _get_sector_size(fd);
	}
	if (ioctl (fd, BLKGETSIZE, &size))
		return 0;
	return size;
}
Exemplo n.º 3
0
static uint64_t
last_lba(int fd)
{
	int rc;
	uint64_t sectors = 0;
	struct stat s;

	memset(&s, 0, sizeof (s));
	rc = fstat(fd, &s);
	if (rc == -1)
	{
		fprintf(stderr, "last_lba() could not stat: %m\n");
		return 0;
	}
	if (S_ISBLK(s.st_mode))
		sectors = _get_num_sectors(fd);
	else if (S_ISREG(s.st_mode))
		sectors = s.st_size >> _get_sector_size(fd);
	else
	{