| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2897,6 +2897,12 @@ features: | |||
| 2897 | 2897 | Type of device (combined major and minor number) if the queried file | |
| 2898 | 2898 | was an inode device. | |
| 2899 | 2899 | ||
| 2900 | + .. attribute:: st_mnt_id | ||
| 2901 | + | ||
| 2902 | + Mount ID of the mountpoint the queried file resides on. Information on | ||
| 2903 | + the associated filesystem may be found by analysing | ||
| 2904 | + */proc/self/mountinfo*. | ||
| 2905 | + | ||
| 2900 | 2906 | On other Unix systems (such as FreeBSD), the following attributes may be | |
| 2901 | 2907 | available (but may be only filled out if root tries to use them): | |
| 2902 | 2908 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -447,5 +447,7 @@ meaning of these constants. | |||
| 447 | 447 | STATX_ATTR_APPEND | |
| 448 | 448 | STATX_ATTR_NODUMP | |
| 449 | 449 | STATX_ATTR_ENCRYPTED | |
| 450 | + STATX_ATTR_VERITY | ||
| 451 | + STATX_ATTR_DAX | ||
| 450 | 452 | ||
| 451 | 453 | .. versionadded:: 3.12 | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -206,6 +206,8 @@ def filemode(mode): | |||
| 206 | 206 | STATX_ATTR_APPEND = 0x0020 | |
| 207 | 207 | STATX_ATTR_NODUMP = 0x0040 | |
| 208 | 208 | STATX_ATTR_ENCRYPTED = 0x0800 | |
| 209 | + STATX_ATTR_VERITY = 0x100000 | ||
| 210 | + STATX_ATTR_DAX = 0x200000 | ||
| 209 | 211 | ||
| 210 | 212 | ||
| 211 | 213 | # If available, use C implementation | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -664,6 +664,8 @@ stat_exec(PyObject *module) | |||
| 664 | 664 | ADD_INT_MACRO(module, STATX_ATTR_APPEND); | |
| 665 | 665 | ADD_INT_MACRO(module, STATX_ATTR_NODUMP); | |
| 666 | 666 | ADD_INT_MACRO(module, STATX_ATTR_ENCRYPTED); | |
| 667 | + ADD_INT_MACRO(module, STATX_ATTR_VERITY); | ||
| 668 | + ADD_INT_MACRO(module, STATX_ATTR_DAX); | ||
| 667 | 669 | #endif /* HAVE_LINUX_STATX */ | |
| 668 | 670 | ||
| 669 | 671 | return 0; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2076,8 +2076,14 @@ win32_stat(const wchar_t* path, struct _Py_stat_struct *result) | |||
| 2076 | 2076 | ||
| 2077 | 2077 | #ifdef HAVE_LINUX_STATX | |
| 2078 | 2078 | ||
| 2079 | + #ifdef STATX_MNT_ID // Added in Linux 5.8 | ||
| 2080 | + # define _PY_STATX_MNT_ID STATX_MNT_ID | ||
| 2081 | + #else | ||
| 2082 | + # define _PY_STATX_MNT_ID 0x00001000U | ||
| 2083 | + #endif | ||
| 2084 | + | ||
| 2079 | 2085 | // Extend this list when adding support for new Linux statx fields | |
| 2080 | - #define LINUX_STATX_MASK STATX_BASIC_STATS | STATX_BTIME | ||
| 2086 | + #define LINUX_STATX_MASK STATX_BASIC_STATS | STATX_BTIME | _PY_STATX_MNT_ID | ||
| 2081 | 2087 | ||
| 2082 | 2088 | static int | |
| 2083 | 2089 | linux_stat(const char* path, struct statx* result) | |
@@ -2165,6 +2171,7 @@ static PyStructSequence_Field stat_result_fields[] = { | |||
| 2165 | 2171 | #ifdef HAVE_LINUX_STATX | |
| 2166 | 2172 | {"st_attributes", "Linux file attribute bits"}, | |
| 2167 | 2173 | {"st_attributes_mask", "Linux supported file attribute bits on this filesystem"}, | |
| 2174 | + {"st_mnt_id", "Linux mount ID of the mount containing the file"}, | ||
| 2168 | 2175 | #endif | |
| 2169 | 2176 | {0} | |
| 2170 | 2177 | }; | |
@@ -2220,9 +2227,11 @@ static PyStructSequence_Field stat_result_fields[] = { | |||
| 2220 | 2227 | #ifdef HAVE_LINUX_STATX | |
| 2221 | 2228 | #define ST_ATTRIBUTES_IDX (ST_REPARSE_TAG_IDX+1) | |
| 2222 | 2229 | #define ST_ATTRIBUTES_MASK_IDX (ST_REPARSE_TAG_IDX+2) | |
| 2230 | + #define ST_MNT_ID_IDX (ST_REPARSE_TAG_IDX+3) | ||
| 2223 | 2231 | #else | |
| 2224 | 2232 | #define ST_ATTRIBUTES_IDX ST_REPARSE_TAG_IDX | |
| 2225 | 2233 | #define ST_ATTRIBUTES_MASK_IDX ST_REPARSE_TAG_IDX | |
| 2234 | + #define ST_MNT_ID_IDX ST_REPARSE_TAG_IDX | ||
| 2226 | 2235 | #endif | |
| 2227 | 2236 | ||
| 2228 | 2237 | static PyStructSequence_Desc stat_result_desc = { | |
@@ -2464,8 +2473,10 @@ _pystat_fromstructstat(PyObject *module, struct statx* stx) | |||
| 2464 | 2473 | ||
| 2465 | 2474 | // Map statx flags to BSD flags | |
| 2466 | 2475 | // | |
| 2467 | - // The contants used here are not defined on Linux, are available to | ||
| 2468 | - // Python users through the "stat" module. | ||
| 2476 | + // The constants used here are not defined on Linux but are available to | ||
| 2477 | + // Python users through the "stat" module. In general, try to follow | ||
| 2478 | + // FreeBSD semantics when adding a mapping here and refrain from mapping | ||
| 2479 | + // attributes that don't have an obvious equivalent. | ||
| 2469 | 2480 | flags = 0; | |
| 2470 | 2481 | if(attributes & STATX_ATTR_COMPRESSED) { | |
| 2471 | 2482 | flags |= 0x00000020; // UF_COMPRESSED | |
@@ -2482,6 +2493,17 @@ _pystat_fromstructstat(PyObject *module, struct statx* stx) | |||
| 2482 | 2493 | if(attributes & STATX_ATTR_ENCRYPTED) { | |
| 2483 | 2494 | flags |= 0x00002000; // UF_ENCRYPTED | |
| 2484 | 2495 | } | |
| 2496 | + // Note: There is nothing in the FreeBSD disk flags list resembling | ||
| 2497 | + // `STATX_ATTR_VERITY` or `STATX_ATTR_DAX`, so leave these unmapped. | ||
| 2498 | + // | ||
| 2499 | + // In addition (as of Linux 5.19), `STATX_ATTR_DAX` does not ever appear | ||
| 2500 | + // to be reported when querying on-disk files that previously had the | ||
| 2501 | + // corresponding "x" flag set using `chattr(1)`, so even if FreeBSD adds | ||
| 2502 | + // a corresponding flag mapping it would likely be of little use. | ||
| 2503 | + // | ||
| 2504 | + // If these flags ever need to be mapped, remember to add a compatibility | ||
| 2505 | + // define for them next to the definition of `LINUX_STATX_MASK`, to ensure | ||
| 2506 | + // builds will continue working on older C library versions. | ||
| 2485 | 2507 | PyStructSequence_SET_ITEM(v, 18, PyLong_FromLong(flags)); | |
| 2486 | 2508 | ||
| 2487 | 2509 | PyStructSequence_SET_ITEM(v, ST_BLKSIZE_IDX, | |
@@ -2494,6 +2516,23 @@ _pystat_fromstructstat(PyObject *module, struct statx* stx) | |||
| 2494 | 2516 | PyStructSequence_SET_ITEM(v, ST_RDEV_IDX, | |
| 2495 | 2517 | _PyLong_FromDev(makedev(stx->stx_rdev_major, stx->stx_rdev_minor))); | |
| 2496 | 2518 | ||
| 2519 | + if(stx->stx_mask & _PY_STATX_MNT_ID) { | ||
| 2520 | + PyStructSequence_SET_ITEM(v, ST_MNT_ID_IDX, PyLong_FromUnsignedLongLong( | ||
| 2521 | + #ifdef STATX_MNT_ID | ||
| 2522 | + stx->stx_mnt_id | ||
| 2523 | + #else | ||
| 2524 | + // `stx_mnt_id` is the next 64-bit field following `stx_dev_minor` | ||
| 2525 | + // | ||
| 2526 | + // It is safe to assume its going to be there even if the C library | ||
| 2527 | + // does not support it yet, since the size of `struct statx` is | ||
| 2528 | + // constant and value presence is only indicated by the kernel in | ||
| 2529 | + // the `stx_mask` field queried above if the field is actually | ||
| 2530 | + // supported and was set. | ||
| 2531 | + *((unsigned long long *) ((&stx->stx_dev_minor) + 1)) | ||
| 2532 | + #endif /* STATX_MNT_ID */ | ||
| 2533 | + )); | ||
| 2534 | + } | ||
| 2535 | + | ||
| 2497 | 2536 | if (PyErr_Occurred()) { | |
| 2498 | 2537 | Py_DECREF(v); | |
| 2499 | 2538 | return NULL; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments