Ejemplo n.º 1
0
        public RPCResult <tysos.Interfaces.IFileSystem> CreateFSHandler(tysos.lib.File src)
        {
            // Get the modules associated with the handler
            tysos.lib.File.Property m_param =
                src.GetPropertyByName("mods");
            if (m_param == null)
            {
                throw new Exception("src does not contain 'mods' property");
            }

            List <tysos.lib.File.Property> mods = m_param.Value as
                                                  List <tysos.lib.File.Property>;

            if (mods == null)
            {
                throw new Exception("mods is of inappropriate type");
            }

            modfs fs = new modfs(mods);

            // Fork off a separate process to handle this instance of the driver
            tysos.Process p = tysos.Process.CreateProcess("modfs: " + src.Name,
                                                          new System.Threading.ThreadStart(fs.MessageLoop), new object[] { fs });
            p.Start();

            System.Diagnostics.Debugger.Log(0, "modfs", "Created FS handler\n");
            return(fs);
        }
Ejemplo n.º 2
0
        public RPCResult <bool> CloseFile(tysos.lib.File handle)
        {
            handle.Error = tysos.lib.MonoIOError.ERROR_INVALID_HANDLE;

            for (int i = 0; i < open_handles.Count; i++)
            {
                if ((open_handles[i].handle == handle) &&
                    ((open_handles[i].process == null && SourceThread == null) ||
                     (open_handles[i].process == SourceThread.owning_process)))
                {
                    open_handles.RemoveAt(i);
                    handle.Error = tysos.lib.MonoIOError.ERROR_SUCCESS;
                    break;
                }
            }

            if (handle.Error == tysos.lib.MonoIOError.ERROR_SUCCESS)
            {
                return(handle.Device.Close(handle).Sync());
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 3
0
        public RPCResult <bool> Mount(string mount_path, string src)
        {
            /* Open source file */
            tysos.lib.File f_src = OpenFile(src, System.IO.FileMode.Open,
                                            System.IO.FileAccess.Read, System.IO.FileShare.ReadWrite,
                                            System.IO.FileOptions.None).Sync();
            if (f_src == null || f_src.Error != tysos.lib.MonoIOError.ERROR_SUCCESS)
            {
                System.Diagnostics.Debugger.Log(0, null, "Mount: couldn't open source: " + src);
                return(false);
            }

            tysos.lib.File.Property driver = f_src.GetPropertyByName("driver");
            if (driver == null)
            {
                System.Diagnostics.Debugger.Log(0, null, "Mount: no driver specified in properties of " + src);
                return(false);
            }
            string protocol = driver.Value as string;

            if (protocol == null || protocol == "")
            {
                System.Diagnostics.Debugger.Log(0, null, "Mount: driver property of " + src + " is invalid");
                return(false);
            }

            return(Mount(mount_path, f_src, protocol));
        }
Ejemplo n.º 4
0
        public RPCResult <string[]> GetFileSystemEntries(string path, string path_with_pattern,
                                                         int attrs, int mask)
        {
            /* We are handed a string, path_with_pattern, which may include wildcards
             *
             * It should be an absolute path (handled by the tysos.lib.MonoIO layer - TODO)
             *
             * We then take each element in turn, expanding it to all possible matches
             * and move on
             */

            System.Diagnostics.Debugger.Log(0, null, "vfs: GetFileSystemEntries(" +
                                            path + ", " + path_with_pattern + ", " + attrs.ToString() + ", " +
                                            mask.ToString() + ")\n");

            List <string> ret = new List <string>();

            string[] split_path = path_with_pattern.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);

            /* Open the root directory and begin searching from there */
            tysos.lib.File root_dir_f = OpenFile("/", System.IO.FileMode.Open,
                                                 System.IO.FileAccess.Read, System.IO.FileShare.ReadWrite,
                                                 System.IO.FileOptions.None).Sync();
            getFSE(split_path, 0, ret, root_dir_f, new List <string>(), attrs, mask);
            CloseFile(root_dir_f);

            return(ret.ToArray());
        }
Ejemplo n.º 5
0
        public RPCResult <int> Read(tysos.lib.File f, long pos, byte[] dest, int dest_offset, int count)
        {
            int        bytes_read = 0;
            modfs_File mf         = f as modfs_File;

            if (pos < 0)
            {
                f.Error = tysos.lib.MonoIOError.ERROR_READ_FAULT;
                System.Diagnostics.Debugger.Log(0, "modfs", "Read Fault (pos = " + pos.ToString() + ")");
                return(-1);
            }

            System.Diagnostics.Debugger.Log(0, "modfs", "Reading from " + mf.name +
                                            ", pos: " + pos.ToString() +
                                            ", addr: " + (mf.mem.Addr64 + (ulong)pos).ToString("X") +
                                            ", length: " + ((long)mf.mem.Length64).ToString() +
                                            ", count: " + count.ToString());

            while (pos < (long)mf.mem.Length64 && bytes_read < count)
            {
                dest[dest_offset++] = (byte)mf.mem.Read(mf.mem.Addr64 + (ulong)pos, 1);
                pos++;
                bytes_read++;
            }

            System.Diagnostics.Debugger.Log(0, "modfs", "Read done");

            return(bytes_read);
        }
Ejemplo n.º 6
0
        public RPCResult <tysos.lib.File> OpenFile(string path, System.IO.FileMode mode, System.IO.FileAccess access,
                                                   System.IO.FileShare share, System.IO.FileOptions options)
        {
            Path p = GetPath(path);

            if (p == null || p.device == null)
            {
                return(new tysos.lib.ErrorFile(tysos.lib.MonoIOError.ERROR_FILE_NOT_FOUND));
            }

            tysos.lib.File ret = p.device.Open(p.path.path, mode, access, share, options).Sync();

            if (ret == null)
            {
                ret = new tysos.lib.ErrorFile(tysos.lib.MonoIOError.ERROR_GEN_FAILURE);
            }

            if (ret.Error == tysos.lib.MonoIOError.ERROR_SUCCESS)
            {
                open_handle h = new open_handle();
                h.handle = ret;

                if (SourceThread != null)
                {
                    h.process = SourceThread.owning_process;
                }
                open_handles.Add(h);
            }

            return(ret);
        }
Ejemplo n.º 7
0
        public RPCResult <bool> Mount(string mount_path, string src, string protocol)
        {
            /* Open source file */
            tysos.lib.File f_src = OpenFile(src, System.IO.FileMode.Open,
                                            System.IO.FileAccess.Read, System.IO.FileShare.ReadWrite,
                                            System.IO.FileOptions.None).Sync();
            if (f_src == null || f_src.Error != tysos.lib.MonoIOError.ERROR_SUCCESS)
            {
                System.Diagnostics.Debugger.Log(0, null, "Mount: couldn't open source: " + src);
                return(false);
            }

            return(Mount(mount_path, f_src, protocol));
        }
Ejemplo n.º 8
0
        public RPCResult <tysos.Interfaces.IFileSystem> CreateFSHandler(tysos.lib.File src)
        {
            // Get the properties of the source file
            tysos.lib.File.Property[] props = src.GetAllProperties();
            if (props == null)
            {
                props = new tysos.lib.File.Property[] { }
            }
            ;

            // Ensure the device is a pciide device
            tysos.lib.File.Property driver = src.GetPropertyByName("driver");
            if (driver == null || driver.Value == null || !(driver.Value is string) || ((string)driver.Value).Equals("pciide") == false)
            {
                System.Diagnostics.Debugger.Log(0, "pciide", "driver property is invalid");
                return(null);
            }

            // Get the subdriver
            string subdriver_str = "";

            tysos.lib.File.Property subdriver = src.GetPropertyByName("subdriver");
            if (subdriver != null && subdriver.Value != null && (subdriver.Value is string))
            {
                subdriver_str = subdriver.Value as string;
            }

            System.Diagnostics.Debugger.Log(0, "pciide", "subdriver " + subdriver_str + " not found");

            pciide.DriverType dt = pciide.DriverType.Unknown;
            if (subdriver_str == "legacy")
            {
                dt = pciide.DriverType.Legacy;
            }
            else if (subdriver_str == "pcinative")
            {
                dt = pciide.DriverType.PCINative;
            }

            pciide fs = new pciide(props, dt);

            tysos.Process p = tysos.Process.CreateProcess("pciide: " + src.Name,
                                                          new System.Threading.ThreadStart(fs.MessageLoop), new object[] { fs });
            p.Start();

            return(fs);
        }
    }
Ejemplo n.º 9
0
        public RPCResult <System.IO.FileAttributes> GetFileAttributes(string path)
        {
            tysos.lib.File f = OpenFile(path, System.IO.FileMode.Open,
                                        System.IO.FileAccess.Read, System.IO.FileShare.ReadWrite,
                                        System.IO.FileOptions.None).Sync();
            if (f.Error != tysos.lib.MonoIOError.ERROR_SUCCESS)
            {
                return((System.IO.FileAttributes)(-1));
            }

            int props = f.IntProperties;

            CloseFile(f);

            return((System.IO.FileAttributes)props);
        }
Ejemplo n.º 10
0
        public RPCResult <tysos.Interfaces.IFileSystem> CreateFSHandler(tysos.lib.File src)
        {
            // Get the properties of the source file
            tysos.lib.File.Property[] props = src.GetAllProperties();
            if (props == null)
            {
                props = new tysos.lib.File.Property[] { }
            }
            ;

            // Ensure the device is a PCI device
            tysos.lib.File.Property driver = src.GetPropertyByName("driver");
            if (driver == null || driver.Value == null || !(driver.Value is string) || ((string)driver.Value).Equals("pci") == false)
            {
                System.Diagnostics.Debugger.Log(0, "pci", "driver property is invalid");
                return(null);
            }

            // Get the subdriver
            string subdriver_str = "";

            tysos.lib.File.Property subdriver = src.GetPropertyByName("subdriver");
            if (subdriver != null && subdriver.Value != null && (subdriver.Value is string))
            {
                subdriver_str = subdriver.Value as string;
            }

            if (subdriver_str == "hostbridge")
            {
                // Create and execute a handler in a separate address space
                hostbridge    fs = new hostbridge(props);
                tysos.Process p  = tysos.Process.CreateProcess("pci: " + src.Name,
                                                               new System.Threading.ThreadStart(fs.MessageLoop), new object[] { fs });
                p.Start();

                System.Diagnostics.Debugger.Log(0, "pci", "Created FS handler\n");
                return(fs);
            }

            System.Diagnostics.Debugger.Log(0, "pci", "subdriver " + subdriver_str + " not found");
            return(null);
        }
    }
