Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

View File

@@ -0,0 +1,188 @@
//
// Mono.Unix/CdeclFunction.cs
//
// Authors:
// Jonathan Pryor (jonpryor@vt.edu)
//
// (C) 2004 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 System.Collections;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.InteropServices;
using System.Text;
namespace Mono.Unix.Native {
// This class represents a single unmanaged function with "cdecl" calling
// convention -- that is, it can accept a variable number of arguments which
// are passed on the runtime stack.
//
// To use, create an instance:
//
// CdeclFunction printf = new CdeclFunction ("the library",
// "the function name", /* optional */ typeof (ReturnType));
//
// Then call the Invoke method with the appropriate number of arguments:
//
// printf.Invoke (new object[]{"hello, %s\n", "world!"});
//
// In the background a P/Invoke definition for the method with the
// requested argument types will be generated and invoked, invoking the
// unmanaged function. The generated methods are cached, so that subsequent
// calls with the same argument list do not generate new code, speeding up
// the call sequence.
//
// Invoking Cdecl functions is not guaranteed to be portable across all
// platforms. For example, AMD64 requires that the caller set EAX to the
// number of floating point arguments passed in the SSE registers. This
// is only required for variable argument/cdecl functions; consequently,
// the overload technique used by this class wouldn't normally work.
// Mono's AMD64 JIT works around this by always setting EAX on P/Invoke
// invocations, allowing CdeclFunction to work properly, but it will not
// necessarily always work. See also:
//
// http://lwn.net/Articles/5201/?format=printable
//
// Due to potential portability issues, cdecl functions should be avoided
// on most platforms.
//
// This class is intended to be thread-safe.
public sealed class CdeclFunction
{
// The readonly fields (1) shouldn't be modified, and (2) should only be
// used when `overloads' is locked.
private readonly string library;
private readonly string method;
private readonly Type returnType;
private readonly AssemblyName assemblyName;
private readonly AssemblyBuilder assemblyBuilder;
private readonly ModuleBuilder moduleBuilder;
private Hashtable overloads;
public CdeclFunction (string library, string method)
: this (library, method, typeof(void))
{
}
public CdeclFunction (string library, string method, Type returnType)
{
this.library = library;
this.method = method;
this.returnType = returnType;
this.overloads = new Hashtable ();
this.assemblyName = new AssemblyName ();
this.assemblyName.Name = "Mono.Posix.Imports." + library;
this.assemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly (
assemblyName, AssemblyBuilderAccess.Run);
this.moduleBuilder = assemblyBuilder.DefineDynamicModule (assemblyName.Name);
}
public object Invoke (object[] parameters)
{
Type[] parameterTypes = GetParameterTypes (parameters);
MethodInfo m = CreateMethod (parameterTypes);
return m.Invoke (null, parameters);
}
private MethodInfo CreateMethod (Type[] parameterTypes)
{
string typeName = GetTypeName (parameterTypes);
lock (overloads) {
MethodInfo mi = (MethodInfo) overloads [typeName];
if (mi != null) {
return mi;
}
TypeBuilder tb = CreateType (typeName);
/* MethodBuilder mb = */ tb.DefinePInvokeMethod (
method,
library,
MethodAttributes.PinvokeImpl | MethodAttributes.Static | MethodAttributes.Public,
CallingConventions.Standard,
returnType,
parameterTypes,
CallingConvention.Cdecl,
CharSet.Ansi);
mi = tb.CreateType ().GetMethod (method);
overloads.Add (typeName, mi);
return mi;
}
}
private TypeBuilder CreateType (string typeName)
{
return moduleBuilder.DefineType (typeName, TypeAttributes.Public);
}
private static Type GetMarshalType (Type t)
{
switch (Type.GetTypeCode (t)) {
// types < sizeof(int) are marshaled as ints
case TypeCode.Boolean: case TypeCode.Char: case TypeCode.SByte:
case TypeCode.Int16: case TypeCode.Int32:
return typeof(int);
case TypeCode.Byte: case TypeCode.UInt16: case TypeCode.UInt32:
return typeof(uint);
case TypeCode.Int64:
return typeof(long);
case TypeCode.UInt64:
return typeof(ulong);
case TypeCode.Single: case TypeCode.Double:
return typeof(double);
default:
return t;
}
}
private string GetTypeName (Type[] parameterTypes)
{
StringBuilder sb = new StringBuilder ();
sb.Append ("[").Append (library).Append ("] ").Append (method);
sb.Append ("(");
if (parameterTypes.Length > 0)
sb.Append (parameterTypes [0]);
for (int i = 1; i < parameterTypes.Length; ++i)
sb.Append (",").Append (parameterTypes [i]);
sb.Append (") : ").Append (returnType.FullName);
return sb.ToString ();
}
private static Type[] GetParameterTypes (object[] parameters)
{
Type[] parameterTypes = new Type [parameters.Length];
for (int i = 0; i < parameters.Length; ++i)
parameterTypes [i] = GetMarshalType (parameters [i].GetType ());
return parameterTypes;
}
}
}

View File

@@ -0,0 +1,272 @@
2010-07-21 Jackson Harper <jackson@ximian.com>
* Syscall.cs: Add bindings to the various epoll
functions. (epoll_create, epoll_ctl, epoll_wait).
2008-12-19 Jonathan Pryor <jpryor@novell.com>
* NativeConvert.cs: Add FromRealTimeSignum(), ToRealTimeSignum().
Patch thanks to tim.jenks@realtimeworlds.com.
* RealTimeSignum.cs: Added; structure which represents a real-time
signal, a value V such that V >= SIGRTMIN and V <= SIGRTMAX.
Patch thanks to tim.jenks@realtimeworlds.com.
* Stdlib.cs: Add SetSignalAction() and raise() overloads which accept
a RealTimeSignum instance.
Patch thanks to tim.jenks@realtimeworlds.com.
2008-10-15 Jonathan Pryor <jpryor@novell.com>
* Syscall.cs: [Map] Flock, add Timespec, bind nanosleep(2).
* NativeConvert.generated.cs: Flush (Add TryCopy methods for Flock,
Timespec).
2008-01-28 Jonathan Pryor <jpryor@novell.com>
* Stdlib.cs: Obsolete Stdlib.signal(), as it's not safe; see also:
http://lists.ximian.com/pipermail/mono-devel-list/2008-January/026501.html
http://lists.ximian.com/pipermail/mono-devel-list/2008-January/026503.html
Add SetSignalAction() as a replacement.
2008-01-22 Sebastien Pouliot <sebastien@ximian.com>
* Syscall.cs: Fix Flock.Equals to avoid NRE (and return false if object
is null). Found using Gendarme.
2008-01-05 Jonathan Pryor <jonpryor@vt.edu>
* Syscall.cs: Add ST_NOEXEC, ST_REMOUNT, ST_BIND to MountFlags. Patch from
Joe Dluzen <jdluzen@gmail.com>.
2007-12-17 Jonathan Pryor <jonpryor@vt.edu>
* Syscall.cs: Bind uname(2).
2007-10-25 Jonathan Pryor <jonpryor@vt.edu>
* Stdlib.cs: Fix perror(3) so that it works as expected. (Since errno is
cleared during P/Invoke, previously Stdlib.perror("") would always print
"Success", which isn't very helpful.)
2007-06-28 Jonathan Pryor <jonpryor@vt.edu>
* NativeConvert.generated.cs: Flush (add TryCopy() methods for Utimbuf).
* Syscall.cs: Map Utimbuf to `struct utimbuf'; needed so that Mono.Fuse can
rely on Mono.Posix.dll for copying all native types.
2006-11-14 Jonathan Pryor <jonpryor@vt.edu>
* MapAttribute.cs: Update (changes SuppressFlags to a string holding mask).
* Syscall.cs: Specify the mask value for non-bitmask values in
FilePermissions.
2006-10-27 Jonathan Pryor <jonpryor@vt.edu>
* MapAttribute.cs: Update (adds SuppressFlags property).
* Syscall.cs: Mark non-flags FilePermissions enumeration members so that
they aren't treated as bitfields. Impacts e.g. S_IFDIR, S_IFCHR, etc..
2006-10-24 Jonathan Pryor <jonpryor@vt.edu>
* HeaderAttribute.cs: Removed. Use create-native-map command-line arguments
instead of HeaderAttribute.Includes & HeaderAttribute.Defines.
* make-map.cs: Moved to mono-tools/create-native-map/src/create-native-map.cs.
* MapAttribute.cs: Moved from ../Mono.Unix. Can now be
specified on Class, Delegeate, Enum, Field, & Struct (instead of just
Enum). Add NativeType property.
* NativeConvert.generated.cs: Flush (adds new .TryCopy methods to copy [Map]'d
structures).
* NativeConvert.cs: Add .TryCopy methods for Statvfs.
* Syscall.cs: Remove HeaderAttribute declaration; Markup [Map]'d structure
members with [Map] attributes (or MapAttribute subclasses) to specify the
native types they correspond to (used by create-native-map).
* TypeAttributes.cs: Added; internal subclasses of MapAttribute to help
markup structures (e.g. so I can use [blkcnt_t] instead of
[Map ("blkcnt_t")], thus minimizing the liklihood of a spelling error).
2006-09-15 Jonathan Pryor <jonpryor@vt.edu>
* Syscall.cs: "Remove" crypt(3), encrypt(3), setkey(3). These use an
encryption algorithm which was broken years ago and could be cracked in
minutes on a modern machine. This also removes a libcrypt.so dependency,
which means you don't need to have development packages installed to use
these either (since "crypt" wasn't <dllmap>'d). These are still present,
but marked [Obsolete] and throw a SecurityException when invoked.
2006-09-07 Jonathan Pryor <jonpryor@vt.edu>
* Syscall.cs: readdir(P) is not thread-safe, so it needs to be locked so
that the `struct dirent' it returns is stable.
2006-04-06 Jonathan Pryor <jonpryor@vt.edu>
* NativeConvert.cs: Fix ToDateTime()/FromDateTime()/ToTimeT()/FromTimeT() so
that they take timezones into account. Previously, results would be off
by an hour if Daylight Savings Time was in effect. Fixes #78033.
2006-03-23 Raja R Harinath <rharinath@novell.com>
* NativeConvert.generated.cs: Update after merge.
2006-02-25 Marek Safar <marek.safar@seznam.cz>
* NativeConvert.generated.cs: Guarded CLSCompliant attribute by NET_2_0
until mcs is merged with gmcs.
2006-02-21 Marek Safar <marek.safar@seznam.cz>
* NativeConvert.generated.cs: Removed duplicated CLSCompliant attribute.
2006-01-10 Raja R Harinath <rharinath@novell.com>
* Syscall.cs (sys_futimes): Remove buggy custom marshaller on 'fd' parameter.
2005-01-09 Jonathan Pryor <jonpryor@vt.edu>
* NativeConvert.cs: s/IsType/IsSet/g: deal with UnixFileSystemInfo method
name change.
2005-01-02 Jonathan Pryor <jonpryor@vt.edu>
* Stdlib.cs: s/ACCESS/ACCES/g. I didn't create a badly named errno value, I
mis-read EACCES in man pages. I can't read. :-(
2005-01-02 Jonathan Pryor <jonpryor@vt.edu>
* NativeConvert.generated.cs: Flush (remove Obsolete members).
* Syscall.cs: Remove invalid utimes(2) wrapper.
2005-01-02 Jonathan Pryor <jonpryor@vt.edu>
* Stdlib.cs: s/ACCES/ACCESS/g. How'd I create a badly named errno value?
2005-12-29 Jonathan Pryor <jonpryor@vt.edu>
* make-map.cs: Properly handle managed arrays in argument lists.
* Syscall.cs: Properly bind utimes(2) (the Linux man pages are vague on what
it does; the BSD ones are much better). Bind lutimes(2) and futimes(2).
2005-12-27 Jonathan Pryor <jonpryor@vt.edu>
* Syscall.cs: Include <sys/mman.h> for map.c generation. Fixes #77091.
2005-12-27 Jonathan Pryor <jonpryor@vt.edu>
* make-map.cs: Always include 2nd parameter of [Obsolete] attributes; mark
the [DllImport]ed method with [Obsolete] if the underlying type is
[Obsolete].
* NativeConvert.generated.cs: Flush.
2005-12-27 Jonathan Pryor <jonpryor@vt.edu>
* FileNameMarshaler.cs: Use UnixMarshal.PtrToStringUnix -- it's faster.
2005-11-28 Jonathan Pryor <jonpryor@vt.edu>
* Stdlib.cs: Prelink all SignalHandlers passed to Stdlib.signal(). This is
so that mono doesn't have to JIT the handler within signal context.
2005-11-08 Jonathan Pryor <jonpryor@vt.edu>
* Stdlib.cs: Implement IEquatable<FilePosition> for FilePosition.
* Syscall.cs: Provide GetHashCode(), Equals(), operator==, operator!= for
all structure types. Implement IEquatable<T> for all "value type"
structs and classes.
2005-11-07 Jonathan Pryor <jonpryor@vt.edu>
* Syscall.cs: *xattr functions should use the FileNameMarshaler for filenames.
2005-11-07 Jonathan Pryor <jonpryor@vt.edu>
* make-map.cs: Always use ordinal string sorting behavior. The string
collation sorting has changed, so to keep the mono/support diff sizes down
we have to explicitly specify the previous implicit ordering.
2005-11-02 Jonathan Pryor <jonpryor@vt.edu>
* Syscall.cs: Remove [CLSCompliant(false)] when it isn't needed.
2005-11-02 Jonathan Pryor <jonpryor@vt.edu>
* FileNameMarshaler.cs: Use UnixMarshal.FreeHeap(). .Free() is obsolete.
2005-10-27 Jonathan Pryor <jonpryor@vt.edu>
* Stdlib.cs: Correct return type of setbuf(IntPtr, byte*).
* Syscall.cs: Remove [Obsolete] SyslogFacility.LOG_USRE member
(Mono.Unix.Native hasn't shipped yet, so nobody is using it); correct
[Obsolete] comment for getpagesize().
2005-10-26 Jonathan Pryor <jonpryor@vt.edu>
* FileNameMarshaler.cs: Deal with UnixMarshal method name changes.
2005-10-26 Jonathan Pryor <jonpryor@vt.edu>
* Stdlib.cs: FilePosition should derive from MarshalByRefObject, for two
reasons: (1) it's a recommendation from FxCop that classes implementing
IDisposable also derive from MarshalByRefObject; (2) FilePosition is
exposed from Mono.Unix.StdioFileStream, which (indirectly) inherits from
MarshalByRefObject. Fix Equals() so it doesn't rely on Reflection.
2005-10-25 Jonathan Pryor <jonpryor@vt.edu>
* FileNameMarshaler.cs: Custom marshaler to marshal filenames using
Mono.Unix.UnixEncoding. A custom marshaler is used to remove the need to
have ~6 lines of boilerplate on every method that takes filenames.
* Stdlib.cs, Syscall.cs: Filenames need to be marshaled through the
FileNameMarshaler, which will encode/decode filenames with UnixEncoder.
2005-10-14 Jonathan Pryor <jonpryor@vt.edu>
* Stdlib.cs, Syscall.cs: Flush naming convention documentation.
2005-10-14 Jonathan Pryor <jonpryor@vt.edu>
* NativeConvert.generated.cs: Flush currently generated version.
2005-10-14 Jonathan Pryor <jonpryor@vt.edu>
* make-map.cs: Fix documentation comment.
* Stdlib.cs: Fix export of XprintfFunctions.syslog(); make SetLastError()
protected (normal user code shouldn't call it, as it isn't safe);
replace functions which return `void' with functions which return `int'
(adding them to MonoPosixHelper.so as well) -- since users can't reliably
use SetLastError(), they need the "normal" error detection mechanism;
correct the strlen(3) export.
* Syscall.cs:
- s/PathConf/PathconfName/, s/SysConf/SysconfName/, s/ConfStr/ConfstrName/
to follow documented enumeration naming conventions.
- replace functions which return `void' with functions which return `int'
(adding them to MonoPosixHelper.so as well) -- since users can't reliably
use SetLastError(), they need the "normal" error detection mechanism;
2005-10-13 Gonzalo Paniagua Javier <gonzalo@ximian.com>
* Stdlib.cs: add strlen() to fix the build.
2005-09-23 Jonathan Pryor <jonpryor@vt.edu>
* make-map.cs: Generate NativeConvert documentation XML fragments for use in
monodoc.
2005-09-20 Jonathan Pryor <jonpryor@vt.edu>
* ChangeLog: Started.
* CdeclFunction.cs: Copied from ../Mono.Unix; change namespace.
* HeaderAttribute.cs: Added
* make-map.cs: Copied from ../Mono.Unix; sort type and member names in
output (makes for a more stable svn history, as types/members won't change
position anymore within generated code); look for HeaderAttribute not
IncludeAttribute for getting headers & #defines; generate NativeConvert
partial class.
* NativeConvert.cs: Copied from ../Mono.Unix; change namespace; turn into a
partial class; Remove generated code (generated code is in
NativeConvert.generated.cs).
* NativeConvert.generated.cs: Added
* Stdlib.cs: Copied from ../Mono.Unix; change namespace; rename Error to
Errno (as Error is a "reserved word" in FxCop); [CLSCompliant(false)]
support.
* Syscall.cs: Use HeaderAttribute, not IncludeAttribute, for CLS compliance;
add [CLSCompliant(false)] as needed; use NativeConvert, not UnixConvert.

View File

@@ -0,0 +1,79 @@
//
// Mono.Unix/FileNameMarshaler.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 System.Runtime.InteropServices;
using Mono.Unix;
namespace Mono.Unix.Native {
class FileNameMarshaler : ICustomMarshaler {
private static FileNameMarshaler Instance = new FileNameMarshaler ();
public static ICustomMarshaler GetInstance (string s)
{
return Instance;
}
public void CleanUpManagedData (object o)
{
}
public void CleanUpNativeData (IntPtr pNativeData)
{
// Console.WriteLine ("# FileNameMarshaler.CleanUpManagedData ({0:x})", pNativeData);
UnixMarshal.FreeHeap (pNativeData);
}
public int GetNativeDataSize ()
{
return IntPtr.Size;
}
public IntPtr MarshalManagedToNative (object obj)
{
string s = obj as string;
if (s == null)
return IntPtr.Zero;
IntPtr p = UnixMarshal.StringToHeap (s, UnixEncoding.Instance);
// Console.WriteLine ("# FileNameMarshaler.MarshalNativeToManaged for `{0}'={1:x}", s, p);
return p;
}
public object MarshalNativeToManaged (IntPtr pNativeData)
{
string s = UnixMarshal.PtrToString (pNativeData, UnixEncoding.Instance);
// Console.WriteLine ("# FileNameMarshaler.MarshalNativeToManaged ({0:x})=`{1}'",
// pNativeData, s);
return s;
}
}
}
// vim: noexpandtab

View File

@@ -0,0 +1,60 @@
//
// MapAttribute.cs
//
// Author:
// Miguel de Icaza (miguel@gnome.org)
//
// (C) Novell, Inc.
//
//
// 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;
[AttributeUsage (
AttributeTargets.Class |
AttributeTargets.Delegate |
AttributeTargets.Enum |
AttributeTargets.Field |
AttributeTargets.Struct)]
internal class MapAttribute : Attribute {
private string nativeType;
private string suppressFlags;
public MapAttribute ()
{
}
public MapAttribute (string nativeType)
{
this.nativeType = nativeType;
}
public string NativeType {
get {return nativeType;}
}
public string SuppressFlags {
get {return suppressFlags;}
set {suppressFlags = value;}
}
}

View File

@@ -0,0 +1,360 @@
/*
* This file was automatically generated by make-map from Mono.Posix.dll.
*
* DO NOT MODIFY.
*/
using System;
using System.IO;
using System.Runtime.InteropServices;
using Mono.Unix.Native;
namespace Mono.Unix.Native {
[CLSCompliant (false)]
public sealed /* static */ partial class NativeConvert
{
//
// Non-generated exports
//
[DllImport (LIB, EntryPoint="Mono_Posix_FromRealTimeSignum")]
private static extern int FromRealTimeSignum (Int32 offset, out Int32 rval);
// convert a realtime signal to os signal
public static int FromRealTimeSignum (RealTimeSignum sig)
{
int sigNum;
if (FromRealTimeSignum (sig.Offset, out sigNum) == -1)
ThrowArgumentException (sig.Offset);
return sigNum;
}
// convert an offset to an rt signum
public static RealTimeSignum ToRealTimeSignum (int offset)
{
return new RealTimeSignum (offset);
}
// convert from octal representation.
public static FilePermissions FromOctalPermissionString (string value)
{
uint n = Convert.ToUInt32 (value, 8);
return ToFilePermissions (n);
}
public static string ToOctalPermissionString (FilePermissions value)
{
string s = Convert.ToString ((int) (value & ~FilePermissions.S_IFMT), 8);
return new string ('0', 4-s.Length) + s;
}
public static FilePermissions FromUnixPermissionString (string value)
{
if (value == null)
throw new ArgumentNullException ("value");
if (value.Length != 9 && value.Length != 10)
throw new ArgumentException ("value", "must contain 9 or 10 characters");
int i = 0;
FilePermissions perms = new FilePermissions ();
if (value.Length == 10) {
perms |= GetUnixPermissionDevice (value [i]);
++i;
}
perms |= GetUnixPermissionGroup (
value [i++], FilePermissions.S_IRUSR,
value [i++], FilePermissions.S_IWUSR,
value [i++], FilePermissions.S_IXUSR,
's', 'S', FilePermissions.S_ISUID);
perms |= GetUnixPermissionGroup (
value [i++], FilePermissions.S_IRGRP,
value [i++], FilePermissions.S_IWGRP,
value [i++], FilePermissions.S_IXGRP,
's', 'S', FilePermissions.S_ISGID);
perms |= GetUnixPermissionGroup (
value [i++], FilePermissions.S_IROTH,
value [i++], FilePermissions.S_IWOTH,
value [i++], FilePermissions.S_IXOTH,
't', 'T', FilePermissions.S_ISVTX);
return perms;
}
private static FilePermissions GetUnixPermissionDevice (char value)
{
switch (value) {
case 'd': return FilePermissions.S_IFDIR;
case 'c': return FilePermissions.S_IFCHR;
case 'b': return FilePermissions.S_IFBLK;
case '-': return FilePermissions.S_IFREG;
case 'p': return FilePermissions.S_IFIFO;
case 'l': return FilePermissions.S_IFLNK;
case 's': return FilePermissions.S_IFSOCK;
}
throw new ArgumentException ("value", "invalid device specification: " +
value);
}
private static FilePermissions GetUnixPermissionGroup (
char read, FilePermissions readb,
char write, FilePermissions writeb,
char exec, FilePermissions execb,
char xboth, char xbitonly, FilePermissions xbit)
{
FilePermissions perms = new FilePermissions ();
if (read == 'r')
perms |= readb;
if (write == 'w')
perms |= writeb;
if (exec == 'x')
perms |= execb;
else if (exec == xbitonly)
perms |= xbit;
else if (exec == xboth)
perms |= (execb | xbit);
return perms;
}
// Create ls(1) drwxrwxrwx permissions display
public static string ToUnixPermissionString (FilePermissions value)
{
char [] access = new char[] {
'-', // device
'-', '-', '-', // owner
'-', '-', '-', // group
'-', '-', '-', // other
};
bool have_device = true;
switch (value & FilePermissions.S_IFMT) {
case FilePermissions.S_IFDIR: access [0] = 'd'; break;
case FilePermissions.S_IFCHR: access [0] = 'c'; break;
case FilePermissions.S_IFBLK: access [0] = 'b'; break;
case FilePermissions.S_IFREG: access [0] = '-'; break;
case FilePermissions.S_IFIFO: access [0] = 'p'; break;
case FilePermissions.S_IFLNK: access [0] = 'l'; break;
case FilePermissions.S_IFSOCK: access [0] = 's'; break;
default: have_device = false; break;
}
SetUnixPermissionGroup (value, access, 1,
FilePermissions.S_IRUSR, FilePermissions.S_IWUSR, FilePermissions.S_IXUSR,
's', 'S', FilePermissions.S_ISUID);
SetUnixPermissionGroup (value, access, 4,
FilePermissions.S_IRGRP, FilePermissions.S_IWGRP, FilePermissions.S_IXGRP,
's', 'S', FilePermissions.S_ISGID);
SetUnixPermissionGroup (value, access, 7,
FilePermissions.S_IROTH, FilePermissions.S_IWOTH, FilePermissions.S_IXOTH,
't', 'T', FilePermissions.S_ISVTX);
return have_device
? new string (access)
: new string (access, 1, 9);
}
private static void SetUnixPermissionGroup (FilePermissions value,
char[] access, int index,
FilePermissions read, FilePermissions write, FilePermissions exec,
char both, char setonly, FilePermissions setxbit)
{
if (UnixFileSystemInfo.IsSet (value, read))
access [index] = 'r';
if (UnixFileSystemInfo.IsSet (value, write))
access [index+1] = 'w';
access [index+2] = GetSymbolicMode (value, exec, both, setonly, setxbit);
}
// Implement the GNU ls(1) permissions spec; see `info coreutils ls`,
// section 10.1.2, the `-l' argument information.
private static char GetSymbolicMode (FilePermissions value,
FilePermissions xbit, char both, char setonly, FilePermissions setxbit)
{
bool is_x = UnixFileSystemInfo.IsSet (value, xbit);
bool is_sx = UnixFileSystemInfo.IsSet (value, setxbit);
if (is_x && is_sx)
return both;
if (is_sx)
return setonly;
if (is_x)
return 'x';
return '-';
}
public static readonly DateTime UnixEpoch =
new DateTime (year:1970, month:1, day:1, hour:0, minute:0, second:0, kind:DateTimeKind.Utc);
public static readonly DateTime LocalUnixEpoch =
new DateTime (1970, 1, 1);
public static readonly TimeSpan LocalUtcOffset =
TimeZone.CurrentTimeZone.GetUtcOffset (DateTime.UtcNow);
public static DateTime ToDateTime (long time)
{
return FromTimeT (time);
}
public static long FromDateTime (DateTime time)
{
return ToTimeT (time);
}
public static DateTime FromTimeT (long time)
{
return UnixEpoch.AddSeconds (time).ToLocalTime ();
}
public static long ToTimeT (DateTime time)
{
if (time.Kind == DateTimeKind.Unspecified)
throw new ArgumentException ("DateTimeKind.Unspecified is not supported. Use Local or Utc times.", "time");
if (time.Kind == DateTimeKind.Local)
time = time.ToUniversalTime ();
return (long) (time - UnixEpoch).TotalSeconds;
}
public static OpenFlags ToOpenFlags (FileMode mode, FileAccess access)
{
OpenFlags flags = 0;
switch (mode) {
case FileMode.CreateNew:
flags = OpenFlags.O_CREAT | OpenFlags.O_EXCL;
break;
case FileMode.Create:
flags = OpenFlags.O_CREAT | OpenFlags.O_TRUNC;
break;
case FileMode.Open:
// do nothing
break;
case FileMode.OpenOrCreate:
flags = OpenFlags.O_CREAT;
break;
case FileMode.Truncate:
flags = OpenFlags.O_TRUNC;
break;
case FileMode.Append:
flags = OpenFlags.O_APPEND;
break;
default:
throw new ArgumentException (Locale.GetText ("Unsupported mode value"), "mode");
}
// Is O_LARGEFILE supported?
int _v;
if (TryFromOpenFlags (OpenFlags.O_LARGEFILE, out _v))
flags |= OpenFlags.O_LARGEFILE;
switch (access) {
case FileAccess.Read:
flags |= OpenFlags.O_RDONLY;
break;
case FileAccess.Write:
flags |= OpenFlags.O_WRONLY;
break;
case FileAccess.ReadWrite:
flags |= OpenFlags.O_RDWR;
break;
default:
throw new ArgumentOutOfRangeException (Locale.GetText ("Unsupported access value"), "access");
}
return flags;
}
public static string ToFopenMode (FileAccess access)
{
switch (access) {
case FileAccess.Read: return "rb";
case FileAccess.Write: return "wb";
case FileAccess.ReadWrite: return "r+b";
default: throw new ArgumentOutOfRangeException ("access");
}
}
public static string ToFopenMode (FileMode mode)
{
switch (mode) {
case FileMode.CreateNew: case FileMode.Create: return "w+b";
case FileMode.Open: case FileMode.OpenOrCreate: return "r+b";
case FileMode.Truncate: return "w+b";
case FileMode.Append: return "a+b";
default: throw new ArgumentOutOfRangeException ("mode");
}
}
private static readonly string[][] fopen_modes = new string[][]{
// Read Write ReadWrite
/* FileMode.CreateNew: */ new string[]{"Can't Read+Create", "wb", "w+b"},
/* FileMode.Create: */ new string[]{"Can't Read+Create", "wb", "w+b"},
/* FileMode.Open: */ new string[]{"rb", "wb", "r+b"},
/* FileMode.OpenOrCreate: */ new string[]{"rb", "wb", "r+b"},
/* FileMode.Truncate: */ new string[]{"Cannot Truncate and Read","wb", "w+b"},
/* FileMode.Append: */ new string[]{"Cannot Append and Read", "ab", "a+b"},
};
public static string ToFopenMode (FileMode mode, FileAccess access)
{
int fm = -1, fa = -1;
switch (mode) {
case FileMode.CreateNew: fm = 0; break;
case FileMode.Create: fm = 1; break;
case FileMode.Open: fm = 2; break;
case FileMode.OpenOrCreate: fm = 3; break;
case FileMode.Truncate: fm = 4; break;
case FileMode.Append: fm = 5; break;
}
switch (access) {
case FileAccess.Read: fa = 0; break;
case FileAccess.Write: fa = 1; break;
case FileAccess.ReadWrite: fa = 2; break;
}
if (fm == -1)
throw new ArgumentOutOfRangeException ("mode");
if (fa == -1)
throw new ArgumentOutOfRangeException ("access");
string fopen_mode = fopen_modes [fm][fa];
if (fopen_mode [0] != 'r' && fopen_mode [0] != 'w' && fopen_mode [0] != 'a')
throw new ArgumentException (fopen_mode);
return fopen_mode;
}
[DllImport (LIB, EntryPoint="Mono_Posix_FromStat")]
private static extern int FromStat (ref Stat source, IntPtr destination);
public static bool TryCopy (ref Stat source, IntPtr destination)
{
return FromStat (ref source, destination) == 0;
}
[DllImport (LIB, EntryPoint="Mono_Posix_ToStat")]
private static extern int ToStat (IntPtr source, out Stat destination);
public static bool TryCopy (IntPtr source, out Stat destination)
{
return ToStat (source, out destination) == 0;
}
[DllImport (LIB, EntryPoint="Mono_Posix_FromStatvfs")]
private static extern int FromStatvfs (ref Statvfs source, IntPtr destination);
public static bool TryCopy (ref Statvfs source, IntPtr destination)
{
return FromStatvfs (ref source, destination) == 0;
}
[DllImport (LIB, EntryPoint="Mono_Posix_ToStatvfs")]
private static extern int ToStatvfs (IntPtr source, out Statvfs destination);
public static bool TryCopy (IntPtr source, out Statvfs destination)
{
return ToStatvfs (source, out destination) == 0;
}
}
}
// vim: noexpandtab

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,83 @@
//
// Authors:
// Tim Jenks (tim.jenks@realtimeworlds.com)
//
// (C) 2008 Realtime Worlds Ltd
//
// 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 System.Runtime.InteropServices;
using System.Threading;
namespace Mono.Unix.Native {
public struct RealTimeSignum
#if NET_2_0
: IEquatable <RealTimeSignum>
#endif
{
private int rt_offset;
private static readonly int MaxOffset = UnixSignal.GetSIGRTMAX () - UnixSignal.GetSIGRTMIN () - 1;
public static readonly RealTimeSignum MinValue = new RealTimeSignum (0);
public static readonly RealTimeSignum MaxValue = new RealTimeSignum (MaxOffset);
public RealTimeSignum (int offset)
{
if (offset < 0)
throw new ArgumentOutOfRangeException ("Offset cannot be negative");
if (offset > MaxOffset)
throw new ArgumentOutOfRangeException ("Offset greater than maximum supported SIGRT");
rt_offset = offset;
}
public int Offset {
get { return rt_offset; }
}
public override int GetHashCode ()
{
return rt_offset.GetHashCode ();
}
public override bool Equals (object obj)
{
if ((obj == null) || (obj.GetType () != GetType ()))
return false;
return Equals ((RealTimeSignum)obj);
}
public bool Equals (RealTimeSignum value)
{
return Offset == value.Offset;
}
public static bool operator== (RealTimeSignum lhs, RealTimeSignum rhs)
{
return lhs.Equals (rhs);
}
public static bool operator!= (RealTimeSignum lhs, RealTimeSignum rhs)
{
return !lhs.Equals (rhs);
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1 @@
7ba53e922bf7d1dd53db2206246a8281c522af7c

View File

@@ -0,0 +1,138 @@
//
// TypeAttributes.cs
//
// Author:
// Jonathan Pryor (jonpryor@vt.edu)
//
// (C) 2006 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;
namespace Mono.Unix.Native {
[AttributeUsage (AttributeTargets.Field)]
internal class blkcnt_tAttribute : MapAttribute {
public blkcnt_tAttribute () : base ("blkcnt_t")
{
}
}
[AttributeUsage (AttributeTargets.Field)]
internal class blksize_tAttribute : MapAttribute {
public blksize_tAttribute () : base ("blksize_t")
{
}
}
[AttributeUsage (AttributeTargets.Field)]
internal class dev_tAttribute : MapAttribute {
public dev_tAttribute () : base ("dev_t")
{
}
}
[AttributeUsage (AttributeTargets.Field)]
internal class gid_tAttribute : MapAttribute {
public gid_tAttribute () : base ("gid_t")
{
}
}
[AttributeUsage (AttributeTargets.Field)]
internal class fsblkcnt_tAttribute : MapAttribute {
public fsblkcnt_tAttribute () : base ("fsblkcnt_t")
{
}
}
[AttributeUsage (AttributeTargets.Field)]
internal class fsfilcnt_tAttribute : MapAttribute {
public fsfilcnt_tAttribute () : base ("fsfilcnt_t")
{
}
}
[AttributeUsage (AttributeTargets.Field)]
internal class ino_tAttribute : MapAttribute {
public ino_tAttribute () : base ("ino_t")
{
}
}
[AttributeUsage (AttributeTargets.Field)]
internal class nlink_tAttribute : MapAttribute {
public nlink_tAttribute () : base ("nlink_t")
{
}
}
[AttributeUsage (AttributeTargets.Field)]
internal class off_tAttribute : MapAttribute {
public off_tAttribute () : base ("off_t")
{
}
}
[AttributeUsage (AttributeTargets.Field)]
internal class pid_tAttribute : MapAttribute {
public pid_tAttribute () : base ("pid_t")
{
}
}
[AttributeUsage (AttributeTargets.Field)]
internal class suseconds_tAttribute : MapAttribute {
public suseconds_tAttribute () : base ("suseconds_t")
{
}
}
[AttributeUsage (AttributeTargets.Field)]
internal class uid_tAttribute : MapAttribute {
public uid_tAttribute () : base ("uid_t")
{
}
}
[AttributeUsage (AttributeTargets.Field)]
internal class time_tAttribute : MapAttribute {
public time_tAttribute () : base ("time_t")
{
}
}
}