nsFileSpec::GetDiskSpace now returns a PRUint64. (12479)

thanks to Chet Murphy <cmurphy@modelworks.com> for the windows code!
This commit is contained in:
dougt%netscape.com 1999-09-09 19:20:35 +00:00
parent 868e1692ef
commit 41a7fa078c
15 changed files with 90 additions and 48 deletions

View File

@ -536,7 +536,7 @@ nsPrefMigration::CheckForSpace(nsFileSpec newProfilePath, PRFloat64 requiredSpac
{
// nsFileSpec drive(newProfilePath);
if (newProfilePath.GetDiskSpaceAvailable() < requiredSpace)
if (LL_CMP(newProfilePath.GetDiskSpaceAvailable(), <, requiredSpace))
return NS_ERROR_FAILURE;
return NS_OK;
}

View File

@ -143,7 +143,7 @@ class nsFileSpecWithUIImpl
{ return mBaseFileSpec ? mBaseFileSpec->GetFileSize(aFileSize) : NS_ERROR_NOT_INITIALIZED; }
/* readonly attribute unsigned long DiskSpaceAvailable; */
NS_IMETHOD GetDiskSpaceAvailable(PRUint32 *aDiskSpaceAvailable)
NS_IMETHOD GetDiskSpaceAvailable(PRUint64 *aDiskSpaceAvailable)
{ return mBaseFileSpec ? mBaseFileSpec->GetDiskSpaceAvailable(aDiskSpaceAvailable) : NS_ERROR_NOT_INITIALIZED; }
/* nsIFileSpec AppendRelativeUnixPath (in string relativePath); */

View File

@ -93,7 +93,7 @@ class nsFileSpecWithUIImpl
NS_IMETHOD GetFileSize(PRUint32 *aFileSize);
/* readonly attribute unsigned long DiskSpaceAvailable; */
NS_IMETHOD GetDiskSpaceAvailable(PRUint32 *aDiskSpaceAvailable);
NS_IMETHOD GetDiskSpaceAvailable(PRUint64 *aDiskSpaceAvailable);
/* nsIFileSpec AppendRelativeUnixPath (in string relativePath); */
NS_IMETHOD AppendRelativeUnixPath(const char *relativePath);

View File

@ -112,7 +112,7 @@
#include "nsError.h"
#include "nsString.h"
#include "nsCRT.h"
#include "prtypes.h"
//========================================================================================
// Compiler-specific macros, as needed
//========================================================================================
@ -418,7 +418,7 @@ class NS_COM nsFileSpec
}
PRUint32 GetFileSize() const;
PRUint32 GetDiskSpaceAvailable() const;
PRUint64 GetDiskSpaceAvailable() const;
nsFileSpec operator + (const char* inRelativeUnixPath) const;
nsFileSpec operator + (const nsString& inRelativeUnixPath) const

View File

@ -421,33 +421,37 @@ nsresult nsFileSpec::Execute(const char* inArgs ) const
} // nsFileSpec::Execute
//----------------------------------------------------------------------------------------
PRUint32 nsFileSpec::GetDiskSpaceAvailable() const
PRUint64 nsFileSpec::GetDiskSpaceAvailable() const
//----------------------------------------------------------------------------------------
{
PRUint64 int64;
LL_I2L(int64 , ULONG_MAX);
char curdir [MAXPATHLEN];
if (!mPath || !*mPath)
{
(void) getcwd(curdir, MAXPATHLEN);
if (!curdir)
return ULONG_MAX; /* hope for the best as we did in cheddar */
return int64; /* hope for the best as we did in cheddar */
}
else
sprintf(curdir, "%.200s", (const char*)mPath);
BEntry e(curdir);
if(e.InitCheck() != B_OK)
return ULONG_MAX; /* hope for the best as we did in cheddar */
return int64; /* hope for the best as we did in cheddar */
entry_ref ref;
e.GetRef(&ref);
BVolume v(ref.device);
// HACK!!!
PRUint32 space = v.FreeBytes() > (int64)(ULONG_MAX) ? ULONG_MAX : (int32)v.FreeBytes();
LL_I2L(int64 , (v.FreeBytes() > (int64)(ULONG_MAX) ? ULONG_MAX : (int32)v.FreeBytes()));
#ifdef DEBUG_DISK_SPACE
printf("DiskSpaceAvailable: %d bytes\n", space);
#endif
return space;
return int64;
} // nsFileSpec::GetDiskSpace()
//========================================================================================