Ejemplo n.º 11
0
        private ServerObject GetServer(string path)
        {
            // Open the file and get its 'server' property
            System.Diagnostics.Debugger.Log(0, null, "GetServer(" + path +
                                            ") called");

            var ret = vfs.OpenFile(path, System.IO.FileMode.Open,
                                   System.IO.FileAccess.Read, System.IO.FileShare.ReadWrite,
                                   System.IO.FileOptions.None);

            Syscalls.SchedulerFunctions.Block(ret);
            tysos.lib.File f = ret.Result;

            if (f == null || f.Error != tysos.lib.MonoIOError.ERROR_SUCCESS)
            {
                System.Diagnostics.Debugger.Log(0, null, "GetServer(" + path +
                                                ") failed - could not open file");
                return(null);
            }

            var p = f.GetPropertyByName("server");

            vfs.CloseFile(f);
            if (p == null)
            {
                System.Diagnostics.Debugger.Log(0, null, "GetServer(" + path +
                                                ") failed - no 'server' property found");
                return(null);
            }

            var s = p.Value as tysos.ServerObject;

            if (s == null)
            {
                System.Diagnostics.Debugger.Log(0, null, "GetServer(" + path +
                                                ") failed - 'server' property is not of type ServerObject");
                return(null);
            }

            System.Diagnostics.Debugger.Log(0, null, "GetServer(" + path +
                                            ") succeeded");
            return(s);
        }
Ejemplo n.º 12
0
        private INetworkDevice GetServer(string path)
        {
            // Open the file and get its 'server' property
            System.Diagnostics.Debugger.Log(0, null, "GetServer(" + path +
                                            ") called");

            tysos.lib.File f = vfs.OpenFile("path", System.IO.FileMode.Open,
                                            System.IO.FileAccess.Read, System.IO.FileShare.ReadWrite,
                                            System.IO.FileOptions.None).Sync();

            if (f == null || f.Error != tysos.lib.MonoIOError.ERROR_SUCCESS)
            {
                System.Diagnostics.Debugger.Log(0, null, "GetServer(" + path +
                                                ") failed - could not open file");
                return(null);
            }

            var p = f.GetPropertyByName("server");

            vfs.CloseFile(f);

            if (p == null)
            {
                System.Diagnostics.Debugger.Log(0, null, "GetServer(" + path +
                                                ") failed - no 'server' property found");
                return(null);
            }

            var s = p.Value as INetworkDevice;

            if (s == null)
            {
                System.Diagnostics.Debugger.Log(0, null, "GetServer(" + path +
                                                ") failed - 'server' property is not of type INetworkDevice");
                return(null);
            }

            System.Diagnostics.Debugger.Log(0, null, "GetServer(" + path +
                                            ") succeeded");
            return(s);
        }
