Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
333 views
in Technique[技术] by (71.8m points)

python - Is there a way to get a meaningful mount point for st_dev on MacOS?

Note this is a MacOS question not a Linux Question - They are different operating systems

I'd like to get a meaningful mount point out of python's os.stat("foo").st_dev. At the moment this is just a number and I can't find anywhere to cross reference it.

All my searches so far have come up with answers that work on Linux by interrogating /proc/... but /proc doesn't exist in MacOS so any such answer will not work.

question from:https://stackoverflow.com/questions/65873319/is-there-a-way-to-get-a-meaningful-mount-point-for-st-dev-on-macos

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I'm a Linux guy, but if I were not allowed to use /proc, I would search the /dev directory for an entry (i.e. filename) which has following stat data:

  • st_mode indicates that it is a block device (helper: stat.S_ISBLK)
  • st_rdev matches the given st_dev value

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...