|
1 | 1 | pub use libc::{dev_t, mode_t};
|
| 2 | +#[cfg(any(target_os = "macos", target_os = "ios", target_os = "openbsd"))] |
| 3 | +pub use libc::c_uint; |
| 4 | +#[cfg(any( |
| 5 | + target_os = "netbsd", |
| 6 | + target_os = "freebsd", |
| 7 | + target_os = "dragonfly" |
| 8 | +))] |
| 9 | +pub use libc::c_ulong; |
2 | 10 | pub use libc::stat as FileStat;
|
3 | 11 |
|
4 | 12 | use crate::{Result, NixPath, errno::Errno};
|
@@ -43,6 +51,110 @@ libc_bitflags! {
|
43 | 51 | }
|
44 | 52 | }
|
45 | 53 |
|
| 54 | +#[cfg(any(target_os = "macos", target_os = "ios", target_os="openbsd"))] |
| 55 | +pub type type_of_file_flag = c_uint; |
| 56 | +#[cfg(any( |
| 57 | + target_os = "netbsd", |
| 58 | + target_os = "freebsd", |
| 59 | + target_os = "dragonfly" |
| 60 | +))] |
| 61 | +pub type type_of_file_flag = c_ulong; |
| 62 | + |
| 63 | +#[cfg(any( |
| 64 | + target_os = "openbsd", |
| 65 | + target_os = "netbsd", |
| 66 | + target_os = "freebsd", |
| 67 | + target_os = "dragonfly", |
| 68 | + target_os = "macos", |
| 69 | + target_os = "ios" |
| 70 | +))] |
| 71 | +libc_bitflags! { |
| 72 | + /// File flags. |
| 73 | + #[cfg_attr(docsrs, doc(cfg(all())))] |
| 74 | + pub struct FileFlag: type_of_file_flag { |
| 75 | + /// The file may only be appended to. |
| 76 | + SF_APPEND; |
| 77 | + /// The file has been archived. |
| 78 | + SF_ARCHIVED; |
| 79 | + #[cfg(any(target_os = "dragonfly"))] |
| 80 | + SF_CACHE; |
| 81 | + /// The file may not be changed. |
| 82 | + SF_IMMUTABLE; |
| 83 | + /// Indicates a WAPBL journal file. |
| 84 | + #[cfg(any(target_os = "netbsd"))] |
| 85 | + SF_LOG; |
| 86 | + /// Do not retain history for file |
| 87 | + #[cfg(any(target_os = "dragonfly"))] |
| 88 | + SF_NOHISTORY; |
| 89 | + /// The file may not be renamed or deleted. |
| 90 | + #[cfg(any(target_os = "freebsd", target_os = "dragonfly"))] |
| 91 | + SF_NOUNLINK; |
| 92 | + /// Mask of superuser changeable flags |
| 93 | + SF_SETTABLE; |
| 94 | + /// Snapshot is invalid. |
| 95 | + #[cfg(any(target_os = "netbsd"))] |
| 96 | + SF_SNAPINVAL; |
| 97 | + /// The file is a snapshot file. |
| 98 | + #[cfg(any(target_os = "netbsd", target_os = "freebsd"))] |
| 99 | + SF_SNAPSHOT; |
| 100 | + #[cfg(any(target_os = "dragonfly"))] |
| 101 | + SF_XLINK; |
| 102 | + /// The file may only be appended to. |
| 103 | + UF_APPEND; |
| 104 | + /// The file needs to be archived. |
| 105 | + #[cfg(any(target_os = "freebsd"))] |
| 106 | + UF_ARCHIVE; |
| 107 | + #[cfg(any(target_os = "dragonfly"))] |
| 108 | + UF_CACHE; |
| 109 | + /// File is compressed at the file system level. |
| 110 | + #[cfg(any(target_os = "macos", target_os = "ios"))] |
| 111 | + UF_COMPRESSED; |
| 112 | + /// The file may be hidden from directory listings at the application's |
| 113 | + /// discretion. |
| 114 | + #[cfg(any( |
| 115 | + target_os = "freebsd", |
| 116 | + target_os = "macos", |
| 117 | + target_os = "ios", |
| 118 | + ))] |
| 119 | + UF_HIDDEN; |
| 120 | + /// The file may not be changed. |
| 121 | + UF_IMMUTABLE; |
| 122 | + /// Do not dump the file. |
| 123 | + UF_NODUMP; |
| 124 | + #[cfg(any(target_os = "dragonfly"))] |
| 125 | + UF_NOHISTORY; |
| 126 | + /// The file may not be renamed or deleted. |
| 127 | + #[cfg(any(target_os = "freebsd", target_os = "dragonfly"))] |
| 128 | + UF_NOUNLINK; |
| 129 | + /// The file is offline, or has the Windows and CIFS |
| 130 | + /// `FILE_ATTRIBUTE_OFFLINE` attribute. |
| 131 | + #[cfg(any(target_os = "freebsd"))] |
| 132 | + UF_OFFLINE; |
| 133 | + /// The directory is opaque when viewed through a union stack. |
| 134 | + UF_OPAQUE; |
| 135 | + /// The file is read only, and may not be written or appended. |
| 136 | + #[cfg(any(target_os = "freebsd"))] |
| 137 | + UF_READONLY; |
| 138 | + /// The file contains a Windows reparse point. |
| 139 | + #[cfg(any(target_os = "freebsd"))] |
| 140 | + UF_REPARSE; |
| 141 | + /// Mask of owner changeable flags. |
| 142 | + UF_SETTABLE; |
| 143 | + /// The file has the Windows `FILE_ATTRIBUTE_SPARSE_FILE` attribute. |
| 144 | + #[cfg(any(target_os = "freebsd"))] |
| 145 | + UF_SPARSE; |
| 146 | + /// The file has the DOS, Windows and CIFS `FILE_ATTRIBUTE_SYSTEM` |
| 147 | + /// attribute. |
| 148 | + #[cfg(any(target_os = "freebsd"))] |
| 149 | + UF_SYSTEM; |
| 150 | + /// File renames and deletes are tracked. |
| 151 | + #[cfg(any(target_os = "macos", target_os = "ios"))] |
| 152 | + UF_TRACKED; |
| 153 | + #[cfg(any(target_os = "dragonfly"))] |
| 154 | + UF_XLINK; |
| 155 | + } |
| 156 | +} |
| 157 | + |
46 | 158 | /// Create a special or ordinary file, by pathname.
|
47 | 159 | pub fn mknod<P: ?Sized + NixPath>(path: &P, kind: SFlag, perm: Mode, dev: dev_t) -> Result<()> {
|
48 | 160 | let res = path.with_nix_path(|cstr| unsafe {
|
|
0 commit comments