View File

@ -344,7 +344,7 @@ NS_IMETHODIMP nsFileSpecImpl::GetFileSize(PRUint32 *aFileSize)
}
//----------------------------------------------------------------------------------------
NS_IMETHODIMP nsFileSpecImpl::GetDiskSpaceAvailable(PRUint32 *aDiskSpaceAvailable)
NS_IMETHODIMP nsFileSpecImpl::GetDiskSpaceAvailable(PRUint64 *aDiskSpaceAvailable)
//----------------------------------------------------------------------------------------
{
TEST_OUT_PTR(aDiskSpaceAvailable)

View File

@ -1105,9 +1105,13 @@ OSErr nsFileSpec::GetFileTypeAndCreator(OSType* type, OSType* creator)
//----------------------------------------------------------------------------------------
PRUint32 nsFileSpec::GetDiskSpaceAvailable() const
PRUint64 nsFileSpec::GetDiskSpaceAvailable() const
//----------------------------------------------------------------------------------------
{
PRUint64 int64;
LL_I2L(int64 , ULONG_MAX);
HVolumeParam pb;
pb.ioCompletion = nsnull;
pb.ioVolIndex = 0;
@ -1117,8 +1121,9 @@ PRUint32 nsFileSpec::GetDiskSpaceAvailable() const
OSErr err = PBHGetVInfoSync( (HParmBlkPtr)&pb );
if ( err == noErr )
return pb.ioVFrBlk * pb.ioVAlBlkSiz;
return ULONG_MAX;
LL_I2L(int64 , (pb.ioVFrBlk * pb.ioVAlBlkSiz));
return int64;
} // nsFileSpec::GetDiskSpace()
//----------------------------------------------------------------------------------------

View File

@ -244,7 +244,7 @@ PRUint32 nsFileSpec::GetFileSize() const
// Okay, this is a really weird place to put this method!
// And it ought to return a PRUint64.
//
PRUint32 nsFileSpec::GetDiskSpaceAvailable() const
PRUint64 nsFileSpec::GetDiskSpaceAvailable() const
{
ULONG ulDriveNo = toupper(mPath[0]) + 1 - 'A';
FSALLOCATE fsAllocate = { 0 };
@ -261,8 +261,12 @@ PRUint32 nsFileSpec::GetDiskSpaceAvailable() const
fsAllocate.cSectorUnit *
fsAllocate.cbSector;
}
PRUint64 int64;
return cbAvail;
LL_I2L(int64 , cbAvail);
return int64;
}
void nsFileSpec::GetParent( nsFileSpec &outSpec) const

View File

@ -474,9 +474,11 @@ nsresult nsFileSpec::Execute(const char* inArgs ) const
} // nsFileSpec::Execute
//----------------------------------------------------------------------------------------
PRUint32 nsFileSpec::GetDiskSpaceAvailable() const
PRUint64 nsFileSpec::GetDiskSpaceAvailable() const
//----------------------------------------------------------------------------------------
{
PRUint64 int64;
LL_I2L(int64 , ULONG_MAX);
#if defined(HAVE_SYS_STATFS_H) || defined(HAVE_SYS_STATVFS_H)
@ -485,7 +487,7 @@ PRUint32 nsFileSpec::GetDiskSpaceAvailable() const
{
(void) getcwd(curdir, MAXPATHLEN);
if (!curdir)
return ULONG_MAX; /* hope for the best as we did in cheddar */
return int64; /* hope for the best as we did in cheddar */
}
else
sprintf(curdir, "%.200s", (const char*)mPath);
@ -496,21 +498,22 @@ PRUint32 nsFileSpec::GetDiskSpaceAvailable() const
#else
if (STATFS(curdir, &fs_buf) < 0)
#endif
return ULONG_MAX; /* hope for the best as we did in cheddar */
return int64; /* hope for the best as we did in cheddar */
#ifdef DEBUG_DISK_SPACE
printf("DiskSpaceAvailable: %d bytes\n",
fs_buf.f_bsize * (fs_buf.f_bavail - 1));
#endif
return fs_buf.f_bsize * (fs_buf.f_bavail - 1);
LL_I2L( int64 , (fs_buf.f_bsize * (fs_buf.f_bavail - 1) ) );
return int64
#else
/*
** This platform doesn't have statfs or statvfs, so we don't have much
** choice but to "hope for the best as we did in cheddar".
*/
return ULONG_MAX;
return int64;
#endif /* HAVE_SYS_STATFS_H or HAVE_SYS_STATVFS_H */
} // nsFileSpec::GetDiskSpace()

