ReactOS  0.4.14-dev-114-gc8cbd56
fileinfo.c File Reference
#include "ext2fs.h"
#include <linux/ext4.h>
#include "linux/ext4_xattr.h"
Include dependency graph for fileinfo.c:

Go to the source code of this file.

Functions

static int Ext2IterateAllEa (struct ext4_xattr_ref *xattr_ref, struct ext4_xattr_item *item, BOOL is_last)
 
NTSTATUS Ext2QueryFileInformation (IN PEXT2_IRP_CONTEXT IrpContext)
 
NTSTATUS Ext2SetFileInformation (IN PEXT2_IRP_CONTEXT IrpContext)
 
ULONG Ext2TotalBlocks (PEXT2_VCB Vcb, PLARGE_INTEGER Size, PULONG pMeta)
 
NTSTATUS Ext2BlockMap (IN PEXT2_IRP_CONTEXT IrpContext, IN PEXT2_VCB Vcb, IN PEXT2_MCB Mcb, IN ULONG Index, IN BOOLEAN bAlloc, OUT PULONG pBlock, OUT PULONG Number)
 
NTSTATUS Ext2ExpandFile (PEXT2_IRP_CONTEXT IrpContext, PEXT2_VCB Vcb, PEXT2_MCB Mcb, PLARGE_INTEGER Size)
 
NTSTATUS Ext2TruncateFile (PEXT2_IRP_CONTEXT IrpContext, PEXT2_VCB Vcb, PEXT2_MCB Mcb, PLARGE_INTEGER Size)
 
NTSTATUS Ext2IsFileRemovable (IN PEXT2_IRP_CONTEXT IrpContext, IN PEXT2_VCB Vcb, IN PEXT2_FCB Fcb, IN PEXT2_CCB Ccb)
 
NTSTATUS Ext2SetDispositionInfo (PEXT2_IRP_CONTEXT IrpContext, PEXT2_VCB Vcb, PEXT2_FCB Fcb, PEXT2_CCB Ccb, BOOLEAN bDelete)
 
NTSTATUS Ext2SetRenameInfo (PEXT2_IRP_CONTEXT IrpContext, PEXT2_VCB Vcb, PEXT2_FCB Fcb, PEXT2_CCB Ccb)
 
NTSTATUS Ext2SetLinkInfo (PEXT2_IRP_CONTEXT IrpContext, PEXT2_VCB Vcb, PEXT2_FCB Fcb, PEXT2_CCB Ccb)
 
ULONG Ext2InodeType (PEXT2_MCB Mcb)
 
NTSTATUS Ext2DeleteFile (PEXT2_IRP_CONTEXT IrpContext, PEXT2_VCB Vcb, PEXT2_FCB Fcb, PEXT2_MCB Mcb)
 

Variables

PEXT2_GLOBAL Ext2Global
 

Function Documentation

◆ Ext2BlockMap()

NTSTATUS Ext2BlockMap ( IN PEXT2_IRP_CONTEXT  IrpContext,
IN PEXT2_VCB  Vcb,
IN PEXT2_MCB  Mcb,
IN ULONG  Index,
IN BOOLEAN  bAlloc,
OUT PULONG  pBlock,
OUT PULONG  Number 
)

Definition at line 1122 of file fileinfo.c.

1131 {
1132  NTSTATUS status;
1133 
1134  if (INODE_HAS_EXTENT(&Mcb->Inode)) {
1135  status = Ext2MapExtent(IrpContext, Vcb, Mcb, Index,
1136  bAlloc, pBlock, Number );
1137  } else {
1138  status = Ext2MapIndirect(IrpContext, Vcb, Mcb, Index,
1139  bAlloc, pBlock, Number );
1140  }
1141 
1142  return status;
1143 }
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS Ext2MapExtent(IN PEXT2_IRP_CONTEXT IrpContext, IN PEXT2_VCB Vcb, IN PEXT2_MCB Mcb, IN ULONG Index, IN BOOLEAN Alloc, OUT PULONG Block, OUT PULONG Number)
Definition: extents.c:25
#define Vcb
Definition: cdprocs.h:1425
static const UCHAR Index[8]
Definition: usbohci.c:18
#define INODE_HAS_EXTENT(i)
Definition: ext4_ext.h:228
_In_opt_ PENTER_STATE_SYSTEM_HANDLER _In_opt_ PVOID _In_ LONG _In_opt_ LONG volatile * Number
Definition: ntpoapi.h:204
IN PVCB IN ULONG IN OUT PULONG IN BOOLEAN OUT PLARGE_MCB Mcb
Definition: fatprocs.h:334
NTSTATUS Ext2MapIndirect(IN PEXT2_IRP_CONTEXT IrpContext, IN PEXT2_VCB Vcb, IN PEXT2_MCB Mcb, IN ULONG Index, IN BOOLEAN bAlloc, OUT PULONG pBlock, OUT PULONG Number)
Definition: indirect.c:823
static SERVICE_STATUS status
Definition: service.c:31
Definition: ps.c:97

Referenced by Ext2BuildExtents().

◆ Ext2DeleteFile()

NTSTATUS Ext2DeleteFile ( PEXT2_IRP_CONTEXT  IrpContext,
PEXT2_VCB  Vcb,
PEXT2_FCB  Fcb,
PEXT2_MCB  Mcb 
)

Definition at line 1915 of file fileinfo.c.

1921 {
1922  PEXT2_FCB Dcb = NULL;
1923 
1925 
1926  BOOLEAN VcbResourceAcquired = FALSE;
1927  BOOLEAN FcbPagingIoAcquired = FALSE;
1928  BOOLEAN FcbResourceAcquired = FALSE;
1929  BOOLEAN DcbResourceAcquired = FALSE;
1930 
1932  LARGE_INTEGER SysTime;
1933 
1934  BOOLEAN bFcbLockAcquired = FALSE;
1935 
1936  DEBUG(DL_INF, ( "Ext2DeleteFile: File %wZ (%xh) will be deleted!\n",
1937  &Mcb->FullName, Mcb->Inode.i_ino));
1938 
1939  if (IsFlagOn(Mcb->Flags, MCB_FILE_DELETED)) {
1940  return STATUS_SUCCESS;
1941  }
1942 
1943  if (!IsMcbSymLink(Mcb) && IsMcbDirectory(Mcb)) {
1944  if (!Ext2IsDirectoryEmpty(IrpContext, Vcb, Mcb)) {
1946  }
1947  }
1948 
1949  _SEH2_TRY {
1950 
1951  Ext2ReferMcb(Mcb);
1952 
1953  ExAcquireResourceExclusiveLite(&Vcb->MainResource, TRUE);
1954  VcbResourceAcquired = TRUE;
1955 
1957  bFcbLockAcquired = TRUE;
1958 
1959  /* Mcb->Parent could be NULL when working with layered file systems */
1960  if (Mcb->Parent) {
1961  Dcb = Mcb->Parent->Fcb;
1962  if (!Dcb)
1963  Dcb = Ext2AllocateFcb(Vcb, Mcb->Parent);
1964  }
1965  if (Dcb)
1966  Ext2ReferXcb(&Dcb->ReferenceCount);
1967 
1968  if (bFcbLockAcquired) {
1969  ExReleaseResourceLite(&Vcb->FcbLock);
1970  bFcbLockAcquired = FALSE;
1971  }
1972 
1973  if (Dcb) {
1974  DcbResourceAcquired =
1975  ExAcquireResourceExclusiveLite(&Dcb->MainResource, TRUE);
1976 
1977  /* remove it's entry form it's parent */
1978  Status = Ext2RemoveEntry(IrpContext, Vcb, Dcb, Mcb);
1979  }
1980 
1981  if (NT_SUCCESS(Status)) {
1982 
1983  SetFlag(Mcb->Flags, MCB_FILE_DELETED);
1984  Ext2RemoveMcb(Vcb, Mcb);
1985 
1986  if (Fcb) {
1987  FcbResourceAcquired =
1989 
1990  FcbPagingIoAcquired =
1992  }
1993 
1994  if (DcbResourceAcquired) {
1995  ExReleaseResourceLite(&Dcb->MainResource);
1996  DcbResourceAcquired = FALSE;
1997  }
1998 
1999  if (VcbResourceAcquired) {
2000  ExReleaseResourceLite(&Vcb->MainResource);
2001  VcbResourceAcquired = FALSE;
2002  }
2003 
2004  if (IsMcbSymLink(Mcb)) {
2005  if (Mcb->Inode.i_nlink > 0) {
2007  _SEH2_LEAVE;
2008  }
2009  } else if (!IsMcbDirectory(Mcb)) {
2010  if (Mcb->Inode.i_nlink > 0) {
2011  _SEH2_LEAVE;
2012  }
2013  } else {
2014  if (Mcb->Inode.i_nlink >= 2) {
2015  _SEH2_LEAVE;
2016  }
2017  }
2018 
2019  if (S_ISLNK(Mcb->Inode.i_mode)) {
2020 
2021  /* for symlink, we should do differenctly */
2022  if (Mcb->Inode.i_size > EXT2_LINKLEN_IN_INODE) {
2023  Size.QuadPart = (LONGLONG)0;
2024  Status = Ext2TruncateFile(IrpContext, Vcb, Mcb, &Size);
2025  }
2026 
2027  } else {
2028 
2029  /* truncate file size */
2030  Size.QuadPart = (LONGLONG)0;
2031  Status = Ext2TruncateFile(IrpContext, Vcb, Mcb, &Size);
2032 
2033  /* check file offset mappings */
2034  DEBUG(DL_EXT, ("Ext2DeleteFile ...: %wZ\n", &Mcb->FullName));
2035 
2036  if (Fcb) {
2037  Fcb->Header.AllocationSize.QuadPart = Size.QuadPart;
2038  if (Fcb->Header.FileSize.QuadPart > Size.QuadPart) {
2039  Fcb->Header.FileSize.QuadPart = Size.QuadPart;
2040  Fcb->Mcb->Inode.i_size = Size.QuadPart;
2041  }
2042  if (Fcb->Header.ValidDataLength.QuadPart > Fcb->Header.FileSize.QuadPart) {
2043  Fcb->Header.ValidDataLength.QuadPart = Fcb->Header.FileSize.QuadPart;
2044  }
2045  } else if (Mcb) {
2046  /* Update the inode's data length . It should be ZERO if succeeds. */
2047  if (Mcb->Inode.i_size > (loff_t)Size.QuadPart) {
2048  Mcb->Inode.i_size = Size.QuadPart;
2049  }
2050  }
2051  }
2052 
2053  /* set delete time and free the inode */
2054  KeQuerySystemTime(&SysTime);
2055  Mcb->Inode.i_nlink = 0;
2056  Mcb->Inode.i_dtime = Ext2LinuxTime(SysTime);
2057  Ext2SaveInode(IrpContext, Vcb, &Mcb->Inode);
2058  Ext2FreeInode(IrpContext, Vcb, Mcb->Inode.i_ino, Ext2InodeType(Mcb));
2059  }
2060 
2061  } _SEH2_FINALLY {
2062 
2063  if (FcbPagingIoAcquired) {
2065  }
2066 
2067  if (FcbResourceAcquired) {
2069  }
2070 
2071  if (DcbResourceAcquired) {
2072  ExReleaseResourceLite(&Dcb->MainResource);
2073  }
2074 
2075  if (bFcbLockAcquired) {
2076  ExReleaseResourceLite(&Vcb->FcbLock);
2077  }
2078 
2079  if (VcbResourceAcquired) {
2080  ExReleaseResourceLite(&Vcb->MainResource);
2081  }
2082 
2083  if (Dcb) {
2085  }
2086 
2087  Ext2DerefMcb(Mcb);
2088  } _SEH2_END;
2089 
2090  DEBUG(DL_INF, ( "Ext2DeleteFile: %wZ Succeed... EXT2SB->S_FREE_BLOCKS = %I64xh .\n",
2091  &Mcb->FullName, ext3_free_blocks_count(SUPER_BLOCK)));
2092 
2093  return Status;
2094 }
#define KeQuerySystemTime(t)
Definition: env_spec_w32.h:570
#define Ext2DerefMcb(Mcb)
Definition: ext2fs.h:987
#define TRUE
Definition: types.h:120
#define IsMcbDirectory(Mcb)
Definition: ext2fs.h:958
FSRTL_ADVANCED_FCB_HEADER Header
Definition: cdstruc.h:931
#define STATUS_DIRECTORY_NOT_EMPTY
Definition: udferr_usr.h:167
LONG NTSTATUS
Definition: precomp.h:26
#define Ext2ReferMcb(Mcb)
Definition: ext2fs.h:986
BOOLEAN Ext2IsDirectoryEmpty(IN PEXT2_IRP_CONTEXT IrpContext, IN PEXT2_VCB Vcb, IN PEXT2_MCB Mcb)
NTSTATUS Ext2TruncateFile(PEXT2_IRP_CONTEXT IrpContext, PEXT2_VCB Vcb, PEXT2_MCB Mcb, PLARGE_INTEGER Size)
Definition: fileinfo.c:1199
_SEH2_TRY
Definition: create.c:4250
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
#define S_ISLNK(m)
Definition: ext2fs.h:368
#define DL_EXT
Definition: ext2fs.h:1406
#define MCB_FILE_DELETED
Definition: ext2fs.h:946
NTSTATUS Ext2FreeInode(IN PEXT2_IRP_CONTEXT IrpContext, IN PEXT2_VCB Vcb, IN ULONG Inode, IN ULONG Type)
Definition: generic.c:1699
#define IsFlagOn(a, b)
Definition: ext2fs.h:177
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
PEXT2_FCB Ext2AllocateFcb(IN PEXT2_VCB Vcb, IN PEXT2_MCB Mcb)
Definition: memory.c:131
#define SUPER_BLOCK
Definition: ext2fs.h:90
int64_t LONGLONG
Definition: typedefs.h:66
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define DL_INF
Definition: ext2fs.h:1399
#define IsMcbSymLink(Mcb)
Definition: ext2fs.h:953
#define Vcb
Definition: cdprocs.h:1425
#define Ext2ReferXcb(_C)
Definition: ext2fs.h:967
#define EXT2_LINKLEN_IN_INODE
Definition: ext2fs.h:76
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
unsigned __int64 loff_t
Definition: types.h:80
CD_MCB Mcb
Definition: cdstruc.h:1022
#define STATUS_CANNOT_DELETE
Definition: shellext.h:66
static ext3_fsblk_t ext3_free_blocks_count(struct ext3_super_block *es)
Definition: ext2fs.h:1704
ULONG Ext2InodeType(PEXT2_MCB Mcb)
Definition: fileinfo.c:1901
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
ERESOURCE MainResource
Definition: ntfs.h:524
BOOLEAN Ext2RemoveMcb(PEXT2_VCB Vcb, PEXT2_MCB Mcb)
Definition: memory.c:1746
Status
Definition: gdiplustypes.h:24
#define SetFlag(_F, _SF)
Definition: ext2fs.h:187
_SEH2_END
Definition: create.c:4424
IN PVCB IN ULONG IN OUT PULONG IN BOOLEAN OUT PLARGE_MCB Mcb
Definition: fatprocs.h:334
_SEH2_FINALLY
Definition: create.c:4395
VOID Ext2ReleaseFcb(IN PEXT2_FCB Fcb)
Definition: memory.c:276
ERESOURCE PagingIoResource
Definition: ntfs.h:523
NTSTATUS Ext2RemoveEntry(IN PEXT2_IRP_CONTEXT IrpContext, IN PEXT2_VCB Vcb, IN PEXT2_FCB Dcb, IN PEXT2_MCB Mcb)
Definition: generic.c:1954
#define DEBUG(args)
Definition: rdesktop.h:129
#define _SEH2_LEAVE
Definition: filesup.c:20
_In_ PFCB Fcb
Definition: cdprocs.h:151
return STATUS_SUCCESS
Definition: btrfs.c:2966
_In_ PIO_STACK_LOCATION _Inout_ PFILE_OBJECT _Inout_ PVCB _Outptr_result_maybenull_ PDCB * Dcb
Definition: create.c:4157
BOOLEAN Ext2SaveInode(IN PEXT2_IRP_CONTEXT IrpContext, IN PEXT2_VCB Vcb, IN struct inode *Inode)
Definition: generic.c:548
ULONG Ext2LinuxTime(IN LARGE_INTEGER SysTime)
Definition: misc.c:51

