コード例 #1
0
    def testIsFunctions(self):
        """Test the Is? functions."""
        path_spec = lvm_path_spec.LVMPathSpec(parent=self._qcow_path_spec,
                                              volume_index=1)
        file_entry = self._file_system.GetFileEntryByPathSpec(path_spec)
        self.assertIsNotNone(file_entry)

        self.assertFalse(file_entry.IsRoot())
        self.assertFalse(file_entry.IsVirtual())
        self.assertTrue(file_entry.IsAllocated())

        self.assertFalse(file_entry.IsDevice())
        self.assertFalse(file_entry.IsDirectory())
        self.assertTrue(file_entry.IsFile())
        self.assertFalse(file_entry.IsLink())
        self.assertFalse(file_entry.IsPipe())
        self.assertFalse(file_entry.IsSocket())

        path_spec = lvm_path_spec.LVMPathSpec(location='/',
                                              parent=self._qcow_path_spec)
        file_entry = self._file_system.GetFileEntryByPathSpec(path_spec)
        self.assertIsNotNone(file_entry)

        self.assertTrue(file_entry.IsRoot())
        self.assertTrue(file_entry.IsVirtual())
        self.assertTrue(file_entry.IsAllocated())

        self.assertFalse(file_entry.IsDevice())
        self.assertTrue(file_entry.IsDirectory())
        self.assertFalse(file_entry.IsFile())
        self.assertFalse(file_entry.IsLink())
        self.assertFalse(file_entry.IsPipe())
        self.assertFalse(file_entry.IsSocket())
コード例 #2
0
    def testDataStreams(self):
        """Test the data streams functionality."""
        path_spec = lvm_path_spec.LVMPathSpec(parent=self._qcow_path_spec,
                                              volume_index=1)
        file_entry = self._file_system.GetFileEntryByPathSpec(path_spec)
        self.assertIsNotNone(file_entry)

        self.assertEqual(file_entry.number_of_data_streams, 1)

        data_stream_names = []
        for data_stream in file_entry.data_streams:
            data_stream_names.append(data_stream.name)

        self.assertEqual(data_stream_names, [''])

        path_spec = lvm_path_spec.LVMPathSpec(location='/',
                                              parent=self._qcow_path_spec)
        file_entry = self._file_system.GetFileEntryByPathSpec(path_spec)
        self.assertIsNotNone(file_entry)

        self.assertEqual(file_entry.number_of_data_streams, 0)

        data_stream_names = []
        for data_stream in file_entry.data_streams:
            data_stream_names.append(data_stream.name)

        self.assertEqual(data_stream_names, [])
コード例 #3
0
ファイル: lvm_path_spec.py プロジェクト: cugu-stars/dfvfs
  def testComparable(self):
    """Tests the path specification comparable property."""
    path_spec = lvm_path_spec.LVMPathSpec(parent=self._path_spec)

    self.assertIsNotNone(path_spec)

    expected_comparable = '\n'.join([
        'type: TEST',
        'type: LVM',
        ''])

    self.assertEqual(path_spec.comparable, expected_comparable)

    path_spec = lvm_path_spec.LVMPathSpec(
        location='/lvm2', parent=self._path_spec)

    self.assertIsNotNone(path_spec)

    expected_comparable = '\n'.join([
        'type: TEST',
        'type: LVM, location: /lvm2',
        ''])

    self.assertEqual(path_spec.comparable, expected_comparable)

    path_spec = lvm_path_spec.LVMPathSpec(
        parent=self._path_spec, volume_index=1)

    self.assertIsNotNone(path_spec)

    expected_comparable = '\n'.join([
        'type: TEST',
        'type: LVM, volume index: 1',
        ''])

    self.assertEqual(path_spec.comparable, expected_comparable)

    path_spec = lvm_path_spec.LVMPathSpec(
        location='/lvm2', parent=self._path_spec, volume_index=1)

    self.assertIsNotNone(path_spec)

    expected_comparable = '\n'.join([
        'type: TEST',
        'type: LVM, location: /lvm2, volume index: 1',
        ''])

    self.assertEqual(path_spec.comparable, expected_comparable)
コード例 #4
0
ファイル: lvm_volume_system.py プロジェクト: tincho9/dfvfs
 def setUp(self):
     """Sets up the needed objects used throughout the test."""
     test_file = self._GetTestFilePath(['lvmtest.qcow2'])
     path_spec = os_path_spec.OSPathSpec(location=test_file)
     path_spec = qcow_path_spec.QCOWPathSpec(parent=path_spec)
     self._lvm_path_spec = lvm_path_spec.LVMPathSpec(location='/',
                                                     parent=path_spec)