View File

@ -549,11 +549,16 @@ nsresult nsFileSpec::Execute(const char* inArgs ) const
return NS_FILE_FAILURE;
} // nsFileSpec::Execute
//----------------------------------------------------------------------------------------
PRUint32 nsFileSpec::GetDiskSpaceAvailable() const
PRUint64 nsFileSpec::GetDiskSpaceAvailable() const
//----------------------------------------------------------------------------------------
{
char aDrive[_MAX_DRIVE + 2];
PRUint64 int64;
LL_I2L(int64 , ULONG_MAX);
char aDrive[_MAX_DRIVE + 2];
_splitpath( (const char*)mPath, aDrive, NULL, NULL, NULL);
if (aDrive[0] == '\0')
@ -569,28 +574,49 @@ PRUint32 nsFileSpec::GetDiskSpaceAvailable() const
else
{
// Return bogus large number and hope for the best
return ULONG_MAX;
return int64;
}
}
strcat(aDrive, "\\");
DWORD dwSectorsPerCluster = 0;
DWORD dwBytesPerSector = 0;
DWORD dwFreeClusters = 0;
DWORD dwTotalClusters = 0;
if (!GetDiskFreeSpace(aDrive,
&dwSectorsPerCluster,
&dwBytesPerSector,
&dwFreeClusters,
&dwTotalClusters))
{
return ULONG_MAX; // Return bogus large number and hope for the best
}
// Check disk space
DWORD dwSecPerClus, dwBytesPerSec, dwFreeClus, dwTotalClus;
ULARGE_INTEGER liFreeBytesAvailableToCaller, liTotalNumberOfBytes, liTotalNumberOfFreeBytes;
double nBytes = 0;
BOOL (WINAPI* getDiskFreeSpaceExA)(LPCTSTR lpDirectoryName,
PULARGE_INTEGER lpFreeBytesAvailableToCaller,
PULARGE_INTEGER lpTotalNumberOfBytes,
PULARGE_INTEGER lpTotalNumberOfFreeBytes) = NULL;
HINSTANCE hInst = LoadLibrary("KERNEL32.DLL");
NS_ASSERTION(hInst != NULL, "COULD NOT LOAD KERNEL32.DLL");
if (hInst != NULL)
{
getDiskFreeSpaceExA = (BOOL (WINAPI*)(LPCTSTR lpDirectoryName,
PULARGE_INTEGER lpFreeBytesAvailableToCaller,
PULARGE_INTEGER lpTotalNumberOfBytes,
PULARGE_INTEGER lpTotalNumberOfFreeBytes))
GetProcAddress(hInst, "GetDiskFreeSpaceExA");
FreeLibrary(hInst);
}
if (getDiskFreeSpaceExA && (*getDiskFreeSpaceExA)(aDrive,
&liFreeBytesAvailableToCaller,
&liTotalNumberOfBytes,
&liTotalNumberOfFreeBytes))
{
nBytes = (double)(signed __int64)liFreeBytesAvailableToCaller.QuadPart;
}
else if ( GetDiskFreeSpace(aDrive, &dwSecPerClus, &dwBytesPerSec, &dwFreeClus, &dwTotalClus))
{
nBytes = (double)dwFreeClus*(double)dwSecPerClus*(double) dwBytesPerSec;
}
return (PRUint64)nBytes;
}
// We can now figure free disk space.
return dwFreeClusters * dwSectorsPerCluster * dwBytesPerSector;
} // nsFileSpec::GetDiskSpaceAvailable()
//========================================================================================
// nsDirectoryIterator

