Example #1
0
        // CreateFile(u32 createOption, u64 size, buffer<bytes<0x301>, 0x19, 0x301> path)
        public ResultCode CreateFile(ServiceCtx context)
        {
            U8Span name = ReadUtf8Span(context);

            CreateFileOptions createOption = (CreateFileOptions)context.RequestData.ReadInt32();

            context.RequestData.BaseStream.Position += 4;

            long size = context.RequestData.ReadInt64();

            return((ResultCode)_fileSystem.CreateFile(name, size, createOption).Value);
        }
Example #2
0
            /// <summary>
            /// Creates and writes the initial commit context to a file.
            /// </summary>
            /// <param name="commitCount">The counter.</param>
            /// <param name="fileSystemCount">The number of file systems being committed.</param>
            /// <returns>The <see cref="Result"/> of the operation.</returns>
            public Result Create(long commitCount, int fileSystemCount)
            {
                IFile contextFile = null;

                try
                {
                    // Open context file and create if it doesn't exist
                    Result rc = _fileSystem.OpenFile(out contextFile, CommitContextFileName, OpenMode.Read);

                    if (rc.IsFailure())
                    {
                        if (!ResultFs.PathNotFound.Includes(rc))
                        {
                            return(rc);
                        }

                        rc = _fileSystem.CreateFile(CommitContextFileName, CommitContextFileSize, CreateFileOptions.None);
                        if (rc.IsFailure())
                        {
                            return(rc);
                        }

                        rc = _fileSystem.OpenFile(out contextFile, CommitContextFileName, OpenMode.Read);
                        if (rc.IsFailure())
                        {
                            return(rc);
                        }
                    }
                }
                finally
                {
                    contextFile?.Dispose();
                }

                try
                {
                    Result rc = _fileSystem.OpenFile(out contextFile, CommitContextFileName, OpenMode.ReadWrite);
                    if (rc.IsFailure())
                    {
                        return(rc);
                    }

                    _context.Version         = CurrentCommitContextVersion;
                    _context.State           = CommitState.NotCommitted;
                    _context.FileSystemCount = fileSystemCount;
                    _context.Counter         = commitCount;

                    // Write the initial context to the file
                    rc = contextFile.Write(0, SpanHelpers.AsByteSpan(ref _context), WriteOption.None);
                    if (rc.IsFailure())
                    {
                        return(rc);
                    }

                    rc = contextFile.Flush();
                    if (rc.IsFailure())
                    {
                        return(rc);
                    }
                }
                finally
                {
                    contextFile?.Dispose();
                }

                return(_fileSystem.Commit());
            }