コード例 #5
0
    def _EntriesGenerator(self):
        """Retrieves directory entries.

    Since a directory can contain a vast number of entries using
    a generator is more memory efficient.

    Yields:
      LVMPathSpec: a path specification.
    """
        # Only the virtual root file has directory entries.
        volume_index = getattr(self.path_spec, 'volume_index', None)
        if volume_index is not None:
            return

        location = getattr(self.path_spec, 'location', None)
        if location is None or location != self._file_system.LOCATION_ROOT:
            return

        vslvm_volume_group = self._file_system.GetLVMVolumeGroup()

        for volume_index in range(
                0, vslvm_volume_group.number_of_logical_volumes):
            yield lvm_path_spec.LVMPathSpec(
                location='/lvm{0:d}'.format(volume_index + 1),
                parent=self.path_spec.parent,
                volume_index=volume_index)
コード例 #6
0
ファイル: lvm_volume_system.py プロジェクト: devgc/dfvfs
 def setUp(self):
     """Sets up the needed objects used throughout the test."""
     test_file = os.path.join(u'test_data', u'lvmtest.qcow2')
     path_spec = os_path_spec.OSPathSpec(location=test_file)
     path_spec = qcow_path_spec.QCOWPathSpec(parent=path_spec)
     self._lvm_path_spec = lvm_path_spec.LVMPathSpec(location=u'/',
                                                     parent=path_spec)
コード例 #7
0
ファイル: lvm_file_io.py プロジェクト: devgc/dfvfs
 def setUp(self):
   """Sets up the needed objects used throughout the test."""
   super(LVMImageFileTest, self).setUp()
   test_file = os.path.join(u'test_data', u'lvmtest.qcow2')
   path_spec = os_path_spec.OSPathSpec(location=test_file)
   self._qcow_path_spec = qcow_path_spec.QCOWPathSpec(parent=path_spec)
   self._lvm_path_spec = lvm_path_spec.LVMPathSpec(
       parent=self._qcow_path_spec, volume_index=0)
コード例 #8
0
    def testGetParentFileEntry(self):
        """Tests the GetParentFileEntry function."""
        path_spec = lvm_path_spec.LVMPathSpec(parent=self._qcow_path_spec,
                                              volume_index=1)
        file_entry = self._file_system.GetFileEntryByPathSpec(path_spec)
        self.assertIsNotNone(file_entry)

        parent_file_entry = file_entry.GetParentFileEntry()
        self.assertIsNotNone(parent_file_entry)

        path_spec = lvm_path_spec.LVMPathSpec(location='/',
                                              parent=self._qcow_path_spec)
        file_entry = self._file_system.GetFileEntryByPathSpec(path_spec)
        self.assertIsNotNone(file_entry)

        parent_file_entry = file_entry.GetParentFileEntry()
        self.assertIsNone(parent_file_entry)
コード例 #9
0
 def setUp(self):
     """Sets up the needed objects used throughout the test."""
     self._resolver_context = context.Context()
     test_file = self._GetTestFilePath([u'lvmtest.qcow2'])
     path_spec = os_path_spec.OSPathSpec(location=test_file)
     self._qcow_path_spec = qcow_path_spec.QCOWPathSpec(parent=path_spec)
     self._lvm_path_spec = lvm_path_spec.LVMPathSpec(
         location=u'/', parent=self._qcow_path_spec)
コード例 #10
0
    def GetRootFileEntry(self):
        """Retrieves the root file entry.

    Returns:
      A file entry (instance of FileEntry).
    """
        path_spec = lvm_path_spec.LVMPathSpec(location=self.LOCATION_ROOT,
                                              parent=self._path_spec.parent)
        return self.GetFileEntryByPathSpec(path_spec)
コード例 #11
0
ファイル: lvm_file_system.py プロジェクト: cugu-stars/dfvfs
    def GetRootFileEntry(self):
        """Retrieves the root file entry.

    Returns:
      LVMFileEntry: root file entry or None if not available.
    """
        path_spec = lvm_path_spec.LVMPathSpec(location=self.LOCATION_ROOT,
                                              parent=self._path_spec.parent)
        return self.GetFileEntryByPathSpec(path_spec)
