From owner-freebsd-hackers Tue Jun 1 7:50:49 1999 Delivered-To: freebsd-hackers@freebsd.org Received: from obie.softweyr.com (unknown [204.68.178.33]) by hub.freebsd.org (Postfix) with ESMTP id DD65115766 for ; Tue, 1 Jun 1999 07:50:37 -0700 (PDT) (envelope-from wes@softweyr.com) Received: from softweyr.com (homer.softweyr.com [204.68.178.39]) by obie.softweyr.com (8.8.8/8.8.8) with ESMTP id IAA16436; Tue, 1 Jun 1999 08:50:33 -0600 (MDT) (envelope-from wes@softweyr.com) Message-ID: <3753F33E.74DAA18C@softweyr.com> Date: Tue, 01 Jun 1999 08:50:38 -0600 From: Wes Peters Organization: Softweyr LLC X-Mailer: Mozilla 4.5 [en] (X11; U; FreeBSD 3.1-RELEASE i386) X-Accept-Language: en MIME-Version: 1.0 To: Zhihui Zhang Cc: freebsd-hackers@FreeBSD.ORG Subject: Re: Accessing special device files References: Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG Zhihui Zhang wrote: > > I write a small program to read/write each FreeBSD partition via special > device file names, e.g. /dev/wd0s2e, /dev/rwd0s2e, etc. I have two > questions about doing this: > > (1) If I try to read() on these files, the buffer size must be given in > multiples of 512 (sector size). Otherwise, I will get an EINVAL error. > Why is this the case? Does the same thing happen to the write() system > call? > > (2) I use lseek() on these device files, it returns the correct offset for > me. But actually it does not work. I read in a recent posting saying that > you can't expect lseek(fd, 0, SEEK_END) to work unless the file descriptor > is associated with a regular file because file size information is not > available at that level. Does this apply to all kinds of lseek(), include > SEEK_SET and SEEK_CUR? Or maybe the offset must also given in a multiple > of 512 for some reason. If I give lseek(fd, 8193, SEEK_SET), it will > actually do lseek(fd, 8192, SEEK_SET)? They're block devices, they can only be read, written, and seeked in terms of their native block size. The block size is typically 512 bytes for disks, other types of media (like CD-ROM) may vary greatly from this. If you want to read, write, or seek to arbitrary ranges, use the "raw" devices, i.e. rwd0s2e. These are character devices that will allow you to read, write, and seek to arbitrary byte locations on the device; the kernel handles the buffering and blocking for you. -- "Where am I, and what am I doing in this handbasket?" Wes Peters Softweyr LLC http://www.softweyr.com/~softweyr wes@softweyr.com To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message