Beispiel #1
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();
        }
    }
        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();
            }
        }