Beispiel #1
0
        /// <summary>
        /// Starts a new process based on the given path and arguments
        /// </summary>
        /// <param name="path">The path</param>
        /// <param name="argv">The arguments</param>
        /// <param name="flags">Spawn flags</param>
        /// <returns>Errorcode or PID</returns>
        public static int StartProcess(string path, string[] argv, Task.SpawnFlags flags)
        {
            if (argv == null)
            {
                Panic.DoPanic("argv == null");
            }

            Node node = VFS.GetByAbsolutePath(path);

            if (node == null)
            {
                return(-(int)ErrorCode.ENOENT);
            }

            // Open and create buffer
            VFS.Open(node, (int)FileMode.O_RDONLY);
            byte[] buffer = new byte[node.Size];
            if (buffer == null)
            {
                Heap.Free(node);
                VFS.Close(node);
                return(-(int)ErrorCode.ENOMEM);
            }

            // Fill buffer contents
            VFS.Read(node, 0, node.Size, buffer);
            VFS.Close(node);

            // Pass execution to ELF loader
            int status = ELFLoader.Execute(buffer, node.Size, argv, flags);

            Heap.Free(buffer);
            Heap.Free(node);
            return(status);
        }
Beispiel #2
0
        /// <summary>
        /// Changes the current directory to newDir
        /// </summary>
        /// <param name="newDir">The new working directory</param>
        /// <returns>Errorcode</returns>
        public static ErrorCode ChDir(string newDir)
        {
            newDir = VFS.CreateAbsolutePath(newDir);
            Node node = VFS.GetByAbsolutePath(newDir);

            if (node == null)
            {
                Heap.Free(newDir);
                return(ErrorCode.ENOENT);
            }

            if (node.Flags != NodeFlags.DIRECTORY)
            {
                Heap.Free(newDir);
                Heap.Free(node);
                return(ErrorCode.ENOTDIR);
            }

            Heap.Free(node);

            // GetByAbsolutePath makes sure there's a slash on the end
            Tasking.CurrentTask.CurrentDirectory = newDir;

            return(ErrorCode.SUCCESS);
        }
Beispiel #3
0
        /// <summary>
        /// Mount a device
        /// </summary>
        /// <param name="devicePath">Path to device</param>
        /// <param name="mountname">Name of mount , eg "D"</param>
        /// <param name="fsType">Filesystem type, eg "Fat16b"</param>
        /// <returns>Success?</returns>
        public static unsafe int Mount(string devicePath, string mountname, string fsType)
        {
            if (mountname.IndexOf(":") > 0)
            {
                return(-(int)ErrorCode.ENOTDIR);
            }

            Node node = VFS.GetByAbsolutePath(devicePath);

            if (node == null)
            {
                return(-(int)ErrorCode.ENOENT);
            }

            // TODO: maybe check if block device?

            Console.WriteLine(devicePath);
            Console.WriteLine(mountname);
            Console.WriteLine(fsType);
            DiskMountResult res = Disk.Mount(node, mountname, fsType);

            if (res == DiskMountResult.FS_TYPE_NOT_FOUND)
            {
                return(-(int)ErrorCode.ENODEV);
            }

            if (res == DiskMountResult.MOUNT_POINT_ALREADY_USED)
            {
                return(-(int)ErrorCode.EBUSY);
            }

            if (res == DiskMountResult.INIT_FAIL)
            {
                return(-(int)ErrorCode.ENODEV);
            }

            return(0);
        }
Beispiel #4
0
        private static void mountBootPartition()
        {
            string bootDevice = BootParams.GetParam("--bootdev");
            string bootFS     = BootParams.GetParam("--boottype");

            if (bootDevice == null)
            {
                Panic.DoPanic("No bootdevice specified.");
            }

            if (bootFS == null)
            {
                Panic.DoPanic("No boot filesystem specified.");
            }

            Console.Write("[Init] Mounting bootdevice ");
            Console.Write(bootDevice);
            Console.Write(":");
            Console.Write(bootFS);
            Console.WriteLine("");

            Node hddNode = VFS.GetByAbsolutePath(bootDevice, 0);

            if (hddNode == null)
            {
                Panic.DoPanic("Bootdevice not found.");
            }

            DiskMountResult res = Disk.Mount(hddNode, "C", bootFS);

            if (res != DiskMountResult.SUCCESS)
            {
                Panic.DoPanic("Failed to mount bootdevice.");
            }


            Tasking.CurrentTask.CurrentDirectory = "C://";
        }