-
Notifications
You must be signed in to change notification settings - Fork 5.1k
use fstatfs to detect whether current file system supports shared locks for files opened for writing #55256
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
use fstatfs to detect whether current file system supports shared locks for files opened for writing #55256
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
71d131a
use fstatfs to detect whether current file system supports shared loc…
adamsitnik 7980cc8
improve comments
adamsitnik 97c1544
cast in explicit way
adamsitnik 5d95af8
hopefully fix the BSD build(s)
adamsitnik d64374f
fix OSX build
adamsitnik c687e6a
assume we should not acquire the lock if we don't know the File System
adamsitnik 9c481ed
try to fix the maccatalyst build
adamsitnik 1c890ec
always use fstatfs as it's available on every platform and can get us…
adamsitnik 04eced6
handle SMB2_SUPER_MAGIC as well (#53182)
adamsitnik 79b6def
introduce a flag that allows to disable file locking on Unix
adamsitnik ba6d027
Emscripten does not support file locking, so there is no need to chec…
adamsitnik 731e65c
some polishing
adamsitnik d31f6e1
Merge remote-tracking branch 'upstream/main' into superMagic
adamsitnik c752b93
reuse the UnixFileSystemTypes enum, move it to a separate file so Cor…
adamsitnik 7443a5e
add SMB2_SUPER_MAGIC to the enum
adamsitnik 1e3878c
don't try to unlock the file if it has not been locked
adamsitnik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
145 changes: 145 additions & 0 deletions
145
src/libraries/Common/src/Interop/Unix/System.Native/Interop.UnixFileSystemTypes.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Runtime.InteropServices; | ||
using Microsoft.Win32.SafeHandles; | ||
|
||
internal static partial class Interop | ||
{ | ||
internal static partial class Sys | ||
{ | ||
/// <summary> | ||
/// Internal FileSystem names and magic numbers taken from man(2) statfs | ||
/// </summary> | ||
/// <remarks> | ||
/// These value names MUST be kept in sync with those in GetDriveType (moved to Interop.MountPoints.FormatInfo.cs), | ||
/// where this enum must be a subset of the GetDriveType list, with the enum | ||
/// values here exactly matching a string there. | ||
/// </remarks> | ||
internal enum UnixFileSystemTypes : long | ||
{ | ||
adfs = 0xADF5, | ||
affs = 0xADFF, | ||
afs = 0x5346414F, | ||
anoninode = 0x09041934, | ||
aufs = 0x61756673, | ||
autofs = 0x0187, | ||
autofs4 = 0x6D4A556D, | ||
befs = 0x42465331, | ||
bdevfs = 0x62646576, | ||
bfs = 0x1BADFACE, | ||
binfmt_misc = 0x42494E4D, | ||
bootfs = 0xA56D3FF9, | ||
btrfs = 0x9123683E, | ||
ceph = 0x00C36400, | ||
cgroupfs = 0x0027E0EB, | ||
cgroup2fs = 0x63677270, | ||
cifs = 0xFF534D42, | ||
coda = 0x73757245, | ||
coherent = 0x012FF7B7, | ||
configfs = 0x62656570, | ||
cramfs = 0x28CD3D45, | ||
debugfs = 0x64626720, | ||
devfs = 0x1373, | ||
devpts = 0x1CD1, | ||
ecryptfs = 0xF15F, | ||
efs = 0x00414A53, | ||
exofs = 0x5DF5, | ||
ext = 0x137D, | ||
ext2_old = 0xEF51, | ||
ext2 = 0xEF53, | ||
ext3 = 0xEF53, | ||
ext4 = 0xEF53, | ||
fat = 0x4006, | ||
fd = 0xF00D1E, | ||
fhgfs = 0x19830326, | ||
fuse = 0x65735546, | ||
fuseblk = 0x65735546, | ||
fusectl = 0x65735543, | ||
futexfs = 0x0BAD1DEA, | ||
gfsgfs2 = 0x1161970, | ||
gfs2 = 0x01161970, | ||
gpfs = 0x47504653, | ||
hfs = 0x4244, | ||
hfsplus = 0x482B, | ||
hpfs = 0xF995E849, | ||
hugetlbfs = 0x958458F6, | ||
inodefs = 0x11307854, | ||
inotifyfs = 0x2BAD1DEA, | ||
isofs = 0x9660, | ||
// isofs = 0x4004, // R_WIN | ||
// isofs = 0x4000, // WIN | ||
jffs = 0x07C0, | ||
jffs2 = 0x72B6, | ||
jfs = 0x3153464A, | ||
kafs = 0x6B414653, | ||
lofs = 0xEF53, /* loopback filesystem, magic same as ext2 */ | ||
logfs = 0xC97E8168, | ||
lustre = 0x0BD00BD0, | ||
minix_old = 0x137F, /* orig. minix */ | ||
minix = 0x138F, /* 30 char minix */ | ||
minix2 = 0x2468, /* minix V2 */ | ||
minix2v2 = 0x2478, /* MINIX V2, 30 char names */ | ||
minix3 = 0x4D5A, | ||
mqueue = 0x19800202, | ||
msdos = 0x4D44, | ||
nfs = 0x6969, | ||
nfsd = 0x6E667364, | ||
nilfs = 0x3434, | ||
novell = 0x564C, | ||
ntfs = 0x5346544E, | ||
openprom = 0x9FA1, | ||
ocfs2 = 0x7461636F, | ||
omfs = 0xC2993D87, | ||
overlay = 0x794C7630, | ||
overlayfs = 0x794C764F, | ||
panfs = 0xAAD7AAEA, | ||
pipefs = 0x50495045, | ||
proc = 0x9FA0, | ||
pstorefs = 0x6165676C, | ||
qnx4 = 0x002F, | ||
qnx6 = 0x68191122, | ||
ramfs = 0x858458F6, | ||
reiserfs = 0x52654973, | ||
romfs = 0x7275, | ||
rootfs = 0x53464846, | ||
rpc_pipefs = 0x67596969, | ||
samba = 0x517B, | ||
securityfs = 0x73636673, | ||
selinux = 0xF97CFF8C, | ||
smb = 0x517B, | ||
smb2 = 0xFE534D42, | ||
sockfs = 0x534F434B, | ||
squashfs = 0x73717368, | ||
sysfs = 0x62656572, | ||
sysv2 = 0x012FF7B6, | ||
sysv4 = 0x012FF7B5, | ||
tmpfs = 0x01021994, | ||
ubifs = 0x24051905, | ||
udf = 0x15013346, | ||
ufs = 0x00011954, | ||
ufscigam = 0x54190100, // ufs byteswapped | ||
ufs2 = 0x19540119, | ||
usbdevice = 0x9FA2, | ||
v9fs = 0x01021997, | ||
vmhgfs = 0xBACBACBC, | ||
vxfs = 0xA501FCF5, | ||
vzfs = 0x565A4653, | ||
xenfs = 0xABBA1974, | ||
xenix = 0x012FF7B4, | ||
xfs = 0x58465342, | ||
xia = 0x012FD16D, | ||
zfs = 0x2FC12FC1, | ||
} | ||
|
||
[DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetFileSystemType")] | ||
private static extern long GetFileSystemType(SafeFileHandle fd); | ||
|
||
internal static bool TryGetFileSystemType(SafeFileHandle fd, out UnixFileSystemTypes fileSystemType) | ||
{ | ||
long fstatfsResult = GetFileSystemType(fd); | ||
fileSystemType = (UnixFileSystemTypes)fstatfsResult; | ||
return fstatfsResult != -1; | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.