Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-99726: Adds os.statx function and associated constants#99755

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
zooba wants to merge30 commits intopython:mainfromzooba:gh-99726

Conversation

zooba
Copy link
Member

@zoobazooba commentedNov 24, 2022
edited by bedevere-bot
Loading

@zooba
Copy link
MemberAuthor

zooba commentedNov 25, 2022
edited
Loading

My TODO list:

  • Verify whetherDeviceType values are devices or types
  • Finish converting stdlib uses of stat()
  • Reread documentation and make sure it's up to date
  • Maybe test whether a totally separate struct would be simpler enough to justify non-interchangeable results
  • More tests

Comment on lines 1149 to 1171
case FILE_DEVICE_DISK:
case FILE_DEVICE_DISK_FILE_SYSTEM:
case FILE_DEVICE_VIRTUAL_DISK:
case FILE_DEVICE_DFS:
case FILE_DEVICE_CD_ROM:
case FILE_DEVICE_CD_ROM_FILE_SYSTEM:
case FILE_DEVICE_CONTROLLER:
case FILE_DEVICE_DATALINK:
break;
case FILE_DEVICE_CONSOLE:
case FILE_DEVICE_NULL:
case FILE_DEVICE_KEYBOARD:
case FILE_DEVICE_MODEM:
case FILE_DEVICE_MOUSE:
case FILE_DEVICE_PARALLEL_PORT:
case FILE_DEVICE_PRINTER:
case FILE_DEVICE_SCREEN:
case FILE_DEVICE_SERIAL_PORT:
case FILE_DEVICE_SOUND:
/* \\.\nul */
result->st_mode = (result->st_mode & ~S_IFMT) | _S_IFCHR;
break;
case FILE_DEVICE_NAMED_PIPE:
Copy link
Contributor

@eryksuneryksunNov 28, 2022
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

From my earlier comment, we shouldn't arrive in_Py_stat_basic_info_to_stat() for device types that don't implement a filesystem or aren't mounted by a filesystem. That's because, in my experience,FileBasicInformation (file attributes and timestamps) is only implemented for files and directories in a filesystem.

A filesystem type that mounts a volume will returnFILE_DEVICE_DISK (e.g. sampleFAT32 source code) orFILE_DEVICE_CD_ROM (e.g. sampleCDFS source code).FILE_DEVICE_DFS is the distributed filesystem that combines multiple shares. A RAM disk device can useFILE_DEVICE_VIRTUAL_DISK, like the old RAM disk sample driver did, and the driver could implement a custom filesystem, but nowadays generallyFILE_DEVICE_DISK orFILE_DEVICE_CD_ROM is used for a RAM disk (the ImDisk driver implements both).

FILE_DEVICE_DISK_FILE_SYSTEM,FILE_DEVICE_CD_ROM_FILE_SYSTEM, andFILE_DEVICE_NETWORK_FILE_SYSTEM are the device types for the base filesystem device, e.g. "\\?\GlobalRoot\FAT", "\\?\GlobalRoot\UdfsCdRom", or "\\?\UNC".os.stat() reports the first two as block devices (S_IFBLK), butFILE_DEVICE_NETWORK_FILE_SYSTEM isn't handled at all becauseGetFileType() returnsFILE_TYPE_UNKNOWN. I don't think these low-level devices fit into the POSIX regime ofS_IFCHR vsS_IFBLK, but they're more likeS_IFCHR since reads and writes don't use a fixed block size. It's nearly a moot point since there's no useful reason to care. There isn't much to be done with such devices in user-mode applications.

In principle, the stat info classes could be implemented for the named-pipe filesystem on theFILE_DEVICE_NAMED_PIPE device type, but in my tests NPFS doesn't implementFileStatInformation. I asked whether it's planned to implement stat info classes in NPFS.

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

From my earlier comment, we shouldn't arrive in _Py_stat_basic_info_to_stat() for device types that don't implement a filesystem or aren't mounted by a filesystem.

Ah, that's a very good point (which I missed). There were some tests that stopped failing with my change here though, so clearly something ends up in this path.

My switch basically mirrorsGetFileType, so it should be the same as our existing code.

