From: Gary Wright Date: 2009-11-27T12:46:13+09:00 Subject: Re: Ruby byte access to disk sectors like dd does On Nov 26, 2009, at 4:07 PM, Gary Hasson wrote: > I have been unable to find any reference to Ruby methods that provide > raw disk access the way dd does. I frequently use the Linux utility > program, dd, and would like to be able to do the same type of byte-level > and sector-level access to the hard drive with Ruby. (What I am looking > for is not file access.) Are there Ruby methods to provide this > capability (other than having Ruby access dd)? dd doesn't ever have 'raw disk access' or 'sector' level access to a disk drive so I'm not sure how to respond. A raw disk device just presents the underlying drive as a file. You use seek and read and write to accomplish I/O but it is generally a mistake to think that you are accessing particular 'sectors' when you do this. Modern disks drives have complex geometries that aren't visible unless you are working at the device driver level. To utilize 'raw' I/O with Ruby look at IO#sysread, IO#syswrite, and IO#sysseek. This would be analogous to a C program utilizing the similarly named system calls. You'll also want to open the device file in binary mode and also be sure that you don't use any of the buffered I/O methods (i.e. don't mix and match). Gary Wright