Referenced by Ext2Cleanup(), Ext2CreateFile(), Ext2SetLinkInfo(), and Ext2SetRenameInfo().

◆ Ext2ExpandFile()

NTSTATUS Ext2ExpandFile ( PEXT2_IRP_CONTEXT  IrpContext,
PEXT2_VCB  Vcb,
PEXT2_MCB  Mcb,
PLARGE_INTEGER  Size 
)

Definition at line 1147 of file fileinfo.c.

1153 {
1155  ULONG Start = 0;
1156  ULONG End = 0;
1157 
1158  Start = (ULONG)((Mcb->Inode.i_size + BLOCK_SIZE - 1) >> BLOCK_BITS);
1159  End = (ULONG)((Size->QuadPart + BLOCK_SIZE - 1) >> BLOCK_BITS);
1160 
1161  /* it's a truncate operation, not expanding */
1162  if (Start >= End) {
1163  Size->QuadPart = ((LONGLONG) Start) << BLOCK_BITS;
1164  return STATUS_SUCCESS;
1165  }
1166 
1167  /* ignore special files */
1168  if (IsMcbSpecialFile(Mcb)) {
1170  }
1171 
1172  /* expandind file extents */
1173  if (INODE_HAS_EXTENT(&Mcb->Inode)) {
1174 
1175  status = Ext2ExpandExtent(IrpContext, Vcb, Mcb, Start, End, Size);
1176 
1177  } else {
1178 
1179  BOOLEAN do_expand;
1180 
1181 #if EXT2_PRE_ALLOCATION_SUPPORT
1182  do_expand = TRUE;
1183 #else
1184  do_expand = (IrpContext->MajorFunction == IRP_MJ_WRITE) ||
1186 #endif
1187  if (!do_expand)
1188  goto errorout;
1189 
1190  status = Ext2ExpandIndirect(IrpContext, Vcb, Mcb, Start, End, Size);
1191  }
1192 
1193 errorout:
1194  return status;
1195 }
#define TRUE
Definition: types.h:120
#define IsMcbDirectory(Mcb)
Definition: ext2fs.h:958
LONG NTSTATUS
Definition: precomp.h:26
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
unsigned char BOOLEAN
#define BLOCK_BITS
Definition: stream.h:22
int64_t LONGLONG
Definition: typedefs.h:66
#define BLOCK_SIZE
Definition: dlist.c:220
#define Vcb
Definition: cdprocs.h:1425
NTSTATUS Ext2ExpandIndirect(PEXT2_IRP_CONTEXT IrpContext, PEXT2_VCB Vcb, PEXT2_MCB Mcb, ULONG Start, ULONG End, PLARGE_INTEGER Size)
Definition: indirect.c:932
#define INODE_HAS_EXTENT(i)
Definition: ext4_ext.h:228
Definition: partlist.h:33
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
UCHAR MajorFunction
Definition: ext2fs.h:1047
IN PVCB IN ULONG IN OUT PULONG IN BOOLEAN OUT PLARGE_MCB Mcb
Definition: fatprocs.h:334
#define IsMcbSpecialFile(Mcb)
Definition: ext2fs.h:955
unsigned int ULONG
Definition: retypes.h:1
#define IRP_MJ_WRITE
Definition: rdpdr.c:47
return STATUS_SUCCESS
Definition: btrfs.c:2966
static SERVICE_STATUS status
Definition: service.c:31
NTSTATUS Ext2ExpandExtent(PEXT2_IRP_CONTEXT IrpContext, PEXT2_VCB Vcb, PEXT2_MCB Mcb, ULONG Start, ULONG End, PLARGE_INTEGER Size)
Definition: extents.c:151
Definition: ps.c:97

Referenced by Ext2CreateFile(), Ext2SetFileInformation(), Ext2SupersedeOrOverWriteFile(), Ext2WriteFile(), and ext3_append().

◆ Ext2InodeType()

ULONG Ext2InodeType ( PEXT2_MCB  Mcb)

Definition at line 1901 of file fileinfo.c.

1902 {
1903  if (IsMcbSymLink(Mcb)) {
1904  return EXT2_FT_SYMLINK;
1905  }
1906 
1907  if (IsMcbDirectory(Mcb)) {
1908  return EXT2_FT_DIR;
1909  }
1910 
1911  return EXT2_FT_REG_FILE;
1912 }
#define IsMcbDirectory(Mcb)
Definition: ext2fs.h:958
#define IsMcbSymLink(Mcb)
Definition: ext2fs.h:953
IN PVCB IN ULONG IN OUT PULONG IN BOOLEAN OUT PLARGE_MCB Mcb
Definition: fatprocs.h:334

Referenced by Ext2DeleteFile().

◆ Ext2IsFileRemovable()

NTSTATUS Ext2IsFileRemovable ( IN PEXT2_IRP_CONTEXT  IrpContext,
IN PEXT2_VCB  Vcb,
IN PEXT2_FCB  Fcb,
IN PEXT2_CCB  Ccb 
)

Definition at line 1234 of file fileinfo.c.

1240 {
1241  PEXT2_MCB Mcb = Fcb->Mcb;
1242 
1243  if (Mcb->Inode.i_ino == EXT2_ROOT_INO) {
1244  return STATUS_CANNOT_DELETE;
1245  }
1246 
1247  if (IsMcbDirectory(Mcb)) {
1248  if (!Ext2IsDirectoryEmpty(IrpContext, Vcb, Mcb)) {
1250  }
1251  }
1252 
1253  if (!MmFlushImageSection(&Fcb->SectionObject,
1254  MmFlushForDelete )) {
1255  return STATUS_CANNOT_DELETE;
1256  }
1257 
1258  if (IsMcbDirectory(Mcb)) {
1260  Vcb->NotifySync,
1261  &Vcb->NotifyList,
1262  Ccb,
1263  NULL,
1264  FALSE,
1265  FALSE,
1266  0,
1267  NULL,
1268  NULL,
1269  NULL
1270  );
1271  }
1272 
1273  return STATUS_SUCCESS;
1274 }
#define IsMcbDirectory(Mcb)
Definition: ext2fs.h:958
VOID NTAPI FsRtlNotifyFullChangeDirectory(IN PNOTIFY_SYNC NotifySync, IN PLIST_ENTRY NotifyList, IN PVOID FsContext, IN PSTRING FullDirectoryName, IN BOOLEAN WatchTree, IN BOOLEAN IgnoreBuffer, IN ULONG CompletionFilter, IN PIRP NotifyIrp, IN PCHECK_FOR_TRAVERSE_ACCESS TraverseCallback OPTIONAL, IN PSECURITY_SUBJECT_CONTEXT SubjectContext OPTIONAL)
Definition: notify.c:1458
#define STATUS_DIRECTORY_NOT_EMPTY
Definition: udferr_usr.h:167
BOOLEAN Ext2IsDirectoryEmpty(IN PEXT2_IRP_CONTEXT IrpContext, IN PEXT2_VCB Vcb, IN PEXT2_MCB Mcb)
smooth NULL
Definition: ftsmooth.c:416
#define EXT2_ROOT_INO
Definition: ext2.h:177
BOOLEAN NTAPI MmFlushImageSection(IN PSECTION_OBJECT_POINTERS SectionObjectPointer, IN MMFLUSH_TYPE FlushType)
Definition: section.c:4798
#define Vcb
Definition: cdprocs.h:1425
CD_MCB Mcb
Definition: cdstruc.h:1022
#define STATUS_CANNOT_DELETE
Definition: shellext.h:66
_Inout_ PFILE_OBJECT _In_ TYPE_OF_OPEN PFCB _In_opt_ PCCB Ccb
Definition: cdprocs.h:593
IN PVCB IN ULONG IN OUT PULONG IN BOOLEAN OUT PLARGE_MCB Mcb
Definition: fatprocs.h:334
_In_ PFCB Fcb
Definition: cdprocs.h:151
return STATUS_SUCCESS
Definition: btrfs.c:2966

Referenced by Ext2CreateFile(), Ext2SetDispositionInfo(), Ext2SetLinkInfo(), and Ext2SetRenameInfo().

◆ Ext2IterateAllEa()

static int Ext2IterateAllEa ( struct ext4_xattr_ref xattr_ref,
struct ext4_xattr_item item,
BOOL  is_last 
)
static

Definition at line 33 of file fileinfo.c.

34 {
35  PULONG EaSize = xattr_ref->iter_arg;
36  ULONG EaEntrySize = 4 + 1 + 1 + 2 + item->name_len + 1 + item->data_size;
37 
38  *EaSize += EaEntrySize - 4;
40 }
static ATOM item
Definition: dde.c:856
#define EXT4_XATTR_ITERATE_CONT
Definition: ext4_xattr.h:162
void * iter_arg
Definition: ext4_xattr.h:155
unsigned int * PULONG
Definition: retypes.h:1
unsigned int ULONG
Definition: retypes.h:1

Referenced by Ext2QueryFileInformation().

◆ Ext2QueryFileInformation()

NTSTATUS Ext2QueryFileInformation ( IN PEXT2_IRP_CONTEXT  IrpContext)

Definition at line 43 of file fileinfo.c.

