On 4/5/06, Glynn Clements <glynn@xxxxxxxxxxxxxxxxxx> wrote: > > Rebelde wrote: > > > On Windows XP I can write directly to disk whitout cache write using the > > CreateFile function with FILE_FLAG_WRITE_THROUGH. Could someone tell me > > how to make this on Linux? > > Pass the O_SYNC flag to open(). This will cause write() calls to block > until the data has been sent to the drive. > > The O_DIRECT flag suggested by Steve is probably overkill. It requires > that the buffer start address, buffer size and file offset are all > multiples of the filesystem's block size, and only works on some > filesystems. Well, the O_SYNC flag causes, i.e. write(2), to block until the data has been physically written to disk, but it does not prevent the C library/kernel from caching the bytes. O_DIRECT, on the other hand, circumvents the caching mechanisms and allows for raw access, although it may degrade performance. While sematically difficult, I think this technique is nearest equivalent to the FILE_FLAG_WRITE_THROUGH flag known from Windows. \Steve - : send the line "unsubscribe linux-c-programming" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html