mirror of
https://github.com/winfsp/winfsp.git
synced 2025-04-23 00:43:00 -05:00
sys: IRP_MJ_CREATE: FileAttributes
This commit is contained in:
parent
02ab670b39
commit
6adc3e792a
@ -112,7 +112,7 @@ typedef struct
|
|||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
UINT32 CreateOptions; /* Disposition: high 8 bits; Options: low 24 bits */
|
UINT32 CreateOptions; /* Disposition: high 8 bits; Options: low 24 bits */
|
||||||
UINT32 FileAttributes; /* FILE_ATTRIBUTE_{NORMAL,DIRECTORY,etc.} */
|
UINT32 FileAttributes; /* file attributes for new files */
|
||||||
FSP_FSCTL_TRANSACT_BUF SecurityDescriptor; /* security descriptor for new files */
|
FSP_FSCTL_TRANSACT_BUF SecurityDescriptor; /* security descriptor for new files */
|
||||||
UINT64 AllocationSize; /* initial allocation size */
|
UINT64 AllocationSize; /* initial allocation size */
|
||||||
UINT64 AccessToken; /* (HANDLE); request access token; sent if NoAccessCheck is 0 */
|
UINT64 AccessToken; /* (HANDLE); request access token; sent if NoAccessCheck is 0 */
|
||||||
@ -128,7 +128,7 @@ typedef struct
|
|||||||
{
|
{
|
||||||
UINT64 UserContext;
|
UINT64 UserContext;
|
||||||
UINT64 UserContext2;
|
UINT64 UserContext2;
|
||||||
UINT32 FileAttributes; /* FILE_ATTRIBUTE_{NORMAL,DIRECTORY,etc.} */
|
UINT32 FileAttributes; /* file attributes for overwritten/superseded files */
|
||||||
UINT32 Supersede:1; /* 0: FILE_OVERWRITE operation, 1: FILE_SUPERSEDE operation */
|
UINT32 Supersede:1; /* 0: FILE_OVERWRITE operation, 1: FILE_SUPERSEDE operation */
|
||||||
} Overwrite;
|
} Overwrite;
|
||||||
struct
|
struct
|
||||||
@ -166,7 +166,7 @@ typedef struct
|
|||||||
{
|
{
|
||||||
UINT64 UserContext; /* user context (unique file id) associated with file node */
|
UINT64 UserContext; /* user context (unique file id) associated with file node */
|
||||||
UINT64 UserContext2; /* user context associated with file descriptor (handle) */
|
UINT64 UserContext2; /* user context associated with file descriptor (handle) */
|
||||||
UINT32 FileAttributes; /* FILE_ATTRIBUTE_{NORMAL,DIRECTORY,etc.} */
|
UINT32 FileAttributes; /* file attributes of opened file */
|
||||||
UINT64 AllocationSize; /* file allocation size */
|
UINT64 AllocationSize; /* file allocation size */
|
||||||
UINT64 FileSize; /* file size */
|
UINT64 FileSize; /* file size */
|
||||||
UINT32 GrantedAccess; /* FILE_{READ_DATA,WRITE_DATA,etc.} */
|
UINT32 GrantedAccess; /* FILE_{READ_DATA,WRITE_DATA,etc.} */
|
||||||
|
@ -290,6 +290,13 @@ static NTSTATUS FspFsvolCreate(
|
|||||||
return Result;
|
return Result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* fix FileAttributes */
|
||||||
|
ClearFlag(FileAttributes, FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_DIRECTORY);
|
||||||
|
if (CreateOptions & FILE_DIRECTORY_FILE)
|
||||||
|
SetFlag(FileAttributes, FILE_ATTRIBUTE_DIRECTORY);
|
||||||
|
else
|
||||||
|
ClearFlag(FileAttributes, FILE_ATTRIBUTE_DIRECTORY);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The new request is associated with our IRP. Go ahead and associate our FileNode/FileDesc
|
* The new request is associated with our IRP. Go ahead and associate our FileNode/FileDesc
|
||||||
* with the Request as well. After this is done completing our IRP will automatically
|
* with the Request as well. After this is done completing our IRP will automatically
|
||||||
@ -590,8 +597,9 @@ VOID FspFsvolCreateComplete(
|
|||||||
* If the user wants to delete on close, we must check at this
|
* If the user wants to delete on close, we must check at this
|
||||||
* point though.
|
* point though.
|
||||||
*/
|
*/
|
||||||
if (FlagOn(Response->Rsp.Create.Opened.GrantedAccess, FILE_WRITE_DATA) ||
|
if (!FlagOn(Response->Rsp.Create.Opened.FileAttributes, FILE_ATTRIBUTE_DIRECTORY) &&
|
||||||
DeleteOnClose)
|
(FlagOn(Response->Rsp.Create.Opened.GrantedAccess, FILE_WRITE_DATA) ||
|
||||||
|
DeleteOnClose))
|
||||||
{
|
{
|
||||||
Result = FspFsvolCreateTryOpen(Irp, 0, FileNode, FileDesc, FileObject);
|
Result = FspFsvolCreateTryOpen(Irp, 0, FileNode, FileDesc, FileObject);
|
||||||
if (STATUS_PENDING == Result || !NT_SUCCESS(Result))
|
if (STATUS_PENDING == Result || !NT_SUCCESS(Result))
|
||||||
@ -611,6 +619,13 @@ VOID FspFsvolCreateComplete(
|
|||||||
* Oh, noes! We have to go back to user mode to overwrite the file!
|
* Oh, noes! We have to go back to user mode to overwrite the file!
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/* save the old Request FileAttributes and make them compatible with the open file */
|
||||||
|
UINT32 FileAttributes = Request->Req.Create.FileAttributes;
|
||||||
|
if (FlagOn(Response->Rsp.Create.Opened.FileAttributes, FILE_ATTRIBUTE_DIRECTORY))
|
||||||
|
SetFlag(FileAttributes, FILE_ATTRIBUTE_DIRECTORY);
|
||||||
|
else
|
||||||
|
ClearFlag(FileAttributes, FILE_ATTRIBUTE_DIRECTORY);
|
||||||
|
|
||||||
/* delete the old request */
|
/* delete the old request */
|
||||||
FspIrpRequest(Irp) = 0;
|
FspIrpRequest(Irp) = 0;
|
||||||
FspIopRequestContext(Request, RequestFileDesc) = 0;
|
FspIopRequestContext(Request, RequestFileDesc) = 0;
|
||||||
@ -632,7 +647,7 @@ VOID FspFsvolCreateComplete(
|
|||||||
Request->Kind = FspFsctlTransactOverwriteKind;
|
Request->Kind = FspFsctlTransactOverwriteKind;
|
||||||
Request->Req.Overwrite.UserContext = FileNode->UserContext;
|
Request->Req.Overwrite.UserContext = FileNode->UserContext;
|
||||||
Request->Req.Overwrite.UserContext2 = FileDesc->UserContext2;
|
Request->Req.Overwrite.UserContext2 = FileDesc->UserContext2;
|
||||||
Request->Req.Overwrite.FileAttributes = IrpSp->Parameters.Create.FileAttributes;
|
Request->Req.Overwrite.FileAttributes = FileAttributes;
|
||||||
Request->Req.Overwrite.Supersede = FILE_SUPERSEDED == Response->IoStatus.Information;
|
Request->Req.Overwrite.Supersede = FILE_SUPERSEDED == Response->IoStatus.Information;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -110,14 +110,23 @@ MEMFS_FILE_NODE *MemfsFileNodeMapGet(MEMFS_FILE_NODE_MAP *FileNodeMap, PWSTR Fil
|
|||||||
}
|
}
|
||||||
|
|
||||||
static inline
|
static inline
|
||||||
MEMFS_FILE_NODE *MemfsFileNodeMapGetParent(MEMFS_FILE_NODE_MAP *FileNodeMap, PWSTR FileName)
|
MEMFS_FILE_NODE *MemfsFileNodeMapGetParent(MEMFS_FILE_NODE_MAP *FileNodeMap, PWSTR FileName,
|
||||||
|
PNTSTATUS PResult)
|
||||||
{
|
{
|
||||||
PWSTR Remain, Suffix;
|
PWSTR Remain, Suffix;
|
||||||
FspPathSuffix(FileName, &Remain, &Suffix);
|
FspPathSuffix(FileName, &Remain, &Suffix);
|
||||||
MEMFS_FILE_NODE_MAP::iterator iter = FileNodeMap->find(Remain);
|
MEMFS_FILE_NODE_MAP::iterator iter = FileNodeMap->find(Remain);
|
||||||
FspPathCombine(Remain, Suffix);
|
FspPathCombine(Remain, Suffix);
|
||||||
if (iter == FileNodeMap->end())
|
if (iter == FileNodeMap->end())
|
||||||
|
{
|
||||||
|
*PResult = STATUS_OBJECT_PATH_NOT_FOUND;
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
if (0 == (iter->second->FileAttributes & FILE_ATTRIBUTE_DIRECTORY))
|
||||||
|
{
|
||||||
|
*PResult = STATUS_NOT_A_DIRECTORY;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
return iter->second;
|
return iter->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -152,11 +161,15 @@ static NTSTATUS GetSecurity(FSP_FILE_SYSTEM *FileSystem,
|
|||||||
{
|
{
|
||||||
MEMFS *Memfs = (MEMFS *)FileSystem->UserContext;
|
MEMFS *Memfs = (MEMFS *)FileSystem->UserContext;
|
||||||
MEMFS_FILE_NODE *FileNode;
|
MEMFS_FILE_NODE *FileNode;
|
||||||
|
NTSTATUS Result;
|
||||||
|
|
||||||
FileNode = MemfsFileNodeMapGet(Memfs->FileNodeMap, FileName);
|
FileNode = MemfsFileNodeMapGet(Memfs->FileNodeMap, FileName);
|
||||||
if (0 == FileNode)
|
if (0 == FileNode)
|
||||||
return !MemfsFileNodeMapGetParent(Memfs->FileNodeMap, FileName) ?
|
{
|
||||||
STATUS_OBJECT_PATH_NOT_FOUND : STATUS_OBJECT_NAME_NOT_FOUND;
|
Result = STATUS_OBJECT_NAME_NOT_FOUND;
|
||||||
|
MemfsFileNodeMapGetParent(Memfs->FileNodeMap, FileName, &Result);
|
||||||
|
return Result;
|
||||||
|
}
|
||||||
|
|
||||||
if (0 != PFileAttributes)
|
if (0 != PFileAttributes)
|
||||||
*PFileAttributes = FileNode->FileAttributes;
|
*PFileAttributes = FileNode->FileAttributes;
|
||||||
@ -188,12 +201,15 @@ static NTSTATUS Create(FSP_FILE_SYSTEM *FileSystem,
|
|||||||
NTSTATUS Result;
|
NTSTATUS Result;
|
||||||
BOOLEAN Inserted;
|
BOOLEAN Inserted;
|
||||||
|
|
||||||
|
if (CreateOptions & FILE_DIRECTORY_FILE)
|
||||||
|
AllocationSize = 0;
|
||||||
|
|
||||||
FileNode = MemfsFileNodeMapGet(Memfs->FileNodeMap, FileName);
|
FileNode = MemfsFileNodeMapGet(Memfs->FileNodeMap, FileName);
|
||||||
if (0 != FileNode)
|
if (0 != FileNode)
|
||||||
return STATUS_OBJECT_NAME_COLLISION;
|
return STATUS_OBJECT_NAME_COLLISION;
|
||||||
|
|
||||||
if (!MemfsFileNodeMapGetParent(Memfs->FileNodeMap, FileName))
|
if (!MemfsFileNodeMapGetParent(Memfs->FileNodeMap, FileName, &Result))
|
||||||
return STATUS_OBJECT_PATH_NOT_FOUND;
|
return Result;
|
||||||
|
|
||||||
if (MemfsFileNodeMapCount(Memfs->FileNodeMap) >= Memfs->MaxFileNodes)
|
if (MemfsFileNodeMapCount(Memfs->FileNodeMap) >= Memfs->MaxFileNodes)
|
||||||
return STATUS_CANNOT_MAKE;
|
return STATUS_CANNOT_MAKE;
|
||||||
@ -255,11 +271,15 @@ static NTSTATUS Open(FSP_FILE_SYSTEM *FileSystem,
|
|||||||
{
|
{
|
||||||
MEMFS *Memfs = (MEMFS *)FileSystem->UserContext;
|
MEMFS *Memfs = (MEMFS *)FileSystem->UserContext;
|
||||||
MEMFS_FILE_NODE *FileNode;
|
MEMFS_FILE_NODE *FileNode;
|
||||||
|
NTSTATUS Result;
|
||||||
|
|
||||||
FileNode = MemfsFileNodeMapGet(Memfs->FileNodeMap, FileName);
|
FileNode = MemfsFileNodeMapGet(Memfs->FileNodeMap, FileName);
|
||||||
if (0 == FileNode)
|
if (0 == FileNode)
|
||||||
return !MemfsFileNodeMapGetParent(Memfs->FileNodeMap, FileName) ?
|
{
|
||||||
STATUS_OBJECT_PATH_NOT_FOUND : STATUS_OBJECT_NAME_NOT_FOUND;
|
Result = STATUS_OBJECT_NAME_NOT_FOUND;
|
||||||
|
MemfsFileNodeMapGetParent(Memfs->FileNodeMap, FileName, &Result);
|
||||||
|
return Result;
|
||||||
|
}
|
||||||
|
|
||||||
FileNode->RefCount++;
|
FileNode->RefCount++;
|
||||||
NodeInfo->FileAttributes = FileNode->FileAttributes;
|
NodeInfo->FileAttributes = FileNode->FileAttributes;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user