コード例 #12
0
  def setUp(self):
    """Sets up the needed objects used throughout the test."""
    test_file = self._GetTestFilePath(['lvm.raw'])
    self._SkipIfPathNotExists(test_file)

    path_spec = os_path_spec.OSPathSpec(location=test_file)
    path_spec = raw_path_spec.RawPathSpec(parent=path_spec)
    self._lvm_path_spec = lvm_path_spec.LVMPathSpec(
        location='/', parent=path_spec)
コード例 #13
0
ファイル: lvm_file_io.py プロジェクト: slad99/dfvfs
    def setUp(self):
        """Sets up the needed objects used throughout the test."""
        super(LVMImageFileTest, self).setUp()
        test_file = self._GetTestFilePath(['lvm.qcow2'])
        self._SkipIfPathNotExists(test_file)

        path_spec = os_path_spec.OSPathSpec(location=test_file)
        self._qcow_path_spec = qcow_path_spec.QCOWPathSpec(parent=path_spec)
        self._lvm_path_spec = lvm_path_spec.LVMPathSpec(
            parent=self._qcow_path_spec, volume_index=0)
コード例 #14
0
    def testGetStat(self):
        """Tests the GetStat function."""
        path_spec = lvm_path_spec.LVMPathSpec(parent=self._qcow_path_spec,
                                              volume_index=1)
        file_entry = self._file_system.GetFileEntryByPathSpec(path_spec)
        self.assertIsNotNone(file_entry)

        stat_object = file_entry.GetStat()

        self.assertIsNotNone(stat_object)
        self.assertEqual(stat_object.type, stat_object.TYPE_FILE)
        self.assertEqual(stat_object.size, 4194304)
コード例 #15
0
    def setUp(self):
        """Sets up the needed objects used throughout the test."""
        self._resolver_context = context.Context()
        test_file = os.path.join(u'test_data', u'lvmtest.qcow2')
        path_spec = os_path_spec.OSPathSpec(location=test_file)
        self._qcow_path_spec = qcow_path_spec.QCOWPathSpec(parent=path_spec)
        self._lvm_path_spec = lvm_path_spec.LVMPathSpec(
            location=u'/', parent=self._qcow_path_spec)

        self._file_system = lvm_file_system.LVMFileSystem(
            self._resolver_context)
        self._file_system.Open(self._lvm_path_spec)
コード例 #16
0
ファイル: lvm_file_system.py プロジェクト: IAMBANMA/dfvfs
    def testFileEntryExistsByPathSpec(self):
        """Test the file entry exists by path specification functionality."""
        file_system = lvm_file_system.LVMFileSystem(self._resolver_context)
        self.assertIsNotNone(file_system)

        file_system.Open(self._lvm_path_spec)

        path_spec = lvm_path_spec.LVMPathSpec(location='/',
                                              parent=self._qcow_path_spec)
        self.assertTrue(file_system.FileEntryExistsByPathSpec(path_spec))

        path_spec = lvm_path_spec.LVMPathSpec(parent=self._qcow_path_spec,
                                              volume_index=1)
        self.assertTrue(file_system.FileEntryExistsByPathSpec(path_spec))

        path_spec = lvm_path_spec.LVMPathSpec(location='/lvm2',
                                              parent=self._qcow_path_spec)
        self.assertTrue(file_system.FileEntryExistsByPathSpec(path_spec))

        path_spec = lvm_path_spec.LVMPathSpec(parent=self._qcow_path_spec,
                                              volume_index=9)
        self.assertFalse(file_system.FileEntryExistsByPathSpec(path_spec))

        path_spec = lvm_path_spec.LVMPathSpec(location='/lvm0',
                                              parent=self._qcow_path_spec)
        self.assertFalse(file_system.FileEntryExistsByPathSpec(path_spec))

        path_spec = lvm_path_spec.LVMPathSpec(location='/lvm9',
                                              parent=self._qcow_path_spec)
        self.assertFalse(file_system.FileEntryExistsByPathSpec(path_spec))

        file_system.Close()
コード例 #17
0
ファイル: lvm_path_spec.py プロジェクト: cugu-stars/dfvfs
  def testInitialize(self):
    """Tests the path specification initialization."""
    path_spec = lvm_path_spec.LVMPathSpec(parent=self._path_spec)

    self.assertIsNotNone(path_spec)

    path_spec = lvm_path_spec.LVMPathSpec(
        location='/lvm2', parent=self._path_spec)

    self.assertIsNotNone(path_spec)

    path_spec = lvm_path_spec.LVMPathSpec(
        parent=self._path_spec, volume_index=1)

    self.assertIsNotNone(path_spec)

    path_spec = lvm_path_spec.LVMPathSpec(
        location='/lvm2', parent=self._path_spec, volume_index=1)

    self.assertIsNotNone(path_spec)

    with self.assertRaises(ValueError):
      lvm_path_spec.LVMPathSpec(parent=None)

    with self.assertRaises(ValueError):
      lvm_path_spec.LVMPathSpec(
          parent=self._path_spec, bogus='BOGUS')