44 {
48  PEXT2_VCB Vcb = NULL;
49  PEXT2_FCB Fcb = NULL;
50  PEXT2_MCB Mcb = NULL;
51  PEXT2_CCB Ccb = NULL;
52  PIRP Irp = NULL;
53  PIO_STACK_LOCATION IoStackLocation;
55  ULONG Length;
56  PVOID Buffer;
57  BOOLEAN FcbResourceAcquired = FALSE;
58 
59  _SEH2_TRY {
60 
61  ASSERT(IrpContext != NULL);
62  ASSERT((IrpContext->Identifier.Type == EXT2ICX) &&
63  (IrpContext->Identifier.Size == sizeof(EXT2_IRP_CONTEXT)));
64 
65  DeviceObject = IrpContext->DeviceObject;
66 
67  //
68  // This request is not allowed on the main device object
69  //
73  }
74 
75  FileObject = IrpContext->FileObject;
76  Fcb = (PEXT2_FCB) FileObject->FsContext;
77  if (Fcb == NULL) {
80  }
81 
82  //
83  // This request is not allowed on volumes
84  //
85  if (Fcb->Identifier.Type == EXT2VCB) {
88  }
89 
90  if (!((Fcb->Identifier.Type == EXT2FCB) &&
91  (Fcb->Identifier.Size == sizeof(EXT2_FCB)))) {
94  }
95 
96  Vcb = Fcb->Vcb;
97 
98  {
100  &Fcb->MainResource,
101  IsFlagOn(IrpContext->Flags, IRP_CONTEXT_FLAG_WAIT)
102  )) {
103 
105  _SEH2_LEAVE;
106  }
107 
108  FcbResourceAcquired = TRUE;
109  }
110 
111  Ccb = (PEXT2_CCB) FileObject->FsContext2;
112  ASSERT(Ccb != NULL);
113  ASSERT((Ccb->Identifier.Type == EXT2CCB) &&
114  (Ccb->Identifier.Size == sizeof(EXT2_CCB)));
115  Mcb = Ccb->SymLink;
116  if (!Mcb)
117  Mcb = Fcb->Mcb;
118 
119  Irp = IrpContext->Irp;
120  IoStackLocation = IoGetCurrentIrpStackLocation(Irp);
122  IoStackLocation->Parameters.QueryFile.FileInformationClass;
123 
124  Length = IoStackLocation->Parameters.QueryFile.Length;
125  Buffer = Irp->AssociatedIrp.SystemBuffer;
127 
128  switch (FileInformationClass) {
129 
131  {
133 
134  if (Length < sizeof(FILE_BASIC_INFORMATION)) {
136  _SEH2_LEAVE;
137  }
138 
140 
141  FileBasicInformation->CreationTime = Mcb->CreationTime;
142  FileBasicInformation->LastAccessTime = Mcb->LastAccessTime;
143  FileBasicInformation->LastWriteTime = Mcb->LastWriteTime;
144  FileBasicInformation->ChangeTime = Mcb->ChangeTime;
145 
146  FileBasicInformation->FileAttributes = Mcb->FileAttr;
147  if (IsLinkInvalid(Mcb)) {
149  }
150  if (FileBasicInformation->FileAttributes == 0) {
152  }
153 
154  Irp->IoStatus.Information = sizeof(FILE_BASIC_INFORMATION);
156  }
157  break;
158 
160  {
162 
163  if (Length < sizeof(FILE_STANDARD_INFORMATION)) {
165  _SEH2_LEAVE;
166  }
167 
169 
170  FSI->NumberOfLinks = Mcb->Inode.i_nlink;
171 
172  if (IsVcbReadOnly(Fcb->Vcb))
173  FSI->DeletePending = FALSE;
174  else
175  FSI->DeletePending = IsFlagOn(Fcb->Flags, FCB_DELETE_PENDING);
176 
177  if (IsLinkInvalid(Mcb)) {
178  FSI->Directory = FALSE;
179  FSI->AllocationSize.QuadPart = 0;
180  FSI->EndOfFile.QuadPart = 0;
181  } else if (IsMcbDirectory(Mcb)) {
182  FSI->Directory = TRUE;
183  FSI->AllocationSize.QuadPart = 0;
184  FSI->EndOfFile.QuadPart = 0;
185  } else {
186  FSI->Directory = FALSE;
187  FSI->AllocationSize = Fcb->Header.AllocationSize;
188  FSI->EndOfFile = Fcb->Header.FileSize;
189  }
190 
191  Irp->IoStatus.Information = sizeof(FILE_STANDARD_INFORMATION);
193  }
194  break;
195 
197  {
199 
200  if (Length < sizeof(FILE_INTERNAL_INFORMATION)) {
202  _SEH2_LEAVE;
203  }
204 
206 
207  /* we use the inode number as the internal index */
208  FileInternalInformation->IndexNumber.QuadPart = (LONGLONG)Mcb->Inode.i_ino;
209 
210  Irp->IoStatus.Information = sizeof(FILE_INTERNAL_INFORMATION);
212  }
213  break;
214 
215 
216  case FileEaInformation:
217  {
218  struct ext4_xattr_ref xattr_ref;
220 
221  if (Length < sizeof(FILE_EA_INFORMATION)) {
223  _SEH2_LEAVE;
224  }
225 
227  FileEaInformation->EaSize = 0;
228 
230  if (!NT_SUCCESS(Status))
231  _SEH2_LEAVE;
232 
233  xattr_ref.iter_arg = &FileEaInformation->EaSize;
235  ext4_fs_put_xattr_ref(&xattr_ref);
236 
237  if (FileEaInformation->EaSize)
238  FileEaInformation->EaSize += 4;
239 
240  Irp->IoStatus.Information = sizeof(FILE_EA_INFORMATION);
242  }
243  break;
244 
245  case FileNameInformation:
246  {
248  ULONG BytesToCopy = 0;
249 
251  Mcb->FullName.Length) {
254  } else {
255  BytesToCopy = Mcb->FullName.Length;
257  }
258 
260  FileNameInformation->FileNameLength = Mcb->FullName.Length;
261 
263  FileNameInformation->FileName,
264  Mcb->FullName.Buffer,
265  BytesToCopy );
266 
267  Irp->IoStatus.Information = BytesToCopy +
269  }
270  break;
271 
273  {
275 
276  if (Length < sizeof(FILE_POSITION_INFORMATION)) {
278  _SEH2_LEAVE;
279  }
280 
282  FilePositionInformation->CurrentByteOffset =
283  FileObject->CurrentByteOffset;
284 
285  Irp->IoStatus.Information = sizeof(FILE_POSITION_INFORMATION);
287  }
288  break;
289 
290  case FileAllInformation:
291  {
299 
300  if (Length < sizeof(FILE_ALL_INFORMATION)) {
302  _SEH2_LEAVE;
303  }
304 
306 
308  &FileAllInformation->BasicInformation;
309 
310  FSI =
311  &FileAllInformation->StandardInformation;
312 
314  &FileAllInformation->InternalInformation;
315 
317  &FileAllInformation->EaInformation;
318 
320  &FileAllInformation->PositionInformation;
321 
323  &FileAllInformation->NameInformation;
324 
325  FileBasicInformation->CreationTime = Mcb->CreationTime;
326  FileBasicInformation->LastAccessTime = Mcb->LastAccessTime;
327  FileBasicInformation->LastWriteTime = Mcb->LastWriteTime;
328  FileBasicInformation->ChangeTime = Mcb->ChangeTime;
329 
330  FileBasicInformation->FileAttributes = Mcb->FileAttr;
331  if (IsMcbSymLink(Mcb) && IsFileDeleted(Mcb->Target)) {
333  }
334  if (FileBasicInformation->FileAttributes == 0) {
336  }
337 
338  FSI->NumberOfLinks = Mcb->Inode.i_nlink;
339 
340  if (IsVcbReadOnly(Fcb->Vcb))
341  FSI->DeletePending = FALSE;
342  else
343  FSI->DeletePending = IsFlagOn(Fcb->Flags, FCB_DELETE_PENDING);
344 
345  if (IsLinkInvalid(Mcb)) {
346  FSI->Directory = FALSE;
347  FSI->AllocationSize.QuadPart = 0;
348  FSI->EndOfFile.QuadPart = 0;
349  } else if (IsDirectory(Fcb)) {
350  FSI->Directory = TRUE;
351  FSI->AllocationSize.QuadPart = 0;
352  FSI->EndOfFile.QuadPart = 0;
353  } else {
354  FSI->Directory = FALSE;
355  FSI->AllocationSize = Fcb->Header.AllocationSize;
356  FSI->EndOfFile = Fcb->Header.FileSize;
357  }
358 
359  // The "inode number"
360  FileInternalInformation->IndexNumber.QuadPart = (LONGLONG)Mcb->Inode.i_ino;
361 
362  // Romfs doesn't have any extended attributes
363  FileEaInformation->EaSize = 0;
364 
365  FilePositionInformation->CurrentByteOffset =
366  FileObject->CurrentByteOffset;
367 
368  FileNameInformation->FileNameLength = Mcb->ShortName.Length;
369 
370  if (Length < sizeof(FILE_ALL_INFORMATION) +
371  Mcb->ShortName.Length - sizeof(WCHAR)) {
372  Irp->IoStatus.Information = sizeof(FILE_ALL_INFORMATION);
375  FileNameInformation->FileName,
376  Mcb->ShortName.Buffer,
378  NameInformation.FileName)
379  );
380  _SEH2_LEAVE;
381  }
382 
384  FileNameInformation->FileName,
385  Mcb->ShortName.Buffer,
386  Mcb->ShortName.Length
387  );
388 
389  Irp->IoStatus.Information = sizeof(FILE_ALL_INFORMATION) +
390  Mcb->ShortName.Length - sizeof(WCHAR);
391 #if 0
392  sizeof(FILE_ACCESS_INFORMATION) -
393  sizeof(FILE_MODE_INFORMATION) -
395 #endif
396 
398  }
399  break;
400 
401  /*
402  case FileAlternateNameInformation:
403  {
404  // TODO: Handle FileAlternateNameInformation
405 
406  // Here we would like to use RtlGenerate8dot3Name but I don't
407  // know how to use the argument PGENERATE_NAME_CONTEXT
408  }
409  */
410 
412  {
414 
415  if (Length < sizeof(FILE_NETWORK_OPEN_INFORMATION)) {
417  _SEH2_LEAVE;
418  }
419 
421 
422  PFNOI->FileAttributes = Mcb->FileAttr;
423  if (IsLinkInvalid(Mcb)) {
425  PFNOI->AllocationSize.QuadPart = 0;
426  PFNOI->EndOfFile.QuadPart = 0;
427  } else if (IsDirectory(Fcb)) {
428  PFNOI->AllocationSize.QuadPart = 0;
429  PFNOI->EndOfFile.QuadPart = 0;
430  } else {
431  PFNOI->AllocationSize = Fcb->Header.AllocationSize;
432  PFNOI->EndOfFile = Fcb->Header.FileSize;
433  }
434 
435  if (PFNOI->FileAttributes == 0) {
437  }
438 
439  PFNOI->CreationTime = Mcb->CreationTime;
440  PFNOI->LastAccessTime = Mcb->LastAccessTime;
441  PFNOI->LastWriteTime = Mcb->LastWriteTime;
442  PFNOI->ChangeTime = Mcb->ChangeTime;
443 
444 
445  Irp->IoStatus.Information =
448  }
449  break;
450 
451 #if (_WIN32_WINNT >= 0x0500)
452 
454  {
456 
457  if (Length < sizeof(FILE_ATTRIBUTE_TAG_INFORMATION)) {
459  _SEH2_LEAVE;
460  }
461 
463  FATI->FileAttributes = Mcb->FileAttr;
464  if (IsLinkInvalid(Mcb)) {
466  }
467  if (FATI->FileAttributes == 0) {
469  }
471  Irp->IoStatus.Information = sizeof(FILE_ATTRIBUTE_TAG_INFORMATION);
473  }
474  break;
475 #endif // (_WIN32_WINNT >= 0x0500)
476 
479  break;
480 
481  default:
482  DEBUG(DL_WRN, ( "Ext2QueryInformation: invalid class: %d\n",
484  Status = STATUS_INVALID_PARAMETER; /* STATUS_INVALID_INFO_CLASS; */
485  break;
486  }
487 
488  } _SEH2_FINALLY {
489 
490  if (FcbResourceAcquired) {
492  }
493 
495  if (Status == STATUS_PENDING ||
498  } else {
500  }
501  }
502  } _SEH2_END;
503 
504  return Status;
505 }
struct _FILE_EA_INFORMATION * PFILE_EA_INFORMATION
NTSTATUS Ext2WinntError(int rc)
Definition: misc.c:410
struct _EXT2_FCB * PEXT2_FCB
struct _FILE_INTERNAL_INFORMATION * PFILE_INTERNAL_INFORMATION
struct _FILE_BASIC_INFORMATION * PFILE_BASIC_INFORMATION
#define TRUE
Definition: types.h:120
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define IRP_CONTEXT_FLAG_WAIT
Definition: cdstruc.h:1221
#define IsMcbDirectory(Mcb)
Definition: ext2fs.h:958
FSRTL_ADVANCED_FCB_HEADER Header
Definition: cdstruc.h:931
_In_ PIRP Irp
Definition: csq.h:116
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
struct _FILE_ALL_INFORMATION FILE_ALL_INFORMATION
LONG NTSTATUS
Definition: precomp.h:26
PEXT2_IRP_CONTEXT IrpContext
Definition: ext4_xattr.h:141
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
struct _FILE_EA_INFORMATION FILE_EA_INFORMATION
static OUT PIO_STATUS_BLOCK OUT PVOID IN ULONG IN FILE_INFORMATION_CLASS FileInformationClass
Definition: pipe.c:75
struct _FILE_ACCESS_INFORMATION FILE_ACCESS_INFORMATION
struct _FILE_POSITION_INFORMATION FILE_POSITION_INFORMATION
#define FCB_DELETE_PENDING
Definition: ext2fs.h:879
_In_ UINT _In_ UINT BytesToCopy
Definition: ndis.h:3167
struct _FILE_NETWORK_OPEN_INFORMATION FILE_NETWORK_OPEN_INFORMATION
#define IO_REPARSE_TAG_RESERVED_ZERO
Definition: iotypes.h:6860
_SEH2_TRY
Definition: create.c:4250
NTFSIDENTIFIER Identifier
Definition: ntfs.h:511
NTSTATUS Ext2QueueRequest(IN PEXT2_IRP_CONTEXT IrpContext)
Definition: dispatch.c:150
#define IsFlagOn(a, b)
Definition: ext2fs.h:177
static int Ext2IterateAllEa(struct ext4_xattr_ref *xattr_ref, struct ext4_xattr_item *item, BOOL is_last)
Definition: fileinfo.c:33
#define IsLinkInvalid(Mcb)
Definition: ext2fs.h:961
unsigned char BOOLEAN
#define IsFileDeleted(Mcb)
Definition: ext2fs.h:959
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
#define FILE_ATTRIBUTE_DIRECTORY
Definition: nt_native.h:705
int ext4_fs_get_xattr_ref(PEXT2_IRP_CONTEXT IrpContext, PEXT2_VCB fs, PEXT2_MCB inode_ref, struct ext4_xattr_ref *ref)
Definition: ext4_xattr.c:1105
int64_t LONGLONG
Definition: typedefs.h:66
enum _FILE_INFORMATION_CLASS FILE_INFORMATION_CLASS
Definition: directory.c:44
if(!(yy_init))
Definition: macro.lex.yy.c:714
__wchar_t WCHAR
Definition: xmlstorage.h:180
int ext4_fs_put_xattr_ref(struct ext4_xattr_ref *ref)
Definition: ext4_xattr.c:1176
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
#define IsVcbReadOnly(Vcb)
Definition: ext2fs.h:805
struct _FILE_ALL_INFORMATION * PFILE_ALL_INFORMATION
#define IsMcbSymLink(Mcb)
Definition: ext2fs.h:953
#define Vcb
Definition: cdprocs.h:1425
struct _FILE_ALIGNMENT_INFORMATION FILE_ALIGNMENT_INFORMATION
void ext4_fs_xattr_iterate(struct ext4_xattr_ref *ref, int(*iter)(struct ext4_xattr_ref *ref, struct ext4_xattr_item *item, BOOL is_last))
Definition: ext4_xattr.c:978
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
* PFILE_OBJECT
Definition: iotypes.h:1955
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
ULONG Flags
Definition: ntfs.h:532
CD_MCB Mcb
Definition: cdstruc.h:1022
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:126
NTSTATUS Ext2CompleteIrpContext(IN PEXT2_IRP_CONTEXT IrpContext, IN NTSTATUS Status)
Definition: read.c:32
_Must_inspect_result_ _In_ PFLT_INSTANCE _Out_ PBOOLEAN IsDirectory
Definition: fltkernel.h:1139
ULONG Type
Definition: ntfs.h:95
#define FILE_STANDARD_INFORMATION
Definition: disk.h:54
_Inout_ PFILE_OBJECT _In_ TYPE_OF_OPEN PFCB _In_opt_ PCCB Ccb
Definition: cdprocs.h:593
struct _FILE_STANDARD_INFORMATION * PFILE_STANDARD_INFORMATION
Definition: bidi.c:98
ERESOURCE MainResource
Definition: ntfs.h:524
struct _FILE_NAME_INFORMATION * PFILE_NAME_INFORMATION
ClearFlag(Dirent->Flags, DIRENT_FLAG_NOT_PERSISTENT)
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
_SEH2_END
Definition: create.c:4424
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:61
IN PVCB IN ULONG IN OUT PULONG IN BOOLEAN OUT PLARGE_MCB Mcb
Definition: fatprocs.h:334
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:254
_SEH2_FINALLY
Definition: create.c:4395
struct _FILE_NETWORK_OPEN_INFORMATION * PFILE_NETWORK_OPEN_INFORMATION
#define DL_WRN
Definition: ext2fs.h:1410
BOOLEAN NTAPI ExAcquireResourceSharedLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:885
#define FileStandardInformation
Definition: propsheet.cpp:61
struct _FILE_ATTRIBUTE_TAG_INFORMATION * PFILE_ATTRIBUTE_TAG_INFORMATION
struct _FILE_POSITION_INFORMATION * PFILE_POSITION_INFORMATION
#define IsExt2FsDevice(DO)
Definition: ext2fs.h:607
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
PVCB Vcb
Definition: cdstruc.h:939
#define DEBUG(args)
Definition: rdesktop.h:129
#define _SEH2_LEAVE
Definition: filesup.c:20
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
_In_ PFCB Fcb
Definition: cdprocs.h:151
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
return STATUS_SUCCESS
Definition: btrfs.c:2966
struct _EXT2_CCB * PEXT2_CCB
struct _FILE_ATTRIBUTE_TAG_INFORMATION FILE_ATTRIBUTE_TAG_INFORMATION
ULONG Size
Definition: ntfs.h:96
LONGLONG QuadPart
Definition: typedefs.h:112
#define STATUS_CANT_WAIT
Definition: ntstatus.h:438
#define FILE_BASIC_INFORMATION
Definition: disk.h:53
BOOLEAN ExceptionInProgress
Definition: ext2fs.h:1069

