Date: Sat, 1 May 2004 13:37:04 +0200 From: Jens Schweikhardt <schweikh@schweikhardt.net> To: freebsd-hackers@freebsd.org Subject: lseek to EOF always 0 for devices Message-ID: <20040501113704.GA5730@schweikhardt.net>
next in thread | raw e-mail | index | archive | help
Fellow hackers, 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. The following program prints correct sizes for plain files and directories, but it consistently prints 0 for block devices. If this is not supported, how would I find the number of blocks for a given block device? I don't want to mess with parsing disklabels and vinum configs... #include <stdio.h> #include <fcntl.h> #include <unistd.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 ((len = lseek (fd, 0, SEEK_END)) == -1) { perror ("lseek"); return 1; } printf ("%lld\n", (long long)len); close (fd); return 0; } Regards, Jens -- Jens Schweikhardt http://www.schweikhardt.net/ SIGSIG -- signature too long (core dumped)
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20040501113704.GA5730>