/rust/registry/src/index.crates.io-6f17d22bba15001f/rustix-0.38.34/src/fs/xattr.rs
Line | Count | Source (jump to first uncovered line) |
1 | | use crate::{backend, io, path}; |
2 | | use backend::c; |
3 | | use backend::fd::AsFd; |
4 | | use bitflags::bitflags; |
5 | | |
6 | | bitflags! { |
7 | | /// `XATTR_*` constants for use with [`setxattr`], and other `*setxattr` |
8 | | /// functions. |
9 | | #[repr(transparent)] |
10 | | #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] |
11 | | pub struct XattrFlags: c::c_uint { |
12 | | /// `XATTR_CREATE` |
13 | | const CREATE = c::XATTR_CREATE as c::c_uint; |
14 | | |
15 | | /// `XATTR_REPLACE` |
16 | | const REPLACE = c::XATTR_REPLACE as c::c_uint; |
17 | | |
18 | | /// <https://docs.rs/bitflags/*/bitflags/#externally-defined-flags> |
19 | | const _ = !0; |
20 | | } |
21 | | } |
22 | | |
23 | | /// `getxattr(path, name, value.as_ptr(), value.len())`—Get extended |
24 | | /// filesystem attributes. |
25 | | /// |
26 | | /// # References |
27 | | /// - [Linux] |
28 | | /// |
29 | | /// [Linux]: https://man7.org/linux/man-pages/man2/getxattr.2.html |
30 | | #[inline] |
31 | 0 | pub fn getxattr<P: path::Arg, Name: path::Arg>( |
32 | 0 | path: P, |
33 | 0 | name: Name, |
34 | 0 | value: &mut [u8], |
35 | 0 | ) -> io::Result<usize> { |
36 | 0 | path.into_with_c_str(|path| { |
37 | 0 | name.into_with_c_str(|name| backend::fs::syscalls::getxattr(path, name, value)) |
38 | 0 | }) |
39 | 0 | } |
40 | | |
41 | | /// `lgetxattr(path, name, value.as_ptr(), value.len())`—Get extended |
42 | | /// filesystem attributes, without following symlinks in the last path |
43 | | /// component. |
44 | | /// |
45 | | /// # References |
46 | | /// - [Linux] |
47 | | /// |
48 | | /// [Linux]: https://man7.org/linux/man-pages/man2/lgetxattr.2.html |
49 | | #[inline] |
50 | 0 | pub fn lgetxattr<P: path::Arg, Name: path::Arg>( |
51 | 0 | path: P, |
52 | 0 | name: Name, |
53 | 0 | value: &mut [u8], |
54 | 0 | ) -> io::Result<usize> { |
55 | 0 | path.into_with_c_str(|path| { |
56 | 0 | name.into_with_c_str(|name| backend::fs::syscalls::lgetxattr(path, name, value)) |
57 | 0 | }) |
58 | 0 | } |
59 | | |
60 | | /// `fgetxattr(fd, name, value.as_ptr(), value.len())`—Get extended |
61 | | /// filesystem attributes on an open file descriptor. |
62 | | /// |
63 | | /// # References |
64 | | /// - [Linux] |
65 | | /// |
66 | | /// [Linux]: https://man7.org/linux/man-pages/man2/fgetxattr.2.html |
67 | | #[inline] |
68 | 0 | pub fn fgetxattr<Fd: AsFd, Name: path::Arg>( |
69 | 0 | fd: Fd, |
70 | 0 | name: Name, |
71 | 0 | value: &mut [u8], |
72 | 0 | ) -> io::Result<usize> { |
73 | 0 | name.into_with_c_str(|name| backend::fs::syscalls::fgetxattr(fd.as_fd(), name, value)) |
74 | 0 | } |
75 | | |
76 | | /// `setxattr(path, name, value.as_ptr(), value.len(), flags)`—Set extended |
77 | | /// filesystem attributes. |
78 | | /// |
79 | | /// # References |
80 | | /// - [Linux] |
81 | | /// |
82 | | /// [Linux]: https://man7.org/linux/man-pages/man2/setxattr.2.html |
83 | | #[inline] |
84 | 0 | pub fn setxattr<P: path::Arg, Name: path::Arg>( |
85 | 0 | path: P, |
86 | 0 | name: Name, |
87 | 0 | value: &[u8], |
88 | 0 | flags: XattrFlags, |
89 | 0 | ) -> io::Result<()> { |
90 | 0 | path.into_with_c_str(|path| { |
91 | 0 | name.into_with_c_str(|name| backend::fs::syscalls::setxattr(path, name, value, flags)) |
92 | 0 | }) |
93 | 0 | } |
94 | | |
95 | | /// `setxattr(path, name, value.as_ptr(), value.len(), flags)`—Set extended |
96 | | /// filesystem attributes, without following symlinks in the last path |
97 | | /// component. |
98 | | /// |
99 | | /// # References |
100 | | /// - [Linux] |
101 | | /// |
102 | | /// [Linux]: https://man7.org/linux/man-pages/man2/lsetxattr.2.html |
103 | | #[inline] |
104 | 0 | pub fn lsetxattr<P: path::Arg, Name: path::Arg>( |
105 | 0 | path: P, |
106 | 0 | name: Name, |
107 | 0 | value: &[u8], |
108 | 0 | flags: XattrFlags, |
109 | 0 | ) -> io::Result<()> { |
110 | 0 | path.into_with_c_str(|path| { |
111 | 0 | name.into_with_c_str(|name| backend::fs::syscalls::lsetxattr(path, name, value, flags)) |
112 | 0 | }) |
113 | 0 | } |
114 | | |
115 | | /// `fsetxattr(fd, name, value.as_ptr(), value.len(), flags)`—Set extended |
116 | | /// filesystem attributes on an open file descriptor. |
117 | | /// |
118 | | /// # References |
119 | | /// - [Linux] |
120 | | /// |
121 | | /// [Linux]: https://man7.org/linux/man-pages/man2/fsetxattr.2.html |
122 | | #[inline] |
123 | 0 | pub fn fsetxattr<Fd: AsFd, Name: path::Arg>( |
124 | 0 | fd: Fd, |
125 | 0 | name: Name, |
126 | 0 | value: &[u8], |
127 | 0 | flags: XattrFlags, |
128 | 0 | ) -> io::Result<()> { |
129 | 0 | name.into_with_c_str(|name| backend::fs::syscalls::fsetxattr(fd.as_fd(), name, value, flags)) |
130 | 0 | } |
131 | | |
132 | | /// `listxattr(path, list.as_ptr(), list.len())`—List extended filesystem |
133 | | /// attributes. |
134 | | /// |
135 | | /// # References |
136 | | /// - [Linux] |
137 | | /// |
138 | | /// [Linux]: https://man7.org/linux/man-pages/man2/listxattr.2.html |
139 | | #[inline] |
140 | 0 | pub fn listxattr<P: path::Arg>(path: P, list: &mut [c::c_char]) -> io::Result<usize> { |
141 | 0 | path.into_with_c_str(|path| backend::fs::syscalls::listxattr(path, list)) |
142 | 0 | } |
143 | | |
144 | | /// `llistxattr(path, list.as_ptr(), list.len())`—List extended filesystem |
145 | | /// attributes, without following symlinks in the last path component. |
146 | | /// |
147 | | /// # References |
148 | | /// - [Linux] |
149 | | /// |
150 | | /// [Linux]: https://man7.org/linux/man-pages/man2/llistxattr.2.html |
151 | | #[inline] |
152 | 0 | pub fn llistxattr<P: path::Arg>(path: P, list: &mut [c::c_char]) -> io::Result<usize> { |
153 | 0 | path.into_with_c_str(|path| backend::fs::syscalls::llistxattr(path, list)) |
154 | 0 | } |
155 | | |
156 | | /// `flistxattr(fd, list.as_ptr(), list.len())`—List extended filesystem |
157 | | /// attributes on an open file descriptor. |
158 | | /// |
159 | | /// # References |
160 | | /// - [Linux] |
161 | | /// |
162 | | /// [Linux]: https://man7.org/linux/man-pages/man2/flistxattr.2.html |
163 | | #[inline] |
164 | 0 | pub fn flistxattr<Fd: AsFd>(fd: Fd, list: &mut [c::c_char]) -> io::Result<usize> { |
165 | 0 | backend::fs::syscalls::flistxattr(fd.as_fd(), list) |
166 | 0 | } |
167 | | |
168 | | /// `removexattr(path, name)`—Remove an extended filesystem attribute. |
169 | | /// |
170 | | /// # References |
171 | | /// - [Linux] |
172 | | /// |
173 | | /// [Linux]: https://man7.org/linux/man-pages/man2/removexattr.2.html |
174 | 0 | pub fn removexattr<P: path::Arg, Name: path::Arg>(path: P, name: Name) -> io::Result<()> { |
175 | 0 | path.into_with_c_str(|path| { |
176 | 0 | name.into_with_c_str(|name| backend::fs::syscalls::removexattr(path, name)) |
177 | 0 | }) |
178 | 0 | } |
179 | | |
180 | | /// `lremovexattr(path, name)`—Remove an extended filesystem attribute, |
181 | | /// without following symlinks in the last path component. |
182 | | /// |
183 | | /// # References |
184 | | /// - [Linux] |
185 | | /// |
186 | | /// [Linux]: https://man7.org/linux/man-pages/man2/lremovexattr.2.html |
187 | 0 | pub fn lremovexattr<P: path::Arg, Name: path::Arg>(path: P, name: Name) -> io::Result<()> { |
188 | 0 | path.into_with_c_str(|path| { |
189 | 0 | name.into_with_c_str(|name| backend::fs::syscalls::lremovexattr(path, name)) |
190 | 0 | }) |
191 | 0 | } |
192 | | |
193 | | /// `fremovexattr(fd, name)`—Remove an extended filesystem attribute on an |
194 | | /// open file descriptor. |
195 | | /// |
196 | | /// # References |
197 | | /// - [Linux] |
198 | | /// |
199 | | /// [Linux]: https://man7.org/linux/man-pages/man2/fremovexattr.2.html |
200 | 0 | pub fn fremovexattr<Fd: AsFd, Name: path::Arg>(fd: Fd, name: Name) -> io::Result<()> { |
201 | 0 | name.into_with_c_str(|name| backend::fs::syscalls::fremovexattr(fd.as_fd(), name)) |
202 | 0 | } |