Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ebd9d5b

Browse files
committed
Patch #1180695: Implement nanosecond stat resolution on FreeBSD,
add st_gen, st_birthtime.
1 parent 147fbe5 commit ebd9d5b

6 files changed

Lines changed: 373 additions & 1 deletion

File tree

Doc/lib/libos.tex

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -996,6 +996,12 @@ \subsection{Files and Directories \label{os-file-dir}}
996996
\member{st_rdev} (type of device if an inode device).
997997
\member{st_flags} (user defined flags for file).
998998

999+
On other Unix systems (such as FreeBSD), the following attributes
1000+
may be available (but may be only filled out of root tries to
1001+
use them:
1002+
\member{st_gen} (file generation number),
1003+
\member{st_birthtime} (time of file creation).
1004+
9991005
On Mac OS systems, the following attributes may also be available:
10001006
\member{st_rsize},
10011007
\member{st_creator},
@@ -1037,6 +1043,7 @@ \subsection{Files and Directories \label{os-file-dir}}
10371043

10381044
\versionchanged
10391045
[Added access to values as attributes of the returned object]{2.2}
1046+
\versionchanged[Added st_gen, st_birthtime]{2.5}
10401047
\end{funcdesc}
10411048

10421049
\begin{funcdesc}{stat_float_times}{\optional{newvalue}}

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ Core and builtins
121121
Extension Modules
122122
-----------------
123123

124+
- Patch #1180695: Add nanosecond stat resolution, and st_gen,
125+
st_birthtime for FreeBSD.
126+
124127
- Patch #1231069: The fcntl.ioctl function now uses the 'I' code for
125128
the request code argument, which results in more C-like behaviour
126129
for large or negative values.

Modules/posixmodule.c

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,12 @@ static PyStructSequence_Field stat_result_fields[] = {
705705
#endif
706706
#ifdef HAVE_STRUCT_STAT_ST_FLAGS
707707
{"st_flags", "user defined flags for file"},
708+
#endif
709+
#ifdef HAVE_STRUCT_STAT_ST_GEN
710+
{"st_gen", "generation number"},
711+
#endif
712+
#ifdef HAVE_STRUCT_STAT_ST_BIRTHTIME
713+
{"st_birthtime", "time of creation"},
708714
#endif
709715
{0}
710716
};
@@ -733,6 +739,18 @@ static PyStructSequence_Field stat_result_fields[] = {
733739
#define ST_FLAGS_IDX ST_RDEV_IDX
734740
#endif
735741

742+
#ifdef HAVE_STRUCT_STAT_ST_GEN
743+
#define ST_GEN_IDX (ST_RDEV_IDX+1)
744+
#else
745+
#define ST_GEN_IDX ST_RDEV_IDX
746+
#endif
747+
748+
#ifdef HAVE_STRUCT_STAT_ST_BIRTHTIME
749+
#define ST_BIRTHTIME_IDX (ST_GEN_IDX+1)
750+
#else
751+
#define ST_BIRTHTIME_IDX ST_GEN_IDX
752+
#endif
753+
736754
static PyStructSequence_Desc stat_result_desc = {
737755
"stat_result", /* name */
738756
stat_result__doc__, /* doc */
@@ -877,8 +895,14 @@ _pystat_fromstructstat(STRUCT_STAT st)
877895
ansec = st.st_atim.tv_nsec;
878896
mnsec = st.st_mtim.tv_nsec;
879897
cnsec = st.st_ctim.tv_nsec;
898+
#else
899+
#ifdef HAVE_STAT_TV_NSEC2
900+
ansec = st.st_atimespec.tv_nsec;
901+
mnsec = st.st_mtimespec.tv_nsec;
902+
cnsec = st.st_ctimespec.tv_nsec;
880903
#else
881904
ansec = mnsec = cnsec = 0;
905+
#endif
882906
#endif
883907
fill_time(v, 7, st.st_atime, ansec);
884908
fill_time(v, 8, st.st_mtime, mnsec);
@@ -896,6 +920,29 @@ _pystat_fromstructstat(STRUCT_STAT st)
896920
PyStructSequence_SET_ITEM(v, ST_RDEV_IDX,
897921
PyInt_FromLong((long)st.st_rdev));
898922
#endif
923+
#ifdef HAVE_STRUCT_STAT_ST_GEN
924+
PyStructSequence_SET_ITEM(v, ST_GEN_IDX,
925+
PyInt_FromLong((long)st.st_gen));
926+
#endif
927+
#ifdef HAVE_STRUCT_STAT_ST_BIRTHTIME
928+
{
929+
PyObject *val;
930+
unsigned long bsec,bnsec;
931+
bsec = (long)st.st_birthtime;
932+
#ifdef HAVE_STAT_TV_NSEC2
933+
bnsec = st.st_birthtimespec.tv_nsec;
934+
#else
935+
bnsec = 0;
936+
#endif
937+
if (_stat_float_times) {
938+
val = PyFloat_FromDouble(bsec + 1e-9*bnsec);
939+
} else {
940+
val = PyInt_FromLong((long)bsec);
941+
}
942+
PyStructSequence_SET_ITEM(v, ST_BIRTHTIME_IDX,
943+
val);
944+
}
945+
#endif
899946
#ifdef HAVE_STRUCT_STAT_ST_FLAGS
900947
PyStructSequence_SET_ITEM(v, ST_FLAGS_IDX,
901948
PyInt_FromLong((long)st.st_flags));

0 commit comments

Comments
 (0)