Exemplo n.º 1
0
 def from_cffi(cls, struct) -> FuseDirent:
     return cls(
         ino=struct.ino,
         off=struct.off,
         type=DT(struct.type),
         # the name is padded with null bytes to make the dirent aligned,
         # so we have to use strlen to find the end
         name=ffi.string(struct.name, struct.namelen).decode(),
     )
Exemplo n.º 2
0
 def from_bytes(cls: t.Type[T], data: bytes) -> t.Tuple[T, int]:
     struct = ffi.cast('struct inotify_event*', ffi.from_buffer(data))
     value = cls(
         wd=WatchDescriptor(struct.wd),
         mask=IN(struct.mask),
         cookie=struct.cookie,
         name=ffi.string(struct.name, struct.len).decode() if struct.len else None,
     )
     size = ffi.sizeof("struct inotify_event") + struct.len
     return value, size
Exemplo n.º 3
0
 def from_bytes(cls: t.Type[T], data: bytes) -> T:
     entries = []
     while len(data) > 0:
         record = ffi.cast('struct linux_dirent64*', ffi.from_buffer(data))
         name_len = record.d_reclen - _d_name_offset
         # the name is padded with null bytes to make the dirent aligned,
         # so we have to use strlen to find the end
         name = ffi.string(record.d_name, name_len).decode()
         entries.append(Dirent(inode=record.d_ino, offset=record.d_off, type=DT(record.d_type), name=name))
         data = data[record.d_reclen:]
     return cls(entries)
Exemplo n.º 4
0
 def from_bytes(cls: t.Type[T], data: bytes) -> T:
     entries = []
     while len(data) > 0:
         # We do the work of from_bytes in this class instead of in Dirent because we need the
         # raw length field from the struct; merely doing len(name) will exclude padding.
         record = ffi.cast('struct linux_dirent64*', ffi.from_buffer(data))
         name_len = record.d_reclen - _d_name_offset
         # the name is padded with null bytes to make the dirent aligned,
         # so we have to use strlen to find the end
         name = ffi.string(record.d_name, name_len).decode()
         entries.append(Dirent(inode=record.d_ino, offset=record.d_off, type=DT(record.d_type), name=name))
         data = data[record.d_reclen:]
     return cls(entries)