*参照元 [#k17aa1f4] #backlinks *説明 [#d8e3276d] -パス: [[linux-2.6.33/fs/read_write.c]] -FIXME: これは何? --説明 **引数 [#ufe97c70] -struct file *file -- --[[linux-2.6.33/file]] -char __user *buf -- -size_t count -- -loff_t *pos -- **返り値 [#e47c2c45] -ssize_t -- **参考 [#r6ff4572] -file_operations::read に対して、 独自の read 関数を設定しているファイルシステムと、 何も設定しない NULL のまま(=デフォルトの関数が呼ばれる) ファイルシステムがある。 --調査データの詳細は 「file_operations::read メンバに指定される関数ポインタの調査データ」 の章を参照 -特殊パターン .read = do_sync_read, fs/9p/vfs_file.c:279: .read = v9fs_file_read, fs/9p/vfs_file.c:291: -v9fs(Plan9 のファイルシステム) --キャッシュ有効だと、 v9fs_cached_file_operations が選択されるため、 read メンバには do_sync_read が設定される。 --キャッシュ無効だと、 v9fs_file_operations が選択されるため、 read メンバには v9fs_file_read が設定される。 ---[[linux-2.6.33/v9fs_file_open()]] .read = do_sync_read, fs/fuse/file.c:1979: .read = fuse_direct_read, fs/fuse/file.c:1998: -FUSE(Filesystem in Userspace, ユーザ空間にファイルシステムを 構築するフレームワーク) --だと、 --(FIXME: 条件がよくわからない)だと、 fuse_file_operations が選択されるため、 read メンバには do_sync_read が設定される。 --だと、 --(FIXME: 条件がよくわからない)だと、 fuse_direct_io_file_operations が選択されるため、 read メンバには fuse_direct_read が設定される。 ---ファイルの open 時に、 fuse_open -> fuse_open_common -> fuse_finish_open の順で呼ばれる。 ---[[linux-2.6.33/fuse_finish_open()]] -独自に設定しているが、標準と同じ関数を設定する(do_sync_read) ファイルシステム一覧 .read = do_sync_read, fs/adfs/file.c:26: .read = do_sync_read, fs/affs/file.c:30: .read = do_sync_read, fs/afs/file.c:33: .read = do_sync_read, fs/bfs/file.c:26: .read = do_sync_read, fs/btrfs/file.c:1155: .read = do_sync_read, fs/ecryptfs/file.c:312: .read = do_sync_read, fs/exofs/file.c:76: .read = do_sync_read, fs/ext2/file.c:64: .read = do_sync_read, fs/ext3/file.c:56: .read = do_sync_read, fs/ext4/file.c:135: .read = do_sync_read, fs/fat/file.c:156: .read = do_sync_read, fs/gfs2/file.c:745: .read = do_sync_read, fs/gfs2/file.c:775: .read = do_sync_read, fs/hpfs/file.c:134: .read = do_sync_read, fs/jffs2/file.c:45: .read = do_sync_read, fs/jfs/file.c:107: .read = do_sync_read, fs/minix/file.c:17: .read = do_sync_read, fs/nfs/file.c:66: .read = do_sync_read, fs/nilfs2/file.c:139: .read = do_sync_read, fs/ntfs/file.c:2207: .read = do_sync_read, fs/ocfs2/file.c:2282: .read = do_sync_read, fs/ocfs2/file.c:2329: .read = do_sync_read, fs/omfs/file.c:327: .read = do_sync_read, fs/reiserfs/file.c:285: .read = do_sync_read, fs/smbfs/file.c:437: .read = do_sync_read, fs/sysv/file.c:24: .read = do_sync_read, fs/ubifs/file.c:1573: .read = do_sync_read, fs/udf/file.c:207: .read = do_sync_read, fs/ufs/file.c:38: .read = do_sync_read, fs/xfs/linux-2.6/xfs_file.c:245: -独自に設定しているファイルシステム一覧 .read = configfs_read_file, fs/configfs/file.c:309: .read = sysfs_read_file, fs/sysfs/file.c:492: *実装 [#p0c75314] ssize_t vfs_read(struct file *file, char __user *buf, size_t count, loff_t *pos) { ssize_t ret; if (!(file->f_mode & FMODE_READ)) return -EBADF; if (!file->f_op || (!file->f_op->read && !file->f_op->aio_read)) return -EINVAL; if (unlikely(!access_ok(VERIFY_WRITE, buf, count))) return -EFAULT; -file->f_op は file_operations 型 --[[linux-2.6.33/file_operations]] - --[[linux-2.6.33/access_ok()]] ret = rw_verify_area(READ, file, pos, count); - --[[linux-2.6.33/rw_verify_area()]] if (ret >= 0) { count = ret; if (file->f_op->read) ret = file->f_op->read(file, buf, count, pos); else ret = do_sync_read(file, buf, count, pos); -file_operations::read に関数が設定されていたら、それを呼ぶ。 --ファイルシステムにより file_operations::read に設定される関数が異なる。 「参考」の章を参照のこと。 --ネットワークファイルシステムを除いて、 大抵のファイルシステムでは do_sync_read を設定しているようだ。 --[[linux-2.6.33/do_sync_read()]] if (ret > 0) { fsnotify_access(file->f_path.dentry); add_rchar(current, ret); } - --[[linux-2.6.33/fsnotify_access()]] - --[[linux-2.6.33/add_rchar()]] inc_syscr(current); - --[[linux-2.6.33/inc_syscr()]] } return ret; } EXPORT_SYMBOL(vfs_read); -特にライセンスを区別せずシンボルを公開する。 --[[linux-2.6.33/EXPORT_SYMBOL()]] *file_operations::read メンバに指定される関数ポインタの調査データ [#n474b096] -コマンド egrep -nr '(struct file_operations|\.read\s+=.+,)' fs | grep file.c > result -結果 fs/9p/vfs_file.c :46:static const struct file_operations v9fs_cached_file_operations; fs/9p/vfs_file.c :277:static const struct file_operations v9fs_cached_file_operations = { fs/9p/vfs_file.c :279: .read = do_sync_read, fs/9p/vfs_file.c :289:const struct file_operations v9fs_file_operations = { fs/9p/vfs_file.c :291: .read = v9fs_file_read, fs/adfs/file.c :24:const struct file_operations adfs_file_operations = { fs/adfs/file.c :26: .read = do_sync_read, fs/affs/file.c :28:const struct file_operations affs_file_operations = { fs/affs/file.c :30: .read = do_sync_read, fs/afs/file.c :29:const struct file_operations afs_file_operations = { fs/afs/file.c :33: .read = do_sync_read, fs/bfs/file.c :24:const struct file_operations bfs_file_operations = { fs/bfs/file.c :26: .read = do_sync_read, fs/btrfs/file.c :1153:const struct file_operations btrfs_file_operations = { fs/btrfs/file.c :1155: .read = do_sync_read, fs/coda/file.c :229:const struct file_operations coda_file_operations = { fs/configfs/file.c :308:const struct file_operations configfs_file_operations = { fs/configfs/file.c :309: .read = configfs_read_file, fs/debugfs/file.c :42:const struct file_operations debugfs_file_operations = { fs/debugfs/file.c :434:static const struct file_operations fops_bool = { fs/debugfs/file.c :479:static const struct file_operations fops_blob = { fs/ecryptfs/file.c :299:const struct file_operations ecryptfs_dir_fops = { fs/ecryptfs/file.c :310:const struct file_operations ecryptfs_main_fops = { fs/ecryptfs/file.c :312: .read = do_sync_read, fs/exofs/file.c :74:const struct file_operations exofs_file_operations = { fs/exofs/file.c :76: .read = do_sync_read, fs/ext2/file.c :62:const struct file_operations ext2_file_operations = { fs/ext2/file.c :64: .read = do_sync_read, fs/ext2/file.c :81:const struct file_operations ext2_xip_file_operations = { fs/ext3/file.c :54:const struct file_operations ext3_file_operations = { fs/ext3/file.c :56: .read = do_sync_read, fs/ext4/file.c :133:const struct file_operations ext4_file_operations = { fs/ext4/file.c :135: .read = do_sync_read, fs/fat/file.c :154:const struct file_operations fat_file_operations = { fs/fat/file.c :156: .read = do_sync_read, fs/fuse/file.c :17:static const struct file_operations fuse_direct_io_file_operations; fs/fuse/file.c :1977:static const struct file_operations fuse_file_operations = { fs/fuse/file.c :1979: .read = do_sync_read, fs/fuse/file.c :1996:static const struct file_operations fuse_direct_io_file_operations = { fs/fuse/file.c :1998: .read = fuse_direct_read, fs/gfs2/file.c :743:const struct file_operations gfs2_file_fops = { fs/gfs2/file.c :745: .read = do_sync_read, fs/gfs2/file.c :761:const struct file_operations gfs2_dir_fops = { fs/gfs2/file.c :773:const struct file_operations gfs2_file_fops_nolock = { fs/gfs2/file.c :775: .read = do_sync_read, fs/gfs2/file.c :789:const struct file_operations gfs2_dir_fops_nolock = { fs/hpfs/file.c :131:const struct file_operations hpfs_file_ops = fs/hpfs/file.c :134: .read = do_sync_read, fs/jffs2/file.c :41:const struct file_operations jffs2_file_operations = fs/jffs2/file.c :45: .read = do_sync_read, fs/jfs/file.c :103:const struct file_operations jfs_file_operations = { fs/jfs/file.c :107: .read = do_sync_read, fs/minix/file.c :15:const struct file_operations minix_file_operations = { fs/minix/file.c :17: .read = do_sync_read, fs/ncpfs/file.c :294:const struct file_operations ncp_file_operations = fs/nfs/file.c :64:const struct file_operations nfs_file_operations = { fs/nfs/file.c :66: .read = do_sync_read, fs/nilfs2/file.c :137:const struct file_operations nilfs_file_operations = { fs/nilfs2/file.c :139: .read = do_sync_read, fs/ntfs/file.c :2205:const struct file_operations ntfs_file_ops = { fs/ntfs/file.c :2207: .read = do_sync_read, /* Read from file. */ fs/ntfs/file.c :2246:const struct file_operations ntfs_empty_file_ops = {}; fs/ocfs2/file.c :2280:const struct file_operations ocfs2_fops = { fs/ocfs2/file.c :2282: .read = do_sync_read, fs/ocfs2/file.c :2300:const struct file_operations ocfs2_dops = { fs/ocfs2/file.c :2327:const struct file_operations ocfs2_fops_no_plocks = { fs/ocfs2/file.c :2329: .read = do_sync_read, fs/ocfs2/file.c :2346:const struct file_operations ocfs2_dops_no_plocks = { fs/omfs/file.c :325:const struct file_operations omfs_file_operations = { fs/omfs/file.c :327: .read = do_sync_read, fs/reiserfs/file.c :284:const struct file_operations reiserfs_file_operations = { fs/reiserfs/file.c :285: .read = do_sync_read, fs/smbfs/file.c :434:const struct file_operations smb_file_operations = fs/smbfs/file.c :437: .read = do_sync_read, fs/sysfs/file.c :491:const struct file_operations sysfs_file_operations = { fs/sysfs/file.c :492: .read = sysfs_read_file, fs/sysv/file.c :22:const struct file_operations sysv_file_operations = { fs/sysv/file.c :24: .read = do_sync_read, fs/ubifs/file.c :1571:const struct file_operations ubifs_file_operations = { fs/ubifs/file.c :1573: .read = do_sync_read, fs/udf/file.c :206:const struct file_operations udf_file_operations = { fs/udf/file.c :207: .read = do_sync_read, fs/ufs/file.c :36:const struct file_operations ufs_file_operations = { fs/ufs/file.c :38: .read = do_sync_read, fs/xfs/linux-2.6/xfs_file.c:243:const struct file_operations xfs_file_operations = { fs/xfs/linux-2.6/xfs_file.c:245: .read = do_sync_read, fs/xfs/linux-2.6/xfs_file.c:264:const struct file_operations xfs_dir_file_operations = { *コメント [#w59631ab]