[HN Gopher] A statx(2) Linux system Python wrapper
       ___________________________________________________________________
        
       A statx(2) Linux system Python wrapper
        
       Author : chriskaneen
       Score  : 23 points
       Date   : 2021-03-29 16:45 UTC (6 hours ago)
        
 (HTM) web link (github.com)
 (TXT) w3m dump (github.com)
        
       | chriskaneen wrote:
       | At my previous job, I needed to access the birth time attribute
       | of a file on Linux. If I am not mistaken, the standard library
       | doesn't support getting it on Linux (st_birthtime - time of file
       | creation is supported on other unix systems, such as freebsd,
       | see: https://docs.python.org/2/library/os.html#os.stat). So, I
       | created this wrapper for getting the file status (birth time,
       | etc.) using the statx(2) linux system call.
        
         | cmeacham98 wrote:
         | Why not use the statx wrapper in glibc, seeing as you already
         | seem to be using the syscall wrapper via
         | ctypes.CDLL(None).syscall?
         | 
         | Possible self-answer: that wrapper only exists on glibc >=
         | 2.28.
        
           | LukeShu wrote:
           | For reference for other readers:
           | 
           | The statx(2) system call was added in Linux 4.11, released on
           | 2017-04-30.
           | 
           | The statx(3) libc wrapper was added in GNU libc 2.28,
           | released on 2018-08-01.
        
       | ddevault wrote:
       | I don't really understand what this is doing here. It definitely
       | does not pique the hacker interest. This is just a simple syscall
       | wrapper. The most interesting thing about it is that it somehow
       | got upvoted 14 times.
       | 
       | Maybe it's just general ignorance of the statx syscall's
       | existence or utility on Linux?
       | 
       | https://man7.org/linux/man-pages/man2/statx.2.html
       | 
       | It's just stat but it accepts a mask for what info you want and
       | returns a couple of extra fields.
        
       | tyingq wrote:
       | Neat, though the if/then tree to get the syscall number is a bit
       | clunky and only works on x86, x64, and ARM. I get that options
       | are limited, but it might be nice to make that list more
       | complete.
        
       | andy_threos_io wrote:
       | There are other more portable way to do OS wrapper, and maybe
       | faster (but it's not an issue).
       | 
       | Just write the wrapper as a C extension module, and in the module
       | make the system call with proper library call.
       | 
       | like in the following code:
       | 
       | https://github.com/torvalds/linux/blob/master/samples/vfs/te...
       | 
       | This way it will be portable!
       | 
       | A couple of weeks ago, I just made for our OS's system calls.
       | It's only a first draft, but works fine.
       | 
       | You could also parse the C header for constant values.
       | 
       | (Actually, I wrote a python script to generate the C extension
       | for the system calls also, not just for the constants)
        
       | jwilk wrote:
       | No test suite. Also no error handling.
       | 
       | I think it's a bit too early to show this to HN...
        
       ___________________________________________________________________
       (page generated 2021-03-29 23:03 UTC)