Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: /dev/disk and /dev/rdisk behavior



Hi Matt,

Is this the intended behavior of /dev/rdisk devices, or is this a bug?

This is correct behaviour. It's as per BSD semantics. Do not read too much into their names. The character ("raw") device is the unbuffered path. The block device is the buffered path. A good BSD book will go into more detail.

Dan

On Tuesday, December 3, 2002, at 02:43 PM, Matt Darland wrote:

The following code snippet( when run with superuser privileges ) reads 8 bytes from the /dev/rdisk0. I would expect that since rdisk is a character device I can do this. But I get an invalid argument error from the read() call. If I increase the number of bytes I read to >=512 (disk sector size?) then the read() call will succeed.
If I read() from /dev/disk0, I can make an 8 byte read() fine, but being a block oriented device this seems counter-intuitive to me.
Is this the intended behavior of /dev/rdisk devices, or is this a bug?

Thanks,
Matt Darland
email@hidden

#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>

int
main( void )
{
int fd;

if( (fd = open( "/dev/rdisk0", O_RDONLY )) < 0 )
{
fprintf( stderr, "open() error %d: %s\n", errno, strerror( errno ) );
}
else
{
int readval;
char buf[ 8 ];

/* Only works if sizeof( buf ) >= 512, or we opened /dev/disk0. */
if( (readval = read( fd, buf, sizeof( buf ) )) < 0 )
{
fprintf(
stderr, "read() error %d: %s\n", errno, strerror( errno ) );
}
else
{
int i;

fprintf( stderr, "Read %d bytes:\n", readval );
for( i = 0; i < (int)(sizeof( buf ) / sizeof( buf[ 0 ] )); ++i )
{
fprintf( stderr, "%02x ", (int)buf[ i ] );
}

fprintf( stderr, "\n" );
}
}

return( 0 );
}
_______________________________________________
darwin-development mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/darwin-development
Do not post admin requests to the list. They will be ignored.
_______________________________________________
darwin-development mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/darwin-development
Do not post admin requests to the list. They will be ignored.

References: 
 >/dev/disk and /dev/rdisk behavior (From: Matt Darland <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.