4

I've skimmed through the Linux Kernel Module Programming guide, but can't figure out:

When I say cat image.iso > /dev/sda, will it cause the write function of file_operations structure to be executed by the sda device driver? Or is the file interface not applied to block device nodes?

Where do I find that function's implementation? (the respective driver within the Linux code tree)?

Boris Burkov
  • 13,420
  • 17
  • 74
  • 109
  • 3
    You can see the system calls a command use with the `strace` utility. Eg. `strace cat image.iso > /dev/sda`. Is that the kind of information you need ? – lgeorget May 21 '13 at 23:24
  • 7
    @lgeorget jftr you don't see all the information because the redirect is happening before strace is called, so it should probably be something like `strace -f sh -c 'cat image.iso > /dev/sda'` – Ulrich Dangel May 21 '13 at 23:45
  • @Igeorget, @Ulrich Dangel Thanks a lot guys! So, file_operations is just a subset of the system calls, which I completely overlooked :(. E.g. if I've typed `cat image.iso > myfile` and `myfile` belonged to ext3 filesystem, the do_sync_write would've been called from here: http://lxr.free-electrons.com/source/fs/ext3/file.c? – Boris Burkov May 21 '13 at 23:55

1 Answers1

0

fs/block-dev.c defines file operations and address space operations as applicable to block devices.

static const struct address_space_operations def_blk_aops = {
    .readpage       = blkdev_readpage,
    .writepage      = blkdev_writepage,
    .write_begin    = blkdev_write_begin,
    .write_end      = blkdev_write_end,
    .writepages     = generic_writepages,
    .releasepage    = blkdev_releasepage,
    .direct_IO      = blkdev_direct_IO,
    .is_dirty_writeback = buffer_check_dirty_writeback,
};

const struct file_operations def_blk_fops = {
    .open           = blkdev_open,
    .release        = blkdev_close,
    .llseek         = block_llseek,
    .read           = do_sync_read,
    .write          = do_sync_write,
    .aio_read       = blkdev_aio_read,
    .aio_write      = blkdev_aio_write,
    .mmap           = generic_file_mmap,
    .fsync          = blkdev_fsync,
    .unlocked_ioctl = block_ioctl,
#ifdef CONFIG_COMPAT
    .compat_ioctl   = compat_blkdev_ioctl,
#endif
    .splice_read    = generic_file_splice_read,
    .splice_write   = generic_file_splice_write,
};