private void CreateFileOrDirectory(rpcCracker cracker, rpcPacker packer, bool createFile) { createargs args = new createargs(cracker); String createPath = FileTable.LookupFileEntry(args.Where.DirHandle).Name + @"\" + args.Where.FileName; Console.WriteLine("Create: {0}", createPath); fhandle fh; if ((fh = FileTable.LookupFileHandle(createPath)) == null) { fh = FileTable.Add(new FileEntry(createPath)); } if (createFile == true) { new FileInfo(createPath).Create().Close(); } else { new DirectoryInfo(createPath).Create(); } fattr attr = new fattr(fh); if (attr.IsFile() != createFile) { throw new System.Exception(); } diropres.PackSuccess(packer, fh, attr); }
private void Read(rpcCracker cracker, rpcPacker packer) { fhandle fh = new fhandle(cracker); uint offset = cracker.get_uint32(); uint count = cracker.get_uint32(); uint totalCount = cracker.get_uint32(); FileStream fs; try { fs = new FileStream(FileTable.LookupFileEntry(fh).Name, FileMode.Open, FileAccess.Read); } catch (System.IO.FileNotFoundException) { FileTable.Remove(fh); throw; } try { fs.Position = offset; Byte[] buf = new Byte[count]; int bytesRead = fs.Read(buf, 0, (int)count); fattr attr = new fattr(fh); if (attr.IsFile() == false) { throw new NFSStatusException(NFSStatus.NFSERR_ISDIR); } packer.setUint32((uint)NFSStatus.NFS_OK); attr.Pack(packer); packer.setData(buf, bytesRead); } finally { fs.Close(); } }
private void Read(rpcCracker cracker, rpcPacker packer) { fhandle fh = new fhandle(cracker); uint offset = cracker.get_uint32(); uint count = cracker.get_uint32(); uint totalCount = cracker.get_uint32(); FileStream fs; try { fs = new FileStream(FileTable.LookupFileEntry(fh).Name, FileMode.Open, FileAccess.Read); } catch (System.IO.FileNotFoundException) { FileTable.Remove(fh); throw; } try { fs.Position = offset; Byte[] buf = new Byte[count]; int bytesRead = fs.Read(buf, 0, (int)count); fattr attr = new fattr(fh); if (attr.IsFile() == false) throw new NFSStatusException(NFSStatus.NFSERR_ISDIR); packer.setUint32((uint)NFSStatus.NFS_OK); attr.Pack(packer); packer.setData(buf, bytesRead); } finally { fs.Close(); } }
private void CreateFileOrDirectory(rpcCracker cracker, rpcPacker packer, bool createFile) { createargs args = new createargs(cracker); String createPath = FileTable.LookupFileEntry(args.Where.DirHandle).Name + @"\" + args.Where.FileName; Console.WriteLine("Create: {0}", createPath); fhandle fh; if ((fh = FileTable.LookupFileHandle(createPath)) == null) fh = FileTable.Add(new FileEntry(createPath)); if (createFile == true) new FileInfo(createPath).Create().Close(); else new DirectoryInfo(createPath).Create(); fattr attr = new fattr(fh); if (attr.IsFile() != createFile) throw new System.Exception(); diropres.PackSuccess(packer, fh, attr); }