* Mono.Posix.dll.sources: Add new files: Mono.Unix/FileAccessPermissions.cs,
authorJonathan Pryor <jpryor@novell.com>
Wed, 19 Oct 2005 18:07:41 +0000 (18:07 -0000)
committerJonathan Pryor <jpryor@novell.com>
Wed, 19 Oct 2005 18:07:41 +0000 (18:07 -0000)
    Mono.Unix/FileSpecialAttributes.cs, Mono.Unix/FileTypes.cs.
  * Mono.Unix/FileAccessPermissions.cs, Mono.Unix/FileSpecialAttributes.cs,
    Mono.Unix/FileTypes.cs: Added.
  * Mono.Unix/UnixFileSystemInfo.cs, Mono.Unix/UnixStream.cs:
    Replace the old Permission property
    with 4 new properties: Protection (for the Native.FilePermissions value),
    FileAccessPermissions (for rwxrwxrwx info), FileSpecialAttributes (for
    set-user-id, set-group-id, sticky), and FileTypes (directory, socket...).
    The new enumeration types have nicer CLS-compliant names.

svn path=/trunk/mcs/; revision=51928

mcs/class/Mono.Posix/ChangeLog
mcs/class/Mono.Posix/Mono.Posix.dll.sources
mcs/class/Mono.Posix/Mono.Unix/ChangeLog
mcs/class/Mono.Posix/Mono.Unix/FileAccessPermissions.cs [new file with mode: 0644]
mcs/class/Mono.Posix/Mono.Unix/FileSpecialAttributes.cs [new file with mode: 0644]
mcs/class/Mono.Posix/Mono.Unix/FileTypes.cs [new file with mode: 0644]
mcs/class/Mono.Posix/Mono.Unix/UnixFileSystemInfo.cs
mcs/class/Mono.Posix/Mono.Unix/UnixStream.cs

index d0dc5c59d5ddb85c9c8bc2e92b766696446d3d4e..16685e488219a0834e01c08cbed2adbd87d20af0 100644 (file)
@@ -1,3 +1,8 @@
+2005-10-19  Jonathan Pryor  <jonpryor@vt.edu>
+
+       * Mono.Posix.dll.sources: Add new files: Mono.Unix/FileAccessPermissions.cs,
+         Mono.Unix/FileSpecialAttributes.cs, Mono.Unix/FileTypes.cs.
+
 2005-10-17  Jonathan Pryor  <jonpryor@vt.edu>
 
        * Mono.Posix_test.dll.sources: Add Mono.Unix/UnixMarshalTest.cs.
index 839569fc527423d3af4b719e8596223f81d52da5..d0a912addd2dbea29ce8a7a929c33c66c2c9829f 100644 (file)
@@ -3,6 +3,9 @@
 ../../build/common/Locale.cs
 ./Mono.Unix/Catalog.cs
 ./Mono.Unix/CdeclFunction.cs
+./Mono.Unix/FileAccessPermissions.cs
+./Mono.Unix/FileSpecialAttributes.cs
+./Mono.Unix/FileTypes.cs
 ./Mono.Unix/IncludeAttribute.cs
 ./Mono.Unix/MapAttribute.cs
 ./Mono.Unix/PeerCred.cs
index 3122643d9c4a480c4591341312f6f8eb6744f50d..ee01dc7b529ac761dc950d93a6a3dfd06f761756 100644 (file)
@@ -1,3 +1,12 @@
+2005-10-19  Jonathan Pryor <jonpryor@vt.edu>
+
+       * FileAccessPermissions.cs, FileSpecialAttributes.cs, FileTypes.cs: Added.
+       * UnixFileSystemInfo.cs, UnixStream.cs: Replace the old Permission property
+         with 4 new properties: Protection (for the Native.FilePermissions value),
+         FileAccessPermissions (for rwxrwxrwx info), FileSpecialAttributes (for
+         set-user-id, set-group-id, sticky), and FileTypes (directory, socket...).
+         The new enumeration types have nicer CLS-compliant names.
+
 2005-10-17  Jonathan Pryor <jonpryor@vt.edu>
 
        * UnixMarshal.cs: Fix GetIntXxBufferLength to require fewer
