Пример #1
0
        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);
        }
Пример #2
0
    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();
        }
    }
Пример #3
0
        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();
            }
        }