From owner-freebsd-hackers@FreeBSD.ORG Wed Nov 10 16:47:13 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 1F64E16A4CE for ; Wed, 10 Nov 2004 16:47:13 +0000 (GMT) Received: from fledge.watson.org (fledge.watson.org [204.156.12.50]) by mx1.FreeBSD.org (Postfix) with ESMTP id B0A7143D68 for ; Wed, 10 Nov 2004 16:47:12 +0000 (GMT) (envelope-from robert@fledge.watson.org) Received: from fledge.watson.org (localhost [127.0.0.1]) by fledge.watson.org (8.13.1/8.13.1) with ESMTP id iAAGk2fS080088; Wed, 10 Nov 2004 11:46:02 -0500 (EST) (envelope-from robert@fledge.watson.org) Received: from localhost (robert@localhost)iAAGk2Ij080085; Wed, 10 Nov 2004 16:46:02 GMT (envelope-from robert@fledge.watson.org) Date: Wed, 10 Nov 2004 16:46:02 +0000 (GMT) From: Robert Watson X-Sender: robert@fledge.watson.org To: Nehal In-Reply-To: <41923564.7W4yXnkn0Ia1Jjug%nehalmistry@gmx.net> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII cc: freebsd-hackers@freebsd.org Subject: Re: read/write less than sector size 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: Wed, 10 Nov 2004 16:47:13 -0000 On Wed, 10 Nov 2004, Nehal wrote: > if i open /dev/ad1s1 for example, i try to read() or write() not in > multiples of 512, it will return an error. > > how would i do this? currently, if i need to read 100 bytes, i read in > the full sector, then memcpy the bytes i need. Disks operate only on full sectors, and the current FreeBSD API for reading and writing disks requires the caller to decide how to handle non-integer multiples of the sector size for I/O operations. Reading into a sector-sized buffer and then selected the desired data or performing desired update and write back to disk is the best (only?) way to handle this. Some systems provide a buffered I/O interface to disks but this can have some odd cache coherency properties, and most large scale consumers of direct disk interfaces (databases or file systems) want to manage their data caching directly in order to provide the desired consistency properties. Robert N M Watson FreeBSD Core Team, TrustedBSD Projects robert@fledge.watson.org Principal Research Scientist, McAfee Research