mercurial/cffi/osutilbuild.py
changeset 32505 05a16c19967e
parent 30346 9cc438bf7d9a
child 32506 2dcb3d52ef41
equal deleted inserted replaced
32504:2ba4d3b74ba8 32505:05a16c19967e
       
     1 from __future__ import absolute_import
       
     2 
       
     3 import cffi
       
     4 
       
     5 ffi = cffi.FFI()
       
     6 ffi.set_source("_osutil_cffi", """
       
     7 #include <sys/attr.h>
       
     8 #include <sys/vnode.h>
       
     9 #include <unistd.h>
       
    10 #include <fcntl.h>
       
    11 #include <time.h>
       
    12 
       
    13 typedef struct val_attrs {
       
    14     uint32_t          length;
       
    15     attribute_set_t   returned;
       
    16     attrreference_t   name_info;
       
    17     fsobj_type_t      obj_type;
       
    18     struct timespec   mtime;
       
    19     uint32_t          accessmask;
       
    20     off_t             datalength;
       
    21 } __attribute__((aligned(4), packed)) val_attrs_t;
       
    22 """, include_dirs=['mercurial'])
       
    23 ffi.cdef('''
       
    24 
       
    25 typedef uint32_t attrgroup_t;
       
    26 
       
    27 typedef struct attrlist {
       
    28     uint16_t     bitmapcount; /* number of attr. bit sets in list */
       
    29     uint16_t   reserved;    /* (to maintain 4-byte alignment) */
       
    30     attrgroup_t commonattr;  /* common attribute group */
       
    31     attrgroup_t volattr;     /* volume attribute group */
       
    32     attrgroup_t dirattr;     /* directory attribute group */
       
    33     attrgroup_t fileattr;    /* file attribute group */
       
    34     attrgroup_t forkattr;    /* fork attribute group */
       
    35     ...;
       
    36 };
       
    37 
       
    38 typedef struct attribute_set {
       
    39     ...;
       
    40 } attribute_set_t;
       
    41 
       
    42 typedef struct attrreference {
       
    43     int attr_dataoffset;
       
    44     int attr_length;
       
    45     ...;
       
    46 } attrreference_t;
       
    47 
       
    48 typedef int ... off_t;
       
    49 
       
    50 typedef struct val_attrs {
       
    51     uint32_t          length;
       
    52     attribute_set_t   returned;
       
    53     attrreference_t   name_info;
       
    54     uint32_t          obj_type;
       
    55     struct timespec   mtime;
       
    56     uint32_t          accessmask;
       
    57     off_t             datalength;
       
    58     ...;
       
    59 } val_attrs_t;
       
    60 
       
    61 /* the exact layout of the above struct will be figured out during build time */
       
    62 
       
    63 typedef int ... time_t;
       
    64 
       
    65 typedef struct timespec {
       
    66     time_t tv_sec;
       
    67     ...;
       
    68 };
       
    69 
       
    70 int getattrlist(const char* path, struct attrlist * attrList, void * attrBuf,
       
    71                 size_t attrBufSize, unsigned int options);
       
    72 
       
    73 int getattrlistbulk(int dirfd, struct attrlist * attrList, void * attrBuf,
       
    74                     size_t attrBufSize, uint64_t options);
       
    75 
       
    76 #define ATTR_BIT_MAP_COUNT ...
       
    77 #define ATTR_CMN_NAME ...
       
    78 #define ATTR_CMN_OBJTYPE ...
       
    79 #define ATTR_CMN_MODTIME ...
       
    80 #define ATTR_CMN_ACCESSMASK ...
       
    81 #define ATTR_CMN_ERROR ...
       
    82 #define ATTR_CMN_RETURNED_ATTRS ...
       
    83 #define ATTR_FILE_DATALENGTH ...
       
    84 
       
    85 #define VREG ...
       
    86 #define VDIR ...
       
    87 #define VLNK ...
       
    88 #define VBLK ...
       
    89 #define VCHR ...
       
    90 #define VFIFO ...
       
    91 #define VSOCK ...
       
    92 
       
    93 #define S_IFMT ...
       
    94 
       
    95 int open(const char *path, int oflag, int perm);
       
    96 int close(int);
       
    97 
       
    98 #define O_RDONLY ...
       
    99 ''')
       
   100 
       
   101 if __name__ == '__main__':
       
   102     ffi.compile()