コード例 #18
0
ファイル: lvm_file_io.py プロジェクト: slad99/dfvfs
    def testOpenClose(self):
        """Test the open and close functionality."""
        path_spec = lvm_path_spec.LVMPathSpec(parent=self._qcow_path_spec,
                                              volume_index=0)
        file_object = lvm_file_io.LVMFile(self._resolver_context)

        file_object.open(path_spec=path_spec)
        self.assertEqual(file_object.get_size(), 4194304)
        file_object.close()

        path_spec = lvm_path_spec.LVMPathSpec(parent=self._qcow_path_spec,
                                              volume_index=9)
        file_object = lvm_file_io.LVMFile(self._resolver_context)

        with self.assertRaises(errors.PathSpecError):
            file_object.open(path_spec=path_spec)

        path_spec = lvm_path_spec.LVMPathSpec(location='/lvm1',
                                              parent=self._qcow_path_spec)
        file_object = lvm_file_io.LVMFile(self._resolver_context)

        file_object.open(path_spec=path_spec)
        self.assertEqual(file_object.get_size(), 4194304)
        file_object.close()

        path_spec = lvm_path_spec.LVMPathSpec(location='/lvm0',
                                              parent=self._qcow_path_spec)
        file_object = lvm_file_io.LVMFile(self._resolver_context)

        with self.assertRaises(errors.PathSpecError):
            file_object.open(path_spec=path_spec)

        path_spec = lvm_path_spec.LVMPathSpec(location='/lvm9',
                                              parent=self._qcow_path_spec)
        file_object = lvm_file_io.LVMFile(self._resolver_context)

        with self.assertRaises(errors.PathSpecError):
            file_object.open(path_spec=path_spec)
コード例 #19
0
    def testRead(self):
        """Test the read functionality."""
        path_spec = lvm_path_spec.LVMPathSpec(parent=self._raw_path_spec,
                                              volume_index=0)
        file_object = lvm_file_io.LVMFile(self._resolver_context, path_spec)

        file_object.Open()
        self.assertEqual(file_object.get_size(), 4194304)

        file_object.seek(0x80400)

        expected_data = (
            b'This is a text file.\n\nWe should be able to parse it.\n')
        self.assertEqual(file_object.read(53), expected_data)
コード例 #20
0
    def testGetDataStream(self):
        """Tests the GetDataStream function."""
        path_spec = lvm_path_spec.LVMPathSpec(parent=self._qcow_path_spec,
                                              volume_index=1)
        file_entry = self._file_system.GetFileEntryByPathSpec(path_spec)
        self.assertIsNotNone(file_entry)

        data_stream_name = ''
        data_stream = file_entry.GetDataStream(data_stream_name)
        self.assertIsNotNone(data_stream)
        self.assertEqual(data_stream.name, data_stream_name)

        data_stream = file_entry.GetDataStream('bogus')
        self.assertIsNone(data_stream)
コード例 #21
0
    def setUp(self):
        """Sets up the needed objects used throughout the test."""
        self._resolver_context = context.Context()
        test_file = self._GetTestFilePath(['lvmtest.qcow2'])
        self._SkipIfPathNotExists(test_file)

        path_spec = os_path_spec.OSPathSpec(location=test_file)
        self._qcow_path_spec = qcow_path_spec.QCOWPathSpec(parent=path_spec)
        self._lvm_path_spec = lvm_path_spec.LVMPathSpec(
            location='/', parent=self._qcow_path_spec)

        self._file_system = lvm_file_system.LVMFileSystem(
            self._resolver_context)
        self._file_system.Open(self._lvm_path_spec)
