From: Douglas G. <dgi...@in...> - 2010-01-26 04:49:54
|
Christian Franke wrote: > Hi, > > thanks to Antonio who tested several of my patches, we found the root of > the problem: > > hdparm opens the device with O_RDONLY > smartctl opens the device with O_RDWR > > Interestingly the latter wakes up the drive. > > Does Linux probably send some extra command when an raw device opened > for writing is closed ? > Is the R/W mode necessary for SCSI pass through ? Christian, What do you mean by "raw device" - /dev/sdb, or - /dev/sg3 (for example) ? In linux SCSI generic devices need to be opened O_RDWR to send commands unless the command is known to be safe (and is pretty common), for example, INQUIRY and MODE SENSE. A minimum of command filtering is done and all uses of the SCSI ATA PASS-THROUGH commands need O_RDWR. As for the sd driver, it is not clear to me. There is definitely code to do a SYNCHRONIZE CACHE command on close if it thinks the device has its Write Cache Enabled (WCE). Since that is a property of the disk the block layer (which receives the open() from the user space) could clear WCE if the device was opened O_RDONLY. So try open("/dev/sd<x>", O_RDONLY) and see what happens. You will soon find out if that is insufficient privilege. Doug Gilbert |