diff --git a/mcs/class/Mono.Posix/Mono.Unix/FileAccessPermissions.cs b/mcs/class/Mono.Posix/Mono.Unix/FileAccessPermissions.cs
new file mode 100644 (file)
index 0000000..492dbe3
--- /dev/null
@@ -0,0 +1,56 @@
+//
+// Mono.Unix/FileAccessPermissions.cs
+//
+// Authors:
+//   Jonathan Pryor (jonpryor@vt.edu)
+//
+// (C) 2005 Jonathan Pryor
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using Mono.Unix;
+
+namespace Mono.Unix {
+
+       [Flags]
+       public enum FileAccessPermissions {
+               UserReadWriteExecute  = (int) Native.FilePermissions.S_IRWXU,
+               UserMask              = UserReadWriteExecute,
+               UserRead              = (int) Native.FilePermissions.S_IRUSR,
+               UserWrite             = (int) Native.FilePermissions.S_IWUSR,
+               UserExecute           = (int) Native.FilePermissions.S_IXUSR,
+               GroupReadWriteExecute = (int) Native.FilePermissions.S_IRWXG,
+               GroupMask             = GroupReadWriteExecute,
+               GroupRead             = (int) Native.FilePermissions.S_IRGRP,
+               GroupWrite            = (int) Native.FilePermissions.S_IWGRP,
+               GroupExecute          = (int) Native.FilePermissions.S_IXGRP,
+               OtherReadWriteExecute = (int) Native.FilePermissions.S_IRWXO,
+               OtherMask             = OtherReadWriteExecute,
+               OtherRead             = (int) Native.FilePermissions.S_IROTH,
+               OtherWrite            = (int) Native.FilePermissions.S_IWOTH,
+               OtherExecute          = (int) Native.FilePermissions.S_IXOTH,
+
+               DefaultPermissions    = (int) Native.FilePermissions.DEFFILEMODE,
+               AllPermissions        = (int) Native.FilePermissions.ACCESSPERMS,
+       }
+}
+
diff --git a/mcs/class/Mono.Posix/Mono.Unix/FileSpecialAttributes.cs b/mcs/class/Mono.Posix/Mono.Unix/FileSpecialAttributes.cs
new file mode 100644 (file)
index 0000000..8f4bdbf
--- /dev/null
@@ -0,0 +1,42 @@
+//
+// Mono.Unix/FileSpecialAttributes.cs
+//
+// Authors:
+//   Jonathan Pryor (jonpryor@vt.edu)
+//
+// (C) 2005 Jonathan Pryor
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using Mono.Unix;
+
+namespace Mono.Unix {
+
+       [Flags]
+       public enum FileSpecialAttributes {
+               SetUserId   = (int) Native.FilePermissions.S_ISUID,
+               SetGroupId  = (int) Native.FilePermissions.S_ISGID,
+               Sticky      = (int) Native.FilePermissions.S_ISVTX,
+               AllAttributes = SetUserId | SetGroupId | Sticky,
+       }
+}
+
diff --git a/mcs/class/Mono.Posix/Mono.Unix/FileTypes.cs b/mcs/class/Mono.Posix/Mono.Unix/FileTypes.cs
new file mode 100644 (file)
index 0000000..647af42
--- /dev/null
@@ -0,0 +1,48 @@
+//
+// Mono.Unix/FileTypes.cs
+//
+// Authors:
+//   Jonathan Pryor (jonpryor@vt.edu)
+//
+// (C) 2005 Jonathan Pryor
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using Mono.Unix;
+
+namespace Mono.Unix {
+
+       [Flags]
+       public enum FileTypes {
+               Directory         = (int) Native.FilePermissions.S_IFDIR,
+               CharacterSpecial  = (int) Native.FilePermissions.S_IFCHR,
+               BlockSpecial      = (int) Native.FilePermissions.S_IFBLK,
+               RegularFile       = (int) Native.FilePermissions.S_IFREG,
+               FIFO              = (int) Native.FilePermissions.S_IFIFO,
+               SymbolicLink      = (int) Native.FilePermissions.S_IFLNK,
+               Socket            = (int) Native.FilePermissions.S_IFSOCK,
+               AllTypes          = 
+                       Directory | CharacterSpecial | BlockSpecial | RegularFile | FIFO | 
+                       SymbolicLink | Socket,
+       }
+}
+
index bdb7b4ac3d9665db73186ddf94c183f773715165..6f58cb040be4da595adb9b532fefbc1924147c6e 100644 (file)
@@ -4,7 +4,7 @@
 // Authors:
 //   Jonathan Pryor (jonpryor@vt.edu)
 //
-// (C) 2004 Jonathan Pryor
+// (C) 2004-2005 Jonathan Pryor
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
@@ -108,13 +108,13 @@ namespace Mono.Unix {
                }
 
                [CLSCompliant (false)]
-               [Obsolete ("The type of this property will change in the next release.")]
+               [Obsolete ("Use Protection.")]
                public FilePermissions Mode {
                        get {AssertValid (); return stat.st_mode;}
                }
 
                [CLSCompliant (false)]
-               [Obsolete ("The type of this property will change in the next release.")]
+               [Obsolete ("Use FileAccessPermissions.")]
                public FilePermissions Permissions {
                        get {AssertValid (); return stat.st_mode & ~FilePermissions.S_IFMT;}
                }
@@ -125,6 +125,56 @@ namespace Mono.Unix {
                        get {AssertValid (); return stat.st_mode & FilePermissions.S_IFMT;}
                }
 
