Exemple #1
0
        /// <summary>
        /// Opens a file
        /// </summary>
        /// <param name="path">The path</param>
        /// <param name="flags">The flags</param>
        /// <returns>The file descriptor ID</returns>
        public static int Open(string path, int flags)
        {
            if (path.Length == 0)
            {
                return(-(int)ErrorCode.EINVAL);
            }

            Node node = null;

            // Check if O_CREATE
            if ((flags & 0x0200) > 0)
            {
                node = VFS.GetOffsetNodeByPath(path, 1);

                node = VFS.Create(node, "test");
                if (node == null)
                {
                    return(-(int)ErrorCode.ENOENT);
                }
            }
            else
            {
                node = VFS.GetByPath(path);
                if (node == null)
                {
                    return(-(int)ErrorCode.ENOENT);
                }

                VFS.Open(node, flags);
            }

            FileDescriptors descriptors = Tasking.CurrentTask.FileDescriptors;

            return(descriptors.AddNode(node));
        }
Exemple #2
0
        private void ProcessUpload(string path, HttpCall call)
        {
            if (readOnly)
            {
                call.Write("KO");
                return;
            }
            string soffset = call.Request.Headers["X-Sunfish-Offset"];
            string slength = call.Request.Headers["X-Sunfish-Length"];

            if (string.IsNullOrEmpty(soffset))
            {
                call.Parameters.TryGetValue("offset", out soffset);
            }
            if (string.IsNullOrEmpty(slength))
            {
                call.Parameters.TryGetValue("length", out slength);
            }
            int pos, len;

            int.TryParse(soffset, out pos);
            int.TryParse(slength, out len);
            try
            {
                VFSItem fil = vfs.GetItem(path);
                if (fil == null)
                {
                    fil = vfs.Create(path);
                }
                if (fil.Directory && len > 0)
                {
                    call.Write("KO: Exists as directory");
                    return;
                }
                if (len > 0)
                {
                    using (Stream s = fil.OpenWrite())
                    {
                        s.Position = pos;
                        using (Stream sin = call.Request.InputStream)
                        {
                            s.TransferFrom(sin, len);
                        }
                    }
                }
                call.Write("OK");
            }
            catch (Exception e)
            {
                call.Write("KO: " + e.GetType().Name + ":" + e.Message);
            }
        }