コード例 #22
0
ファイル: lvm_file_io.py プロジェクト: slad99/dfvfs
    def testSeek(self):
        """Test the seek functionality."""
        path_spec = lvm_path_spec.LVMPathSpec(parent=self._qcow_path_spec,
                                              volume_index=0)
        file_object = lvm_file_io.LVMFile(self._resolver_context)

        file_object.open(path_spec=path_spec)
        self.assertEqual(file_object.get_size(), 4194304)

        file_object.seek(0x488)
        self.assertEqual(file_object.get_offset(), 0x00000488)
        self.assertEqual(file_object.read(11), b'/mnt/dfvfs\x00')
        self.assertEqual(file_object.get_offset(), 0x00000493)

        file_object.seek(-1047544, os.SEEK_END)
        self.assertEqual(file_object.get_offset(), 0x00300408)
        self.assertEqual(file_object.read(8), b'er,passw')
        self.assertEqual(file_object.get_offset(), 0x00300410)

        file_object.seek(3, os.SEEK_CUR)
        self.assertEqual(file_object.get_offset(), 0x00300413)
        self.assertEqual(file_object.read(7), b'\nbank,j')
        self.assertEqual(file_object.get_offset(), 0x0030041a)

        # Conforming to the POSIX seek the offset can exceed the file size
        # but reading will result in no data being returned.
        expected_offset = 4194304 + 100
        file_object.seek(expected_offset, os.SEEK_SET)
        self.assertEqual(file_object.get_offset(), expected_offset)
        self.assertEqual(file_object.read(20), b'')

        with self.assertRaises(IOError):
            file_object.seek(-10, os.SEEK_SET)

        # On error the offset should not change.
        self.assertEqual(file_object.get_offset(), expected_offset)

        with self.assertRaises(IOError):
            file_object.seek(10, 5)

        # On error the offset should not change.
        self.assertEqual(file_object.get_offset(), expected_offset)

        file_object.close()
コード例 #23
0
    def testSubFileEntries(self):
        """Test the sub file entries iteration functionality."""
        path_spec = lvm_path_spec.LVMPathSpec(location='/',
                                              parent=self._qcow_path_spec)
        file_entry = self._file_system.GetFileEntryByPathSpec(path_spec)
        self.assertIsNotNone(file_entry)

        self.assertEqual(file_entry.number_of_sub_file_entries, 2)

        expected_sub_file_entry_names = ['lvm1', 'lvm2']

        sub_file_entry_names = []
        for sub_file_entry in file_entry.sub_file_entries:
            sub_file_entry_names.append(sub_file_entry.name)

        self.assertEqual(len(sub_file_entry_names),
                         len(expected_sub_file_entry_names))
        self.assertEqual(sorted(sub_file_entry_names),
                         sorted(expected_sub_file_entry_names))
コード例 #24
0
ファイル: lvm_file_system.py プロジェクト: IAMBANMA/dfvfs
    def testGetFileEntryByPathSpec(self):
        """Tests the GetFileEntryByPathSpec function."""
        file_system = lvm_file_system.LVMFileSystem(self._resolver_context)
        self.assertIsNotNone(file_system)

        file_system.Open(self._lvm_path_spec)

        path_spec = lvm_path_spec.LVMPathSpec(location='/',
                                              parent=self._qcow_path_spec)
        file_entry = file_system.GetFileEntryByPathSpec(path_spec)

        self.assertIsNotNone(file_entry)
        self.assertEqual(file_entry.name, '')

        path_spec = lvm_path_spec.LVMPathSpec(parent=self._qcow_path_spec,
                                              volume_index=1)
        file_entry = file_system.GetFileEntryByPathSpec(path_spec)

        self.assertIsNotNone(file_entry)
        self.assertEqual(file_entry.name, 'lvm2')

        path_spec = lvm_path_spec.LVMPathSpec(location='/lvm2',
                                              parent=self._qcow_path_spec)
        file_entry = file_system.GetFileEntryByPathSpec(path_spec)

        self.assertIsNotNone(file_entry)
        self.assertEqual(file_entry.name, 'lvm2')

        path_spec = lvm_path_spec.LVMPathSpec(parent=self._qcow_path_spec,
                                              volume_index=9)
        file_entry = file_system.GetFileEntryByPathSpec(path_spec)

        self.assertIsNone(file_entry)

        path_spec = lvm_path_spec.LVMPathSpec(location='/lvm0',
                                              parent=self._qcow_path_spec)
        file_entry = file_system.GetFileEntryByPathSpec(path_spec)

        self.assertIsNone(file_entry)

        path_spec = lvm_path_spec.LVMPathSpec(location='/lvm9',
                                              parent=self._qcow_path_spec)
        file_entry = file_system.GetFileEntryByPathSpec(path_spec)

        self.assertIsNone(file_entry)

        file_system.Close()