dissect.extfs 3.12.dev1__py3-none-any.whl → 3.13.dev1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
dissect/extfs/__init__.py CHANGED
@@ -8,11 +8,11 @@ from dissect.extfs.extfs import ExtFS, INode
8
8
  from dissect.extfs.journal import JDB2
9
9
 
10
10
  __all__ = [
11
- "ExtFS",
12
- "INode",
13
11
  "JDB2",
14
12
  "Error",
13
+ "ExtFS",
15
14
  "FileNotFoundError",
15
+ "INode",
16
16
  "NotADirectoryError",
17
17
  "NotASymlinkError",
18
18
  ]
dissect/extfs/c_ext.py CHANGED
@@ -1,3 +1,5 @@
1
+ from __future__ import annotations
2
+
1
3
  import stat
2
4
 
3
5
  from dissect.cstruct import cstruct
dissect/extfs/c_jdb2.py CHANGED
@@ -1,3 +1,5 @@
1
+ from __future__ import annotations
2
+
1
3
  from dissect.cstruct import cstruct
2
4
 
3
5
  jdb2_def = """
dissect/extfs/extfs.py CHANGED
@@ -4,9 +4,8 @@ import io
4
4
  import logging
5
5
  import os
6
6
  import stat
7
- from datetime import datetime
8
7
  from functools import lru_cache
9
- from typing import BinaryIO, Iterator, Optional, Union
8
+ from typing import TYPE_CHECKING, BinaryIO
10
9
  from uuid import UUID
11
10
 
12
11
  from dissect.util import ts
@@ -29,6 +28,10 @@ from dissect.extfs.exceptions import (
29
28
  )
30
29
  from dissect.extfs.journal import JDB2
31
30
 
31
+ if TYPE_CHECKING:
32
+ from collections.abc import Iterator
33
+ from datetime import datetime
34
+
32
35
  log = logging.getLogger(__name__)
33
36
  log.setLevel(os.getenv("DISSECT_LOG_EXTFS", "CRITICAL"))
34
37
 
@@ -114,7 +117,7 @@ class ExtFS:
114
117
 
115
118
  return self._journal
116
119
 
117
- def get(self, path: Union[str, int], node: Optional[INode] = None) -> INode:
120
+ def get(self, path: str | int, node: INode | None = None) -> INode:
118
121
  if isinstance(path, int):
119
122
  return self.get_inode(path)
120
123
 
@@ -139,9 +142,9 @@ class ExtFS:
139
142
  def get_inode(
140
143
  self,
141
144
  inum: int,
142
- filename: Optional[str] = None,
143
- filetype: Optional[int] = None,
144
- parent: Optional[INode] = None,
145
+ filename: str | None = None,
146
+ filetype: int | None = None,
147
+ parent: INode | None = None,
145
148
  lazy: bool = False,
146
149
  ) -> INode:
147
150
  if inum < c_ext.EXT2_BAD_INO or inum > self.sb.s_inodes_count:
@@ -181,9 +184,9 @@ class INode:
181
184
  self,
182
185
  extfs: ExtFS,
183
186
  inum: int,
184
- filename: Optional[str] = None,
185
- filetype: Optional[int] = None,
186
- parent: Optional[INode] = None,
187
+ filename: str | None = None,
188
+ filetype: int | None = None,
189
+ parent: INode | None = None,
187
190
  ):
188
191
  self.extfs = extfs
189
192
  self.inum = inum
@@ -248,10 +251,7 @@ class INode:
248
251
  if not self._link_inode:
249
252
  # Relative lookups work because . and .. are actual directory entries
250
253
  link = self.link
251
- if link.startswith("/"):
252
- relnode = None
253
- else:
254
- relnode = self.parent
254
+ relnode = None if link.startswith("/") else self.parent
255
255
  self._link_inode = self.extfs.get(self.link, relnode)
256
256
  return self._link_inode
257
257
 
@@ -320,14 +320,14 @@ class INode:
320
320
  return ts.from_unix(self.inode.i_dtime)
321
321
 
322
322
  @property
323
- def crtime(self) -> Optional[datetime]:
323
+ def crtime(self) -> datetime | None:
324
324
  time_ns = self.crtime_ns
325
325
  if time_ns is None:
326
326
  return None
327
327
  return ts.from_unix_ns(time_ns)
328
328
 
329
329
  @property
330
- def crtime_ns(self) -> Optional[int]:
330
+ def crtime_ns(self) -> int | None:
331
331
  if self.extfs.sb.s_inode_size <= 128:
332
332
  return None
333
333
 
@@ -370,7 +370,7 @@ class INode:
370
370
  offset += direntry.rec_len
371
371
  buf.seek(offset)
372
372
 
373
- def dataruns(self) -> list[tuple[Optional[int], int]]:
373
+ def dataruns(self) -> list[tuple[int | None, int]]:
374
374
  if not self._runlist:
375
375
  expected_runs = (self.size + self.extfs.block_size - 1) // self.extfs.block_size
376
376
 
@@ -446,7 +446,7 @@ class INode:
446
446
  return self._runlist
447
447
 
448
448
  def open(self) -> BinaryIO:
449
- if self.inode.i_flags & c_ext.EXT4_INLINE_DATA_FL or self.filetype == stat.S_IFLNK and self.size < 60:
449
+ if self.inode.i_flags & c_ext.EXT4_INLINE_DATA_FL or (self.filetype == stat.S_IFLNK and self.size < 60):
450
450
  buf = io.BytesIO(memoryview(self.inode.i_block)[: self.size])
451
451
  # Need to add a size attribute to maintain compatibility with dissect streams
452
452
  buf.size = self.size
@@ -478,21 +478,21 @@ def _parse_indirect(inode: INode, offset: int, num_blocks: int, level: int) -> l
478
478
  return [0] * read_blocks
479
479
  inode.extfs.fh.seek(offset * inode.extfs.block_size)
480
480
  return c_ext.uint32[read_blocks](inode.extfs.fh)
481
- else:
482
- blocks = []
483
481
 
484
- max_level_blocks = offsets_per_block**level
485
- blocks_per_nest = max_level_blocks // offsets_per_block
486
- read_blocks = (num_blocks + blocks_per_nest - 1) // blocks_per_nest
487
- read_blocks = min(read_blocks, offsets_per_block)
482
+ blocks = []
488
483
 
489
- inode.extfs.fh.seek(offset * inode.extfs.block_size)
490
- for addr in c_ext.uint32[read_blocks](inode.extfs.fh):
491
- parsed_blocks = _parse_indirect(inode, addr, num_blocks, level - 1)
492
- num_blocks -= len(parsed_blocks)
493
- blocks.extend(parsed_blocks)
484
+ max_level_blocks = offsets_per_block**level
485
+ blocks_per_nest = max_level_blocks // offsets_per_block
486
+ read_blocks = (num_blocks + blocks_per_nest - 1) // blocks_per_nest
487
+ read_blocks = min(read_blocks, offsets_per_block)
488
+
489
+ inode.extfs.fh.seek(offset * inode.extfs.block_size)
490
+ for addr in c_ext.uint32[read_blocks](inode.extfs.fh):
491
+ parsed_blocks = _parse_indirect(inode, addr, num_blocks, level - 1)
492
+ num_blocks -= len(parsed_blocks)
493
+ blocks.extend(parsed_blocks)
494
494
 
495
- return blocks
495
+ return blocks
496
496
 
497
497
 
498
498
  def _parse_extents(inode: INode, buf: bytes) -> Iterator[c_ext.ext4_extent]:
dissect/extfs/journal.py CHANGED
@@ -2,13 +2,16 @@ from __future__ import annotations
2
2
 
3
3
  import datetime
4
4
  import io
5
- from typing import BinaryIO, Iterator, Optional
5
+ from typing import TYPE_CHECKING, BinaryIO
6
6
 
7
7
  from dissect.util.stream import RangeStream
8
8
 
9
9
  from dissect.extfs.c_jdb2 import c_jdb2
10
10
  from dissect.extfs.exceptions import Error
11
11
 
12
+ if TYPE_CHECKING:
13
+ from collections.abc import Iterator
14
+
12
15
 
13
16
  class JDB2:
14
17
  def __init__(self, fh: BinaryIO):
@@ -132,7 +135,7 @@ class CommitBlock:
132
135
  jdb2: JDB2,
133
136
  header: c_jdb2.commit_header,
134
137
  journal_block: int,
135
- descriptors: Optional[list[DescriptorBlock]] = None,
138
+ descriptors: list[DescriptorBlock] | None = None,
136
139
  ):
137
140
  self.jdb2 = jdb2
138
141
  self.header = header
@@ -140,7 +143,7 @@ class CommitBlock:
140
143
  self.descriptors = descriptors if descriptors else []
141
144
 
142
145
  self.sequence = self.header.h_sequence
143
- self.ts = datetime.datetime.utcfromtimestamp(self.header.h_commit_sec)
146
+ self.ts = datetime.datetime.fromtimestamp(self.header.h_commit_sec, tz=datetime.timezone.utc)
144
147
  self.ts += datetime.timedelta(microseconds=self.header.h_commit_nsec // 1000)
145
148
 
146
149
  def __repr__(self) -> str:
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.2
2
2
  Name: dissect.extfs
3
- Version: 3.12.dev1
3
+ Version: 3.13.dev1
4
4
  Summary: A Dissect module implementing a parser for the ExtFS file system, the native filesystem for Linux operating systems
5
5
  Author-email: Dissect Team <dissect@fox-it.com>
6
6
  License: Affero General Public License v3
@@ -22,11 +22,11 @@ Requires-Python: ~=3.9
22
22
  Description-Content-Type: text/markdown
23
23
  License-File: LICENSE
24
24
  License-File: COPYRIGHT
25
- Requires-Dist: dissect.cstruct <5,>=4
26
- Requires-Dist: dissect.util <4,>=3
25
+ Requires-Dist: dissect.cstruct<5,>=4
26
+ Requires-Dist: dissect.util<4,>=3
27
27
  Provides-Extra: dev
28
- Requires-Dist: dissect.cstruct <5.0.dev,>=4.0.dev ; extra == 'dev'
29
- Requires-Dist: dissect.util <4.0.dev,>=3.0.dev ; extra == 'dev'
28
+ Requires-Dist: dissect.cstruct<5.0.dev,>=4.0.dev; extra == "dev"
29
+ Requires-Dist: dissect.util<4.0.dev,>=3.0.dev; extra == "dev"
30
30
 
31
31
  # dissect.extfs
32
32
 
@@ -0,0 +1,12 @@
1
+ dissect/extfs/__init__.py,sha256=1_K5exKlh5eEUQF-vFkj0JzdDoxIZxPp4EC6B_8rQtI,346
2
+ dissect/extfs/c_ext.py,sha256=4429SV3LXJIeD1YIot-vzS-pVdNguwlcvi37cFfh1pY,23423
3
+ dissect/extfs/c_jdb2.py,sha256=4KZ_eq6MQ_gCh1VGtw11G_mN4PEV6PvJBDNUGhfLbMM,3664
4
+ dissect/extfs/exceptions.py,sha256=rVL-M01CBpk74d8VeeeqQuwD5P1WHluvNbAnj5D8BBw,263
5
+ dissect/extfs/extfs.py,sha256=rjAi6qCipWYhi14iJ8c2yD5HaxQ_1gsJMGXyAqVglKs,19202
6
+ dissect/extfs/journal.py,sha256=3od5IdtKAeF6zFi2iCcQ-YynrQx4e8_SAJ7zpv6Qv3k,5043
7
+ dissect.extfs-3.13.dev1.dist-info/COPYRIGHT,sha256=vz2IXoFr4ZWY2Q8QmDgdqzZmyqHhRZiAQC490UHWWdQ,300
8
+ dissect.extfs-3.13.dev1.dist-info/LICENSE,sha256=DZak_2itbUtvHzD3E7GNUYSRK6jdOJ-GqncQ2weavLA,34523
9
+ dissect.extfs-3.13.dev1.dist-info/METADATA,sha256=9_5c8REYLsO9RmES3ZNJhYIr-qPx1EdDxFPS0kpfp8o,3260
10
+ dissect.extfs-3.13.dev1.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
11
+ dissect.extfs-3.13.dev1.dist-info/top_level.txt,sha256=Mn-CQzEYsAbkxrUI0TnplHuXnGVKzxpDw_po_sXpvv4,8
12
+ dissect.extfs-3.13.dev1.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (75.3.0)
2
+ Generator: setuptools (75.8.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,12 +0,0 @@
1
- dissect/extfs/__init__.py,sha256=7LER03IJw1H_l1QY43uEJIbXfYSwUuV5qOjfAP26m8o,346
2
- dissect/extfs/c_ext.py,sha256=fB5V39vG94BfWgWiJW0i-ahRKNrAVY7zDHEIi2tfyBs,23387
3
- dissect/extfs/c_jdb2.py,sha256=I3VpjTl6u8b8dV9_3HGEzC64sjcrcO_f6APjlMndnvA,3628
4
- dissect/extfs/exceptions.py,sha256=rVL-M01CBpk74d8VeeeqQuwD5P1WHluvNbAnj5D8BBw,263
5
- dissect/extfs/extfs.py,sha256=y9j-1gDx7OrFd4_tQfioevHoQxg-1P_JppvgiccwpvA,19293
6
- dissect/extfs/journal.py,sha256=X5DSg_hYfKgIZnzwG617JspGdFDGyWV-rQfb75MapoQ,4968
7
- dissect.extfs-3.12.dev1.dist-info/COPYRIGHT,sha256=vz2IXoFr4ZWY2Q8QmDgdqzZmyqHhRZiAQC490UHWWdQ,300
8
- dissect.extfs-3.12.dev1.dist-info/LICENSE,sha256=DZak_2itbUtvHzD3E7GNUYSRK6jdOJ-GqncQ2weavLA,34523
9
- dissect.extfs-3.12.dev1.dist-info/METADATA,sha256=HVAFxaYjy5sS0bchthKhcmxz9fcztuS8XMK-Z7y8yaQ,3266
10
- dissect.extfs-3.12.dev1.dist-info/WHEEL,sha256=P9jw-gEje8ByB7_hXoICnHtVCrEwMQh-630tKvQWehc,91
11
- dissect.extfs-3.12.dev1.dist-info/top_level.txt,sha256=Mn-CQzEYsAbkxrUI0TnplHuXnGVKzxpDw_po_sXpvv4,8
12
- dissect.extfs-3.12.dev1.dist-info/RECORD,,