[fastfat_new]
[reactos.git] / reactos / drivers / filesystems / fastfat_new / finfo.c
1 /*
2 * PROJECT: ReactOS FAT file system driver
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: drivers/filesystems/fastfat/finfo.c
5 * PURPOSE: File Information support routines
6 * PROGRAMMERS: Aleksey Bragin (aleksey@reactos.org)
7 */
8
9 /* INCLUDES *****************************************************************/
10
11 #define NDEBUG
12 #include "fastfat.h"
13
14 /* FUNCTIONS ****************************************************************/
15
16 VOID
17 NTAPI
18 FatiQueryStandardInformation(IN PFAT_IRP_CONTEXT IrpContext,
19 IN PFCB Fcb,
20 IN PFILE_OBJECT FileObject,
21 IN OUT PFILE_STANDARD_INFORMATION Buffer,
22 IN OUT PLONG Length)
23 {
24 /* Zero the buffer */
25 RtlZeroMemory(Buffer, sizeof(FILE_STANDARD_INFORMATION));
26
27 /* Deduct the written length */
28 *Length -= sizeof(FILE_STANDARD_INFORMATION);
29
30 Buffer->NumberOfLinks = 1;
31 Buffer->DeletePending = FALSE; // FIXME
32
33 /* Check if it's a dir or a file */
34 if (FatNodeType(Fcb) == FAT_NTC_FCB)
35 {
36 Buffer->Directory = FALSE;
37
38 Buffer->EndOfFile.LowPart = Fcb->FatHandle->Filesize;
39 Buffer->AllocationSize = Buffer->EndOfFile;
40 DPRINT1("Filesize %d, chain length %d\n", Fcb->FatHandle->Filesize, Fcb->FatHandle->iChainLength);
41 }
42 else
43 {
44 Buffer->Directory = TRUE;
45 }
46 }
47
48 VOID
49 NTAPI
50 FatiQueryInternalInformation(IN PFAT_IRP_CONTEXT IrpContext,
51 IN PFCB Fcb,
52 IN PFILE_OBJECT FileObject,
53 IN OUT PFILE_INTERNAL_INFORMATION Buffer,
54 IN OUT PLONG Length)
55 {
56 UNIMPLEMENTED;
57 }
58
59 NTSTATUS
60 NTAPI
61 FatiQueryInformation(IN PFAT_IRP_CONTEXT IrpContext,
62 IN PIRP Irp)
63 {
64 PFILE_OBJECT FileObject;
65 PIO_STACK_LOCATION IrpSp;
66 FILE_INFORMATION_CLASS InfoClass;
67 TYPE_OF_OPEN FileType;
68 PVCB Vcb;
69 PFCB Fcb;
70 PCCB Ccb;
71 LONG Length;
72 PVOID Buffer;
73 NTSTATUS Status = STATUS_SUCCESS;
74
75 /* Get IRP stack location */
76 IrpSp = IoGetCurrentIrpStackLocation(Irp);
77
78 /* Get the file object */
79 FileObject = IrpSp->FileObject;
80
81 /* Copy variables to something with shorter names */
82 InfoClass = IrpSp->Parameters.QueryFile.FileInformationClass;
83 Length = IrpSp->Parameters.QueryFile.Length;
84 Buffer = Irp->AssociatedIrp.SystemBuffer;
85
86 DPRINT1("FatiQueryInformation\n", 0);
87 DPRINT1("\tIrp = %08lx\n", Irp);
88 DPRINT1("\tLength = %08lx\n", Length);
89 DPRINT1("\tFileInformationClass = %08lx\n", InfoClass);
90 DPRINT1("\tBuffer = %08lx\n", Buffer);
91
92 FileType = FatDecodeFileObject(FileObject, &Vcb, &Fcb, &Ccb);
93
94 DPRINT1("Vcb %p, Fcb %p, Ccb %p, open type %d\n", Vcb, Fcb, Ccb, FileType);
95
96 // TODO: Acquire FCB locks
97
98 switch (InfoClass)
99 {
100 case FileStandardInformation:
101 FatiQueryStandardInformation(IrpContext, Fcb, FileObject, Buffer, &Length);
102 break;
103 case FileInternalInformation:
104 FatiQueryInternalInformation(IrpContext, Fcb, FileObject, Buffer, &Length);
105 break;
106 default:
107 DPRINT1("Unimplemented information class %d requested\n", InfoClass);
108 Status = STATUS_INVALID_PARAMETER;
109 }
110
111 /* Check for buffer overflow */
112 if (Length < 0)
113 {
114 Status = STATUS_BUFFER_OVERFLOW;
115 Length = 0;
116 }
117
118 /* Set IoStatus.Information to amount of filled bytes */
119 Irp->IoStatus.Information = IrpSp->Parameters.QueryFile.Length - Length;
120
121 // TODO: Release FCB locks
122
123 /* Complete request and return status */
124 FatCompleteRequest(IrpContext, Irp, Status);
125 return Status;
126 }
127
128 NTSTATUS
129 NTAPI
130 FatQueryInformation(PDEVICE_OBJECT DeviceObject, PIRP Irp)
131 {
132 NTSTATUS Status;
133 BOOLEAN TopLevel, CanWait;
134 PFAT_IRP_CONTEXT IrpContext;
135
136 CanWait = TRUE;
137 TopLevel = FALSE;
138 Status = STATUS_INVALID_DEVICE_REQUEST;
139
140 /* Get CanWait flag */
141 if (IoGetCurrentIrpStackLocation(Irp)->FileObject != NULL)
142 CanWait = IoIsOperationSynchronous(Irp);
143
144 /* Enter FsRtl critical region */
145 FsRtlEnterFileSystem();
146
147 /* Set Top Level IRP if not set */
148 if (IoGetTopLevelIrp() == NULL)
149 {
150 IoSetTopLevelIrp(Irp);
151 TopLevel = TRUE;
152 }
153
154 /* Build an irp context */
155 IrpContext = FatBuildIrpContext(Irp, CanWait);
156
157 /* Perform the actual read */
158 Status = FatiQueryInformation(IrpContext, Irp);
159
160 /* Restore top level Irp */
161 if (TopLevel) IoSetTopLevelIrp(NULL);
162
163 /* Leave FsRtl critical region */
164 FsRtlExitFileSystem();
165
166 return Status;
167 }
168
169 NTSTATUS
170 NTAPI
171 FatSetInformation(PDEVICE_OBJECT DeviceObject, PIRP Irp)
172 {
173 DPRINT1("FatSetInformation()\n");
174 return STATUS_NOT_IMPLEMENTED;
175 }
176
177 /* EOF */