Ejemplo n.º 13
0
        public RPCResult <tysos.Interfaces.IFileSystem> CreateFSHandler(tysos.lib.File src)
        {
            // Get the properties of the source file
            tysos.lib.File.Property[] props = src.GetAllProperties();
            if (props == null)
            {
                props = new tysos.lib.File.Property[] { }
            }
            ;

            // Create and execute a handler in a separate address space
            acpipc fs = new acpipc(props);

            tysos.Process p = tysos.Process.CreateProcess("acpipc: " + src.Name,
                                                          new System.Threading.ThreadStart(fs.MessageLoop), new object[] { fs });
            p.Start();

            System.Diagnostics.Debugger.Log(0, "acpipc", "Created FS handler\n");
            return(fs);
        }
    }
Ejemplo n.º 14
0
        public RPCResult <bool> Mount(string mount_path, tysos.lib.File f_src, string protocol)
        {
            if (mount_path == null)
            {
                System.Diagnostics.Debugger.Log(0, null, "Mount: mount_path is null");
                CloseFile(f_src);
                return(false);
            }

            System.Diagnostics.Debugger.Log(0, null, "Mount: beginning to mount " + mount_path);

            Path path = GetPath(mount_path);

            System.Diagnostics.Debugger.Log(0, null, "Mount: device: " +
                                            protocol + ", mount_point: " + path.FullPath);

            if (mounts.ContainsKey((PathPart)path))
            {
                System.Diagnostics.Debugger.Log(0, null, "Mount: mount point " + path.FullPath + " is already mounted");
                CloseFile(f_src);
                return(false);
            }

            /* See if the requested file system process is already running */
            tysos.Process p = tysos.Syscalls.ProcessFunctions.GetProcessByName(protocol);
            if (p == null)
            {
                System.Diagnostics.Debugger.Log(0, null, "Mount: driver " + protocol + " not running.  Starting it...");
                tysos.lib.File f = OpenFile("/modules/" + protocol, System.IO.FileMode.Open,
                                            System.IO.FileAccess.Read, System.IO.FileShare.Read,
                                            System.IO.FileOptions.None).Sync();
                if (f.Error != tysos.lib.MonoIOError.ERROR_SUCCESS)
                {
                    throw new Exception("failed to open /modules/" + protocol + ": " +
                                        f.Error.ToString());
                }

                p = tysos.Process.CreateProcess(f, protocol, new object[] { });
                p.Start();
            }
            else
            {
                System.Diagnostics.Debugger.Log(0, null, "Mount: driver " + protocol + " already running");
            }

            // TODO: create a special event class that waits for p.MessageServer to be non-null
            //  or for a timeout then handle failure
            while (p.MessageServer == null)
            {
                ;
            }

            // Invoke the process to create a new handler for the new mount
            var fs = ((tysos.Interfaces.IFactory)p.MessageServer).CreateFSHandler(f_src).Sync();

            if (fs == null)
            {
                throw new Exception("CreateFSHandler failed");
            }

            System.Diagnostics.Debugger.Log(0, null, "Mount: mounting " + fs.GetType().FullName + " to " + path.FullPath);

            fs.SetMountPath(path.FullPath);
            mounts[(PathPart)path] = fs;

            //foreach (var tag in fs.Tags)
            //    RegisterTag(tag, fs.MountPath);

            return(true);
        }
Ejemplo n.º 15
0
 public RPCResult <int> Write(tysos.lib.File f, long pos, byte[] dest, int dest_offset, int count)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 16
0
 public RPCResult <string> GetName(tysos.lib.File f)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 17
0
 public RPCResult <tysos.lib.File.Property> GetPropertyByName(tysos.lib.File f, string name)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 18
0
 static MonoFileType GetFileType(tysos.lib.File handle, out MonoIOError err)
 {
     err = MonoIOError.ERROR_SUCCESS;
     return(handle.FileType);
 }