Other than leading people the wrong way when they read our code, is there anythingwrong with checking all the values? There's already a ton of stuff that doesn't map well into POSIX (all the error codes, for example), and I'd prefer our approximations at least be consistent with themselves, even if they aren't meaningful.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Other than leading people the wrong way when they read our code, is there anything wrong with checking all the values?

For the stat info classes, they could decide to specially handle some devices in the I/O manager, or implement a fallback inGetFileInformationByName(). I wouldn't want a device to be reported as a regular file instead of eitherS_IFCHR orS_IFBLK. It shouldn't be a problem as long as they only support the stat info classes for filesystem files and directories -- not for volume devices, filesystem devices, or controllers. (I don't thinkFILE_DEVICE_DATALINK is used by anything.)

zooba reacted with thumbs up emoji
Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I'll update the cases that should handle devices, though it does seem that the current builds don't return stat information by name for\\?\GlobalRoot\NTFS at least, and it goes through the old function. That could always change though.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

If they do end up supporting all devices for the stat info classes, it should be okay as long as they require thatFileAttributes is set toFILE_ATTRIBUTE_NORMAL for a file that has no other attributes set. That's already required forFileBasicInformation, according to[MS-FSA]. Devices would be distinguished by havingFileAttributes set to 0.

@zoobazooba marked this pull request as ready for reviewNovember 29, 2022 00:05
Copy link
Member

@jaracojaraco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Looks good to me, though I haven't analyzed it in detail. If there's any particular critique you're seeking from me, please let me know.

@zooba
Copy link
MemberAuthor

I'm guessing it picked up everyone whose code had astat in it that I decided to change (a few made more sense to leave alone).

So no specific review requests unless someone has concerns about changing thestat_result struct (I'm basically convinced it's better to modify the existing struct than to create a new one -samestat(statx(), stat()) ought to work).

I'll do a buildbot run, but if anyone has access to a Linux machine withstatx and wants to try it out, I'd also appreciate that. My Ubuntu 22 images have it, but don't seem to behave any different.

@zoobazooba added the 🔨 test-with-buildbotsTest PR w/ buildbots; report in status section labelNov 30, 2022
@bedevere-bot
Copy link

🤖 New build scheduled with the buildbot fleet by@zooba for commitbbcc6ee 🤖

If you want to schedule another build, you need to add the ":hammer: test-with-buildbots" label again.

@bedevere-botbedevere-bot removed the 🔨 test-with-buildbotsTest PR w/ buildbots; report in status section labelNov 30, 2022
@brettcannonbrettcannon removed their request for reviewDecember 9, 2022 23:38
@zooba
Copy link
MemberAuthor

FYI, I've not forgotten about this. I'm waiting to hear back from the Windows team on whether they can fix their new API to provide all the informationstat() wants. If they do, I can simply switch to that API directly rather than adding a new one.

That said, if anyone sees enough value instatx generally, I'm happy to have this merged. We might have to tweak the Windows side of things if they change it, but I'm sure they'll find a non-breaking way to make the change.

@netlify
Copy link

netlifybot commentedDec 15, 2022
edited
Loading

Deploy Preview forpython-cpython-preview ready!

NameLink
🔨 Latest commitcadeecb
🔍 Latest deploy loghttps://app.netlify.com/sites/python-cpython-preview/deploys/639b3ffff08a180008b9bd22
😎 Deploy Previewhttps://deploy-preview-99755--python-cpython-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to yourNetlify site settings.

@gvanrossum
Copy link
Member

I'm leaving this PR, it looks like it's in good hands.

@zooba
Copy link
MemberAuthor

Superseded and now massively conflicted, so I'm just going to close this. Adding statx still seems like a good idea if someone wants to do it.

@zoobazooba closed thisMar 16, 2023
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@clintonroyclintonroyclintonroy left review comments

@eryksuneryksuneryksun left review comments

@jaracojaracojaraco approved these changes

@warsawwarsawAwaiting requested review from warsawwarsaw is a code owner

@vsajipvsajipAwaiting requested review from vsajipvsajip is a code owner

Assignees
No one assigned
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

7 participants
@zooba@bedevere-bot@gvanrossum@jaraco@clintonroy@eryksun@carljm

[8]ページ先頭

©2009-2025 Movatter.jp