public virtual NfsPacket Create(uint xid, NfsPacket packet)
{
try {
FileHandle dirFH = new FileHandle(packet);
string entry = packet.GetString();
string dirName = GetNameFromHandle(dirFH.Handle, xid);
string path = Path.Combine(dirName, entry);
// make the file
if (File.Exists(path))
{
throw new NFSException(xid, (uint)NfsReply.ERR_EXIST);
}
using (var file = File.Create(path)) { }
// make a new handle for this file
FileHandle fh = new FileHandle();
long handle = HandleManager.Current.GetHandle(path);
fh.Set(dirFH.Root, (uint)handle, dirFH.ReadOnly);
// get the attributes of this new file
NfsFileAttributes fa = new NfsFileAttributes();
fa.Load(path);
// create the reply packet
NfsPacket reply = new NfsPacket(128);
reply.AddReplyHeader(xid);
reply.SetUInt((uint)NfsReply.OK);
fh.Emit(ref reply);
fa.Emit(ref reply);
return(reply);
}
catch (FileNotFoundException) {
throw new NFSException(xid, (uint)NfsReply.ERR_IO);
}
catch (IOException) {
throw new NFSException(xid, (uint)NfsReply.ERR_IO);
}
catch (System.Security.SecurityException) {
throw new NFSException(xid, (uint)NfsReply.ERR_PERM);
}
}