+               [CLSCompliant (false)]
+               public Native.FilePermissions Protection {
+                       get {AssertValid (); return (Native.FilePermissions) stat.st_mode;}
+                       set {
+                               int r = Native.Syscall.chmod (FullPath, value);
+                               UnixMarshal.ThrowExceptionForLastErrorIf (r);
+                       }
+               }
+
+#if false
+               public FileTypes FileType {
+                       get {
+                               AssertValid ();
+                               int type = (int) stat.st_mode;
+                               return (FileTypes) (type & (int) FileTypes.AllTypes);
+                       }
+                       // no set as chmod(2) won't accept changing the file type.
+               }
+#endif
+
+               public FileAccessPermissions FileAccessPermissions {
+                       get {
+                               AssertValid (); 
+                               int perms = (int) stat.st_mode;
+                               return (FileAccessPermissions) (perms & (int) FileAccessPermissions.AllPermissions);
+                       }
+                       set {
+                               AssertValid ();
+                               int perms = (int) stat.st_mode;
+                               perms &= (int) ~FileAccessPermissions.AllPermissions;
+                               perms |= (int) value;
+                               Protection = (Native.FilePermissions) perms;
+                       }
+               }
+
+               public FileSpecialAttributes FileSpecialAttributes {
+                       get {
+                               AssertValid ();
+                               int attrs = (int) stat.st_mode;
+                               return (FileSpecialAttributes) (attrs & (int) FileSpecialAttributes.AllAttributes);
+                       }
+                       set {
+                               AssertValid ();
+                               int perms = (int) stat.st_mode;
+                               perms &= (int) ~FileSpecialAttributes.AllAttributes;
+                               perms |= (int) value;
+                               Protection = (Native.FilePermissions) perms;
+                       }
+               }
+
                [CLSCompliant (false)]
                [Obsolete ("The type of this property will change in the next release.")]
                public ulong LinkCount {
@@ -327,20 +377,13 @@ namespace Mono.Unix {
                }
 
                [CLSCompliant (false)]
-               [Obsolete ("Use SetPermissions (Mono.Unix.Native.FilePermissions)")]
+               [Obsolete ("Use Protection setter")]
                public void SetPermissions (FilePermissions perms)
                {
                        int r = Syscall.chmod (FullPath, perms);
                        UnixMarshal.ThrowExceptionForLastErrorIf (r);
                }
 
-               [CLSCompliant (false)]
-               public void SetPermissions (Native.FilePermissions perms)
-               {
-                       int r = Native.Syscall.chmod (FullPath, perms);
-                       UnixMarshal.ThrowExceptionForLastErrorIf (r);
-               }
-
                [CLSCompliant (false)]
                [Obsolete ("Use SetOwner (long, long)")]
                public virtual void SetOwner (uint owner, uint group)
index a215667ab844a3b2ebc4cd3abdb50b5a6c6d2780..e7149285aa64fb5e80221c2e225b9aa7cf3f634b 100644 (file)
@@ -4,7 +4,7 @@
 // Authors:
 //   Jonathan Pryor (jonpryor@vt.edu)
 //
-// (C) 2004 Jonathan Pryor
+// (C) 2004-2005 Jonathan Pryor
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
@@ -113,7 +113,7 @@ namespace Mono.Unix {
                }
 
                [CLSCompliant (false)]
-               [Obsolete ("The type of this property will change in the next release.")]
+               [Obsolete ("Use Protection")]
                public FilePermissions Permissions {
                        get {
                                Stat stat;
@@ -127,6 +127,56 @@ namespace Mono.Unix {
                        }
                }
 
+               [CLSCompliant (false)]
+               public Native.FilePermissions Protection {
+                       get {
+                               Native.Stat stat;
+                               int r = Native.Syscall.fstat (fileDescriptor, out stat);
+                               UnixMarshal.ThrowExceptionForLastErrorIf (r);
+                               return stat.st_mode;
+                       }
+                       set {
+                               // we can't change file type with fchmod, so clear out that portion
+                               value &= ~Native.FilePermissions.S_IFMT;
+                               int r = Native.Syscall.fchmod (fileDescriptor, value);
+                               UnixMarshal.ThrowExceptionForLastErrorIf (r);
+                       }
+               }
+
+               public FileTypes FileType {
+                       get {
+                               int type = (int) Protection;
+                               return (FileTypes) (type & (int) FileTypes.AllTypes);
+                       }
+                       // no set as fchmod(2) won't accept changing the file type.
+               }
+
+               public FileAccessPermissions FileAccessPermissions {
+                       get {
+                               int perms = (int) Protection;
+                               return (FileAccessPermissions) (perms & (int) FileAccessPermissions.AllPermissions);
+                       }
+                       set {
+                               int perms = (int) Protection;
+                               perms &= (int) ~FileAccessPermissions.AllPermissions;
+                               perms |= (int) value;
+                               Protection = (Native.FilePermissions) perms;
+                       }
+               }
+
+               public FileSpecialAttributes FileSpecialAttributes {
+                       get {
+                               int attrs = (int) Protection;
+                               return (FileSpecialAttributes) (attrs & (int) FileSpecialAttributes.AllAttributes);
+                       }
+                       set {
+                               int perms = (int) Protection;
+                               perms &= (int) ~FileSpecialAttributes.AllAttributes;
+                               perms |= (int) value;
+                               Protection = (Native.FilePermissions) perms;
+                       }
+               }
+
                public void AdviseNormalAccess (long offset, long len)
                {
                        UnixFile.AdviseNormalAccess (fileDescriptor, offset, len);