/// <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)); }
/// <summary> /// Truncates a file by path /// </summary> /// <param name="path">The path of the file to truncate</param> /// <param name="length">The length to truncate to</param> /// <returns>Errorcode</returns> public static int Truncate(string path, uint length) { Node node = VFS.GetByPath(path); if (node == null) { return(-(int)ErrorCode.ENOENT); } VFS.Truncate(node, length); Heap.Free(node); return(0); }
/// <summary> /// Gets the file status of a path /// </summary> /// <param name="path">The path</param> /// <param name="st">The stat structure</param> /// <returns>The errorcode</returns> public static unsafe ErrorCode Stat(string path, Stat *st) { Node node = VFS.GetByPath(path); if (node == null) { return(ErrorCode.ENOENT); } node.Stat(st); Heap.Free(node); return(ErrorCode.SUCCESS); }