internal void OnUnmount(LinuxMount mount) { _mountSemaphore.Release(); }
private void UnmountISO(LinuxMount mount) { string cmdArguments; string cmdFilename; if (mount != null) { Logger.Info( "[{0}] Attempting to unmount ISO [{1}] mounted on [{2}].", Name, mount.IsoPath, mount.MountedPath ); } else { throw new ArgumentNullException(nameof(mount)); } if (GetUID() == 0) { cmdFilename = UmountCommand; cmdArguments = string.Format("\"{0}\"", mount.MountedPath); } else { cmdFilename = SudoCommand; cmdArguments = string.Format("\"{0}\" \"{1}\"", UmountCommand, mount.MountedPath); } Logger.Debug( "[{0}] Umount command [{1}], umount arguments [{2}].", Name, cmdFilename, cmdArguments ); if (ExecuteCommand(cmdFilename, cmdArguments)) { Logger.Info( "[{0}] ISO unmount completed successfully.", Name ); } else { Logger.Info( "[{0}] ISO unmount completed with errors.", Name ); } try { FileSystem.DeleteDirectory(mount.MountedPath, false); } catch (Exception ex) { Logger.Info( "[{0}] Unhandled exception removing mount point, exception is [{1}].", Name, ex.Message ); } }
internal void OnUnmount(LinuxMount mount) { UnmountISO(mount); }
private bool MountISO(string isoPath, out LinuxMount mountedISO) { string cmdArguments; string cmdFilename; string mountPoint = Path.Combine(MountPointRoot, Guid.NewGuid().ToString()); if (!string.IsNullOrEmpty(isoPath)) { Logger.Info( "[{0}] Attempting to mount [{1}].", Name, isoPath ); Logger.Debug( "[{0}] ISO will be mounted at [{1}].", Name, mountPoint ); } else { throw new ArgumentNullException(nameof(isoPath)); } try { FileSystem.CreateDirectory(mountPoint); } catch (UnauthorizedAccessException) { throw new IOException("Unable to create mount point(Permission denied) for " + isoPath); } catch (Exception) { throw new IOException("Unable to create mount point for " + isoPath); } if (GetUID() == 0) { cmdFilename = MountCommand; cmdArguments = string.Format("\"{0}\" \"{1}\"", isoPath, mountPoint); } else { cmdFilename = SudoCommand; cmdArguments = string.Format("\"{0}\" \"{1}\" \"{2}\"", MountCommand, isoPath, mountPoint); } Logger.Debug( "[{0}] Mount command [{1}], mount arguments [{2}].", Name, cmdFilename, cmdArguments ); if (ExecuteCommand(cmdFilename, cmdArguments)) { Logger.Info( "[{0}] ISO mount completed successfully.", Name ); mountedISO = new LinuxMount(this, isoPath, mountPoint); } else { Logger.Info( "[{0}] ISO mount completed with errors.", Name ); try { FileSystem.DeleteDirectory(mountPoint, false); } catch (Exception ex) { Logger.Info( "[{0}] Unhandled exception removing mount point, exception is [{1}].", Name, ex.Message ); } mountedISO = null; } return(mountedISO != null); }