Exemplo n.º 1
0
        internal virtual bool Read(NfsPacket packet)
        {
            root      = packet.GetUInt();        // the first long in the packet is the handle of the root
            handle    = packet.GetUInt();        // the next long is the handle of the file
            @readonly = packet.GetUInt();        // the next is a read only flag

            // The rest is nothing. There are 32 bytes in a FileHandle and this has read in 3 words, or 12 bytes.
            packet.Advance(32 - 3 * 4);

            return(true);
        }
Exemplo n.º 2
0
        public NfsPacket Write(uint xid, NfsPacket packet)
        {
            string fileName = null;

            try {
                // read info out of packet
                FileHandle fh          = new FileHandle(packet);
                uint       beginoffset = packet.GetUInt();
                uint       offset      = packet.GetUInt();
                uint       totalcount  = packet.GetUInt();
                // next comes the data which is a uint of size and the bytes.
                uint datalen      = packet.GetUInt();
                uint packetOffset = (uint)packet.Position;
                packet.Advance(datalen);

                // carry out the write operation
                fileName = HandleManager.Current.GetName(fh.Handle);
                if (fileName == null)
                {
                    throw new NFSException(xid, (uint)NfsReply.ERR_STALE);
                }
                // XXX comment out print lines to improve performance
                // System.out.print("Write(" + fileName + ", " + offset + ", " +
                //		     datalen + ")\n");
                using (StreamWriter sw = new StreamWriter(fileName)) {
                    sw.BaseStream.Seek(offset, SeekOrigin.Begin);
                    sw.BaseStream.Write(packet.Data, (int)packetOffset, (int)datalen);
                }

                // load in new file attributes
                NfsFileAttributes fa = new NfsFileAttributes();
                fa.Load(fileName);

                // create the reply packet
                NfsPacket result = new NfsPacket(128);
                result.Reset();
                result.AddReplyHeader(xid);
                result.SetUInt((uint)NfsReply.OK);
                fa.Emit(ref result);

                return(result);
            }
            catch (IOException) {
                throw new NFSException(xid, (uint)NfsReply.ERR_IO);
            }
            catch (System.Security.SecurityException) {
                throw new NFSException(xid, (uint)NfsReply.ERR_PERM);
            }
        }
Exemplo n.º 3
0
        public NfsPacket Write(uint xid, NfsPacket packet)
        {
            string fileName = null;

            try {
                // read info out of packet
                FileHandle fh = new FileHandle(packet);
                uint beginoffset = packet.GetUInt();
                uint offset = packet.GetUInt();
                uint totalcount = packet.GetUInt();
                // next comes the data which is a uint of size and the bytes.
                uint datalen = packet.GetUInt();
                uint packetOffset = (uint)packet.Position;
                packet.Advance(datalen);

                // carry out the write operation
                fileName = HandleManager.Current.GetName(fh.Handle);
                if (fileName == null) {
                    throw new NFSException(xid, (uint)NfsReply.ERR_STALE);
                }
                // XXX comment out print lines to improve performance
                // System.out.print("Write(" + fileName + ", " + offset + ", " +
                //		     datalen + ")\n");
                using (StreamWriter sw = new StreamWriter(fileName)) {
                    sw.BaseStream.Seek(offset, SeekOrigin.Begin);
                    sw.BaseStream.Write(packet.Data, (int)packetOffset, (int)datalen);
                }

                // load in new file attributes
                NfsFileAttributes fa = new NfsFileAttributes();
                fa.Load(fileName);

                // create the reply packet
                NfsPacket result = new NfsPacket(128);
                result.Reset();
                result.AddReplyHeader(xid);
                result.SetUInt((uint)NfsReply.OK);
                fa.Emit(ref result);

                return result;
            }
            catch (IOException) {
                throw new NFSException(xid, (uint)NfsReply.ERR_IO);
            }
            catch (System.Security.SecurityException) {
                throw new NFSException(xid, (uint)NfsReply.ERR_PERM);
            }
        }
Exemplo n.º 4
0
        internal virtual bool Read(NfsPacket packet)
        {
            root = packet.GetUInt(); // the first long in the packet is the handle of the root
            handle = packet.GetUInt(); // the next long is the handle of the file
            @readonly = packet.GetUInt(); // the next is a read only flag

            // The rest is nothing. There are 32 bytes in a FileHandle and this has read in 3 words, or 12 bytes.
            packet.Advance(32 - 3 * 4);

            return true;
        }