fs-win.cpp revision 922fb31280a8b013eca26bc49b3750979b3db6f0
/* $Id$ */
/** @file
* IPRT - File System, Win32.
*/
/*
* Copyright (C) 2006-2007 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*
* The contents of this file may alternatively be used under the terms
* of the Common Development and Distribution License Version 1.0
* (CDDL) only, as it comes in the "COPYING.CDDL" file of the
* VirtualBox OSE distribution, in which case the provisions of the
* CDDL are applicable instead of those of the GPL.
*
* You may elect to license modified versions of this file under the
* terms and conditions of either the GPL or the CDDL or both.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#define LOG_GROUP RTLOGGROUP_FS
#include <windows.h>
/* from ntdef.h */
/* from ntddk.h */
typedef struct _IO_STATUS_BLOCK {
union {
};
typedef enum _FSINFOCLASS {
/* from ntifs.h */
typedef struct _FILE_FS_ATTRIBUTE_INFORMATION {
extern "C" NTSTATUS NTAPI NtQueryVolumeInformationFile(HANDLE, PIO_STATUS_BLOCK, PVOID, ULONG, FS_INFORMATION_CLASS);
/**
* Checks quickly if this is an correct root specification.
* Root specs ends with a slash of some kind.
*
* @returns indicator.
* @param pszFsPath Path to check.
*/
static bool rtFsIsRoot(const char *pszFsPath)
{
/*
* UNC has exactly two slashes..
*
* Anything else starting with slashe(s) requires
* expansion and will have to take the long road.
*/
if (RTPATH_IS_SLASH(pszFsPath[0]))
{
return false;
/* end of machine name */
if (!pszSlash)
return false;
/* end of service name. */
if (!pszSlash)
return false;
}
/*
* Ok the other alternative is driver letter.
*/
&& !pszFsPath[3];
}
/**
* Finds the root of the specified volume.
*
* @returns iprt status code.
* @param pszFsPath Path within the filesystem. Verified as one byte or more.
* @param ppwszFsRoot Where to store the returned string. Free with rtFsFreeRoot(),
*/
{
/*
* Do straight forward stuff first,
*/
if (rtFsIsRoot(pszFsPath))
/*
* Expand and add slash (if required).
*/
char szFullPath[RTPATH_MAX];
if (RT_FAILURE(rc))
return rc;
{
}
/*
* Convert the path.
*/
if (RT_FAILURE(rc))
/*
* Walk the path until our proper API is happy or there is no more path left.
*/
{
do
{
/* Strip off the last path component. */
if (RTPATH_IS_SLASH(*pwszEnd))
break;
AssertReturn(pwszEnd >= pwszMin, VERR_INTERNAL_ERROR); /* leaks, but that's irrelevant for an internal error. */
}
return VINF_SUCCESS;
}
/**
* Frees string returned by rtFsGetRoot().
*/
{
}
{
/*
* Validate & get valid root path.
*/
if (RT_FAILURE(rc))
return rc;
/*
* Free and total.
*/
{
{
if (pcbTotal)
if (pcbFree)
}
else
{
Log(("RTFsQuerySizes(%s,): GetDiskFreeSpaceEx failed with lasterr %d (%Rrc)\n",
}
}
/*
* Block and sector size.
*/
if ( RT_SUCCESS(rc)
{
{
if (pcbBlock)
if (pcbSector)
}
else
{
Log(("RTFsQuerySizes(%s,): GetDiskFreeSpace failed with lasterr %d (%Rrc)\n",
}
}
return rc;
}
/**
* Query the serial number of a filesystem.
*
* @returns iprt status code.
* @param pszFsPath Path within the mounted filesystem.
* @param pu32Serial Where to store the serial number.
*/
{
/*
* Validate & get valid root path.
*/
if (RT_FAILURE(rc))
return rc;
/*
* Do work.
*/
*pu32Serial = dwSerial;
else
{
Log(("RTFsQuerySizes(%s,): GetDiskFreeSpaceEx failed with lasterr %d (%Rrc)\n",
}
return rc;
}
/**
* Query the properties of a mounted filesystem.
*
* @returns iprt status code.
* @param pszFsPath Path within the mounted filesystem.
* @param pProperties Where to store the properties.
*/
{
/*
* Validate & get valid root path.
*/
if (RT_FAILURE(rc))
return rc;
/*
* Do work.
*/
{
}
else
{
Log(("RTFsQuerySizes(%s,): GetVolumeInformation failed with lasterr %d (%Rrc)\n",
}
return rc;
}
{
int rc = VINF_SUCCESS;
NULL,
NULL);
if (hFile != INVALID_HANDLE_VALUE)
{
char abBuf[8192];
if (rcNt >= 0)
{
/* This is either FAT32 or FAT12/16. IMO it doesn't make
* sense to distinguish more detailed because we cannot
* easily distinguish between these FAT types on Linux
* and users who put some image file on an FAT16 partition
* should know what they are doing. */
}
/* else: Is RTFS_FS_UNKNOWN suffient or should we return an error? */
}
return rc;
}