Example #1
0
 public void Write(ByteBufferRef buf, int offset)
 {
     Contract.Assert(offset >= 0 && offset + Size <= buf.Length);
     Deserializer.WriteInt(fd, buf, offset);
     Deserializer.WriteShort(events, buf, offset + sizeof(int));
     Deserializer.WriteShort(revents, buf, offset + sizeof(int) + sizeof(short));
 }
Example #2
0
        internal void WriteInt32(int v)
        {
            // Fail sliently
            if (cursor + sizeof(int) > Buffer.Length)
            {
                return;
            }

            var r = new ByteBufferRef(Buffer);

            Deserializer.WriteInt(v, r, cursor);
            cursor += sizeof(int);
        }
Example #3
0
        private int PrepareBuffer(ByteBufferRef buf, CachePage[] sealed_page)
        {
            var cursor = 0;

            // Metadata
            for (var i = 0; i < DataPageOffset; ++i)
            {
                Deserializer.WriteInt(i, buf, cursor);
                cursor += sizeof(int);
            }

            for (var i = 0; i < sealed_page.Length; ++i)
            {
                var pgoffset = sealed_page[i].Location;
                Deserializer.WriteInt(pgoffset + DataPageOffset, buf, cursor);
                cursor += sizeof(int);
                if (pgoffset > MaximumPageOffset())
                {
                    Arch.Console.WriteLine("SecureFSINode::FlushAndCloseAsync, file too big");
                    Utils.Panic();
                    return(-1);
                }
            }

            var metadata_cursor = cursor;

            cursor += DataPageOffset * Arch.ArchDefinition.PageSize;

            // Copy data
            var sha1 = new SHA1Managed();

            for (var i = 0; i < sealed_page.Length; ++i)
            {
                var page = sealed_page[i];
                buf.CopyFrom(cursor, page.Buffer);
                sha1.Reset();
                sha1.Input(page.Buffer);
                var r = sha1.GetResult();

                for (var j = 0; j < r.Length; ++j)
                {
                    Signatures[page.Location * HMACSize + j] = r[j];
                }

                page.Dispose();
                cursor += Arch.ArchDefinition.PageSize;
            }

            SerializeMetadata(buf, metadata_cursor);
            return(0);
        }
Example #4
0
        private void SerializeMetadata(ByteBufferRef buf, int cursor)
        {
            Deserializer.WriteULong(HeaderMagic, buf, cursor);
            cursor += sizeof(ulong);
            var hmac = CalculateHMAC(DataPageOffset, FileSize, Signatures);

            buf.CopyFrom(cursor, hmac);
            cursor += HMACSize;
            Deserializer.WriteInt(DataPageOffset, buf, cursor);
            cursor += sizeof(int);
            Deserializer.WriteUInt(FileSize, buf, cursor);
            cursor += sizeof(uint);
            Deserializer.WriteInt(Signatures.Length, buf, cursor);
            cursor += sizeof(int);
            buf.CopyFrom(cursor, Signatures);
        }
Example #5
0
        private int AppendPatchTable()
        {
            // Skip the field storing the number of the patch
            PatchTableOffset = WriteCursor + sizeof(int);
            if (WriteCursor + (CurrentPatchEntry + 1) * sizeof(int) > buf.Length)
            {
                return(-1);
            }

            Deserializer.WriteInt(CurrentPatchEntry, buf, WriteCursor);
            WriteCursor += sizeof(int);
            for (var i = 0; i < CurrentPatchEntry; i++)
            {
                Deserializer.WriteInt(patchTable[i], buf, WriteCursor);
                WriteCursor += sizeof(int);
            }

            return(0);
        }