Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 10 Nov 2004 16:46:02 +0000 (GMT)
From:      Robert Watson <rwatson@freebsd.org>
To:        Nehal <nehalmistry@gmx.net>
Cc:        freebsd-hackers@freebsd.org
Subject:   Re: read/write less than sector size
Message-ID:  <Pine.NEB.3.96L.1041110164248.60848d-100000@fledge.watson.org>
In-Reply-To: <41923564.7W4yXnkn0Ia1Jjug%nehalmistry@gmx.net>

next in thread | previous in thread | raw e-mail | index | archive | help

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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.NEB.3.96L.1041110164248.60848d-100000>