|
| 1 | +// This file is compiled ONLY on Windows (when WINDOWS_BUILD is defined) |
| 2 | +// It provides stub implementations of Mono.Unix types that throw PlatformNotSupportedException |
| 3 | +// since Unix-specific operations should never be called on Windows (protected by runtime guards) |
| 4 | + |
| 5 | +#if WINDOWS_BUILD |
| 6 | + |
| 7 | +using System; |
| 8 | +using System.IO; |
| 9 | +using Microsoft.Win32.SafeHandles; |
| 10 | + |
| 11 | +namespace Mono.Unix |
| 12 | +{ |
| 13 | + [Flags] |
| 14 | + internal enum FileAccessPermissions |
| 15 | + { |
| 16 | + None = 0, |
| 17 | + OtherExecute = 1, |
| 18 | + OtherWrite = 2, |
| 19 | + OtherRead = 4, |
| 20 | + OtherReadWriteExecute = 7, |
| 21 | + GroupExecute = 8, |
| 22 | + GroupWrite = 16, |
| 23 | + GroupRead = 32, |
| 24 | + GroupReadWriteExecute = 56, |
| 25 | + UserExecute = 64, |
| 26 | + UserWrite = 128, |
| 27 | + UserRead = 256, |
| 28 | + UserReadWrite = 384, |
| 29 | + UserReadWriteExecute = 448, |
| 30 | + AllPermissions = 511, |
| 31 | + DefaultPermissions = 420 |
| 32 | + } |
| 33 | + |
| 34 | + internal class UnixStream : Stream |
| 35 | + { |
| 36 | + private const string ErrorMessage = "Unix file operations are not supported on Windows"; |
| 37 | + |
| 38 | + public UnixUserInfo OwnerUser => throw new PlatformNotSupportedException(ErrorMessage); |
| 39 | + public UnixGroupInfo OwnerGroup => throw new PlatformNotSupportedException(ErrorMessage); |
| 40 | + public long OwnerUserId => throw new PlatformNotSupportedException(ErrorMessage); |
| 41 | + public long OwnerGroupId => throw new PlatformNotSupportedException(ErrorMessage); |
| 42 | + public FileAccessPermissions FileAccessPermissions => throw new PlatformNotSupportedException(ErrorMessage); |
| 43 | + |
| 44 | + public override bool CanRead => throw new PlatformNotSupportedException(ErrorMessage); |
| 45 | + public override bool CanSeek => throw new PlatformNotSupportedException(ErrorMessage); |
| 46 | + public override bool CanWrite => throw new PlatformNotSupportedException(ErrorMessage); |
| 47 | + public override long Length => throw new PlatformNotSupportedException(ErrorMessage); |
| 48 | + public override long Position |
| 49 | + { |
| 50 | + get => throw new PlatformNotSupportedException(ErrorMessage); |
| 51 | + set => throw new PlatformNotSupportedException(ErrorMessage); |
| 52 | + } |
| 53 | + |
| 54 | + public override void Flush() => throw new PlatformNotSupportedException(ErrorMessage); |
| 55 | + public override int Read(byte[] buffer, int offset, int count) => throw new PlatformNotSupportedException(ErrorMessage); |
| 56 | + public override long Seek(long offset, SeekOrigin origin) => throw new PlatformNotSupportedException(ErrorMessage); |
| 57 | + public override void SetLength(long value) => throw new PlatformNotSupportedException(ErrorMessage); |
| 58 | + public override void Write(byte[] buffer, int offset, int count) => throw new PlatformNotSupportedException(ErrorMessage); |
| 59 | + } |
| 60 | + |
| 61 | + internal class UnixFileInfo |
| 62 | + { |
| 63 | + private const string ErrorMessage = "Unix file operations are not supported on Windows"; |
| 64 | + |
| 65 | + public UnixFileInfo(string path) |
| 66 | + { |
| 67 | + throw new PlatformNotSupportedException(ErrorMessage); |
| 68 | + } |
| 69 | + |
| 70 | + public string FullName => throw new PlatformNotSupportedException(ErrorMessage); |
| 71 | + public bool Exists => throw new PlatformNotSupportedException(ErrorMessage); |
| 72 | + public FileAccessPermissions FileAccessPermissions => throw new PlatformNotSupportedException(ErrorMessage); |
| 73 | + public long OwnerUserId => throw new PlatformNotSupportedException(ErrorMessage); |
| 74 | + public UnixUserInfo OwnerUser => throw new PlatformNotSupportedException(ErrorMessage); |
| 75 | + public long Length => throw new PlatformNotSupportedException(ErrorMessage); |
| 76 | + |
| 77 | + public Stream Create(FileAccessPermissions permissions) |
| 78 | + => throw new PlatformNotSupportedException(ErrorMessage); |
| 79 | + |
| 80 | + public UnixStream OpenRead() |
| 81 | + => throw new PlatformNotSupportedException(ErrorMessage); |
| 82 | + |
| 83 | + public UnixStream Open(FileMode mode, FileAccess access, Native.FilePermissions permissions) |
| 84 | + => throw new PlatformNotSupportedException(ErrorMessage); |
| 85 | + } |
| 86 | + |
| 87 | + internal class UnixDirectoryInfo |
| 88 | + { |
| 89 | + private const string ErrorMessage = "Unix directory operations are not supported on Windows"; |
| 90 | + |
| 91 | + public UnixDirectoryInfo(string path) |
| 92 | + { |
| 93 | + throw new PlatformNotSupportedException(ErrorMessage); |
| 94 | + } |
| 95 | + |
| 96 | + public string FullName => throw new PlatformNotSupportedException(ErrorMessage); |
| 97 | + public bool Exists => throw new PlatformNotSupportedException(ErrorMessage); |
| 98 | + public FileAccessPermissions FileAccessPermissions => throw new PlatformNotSupportedException(ErrorMessage); |
| 99 | + public long OwnerUserId => throw new PlatformNotSupportedException(ErrorMessage); |
| 100 | + public UnixUserInfo OwnerUser => throw new PlatformNotSupportedException(ErrorMessage); |
| 101 | + |
| 102 | + public void Create(FileAccessPermissions permissions) |
| 103 | + => throw new PlatformNotSupportedException(ErrorMessage); |
| 104 | + } |
| 105 | + |
| 106 | + internal class UnixUserInfo |
| 107 | + { |
| 108 | + private const string ErrorMessage = "Unix user operations are not supported on Windows"; |
| 109 | + |
| 110 | + public UnixUserInfo(long userId) |
| 111 | + { |
| 112 | + throw new PlatformNotSupportedException(ErrorMessage); |
| 113 | + } |
| 114 | + |
| 115 | + public long UserId => throw new PlatformNotSupportedException(ErrorMessage); |
| 116 | + } |
| 117 | + |
| 118 | + internal class UnixGroupInfo |
| 119 | + { |
| 120 | + private const string ErrorMessage = "Unix group operations are not supported on Windows"; |
| 121 | + |
| 122 | + public UnixGroupInfo(long groupId) |
| 123 | + { |
| 124 | + throw new PlatformNotSupportedException(ErrorMessage); |
| 125 | + } |
| 126 | + |
| 127 | + public long GroupId => throw new PlatformNotSupportedException(ErrorMessage); |
| 128 | + } |
| 129 | +} |
| 130 | + |
| 131 | +namespace Mono.Unix.Native |
| 132 | +{ |
| 133 | + [Flags] |
| 134 | + internal enum FilePermissions |
| 135 | + { |
| 136 | + S_ISUID = 0x0800, |
| 137 | + S_ISGID = 0x0400, |
| 138 | + S_ISVTX = 0x0200, |
| 139 | + S_IRUSR = 0x0100, |
| 140 | + S_IWUSR = 0x0080, |
| 141 | + S_IXUSR = 0x0040, |
| 142 | + S_IRGRP = 0x0020, |
| 143 | + S_IWGRP = 0x0010, |
| 144 | + S_IXGRP = 0x0008, |
| 145 | + S_IROTH = 0x0004, |
| 146 | + S_IWOTH = 0x0002, |
| 147 | + S_IXOTH = 0x0001, |
| 148 | + |
| 149 | + S_IRWXU = S_IRUSR | S_IWUSR | S_IXUSR, |
| 150 | + S_IRWXG = S_IRGRP | S_IWGRP | S_IXGRP, |
| 151 | + S_IRWXO = S_IROTH | S_IWOTH | S_IXOTH, |
| 152 | + |
| 153 | + ACCESSPERMS = S_IRWXU | S_IRWXG | S_IRWXO, |
| 154 | + ALLPERMS = S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO, |
| 155 | + DEFFILEMODE = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH |
| 156 | + } |
| 157 | + |
| 158 | + internal static class Syscall |
| 159 | + { |
| 160 | + private const string ErrorMessage = "Unix syscalls are not supported on Windows"; |
| 161 | + |
| 162 | + public static int mkdir(string path, FilePermissions permissions) |
| 163 | + => throw new PlatformNotSupportedException(ErrorMessage); |
| 164 | + |
| 165 | + public static long chown(string path, int userId, int groupId) |
| 166 | + => throw new PlatformNotSupportedException(ErrorMessage); |
| 167 | + |
| 168 | + public static long chmod(string path, FilePermissions permissions) |
| 169 | + => throw new PlatformNotSupportedException(ErrorMessage); |
| 170 | + |
| 171 | + public static long getuid() |
| 172 | + => throw new PlatformNotSupportedException(ErrorMessage); |
| 173 | + |
| 174 | + public static long getgid() |
| 175 | + => throw new PlatformNotSupportedException(ErrorMessage); |
| 176 | + |
| 177 | + public static long geteuid() |
| 178 | + => throw new PlatformNotSupportedException(ErrorMessage); |
| 179 | + |
| 180 | + public static long getegid() |
| 181 | + => throw new PlatformNotSupportedException(ErrorMessage); |
| 182 | + } |
| 183 | +} |
| 184 | + |
| 185 | +#endif |
| 186 | + |
0 commit comments