Пример #1
0
        public static unsafe void Cmd_OpenFile(SystemMessage *msg)
        {
            //var addr = msg->Arg1;
            //var str = (NullTerminatedString*)addr;
            //var path = str->ToString();

            //var path = ((NullTerminatedString*)msg->Arg1)->ToString();
            var path = NullTerminatedString.ToString((byte *)msg->Arg1);

            if (TraceFileIO)
            {
                Console.Write("Open File: ");
                Console.WriteLine(path);
            }

            var file = FindFile(path);

            if (file == null)
            {
                Console.Write("File not found: ");
                //Console.WriteLine(length.ToString("X"));
                Console.WriteLine(path.Length.ToString("X"));
                Console.WriteLine(path);
                Console.WriteLine(">>");
                MessageManager.Send(new SystemMessage(SysCallTarget.ServiceReturn, FileHandle.Zero));
                return;
            }

            var openFile = new OpenFile()
            {
                Handle    = ++lastHandle,
                Path      = path,
                ProcessId = -1,
                Buffer    = file.Buffer,
            };

            OpenFiles.Add(openFile);

            if (TraceFileIO)
            {
                Console.WriteLine("Created Handle: " + ((uint)openFile.Handle).ToString("X"));
            }

            MessageManager.Send(new SystemMessage(SysCallTarget.ServiceReturn, openFile.Handle));
        }
Пример #2
0
        private static OpenFile EnsurePredefinedHandleIsOpen(int processID, FileHandle handle, string path)
        {
            for (var i = 0; i < OpenFiles.Count; i++)
            {
                if (OpenFiles[i].ProcessId == processID && OpenFiles[i].Handle == handle)
                {
                    return(OpenFiles[i]);
                }
            }

            var file     = FindFile(path);
            var openFile = new OpenFile()
            {
                Handle    = handle,
                Path      = path,
                ProcessId = processID,
                Buffer    = file.Buffer,
            };

            OpenFiles.Add(openFile);
            return(openFile);
        }