From owner-freebsd-hackers@FreeBSD.ORG Sat May 1 07:03:17 2004 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 4D55316A4CE for ; Sat, 1 May 2004 07:03:17 -0700 (PDT) Received: from tensor.xs4all.nl (tensor.xs4all.nl [194.109.160.97]) by mx1.FreeBSD.org (Postfix) with ESMTP id B555243D1F for ; Sat, 1 May 2004 07:03:16 -0700 (PDT) (envelope-from dimitry@andric.com) Received: from kilgore.dim (kilgore.dim [192.168.0.3]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by tensor.xs4all.nl (Postfix) with ESMTP id 5CA422284E; Sat, 1 May 2004 16:03:14 +0200 (CEST) Date: Sat, 1 May 2004 16:01:36 +0200 From: Dimitry Andric X-Mailer: The Bat! (v2.10.03) Business X-Priority: 3 (Normal) Message-ID: <1434443012.20040501160136@andric.com> To: Jens Schweikhardt In-Reply-To: <20040501113704.GA5730@schweikhardt.net> References: <20040501113704.GA5730@schweikhardt.net> MIME-Version: 1.0 Content-Type: multipart/signed; protocol="application/pgp-signature"; micalg="pgp-sha1"; boundary="----------9C16C19E114218" cc: freebsd-hackers@freebsd.org Subject: Re: lseek to EOF always 0 for devices X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 01 May 2004 14:03:17 -0000 ------------9C16C19E114218 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit 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 ), this works fine for me: #include #include #include #include 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; } ------------9C16C19E114218 Content-Type: application/pgp-signature -----BEGIN PGP MESSAGE----- Version: GnuPG v1.2.4 (MingW32) iD8DBQFAk63AsF6jCi4glqMRAiAUAJoDaKao+Uk92h943NrH6l8feHhBNgCgqFJi UZn7ZyVMNuQft1KM0WgW5jY= =xO8W -----END PGP MESSAGE----- ------------9C16C19E114218--