Referenced by Ext2DispatchRequest().

◆ Ext2SetDispositionInfo()

NTSTATUS Ext2SetDispositionInfo ( PEXT2_IRP_CONTEXT  IrpContext,
PEXT2_VCB  Vcb,
PEXT2_FCB  Fcb,
PEXT2_CCB  Ccb,
BOOLEAN  bDelete 
)

Definition at line 1277 of file fileinfo.c.

1284 {
1285  PIRP Irp = IrpContext->Irp;
1288  PEXT2_MCB Mcb = Fcb->Mcb;
1289 
1291 
1292  DEBUG(DL_INF, ( "Ext2SetDispositionInfo: bDelete=%x\n", bDelete));
1293 
1294  if (bDelete) {
1295 
1296  DEBUG(DL_INF, ( "Ext2SetDispositionInformation: Removing %wZ.\n",
1297  &Mcb->FullName));
1298 
1299  if (Ccb->SymLink || IsInodeSymLink(&Mcb->Inode)) {
1300  /* always allow deleting on symlinks */
1301  } else {
1303  }
1304 
1305  if (NT_SUCCESS(status)) {
1307  IrpSp->FileObject->DeletePending = TRUE;
1308  }
1309 
1310  } else {
1311 
1313  IrpSp->FileObject->DeletePending = FALSE;
1314  }
1315 
1316  return status;
1317 }
#define IsInodeSymLink(I)
Definition: ext2fs.h:281
#define TRUE
Definition: types.h:120
_In_ PIRP Irp
Definition: csq.h:116
LONG NTSTATUS
Definition: precomp.h:26
PIRP Irp
Definition: ext2fs.h:1041
PEXT2_IRP_CONTEXT IrpContext
Definition: ext4_xattr.h:141
#define FCB_DELETE_PENDING
Definition: ext2fs.h:879
#define ClearLongFlag(_F, _SF)
Definition: ext2fs.h:254
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define DL_INF
Definition: ext2fs.h:1399
#define Vcb
Definition: cdprocs.h:1425
ULONG Flags
Definition: ntfs.h:532
CD_MCB Mcb
Definition: cdstruc.h:1022
NTSTATUS Ext2IsFileRemovable(IN PEXT2_IRP_CONTEXT IrpContext, IN PEXT2_VCB Vcb, IN PEXT2_FCB Fcb, IN PEXT2_CCB Ccb)
Definition: fileinfo.c:1234
_Inout_ PFILE_OBJECT _In_ TYPE_OF_OPEN PFCB _In_opt_ PCCB Ccb
Definition: cdprocs.h:593
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
PFILE_OBJECT FileObject
Definition: iotypes.h:2813
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
IN PVCB IN ULONG IN OUT PULONG IN BOOLEAN OUT PLARGE_MCB Mcb
Definition: fatprocs.h:334
#define SetLongFlag(_F, _SF)
Definition: ext2fs.h:253
#define DEBUG(args)
Definition: rdesktop.h:129
_In_ PFCB Fcb
Definition: cdprocs.h:151
return STATUS_SUCCESS
Definition: btrfs.c:2966
static SERVICE_STATUS status
Definition: service.c:31
Definition: ps.c:97

Referenced by Ext2SetFileInformation().

◆ Ext2SetFileInformation()

NTSTATUS Ext2SetFileInformation ( IN PEXT2_IRP_CONTEXT  IrpContext)

Definition at line 509 of file fileinfo.c.

