Exemplo n.º 1
0
        /// <summary>
        /// Gets the file status of a descriptor
        /// </summary>
        /// <param name="descriptor">The descriptor ID</param>
        /// <param name="st">The stat structure</param>
        /// <returns>The errorcode</returns>
        public static unsafe ErrorCode FStat(int descriptor, Stat *st)
        {
            FileDescriptors descriptors = Tasking.CurrentTask.FileDescriptors;

            Node node = descriptors.GetNode(descriptor);

            if (node == null)
            {
                return(ErrorCode.EBADF);
            }

            node.Stat(st);
            return(ErrorCode.SUCCESS);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Sets the file position of the descriptor to the given offset
        /// </summary>
        /// <param name="descriptor">The descriptor</param>
        /// <param name="offset">The offset</param>
        /// <param name="whence">The direction</param>
        /// <returns>The new offset from the beginning of the file in bytes</returns>
        public static int Seek(int descriptor, int offset, FileWhence whence)
        {
            FileDescriptors descriptors = Tasking.CurrentTask.FileDescriptors;

            Node node = descriptors.GetNode(descriptor);

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

            uint currentOffset = descriptors.GetOffset(descriptor);

            if (whence == FileWhence.SEEK_CUR)
            {
                currentOffset = (uint)(currentOffset + offset);
            }
            else if (whence == FileWhence.SEEK_SET)
            {
                if (offset < 0)
                {
                    currentOffset = 0;
                }
                else
                {
                    currentOffset = (uint)offset;
                }
            }
            else if (whence == FileWhence.SEEK_END)
            {
                if (offset > 0)
                {
                    currentOffset = node.Size;
                }
                else
                {
                    currentOffset = (uint)(node.Size + offset);
                }
            }
            else
            {
                return(-(int)ErrorCode.EINVAL);
            }

            descriptors.SetOffset(descriptor, currentOffset);

            return((int)currentOffset);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Write to a file descriptor
        /// </summary>
        /// <param name="descriptor">The descriptor ID</param>
        /// <param name="buffer">The buffer</param>
        /// <param name="size">The size</param>
        /// <returns>The amount of bytes written</returns>
        public static int Write(int descriptor, byte[] buffer, uint size)
        {
            FileDescriptors descriptors = Tasking.CurrentTask.FileDescriptors;

            Node node = descriptors.GetNode(descriptor);

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

            uint offset = descriptors.GetOffset(descriptor);

            descriptors.SetOffset(descriptor, offset + size);

            return((int)VFS.Write(node, offset, size, buffer));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Read from a file descriptor
        /// </summary>
        /// <param name="descriptor">The descriptor ID</param>
        /// <param name="buffer">The buffer</param>
        /// <param name="size">The size</param>
        /// <returns>The amount of bytes read</returns>
        public static int Read(int descriptor, byte[] buffer, uint size)
        {
            FileDescriptors descriptors = Tasking.CurrentTask.FileDescriptors;


            Node node = descriptors.GetNode(descriptor);

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

            // Can't do read from a directory
            if ((node.Flags & NodeFlags.DIRECTORY) == NodeFlags.DIRECTORY)
            {
                return(-(int)ErrorCode.EISDIR);
            }

            bool isNonBlocking = ((node.OpenFlags & O_NONBLOCK) == O_NONBLOCK);

            // Wait until data is available if its blocking
            if (!isNonBlocking)
            {
                while (VFS.GetSize(node) == 0)
                {
                    Tasking.Yield();
                }
            }
            // Non-blocking but no data available?
            else
            {
                if (VFS.GetSize(node) == 0)
                {
                    return(-(int)ErrorCode.EAGAIN);
                }
            }

            uint offset    = descriptors.GetOffset(descriptor);
            uint readBytes = VFS.Read(node, offset, size, buffer);

            descriptors.SetOffset(descriptor, offset + readBytes);

            return((int)readBytes);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Creates a UNIX pipe
        /// </summary>
        /// <param name="pipefd">The pipe file descriptors (output)</param>
        /// <returns>The errorcode</returns>
        public static unsafe ErrorCode Pipe(int *pipefd)
        {
            Node[]    nodes = new Node[2];
            ErrorCode error = PipeFS.Create(nodes, PipeFS.DefaultPipeSize);

            if (error != ErrorCode.SUCCESS)
            {
                Heap.Free(nodes);
                return(error);
            }

            FileDescriptors descriptors = Tasking.CurrentTask.FileDescriptors;

            pipefd[0] = descriptors.AddNode(nodes[0]);
            pipefd[1] = descriptors.AddNode(nodes[1]);

            Heap.Free(nodes);

            return(ErrorCode.SUCCESS);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Reads a directory entry
        /// </summary>
        /// <param name="descriptor">The descriptor</param>
        /// <param name="entry">The directory entry</param>
        /// <param name="index">The index</param>
        /// <returns>Errorcode</returns>
        public static unsafe ErrorCode Readdir(int descriptor, DirEntry *entry, uint index)
        {
            FileDescriptors descriptors = Tasking.CurrentTask.FileDescriptors;

            Node node = descriptors.GetNode(descriptor);

            if (node == null)
            {
                return(ErrorCode.EBADF);
            }

            DirEntry *gotEntry = VFS.ReadDir(node, index);

            if (gotEntry == null)
            {
                return(ErrorCode.ENOENT);
            }

            Memory.Memcpy(entry, gotEntry, sizeof(DirEntry));
            Heap.Free(gotEntry);

            return(ErrorCode.SUCCESS);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Replaces an old file descriptor with a new one
        /// </summary>
        /// <param name="oldfd">The old file descriptor</param>
        /// <param name="newfd">The new file descriptor</param>
        /// <returns>The new file descriptor or errorcode</returns>
        public static int Dup2(int oldfd, int newfd)
        {
            FileDescriptors descriptors = Tasking.CurrentTask.FileDescriptors;

            return(descriptors.Dup2(oldfd, newfd));
        }
Exemplo n.º 8
0
        /// <summary>
        /// Duplicates a file descriptor to the lowest unused file descriptor
        /// </summary>
        /// <param name="fd">The file descriptor to clone</param>
        /// <returns>The cloned file descriptor</returns>
        public static int Dup(int fd)
        {
            FileDescriptors descriptors = Tasking.CurrentTask.FileDescriptors;

            return(descriptors.Dup(fd));
        }
Exemplo n.º 9
0
        /// <summary>
        /// Closes a file
        /// </summary>
        /// <param name="descriptor">The descriptor ID</param>
        /// <returns>The errorcode</returns>
        public static int Close(int descriptor)
        {
            FileDescriptors descriptors = Tasking.CurrentTask.FileDescriptors;

            return(descriptors.Close(descriptor));
        }
Exemplo n.º 10
0
        public MainForm()
        {
            //DisplaySettingsManager.Initialize();

            InitializeComponent();

            UpdateList();
            InitDialogCombo();

            // Mac layout debugging
            //this.DebugAllControls();

            this.filterTextBox.KeyDown += FilterTextBox_KeyDown;

            AddButton("WebForm", () => { new WebForm().Show(); });
            AddButton("ImageForm", () => { new ImageForm().Show(); });
            AddButton("TextBoxes", () => { new TextBoxForm().Show(); });
            //AddButton("ImapOptions", () => { new ImapOptionsForm().Show(); });
            //AddButton("MailOptions", () => { new MailOptionsForm().Show(); });

            /*AddButton("FormInputBox", () => { new FormInputBox(
             *      "Nazdar",
             *      "Přihlášení k webovému kalendáři",
             *  "Zadej url kalendáře, ke kterému se chceš přihlásit, třeba http://calndar.org-mycalndar.ics"
             * ).Show(); });*/
            AddButton("Layout 1", () => { new DebugLayoutForm().Show(); });
            AddButton("Layout 2", () => { new DebugLayoutForm2().Show(); });
            AddButton("Layout 3", () => { new DebugLayoutForm3().Show(); });
            AddButton("Layout 4", () => { new DebugLayoutForm4().Show(); });

            /*AddButton("Editor", () =>
             * {
             *      var f = new Form() { Size = new Size(500, 300), Text = "Editor" };
             *
             *      f.Controls.Add(new HtmlEditorControl.HtmlEditorBrowser { Dock = DockStyle.Fill });
             *      f.Controls.Add(new MailClient.Common.UI.Controls.ControlTextBox.ControlTextBox { Dock = DockStyle.Top });
             *      var toolStrip = new MailClient.Common.UI.Controls.ControlToolStrip.ControlToolStrip { Dock = DockStyle.Top, AutoSize = true, Height = 40 };
             *      f.Controls.Add(toolStrip);
             *      toolStrip.Items.Add(new MailClient.Common.UI.Controls.ToolStripControls.ControlToolStripButtonFontSelector());
             *      f.Show();
             * });*/
            /*AddButton("FormLinkMessageBox", () =>
             * {
             *      new FormLinkMessageBox("Hello", "Zkušební doba vypršela. Platnou licenci pro eM Client můžete získat na http://cz.emclient.com/prehled-cenovych-moznosti\r\nNyní budete mít ke svým datům přístup pouze v režimu off-line. Synchronizace a odesílání jakýchkoliv zpráv bude nyní zablokována. Jakmile bude zadána validní licence, všechny funkce aplikace budou okamžitě obnoveny.").Show();
             * });*/
            /*AddButton("Recurrence", () =>
             * {
             *      var f = new Form() { Size = new Size(500, 300), Text = "Recurrence" };
             *      f.Controls.Add(new MailClient.UI.Controls.ControlRecurrence());
             *      f.Show();
             * });
             * AddButton("Confirmations", () =>
             * {
             *      var f = new Form() { Size = new Size(400, 500), Text = "Confirmations" };
             *      f.Controls.Add(new MailClient.UI.Controls.SettingsControls.ControlSettingsConfirmations() { Dock = DockStyle.Top, AutoSize = true });
             *      f.DebugAllControls();
             *      f.Show();
             * });
             * AddButton("Spell checker", () =>
             * {
             *      var f = new Form() { Size = new Size(400, 500), Text = "Spell checker" };
             *      f.Controls.Add(new MailClient.UI.Controls.SettingsControls.ControlSettingsSpellChecker() { Dock = DockStyle.Top, AutoSize = true });
             *      f.Show();
             * });
             * AddButton("Autodiscover", () =>
             * {
             *      var f = new Form() { Size = new Size(400, 500), Text = "Autodiscover" };
             *      f.Controls.Add(new MailClient.UI.Controls.WizardControls.ControlExpandablePanelAutodiscover() { Dock = DockStyle.Top, AutoSize = true, Expanded = true });
             *      f.Show();
             * });*/

            AddButton("Animations", () => { new AnimationsForm().Show(); });
            AddButton("Print dialog", () => { ShowPrintDialog(); });
            AddButton("Toolstrip form", () => { new ToolstripForm().Show(); });
#if MAC
            AddButton("Bg activity", () => { ToggleBgActivity(); });
            AddButton("Swizzle (cls)", () => { SwizzleCls(); });
            AddButton("NSException", () => { NativeException(); });
            AddButton("QuickLook panel", () => { ToggleQuickLookPanel(); });
            AddButton("NC Preferences", () => { ReadNotificationCenterPreferences(); });
            AddButton("Back color", () => { ChangeBackColor(); });
#endif

            //AddButton("Data Grid", () => { new DataGridForm().Show(); });
            AddButton("Font Dialog", () => { FontDialogTest(); });
            AddButton("Date Time", () => { new DateTimeForm().Show(); });
            AddButton("Texture Brush", () => { new TextureBrushForm().Show(); });
            AddButton("File Descriptors", () => { (fd = new FileDescriptors()).RunTest(); });
            AddButton("Catch When", () => { CatchWhen.RunTest(); });
            AddButton("Print Preview", () => { PrintPreview(); });
        }