def _Stat( self, entry: pyfsntfs.file_entry, data_stream: pyfsntfs.data_stream, pathspec: rdf_paths.PathSpec, ) -> rdf_client_fs.StatEntry: st = rdf_client_fs.StatEntry() st.pathspec = pathspec st.st_atime = rdfvalue.RDFDatetimeSeconds.FromDatetime( entry.get_access_time()) st.st_mtime = rdfvalue.RDFDatetimeSeconds.FromDatetime( entry.get_modification_time()) st.st_crtime = rdfvalue.RDFDatetimeSeconds.FromDatetime( entry.get_creation_time()) if entry.has_directory_entries_index(): st.st_mode = stat.S_IFDIR else: st.st_mode = stat.S_IFREG if data_stream is not None: st.st_size = data_stream.get_size() flags = entry.file_attribute_flags st.st_mode |= stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH if (flags & FILE_ATTRIBUTE_READONLY) == 0: st.st_mode |= stat.S_IWUSR | stat.S_IWGRP | stat.S_IWOTH if (flags & FILE_ATTRIBUTE_HIDDEN) == 0: st.st_mode |= stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH return st
def _get_data_stream( entry: pyfsntfs.file_entry, stream_name: Optional[str]) -> Optional[pyfsntfs.data_stream]: """Returns a data stream by name, or the default data stream.""" if stream_name is None: if entry.has_default_data_stream(): return entry else: return None data_stream = entry.get_alternate_data_stream_by_name(stream_name) if data_stream is None: raise IOError(f"Failed to open data stream {stream_name}.") return data_stream
def _get_data_stream(entry: pyfsntfs.file_entry, stream_name: Optional[str]) -> pyfsntfs.data_stream: if stream_name is None: return entry data_stream = entry.get_alternate_data_stream_by_name(stream_name) if data_stream is None: raise IOError(f"Failed to open data stream {stream_name}.") return data_stream
def _Stat( self, entry: pyfsntfs.file_entry, data_stream: pyfsntfs.data_stream, ) -> filesystem_pb2.StatEntry: st = filesystem_pb2.StatEntry() if entry.name is not None: st.name = entry.name st.st_ino = entry.file_reference st.st_atime.FromDatetime(entry.get_access_time()) st.st_mtime.FromDatetime(entry.get_modification_time()) st.st_btime.FromDatetime(entry.get_creation_time()) st.st_ctime.FromDatetime(entry.get_entry_modification_time()) st.ntfs.is_directory = entry.has_directory_entries_index() if not entry.has_directory_entries_index() and data_stream is not None: st.st_size = data_stream.get_size() if entry != data_stream and data_stream is not None: st.stream_name = data_stream.name st.ntfs.flags = entry.file_attribute_flags return st