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.
This commit is contained in:
Adrien Destugues 2015-10-11 18:26:21 +02:00
parent 1084b509b3
commit 1388211503
2 changed files with 7 additions and 27 deletions

View File

@ -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;

View File

@ -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;