forked from log2timeline/dfvfs
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added fsext back-end log2timeline#464
- Loading branch information
1 parent
05d0d5c
commit add269a
Showing
15 changed files
with
1,383 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# -*- coding: utf-8 -*- | ||
"""The EXT format analyzer helper implementation.""" | ||
|
||
from __future__ import unicode_literals | ||
|
||
from dfvfs.analyzer import analyzer | ||
from dfvfs.analyzer import analyzer_helper | ||
from dfvfs.analyzer import specification | ||
from dfvfs.lib import definitions | ||
|
||
|
||
class EXTAnalyzerHelper(analyzer_helper.AnalyzerHelper): | ||
"""EXT analyzer helper.""" | ||
|
||
FORMAT_CATEGORIES = frozenset([ | ||
definitions.FORMAT_CATEGORY_FILE_SYSTEM]) | ||
|
||
TYPE_INDICATOR = definitions.TYPE_INDICATOR_EXT | ||
|
||
def GetFormatSpecification(self): | ||
"""Retrieves the format specification. | ||
Returns: | ||
FormatSpecification: format specification or None if the format cannot | ||
be defined by a specification object. | ||
""" | ||
format_specification = specification.FormatSpecification( | ||
self.type_indicator) | ||
|
||
# EXT file system signature. | ||
format_specification.AddNewSignature(b'\x53\xef', offset=56) | ||
|
||
return format_specification | ||
|
||
|
||
analyzer.Analyzer.RegisterHelper(EXTAnalyzerHelper()) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
# -*- coding: utf-8 -*- | ||
"""The Extended File System (EXT) file-like object implementation.""" | ||
|
||
from __future__ import unicode_literals | ||
|
||
import os | ||
|
||
from dfvfs.file_io import file_io | ||
from dfvfs.lib import errors | ||
from dfvfs.resolver import resolver | ||
|
||
|
||
class EXTFile(file_io.FileIO): | ||
"""File-like object using pyfsext.file_entry""" | ||
|
||
def __init__(self, resolver_context): | ||
"""Initializes a file-like object. | ||
Args: | ||
resolver_context (Context): resolver context. | ||
""" | ||
super(EXTFile, self).__init__(resolver_context) | ||
self._file_system = None | ||
self._fsext_file_entry = None | ||
|
||
def _Close(self): | ||
"""Closes the file-like object.""" | ||
self._fsext_file_entry = None | ||
|
||
self._file_system.Close() | ||
self._file_system = None | ||
|
||
def _Open(self, path_spec=None, mode='rb'): | ||
"""Opens the file-like object defined by path specification. | ||
Args: | ||
path_spec (PathSpec): path specification. | ||
mode (Optional[str]): file access mode. | ||
Raises: | ||
AccessError: if the access to open the file was denied. | ||
IOError: if the file-like object could not be opened. | ||
NotSupported: if a data stream, like the resource or named fork, is | ||
requested to be opened. | ||
OSError: if the file-like object could not be opened. | ||
PathSpecError: if the path specification is incorrect. | ||
ValueError: if the path specification is invalid. | ||
""" | ||
if not path_spec: | ||
raise ValueError('Missing path specification.') | ||
|
||
data_stream = getattr(path_spec, 'data_stream', None) | ||
if data_stream: | ||
raise errors.NotSupported( | ||
'Open data stream: {0:s} not supported.'.format(data_stream)) | ||
|
||
self._file_system = resolver.Resolver.OpenFileSystem( | ||
path_spec, resolver_context=self._resolver_context) | ||
|
||
file_entry = self._file_system.GetFileEntryByPathSpec(path_spec) | ||
if not file_entry: | ||
raise IOError('Unable to open file entry.') | ||
|
||
fsext_file_entry = file_entry.GetEXTFileEntry() | ||
if not fsext_file_entry: | ||
raise IOError('Unable to open EXT file entry.') | ||
|
||
self._fsext_file_entry = fsext_file_entry | ||
|
||
# Note: that the following functions do not follow the style guide | ||
# because they are part of the file-like object interface. | ||
# pylint: disable=invalid-name | ||
|
||
def read(self, size=None): | ||
"""Reads a byte string from the file-like object at the current offset. | ||
The function will read a byte string of the specified size or | ||
all of the remaining data if no size was specified. | ||
Args: | ||
size (Optional[int]): number of bytes to read, where None is all | ||
remaining data. | ||
Returns: | ||
bytes: data read. | ||
Raises: | ||
IOError: if the read failed. | ||
OSError: if the read failed. | ||
""" | ||
if not self._is_open: | ||
raise IOError('Not opened.') | ||
|
||
return self._fsext_file_entry.read(size=size) | ||
|
||
def seek(self, offset, whence=os.SEEK_SET): | ||
"""Seeks to an offset within the file-like object. | ||
Args: | ||
offset (int): offset to seek to. | ||
whence (Optional(int)): value that indicates whether offset is an absolute | ||
or relative position within the file. | ||
Raises: | ||
IOError: if the seek failed. | ||
OSError: if the seek failed. | ||
""" | ||
if not self._is_open: | ||
raise IOError('Not opened.') | ||
|
||
self._fsext_file_entry.seek(offset, whence) | ||
|
||
def get_offset(self): | ||
"""Retrieves the current offset into the file-like object. | ||
Return: | ||
int: current offset into the file-like object. | ||
Raises: | ||
IOError: if the file-like object has not been opened. | ||
OSError: if the file-like object has not been opened. | ||
""" | ||
if not self._is_open: | ||
raise IOError('Not opened.') | ||
|
||
return self._fsext_file_entry.get_offset() | ||
|
||
def get_size(self): | ||
"""Retrieves the size of the file-like object. | ||
Returns: | ||
int: size of the file-like object data. | ||
Raises: | ||
IOError: if the file-like object has not been opened. | ||
OSError: if the file-like object has not been opened. | ||
""" | ||
if not self._is_open: | ||
raise IOError('Not opened.') | ||
|
||
return self._fsext_file_entry.get_size() |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# -*- coding: utf-8 -*- | ||
"""The EXT path specification implementation.""" | ||
|
||
from __future__ import unicode_literals | ||
|
||
from dfvfs.lib import definitions | ||
from dfvfs.path import factory | ||
from dfvfs.path import path_spec | ||
|
||
|
||
class EXTPathSpec(path_spec.PathSpec): | ||
"""EXT path specification implementation. | ||
Attributes: | ||
inode (int): inode. | ||
location (str): location. | ||
""" | ||
|
||
TYPE_INDICATOR = definitions.TYPE_INDICATOR_EXT | ||
|
||
def __init__( | ||
self, inode=None, location=None, parent=None, **kwargs): | ||
"""Initializes a path specification. | ||
Note that an EXT path specification must have a parent. | ||
Args: | ||
inode (Optional[int]): inode. | ||
location (Optional[str]): location. | ||
parent (Optional[PathSpec]): parent path specification. | ||
Raises: | ||
ValueError: when parent or both inode and location are not set. | ||
""" | ||
if (not inode and not location) or not parent: | ||
raise ValueError('Missing inode and location, or parent value.') | ||
|
||
super(EXTPathSpec, self).__init__(parent=parent, **kwargs) | ||
self.inode = inode | ||
self.location = location | ||
|
||
@property | ||
def comparable(self): | ||
"""str: comparable representation of the path specification.""" | ||
string_parts = [] | ||
|
||
if self.inode is not None: | ||
string_parts.append('inode: {0:d}'.format(self.inode)) | ||
if self.location is not None: | ||
string_parts.append('location: {0:s}'.format(self.location)) | ||
|
||
return self._GetComparable(sub_comparable_string=', '.join(string_parts)) | ||
|
||
|
||
factory.Factory.RegisterPathSpec(EXTPathSpec) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# -*- coding: utf-8 -*- | ||
"""The EXT path specification resolver helper implementation.""" | ||
|
||
from __future__ import unicode_literals | ||
|
||
from dfvfs.file_io import ext_file_io | ||
from dfvfs.lib import definitions | ||
from dfvfs.resolver_helpers import manager | ||
from dfvfs.resolver_helpers import resolver_helper | ||
from dfvfs.vfs import ext_file_system | ||
|
||
|
||
class EXTResolverHelper(resolver_helper.ResolverHelper): | ||
"""EXT resolver helper.""" | ||
|
||
TYPE_INDICATOR = definitions.TYPE_INDICATOR_EXT | ||
|
||
def NewFileObject(self, resolver_context): | ||
"""Creates a new file-like object. | ||
Args: | ||
resolver_context (Context): resolver context. | ||
Returns: | ||
FileIO: file-like object. | ||
""" | ||
return ext_file_io.EXTFile(resolver_context) | ||
|
||
def NewFileSystem(self, resolver_context): | ||
"""Creates a new file system object. | ||
Args: | ||
resolver_context (Context): resolver context. | ||
Returns: | ||
FileSystem: file system. | ||
""" | ||
return ext_file_system.EXTFileSystem(resolver_context) | ||
|
||
|
||
manager.ResolverHelperManager.RegisterHelper(EXTResolverHelper()) |
Oops, something went wrong.