File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -28,6 +28,7 @@ trap "rm -r \"$tmp_dir\"" EXIT
2828echo " [test] Using temporary directory: $tmp_dir "
2929echo " [test] Generating files..."
3030echo " hello world" > " $tmp_dir " /test.txt
31+ ln -s test.txt " $tmp_dir " /symlink.txt
3132for i in {1..1000}; do
3233 echo " echo " hello world" >>'$tmp_dir /test.txt'"
3334done | xargs -P " $( nproc) " -I {} bash -c ' {}'
@@ -43,7 +44,7 @@ done | xargs -P "$(nproc)" -I {} bash -c '{}'
4344mkimage test32 " $tmp_dir " 20 -O ^64bit
4445mkimage test64 " $tmp_dir " 20 -O 64bit
4546
46- rm -f " $tmp_dir " /test* .txt
47+ rm -f " $tmp_dir " /test* .txt " $tmp_dir " /symlink.txt
4748echo " [test] Generating files..."
4849
4950echo " [test] Making image test_htree..."
Original file line number Diff line number Diff line change 1- # pyright: reportImportCycles=false
21import errno
32import io
43import os
Original file line number Diff line number Diff line change 1- # pyright: reportImportCycles=false
21from ctypes import (
32 c_uint16 ,
43 c_uint32 ,
Original file line number Diff line number Diff line change 1- # pyright: reportImportCycles=false
21from ctypes import (
32 addressof ,
43 c_char ,
Original file line number Diff line number Diff line change 1- # pyright: reportImportCycles=false
21from ctypes import (
32 c_uint8 ,
43 c_uint16 ,
Original file line number Diff line number Diff line change 1- # pyright: reportImportCycles=false
21from collections .abc import Iterator
32from ctypes import (
43 c_uint16 ,
Original file line number Diff line number Diff line change 1- # pyright: reportImportCycles=false
21import warnings
32from collections .abc import Generator
43from ctypes import (
Original file line number Diff line number Diff line change 1- # pyright: reportImportCycles=false
21from __future__ import annotations
32
43import errno
@@ -74,6 +73,10 @@ class InodeError(Exception):
7473 pass
7574
7675
76+ class MalformedInodeError (Exception ):
77+ pass
78+
79+
7780@final
7881class Linux1 (LittleEndianStructure ):
7982 _pack_ = 1
@@ -482,8 +485,22 @@ def open(
482485
483486
484487class SymbolicLink (Inode ):
488+ @property
489+ def is_fast_symlink (self ) -> bool :
490+ i_blocks_lo = assert_cast (self .i_blocks_lo , int ) # pyright: ignore[reportAny]
491+ return i_blocks_lo == 0 and not self .is_inline
492+
485493 def readlink (self ) -> bytes :
486- return self ._open ().read ()
494+ if not self .is_fast_symlink :
495+ return self ._open ().read ()
496+
497+ if self .i_size > Inode .i_block .size :
498+ raise MalformedInodeError (
499+ f"Fast symlink target too large: { self .i_size } > { Inode .i_block .size } "
500+ )
501+
502+ _ = self .volume .seek (self .offset + Inode .i_block .offset )
503+ return self .volume .read (self .i_size )
487504
488505
489506class Directory (Inode ):
Original file line number Diff line number Diff line change 1- # pyright: reportImportCycles=false
21import ctypes
32import errno
43import warnings
Original file line number Diff line number Diff line change 1- # pyright: reportImportCycles=false
21from ctypes import (
32 c_ubyte ,
43 c_uint8 ,
You can’t perform that action at this time.
0 commit comments