Created
June 29, 2016 14:07
-
-
Save beekhof/603ac719e18ecd8b48501eddbc6e312a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from ctypes import * | |
class struct_timespec(Structure): | |
_fields_ = [('tv_sec', c_long), ('tv_nsec', c_long)] | |
class struct_stat64(Structure): | |
_fields_ = [ | |
('st_dev', c_int32), | |
('st_mode', c_uint16), | |
('st_nlink', c_uint16), | |
('st_ino', c_uint64), | |
('st_uid', c_uint32), | |
('st_gid', c_uint32), | |
('st_rdev', c_int32), | |
('st_atimespec', struct_timespec), | |
('st_mtimespec', struct_timespec), | |
('st_ctimespec', struct_timespec), | |
('st_birthtimespec', struct_timespec), | |
('st_size', c_uint64), | |
('st_blocks', c_uint64), | |
('st_blksize', c_uint32), | |
('st_flags', c_uint32), | |
('st_gen', c_uint32), | |
('st_lspare', c_uint32), | |
('st_qspare', c_uint64 * 2) | |
] | |
libc = CDLL('/usr/lib/libc.dylib') # or /usr/lib/libc.dylib | |
stat64 = libc.stat64 | |
stat64.argtypes = [c_char_p, POINTER(struct_stat64)] | |
def get_generation(path): | |
buf = struct_stat64() | |
rv = stat64(path, pointer(buf)) | |
if rv != 0: | |
raise OSError("Couldn't stat file %r" % path) | |
return buf.st_gen | |
print get_generation('test.txt') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment