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); }
public void Open(string path, FileAccessMode access, FileOpenMode mode, FilePermissions permissions, Action <UvArgs> callback = null) { if (this.IsDisposed) { throw new InvalidOperationException("Cannot open a stream after it has been disposed"); } if (this.Status != FileStatus.Closed) { throw new InvalidOperationException(String.Format("Cannot open a file handle when it's status is {0}", this.Status)); } IntPtr req = IntPtr.Zero; try { req = this.CreateRequest(); CheckError(uv_fs_open(this.Loop, req, path, access, mode, permissions, _openDelegate)); this.Status = FileStatus.Opening; _openCallback = new UvCallback(this, callback); } catch (Exception) { this.FreeRequest(req); throw; } }
public Result Chmod(string path, FilePermissions permissions) { #if DEBUG var request = new CrazyFsRequest(CrazyFsRequestName.Chmod, new[] { new KeyValuePair <string, string>("path", path), new KeyValuePair <string, string>("permissions", permissions.ToString()) }).Log(); #endif try { FileSystem.Path.Chmod(path, permissions); var result = new Result(ResultStatus.Success); #if DEBUG request.Log(result); #endif return(result); } catch (Exception ex) { var result = ex.GetResult(); #if DEBUG request.Log(result); #endif return(result); } }
public Result CreateSpecialFile(string path, FilePermissions mode, ulong rdev) { #if DEBUG var request = new CrazyFsRequest(CrazyFsRequestName.CreateSpecialFile, new[] { new KeyValuePair <string, string>("path", path), new KeyValuePair <string, string>("rdev", rdev.ToString()) }).Log(); #endif try { FileSystem.File.CreateSpecialFile(path, mode, rdev); var result = new Result(ResultStatus.Success); #if DEBUG request.Log(result); #endif return(result); } catch (Exception ex) { var result = ex.GetResult(); #if DEBUG request.Log(result); #endif return(result); } }
public Result CreateDirectory(string path, FilePermissions mode) { #if DEBUG var request = new CrazyFsRequest(CrazyFsRequestName.CreateDirectory, new[] { new KeyValuePair <string, string>("path", path), new KeyValuePair <string, string>("mode", mode.ToString()) }).Log(); #endif try { FileSystem.Directory.CreateDirectory(path, mode); var result = new Result(ResultStatus.Success); #if DEBUG request.Log(result); #endif return(result); } catch (Exception ex) { var result = ex.GetResult(); #if DEBUG request.Log(result); #endif return(result); } }
public static Handle Create (string uri, OpenMode mode, bool exclusive, FilePermissions perm, int priority, AsyncCallback callback) { IntPtr handle = IntPtr.Zero; AsyncCallbackWrapper wrapper = new AsyncCallbackWrapper (callback, null); gnome_vfs_async_create (out handle, uri, mode, exclusive, (uint)perm, priority, wrapper.NativeDelegate, IntPtr.Zero); return new Handle (handle); }
public Result CreateFile(string path, FilePermissions mode, ulong rdev) { var parentDirPath = GetParentDirectory(path); return(IsDirectoryValid(parentDirPath) .Check(() => !fileRepository.IsFileExists(path), FileSystemError.AlreadyExist) .Then(() => { var fileName = GetFileName(path); var now = DateTimeOffset.Now; var uid = Syscall.getuid(); var gid = Syscall.getgid(); var file = new FileModel { Path = parentDirPath, Name = fileName, Data = new byte[0], ExtendedAttributes = new ExtendedAttributes(), ModifiedTimestamp = now, FilePermissions = mode, GID = gid, UID = uid, }; fileRepository.WriteFile(file); return Result.Ok(); })); }
public virtual void CreateSpecialFile(string path, FilePermissions mode, ulong rdev) { if (Syscall.mknod(path.GetPath(_source), mode, rdev) != -1) { throw new NativeException((int)Stdlib.GetLastError()); } }
public override Errno OnCreateSpecialFile( string file, FilePermissions perms, ulong dev) { Trace.WriteLine($"OnCreateSpecialFile {file} Permissions:{perms}"); string target = GetTargetPath(file); int r = 0; if ((perms & FilePermissions.S_IFMT) == FilePermissions.S_IFREG) { r = Syscall.open(target, OpenFlags.O_CREAT | OpenFlags.O_EXCL | OpenFlags.O_WRONLY, perms); if (r >= 0) { r = Syscall.close(r); } } else if ((perms & FilePermissions.S_IFMT) == FilePermissions.S_IFIFO) { r = Syscall.mkfifo(target, perms); } else { r = Syscall.mknod(target, perms, dev); } if (r < 0) { return(GetLastError()); } return(0); }
public override Errno OnCreateDirectory( string directory, FilePermissions mode) { Trace.WriteLine($"OnCreateDirectory {directory} Permissions={mode}"); string directoryToCreate = GetTargetPath(directory); string parent = Directory.GetParent(directoryToCreate).FullName; Errno errno = Access(parent, AccessModes.W_OK); if (errno < 0) { return(errno); } int fd = Syscall.mkdir(directoryToCreate, mode); if (fd < 0) { Trace.WriteLine(string.Format("\tmkdir returned {0}", GetLastError())); return(GetLastError()); } return(0); }
public void TestPermissions() { Assert.AreEqual(FilePermissions.FromOctalString("644"), FilePermissions.DefaultFilePermissions); Assert.AreEqual(FilePermissions.FromOctalString("755"), FilePermissions.DefaultFolderPermissions); LayerEntriesDo( (layerName, layerEntry) => { if (layerEntry.IsFile()) { const PosixFilePermissions expectedFilePermissions = PosixFilePermissions.OwnerRead | PosixFilePermissions.OwnerWrite | PosixFilePermissions.GroupRead | PosixFilePermissions.OthersRead; Assert.AreEqual( expectedFilePermissions, layerEntry.GetMode() & PosixFilePermissions.All, layerName + ": " + layerEntry.Name); } else if (layerEntry.IsDirectory) { const PosixFilePermissions expectedDirectoryPermissions = PosixFilePermissions.OwnerAll | PosixFilePermissions.GroupReadExecute | PosixFilePermissions.OthersReadExecute; Assert.AreEqual( expectedDirectoryPermissions, layerEntry.GetMode() & PosixFilePermissions.All, layerName + ": " + layerEntry.Name); } }); }
public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args) .UseSystemd() .ConfigureAppConfiguration((hostContext, config) => { // see chmod(2), https://linux.die.net/man/2/chmod for reference FilePermissions root600 = FilePermissions.S_IRUSR | FilePermissions.S_IWUSR | FilePermissions.S_IFREG; FilePermissions root640 = FilePermissions.S_IRUSR | FilePermissions.S_IWUSR | FilePermissions.S_IRGRP | FilePermissions.S_IFREG; if (File.Exists("/etc/EchoSeven/appsettings.json") && UnixFileSystemInfo.GetFileSystemEntry("/etc/EchoSeven/appsettings.json").OwnerUser.UserName.Equals("root") && UnixFileSystemInfo.GetFileSystemEntry("/etc/EchoSeven/appsettings.json").OwnerGroup.GroupName.Equals("root") && (UnixFileSystemInfo.GetFileSystemEntry("/etc/EchoSeven/appsettings.json").Protection.Equals(root600) || UnixFileSystemInfo.GetFileSystemEntry("/etc/EchoSeven/appsettings.json").Protection.Equals(root640)) && UnixEnvironment.EffectiveUser.UserName.Equals("root")) { var settings = config.Build(); config.AddJsonFile("/etc/EchoSeven/appsettings.json", optional: true, reloadOnChange: false); } }) .ConfigureServices((hostContext, services) => { IConfiguration configuration = hostContext.Configuration; EchoServerOptions options = configuration.GetSection("EchoService").Get <EchoServerOptions>(); services.AddSingleton(options); services.AddHostedService <EchoSevenService>(); });
public void Chmod(string path, FilePermissions permissions) { if (Syscall.chmod(path.GetPath(_source), permissions) == -1) { throw new NativeException((int)Stdlib.GetLastError()); } }
protected void SetPermissions(string path, string mask, string group, FilePermissions permissions) { _logger.Debug("Setting permissions: {0} on {1}", mask, path); // Preserve non-access permissions if (Syscall.stat(path, out var curStat) < 0) { var error = Stdlib.GetLastError(); throw new LinuxPermissionsException("Error getting current permissions: " + error); } // Preserve existing non-access permissions unless mask is 4 digits if (mask.Length < 4) { permissions |= curStat.st_mode & ~FilePermissions.ACCESSPERMS; } if (Syscall.chmod(path, permissions) < 0) { var error = Stdlib.GetLastError(); throw new LinuxPermissionsException("Error setting permissions: " + error); } var groupId = GetGroupId(group); if (Syscall.chown(path, unchecked ((uint)-1), groupId) < 0) { var error = Stdlib.GetLastError(); throw new LinuxPermissionsException("Error setting group: " + error); } }
private void WriteToBaseLog(string message) { string log = $"[{DateTime.Now:MM/dd/yyyy h:mm:ss.fff tt}]----------------------------------------\n{message}"; File.AppendAllText(baseDirectory + "BaseLog.txt", log); File.SetAccessControl(baseDirectory + "BaseLog.txt", FilePermissions.CreateFilePermissions()); }
public bool Read(NfsPacket packet) { type = (FileType)packet.GetUInt(); mode = (FilePermissions)packet.GetUInt(); nlink = packet.GetUInt(); uid = packet.GetUInt(); gid = packet.GetUInt(); size = packet.GetUInt(); blocksize = packet.GetUInt(); rdev = packet.GetUInt(); blocks = packet.GetUInt(); fsid = packet.GetUInt(); fileid = packet.GetUInt(); if (!lastAccessed.Read(packet)) { return(false); } if (!lastModified.Read(packet)) { return(false); } if (!lastChanged.Read(packet)) { return(false); } return(true); }
protected void SetWritePermissionsInternal(string path, bool writable, bool setgid) { // Remove Write permissions, we're still owner so we can clean it up, but we'll have to do that explicitly. Stat stat; Syscall.stat(path, out stat); FilePermissions mode = stat.st_mode; if (writable) { mode |= FilePermissions.S_IWUSR | FilePermissions.S_IWGRP | FilePermissions.S_IWOTH; } else { mode &= ~(FilePermissions.S_IWUSR | FilePermissions.S_IWGRP | FilePermissions.S_IWOTH); } if (setgid) { mode |= FilePermissions.S_ISGID; } else { mode &= ~FilePermissions.S_ISGID; } if (stat.st_mode != mode) { if (Syscall.chmod(path, mode) < 0) { var error = Stdlib.GetLastError(); throw new LinuxPermissionsException("Error setting group: " + error); } } }
public virtual int ReadFrom(byte[] buffer, int offset) { DescriptorTag = Utilities.ToStruct<DescriptorTag>(buffer, offset); InformationControlBlock = Utilities.ToStruct<InformationControlBlock>(buffer, offset + 16); Uid = Utilities.ToUInt32LittleEndian(buffer, offset + 36); Gid = Utilities.ToUInt32LittleEndian(buffer, offset + 40); Permissions = (FilePermissions)Utilities.ToUInt32LittleEndian(buffer, offset + 44); FileLinkCount = Utilities.ToUInt16LittleEndian(buffer, offset + 48); RecordFormat = buffer[offset + 50]; RecordDisplayAttributes = buffer[offset + 51]; RecordLength = Utilities.ToUInt16LittleEndian(buffer, offset + 52); InformationLength = Utilities.ToUInt64LittleEndian(buffer, offset + 56); LogicalBlocksRecorded = Utilities.ToUInt64LittleEndian(buffer, offset + 64); AccessTime = UdfUtilities.ParseTimestamp(buffer, offset + 72); ModificationTime = UdfUtilities.ParseTimestamp(buffer, offset + 84); AttributeTime = UdfUtilities.ParseTimestamp(buffer, offset + 96); Checkpoint = Utilities.ToUInt32LittleEndian(buffer, offset + 108); ExtendedAttributeIcb = Utilities.ToStruct<LongAllocationDescriptor>(buffer, offset + 112); ImplementationIdentifier = Utilities.ToStruct<ImplementationEntityIdentifier>(buffer, offset + 128); UniqueId = Utilities.ToUInt64LittleEndian(buffer, offset + 160); ExtendedAttributesLength = Utilities.ToInt32LittleEndian(buffer, offset + 168); AllocationDescriptorsLength = Utilities.ToInt32LittleEndian(buffer, offset + 172); AllocationDescriptors = Utilities.ToByteArray(buffer, offset + 176 + ExtendedAttributesLength, AllocationDescriptorsLength); byte[] eaData = Utilities.ToByteArray(buffer, offset + 176, ExtendedAttributesLength); ExtendedAttributes = ReadExtendedAttributes(eaData); return (int)(176 + ExtendedAttributesLength + AllocationDescriptorsLength); }
protected override Errno OnCreateSpecialFile(string path, FilePermissions mode, ulong rdev) { int r; // On Linux, this could just be `mknod(basedir+path, mode, rdev)' but this is // more portable. if ((mode & FilePermissions.S_IFMT) == FilePermissions.S_IFREG) { r = Syscall.open(basedir + path, OpenFlags.O_CREAT | OpenFlags.O_EXCL | OpenFlags.O_WRONLY, mode); if (r >= 0) { r = Syscall.close(r); } } else if ((mode & FilePermissions.S_IFMT) == FilePermissions.S_IFIFO) { r = Syscall.mkfifo(basedir + path, mode); } else { r = Syscall.mknod(basedir + path, mode, rdev); } if (r == -1) { return(Stdlib.GetLastError()); } return(0); }
/** * Adds an entry to the layer. If the source file is a directory, the directory and its contents * will be added recursively. * * @param sourceFile the source file to add to the layer recursively * @param pathInContainer the path in the container file system corresponding to the {@code * sourceFile} * @param filePermissionProvider a provider that takes a source path and destination path on the * container and returns the file permissions that should be set for that path * @param lastModifiedTimeProvider a provider that takes a source path and destination path on * the container and returns the file modification time that should be set for that path * @return this * @throws IOException if an exception occurred when recursively listing the directory */ public Builder AddEntryRecursive( SystemPath sourceFile, AbsoluteUnixPath pathInContainer, Func <SystemPath, AbsoluteUnixPath, FilePermissions> filePermissionProvider, Func <SystemPath, AbsoluteUnixPath, Instant> lastModifiedTimeProvider) { FilePermissions permissions = filePermissionProvider?.Invoke(sourceFile, pathInContainer); Instant modifiedTime = lastModifiedTimeProvider(sourceFile, pathInContainer); AddEntry(sourceFile, pathInContainer, permissions, modifiedTime); if (!Files.IsDirectory(sourceFile)) { return(this); } IEnumerable <SystemPath> files = Files.List(sourceFile); { foreach (SystemPath file in files.ToList()) { AddEntryRecursive( file, pathInContainer.Resolve(file.GetFileName()), filePermissionProvider, lastModifiedTimeProvider); } } return(this); }
protected void SetWritePermissionsInternal(string path, bool writable, bool setgid) { // Remove Write permissions, we're still owner so we can clean it up, but we'll have to do that explicitly. Stat stat; Syscall.stat(path, out stat); FilePermissions mode = stat.st_mode; if (writable) { mode |= FilePermissions.S_IWUSR | FilePermissions.S_IWGRP | FilePermissions.S_IWOTH; } else { mode &= ~(FilePermissions.S_IWUSR | FilePermissions.S_IWGRP | FilePermissions.S_IWOTH); } if (setgid) { mode |= FilePermissions.S_ISGID; } else { mode &= ~FilePermissions.S_ISGID; } if (stat.st_mode != mode) { Syscall.chmod(path, mode); } }
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; }
protected override Errno OnCreateHandle(string path, OpenedPathInfo info, FilePermissions mode) { Logger.WriteLineIf(LogLevel.Verbose, _log_props, string.Format( "OnCreateHandle, path={0}, openflags={1}, filepermission={2}, OpenAccess={3}", path, info.OpenFlags, mode, info.OpenAccess)); return(this._rfs.CreateHandle(path, info, mode)); }
/// <inheritdoc /> public void SetFileAttributes(string path, FileAttributes attributes) { int result = GetFilePermission(path); if (result < 0) { throw new BuildXLException($"Failed to get permissions for file '{path}' - error: {Marshal.GetLastWin32Error()}"); } FilePermissions filePermissions = checked ((FilePermissions)result); FilePermissions writePermissions = (FilePermissions.S_IWUSR | FilePermissions.S_IWGRP | FilePermissions.S_IWOTH); if (attributes.HasFlag(FileAttributes.ReadOnly)) { filePermissions &= ~writePermissions; } else { filePermissions |= writePermissions; } result = SetFilePermissionsForFilePath(path, filePermissions); if (result < 0) { throw new BuildXLException($"Failed to set permissions for file '{path}' - error: {Marshal.GetLastWin32Error()}"); } }
/// <summary> /// Creates the directory. Both normal and meta directories are created. /// </summary> /// <param name="path">The path.</param> /// <param name="mode">The mode.</param> public override Errno CreateDirectory(string path, FilePermissions mode) { var result = base.CreateDirectory(path, mode); if (result != 0) { // First directory creation unsuccessful. No need to create the 2nd one. return(result); } else { var metaPath = _pathFactory.CreateVirtualPath(new VirtualRawPath(path), PathFactory.FilesysOp.Read); result = base.CreateDirectory(metaPath.PathString, mode); if (result != 0) { Logger.WriteLineIf(LogLevel.Error, _log_props, string.Format( "Error occurred while creating {0}. Removing {1}... (Virtual paths)", metaPath.PathString, path)); // Error in the 2nd creation. Delete the first one. base.RemoveDirectory(path); } return(result); } }
/// <inheritdoc /> public void MoveFile(string fileName, string newFileName) { string filePath = GetFilePath(fileName); string newFilePath = GetFilePath(newFileName); try { File.Move(filePath, newFilePath); File.SetAccessControl(newFilePath, FilePermissions.CreateFilePermissions()); } catch (PathTooLongException exception) { // Determine which is the longer file name string longFileName = (fileName.Length > newFileName.Length) ? fileName : newFileName; throw new RepositoryConfigurationException(ConfigurationExceptionCategory.FileNameTooLong, this, String.Format(RepositoryExceptionMessage.TooLong_1, longFileName), exception); } catch (FileNotFoundException exception) { // Thrown when the original file could not be found. throw new RepositoryConfigurationException(ConfigurationExceptionCategory.FileNotFound, this, String.Format(RepositoryExceptionMessage.FileNotFound_1, filePath), exception); } catch (IOException exception) { // Thrown when the destination file already exists. throw new RepositoryConfigurationException(ConfigurationExceptionCategory.FileExists, this, String.Format(RepositoryExceptionMessage.FileAlreadyExists_1, newFilePath), exception); } catch (UnauthorizedAccessException exception) { // Thrown if the caller does not have the required permission. throw new RepositoryConfigurationException(ConfigurationExceptionCategory.UnauthorizedAccess, this, RepositoryExceptionMessage.PermissionDenied_1, exception); } }
public virtual int ReadFrom(byte[] buffer, int offset) { DescriptorTag = Utilities.ToStruct <DescriptorTag>(buffer, offset); InformationControlBlock = Utilities.ToStruct <InformationControlBlock>(buffer, offset + 16); Uid = Utilities.ToUInt32LittleEndian(buffer, offset + 36); Gid = Utilities.ToUInt32LittleEndian(buffer, offset + 40); Permissions = (FilePermissions)Utilities.ToUInt32LittleEndian(buffer, offset + 44); FileLinkCount = Utilities.ToUInt16LittleEndian(buffer, offset + 48); RecordFormat = buffer[offset + 50]; RecordDisplayAttributes = buffer[offset + 51]; RecordLength = Utilities.ToUInt16LittleEndian(buffer, offset + 52); InformationLength = Utilities.ToUInt64LittleEndian(buffer, offset + 56); LogicalBlocksRecorded = Utilities.ToUInt64LittleEndian(buffer, offset + 64); AccessTime = UdfUtilities.ParseTimestamp(buffer, offset + 72); ModificationTime = UdfUtilities.ParseTimestamp(buffer, offset + 84); AttributeTime = UdfUtilities.ParseTimestamp(buffer, offset + 96); Checkpoint = Utilities.ToUInt32LittleEndian(buffer, offset + 108); ExtendedAttributeIcb = Utilities.ToStruct <LongAllocationDescriptor>(buffer, offset + 112); ImplementationIdentifier = Utilities.ToStruct <ImplementationEntityIdentifier>(buffer, offset + 128); UniqueId = Utilities.ToUInt64LittleEndian(buffer, offset + 160); ExtendedAttributesLength = Utilities.ToInt32LittleEndian(buffer, offset + 168); AllocationDescriptorsLength = Utilities.ToInt32LittleEndian(buffer, offset + 172); ExtendedAttributes = Utilities.ToByteArray(buffer, offset + 176, ExtendedAttributesLength); AllocationDescriptors = Utilities.ToByteArray(buffer, offset + 176 + ExtendedAttributesLength, AllocationDescriptorsLength); return((int)(176 + ExtendedAttributesLength + AllocationDescriptorsLength)); }
/// <summary> /// Mutates <see cref="Process"/>. /// </summary> protected Process CreateAndSetUpProcess() { Contract.Requires(Process == null); #if !PLATFORM_OSX if (!FileUtilities.FileExistsNoFollow(ProcessInfo.FileName)) { ThrowFileDoesNotExist(); } #else var mode = GetFilePermissionsForFilePath(ProcessInfo.FileName, followSymlink: false); if (mode < 0) { ThrowFileDoesNotExist(); } var filePermissions = checked ((FilePermissions)mode); FilePermissions exePermission = FilePermissions.S_IXUSR; if (!filePermissions.HasFlag(exePermission)) { SetFilePermissionsForFilePath(ProcessInfo.FileName, exePermission); } #endif Process = new Process(); Process.StartInfo = new ProcessStartInfo { FileName = ProcessInfo.FileName, Arguments = ProcessInfo.Arguments, WorkingDirectory = ProcessInfo.WorkingDirectory, StandardErrorEncoding = m_output.Encoding, StandardOutputEncoding = m_error.Encoding, RedirectStandardError = true, RedirectStandardOutput = true, UseShellExecute = false, CreateNoWindow = true }; Process.StartInfo.EnvironmentVariables.Clear(); if (ProcessInfo.EnvironmentVariables != null) { foreach (var envKvp in ProcessInfo.EnvironmentVariables.ToDictionary()) { Process.StartInfo.EnvironmentVariables[envKvp.Key] = envKvp.Value; } } Process.EnableRaisingEvents = true; Process.OutputDataReceived += (sender, e) => FeedStdOut(m_output, m_stdoutFlushedTcs, e.Data); Process.ErrorDataReceived += (sender, e) => FeedStdErr(m_error, m_stderrFlushedTcs, e.Data); Process.Exited += (sender, e) => m_processExitedTcs.TrySetResult(Unit.Void); return(Process); void ThrowFileDoesNotExist() { ThrowCouldNotStartProcess(I($"File '{ProcessInfo.FileName}' not found"), new Win32Exception(0x2)); } }
public static void CreateDirectory(this IDirectory directory, string path, FilePermissions mode) { if (directory is not ILinuxDirectory dir) { throw new Exception("IDirectory is not the linux version"); } dir.CreateDirectory(path, mode); }
public override File OpenFile(string path, FilePermissions permissions, FileOpenMode mode) { using (var isolatedStorage = IsolatedStorageFile.GetUserStoreForApplication()) { var stream = isolatedStorage.OpenFile(path, EnumConverters.ToFileMode(mode), EnumConverters.ToFileAccess(permissions)); return(new PhoneFile(path, permissions, stream)); } }
public UnixStream Create (FilePermissions mode) { int fd = Syscall.creat (FullPath, mode); if (fd < 0) UnixMarshal.ThrowExceptionForLastError (); base.Refresh (); return new UnixStream (fd); }
protected virtual void CreateNonExistingFile(string path) { // copy from default location File.Copy(Path.Combine(Installation.Properties.DefaultConfigurationDirectory, Filename), path); // allow everyone to write to the config FilePermissions.SetAclForUserOnFile(path, FilePermissions.EveryoneIdentity, FileSystemRights.FullControl, AccessControlType.Allow); }
public static void chmod(string Path, FilePermissions Mode) { CheckRoot(); if (Syscall.chmod(Path, Mode) != 0) { throw new Exception("chmod failed"); } }
/** * Adds an entry to the layer with the given permissions. Only adds the single source file to * the exact path in the container file system. See {@link Builder#addEntry(Path, * AbsoluteUnixPath)} for more information. * * @param sourceFile the source file to add to the layer * @param pathInContainer the path in the container file system corresponding to the {@code * sourceFile} * @param permissions the file permissions on the container * @param lastModifiedTime the file modification timestamp * @return this * @see Builder#addEntry(Path, AbsoluteUnixPath) * @see FilePermissions#DEFAULT_FILE_PERMISSIONS * @see FilePermissions#DEFAULT_FOLDER_PERMISSIONS */ public Builder AddEntry( SystemPath sourceFile, AbsoluteUnixPath pathInContainer, FilePermissions permissions, Instant lastModifiedTime) { return(AddEntry(new LayerEntry(sourceFile, pathInContainer, permissions, lastModifiedTime))); }
public static Handle Create (Uri uri, OpenMode mode, bool exclusive, FilePermissions perm) { IntPtr handle = IntPtr.Zero; Result result = gnome_vfs_create_uri (out handle, uri.Handle, mode, exclusive, (uint)perm); if (result != Result.Ok) { Vfs.ThrowException (uri, result); return null; } else { return new Handle (handle); } }
public void CreateDirectory(string path, FilePermissions permissions, Action<UvArgs> callback = null) { IntPtr req = IntPtr.Zero; try { req = this.CreateRequest(); CheckError(Uvi.uv_fs_mkdir(this.Loop.Handle, req, path, (int)permissions, _mkdirDelegate)); _mkdirCallback = new UvCallback(this, callback); } catch (Exception) { this.FreeRequest(req); throw; } }
protected override Errno OnCreateDirectory(string directory, FilePermissions mode) { Logging.Write("In OnCreateDirectory (" + directory + ")"); // Determine which node this will be a sub-node of. string npath = directory.Substring(0, directory.LastIndexOf("/") + 1); Logging.Write("NodePath: " + npath); int parentnodeid = SoundCloudFS.FileTree.Node.FindNode(npath); Logging.Write("ParentNodeID: " + parentnodeid.ToString()); if(parentnodeid < 0) { return Errno.ENOENT; } string newnodename = directory.Substring(directory.LastIndexOf('/') + 1); int newnodeid = Engine.FSNodes[parentnodeid].AddSubNode(newnodename); Engine.FSNodes[newnodeid].NodeType = SoundCloudFS.FileTree.Node.NodeTypeTree; Logging.Write("Created Directory, newnodeid: " + newnodeid.ToString()); //return base.OnCreateDirectory (directory, mode); if(Engine.Config.AutoSaveNodes) { SoundCloudFS.FileTree.Node.SaveNodes(); } return 0; }
public static string ToOctalPermissionString (FilePermissions value) { string s = Convert.ToString ((int) (value & ~FilePermissions.S_IFMT), 8); return new string ('0', 4-s.Length) + s; }
// 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 '-'; }
protected override Errno OnCreateSpecialFile(string path, FilePermissions mode, ulong rdev) { int r; // On Linux, this could just be `mknod(basedir+path, mode, rdev)' but // this is more portable. if ((mode & FilePermissions.S_IFMT) == FilePermissions.S_IFREG) { r = Syscall.open (basedir+path, OpenFlags.O_CREAT | OpenFlags.O_EXCL | OpenFlags.O_WRONLY, mode); if (r >= 0) r = Syscall.close (r); } else if ((mode & FilePermissions.S_IFMT) == FilePermissions.S_IFIFO) { r = Syscall.mkfifo (basedir+path, mode); } else { r = Syscall.mknod (basedir+path, mode, rdev); } if (r == -1) return Stdlib.GetLastError (); return 0; }
protected override Errno OnCreateSpecialFile(string path, FilePermissions mode, ulong rdev) { Logger.WriteLineIf(LogLevel.Verbose, _fslog_props, string.Format("OnCreateSpecialFile, path={0}, mode={1}, rdev={2}", path, mode, rdev)); return this._rfs.CreateSpecialFile(path, mode, rdev); }
public static void open(string path, OpenFlags flags, FilePermissions mode, Action<int, int> callback) { eio_open (path, flags, mode, 0, openCB, GCHandle.ToIntPtr (GCHandle.Alloc (callback))); }
public static UnixDirectoryInfo CreateDirectory (string path, FilePermissions mode) { int r = Syscall.mkdir (path, mode); UnixMarshal.ThrowExceptionForLastErrorIf (r); return new UnixDirectoryInfo (path); }
public static bool TryToFilePermissions (UInt32 value, out FilePermissions rval) { return ToFilePermissions (value, out rval) == 0; }
public static bool TryFromFilePermissions (FilePermissions value, out UInt32 rval) { return FromFilePermissions (value, out rval) == 0; }
/// <summary> /// Creates the directory. Both normal and meta directories are created. /// </summary> /// <param name="path">The path.</param> /// <param name="mode">The mode.</param> public override Errno CreateDirectory(string path, FilePermissions mode) { var result = base.CreateDirectory(path, mode); if (result != 0) { // First directory creation unsuccessful. No need to create the 2nd one. return result; } else { var metaPath = _pathFactory.CreateVirtualPath(new VirtualRawPath(path), PathFactory.FilesysOp.Read); result = base.CreateDirectory(metaPath.PathString, mode); if (result != 0) { Logger.WriteLineIf(LogLevel.Error, _log_props, string.Format( "Error occurred while creating {0}. Removing {1}... (Virtual paths)", metaPath.PathString, path)); // Error in the 2nd creation. Delete the first one. base.RemoveDirectory(path); } return result; } }
/// <summary> /// Creates the handle. /// </summary> /// <param name="path">The path.</param> /// <param name="info">The info.</param> /// <param name="mode">The mode.</param> /// <returns></returns> /// <remarks>This method is for FilesysOp.Write.</remarks> public override Errno CreateHandle(string path, OpenedPathInfo info, FilePermissions mode) { // Create the handle for the write. String writePath = _pathFactory.CreateVirtualPath4Write(new VirtualRawPath(path)); Errno retVal = base.CreateHandle(writePath, info, mode); // Create the VF so the reads afterwards knows about the file. VirtualPath vp = VirtualPath.CreateFromRawString(path); VirtualFile vf = CreateAndWriteVirtualFile(vp); var ofi = new OpenFileInfo(info.Handle, vp, vf, FileAccess.Write); _filesysContext.AddOpenFile(info.Handle, ofi); return retVal; }
protected override Errno OnChangePathPermissions(string path, FilePermissions mode) { int r = Syscall.chmod (basedir+path, mode); if (r == -1) return Stdlib.GetLastError (); return 0; }
public static void SetPermissions (string path, FilePermissions perms) { int r = Syscall.chmod (path, perms); UnixMarshal.ThrowExceptionForLastErrorIf (r); }
private static extern int FromFilePermissions (FilePermissions value, out UInt32 rval);
public static UnixStream Create (string path, FilePermissions mode) { int fd = Syscall.creat (path, mode); if (fd < 0) UnixMarshal.ThrowExceptionForLastError (); return new UnixStream (fd); }
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; }
public UnixStream Open (FileMode mode, FileAccess access, FilePermissions perms) { OpenFlags flags = UnixConvert.ToOpenFlags (mode, access); int fd = Syscall.open (FullPath, flags, perms); if (fd < 0) UnixMarshal.ThrowExceptionForLastError (); return new UnixStream (fd); }
// 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); }
public UnixStream Open (OpenFlags flags, FilePermissions mode) { int fd = Syscall.open (FullPath, flags, mode); if (fd < 0) UnixMarshal.ThrowExceptionForLastError (); return new UnixStream (fd); }
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); }
protected override Errno OnCreateHandle(string path, OpenedPathInfo info, FilePermissions mode) { int fd = Syscall.open (basedir+path, info.OpenFlags, mode); if (fd == -1) return Stdlib.GetLastError (); info.Handle = (IntPtr) fd; return 0; }
protected override Errno OnCreateDirectory(string path, FilePermissions mode) { int r = Syscall.mkdir (basedir+path, mode); if (r == -1) return Stdlib.GetLastError (); return 0; }
public static UInt32 FromFilePermissions (FilePermissions value) { UInt32 rval; if (FromFilePermissions (value, out rval) == -1) ThrowArgumentException (value); return rval; }
private static extern int ToFilePermissions (UInt32 value, out FilePermissions rval);