510 {
513  PEXT2_VCB Vcb = NULL;
515  PEXT2_FCB Fcb = NULL;
516  PEXT2_CCB Ccb = NULL;
517  PEXT2_MCB Mcb = NULL;
518  PIRP Irp = NULL;
519  PIO_STACK_LOCATION IoStackLocation = NULL;
521 
522  ULONG NotifyFilter = 0;
523 
524  ULONG Length;
525  PVOID Buffer;
526 
527  BOOLEAN FcbMainResourceAcquired = FALSE;
528  BOOLEAN FcbPagingIoResourceAcquired = FALSE;
529 
530  _SEH2_TRY {
531 
532  ASSERT(IrpContext != NULL);
533 
537 
538  //
539  // This request is not allowed on the main device object
540  //
543  _SEH2_LEAVE;
544  }
545 
546  /* check io stack location of irp stack */
547  Irp = IrpContext->Irp;
548  IoStackLocation = IoGetCurrentIrpStackLocation(Irp);
550  IoStackLocation->Parameters.SetFile.FileInformationClass;
551  Length = IoStackLocation->Parameters.SetFile.Length;
552  Buffer = Irp->AssociatedIrp.SystemBuffer;
553 
554  /* check Vcb */
556  ASSERT(Vcb != NULL);
557  ASSERT((Vcb->Identifier.Type == EXT2VCB) &&
558  (Vcb->Identifier.Size == sizeof(EXT2_VCB)));
559  if (!IsMounted(Vcb)) {
561  _SEH2_LEAVE;
562  }
563 
564  if (FlagOn(Vcb->Flags, VCB_VOLUME_LOCKED)) {
566  _SEH2_LEAVE;
567  }
568 
570  Fcb = (PEXT2_FCB) FileObject->FsContext;
571 
572  // This request is issued to volumes, just return success
573  if (Fcb == NULL || Fcb->Identifier.Type == EXT2VCB) {
575  _SEH2_LEAVE;
576  }
577  ASSERT((Fcb->Identifier.Type == EXT2FCB) &&
578  (Fcb->Identifier.Size == sizeof(EXT2_FCB)));
579 
580  if (IsFlagOn(Fcb->Mcb->Flags, MCB_FILE_DELETED)) {
582  _SEH2_LEAVE;
583  }
584 
585  Ccb = (PEXT2_CCB) FileObject->FsContext2;
586  ASSERT(Ccb != NULL);
587  ASSERT((Ccb->Identifier.Type == EXT2CCB) &&
588  (Ccb->Identifier.Size == sizeof(EXT2_CCB)));
589  Mcb = Ccb->SymLink;
590  if (Mcb) {
591  if (IsFlagOn(Mcb->Flags, MCB_FILE_DELETED)) {
593  _SEH2_LEAVE;
594  }
595  } else {
596  Mcb = Fcb->Mcb;
597  }
598 
600  if (IsVcbReadOnly(Vcb)) {
602  _SEH2_LEAVE;
603  }
606  _SEH2_LEAVE;
607  }
608  }
609 
610  if ( !IsDirectory(Fcb) && !FlagOn(Fcb->Flags, FCB_PAGE_FILE) &&
614 
615  Status = FsRtlCheckOplock( &Fcb->Oplock,
616  Irp,
617  IrpContext,
618  NULL,
619  NULL );
620 
621  if (Status != STATUS_SUCCESS) {
622  _SEH2_LEAVE;
623  }
624 
625  //
626  // Set the flag indicating if Fast I/O is possible
627  //
628 
629  Fcb->Header.IsFastIoPossible = Ext2IsFastIoPossible(Fcb);
630  }
631 
632  /* for renaming or set link, we must not grab any Fcb locks,
633  and later we will get Dcb or Fcb resources exclusively. */
634  if (!IsFlagOn(Fcb->Flags, FCB_PAGE_FILE) &&
637 
639  &Fcb->MainResource,
642  _SEH2_LEAVE;
643  }
644 
645  FcbMainResourceAcquired = TRUE;
646 
650 
655  DbgBreak();
656  _SEH2_LEAVE;
657  }
658  FcbPagingIoResourceAcquired = TRUE;
659  }
660  }
661 
662  switch (FileInformationClass) {
663 
665  {
667  struct inode *Inode = &Mcb->Inode;
668 
669  if (FBI->CreationTime.QuadPart != 0 && FBI->CreationTime.QuadPart != -1) {
670  Inode->i_ctime = Ext2LinuxTime(FBI->CreationTime);
671  Mcb->CreationTime = Ext2NtTime(Inode->i_ctime);
673  }
674 
675  if (FBI->LastAccessTime.QuadPart != 0 && FBI->LastAccessTime.QuadPart != -1) {
676  Inode->i_atime = Ext2LinuxTime(FBI->LastAccessTime);
677  Mcb->LastAccessTime = Ext2NtTime(Inode->i_atime);
679  }
680 
681  if (FBI->LastWriteTime.QuadPart != 0 && FBI->LastWriteTime.QuadPart != -1) {
682  Inode->i_mtime = Ext2LinuxTime(FBI->LastWriteTime);
683  Mcb->LastWriteTime = Ext2NtTime(Inode->i_mtime);
686  }
687 
688  if (FBI->ChangeTime.QuadPart !=0 && FBI->ChangeTime.QuadPart != -1) {
689  Mcb->ChangeTime = FBI->ChangeTime;
690  }
691 
692  if (FBI->FileAttributes != 0) {
693 
694  BOOLEAN bIsDirectory = IsDirectory(Fcb);
696 
699  } else {
701  }
702 
705  } else {
707  }
708 
709  Mcb->FileAttr = FBI->FileAttributes;
710  if (bIsDirectory) {
712  ClearFlag(Mcb->FileAttr, FILE_ATTRIBUTE_NORMAL);
713  }
714  }
715 
716  if (NotifyFilter != 0) {
717  if (Ext2SaveInode(IrpContext, Vcb, Inode)) {
719  }
720  }
721 
724  }
725 
726  break;
727 
729  {
732 
735  _SEH2_LEAVE;
736  } else {
738  }
739 
740  /* set Mcb to it's target */
741  if (IsMcbSymLink(Mcb)) {
742  ASSERT(Fcb->Mcb == Mcb->Target);
743  }
744  Mcb = Fcb->Mcb;
745 
746  /* get user specified allocationsize aligned with BLOCK_SIZE */
750 
751  if (AllocationSize.QuadPart > Fcb->Header.AllocationSize.QuadPart) {
752 
753  Status = Ext2ExpandFile(IrpContext, Vcb, Mcb, &AllocationSize);
754  Fcb->Header.AllocationSize = AllocationSize;
757 
758  } else if (AllocationSize.QuadPart < Fcb->Header.AllocationSize.QuadPart) {
759 
760  if (MmCanFileBeTruncated(&(Fcb->SectionObject), &AllocationSize)) {
761 
762  /* truncate file blocks */
763  Status = Ext2TruncateFile(IrpContext, Vcb, Mcb, &AllocationSize);
764 
765  if (NT_SUCCESS(Status)) {
767  }
768 
770  Fcb->Header.AllocationSize.QuadPart = AllocationSize.QuadPart;
771  if (Mcb->Inode.i_size > (loff_t)AllocationSize.QuadPart) {
772  Mcb->Inode.i_size = AllocationSize.QuadPart;
773  }
774  Fcb->Header.FileSize.QuadPart = Mcb->Inode.i_size;
775  if (Fcb->Header.ValidDataLength.QuadPart > Fcb->Header.FileSize.QuadPart) {
776  Fcb->Header.ValidDataLength.QuadPart = Fcb->Header.FileSize.QuadPart;
777  }
778 
779  } else {
780 
782  DbgBreak();
783  _SEH2_LEAVE;
784  }
785  }
786 
787  if (NotifyFilter) {
788 
791  Ext2SaveInode(IrpContext, Vcb, &Mcb->Inode);
792  if (CcIsFileCached(FileObject)) {
793  CcSetFileSizes(FileObject, (PCC_FILE_SIZES)(&(Fcb->Header.AllocationSize)));
794  }
795  }
796 
797  DEBUG(DL_IO, ("Ext2SetInformation: %wZ NewSize=%I64xh AllocationSize=%I64xh "
798  "FileSize=%I64xh VDL=%I64xh i_size=%I64xh status = %xh\n",
799  &Fcb->Mcb->ShortName, AllocationSize.QuadPart,
800  Fcb->Header.AllocationSize.QuadPart,
801  Fcb->Header.FileSize.QuadPart, Fcb->Header.ValidDataLength.QuadPart,
802  Mcb->Inode.i_size, Status));
803  }
804 
805  break;
806 
808  {
810  LARGE_INTEGER NewSize, OldSize, EndOfFile;
811 
814  _SEH2_LEAVE;
815  } else {
817  }
818 
819  /* set Mcb to it's target */
820  if (IsMcbSymLink(Mcb)) {
821  ASSERT(Fcb->Mcb == Mcb->Target);
822  }
823  Mcb = Fcb->Mcb;
824 
825  OldSize = Fcb->Header.AllocationSize;
826  EndOfFile = FEOFI->EndOfFile;
827 
828  if (IoStackLocation->Parameters.SetFile.AdvanceOnly) {
829 
831  _SEH2_LEAVE;
832  }
833 
834  if (EndOfFile.QuadPart > Fcb->Header.FileSize.QuadPart) {
835  EndOfFile.QuadPart = Fcb->Header.FileSize.QuadPart;
836  }
837 
838  if (EndOfFile.QuadPart > Fcb->Header.ValidDataLength.QuadPart) {
839  Fcb->Header.ValidDataLength.QuadPart = EndOfFile.QuadPart;
841  }
842 
843  _SEH2_LEAVE;
844  }
845 
846  NewSize.QuadPart = CEILING_ALIGNED(ULONGLONG,
847  EndOfFile.QuadPart, BLOCK_SIZE);
848 
849  if (NewSize.QuadPart > OldSize.QuadPart) {
850 
851  Fcb->Header.AllocationSize = NewSize;
853  IrpContext,
854  Vcb,
855  Mcb,
856  &(Fcb->Header.AllocationSize)
857  );
860 
861 
862  } else if (NewSize.QuadPart == OldSize.QuadPart) {
863 
864  /* we are luck ;) */
866 
867  } else {
868 
869  /* don't truncate file data since it's still being written */
871 
873 
874  } else {
875 
876  if (!MmCanFileBeTruncated(&(Fcb->SectionObject), &NewSize)) {
878  DbgBreak();
879  _SEH2_LEAVE;
880  }
881 
882  /* truncate file blocks */
883  Status = Ext2TruncateFile(IrpContext, Vcb, Mcb, &NewSize);
884 
885  /* restore original file size */
886  if (NT_SUCCESS(Status)) {
888  }
889 
890  /* update file allocateion size */
891  Fcb->Header.AllocationSize.QuadPart = NewSize.QuadPart;
892 
893  ASSERT((loff_t)NewSize.QuadPart >= Mcb->Inode.i_size);
894  if ((loff_t)Fcb->Header.FileSize.QuadPart < Mcb->Inode.i_size) {
895  Fcb->Header.FileSize.QuadPart = Mcb->Inode.i_size;
896  }
897  if (Fcb->Header.ValidDataLength.QuadPart > Fcb->Header.FileSize.QuadPart) {
898  Fcb->Header.ValidDataLength.QuadPart = Fcb->Header.FileSize.QuadPart;
899  }
900 
903  }
904 
906  }
907 
908  if (NT_SUCCESS(Status)) {
909 
910  Fcb->Header.FileSize.QuadPart = Mcb->Inode.i_size = EndOfFile.QuadPart;
911  if (CcIsFileCached(FileObject)) {
912  CcSetFileSizes(FileObject, (PCC_FILE_SIZES)(&(Fcb->Header.AllocationSize)));
913  }
914 
915  if (Fcb->Header.FileSize.QuadPart >= 0x80000000 &&
916  !IsFlagOn(SUPER_BLOCK->s_feature_ro_compat, EXT2_FEATURE_RO_COMPAT_LARGE_FILE)) {
918  Ext2SaveSuper(IrpContext, Vcb);
919  }
920 
924  }
925 
926 
927  Ext2SaveInode( IrpContext, Vcb, &Mcb->Inode);
928 
929  DEBUG(DL_IO, ("Ext2SetInformation: FileEndOfFileInformation %wZ EndofFile=%I64xh "
930  "AllocatieonSize=%I64xh FileSize=%I64xh VDL=%I64xh i_size=%I64xh status = %xh\n",
931  &Fcb->Mcb->ShortName, EndOfFile.QuadPart, Fcb->Header.AllocationSize.QuadPart,
932  Fcb->Header.FileSize.QuadPart, Fcb->Header.ValidDataLength.QuadPart,
933  Mcb->Inode.i_size, Status));
934  }
935 
936  break;
937 
939  {
941  LARGE_INTEGER NewVDL;
942 
945  _SEH2_LEAVE;
946  } else {
948  }
949 
950  NewVDL = FVDL->ValidDataLength;
951  if ((NewVDL.QuadPart < Fcb->Header.ValidDataLength.QuadPart)) {
953  _SEH2_LEAVE;
954  }
955  if (NewVDL.QuadPart > Fcb->Header.FileSize.QuadPart)
956  NewVDL = Fcb->Header.FileSize;
957 
958  if (!MmCanFileBeTruncated(FileObject->SectionObjectPointer,
959  &NewVDL)) {
961  _SEH2_LEAVE;
962  }
963 
964  Fcb->Header.ValidDataLength = NewVDL;
965  FileObject->Flags |= FO_FILE_MODIFIED;
966  if (CcIsFileCached(FileObject)) {
967  CcSetFileSizes(FileObject, (PCC_FILE_SIZES)(&(Fcb->Header.AllocationSize)));
968  }
969  }
970 
971  break;
972 
974  {
976 
977  Status = Ext2SetDispositionInfo(IrpContext, Vcb, Fcb, Ccb, FDI->DeleteFile);
978 
979  DEBUG(DL_INF, ( "Ext2SetInformation: SetDispositionInformation: DeleteFile=%d %wZ status = %xh\n",
980  FDI->DeleteFile, &Mcb->ShortName, Status));
981  }
982 
983  break;
984 
986  {
987  Status = Ext2SetRenameInfo(IrpContext, Vcb, Fcb, Ccb);
988  }
989 
990  break;
991 
992 
993  case FileLinkInformation:
994  {
995  Status = Ext2SetLinkInfo(IrpContext, Vcb, Fcb, Ccb);
996  }
997 
998  break;
999 
1000  //
1001  // This is the only set file information request supported on read
1002  // only file systems
1003  //
1005  {
1007 
1008  if (Length < sizeof(FILE_POSITION_INFORMATION)) {
1010  _SEH2_LEAVE;
1011  }
1012 
1014 
1016  (FilePositionInformation->CurrentByteOffset.LowPart &
1019  _SEH2_LEAVE;
1020  }
1021 
1022  FileObject->CurrentByteOffset =
1023  FilePositionInformation->CurrentByteOffset;
1024 
1026  _SEH2_LEAVE;
1027  }
1028 
1029  break;
1030 
1031  default:
1032  DEBUG(DL_WRN, ( "Ext2SetInformation: invalid class: %d\n",
1034  Status = STATUS_INVALID_PARAMETER;/* STATUS_INVALID_INFO_CLASS; */
1035  }
1036 
1037  } _SEH2_FINALLY {
1038 
1039  if (FcbPagingIoResourceAcquired) {
1041  }
1042 
1043  if (NT_SUCCESS(Status) && (NotifyFilter != 0)) {
1045  IrpContext,
1046  Vcb,
1047  Mcb,
1048  NotifyFilter,
1050 
1051  }
1052 
1053  if (FcbMainResourceAcquired) {
1055  }
1056 
1057  if (!IrpContext->ExceptionInProgress) {
1058  if (Status == STATUS_PENDING ||
1059  Status == STATUS_CANT_WAIT ) {
1060  DbgBreak();
1061  Status = Ext2QueueRequest(IrpContext);
1062  } else {
1063  Ext2CompleteIrpContext(IrpContext, Status);
1064  }
1065  }
1066  } _SEH2_END;
1067 
1068  return Status;
1069 }
struct _EXT2_FCB * PEXT2_FCB
BOOLEAN NTAPI MmCanFileBeTruncated(IN PSECTION_OBJECT_POINTERS SectionObjectPointer, IN PLARGE_INTEGER NewFileSize)
Definition: section.c:4724
struct _FILE_BASIC_INFORMATION * PFILE_BASIC_INFORMATION
#define IsMounted(Vcb)
Definition: ext2fs.h:803
#define TRUE
Definition: types.h:120
#define IRP_CONTEXT_FLAG_WAIT
Definition: cdstruc.h:1221
NTSTATUS Ext2SetDispositionInfo(PEXT2_IRP_CONTEXT IrpContext, PEXT2_VCB Vcb, PEXT2_FCB Fcb, PEXT2_CCB Ccb, BOOLEAN bDelete)
Definition: fileinfo.c:1277
#define FILE_ATTRIBUTE_TEMPORARY
Definition: nt_native.h:708
#define IsMcbDirectory(Mcb)
Definition: ext2fs.h:958
FSRTL_ADVANCED_FCB_HEADER Header
Definition: cdstruc.h:931
BOOLEAN Ext2SaveSuper(IN PEXT2_IRP_CONTEXT IrpContext, IN PEXT2_VCB Vcb)
Definition: generic.c:63
#define CEILING_ALIGNED(T, A, B)
Definition: ext2fs.h:111
LARGE_INTEGER Ext2NtTime(IN ULONG i_time)
Definition: misc.c:40
struct _FILE_DISPOSITION_INFORMATION * PFILE_DISPOSITION_INFORMATION
LARGE_INTEGER LastAccessTime
Definition: nt_native.h:940
_In_ PIRP Irp
Definition: csq.h:116
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
PDEVICE_OBJECT DeviceObject
Definition: ext2fs.h:1051
umode_t i_mode
Definition: fs.h:87
#define Ext2SetOwnerWritable(m)
Definition: ext2fs.h:408
LONG NTSTATUS
Definition: precomp.h:26
PIRP Irp
Definition: ext2fs.h:1041
PEXT2_IRP_CONTEXT IrpContext
Definition: ext4_xattr.h:141
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
#define FILE_NOTIFY_CHANGE_SIZE
ULONG Flags
Definition: ext2fs.h:1044
#define FILE_NOTIFY_CHANGE_LAST_WRITE
static OUT PIO_STATUS_BLOCK OUT PVOID IN ULONG IN FILE_INFORMATION_CLASS FileInformationClass
Definition: pipe.c:75
__u32 i_atime
Definition: fs.h:81
#define FO_NO_INTERMEDIATE_BUFFERING
Definition: iotypes.h:1735
__u32 i_mtime
Definition: fs.h:83
#define FCB_DELETE_PENDING
Definition: ext2fs.h:879
NTSTATUS Ext2TruncateFile(PEXT2_IRP_CONTEXT IrpContext, PEXT2_VCB Vcb, PEXT2_MCB Mcb, PLARGE_INTEGER Size)
Definition: fileinfo.c:1199
LARGE_INTEGER AllocationSize
Definition: winternl.h:688
_SEH2_TRY
Definition: create.c:4250
EXT2_IDENTIFIER_TYPE Type
Definition: ext2fs.h:472
Definition: fs.h:78
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
#define MCB_FILE_DELETED
Definition: ext2fs.h:946
#define FO_FILE_MODIFIED
Definition: iotypes.h:1745
NTFSIDENTIFIER Identifier
Definition: ntfs.h:511
int Ext2CheckFileAccess(PEXT2_VCB Vcb, PEXT2_MCB Mcb, int attempt)
Definition: access.c:51
NTSTATUS Ext2QueueRequest(IN PEXT2_IRP_CONTEXT IrpContext)
Definition: dispatch.c:150
#define CcIsFileCached(FO)
#define IsFlagOn(a, b)
Definition: ext2fs.h:177
#define FILE_ACTION_MODIFIED
VOID Ext2NotifyReportChange(IN PEXT2_IRP_CONTEXT IrpContext, IN PEXT2_VCB Vcb, IN PEXT2_MCB Mcb, IN ULONG Filter, IN ULONG Action)
Definition: dirctl.c:1209
NTSTATUS Ext2SetRenameInfo(PEXT2_IRP_CONTEXT IrpContext, PEXT2_VCB Vcb, PEXT2_FCB Fcb, PEXT2_CCB Ccb)
Definition: fileinfo.c:1320
PVOID DeviceExtension
Definition: env_spec_w32.h:418
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
#define STATUS_MEDIA_WRITE_PROTECTED
Definition: udferr_usr.h:161
#define ClearLongFlag(_F, _SF)
Definition: ext2fs.h:254
Definition: bufpool.h:45
FAST_IO_POSSIBLE Ext2IsFastIoPossible(IN PEXT2_FCB Fcb)
Definition: fastio.c:38
#define FCB_ALLOC_IN_WRITE
Definition: ext2fs.h:876
#define STATUS_USER_MAPPED_FILE
Definition: ntstatus.h:697
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
#define STATUS_FILE_DELETED
Definition: udferr_usr.h:172
#define SUPER_BLOCK
Definition: ext2fs.h:90
#define FILE_NOTIFY_CHANGE_CREATION
#define Ext2SetOwnerReadOnly(m)
Definition: ext2fs.h:409
struct _FILE_END_OF_FILE_INFORMATION * PFILE_END_OF_FILE_INFORMATION
#define FILE_ATTRIBUTE_DIRECTORY
Definition: nt_native.h:705
EXT2_IDENTIFIER Identifier
Definition: ext2fs.h:1038
enum _FILE_INFORMATION_CLASS FILE_INFORMATION_CLASS
Definition: directory.c:44
#define BLOCK_SIZE
Definition: dlist.c:220
__u32 i_ctime
Definition: fs.h:82
LARGE_INTEGER LastWriteTime
Definition: nt_native.h:941
if(!(yy_init))
Definition: macro.lex.yy.c:714
struct _FILE_ALLOCATION_INFORMATION * PFILE_ALLOCATION_INFORMATION
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
#define DL_INF
Definition: ext2fs.h:1399
#define IsVcbReadOnly(Vcb)
Definition: ext2fs.h:805
uint64_t ULONGLONG
Definition: typedefs.h:65
#define CCB_LAST_WRITE_UPDATED
Definition: ext2fs.h:1024
#define IsMcbSymLink(Mcb)
Definition: ext2fs.h:953
#define Vcb
Definition: cdprocs.h:1425
#define FILE_ATTRIBUTE_READONLY
Definition: nt_native.h:702
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
* PFILE_OBJECT
Definition: iotypes.h:1955
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
ULONG Flags
Definition: ntfs.h:532
unsigned __int64 loff_t
Definition: types.h:80
CD_MCB Mcb
Definition: cdstruc.h:1022
LARGE_INTEGER CreationTime
Definition: nt_native.h:939
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:126
PFILE_OBJECT FileObject
Definition: ext2fs.h:1057
struct _FILE_VALID_DATA_LENGTH_INFORMATION * PFILE_VALID_DATA_LENGTH_INFORMATION
NTSTATUS Ext2CompleteIrpContext(IN PEXT2_IRP_CONTEXT IrpContext, IN NTSTATUS Status)
Definition: read.c:32
_Must_inspect_result_ _In_ PFLT_INSTANCE _Out_ PBOOLEAN IsDirectory
Definition: fltkernel.h:1139
ULONG Type
Definition: ntfs.h:95
#define FCB_FILE_MODIFIED
Definition: ext2fs.h:873
_Inout_ PFILE_OBJECT _In_ TYPE_OF_OPEN PFCB _In_opt_ PCCB Ccb
Definition: cdprocs.h:593
_Must_inspect_result_ _In_ USHORT NewSize
Definition: fltkernel.h:975
#define FlagOn(_F, _SF)
Definition: ext2fs.h:179
ERESOURCE MainResource
Definition: ntfs.h:524
ULONG AlignmentRequirement
Definition: env_spec_w32.h:420
LARGE_INTEGER ChangeTime
Definition: nt_native.h:942
ClearFlag(Dirent->Flags, DIRENT_FLAG_NOT_PERSISTENT)
Status
Definition: gdiplustypes.h:24
IN PFCB IN PFILE_OBJECT FileObject IN ULONG AllocationSize
Definition: fatprocs.h:310
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
#define SetFlag(_F, _SF)
Definition: ext2fs.h:187
_SEH2_END
Definition: create.c:4424
#define FO_TEMPORARY_FILE
Definition: iotypes.h:1748
#define FILE_NOTIFY_CHANGE_ATTRIBUTES
VOID NTAPI CcSetFileSizes(IN PFILE_OBJECT FileObject, IN PCC_FILE_SIZES FileSizes)
Definition: fssup.c:354
IN PVCB IN ULONG IN OUT PULONG IN BOOLEAN OUT PLARGE_MCB Mcb
Definition: fatprocs.h:334
#define SetLongFlag(_F, _SF)
Definition: ext2fs.h:253
NTSTATUS Ext2ExpandFile(PEXT2_IRP_CONTEXT IrpContext, PEXT2_VCB Vcb, PEXT2_MCB Mcb, PLARGE_INTEGER Size)
Definition: fileinfo.c:1147
_SEH2_FINALLY
Definition: create.c:4395
#define DL_IO
Definition: ext2fs.h:1413
#define FCB_PAGE_FILE
Definition: ext2fs.h:872
#define DL_WRN
Definition: ext2fs.h:1410
#define VCB_VOLUME_LOCKED
Definition: ext2fs.h:780
#define IsMcbSpecialFile(Mcb)
Definition: ext2fs.h:955
struct _FILE_POSITION_INFORMATION * PFILE_POSITION_INFORMATION
#define IsExt2FsDevice(DO)
Definition: ext2fs.h:607
unsigned int ULONG
Definition: retypes.h:1
ERESOURCE PagingIoResource
Definition: ntfs.h:523
#define DbgBreak()
Definition: ext2fs.h:46
struct _EXT2_VCB * PEXT2_VCB
#define DEBUG(args)
Definition: rdesktop.h:129
#define EXT2_FEATURE_RO_COMPAT_LARGE_FILE
Definition: ext2_fs.h:466
NTSTATUS NTAPI FsRtlCheckOplock(IN POPLOCK Oplock, IN PIRP Irp, IN PVOID Context, IN POPLOCK_WAIT_COMPLETE_ROUTINE CompletionRoutine OPTIONAL, IN POPLOCK_FS_PREPOST_IRP PostIrpRoutine OPTIONAL)
Definition: oplock.c:1172
#define FCB_ALLOC_IN_CREATE
Definition: ext2fs.h:875
#define FCB_ALLOC_IN_SETINFO
Definition: ext2fs.h:877
#define _SEH2_LEAVE
Definition: filesup.c:20
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
_In_ PFCB Fcb
Definition: cdprocs.h:151
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
return STATUS_SUCCESS
Definition: btrfs.c:2966
struct _EXT2_CCB * PEXT2_CCB
#define FILE_NOTIFY_CHANGE_LAST_ACCESS
#define Ext2FileCanWrite
Definition: ext2fs.h:427
BOOLEAN Ext2SaveInode(IN PEXT2_IRP_CONTEXT IrpContext, IN PEXT2_VCB Vcb, IN struct inode *Inode)
Definition: generic.c:548
ULONG Size
Definition: ntfs.h:96
ULONG Ext2LinuxTime(IN LARGE_INTEGER SysTime)
Definition: misc.c:51
_In_opt_ HANDLE _In_opt_ PIO_APC_ROUTINE _In_opt_ PVOID _Out_ PIO_STATUS_BLOCK _In_ ULONG NotifyFilter
Definition: zwfuncs.h:500
LONGLONG QuadPart
Definition: typedefs.h:112
#define STATUS_CANT_WAIT
Definition: ntstatus.h:438
NTSTATUS Ext2SetLinkInfo(PEXT2_IRP_CONTEXT IrpContext, PEXT2_VCB Vcb, PEXT2_FCB Fcb, PEXT2_CCB Ccb)
Definition: fileinfo.c:1660

