Summary description for sattr.
示例#1
0
文件: nfsd.cs 项目: zaubererty/NFS
        private void SymLink(rpcCracker cracker, rpcPacker packer)
        {
            diropargs args = new diropargs(cracker);
            string    path = cracker.get_String();
            sattr     attr = new sattr(cracker);

            String createPath = FileTable.LookupFileEntry(args.DirHandle).Name + @"\" + args.FileName + ".sl";

            Console.WriteLine("Symlink: {0}->{1}", createPath, path);

            fhandle fh;

            if ((fh = FileTable.LookupFileHandle(createPath)) == null)
            {
                fh = FileTable.Add(new FileEntry(createPath));
            }

            try
            {
                FileStream symlink = new FileStream(createPath, FileMode.CreateNew, FileAccess.Write);

                try
                {
                    UTF8Encoding pathUTF8 = new UTF8Encoding();

                    byte[] buf = pathUTF8.GetBytes(path);

                    symlink.Write(buf, 0, buf.Length);

                    packer.setUint32((uint)NFSStatus.NFS_OK);
                }
                finally
                {
                    symlink.Close();
                }
            }
            catch (IOException)
            {
                if (new FileInfo(createPath).Exists == true)
                {
                    throw new NFSStatusException(NFSStatus.NFSERR_EXIST);
                }
                else
                {
                    throw;
                }
            }
        }
示例#2
0
文件: nfsd.cs 项目: zaubererty/NFS
        private void SetAttr(rpcCracker cracker, rpcPacker packer)
        {
            fhandle fh         = new fhandle(cracker);
            sattr   attributes = new sattr(cracker);

            FileEntry file = FileTable.LookupFileEntry(fh);

            if (file == null)
            {
                Console.WriteLine("Invalid file handle:{0}", fh.Index);
                throw new NFSStatusException(NFSStatus.NFSERR_STALE);
            }

            // TODO: Actually do something with the attributes.
            if (attributes.Size == 0)
            {
                try
                {
                    FileStream fs = new FileStream(file.Name, FileMode.Truncate, FileAccess.Write);
                    fs.Close();
                }
                catch (System.IO.FileNotFoundException)
                {
                    FileTable.Remove(fh);
                    throw;
                }
            }

            if ((int)attributes.Mode != -1)
            {
                FileInfo info = new FileInfo(FileTable.LookupFileEntry(fh).Name);

                if ((attributes.Mode & (uint)fattr.modes.WOWN) == (uint)fattr.modes.WOWN)
                {
                    info.Attributes = info.Attributes & ~FileAttributes.ReadOnly;
                }
                else
                {
                    info.Attributes = info.Attributes | FileAttributes.ReadOnly;
                }
            }

            attrstat.PackSuccess(packer, new fattr(fh));
        }
示例#3
0
文件: nfsd.cs 项目: petebarber/NFS
        private void SymLink(rpcCracker cracker, rpcPacker packer)
        {
            diropargs	args	= new diropargs(cracker);
            string		path	= cracker.get_String();
            sattr		attr	= new sattr(cracker);

            String createPath = FileTable.LookupFileEntry(args.DirHandle).Name + @"\" + args.FileName + ".sl";

            Console.WriteLine("Symlink: {0}->{1}", createPath, path);

            fhandle fh;

            if ((fh = FileTable.LookupFileHandle(createPath)) == null)
                fh = FileTable.Add(new FileEntry(createPath));

            try
            {
                FileStream symlink = new FileStream(createPath, FileMode.CreateNew, FileAccess.Write);

                try
                {
                    UTF8Encoding pathUTF8 = new UTF8Encoding();

                    byte[] buf = pathUTF8.GetBytes(path);

                    symlink.Write(buf, 0, buf.Length);

                    packer.setUint32((uint)NFSStatus.NFS_OK);
                }
                finally
                {
                    symlink.Close();
                }
            }
            catch(IOException)
            {
                if (new FileInfo(createPath).Exists == true)
                    throw new NFSStatusException(NFSStatus.NFSERR_EXIST);
                else
                    throw;
            }
        }
示例#4
0
文件: nfsd.cs 项目: petebarber/NFS
        private void SetAttr(rpcCracker cracker, rpcPacker packer)
        {
            fhandle	fh			= new fhandle(cracker);
            sattr	attributes	= new sattr(cracker);

            FileEntry file = FileTable.LookupFileEntry(fh);

            if (file == null)
            {
                Console.WriteLine("Invalid file handle:{0}", fh.Index);
                throw new NFSStatusException(NFSStatus.NFSERR_STALE);
            }

            // TODO: Actually do something with the attributes.
            if (attributes.Size == 0)
            {
                try
                {
                    FileStream fs = new FileStream(file.Name, FileMode.Truncate, FileAccess.Write);
                    fs.Close();
                }
                catch (System.IO.FileNotFoundException)
                {
                    FileTable.Remove(fh);
                    throw;
                }
            }

            if ((int)attributes.Mode != -1)
            {
                FileInfo info = new FileInfo(FileTable.LookupFileEntry(fh).Name);

                if ((attributes.Mode & (uint)fattr.modes.WOWN) == (uint)fattr.modes.WOWN)
                    info.Attributes = info.Attributes & ~FileAttributes.ReadOnly;
                else
                    info.Attributes = info.Attributes | FileAttributes.ReadOnly;
            }

            attrstat.PackSuccess(packer, new fattr(fh));
        }
示例#5
0
 public createargs(rpcCracker cracker)
 {
     where      = new diropargs(cracker);
     attributes = new sattr(cracker);
 }
示例#6
0
 public createargs(rpcCracker cracker)
 {
     where		= new diropargs(cracker);
     attributes	= new sattr(cracker);
 }