Exemplo n.º 1
0
        public override Int32 Overwrite(
            Object fileNode,
            Object fileDesc0,
            UInt32 fileAttributes,
            Boolean replaceFileAttributes,
            UInt64 allocationSize,
            out FileInfo fileInfo)
        {
            FileDescriptor fileDesc = (FileDescriptor)fileDesc0;

            MakeWriteable(fileDesc);

            if (replaceFileAttributes)
            {
                fileDesc.SetFileAttributes(fileAttributes | (UInt32)System.IO.FileAttributes.Archive);
            }
            else if (0 != fileAttributes)
            {
                fileDesc.SetFileAttributes(fileDesc.GetFileAttributes() | fileAttributes | (UInt32)System.IO.FileAttributes.Archive);
            }

            fileDesc.WriteStream.SetLength(0);

            return(fileDesc.GetFileInfo(out fileInfo));
        }
Exemplo n.º 2
0
        public override Int32 Create(
            String fileName,
            UInt32 createOptions,
            UInt32 grantedAccess,
            UInt32 fileAttributes,
            Byte[] securityDescriptor,
            UInt64 allocationSize,
            out Object fileNode,
            out Object fileDesc0,
            out FileInfo fileInfo,
            out String normalizedName)
        {
            fileNode       = default(Object);
            normalizedName = default(String);

            FileDescriptor fileDesc = null;

            try
            {
                var path = GetWritePath(fileName);

                // directory or file?
                if (0 == (createOptions & FILE_DIRECTORY_FILE))
                {
                    // file

                    FileSecurity Security = null;

                    if (null != securityDescriptor)
                    {
                        Security = new FileSecurity();
                        Security.SetSecurityDescriptorBinaryForm(securityDescriptor);
                    }

                    fileDesc = new FileDescriptor(fileName,
                                                  new FileStream(
                                                      path,
                                                      FileMode.CreateNew,
                                                      (FileSystemRights)grantedAccess | FileSystemRights.WriteAttributes,
                                                      FileShare.Read | FileShare.Write | FileShare.Delete,
                                                      4096,
                                                      0,
                                                      Security), true);

                    fileDesc.SetFileAttributes(fileAttributes | (UInt32)System.IO.FileAttributes.Archive);
                }
                else
                {
                    // directory

                    if (Directory.Exists(path))
                    {
                        Utils.ThrowIoExceptionWithNtStatus(STATUS_OBJECT_NAME_COLLISION);
                    }

                    DirectorySecurity Security = null;

                    if (null != securityDescriptor)
                    {
                        Security = new DirectorySecurity();
                        Security.SetSecurityDescriptorBinaryForm(securityDescriptor);
                    }

                    fileDesc = new FileDescriptor(fileName, Directory.CreateDirectory(path, Security), true);

                    fileDesc.SetFileAttributes(fileAttributes);
                }

                // assign the file descriptor
                fileDesc0 = fileDesc;
                return(fileDesc.GetFileInfo(out fileInfo));
            }
            catch
            {
                if (null != fileDesc)
                {
                    fileDesc.Dispose();
                }

                throw;
            }
        }