Referenced by Ext2DispatchRequest().

◆ Ext2SetLinkInfo()

NTSTATUS Ext2SetLinkInfo ( PEXT2_IRP_CONTEXT  IrpContext,
PEXT2_VCB  Vcb,
PEXT2_FCB  Fcb,
PEXT2_CCB  Ccb 
)

Definition at line 1660 of file fileinfo.c.

1666 {
1667  PEXT2_MCB Mcb = Fcb->Mcb;
1668 
1669  PEXT2_FCB TargetDcb = NULL; /* Dcb of target directory */
1670  PEXT2_MCB TargetMcb = NULL;
1671  PEXT2_FCB ParentDcb = NULL; /* Dcb of it's current parent */
1672  PEXT2_MCB ParentMcb = NULL;
1673 
1674  PEXT2_FCB ExistingFcb = NULL; /* Target file Fcb if it exists*/
1675  PEXT2_MCB ExistingMcb = NULL;
1676  PEXT2_MCB LinkMcb = NULL; /* Mcb for new hardlink */
1677 
1679 
1680  NTSTATUS Status;
1681 
1682  PIRP Irp;
1684 
1686  PFILE_OBJECT TargetObject;
1687 
1688  BOOLEAN ReplaceIfExists;
1689  BOOLEAN bTargetRemoved = FALSE;
1690 
1691  BOOLEAN bFcbLockAcquired = FALSE;
1692 
1694 
1695  if (Ccb->SymLink) {
1696  Mcb = Ccb->SymLink;
1697  }
1698 
1699  if (IsMcbDirectory(Mcb)) {
1701  goto errorout;
1702  }
1703 
1704  Irp = IrpContext->Irp;
1706 
1708  TargetObject = IrpSp->Parameters.SetFile.FileObject;
1709  ReplaceIfExists = IrpSp->Parameters.SetFile.ReplaceIfExists;
1710 
1711  FLI = (PFILE_LINK_INFORMATION)Irp->AssociatedIrp.SystemBuffer;
1712 
1713  if (TargetObject == NULL) {
1714 
1716 
1717  NewName.Buffer = FLI->FileName;
1719 
1720  while (NewName.Length > 0 && NewName.Buffer[NewName.Length/2 - 1] == L'\\') {
1721  NewName.Buffer[NewName.Length/2 - 1] = 0;
1722  NewName.Length -= 2;
1723  }
1724 
1725  while (NewName.Length > 0 && NewName.Buffer[NewName.Length/2 - 1] != L'\\') {
1726  NewName.Length -= 2;
1727  }
1728 
1731 
1732  FileName = NewName;
1733 
1734  TargetMcb = Mcb->Parent;
1735  if (IsMcbSymLink(TargetMcb)) {
1736  TargetMcb = TargetMcb->Target;
1737  ASSERT(!IsMcbSymLink(TargetMcb));
1738  }
1739 
1740  if (TargetMcb == NULL || FileName.Length >= EXT2_NAME_LEN*2) {
1742  goto errorout;
1743  }
1744 
1745  } else {
1746 
1747  TargetDcb = (PEXT2_FCB)(TargetObject->FsContext);
1748  if (!TargetDcb || TargetDcb->Vcb != Vcb) {
1749  DbgBreak();
1751  goto errorout;
1752  }
1753 
1754  TargetMcb = TargetDcb->Mcb;
1755  FileName = TargetObject->FileName;
1756  }
1757 
1760  goto errorout;
1761  }
1762 
1763  if (TargetMcb->Inode.i_ino == Mcb->Parent->Inode.i_ino) {
1765  &(Mcb->ShortName),
1766  FALSE,
1767  NULL )) {
1769  goto errorout;
1770  }
1771  }
1772 
1774  bFcbLockAcquired = TRUE;
1775 
1776  TargetDcb = TargetMcb->Fcb;
1777  if (TargetDcb == NULL) {
1778  TargetDcb = Ext2AllocateFcb(Vcb, TargetMcb);
1779  }
1780  if (TargetDcb) {
1781  Ext2ReferXcb(&TargetDcb->ReferenceCount);
1782  }
1783 
1784  ParentMcb = Mcb->Parent;
1785  ParentDcb = ParentMcb->Fcb;
1786 
1787  if ((TargetMcb->Inode.i_ino != ParentMcb->Inode.i_ino)) {
1788 
1789  if (ParentDcb == NULL) {
1790  ParentDcb = Ext2AllocateFcb(Vcb, ParentMcb);
1791  }
1792  }
1793  if (ParentDcb) {
1794  Ext2ReferXcb(&ParentDcb->ReferenceCount);
1795  }
1796 
1797  if (bFcbLockAcquired) {
1798  ExReleaseResourceLite(&Vcb->FcbLock);
1799  bFcbLockAcquired = FALSE;
1800  }
1801 
1802  if (!TargetDcb || !ParentDcb) {
1804  goto errorout;
1805  }
1806 
1807  DEBUG(DL_RES, ("Ext2SetLinkInfo: %wZ\\%wZ -> %wZ\n",
1808  &TargetMcb->FullName, &FileName, &Mcb->FullName));
1809 
1810  Status = Ext2LookupFile(IrpContext, Vcb, &FileName,
1811  TargetMcb, &ExistingMcb, 0);
1812  if (NT_SUCCESS(Status) && ExistingMcb != Mcb) {
1813 
1814  if (!ReplaceIfExists) {
1815 
1817  DEBUG(DL_RES, ("Ext2SetRenameInfo: Target file %wZ exists\n",
1818  &ExistingMcb->FullName));
1819  goto errorout;
1820 
1821  } else {
1822 
1823  if ( (ExistingFcb = ExistingMcb->Fcb) && !IsMcbSymLink(ExistingMcb) ) {
1824  Status = Ext2IsFileRemovable(IrpContext, Vcb, ExistingFcb, Ccb);
1825  if (!NT_SUCCESS(Status)) {
1826  DEBUG(DL_REN, ("Ext2SetRenameInfo: Target file %wZ cannot be removed.\n",
1827  &ExistingMcb->FullName));
1828  goto errorout;
1829  }
1830  }
1831 
1832  Status = Ext2DeleteFile(IrpContext, Vcb, ExistingFcb, ExistingMcb);
1833  if (!NT_SUCCESS(Status)) {
1834  DEBUG(DL_REN, ("Ext2SetRenameInfo: Failed to delete %wZ with status: %xh.\n",
1835  &FileName, Status));
1836 
1837  goto errorout;
1838  }
1839  bTargetRemoved = TRUE;
1840  }
1841  }
1842 
1843  /* add new entry for new target name */
1844  Status = Ext2AddEntry(IrpContext, Vcb, TargetDcb, &Mcb->Inode, &FileName, NULL);
1845  if (!NT_SUCCESS(Status)) {
1846  DEBUG(DL_REN, ("Ext2SetLinkInfo: Failed to add entry for %wZ with status: %xh.\n",
1847  &FileName, Status));
1848  goto errorout;
1849  }
1850 
1851  if (bTargetRemoved) {
1853  IrpContext,
1854  Vcb,
1855  ExistingMcb,
1856  (IsMcbDirectory(ExistingMcb) ?
1860  }
1861 
1862  if (NT_SUCCESS(Status)) {
1863 
1864  Ext2LookupFile(IrpContext, Vcb, &FileName, TargetMcb, &LinkMcb, 0);
1865  if (!LinkMcb)
1866  goto errorout;
1867 
1869  IrpContext,
1870  Vcb,
1871  LinkMcb,
1874  }
1875 
1876 errorout:
1877 
1878  if (bFcbLockAcquired) {
1879  ExReleaseResourceLite(&Vcb->FcbLock);
1880  bFcbLockAcquired = FALSE;
1881  }
1882 
1883  if (TargetDcb) {
1885  }
1886 
1887  if (ParentDcb) {
1889  }
1890 
1891  if (ExistingMcb)
1892  Ext2DerefMcb(ExistingMcb);
1893 
1894  if (LinkMcb)
1895  Ext2DerefMcb(LinkMcb);
1896 
1897  return Status;
1898 }
#define STATUS_OBJECT_NAME_COLLISION
Definition: udferr_usr.h:150
struct _EXT2_FCB * PEXT2_FCB
#define Ext2DerefMcb(Mcb)
Definition: ext2fs.h:987
#define TRUE
Definition: types.h:120
PEXT2_FCB Fcb
Definition: ext2fs.h:905
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
PEXT2_MCB Target
Definition: ext2fs.h:899
#define IsMcbDirectory(Mcb)
Definition: ext2fs.h:958
struct inode Inode
Definition: ext2fs.h:936
BOOLEAN Ext2LookupFile(PEXT2_VOLUME_INFO Volume, PCSTR FileName, PEXT2_FILE_INFO Ext2FileInfo)
Definition: ext2.c:205
USHORT MaximumLength
Definition: env_spec_w32.h:370
_In_ PIRP Irp
Definition: csq.h:116
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
PIRP Irp
Definition: ext2fs.h:1041
#define FILE_NOTIFY_CHANGE_FILE_NAME
_In_ PIO_STACK_LOCATION _Inout_ PFILE_OBJECT _Inout_ PVCB _Outptr_result_maybenull_ PDCB _In_ PDCB ParentDcb
Definition: create.c:4157
#define FILE_NOTIFY_CHANGE_DIR_NAME
BOOLEAN NTAPI FsRtlDoesNameContainWildCards(IN PUNICODE_STRING Name)
Definition: name.c:464
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
while(1)
Definition: macro.lex.yy.c:740
VOID Ext2NotifyReportChange(IN PEXT2_IRP_CONTEXT IrpContext, IN PEXT2_VCB Vcb, IN PEXT2_MCB Mcb, IN ULONG Filter, IN ULONG Action)
Definition: dirctl.c:1209
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
#define FILE_ACTION_REMOVED
PEXT2_FCB Ext2AllocateFcb(IN PEXT2_VCB Vcb, IN PEXT2_MCB Mcb)
Definition: memory.c:131
IN PDCB TargetDcb
Definition: fatprocs.h:779
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
NTSTATUS Ext2AddEntry(IN PEXT2_IRP_CONTEXT IrpContext, IN PEXT2_VCB Vcb, IN PEXT2_FCB Dcb, IN struct inode *Inode, IN PUNICODE_STRING FileName, OUT struct dentry **dentry)
BOOLEAN NTAPI FsRtlAreNamesEqual(IN PCUNICODE_STRING Name1, IN PCUNICODE_STRING Name2, IN BOOLEAN IgnoreCase, IN PCWCH UpcaseTable OPTIONAL)
Definition: name.c:296
#define DL_REN
Definition: ext2fs.h:1402
UNICODE_STRING FullName
Definition: ext2fs.h:911
if(!(yy_init))
Definition: macro.lex.yy.c:714
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define IsMcbSymLink(Mcb)
Definition: ext2fs.h:953
#define Vcb
Definition: cdprocs.h:1425
#define Ext2ReferXcb(_C)
Definition: ext2fs.h:967
NTSTATUS Ext2DeleteFile(PEXT2_IRP_CONTEXT IrpContext, PEXT2_VCB Vcb, PEXT2_FCB Fcb, PEXT2_MCB Mcb)
Definition: fileinfo.c:1915
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
* PFILE_OBJECT
Definition: iotypes.h:1955
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
CD_MCB Mcb
Definition: cdstruc.h:1022
unsigned char UCHAR
Definition: xmlstorage.h:181
static const WCHAR L[]
Definition: oid.c:1250
#define EXT2_NAME_LEN
Definition: ext2.h:156
NTSTATUS Ext2IsFileRemovable(IN PEXT2_IRP_CONTEXT IrpContext, IN PEXT2_VCB Vcb, IN PEXT2_FCB Fcb, IN PEXT2_CCB Ccb)
Definition: fileinfo.c:1234
_Inout_ PFILE_OBJECT _In_ TYPE_OF_OPEN PFCB _In_opt_ PCCB Ccb
Definition: cdprocs.h:593
Status
Definition: gdiplustypes.h:24
#define DL_RES
Definition: ext2fs.h:1403
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
struct _FileName FileName
Definition: fatprocs.h:884
PFILE_OBJECT FileObject
Definition: iotypes.h:2813
unsigned short USHORT
Definition: pedump.c:61
struct _FILE_LINK_INFORMATION * PFILE_LINK_INFORMATION
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
IN PVCB IN ULONG IN OUT PULONG IN BOOLEAN OUT PLARGE_MCB Mcb
Definition: fatprocs.h:334
#define STATUS_OBJECT_NAME_INVALID
Definition: udferr_usr.h:148
#define FILE_ACTION_ADDED
_In_ PUNICODE_STRING NewName
Definition: zwfuncs.h:1203
VOID Ext2ReleaseFcb(IN PEXT2_FCB Fcb)
Definition: memory.c:276
PVCB Vcb
Definition: cdstruc.h:939
#define DbgBreak()
Definition: ext2fs.h:46
#define DEBUG(args)
Definition: rdesktop.h:129
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
_In_ PFCB Fcb
Definition: cdprocs.h:151
return STATUS_SUCCESS
Definition: btrfs.c:2966

