def to_bytes(self) -> bytes: return bytes( ffi.buffer( ffi.new('struct fuse_open_in*', { 'flags': self.flags, 'unused': 0, })))
def to_bytes(self) -> bytes: data = self.data + "\0" return bytes( ffi.buffer( ffi.new('struct fuse_getxattr_in*', { 'size': len(data), })))
def from_bytes(cls: t.Type[T], data: bytes) -> T: if len(data) != cls.sizeof(): raise Exception("data length", len(data), "doesn't match actual length of struct ifreq", cls.sizeof()) cffi = ffi.new('struct ifreq*') ffi.memmove(cffi, ffi.from_buffer(data), cls.sizeof()) return cls(cffi=cffi)
def to_bytes(self) -> bytes: return bytes( ffi.buffer( ffi.new('struct fuse_flush_in*', { 'fh': self.fh, 'lock_owner': self.lock_owner, })))
def to_bytes(self) -> bytes: struct = ffi.new('struct siginfo*') struct.si_code = self.code struct.si_pid = self.pid struct.si_uid = self.uid struct.si_status = self.status return bytes(ffi.buffer(struct))
def to_bytes(self) -> bytes: return bytes( ffi.buffer( ffi.new('struct fuse_getattr_in*', { 'getattr_flags': self.getattr_flags, 'fh': self.fh, })))
def to_bytes(self) -> bytes: return bytes(ffi.buffer(ffi.new('struct file_clone_range const*', { "src_fd": self.src_fd, "src_offset": self.src_offset, "src_length": self.src_length, "dest_offset": self.dest_offset, })))
def to_bytes(self) -> bytes: output = [0] * 16 for val in self: idx = val // 64 bit = val % 64 output[idx] |= 1 << bit return bytes(ffi.buffer(ffi.new('cpu_set_t const*', (output, ))))
def to_bytes(self) -> bytes: return bytes( ffi.buffer( ffi.new('struct fuse_open_out*', { 'fh': self.fh, 'open_flags': self.open_flags, })))
def to_bytes(self) -> bytes: # We can't just create a struct sockaddr_storage and turn the whole thing to bytes, # because that will pad the actually valid data with a bunch of trailing null bytes. # And we can't do that because the length of the valid data is semantically # meaningful for some socket addresses, such as sockaddr_un. return bytes(ffi.buffer(ffi.new('sa_family_t*', self.family))) + self.data
def to_bytes(self) -> bytes: ret = b"" for ptr in self: ret += bytes(ffi.buffer(ffi.new('struct iovec const*', { "iov_base": ffi.cast('void*', int(ptr.near)), "iov_len": ptr.size(), }))) return ret
def to_bytes(self) -> bytes: return bytes( ffi.buffer( ffi.new( 'struct fuse_release_in*', { 'fh': self.fh, 'flags': self.flags, 'release_flags': self.release_flags, })))
def to_bytes(self) -> bytes: return bytes( ffi.buffer( ffi.new( 'struct fuse_attr_out*', { 'attr_valid': self.attr_valid.sec, 'attr_valid_nsec': self.attr_valid.nsec, 'attr': self.attr._to_cffi_dict(), })))
def to_bytes(self) -> bytes: namebytes = self.name.encode() + b'\0' length = ffi.sizeof('struct fuse_dirent') + len(namebytes) padding = align(length, 8) - length namebytes = namebytes + bytes(padding) return bytes( ffi.buffer( ffi.new('struct fuse_dirent*', self._to_cffi_dict(namebytes)))) + namebytes
def to_bytes(self) -> bytes: struct = ffi.new( 'struct robust_list_head*', { 'list': (ffi.cast('struct robust_list*', int(self.first.near)), ), 'futex_offset': ffi.offsetof('struct futex_node', 'futex'), 'list_op_pending': ffi.NULL, }) return bytes(ffi.buffer(struct))
def to_bytes(self) -> bytes: struct = ffi.new('struct __user_cap_data_struct[2]') capset_names = ['effective', 'permitted', 'inheritable'] for name in capset_names: capset = getattr(self, name) one, two = to_uint32s(capset) setattr(struct[0], name, one) setattr(struct[1], name, two) return bytes(ffi.buffer(struct))
def to_bytes(self) -> bytes: return bytes( ffi.buffer( ffi.new( 'struct rsyscall_syscall const*', { "sys": self.number, "args": (self.arg1, self.arg2, self.arg3, self.arg4, self.arg5, self.arg6), })))
def to_bytes(self) -> bytes: return bytes( ffi.buffer( ffi.new( 'struct fuse_init_in*', { 'major': self.major, 'minor': self.minor, 'max_readahead': self.max_readahead, 'flags': self.flags, })))
def __init__(self, name: str=None, *, addr: Sockaddr=None, flags: IFF=None, cffi=None) -> None: if cffi is None: cffi = ffi.new('struct ifreq*') self.cffi = cffi if name is not None: self.name = name if addr is not None: self.addr = addr if flags is not None: self.flags = flags
def to_bytes(self) -> bytes: return bytes(ffi.buffer(ffi.new('struct msghdr*', { "msg_name": ffi.cast('void*', int(self.name.near)) if self.name else ffi.NULL, "msg_namelen": self.name.size() if self.name else 0, "msg_iov": ffi.cast('void*', int(self.iov.near)), "msg_iovlen": len(self.iov.value), "msg_control": ffi.cast('void*', int(self.control.near)) if self.control else ffi.NULL, "msg_controllen": self.control.size() if self.control else 0, "msg_flags": 0, })))
def to_bytes(self) -> bytes: return bytes( ffi.buffer( ffi.new( 'struct fuse_read_in*', { 'fh': self.fh, 'offset': self.offset, 'size': self.size, 'read_flags': self.read_flags, 'flags': self.flags, })))
def to_bytes(self, val: T_cmsg) -> bytes: if not isinstance(val, self.cls): raise Exception("Serializer for", self.cls, "had to_bytes called on different type", val) data = val.to_data() header = bytes(ffi.buffer(ffi.new('struct cmsghdr*', { "cmsg_len": ffi.sizeof('struct cmsghdr') + len(data), "cmsg_level": val.level(), "cmsg_type": val.type(), }))) return header + data
def record(reclen: int) -> bytes: record = ffi.new('struct linux_dirent64*', { "d_ino": self.inode, "d_off": self.offset, "d_reclen": reclen, "d_type": self.type, "d_name": self.name.encode(), }) data = bytes(ffi.buffer(record)) # pad to real length return data + bytes(8 - (len(data) % 8))
def to_bytes(self) -> bytes: msg_data = self.msg_to_bytes() return bytes( ffi.buffer( ffi.new( 'struct fuse_out_header*', { 'len': ffi.sizeof('struct fuse_out_header') + len(msg_data), 'error': self.hdr.error, 'unique': self.hdr.unique, }))) + msg_data
def __init__(self, name: str = None, *, flags: int = None, cffi=None) -> None: if cffi is None: cffi = ffi.new('struct ifreq*') self.cffi = cffi if name is not None: self.name = name if flags is not None: self.flags = flags
def to_bytes(self) -> bytes: namebytes = self.dirent.name.encode() + b'\0' length = ffi.sizeof('struct fuse_direntplus') + len(namebytes) padding = align(length, 8) - length namebytes = namebytes + bytes(padding) return bytes( ffi.buffer( ffi.new( 'struct fuse_direntplus*', { "entry_out": self.entry_out._to_cffi_dict(), "dirent": self.dirent._to_cffi_dict(namebytes), }))) + namebytes
async def read_cffi(self, name: str) -> t.Any: "Read, parse, and return this fixed-size cffi type." size = ffi.sizeof(name) data = await self.read_length(size) if data is None: raise EOFException("got EOF while expecting to read a", name) nameptr = name + '*' dest = ffi.new(nameptr) # ffi.cast drops the reference to the backing buffer, so we have to copy it src = ffi.cast(nameptr, ffi.from_buffer(data)) ffi.memmove(dest, src, size) return dest[0]
def to_bytes(self) -> bytes: msg_data = self.msg_to_bytes() return bytes( ffi.buffer( ffi.new( 'struct fuse_in_header*', { 'len': FuseInHeader.sizeof() + len(msg_data), 'opcode': self.opcode, 'unique': self.hdr.unique, 'nodeid': self.hdr.nodeid, 'uid': self.hdr.uid, 'gid': self.hdr.gid, 'pid': self.hdr.pid, }))) + msg_data
def to_bytes(self) -> bytes: return bytes( ffi.buffer( ffi.new( 'struct kernel_sigaction const*', { "ksa_handler": ffi.cast('sighandler_t', int(self.handler)), "ksa_flags": self.flags, "ksa_restorer": ffi.cast('sigrestore_t', int(self.restorer or 0)), "ksa_mask": self.mask.to_cffi()[0], })))
def to_bytes(self) -> bytes: return bytes( ffi.buffer( ffi.new( 'struct fuse_init_out*', { 'major': self.major, 'minor': self.minor, 'max_readahead': self.max_readahead, 'flags': self.flags, 'max_background': self.max_background, 'congestion_threshold': self.congestion_threshold, 'max_write': self.max_write, 'time_gran': self.time_gran, })))