From owner-freebsd-hackers@FreeBSD.ORG Sat May 1 04:37:07 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 64ED516A4CE for ; Sat, 1 May 2004 04:37:07 -0700 (PDT) Received: from bremen.shuttle.de (bremen.shuttle.de [194.95.249.251]) by mx1.FreeBSD.org (Postfix) with ESMTP id 9BF7143D3F for ; Sat, 1 May 2004 04:37:06 -0700 (PDT) (envelope-from schweikh@schweikhardt.net) Received: by bremen.shuttle.de (Postfix, from userid 10) id 047FD3BA8E; Sat, 1 May 2004 13:37:04 +0200 (CEST) Received: from hal9000.schweikhardt.net (localhost [127.0.0.1]) i41Bb4CZ005906 for ; Sat, 1 May 2004 13:37:04 +0200 (CEST) (envelope-from schweikh@hal9000.schweikhardt.net) Received: (from schweikh@localhost) by hal9000.schweikhardt.net (8.12.11/8.12.11/Submit) id i41Bb4bD005905 for freebsd-hackers@freebsd.org; Sat, 1 May 2004 13:37:04 +0200 (CEST) (envelope-from schweikh) Date: Sat, 1 May 2004 13:37:04 +0200 From: Jens Schweikhardt To: freebsd-hackers@freebsd.org Message-ID: <20040501113704.GA5730@schweikhardt.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.6i Subject: 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 11:37:07 -0000 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 #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 ((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)