Referenced by Ext2SetFileInformation().

◆ Ext2SetRenameInfo()

NTSTATUS Ext2SetRenameInfo ( PEXT2_IRP_CONTEXT  IrpContext,
PEXT2_VCB  Vcb,
PEXT2_FCB  Fcb,
PEXT2_CCB  Ccb 
)

Definition at line 1320 of file fileinfo.c.

1326 {
1327  PEXT2_MCB Mcb = Fcb->Mcb;
1328 
1329  PEXT2_FCB TargetDcb = NULL; /* Dcb of target directory */
1330  PEXT2_MCB TargetMcb = NULL;
1331  PEXT2_FCB ParentDcb = NULL; /* Dcb of it's current parent */
1332  PEXT2_MCB ParentMcb = NULL;
1333 
1334  PEXT2_FCB ExistingFcb = NULL; /* Target file Fcb if it exists*/
1335  PEXT2_MCB ExistingMcb = NULL;
1336 
1338 
1339  NTSTATUS Status;
1340 
1341  PIRP Irp;
1343 
1345  PFILE_OBJECT TargetObject;
1346 
1347  struct dentry *NewEntry = NULL;
1348 
1349  BOOLEAN ReplaceIfExists;
1350  BOOLEAN bMove = FALSE;
1351  BOOLEAN bTargetRemoved = FALSE;
1352 
1353  BOOLEAN bFcbLockAcquired = FALSE;
1354 
1356 
1357  if (Ccb->SymLink) {
1358  Mcb = Ccb->SymLink;
1359  }
1360 
1361  if (Mcb->Inode.i_ino == EXT2_ROOT_INO) {
1363  goto errorout;
1364  }
1365 
1366  Irp = IrpContext->Irp;
1368 
1370  TargetObject = IrpSp->Parameters.SetFile.FileObject;
1371  ReplaceIfExists = IrpSp->Parameters.SetFile.ReplaceIfExists;
1372 
1373  FRI = (PFILE_RENAME_INFORMATION)Irp->AssociatedIrp.SystemBuffer;
1374 
1375  if (TargetObject == NULL) {
1376 
1378 
1379  NewName.Buffer = FRI->FileName;
1381 
1382  while (NewName.Length > 0 && NewName.Buffer[NewName.Length/2 - 1] == L'\\') {
1383  NewName.Buffer[NewName.Length/2 - 1] = 0;
1384  NewName.Length -= 2;
1385  }
1386 
1387  while (NewName.Length > 0 && NewName.Buffer[NewName.Length/2 - 1] != L'\\') {
1388  NewName.Length -= 2;
1389  }
1390 
1393 
1394  FileName = NewName;
1395 
1396  TargetMcb = Mcb->Parent;
1397  if (IsMcbSymLink(TargetMcb)) {
1398  TargetMcb = TargetMcb->Target;
1399  ASSERT(!IsMcbSymLink(TargetMcb));
1400  }
1401 
1402  if (TargetMcb == NULL || FileName.Length >= EXT2_NAME_LEN*2) {
1404  goto errorout;
1405  }
1406 
1407  } else {
1408 
1409  TargetDcb = (PEXT2_FCB)(TargetObject->FsContext);
1410 
1411  if (!TargetDcb || TargetDcb->Vcb != Vcb) {
1412 
1413  DbgBreak();
1414 
1416  goto errorout;
1417  }
1418 
1419  TargetMcb = TargetDcb->Mcb;
1420  FileName = TargetObject->FileName;
1421  }
1422 
1425  goto errorout;
1426  }
1427 
1428  if (TargetMcb->Inode.i_ino == Mcb->Parent->Inode.i_ino) {
1430  &(Mcb->ShortName),
1431  FALSE,
1432  NULL )) {
1434  goto errorout;
1435  }
1436  } else {
1437  bMove = TRUE;
1438  }
1439 
1440  if (!bFcbLockAcquired) {
1442  bFcbLockAcquired = TRUE;
1443  }
1444 
1445  TargetDcb = TargetMcb->Fcb;
1446  if (TargetDcb == NULL) {
1447  TargetDcb = Ext2AllocateFcb(Vcb, TargetMcb);
1448  }
1449  if (TargetDcb) {
1450  Ext2ReferXcb(&TargetDcb->ReferenceCount);
1451  }
1452 
1453  ParentMcb = Mcb->Parent;
1454  ParentDcb = ParentMcb->Fcb;
1455 
1456  if ((TargetMcb->Inode.i_ino != ParentMcb->Inode.i_ino)) {
1457 
1458  if (ParentDcb == NULL) {
1459  ParentDcb = Ext2AllocateFcb(Vcb, ParentMcb);
1460  }
1461  }
1462  if (ParentDcb) {
1463  Ext2ReferXcb(&ParentDcb->ReferenceCount);
1464  }
1465 
1466  if (bFcbLockAcquired) {
1467  ExReleaseResourceLite(&Vcb->FcbLock);
1468  bFcbLockAcquired = FALSE;
1469  }
1470 
1471  if (!TargetDcb || !ParentDcb) {
1473  goto errorout;
1474  }
1475 
1476  DEBUG(DL_RES, ("Ext2SetRenameInfo: rename %wZ to %wZ\\%wZ\n",
1477  &Mcb->FullName, &TargetMcb->FullName, &FileName));
1478 
1480  IrpContext,
1481  Vcb,
1482  &FileName,
1483  TargetMcb,
1484  &ExistingMcb,
1485  0
1486  );
1487 
1488  if (NT_SUCCESS(Status) && ExistingMcb != Mcb) {
1489 
1490  if (!ReplaceIfExists) {
1491 
1493  DEBUG(DL_RES, ("Ext2SetRenameInfo: Target file %wZ exists\n",
1494  &ExistingMcb->FullName));
1495  goto errorout;
1496 
1497  } else {
1498 
1499  if ( (ExistingFcb = ExistingMcb->Fcb) && !IsMcbSymLink(ExistingMcb) ) {
1500 
1501  Status = Ext2IsFileRemovable(IrpContext, Vcb, ExistingFcb, Ccb);
1502  if (!NT_SUCCESS(Status)) {
1503  DEBUG(DL_REN, ("Ext2SetRenameInfo: Target file %wZ cannot be removed.\n",
1504  &ExistingMcb->FullName));
1505  goto errorout;
1506  }
1507  }
1508 
1509  Status = Ext2DeleteFile(IrpContext, Vcb, ExistingFcb, ExistingMcb);
1510  if (!NT_SUCCESS(Status)) {
1511  DEBUG(DL_REN, ("Ext2SetRenameInfo: Failed to delete %wZ with status: %xh.\n",
1512  &FileName, Status));
1513 
1514  goto errorout;
1515  }
1516 
1517  bTargetRemoved = TRUE;
1518  }
1519  }
1520 
1521  /* remove directory entry of old name */
1522  Status = Ext2RemoveEntry(IrpContext, Vcb, ParentDcb, Mcb);
1523  if (!NT_SUCCESS(Status)) {
1524  DEBUG(DL_REN, ("Ext2SetRenameInfo: Failed to remove entry %wZ with status %xh.\n",
1525  &Mcb->FullName, Status));
1526  DbgBreak();
1527  goto errorout;
1528  }
1529 
1530  /* add new entry for new target name */
1531  Status = Ext2AddEntry(IrpContext, Vcb, TargetDcb, &Mcb->Inode, &FileName, &NewEntry);
1532  if (!NT_SUCCESS(Status)) {
1533  DEBUG(DL_REN, ("Ext2SetRenameInfo: Failed to add entry for %wZ with status: %xh.\n",
1534  &FileName, Status));
1535  Ext2AddEntry(IrpContext, Vcb, ParentDcb, &Mcb->Inode, &Mcb->ShortName, &NewEntry);
1536  goto errorout;
1537  }
1538 
1539  /* correct the inode number in .. entry */
1540  if (IsMcbDirectory(Mcb)) {
1542  IrpContext, Vcb, Fcb,
1543  ParentMcb->Inode.i_ino,
1544  TargetMcb->Inode.i_ino );
1545  if (!NT_SUCCESS(Status)) {
1546  DEBUG(DL_REN, ("Ext2SetRenameInfo: Failed to set parent refer of %wZ with %xh.\n",
1547  &Mcb->FullName, Status));
1548  DbgBreak();
1549  goto errorout;
1550  }
1551  }
1552 
1553  /* Update current dentry from the newly created one. We need keep the original
1554  dentry to assure children's links are valid if current entry is a directory */
1555  if (Mcb->de) {
1556  char *np = Mcb->de->d_name.name;
1557  *(Mcb->de) = *NewEntry;
1558  NewEntry->d_name.name = np;
1559  }
1560 
1561  if (bTargetRemoved) {
1563  IrpContext,
1564  Vcb,
1565  ExistingMcb,
1566  (IsMcbDirectory(ExistingMcb) ?
1570  }
1571 
1572  if (NT_SUCCESS(Status)) {
1573 
1574  if (bMove) {
1576  IrpContext,
1577  Vcb,
1578  Mcb,
1579  (IsDirectory(Fcb) ?
1583 
1584  } else {
1586  IrpContext,
1587  Vcb,
1588  Mcb,
1589  (IsDirectory(Fcb) ?
1593 
1594  }
1595 
1596  if (TargetMcb->Inode.i_ino != ParentMcb->Inode.i_ino) {
1597  Ext2RemoveMcb(Vcb, Mcb);
1598  Ext2InsertMcb(Vcb, TargetMcb, Mcb);
1599  }
1600 
1601  if (!Ext2BuildName( &Mcb->ShortName,
1602  &FileName, NULL )) {
1604  goto errorout;
1605  }
1606 
1607  if (!Ext2BuildName( &Mcb->FullName,
1608  &FileName,
1609  &TargetMcb->FullName)) {
1611  goto errorout;
1612  }
1613 
1614  if (bMove) {
1616  IrpContext,
1617  Vcb,
1618  Mcb,
1619  (IsDirectory(Fcb) ?
1623  } else {
1625  IrpContext,
1626  Vcb,
1627  Mcb,
1628  (IsDirectory(Fcb) ?
1632  }
1633  }
1634 
1635 errorout:
1636 
1637  if (bFcbLockAcquired) {
1638  ExReleaseResourceLite(&Vcb->FcbLock);
1639  bFcbLockAcquired = FALSE;
1640  }
1641 
1642  if (NewEntry)
1643  Ext2FreeEntry(NewEntry);
1644 
1645  if (TargetDcb) {
1647  }
1648 
1649  if (ParentDcb) {
1651  }
1652 
1653  if (ExistingMcb)
1654  Ext2DerefMcb(ExistingMcb);
1655 
1656  return Status;
1657 }
#define STATUS_OBJECT_NAME_COLLISION
Definition: udferr_usr.h:150
struct _EXT2_FCB * PEXT2_FCB
#define Ext2DerefMcb(Mcb)
Definition: ext2fs.h:987
#define TRUE
Definition: types.h:120
PEXT2_FCB Fcb
Definition: ext2fs.h:905
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
PEXT2_MCB Target
Definition: ext2fs.h:899
#define IsMcbDirectory(Mcb)
Definition: ext2fs.h:958
struct inode Inode
Definition: ext2fs.h:936
#define FILE_ACTION_RENAMED_OLD_NAME
BOOLEAN Ext2LookupFile(PEXT2_VOLUME_INFO Volume, PCSTR FileName, PEXT2_FILE_INFO Ext2FileInfo)
Definition: ext2.c:205
USHORT MaximumLength
Definition: env_spec_w32.h:370
_In_ PIRP Irp
Definition: csq.h:116
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
PIRP Irp
Definition: ext2fs.h:1041
#define FILE_NOTIFY_CHANGE_FILE_NAME
_In_ PIO_STACK_LOCATION _Inout_ PFILE_OBJECT _Inout_ PVCB _Outptr_result_maybenull_ PDCB _In_ PDCB ParentDcb
Definition: create.c:4157
#define FILE_NOTIFY_CHANGE_DIR_NAME
BOOLEAN NTAPI FsRtlDoesNameContainWildCards(IN PUNICODE_STRING Name)
Definition: name.c:464
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
VOID Ext2FreeEntry(IN struct dentry *de)
Definition: memory.c:432
while(1)
Definition: macro.lex.yy.c:740
VOID Ext2InsertMcb(PEXT2_VCB Vcb, PEXT2_MCB Parent, PEXT2_MCB Child)
Definition: memory.c:1686
BOOLEAN Ext2BuildName(IN OUT PUNICODE_STRING Target, IN PUNICODE_STRING File, IN PUNICODE_STRING Parent)
Definition: memory.c:1361
VOID Ext2NotifyReportChange(IN PEXT2_IRP_CONTEXT IrpContext, IN PEXT2_VCB Vcb, IN PEXT2_MCB Mcb, IN ULONG Filter, IN ULONG Action)
Definition: dirctl.c:1209
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
struct dentry::@680 d_name
#define FILE_ACTION_REMOVED
PEXT2_FCB Ext2AllocateFcb(IN PEXT2_VCB Vcb, IN PEXT2_MCB Mcb)
Definition: memory.c:131
Definition: fs.h:117
IN PDCB TargetDcb
Definition: fatprocs.h:779
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
#define EXT2_ROOT_INO
Definition: ext2.h:177
NTSTATUS Ext2AddEntry(IN PEXT2_IRP_CONTEXT IrpContext, IN PEXT2_VCB Vcb, IN PEXT2_FCB Dcb, IN struct inode *Inode, IN PUNICODE_STRING FileName, OUT struct dentry **dentry)
BOOLEAN NTAPI FsRtlAreNamesEqual(IN PCUNICODE_STRING Name1, IN PCUNICODE_STRING Name2, IN BOOLEAN IgnoreCase, IN PCWCH UpcaseTable OPTIONAL)
Definition: name.c:296
#define DL_REN
Definition: ext2fs.h:1402
UNICODE_STRING FullName
Definition: ext2fs.h:911
if(!(yy_init))
Definition: macro.lex.yy.c:714
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define IsMcbSymLink(Mcb)
Definition: ext2fs.h:953
#define Vcb
Definition: cdprocs.h:1425
#define Ext2ReferXcb(_C)
Definition: ext2fs.h:967
NTSTATUS Ext2DeleteFile(PEXT2_IRP_CONTEXT IrpContext, PEXT2_VCB Vcb, PEXT2_FCB Fcb, PEXT2_MCB Mcb)
Definition: fileinfo.c:1915
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
* PFILE_OBJECT
Definition: iotypes.h:1955
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
CD_MCB Mcb
Definition: cdstruc.h:1022
unsigned char UCHAR
Definition: xmlstorage.h:181
struct _FILE_RENAME_INFORMATION * PFILE_RENAME_INFORMATION
static const WCHAR L[]
Definition: oid.c:1250
#define EXT2_NAME_LEN
Definition: ext2.h:156
_Must_inspect_result_ _In_ PFLT_INSTANCE _Out_ PBOOLEAN IsDirectory
Definition: fltkernel.h:1139
#define FILE_ACTION_RENAMED_NEW_NAME
NTSTATUS Ext2IsFileRemovable(IN PEXT2_IRP_CONTEXT IrpContext, IN PEXT2_VCB Vcb, IN PEXT2_FCB Fcb, IN PEXT2_CCB Ccb)
Definition: fileinfo.c:1234
_Inout_ PFILE_OBJECT _In_ TYPE_OF_OPEN PFCB _In_opt_ PCCB Ccb
Definition: cdprocs.h:593
BOOLEAN Ext2RemoveMcb(PEXT2_VCB Vcb, PEXT2_MCB Mcb)
Definition: memory.c:1746
Status
Definition: gdiplustypes.h:24
#define DL_RES
Definition: ext2fs.h:1403
NTSTATUS Ext2SetParentEntry(IN PEXT2_IRP_CONTEXT IrpContext, IN PEXT2_VCB Vcb, IN PEXT2_FCB Dcb, IN ULONG OldParent, IN ULONG NewParent)
Definition: generic.c:2031
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
struct _FileName FileName
Definition: fatprocs.h:884
PFILE_OBJECT FileObject
Definition: iotypes.h:2813
unsigned short USHORT
Definition: pedump.c:61
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
IN PVCB IN ULONG IN OUT PULONG IN BOOLEAN OUT PLARGE_MCB Mcb
Definition: fatprocs.h:334
#define STATUS_OBJECT_NAME_INVALID
Definition: udferr_usr.h:148
#define FILE_ACTION_ADDED
_In_ PUNICODE_STRING NewName
Definition: zwfuncs.h:1203
VOID Ext2ReleaseFcb(IN PEXT2_FCB Fcb)
Definition: memory.c:276
PVCB Vcb
Definition: cdstruc.h:939
NTSTATUS Ext2RemoveEntry(IN PEXT2_IRP_CONTEXT IrpContext, IN PEXT2_VCB Vcb, IN PEXT2_FCB Dcb, IN PEXT2_MCB Mcb)
Definition: generic.c:1954
#define DbgBreak()
Definition: ext2fs.h:46
#define DEBUG(args)
Definition: rdesktop.h:129
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
_In_ PFCB Fcb
Definition: cdprocs.h:151
return STATUS_SUCCESS
Definition: btrfs.c:2966

Referenced by Ext2SetFileInformation().

◆ Ext2TotalBlocks()

ULONG Ext2TotalBlocks ( PEXT2_VCB  Vcb,
PLARGE_INTEGER  Size,
PULONG  pMeta 
)

Definition at line 1072 of file fileinfo.c.

1077 {
1078  ULONG Blocks, Meta =0, Remain;
1079 
1080  Blocks = (ULONG)((Size->QuadPart + BLOCK_SIZE - 1) >> BLOCK_BITS);
1081  if (Blocks <= EXT2_NDIR_BLOCKS)
1082  goto errorout;
1083  Blocks -= EXT2_NDIR_BLOCKS;
1084 
1085  Meta += 1;
1086  if (Blocks <= Vcb->max_blocks_per_layer[1]) {
1087  goto errorout;
1088  }
1089  Blocks -= Vcb->max_blocks_per_layer[1];
1090 
1091 level2:
1092 
1093  if (Blocks <= Vcb->max_blocks_per_layer[2]) {
1094  Meta += 1 + ((Blocks + BLOCK_SIZE/4 - 1) >> (BLOCK_BITS - 2));
1095  goto errorout;
1096  }
1097  Meta += 1 + BLOCK_SIZE/4;
1098  Blocks -= Vcb->max_blocks_per_layer[2];
1099 
1100  if (Blocks > Vcb->max_blocks_per_layer[3]) {
1101  Blocks = Vcb->max_blocks_per_layer[3];
1102  }
1103 
1104  ASSERT(Vcb->max_blocks_per_layer[2]);
1105  Remain = Blocks % Vcb->max_blocks_per_layer[2];
1106  Blocks = Blocks / Vcb->max_blocks_per_layer[2];
1107  Meta += 1 + Blocks * (1 + BLOCK_SIZE/4);
1108  if (Remain) {
1109  Blocks = Remain;
1110  goto level2;
1111  }
1112 
1113 errorout:
1114 
1115  if (pMeta)
1116  *pMeta = Meta;
1117  Blocks = (ULONG)((Size->QuadPart + BLOCK_SIZE - 1) >> BLOCK_BITS);
1118  return (Blocks + Meta);
1119 }
#define BLOCK_BITS
Definition: stream.h:22
#define BLOCK_SIZE
Definition: dlist.c:220
#define EXT2_NDIR_BLOCKS
Definition: ext2_fs.h:177
#define Vcb
Definition: cdprocs.h:1425
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
unsigned int ULONG
Definition: retypes.h:1

Referenced by Ext2CreateFile().

◆ Ext2TruncateFile()

NTSTATUS Ext2TruncateFile ( PEXT2_IRP_CONTEXT  IrpContext,
PEXT2_VCB  Vcb,
PEXT2_MCB  Mcb,
PLARGE_INTEGER  Size 
)

Definition at line 1199 of file fileinfo.c.

1205 {
1207 
1208  if (INODE_HAS_EXTENT(&Mcb->Inode)) {
1209  status = Ext2TruncateExtent(IrpContext, Vcb, Mcb, Size);
1210  } else {
1211  status = Ext2TruncateIndirect(IrpContext, Vcb, Mcb, Size);
1212  }
1213 
1214  /* check and clear data/meta mcb extents */
1215  if (Size->QuadPart == 0) {
1216 
1217  /* check and remove all data extents */
1218  if (Ext2ListExtents(&Mcb->Extents)) {
1219  DbgBreak();
1220  }
1221  Ext2ClearAllExtents(&Mcb->Extents);
1222  /* check and remove all meta extents */
1223  if (Ext2ListExtents(&Mcb->MetaExts)) {
1224  DbgBreak();
1225  }
1226  Ext2ClearAllExtents(&Mcb->MetaExts);
1228  }
1229 
1230  return status;
1231 }
VOID Ext2ClearAllExtents(PLARGE_MCB Zone)
Definition: memory.c:637
LONG NTSTATUS
Definition: precomp.h:26
#define ClearLongFlag(_F, _SF)
Definition: ext2fs.h:254
#define Vcb
Definition: cdprocs.h:1425
#define INODE_HAS_EXTENT(i)
Definition: ext4_ext.h:228
BOOLEAN Ext2ListExtents(PLARGE_MCB Extents)
Definition: memory.c:558
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
#define MCB_ZONE_INITED
Definition: ext2fs.h:948
IN PVCB IN ULONG IN OUT PULONG IN BOOLEAN OUT PLARGE_MCB Mcb
Definition: fatprocs.h:334
#define DbgBreak()
Definition: ext2fs.h:46
NTSTATUS Ext2TruncateExtent(PEXT2_IRP_CONTEXT IrpContext, PEXT2_VCB Vcb, PEXT2_MCB Mcb, PLARGE_INTEGER Size)
Definition: extents.c:200
return STATUS_SUCCESS
Definition: btrfs.c:2966
static SERVICE_STATUS status
Definition: service.c:31
NTSTATUS Ext2TruncateIndirect(PEXT2_IRP_CONTEXT IrpContext, PEXT2_VCB Vcb, PEXT2_MCB Mcb, PLARGE_INTEGER Size)
Definition: indirect.c:1079
Definition: ps.c:97

Referenced by Ext2Cleanup(), Ext2CreateFile(), Ext2DeleteFile(), Ext2SetFileInformation(), Ext2SetReparsePoint(), Ext2SupersedeOrOverWriteFile(), Ext2TruncateSymlink(), and Ext2WriteSymlink().

Variable Documentation

◆ Ext2Global

PEXT2_GLOBAL Ext2Global

Definition at line 16 of file init.c.