Debian Codegraph @

contrib/bindings/python/pathrs/_libpathrs_cffi/lib.pyi

raw symbols SCIP
1 # SPDX-License-Identifier: MPL-2.0
2 #
3 # libpathrs: safe path resolution on Linux
4 # Copyright (C) 2019-2025 SUSE LLC
5 # Copyright (C) 2026 Aleksa Sarai <[email protected]>
6 #
7 # This Source Code Form is subject to the terms of the Mozilla Public
8 # License, v. 2.0. If a copy of the MPL was not distributed with this
9 # file, You can obtain one at https://mozilla.org/MPL/2.0/.
10
11 from typing import type_check_only, Union
12
13 # TODO: Remove this once we only support Python >= 3.10.
14 from typing_extensions import TypeAlias, Literal
15
16 from .._pathrs import CBuffer, CString
17 from ..procfs import ProcfsBase
18
19 RawFd: TypeAlias = int
20
21 # pathrs_errorinfo_t *
22 @type_check_only
23 class CError:
24 saved_errno: int
25 description: CString
26
27 ErrorId: TypeAlias = int
28 __PATHRS_MAX_ERR_VALUE: ErrorId
29
30 # TODO: We actually return Union[CError, cffi.FFI.NULL] but we can't express
31 # this using the typing stubs for CFFI...
32 def pathrs_errorinfo(err_id: Union[ErrorId, int]) -> CError: ...
33 def pathrs_errorinfo_free(err: CError) -> None: ...
34
35 # pathrs_version_info_t *
36 @type_check_only
37 class VersionInfo:
38 version_string: CString
39
40 def pathrs_version(info: VersionInfo, size: int) -> Union[ErrorId, int]: ...
41
42 # uint64_t
43 ProcfsOpenFlags: TypeAlias = int
44 PATHRS_PROCFS_NEW_UNMASKED: ProcfsOpenFlags
45
46 # pathrs_procfs_open_how *
47 @type_check_only
48 class ProcfsOpenHow:
49 flags: ProcfsOpenFlags
50
51 PATHRS_PROC_ROOT: ProcfsBase
52 PATHRS_PROC_SELF: ProcfsBase
53 PATHRS_PROC_THREAD_SELF: ProcfsBase
54
55 __PATHRS_PROC_TYPE_MASK: ProcfsBase
56 __PATHRS_PROC_TYPE_PID: ProcfsBase
57
58 PATHRS_PROC_DEFAULT_ROOTFD: RawFd
59
60 # procfs API
61 def pathrs_procfs_open(how: ProcfsOpenHow, size: int) -> Union[RawFd, ErrorId]: ...
62 def pathrs_proc_open(
63 base: ProcfsBase, path: CString, flags: int
64 ) -> Union[RawFd, ErrorId]: ...
65 def pathrs_proc_openat(
66 proc_root_fd: RawFd, base: ProcfsBase, path: CString, flags: int
67 ) -> Union[RawFd, ErrorId]: ...
68 def pathrs_proc_readlink(
69 base: ProcfsBase, path: CString, linkbuf: CBuffer, linkbuf_size: int
70 ) -> Union[int, ErrorId]: ...
71 def pathrs_proc_readlinkat(
72 proc_root_fd: RawFd,
73 base: ProcfsBase,
74 path: CString,
75 linkbuf: CBuffer,
76 linkbuf_size: int,
77 ) -> Union[int, ErrorId]: ...
78
79 # core API
80 def pathrs_open_root(path: CString) -> Union[RawFd, ErrorId]: ...
81 def pathrs_reopen(fd: RawFd, flags: int) -> Union[RawFd, ErrorId]: ...
82 def pathrs_inroot_resolve(rootfd: RawFd, path: CString) -> Union[RawFd, ErrorId]: ...
83 def pathrs_inroot_resolve_nofollow(
84 rootfd: RawFd, path: CString
85 ) -> Union[RawFd, ErrorId]: ...
86 def pathrs_inroot_open(
87 rootfd: RawFd, path: CString, flags: int
88 ) -> Union[RawFd, ErrorId]: ...
89 def pathrs_inroot_creat(
90 rootfd: RawFd, path: CString, flags: int, filemode: int
91 ) -> Union[RawFd, ErrorId]: ...
92 def pathrs_inroot_rename(
93 old_rootfd: RawFd,
94 old_path: CString,
95 new_rootfd: RawFd,
96 new_path: CString,
97 flags: int,
98 ) -> Union[Literal[0], ErrorId]: ...
99 def pathrs_inroot_rmdir(rootfd: RawFd, path: CString) -> Union[Literal[0], ErrorId]: ...
100 def pathrs_inroot_unlink(
101 rootfd: RawFd, path: CString
102 ) -> Union[Literal[0], ErrorId]: ...
103 def pathrs_inroot_remove_all(rootfd: RawFd, path: CString) -> Union[RawFd, ErrorId]: ...
104 def pathrs_inroot_mkdir(
105 rootfd: RawFd, path: CString, mode: int
106 ) -> Union[Literal[0], ErrorId]: ...
107 def pathrs_inroot_mkdir_all(
108 rootfd: RawFd, path: CString, mode: int
109 ) -> Union[Literal[0], ErrorId]: ...
110 def pathrs_inroot_mknod(
111 rootfd: RawFd, path: CString, mode: int, dev: int
112 ) -> Union[Literal[0], ErrorId]: ...
113 def pathrs_inroot_hardlink(
114 old_rootfd: RawFd,
115 old_path: CString,
116 new_rootfd: RawFd,
117 new_path: CString,
118 flags: int,
119 ) -> Union[Literal[0], ErrorId]: ...
120 def pathrs_inroot_symlink(
121 target: CString,
122 rootfd: RawFd,
123 linkpath: CString,
124 ) -> Union[Literal[0], ErrorId]: ...
125 def pathrs_inroot_readlink(
126 rootfd: RawFd, path: CString, linkbuf: CBuffer, linkbuf_size: int
127 ) -> Union[int, ErrorId]: ...