View File

@ -157,7 +157,7 @@ interface nsIFile : nsISupports
readonly attribute unsigned long fileSizeOfLink;
readonly attribute unsigned long diskSpaceAvailable; // maybe we should put this somewhere else.
readonly attribute unsigned long long diskSpaceAvailable; // maybe we should put this somewhere else.
/**
* Parent will be nsnull when this is at the top of the volume.

View File

@ -647,7 +647,7 @@ nsInstall::DeleteFile(const nsString& aFolder, const nsString& aRelativeFileName
}
PRInt32
nsInstall::DiskSpaceAvailable(const nsString& aFolder, PRUint32* aReturn)
nsInstall::DiskSpaceAvailable(const nsString& aFolder, PRUint64* aReturn)
{
nsFileSpec fsFolder(aFolder);
@ -1574,7 +1574,7 @@ nsInstall::FileOpFileGetNativeVersion(nsFileSpec& aTarget, nsString* aReturn)
}
PRInt32
nsInstall::FileOpFileGetDiskSpaceAvailable(nsFileSpec& aTarget, PRUint32* aReturn)
nsInstall::FileOpFileGetDiskSpaceAvailable(nsFileSpec& aTarget, PRUint64* aReturn)
{
*aReturn = aTarget.GetDiskSpaceAvailable();
return NS_OK;

View File

@ -180,7 +180,7 @@ class nsInstall
PRInt32 DeleteComponent(const nsString& aRegistryName, PRInt32* aReturn);
PRInt32 DeleteFile(const nsString& aFolder, const nsString& aRelativeFileName, PRInt32* aReturn);
PRInt32 DiskSpaceAvailable(const nsString& aFolder, PRUint32* aReturn);
PRInt32 DiskSpaceAvailable(const nsString& aFolder, PRUint64* aReturn);
PRInt32 Execute(const nsString& aJarSource, const nsString& aArgs, PRInt32* aReturn);
PRInt32 Execute(const nsString& aJarSource, PRInt32* aReturn);
PRInt32 FinalizeInstall(PRInt32* aReturn);
@ -209,7 +209,7 @@ class nsInstall
PRInt32 FileOpFileExists(nsFileSpec& aTarget, PRBool* aReturn);
PRInt32 FileOpFileExecute(nsFileSpec& aTarget, nsString& aParams, PRInt32* aReturn);
PRInt32 FileOpFileGetNativeVersion(nsFileSpec& aTarget, nsString* aReturn);
PRInt32 FileOpFileGetDiskSpaceAvailable(nsFileSpec& aTarget, PRUint32* aReturn);
PRInt32 FileOpFileGetDiskSpaceAvailable(nsFileSpec& aTarget, PRUint64* aReturn);
PRInt32 FileOpFileGetModDate(nsFileSpec& aTarget, nsFileSpec::TimeStamp* aReturn);
PRInt32 FileOpFileGetSize(nsFileSpec& aTarget, PRUint32* aReturn);
PRInt32 FileOpFileIsDirectory(nsFileSpec& aTarget, PRBool* aReturn);

View File

@ -640,7 +640,7 @@ PR_STATIC_CALLBACK(JSBool)
InstallDiskSpaceAvailable(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsInstall *nativeThis = (nsInstall*)JS_GetPrivate(cx, obj);
PRUint32 nativeRet;
PRUint64 nativeRet;
nsAutoString b0;
*rval = JSVAL_NULL;
@ -1748,7 +1748,7 @@ PR_STATIC_CALLBACK(JSBool)
InstallFileOpFileGetDiskSpaceAvailable(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsInstall* nativeThis = (nsInstall*)JS_GetPrivate(cx, obj);
PRUint32 nativeRet;
PRUint64 nativeRet;
nsAutoString b0;
*rval = JSVAL_NULL;

View File

@ -353,7 +353,7 @@ extern "C" void RunInstallOnThread(void *data)
args.GetUnicode(),
&rt, &cx, &glob);
if (NS_FAILED(rv))
goto bail;
goto bail; // TODO need to log that this failed!
// Go ahead and run!!
jsval rval;