Project

General

Profile

Actions

Submit #3272

closed

fstat: Show offset for device files too.

Added by falsifian over 3 years ago. Updated over 3 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Userland
Target version:
Start date:
05/11/2021
Due date:
% Done:

100%

Estimated time:

Description

This patch changes fstat to print, e.g, "da0:42" instead of just "da0"
if a process has /dev/da0 open at offset 42.

Tested minimally: I just wrote wrote a program that seeks to offset 42,
then ran fstat on it. Output:

root@copter-dfly:/usr/src/usr.bin/fstat # ./fstat p6527
USER CMD PID FD PATH INUM MODE SZ|DV R/W
root f 6527 root / 1 drwxr-xr-x 0 r
root f 6527 wd /home/falsifian/tmp 23445 drwx-----
0 r
root f 6527 text /home/falsifian/tmp/f 301743 rwxr-xr-x 0 r
root f 6527 0 /dev/pts/3 1402 crw------
pts/3:13384 rw
root f 6527 1 /dev/pts/3 1402 crw------- pts/3:13384 rw
root f 6527 2 /dev/pts/3 1402 crw------- pts/3:13384 rw
root f 6527 3 /dev/da0 1361 crw-r----- da0:42 r

(I wanted this when I first installed DragonflyBSD yesterday. I was
trying to figure out why newfs_hammer2 was stuck, and this might have
helped me narrow down the possibilities by checking whether the offset
was changing very slowly vs. not at all.)

Some notes / questions:

- fst.offset generally seems to come from the f_offset field of a
struct file. I am not familiar with that struct. It would be good if
someone who knows more could confirm my assumption that f_offset is
at least never going to be uninitialized garbage.

- For regular files, it looks like the size is no longer printed at all
since commit afdbde1b changed it to offset. Was that intentional? At
least the man page should be updated. (I'm happy to give that a try.)

- Should the indentation fix have been a separate commit? (For future
reference, at least.) I'm normally pretty pedantic about separating
commits, but didn't want to annoy anyone.


Files

Actions

Also available in: Atom PDF