Re: lseek to EOF always 0 for devices
From: Dimitry Andric (dimitry_at_andric.com)
Date: 05/01/04
- Previous message: Richard Bradley: "linking questions (how to use linux version of libc)"
- In reply to: Jens Schweikhardt: "lseek to EOF always 0 for devices"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sat, 1 May 2004 16:01:36 +0200 To: Jens Schweikhardt <schweikh@schweikhardt.net>
On 2004-05-01 at 13:37:04 Jens Schweikhardt wrote:
> I'm not sure if I'm trying something impossible here. I want to find the
> size in bytes of a disk special device, eg /dev/da0, /dev/da0s1,
> /dev/da0s1a, /dev/vinum/usr and so on.
I have no idea why lseek'ing in the devices doesn't work, but try
using ioctl(2) with DIOCGMEDIASIZE (from <sys/disk.h>), this works
fine for me:
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/disk.h>
int main (int argc, char **argv)
{
int fd;
off_t len;
if (argc != 2)
return 1;
if ((fd = open (argv[1], O_RDONLY)) < 0) {
perror (argv[1]);
return 1;
}
if (ioctl (fd, DIOCGMEDIASIZE, &len) == -1) {
perror ("DIOCGMEDIASIZE");
return 1;
}
printf ("%lld\n", (long long)len);
close (fd);
return 0;
}
- application/pgp-signature attachment: stored
- Previous message: Richard Bradley: "linking questions (how to use linux version of libc)"
- In reply to: Jens Schweikhardt: "lseek to EOF always 0 for devices"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|