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); } }
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); } }