On Tue, 28 Jan 2014, Linus Torvalds wrote: > On Tue, Jan 28, 2014 at 5:51 PM, Mikulas Patocka > <mikulas@xxxxxxxxxxxxxxxxxxxxxxxx> wrote: > > > > Another question is - what would happen with direct access to the block > > device using read or write on nodes in /dev? > > We actually don't support coherent direct block access and filesystem > access. We haven't since the page cache days. Back in *really* early > days, everything was about "struct buffer_head", and things were > coherent because all caches were physically indexed by the location on > disk. > > But ever since the page cache (which has been around forever), > filesystem caching has been virtually indexed, and not coherent with > the physically indexed block device direct access. > > Linus You have to support it because tune2fs does it. If you create an ext2 filesystem with 1kB block size, mount it, and run some command that modifies the superblock on it (for example tune2fs -c 123), you can see on the block trace that the kernel writes only 1kB superblocks. If it were writing full pages, it may destroy data that are placed next to the superblocks --- for example: 1. tune2fs reads a full page with some backup superblock 2. the filesystem writes some file data that are placed next to that superblock 3. tune2fs writes back that full page with the superblock modified, overwriting data stored at step 2 --- that's why direct access to block devices must use buffer cache. grub is another example, it writes bootloader to the sector 0. If it were doing full-page read, modify, full-page write, it can destroy file data stored in sectors 1-7. Mikulas -- To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html