Ejemplo n.º 19
0
        private void getFSE(string[] split_path, int cur_depth, List <string> ret,
                            tysos.lib.File cur_dir_f, List <string> cur_path, int attrs, int mask)
        {
            // Get the children of the current node
            if (cur_dir_f == null || cur_dir_f.Error != tysos.lib.MonoIOError.ERROR_SUCCESS)
            {
                System.Diagnostics.Debugger.Log(0, null, "getFSE: cur_dir_f is null");
                return;
            }
            tysos.lib.File.Property children = cur_dir_f.GetPropertyByName("Children");
            if (children == null)
            {
                System.Diagnostics.Debugger.Log(0, null, "getFSE: GetPropertyByName(\"Children\") returned null");
                return;
            }

            // Iterate through each, seeing if they match the current part of the name
            IList <string> children_list = children.Value as IList <string>;

            if (children_list == null)
            {
                System.Diagnostics.Debugger.Log(0, null, "getFSE: children.Value is not of type " +
                                                "IList<string> (instead is " + children.Value.GetType().FullName + ")");
                ulong v0 = libsupcs.CastOperations.ReinterpretAsUlong(children.Value);
                ulong v1 = libsupcs.CastOperations.ReinterpretAsUlong(children.Value.GetType());
                ulong v2 = libsupcs.CastOperations.ReinterpretAsUlong(typeof(IList <string>));
                System.Diagnostics.Debugger.Log(0, null, "getFSE: " + v1.ToString("X16") + " (" + v0.ToString("X16") + ") vs " + v2.ToString("X16"));
                return;
            }
            foreach (string child in children_list)
            {
                //tysos.Syscalls.DebugFunctions.DebugWrite("getFSE: examining child: " + child + "\n");

                if (match(child, split_path[cur_depth], true))
                {
                    //tysos.Syscalls.DebugFunctions.DebugWrite("match successful\n");

                    /* Build the absolute path to the child */
                    StringBuilder cur_child_path = new StringBuilder();
                    foreach (string parent in cur_path)
                    {
                        cur_child_path.Append("/");
                        cur_child_path.Append(parent);
                    }
                    cur_child_path.Append("/");
                    cur_child_path.Append(child);

                    /* Open the file to get its properties */
                    tysos.lib.File child_dir = OpenFile(cur_child_path.ToString(),
                                                        System.IO.FileMode.Open, System.IO.FileAccess.Read,
                                                        System.IO.FileShare.ReadWrite,
                                                        System.IO.FileOptions.None).Sync();
                    if (child_dir == null || child_dir.Error != tysos.lib.MonoIOError.ERROR_SUCCESS)
                    {
                        System.Diagnostics.Debugger.Log(0, null, "getFSE: OpenFile(" + cur_child_path.ToString() + ") failed");
                        return;
                    }
                    int int_attrs = child_dir.IntProperties;

                    /* If this is the deepest depth to check, then all matching
                     * children are valid and should be added to ret */
                    if (cur_depth == split_path.Length - 1)
                    {
                        //tysos.Syscalls.DebugFunctions.DebugWrite("adding: " + cur_child_path.ToString() + "\n");

                        if ((int_attrs & mask) == attrs)
                        {
                            ret.Add(cur_child_path.ToString());
                        }
                    }
                    else
                    {
                        /* We are not yet at the deepest search path yet -
                         * recurse into the next directory if it is one */
                        System.IO.FileAttributes child_attrs = (System.IO.FileAttributes)int_attrs;
                        if ((child_attrs & System.IO.FileAttributes.Directory) != 0)
                        {
                            /* This is a directory - recurse into it */
                            cur_path.Add(child);
                            getFSE(split_path, cur_depth + 1, ret, child_dir, cur_path, attrs, mask);
                            cur_path.RemoveAt(cur_path.Count - 1);
                        }

                        CloseFile(child_dir);
                    }
                }
                else
                {
                    // tysos.Syscalls.DebugFunctions.DebugWrite("match unsuccessful\n");
                }
            }
        }
Ejemplo n.º 20
0
 public RPCResult <tysos.lib.File.Property[]> GetAllProperties(tysos.lib.File f)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 21
0
 public RPCResult <int> Write(tysos.lib.File f, long pos, byte[] dest, int dest_offset, int count)
 {
     f.Error = MonoIOError.ERROR_WRITE_FAULT;
     return(0);
 }
Ejemplo n.º 22
0
 public RPCResult <bool> Close(tysos.lib.File handle)
 {
     return(true);
 }
Ejemplo n.º 23
0
 public RPCResult <int> IntProperties(tysos.lib.File f)
 {
     return(((modfs_File)f).intProperties);
 }
Ejemplo n.º 24
0
 public RPCResult <long> GetLength(tysos.lib.File f)
 {
     return((long)((modfs_File)f).mem.Length64);
 }