internal void Mount() { if (MountedPath != null) { logger.Debug("MountedPath is null", null); return; } if (!CheckEnvironment()) { logger.Error("ERROR:{0}.\n", "checkEnvironment is false"); return; } Pfm.Api api = null; Pfm.ApiFactory(out api); api.FileMountFactory(out fileMount); Pfm.FileMountCreateParams fmp = new Pfm.FileMountCreateParams(); fmp.mountFileName = IsoPath; fmp.fileMountFlags |= Pfm.fileMountFlagConsoleUi; //ÔÊÐíÖظ´¹ÒÔØ fmp.fileMountFlags |= Pfm.fileMountFlagMultiMount; //ÔÊÐíÖظ´¹ÒÔØ fmp.mountFlags = Pfm.mountFlagReadOnly; //Ö»¶Á int error = 0; logger.Debug("pfm do mount", null); error = fileMount.Start(fmp); if (error != Pfm.errorSuccess) { logger.Error("ERROR: {0} Unable to create mount.\n", error); return; } error = fileMount.WaitReady(); if (error != Pfm.errorSuccess) { logger.Error("ERROR: {0} Unable to create mount.\n", error); return; } mount = fileMount.GetMount(); MountedPath = mount.GetMountPoint(); MountedFolderPath = mount.GetMountPoint(); MountedProtocol = MediaProtocol.File; if (string.Equals(container, MediaContainer.DvdIso.ToString(), StringComparison.OrdinalIgnoreCase)) { //var files = mediaEncoder.GetDvdVobFiles(MountedFolderPath); var files = fileSystem.GetFilePaths(MountedFolderPath, new string[] { ".vob" }, false, true); MountedPath = string.Join("|", files); } else if (string.Equals(container, MediaContainer.BlurayIso.ToString(), StringComparison.OrdinalIgnoreCase)) { //var files = mediaEncoder.GetBlurayM2tsFiles(MountedFolderPath); var files = fileSystem.GetFilePaths(MountedFolderPath, new string[] { ".m2tfs" }, false, true); MountedPath = string.Join("|", files); } else if (string.Equals(container, MediaContainer.Iso.ToString(), StringComparison.OrdinalIgnoreCase)) { //var files = mediaEncoder.GetBlurayM2tsFiles(MountedFolderPath); var files = fileSystem.GetFilePaths(MountedFolderPath, new string[] { ".m2tfs" }, false, true); MountedPath = string.Join("|", files); } logger.Debug("pfm mount result,MountedPath: [{0}],MountedFolderPath:[{1}]", MountedPath, MountedFolderPath); }
static void Main(string[] args) { int err = 0; Pfm.Api pfm = null; Pfm.Mount mount = null; Pfm.MountCreateParams mcp = new Pfm.MountCreateParams(); Pfm.MarshallerServeParams msp = new Pfm.MarshallerServeParams(); Volume volume = new Volume(); IntPtr invalidFd = new IntPtr(-1); msp.dispatch = volume; msp.formatterName = "hellofs"; if (args.Length != 1) { Console.Write( "Sample file system application.\n" + "syntax: hellofs <mount name>\n"); err = -1; } if (err == 0) { mcp.mountSourceName = args[0]; err = Pfm.ApiFactory(out pfm); if (err != 0) { Console.Write("ERROR: {0} Unable to open PFM API.\n", err); } } if (err == 0) { err = Pfm.MarshallerFactory(out volume.marshaller); if (err != 0) { Console.Write("ERROR: {0} Unable to create marshaller.\n", err); } } if (err == 0) { // Communication between the driver and file system is done // over a pair of simple pipes. Application is responsible // for creating the pipes. err = Pfm.SystemCreatePipe(out msp.toFormatterRead, out mcp.toFormatterWrite); if (err == 0) { err = Pfm.SystemCreatePipe(out mcp.fromFormatterRead, out msp.fromFormatterWrite); } } if (err == 0) { // Various mount options are available through mountFlags, // visibleProcessId, and ownerSid. err = pfm.MountCreate(mcp, out mount); if (err != 0) { Console.Write("ERROR: {0} Unable to create mount.\n", err); } } // Close driver end pipe handles now. Driver has duplicated what // it needs. If these handles are not closed then pipes will not // break if driver disconnects, leaving us stuck in the // marshaller. Pfm.SystemCloseFd(mcp.toFormatterWrite); Pfm.SystemCloseFd(mcp.fromFormatterRead); if (err == 0) { // If tracemon is installed and running then diagnostic // messsages can be viewed in the "hellofs" channel. volume.marshaller.SetTrace(mount.GetMountEndName()); // Also send diagnostic messages to stdout. This can slow // things down quite a bit. IntPtr stdoutFd = invalidFd; Pfm.SystemGetStdout(out stdoutFd); volume.marshaller.SetStatus(stdoutFd); // The marshaller uses alertable I/O, so process can be // exited via ctrl+c. Console.Write("Press CTRL+C to exit.\n"); // The marshaller serve function will return at unmount or // if driver disconnects. volume.marshaller.ServeDispatch(msp); } Pfm.SystemCloseFd(msp.toFormatterRead); Pfm.SystemCloseFd(msp.fromFormatterWrite); if (pfm != null) { pfm.Dispose(); } if (mount != null) { mount.Dispose(); } if (volume.marshaller != null) { volume.marshaller.Dispose(); } }
static int Main(string[] args) { int err = 0; int argi; string arg = null; bool showHelp = false; bool showBanner = true; Pfm.Api pfm = null; Pfm.FileMount mount = null; Pfm.FileMountCreateParams fmp = new Pfm.FileMountCreateParams(); fmp.fileMountFlags |= Pfm.fileMountFlagInProcess; argi = 0; while (argi < args.Length) { arg = args[argi++]; showBanner = false; if (arg.Length == 2 && arg[0] == '-') { switch (arg[1]) { case 'h': case 'H': case '?': showHelp = true; break; case 'm': case 'M': if (argi < args.Length) { arg = args[argi++]; if (arg.Length < 1 || arg.Length > 2 || (arg.Length == 2 && arg[1] != ':')) { Console.Write("ERROR: Invalid drive letter \"{0}\".\n", arg); err = -1; } else { fmp.driveLetter = arg[0]; } } break; case 'p': case 'P': if (argi < args.Length) { arg = args[argi++]; fmp.password = arg; } break; default: Console.Write("WARNING: Ignoring unknown command line switch \"{0}\".\n", arg); break; } } else if (fmp.mountFileName == null) { fmp.mountFileName = arg; } else { Console.Write("WARNING: Ignoring extra command line argument \"{0}\".\n", arg); } } if (showHelp) { Console.Write("syntax: mounter [<switch> ...] <container file>\n" + "switches:\n" + " -h Show this help information.\n" + " -m <drive letter> Mount at specified drive letter.\n" + " -p <password> Answer for password prompt.\n"); err = -1; } else if (showBanner) { Console.Write("Pismo Mounter Sample\n" + "Copyright 2012-2015 Joe Lowe\n" + "For help run: mounter -h\n"); err = -1; } else if (fmp.mountFileName == null) { Console.Write("ERROR: Must supply container file name.\n"); err = -1; } else { err = Pfm.InstallCheck(); if (err == Pfm.instInstalled) { err = 0; } else if (err == Pfm.instOldBuild) { Console.Write("WARNING: PFM system extension is old, consider updating.\n"); err = 0; } else { if (err == Pfm.instOldVersion) { Console.Write("NOTE: PFM system extension is too old, update required.\n"); } else // (err == Pfm.instNotInstalled) { Console.Write("NOTE: PFM system extension is not installed.\n"); } // Auto-installation is left as an exercise for the // implementor. err = -1; // if(!IsUserPriviliged()) // { // Console.Write("ERROR: PFM system extension must be installed. Rerun command as administrator.\n"); // } // else // { // Console.Write("NOTE: Installing PFM system extension.\n"); // if(RunCmd("pfminst install") == 0) // { // err = 0; // } // } if (err != 0) { Console.Write("ERROR: PFM system extension installation failed.\n"); } } } if (err == 0) { err = Pfm.ApiFactory(out pfm); if (err != 0) { Console.Write("ERROR: {0} Unable to open PFM Api.\n", err); } } if (err == 0) { err = pfm.FileMountFactory(out mount); if (err == 0) { err = mount.Start(fmp); } if (err != 0) { Console.Write("ERROR: {0} Unable to create mount.\n", err); } } if (err == 0) { err = mount.WaitReady(); } if (err == 0) { Console.Write("Press 'q' to exit.\n"); do { arg = Console.ReadKey(false /*display*/).Key.ToString(); } while(arg.Length != 0 && arg != "q" && arg != "Q"); mount.Cancel(); } if (mount != null) { if (err != 0) { mount.Cancel(); } mount.Detach(); mount.Dispose(); } if (pfm != null) { pfm.Dispose(); } return(err); }
private void Start1(object data) { string[] par = data as string[]; int err = 0; Pfm.Api pfm = null; Pfm.Mount mount = null; Pfm.MountCreateParams mcp = new Pfm.MountCreateParams(); Pfm.MarshallerServeParams msp = new Pfm.MarshallerServeParams(); BaiduDisk volume = new BaiduDisk(par[0], par[1]); LoginSuccess(par[0], par[1], volume.IsAviliable(), volume); if (!volume.IsAviliable()) { return; } IntPtr invalidFd = new IntPtr(-1); msp.dispatch = volume; msp.formatterName = "BaiduDisk"; //if (args.Length != 1) //{ // Console.Write( // "Sample file system application.\n" + // "syntax: hellofs <mount name>\n"); // err = -1; //} if (err == 0) { mcp.mountSourceName = par[0]; DriveInfo[] dinfos = DriveInfo.GetDrives(); string tem = "CDEFGHIJKLMNOPQRSTUVWXYZ"; char dltter = tem.ToCharArray().First(c => !dinfos.Any(i => i.Name.StartsWith(c.ToString()))); mcp.driveLetter = dltter; err = Pfm.ApiFactory(out pfm); if (err != 0) { Console.Write("ERROR: {0} Unable to open PFM API.\n", err); } } if (err == 0) { err = Pfm.MarshallerFactory(out volume.marshaller); if (err != 0) { Console.Write("ERROR: {0} Unable to create marshaller.\n", err); } } if (err == 0) { // Communication between the driver and file system is done // over a pair of simple pipes. Application is responsible // for creating the pipes. err = Pfm.SystemCreatePipe(out msp.toFormatterRead, out mcp.toFormatterWrite); if (err == 0) { err = Pfm.SystemCreatePipe(out mcp.fromFormatterRead, out msp.fromFormatterWrite); } } if (err == 0) { // Various mount options are available through mountFlags, // visibleProcessId, and ownerSid. err = pfm.MountCreate(mcp, out mount); if (err != 0) { Console.Write("ERROR: {0} Unable to create mount.\n", err); } } // Close driver end pipe handles now. Driver has duplicated what // it needs. If these handles are not closed then pipes will not // break if driver disconnects, leaving us stuck in the // marshaller. Pfm.SystemCloseFd(mcp.toFormatterWrite); Pfm.SystemCloseFd(mcp.fromFormatterRead); if (err == 0) { // If tracemon is installed and running then diagnostic // messsages can be viewed in the "hellofs" channel. volume.marshaller.SetTrace(mount.GetMountEndName()); // Also send diagnostic messages to stdout. This can slow // things down quite a bit. IntPtr stdoutFd = invalidFd; Pfm.SystemGetStdout(out stdoutFd); volume.marshaller.SetStatus(stdoutFd); // The marshaller uses alertable I/O, so process can be // exited via ctrl+c. Console.Write("Press CTRL+C to exit.\n"); // The marshaller serve function will return at unmount or // if driver disconnects. volume.marshaller.ServeDispatch(msp); } Pfm.SystemCloseFd(msp.toFormatterRead); Pfm.SystemCloseFd(msp.fromFormatterWrite); if (pfm != null) { pfm.Dispose(); } if (mount != null) { mount.Dispose(); } if (volume.marshaller != null) { volume.marshaller.Dispose(); } }