From 1388211503e3d8c805a6a9b026a44ff093f71312 Mon Sep 17 00:00:00 2001 From: Adrien Destugues Date: Sun, 11 Oct 2015 18:26:21 +0200 Subject: [PATCH] Implement stat.st_rdev for block and character devices. * devfs: set st_rdev to the inode number of the node being queried. This may not be the best thing to do, as it does not match what is set in st_dev for other files, so it can't be used to find which device stores a particular file. I'm not sure if st_rdev is actually used that way anywhere, however. * vfs: do not clobber st_rdev with -1 for "special" (device) files. Refactor the code a little so setting the common attributes is done in a single place. Fixes #12390. --- src/system/kernel/device_manager/devfs.cpp | 1 + src/system/kernel/fs/vfs.cpp | 33 ++++------------------ 2 files changed, 7 insertions(+), 27 deletions(-) diff --git a/src/system/kernel/device_manager/devfs.cpp b/src/system/kernel/device_manager/devfs.cpp index 7876ae3754..9f8c742c89 100644 --- a/src/system/kernel/device_manager/devfs.cpp +++ b/src/system/kernel/device_manager/devfs.cpp @@ -1758,6 +1758,7 @@ devfs_read_stat(fs_volume* _volume, fs_vnode* _vnode, struct stat* stat) stat)); stat->st_ino = vnode->id; + stat->st_rdev = vnode->id; stat->st_size = 0; stat->st_mode = vnode->stream.type; diff --git a/src/system/kernel/fs/vfs.cpp b/src/system/kernel/fs/vfs.cpp index 3cc6483335..2d133b8e36 100644 --- a/src/system/kernel/fs/vfs.cpp +++ b/src/system/kernel/fs/vfs.cpp @@ -4681,7 +4681,9 @@ vfs_stat_vnode(struct vnode* vnode, struct stat* stat) if (status == B_OK) { stat->st_dev = vnode->device; stat->st_ino = vnode->id; - stat->st_rdev = -1; + // the rdev field must stay unset for non-special files + if (!S_ISBLK(stat->st_mode) && !S_ISCHR(stat->st_mode)) + stat->st_rdev = -1; } return status; @@ -4696,14 +4698,7 @@ vfs_stat_node_ref(dev_t device, ino_t inode, struct stat* stat) if (status != B_OK) return status; - status = FS_CALL(vnode, read_stat, stat); - - // fill in the st_dev and st_ino fields - if (status == B_OK) { - stat->st_dev = vnode->device; - stat->st_ino = vnode->id; - stat->st_rdev = -1; - } + status = vfs_stat_vnode(vnode, stat); put_vnode(vnode); return status; @@ -6435,16 +6430,7 @@ common_read_stat(struct file_descriptor* descriptor, struct stat* stat) stat->st_mtim.tv_nsec = 0; stat->st_atim.tv_nsec = 0; - status_t status = FS_CALL(vnode, read_stat, stat); - - // fill in the st_dev and st_ino fields - if (status == B_OK) { - stat->st_dev = vnode->device; - stat->st_ino = vnode->id; - stat->st_rdev = -1; - } - - return status; + return vfs_stat_vnode(vnode, stat); } @@ -6477,14 +6463,7 @@ common_path_read_stat(int fd, char* path, bool traverseLeafLink, if (status != B_OK) return status; - status = FS_CALL(vnode, read_stat, stat); - - // fill in the st_dev and st_ino fields - if (status == B_OK) { - stat->st_dev = vnode->device; - stat->st_ino = vnode->id; - stat->st_rdev = -1; - } + status = vfs_stat_vnode(vnode, stat); put_vnode(vnode); return status;