ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

finfo.c
Go to the documentation of this file.
00001 /*
00002 *  ReactOS kernel
00003 *  Copyright (C) 2002, 2004 ReactOS Team
00004 *
00005 *  This program is free software; you can redistribute it and/or modify
00006 *  it under the terms of the GNU General Public License as published by
00007 *  the Free Software Foundation; either version 2 of the License, or
00008 *  (at your option) any later version.
00009 *
00010 *  This program is distributed in the hope that it will be useful,
00011 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 *  GNU General Public License for more details.
00014 *
00015 *  You should have received a copy of the GNU General Public License along
00016 *  with this program; if not, write to the Free Software Foundation, Inc.,
00017 *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00018 */
00019 /* $Id: finfo.c 53676 2011-09-10 21:31:09Z akhaldi $
00020 *
00021 * COPYRIGHT:        See COPYING in the top level directory
00022 * PROJECT:          ReactOS kernel
00023 * FILE:             services/fs/cdfs/finfo.c
00024 * PURPOSE:          CDROM (ISO 9660) filesystem driver
00025 * PROGRAMMER:       Art Yerkes
00026 *                   Eric Kohl
00027 * UPDATE HISTORY:
00028 */
00029 
00030 /* INCLUDES *****************************************************************/
00031 
00032 #include "cdfs.h"
00033 
00034 #define NDEBUG
00035 #include <debug.h>
00036 
00037 /* FUNCTIONS ****************************************************************/
00038 
00039 /*
00040 * FUNCTION: Retrieve the standard file information
00041 */
00042 static NTSTATUS
00043 CdfsGetStandardInformation(PFCB Fcb,
00044                            PDEVICE_OBJECT DeviceObject,
00045                            PFILE_STANDARD_INFORMATION StandardInfo,
00046                            PULONG BufferLength)
00047 {
00048     DPRINT("CdfsGetStandardInformation() called\n");
00049 
00050     if (*BufferLength < sizeof(FILE_STANDARD_INFORMATION))
00051         return STATUS_BUFFER_OVERFLOW;
00052 
00053     /* PRECONDITION */
00054     ASSERT(StandardInfo != NULL);
00055     ASSERT(Fcb != NULL);
00056 
00057     RtlZeroMemory(StandardInfo,
00058         sizeof(FILE_STANDARD_INFORMATION));
00059 
00060     if (CdfsFCBIsDirectory(Fcb))
00061     {
00062         StandardInfo->AllocationSize.QuadPart = 0LL;
00063         StandardInfo->EndOfFile.QuadPart = 0LL;
00064         StandardInfo->Directory = TRUE;
00065     }
00066     else
00067     {
00068         StandardInfo->AllocationSize = Fcb->RFCB.AllocationSize;
00069         StandardInfo->EndOfFile = Fcb->RFCB.FileSize;
00070         StandardInfo->Directory = FALSE;
00071     }
00072     StandardInfo->NumberOfLinks = 0;
00073     StandardInfo->DeletePending = FALSE;
00074 
00075     *BufferLength -= sizeof(FILE_STANDARD_INFORMATION);
00076     return(STATUS_SUCCESS);
00077 }
00078 
00079 
00080 /*
00081 * FUNCTION: Retrieve the file position information
00082 */
00083 static NTSTATUS
00084 CdfsGetPositionInformation(PFILE_OBJECT FileObject,
00085                            PFILE_POSITION_INFORMATION PositionInfo,
00086                            PULONG BufferLength)
00087 {
00088     DPRINT("CdfsGetPositionInformation() called\n");
00089 
00090     if (*BufferLength < sizeof(FILE_POSITION_INFORMATION))
00091         return STATUS_BUFFER_OVERFLOW;
00092 
00093     PositionInfo->CurrentByteOffset.QuadPart =
00094         FileObject->CurrentByteOffset.QuadPart;
00095 
00096     DPRINT("Getting position %I64x\n",
00097         PositionInfo->CurrentByteOffset.QuadPart);
00098 
00099     *BufferLength -= sizeof(FILE_POSITION_INFORMATION);
00100     return(STATUS_SUCCESS);
00101 }
00102 
00103 
00104 /*
00105 * FUNCTION: Retrieve the basic file information
00106 */
00107 static NTSTATUS
00108 CdfsGetBasicInformation(PFILE_OBJECT FileObject,
00109                         PFCB Fcb,
00110                         PDEVICE_OBJECT DeviceObject,
00111                         PFILE_BASIC_INFORMATION BasicInfo,
00112                         PULONG BufferLength)
00113 {
00114     DPRINT("CdfsGetBasicInformation() called\n");
00115 
00116     if (*BufferLength < sizeof(FILE_BASIC_INFORMATION))
00117         return STATUS_BUFFER_OVERFLOW;
00118 
00119     CdfsDateTimeToSystemTime(Fcb,
00120         &BasicInfo->CreationTime);
00121     CdfsDateTimeToSystemTime(Fcb,
00122         &BasicInfo->LastAccessTime);
00123     CdfsDateTimeToSystemTime(Fcb,
00124         &BasicInfo->LastWriteTime);
00125     CdfsDateTimeToSystemTime(Fcb,
00126         &BasicInfo->ChangeTime);
00127 
00128     CdfsFileFlagsToAttributes(Fcb,
00129         &BasicInfo->FileAttributes);
00130 
00131     *BufferLength -= sizeof(FILE_BASIC_INFORMATION);
00132 
00133     return(STATUS_SUCCESS);
00134 }
00135 
00136 
00137 /*
00138 * FUNCTION: Retrieve the file name information
00139 */
00140 static NTSTATUS
00141 CdfsGetNameInformation(PFILE_OBJECT FileObject,
00142                        PFCB Fcb,
00143                        PDEVICE_OBJECT DeviceObject,
00144                        PFILE_NAME_INFORMATION NameInfo,
00145                        PULONG BufferLength)
00146 {
00147     ULONG NameLength;
00148     ULONG BytesToCopy;
00149 
00150     DPRINT("CdfsGetNameInformation() called\n");
00151 
00152     ASSERT(NameInfo != NULL);
00153     ASSERT(Fcb != NULL);
00154 
00155     /* If buffer can't hold at least the file name length, bail out */
00156     if (*BufferLength < (ULONG)FIELD_OFFSET(FILE_NAME_INFORMATION, FileName[0]))
00157         return STATUS_BUFFER_OVERFLOW;
00158 
00159     /* Calculate file name length in bytes */
00160     NameLength = wcslen(Fcb->PathName) * sizeof(WCHAR);
00161     NameInfo->FileNameLength = NameLength;
00162 
00163     /* Calculate amount of bytes to copy not to overflow the buffer */
00164     BytesToCopy = min(NameLength,
00165         *BufferLength - FIELD_OFFSET(FILE_NAME_INFORMATION, FileName[0]));
00166 
00167     /* Fill in the bytes */
00168     RtlCopyMemory(NameInfo->FileName, Fcb->PathName, BytesToCopy);
00169 
00170     /* Check if we could write more but are not able to */
00171     if (*BufferLength < NameLength + FIELD_OFFSET(FILE_NAME_INFORMATION, FileName[0]))
00172     {
00173         /* Return number of bytes written */
00174         *BufferLength -= FIELD_OFFSET(FILE_NAME_INFORMATION, FileName[0]) + BytesToCopy;
00175         return STATUS_BUFFER_OVERFLOW;
00176     }
00177 
00178     /* We filled up as many bytes, as needed */
00179     *BufferLength -= (FIELD_OFFSET(FILE_NAME_INFORMATION, FileName[0]) + NameLength);
00180 
00181     return STATUS_SUCCESS;
00182 }
00183 
00184 
00185 /*
00186 * FUNCTION: Retrieve the internal file information
00187 */
00188 static NTSTATUS
00189 CdfsGetInternalInformation(PFCB Fcb,
00190                            PFILE_INTERNAL_INFORMATION InternalInfo,
00191                            PULONG BufferLength)
00192 {
00193     DPRINT("CdfsGetInternalInformation() called\n");
00194 
00195     ASSERT(InternalInfo);
00196     ASSERT(Fcb);
00197 
00198     if (*BufferLength < sizeof(FILE_INTERNAL_INFORMATION))
00199         return(STATUS_BUFFER_OVERFLOW);
00200 
00201     InternalInfo->IndexNumber.QuadPart = Fcb->IndexNumber.QuadPart;
00202 
00203     *BufferLength -= sizeof(FILE_INTERNAL_INFORMATION);
00204 
00205     return(STATUS_SUCCESS);
00206 }
00207 
00208 
00209 /*
00210 * FUNCTION: Retrieve the file network open information
00211 */
00212 static NTSTATUS
00213 CdfsGetNetworkOpenInformation(PFCB Fcb,
00214                               PFILE_NETWORK_OPEN_INFORMATION NetworkInfo,
00215                               PULONG BufferLength)
00216 {
00217     ASSERT(NetworkInfo);
00218     ASSERT(Fcb);
00219 
00220     if (*BufferLength < sizeof(FILE_NETWORK_OPEN_INFORMATION))
00221         return(STATUS_BUFFER_OVERFLOW);
00222 
00223     CdfsDateTimeToSystemTime(Fcb,
00224         &NetworkInfo->CreationTime);
00225     CdfsDateTimeToSystemTime(Fcb,
00226         &NetworkInfo->LastAccessTime);
00227     CdfsDateTimeToSystemTime(Fcb,
00228         &NetworkInfo->LastWriteTime);
00229     CdfsDateTimeToSystemTime(Fcb,
00230         &NetworkInfo->ChangeTime);
00231     if (CdfsFCBIsDirectory(Fcb))
00232     {
00233         NetworkInfo->AllocationSize.QuadPart = 0LL;
00234         NetworkInfo->EndOfFile.QuadPart = 0LL;
00235     }
00236     else
00237     {
00238         NetworkInfo->AllocationSize = Fcb->RFCB.AllocationSize;
00239         NetworkInfo->EndOfFile = Fcb->RFCB.FileSize;
00240     }
00241     CdfsFileFlagsToAttributes(Fcb,
00242         &NetworkInfo->FileAttributes);
00243 
00244     *BufferLength -= sizeof(FILE_NETWORK_OPEN_INFORMATION);
00245 
00246     return(STATUS_SUCCESS);
00247 }
00248 
00249 
00250 /*
00251 * FUNCTION: Retrieve all file information
00252 */
00253 static NTSTATUS
00254 CdfsGetAllInformation(PFILE_OBJECT FileObject,
00255                       PFCB Fcb,
00256                       PFILE_ALL_INFORMATION Info,
00257                       PULONG BufferLength)
00258 {
00259     ULONG NameLength;
00260 
00261     ASSERT(Info);
00262     ASSERT(Fcb);
00263 
00264     NameLength = wcslen(Fcb->PathName) * sizeof(WCHAR);
00265     if (*BufferLength < sizeof(FILE_ALL_INFORMATION) + NameLength)
00266         return(STATUS_BUFFER_OVERFLOW);
00267 
00268     /* Basic Information */
00269     CdfsDateTimeToSystemTime(Fcb,
00270         &Info->BasicInformation.CreationTime);
00271     CdfsDateTimeToSystemTime(Fcb,
00272         &Info->BasicInformation.LastAccessTime);
00273     CdfsDateTimeToSystemTime(Fcb,
00274         &Info->BasicInformation.LastWriteTime);
00275     CdfsDateTimeToSystemTime(Fcb,
00276         &Info->BasicInformation.ChangeTime);
00277     CdfsFileFlagsToAttributes(Fcb,
00278         &Info->BasicInformation.FileAttributes);
00279 
00280     /* Standard Information */
00281     if (CdfsFCBIsDirectory(Fcb))
00282     {
00283         Info->StandardInformation.AllocationSize.QuadPart = 0LL;
00284         Info->StandardInformation.EndOfFile.QuadPart = 0LL;
00285         Info->StandardInformation.Directory = TRUE;
00286     }
00287     else
00288     {
00289         Info->StandardInformation.AllocationSize = Fcb->RFCB.AllocationSize;
00290         Info->StandardInformation.EndOfFile = Fcb->RFCB.FileSize;
00291         Info->StandardInformation.Directory = FALSE;
00292     }
00293     Info->StandardInformation.NumberOfLinks = 0;
00294     Info->StandardInformation.DeletePending = FALSE;
00295 
00296     /* Internal Information */
00297     Info->InternalInformation.IndexNumber.QuadPart = Fcb->IndexNumber.QuadPart;
00298 
00299     /* EA Information */
00300     Info->EaInformation.EaSize = 0;
00301 
00302     /* Access Information */
00303     /* The IO-Manager adds this information */
00304 
00305     /* Position Information */
00306     Info->PositionInformation.CurrentByteOffset.QuadPart = FileObject->CurrentByteOffset.QuadPart;
00307 
00308     /* Mode Information */
00309     /* The IO-Manager adds this information */
00310 
00311     /* Alignment Information */
00312     /* The IO-Manager adds this information */
00313 
00314     /* Name Information */
00315     Info->NameInformation.FileNameLength = NameLength;
00316     RtlCopyMemory(Info->NameInformation.FileName,
00317         Fcb->PathName,
00318         NameLength + sizeof(WCHAR));
00319 
00320     *BufferLength -= (sizeof(FILE_ALL_INFORMATION) + NameLength + sizeof(WCHAR));
00321 
00322     return STATUS_SUCCESS;
00323 }
00324 
00325 
00326 /*
00327 * FUNCTION: Retrieve the specified file information
00328 */
00329 NTSTATUS NTAPI
00330 CdfsQueryInformation(PDEVICE_OBJECT DeviceObject,
00331                      PIRP Irp)
00332 {
00333     FILE_INFORMATION_CLASS FileInformationClass;
00334     PIO_STACK_LOCATION Stack;
00335     PFILE_OBJECT FileObject;
00336     PFCB Fcb;
00337     PVOID SystemBuffer;
00338     ULONG BufferLength;
00339 
00340     NTSTATUS Status = STATUS_SUCCESS;
00341 
00342     DPRINT("CdfsQueryInformation() called\n");
00343 
00344     Stack = IoGetCurrentIrpStackLocation(Irp);
00345     FileInformationClass = Stack->Parameters.QueryFile.FileInformationClass;
00346     FileObject = Stack->FileObject;
00347     Fcb = FileObject->FsContext;
00348 
00349     SystemBuffer = Irp->AssociatedIrp.SystemBuffer;
00350     BufferLength = Stack->Parameters.QueryFile.Length;
00351 
00352     switch (FileInformationClass)
00353     {
00354     case FileStandardInformation:
00355         Status = CdfsGetStandardInformation(Fcb,
00356             DeviceObject,
00357             SystemBuffer,
00358             &BufferLength);
00359         break;
00360 
00361     case FilePositionInformation:
00362         Status = CdfsGetPositionInformation(FileObject,
00363             SystemBuffer,
00364             &BufferLength);
00365         break;
00366 
00367     case FileBasicInformation:
00368         Status = CdfsGetBasicInformation(FileObject,
00369             Fcb,
00370             DeviceObject,
00371             SystemBuffer,
00372             &BufferLength);
00373         break;
00374 
00375     case FileNameInformation:
00376         Status = CdfsGetNameInformation(FileObject,
00377             Fcb,
00378             DeviceObject,
00379             SystemBuffer,
00380             &BufferLength);
00381         break;
00382 
00383     case FileInternalInformation:
00384         Status = CdfsGetInternalInformation(Fcb,
00385             SystemBuffer,
00386             &BufferLength);
00387         break;
00388 
00389     case FileNetworkOpenInformation:
00390         Status = CdfsGetNetworkOpenInformation(Fcb,
00391             SystemBuffer,
00392             &BufferLength);
00393         break;
00394 
00395     case FileAllInformation:
00396         Status = CdfsGetAllInformation(FileObject,
00397             Fcb,
00398             SystemBuffer,
00399             &BufferLength);
00400         break;
00401 
00402     case FileAlternateNameInformation:
00403         Status = STATUS_NOT_IMPLEMENTED;
00404         break;
00405 
00406     default:
00407         DPRINT("Unimplemented information class %u\n", FileInformationClass);
00408         Status = STATUS_INVALID_PARAMETER;
00409         break;
00410     }
00411 
00412     Irp->IoStatus.Status = Status;
00413     if (NT_SUCCESS(Status) || Status == STATUS_BUFFER_OVERFLOW)
00414         Irp->IoStatus.Information =
00415         Stack->Parameters.QueryFile.Length - BufferLength;
00416     else
00417         Irp->IoStatus.Information = 0;
00418 
00419     IoCompleteRequest(Irp, IO_NO_INCREMENT);
00420 
00421     return(Status);
00422 }
00423 
00424 
00425 /*
00426 * FUNCTION: Set the file position information
00427 */
00428 static NTSTATUS
00429 CdfsSetPositionInformation(PFILE_OBJECT FileObject,
00430                            PFILE_POSITION_INFORMATION PositionInfo)
00431 {
00432     DPRINT ("CdfsSetPositionInformation()\n");
00433 
00434     DPRINT ("PositionInfo %x\n", PositionInfo);
00435     DPRINT ("Setting position %I64u\n", PositionInfo->CurrentByteOffset.QuadPart);
00436 
00437     FileObject->CurrentByteOffset.QuadPart =
00438         PositionInfo->CurrentByteOffset.QuadPart;
00439 
00440     return STATUS_SUCCESS;
00441 }
00442 
00443 
00444 /*
00445 * FUNCTION: Set the specified file information
00446 */
00447 NTSTATUS NTAPI
00448 CdfsSetInformation(PDEVICE_OBJECT DeviceObject,
00449                    PIRP Irp)
00450 {
00451     FILE_INFORMATION_CLASS FileInformationClass;
00452     PIO_STACK_LOCATION Stack;
00453     PFILE_OBJECT FileObject;
00454     PVOID SystemBuffer;
00455 
00456     NTSTATUS Status = STATUS_SUCCESS;
00457 
00458     DPRINT("CdfsSetInformation() called\n");
00459 
00460     Stack = IoGetCurrentIrpStackLocation(Irp);
00461     FileInformationClass = Stack->Parameters.SetFile.FileInformationClass;
00462     FileObject = Stack->FileObject;
00463 
00464     SystemBuffer = Irp->AssociatedIrp.SystemBuffer;
00465 
00466     switch (FileInformationClass)
00467     {
00468     case FilePositionInformation:
00469         Status = CdfsSetPositionInformation(FileObject,
00470             SystemBuffer);
00471         break;
00472 
00473     case FileBasicInformation:
00474     case FileRenameInformation:
00475         Status = STATUS_NOT_IMPLEMENTED;
00476         break;
00477 
00478     default:
00479         Status = STATUS_NOT_SUPPORTED;
00480         break;
00481     }
00482 
00483     Irp->IoStatus.Status = Status;
00484     Irp->IoStatus.Information = 0;
00485 
00486     IoCompleteRequest(Irp, IO_NO_INCREMENT);
00487 
00488     return Status;
00489 }
00490 
00491 /* EOF */

Generated on Sun May 27 2012 04:27:35 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.