Skip to content
Snippets Groups Projects
Commit ae44ab15 authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
Browse files

Support larger file systems (>4GB size/space) using uint64_t through-out

getdirsize() is maxed out at size_t, so return that type
parent 27fbf257
No related branches found
No related tags found
1 merge request!463MRC mods by Codefenix (2024-10-20)
Pipeline #3777 passed
......@@ -345,7 +345,7 @@ int32_t * sbbs_t::getintvar(csi_t *bin, uint32_t name)
case 0x4569c62e:
return((int32_t *)&cfg.expired_rest);
case 0xfcf3542e:
sysvar_l[sysvar_li]=cfg.min_dspace;
sysvar_l[sysvar_li]=(int32_t)(cfg.min_dspace / 1024);
break;
case 0xcf9ce02c:
sysvar_l[sysvar_li]=cfg.cdt_min_value;
......
......@@ -3668,7 +3668,7 @@ js_freediskspace(JSContext *cx, uintN argc, jsval *arglist)
jsval *argv=JS_ARGV(cx, arglist);
int32 unit=0;
char* p = NULL;
ulong fd;
uint64_t fd;
jsrefcount rc;
JS_SET_RVAL(cx, arglist, JSVAL_VOID);
......@@ -3703,7 +3703,7 @@ js_disksize(JSContext *cx, uintN argc, jsval *arglist)
jsval *argv=JS_ARGV(cx, arglist);
int32 unit=0;
char* p = NULL;
ulong ds;
uint64_t ds;
jsrefcount rc;
JS_SET_RVAL(cx, arglist, JSVAL_VOID);
......
......@@ -117,7 +117,7 @@ static JSBool js_system_get(JSContext *cx, JSObject *obj, jsid id, jsval *vp)
char* p=NULL;
jsint tiny;
JSString* js_str;
ulong val;
uint64_t space;
jsrefcount rc;
JSObject *robj;
jsval jval;
......@@ -194,11 +194,11 @@ static JSBool js_system_get(JSContext *cx, JSObject *obj, jsid id, jsval *vp)
case SYS_PROP_FREEDISKSPACEK:
rc=JS_SUSPENDREQUEST(cx);
if(tiny==SYS_PROP_FREEDISKSPACE)
val = getfreediskspace(cfg->temp_dir,0);
space = getfreediskspace(cfg->temp_dir,0);
else
val = getfreediskspace(cfg->temp_dir,1024);
space = getfreediskspace(cfg->temp_dir,1024);
JS_RESUMEREQUEST(cx, rc);
*vp=DOUBLE_TO_JSVAL((double)val);
*vp=DOUBLE_TO_JSVAL((double)space);
break;
#ifndef JSDOOR
case SYS_PROP_NEW_PASS:
......
......@@ -324,10 +324,10 @@ const char * const text_defaults[TOTAL_TEXT]={
"\x20\x66\x75\x6c\x6c\x2e\x01\x6e\x0d\x0a" // 198 BatchDlQueueIsFull
,"\x01\x5f\x01\x3f\x01\x79\x01\x68\x46\x69\x6c\x65\x73\x70\x65\x63\x20\x5b\x01\x77\x41\x6c\x6c\x20\x46\x69\x6c\x65\x73\x01\x79\x5d"
"\x3a\x20\x01\x6e" // 199 FileSpecStarDotStar
,"\x0d\x0a\x0d\x0a\x01\x72\x01\x68\x01\x69\x4e\x6f\x74\x20\x65\x6e\x6f\x75\x67\x68\x20\x66\x72\x65\x65\x20\x64\x69\x73\x6b\x20\x73"
"\x70\x61\x63\x65\x2e\x01\x6e\x0d\x0a\x0d\x0a\x01\x68\x54\x68\x65\x20\x73\x79\x73\x6f\x70\x20\x68\x61\x73\x20\x62\x65\x65\x6e\x20"
"\x6e\x6f\x74\x69\x66\x69\x65\x64\x2e\x01\x6e\x0d\x0a" // 200 LowDiskSpace
,"\x0d\x0a\x25\x73\x20\x6b\x69\x6c\x6f\x62\x79\x74\x65\x73\x20\x66\x72\x65\x65\x0d\x0a\x0d\x0a" // 201 DiskNBytesFree
,"\x01\x3f\x01\x72\x01\x68\x01\x69\x4e\x6f\x74\x20\x65\x6e\x6f\x75\x67\x68\x20\x66\x72\x65\x65\x20\x64\x69\x73\x6b\x20\x73\x70\x61"
"\x63\x65\x2e\x01\x6e\x0d\x0a\x0d\x0a\x01\x68\x54\x68\x65\x20\x73\x79\x73\x6f\x70\x20\x68\x61\x73\x20\x62\x65\x65\x6e\x20\x6e\x6f"
"\x74\x69\x66\x69\x65\x64\x2e\x01\x6e\x0d\x0a" // 200 LowDiskSpace
,"\x0d\x0a\x25\x73\x20\x62\x79\x74\x65\x73\x20\x66\x72\x65\x65\x0d\x0a\x0d\x0a" // 201 DiskNBytesFree
,"\x01\x5f\x01\x79\x01\x68\x46\x69\x6c\x65\x6e\x61\x6d\x65\x3a\x20\x01\x6e" // 202 Filename
,"\x01\x2f\x01\x72\x01\x68\x42\x61\x64\x20\x66\x69\x6c\x65\x6e\x61\x6d\x65\x3a\x20\x27\x25\x73\x27\x0d\x0a" // 203 BadFilename
,"\x55\x70\x6c\x6f\x61\x64\x20\x27\x25\x73\x27\x20\x74\x6f\x20\x53\x79\x73\x6f\x70\x20\x64\x69\x72\x65\x63\x74\x6f\x72\x79" // 204 UploadToSysopDirQ
......@@ -947,9 +947,9 @@ const char * const text_defaults[TOTAL_TEXT]={
"\x73\x0d\x0a\x0d\x0a" // 567 ReducedTime
,"\x01\x6e\x0d\x0a\x54\x69\x6d\x65\x64\x20\x45\x76\x65\x6e\x74\x20\x2d\x20\x4e\x6f\x64\x65\x3a\x20\x25\x64\x20\x20\x20\x54\x69\x6d"
"\x65\x3a\x20\x25\x30\x32\x64\x3a\x25\x30\x32\x64\x20\x20\x20\x4c\x61\x73\x74\x20\x52\x61\x6e\x3a\x20\x25\x73\x0d\x0a" // 568 EventInfo
,"\x01\x5f\x01\x72\x01\x68\x01\x69\x0d\x0a\x0d\x0a\x43\x6f\x6e\x6e\x65\x63\x74\x69\x6f\x6e\x20\x77\x69\x6c\x6c\x20\x62\x65\x20\x64"
"\x72\x6f\x70\x70\x65\x64\x20\x69\x6e\x20\x25\x64\x20\x6d\x69\x6e\x75\x74\x65\x73\x20\x64\x75\x65\x20\x74\x6f\x20\x75\x70\x63\x6f"
"\x6d\x69\x6e\x67\x20\x65\x76\x65\x6e\x74\x2e\x01\x6e" // 569 UploadBeforeEvent
,"\x01\x5f\x01\x72\x01\x68\x01\x69\x01\x3f\x43\x6f\x6e\x6e\x65\x63\x74\x69\x6f\x6e\x20\x77\x69\x6c\x6c\x20\x62\x65\x20\x64\x72\x6f"
"\x70\x70\x65\x64\x20\x69\x6e\x20\x25\x64\x20\x6d\x69\x6e\x75\x74\x65\x73\x20\x64\x75\x65\x20\x74\x6f\x20\x75\x70\x63\x6f\x6d\x69"
"\x6e\x67\x20\x65\x76\x65\x6e\x74\x2e\x01\x6e" // 569 UploadBeforeEvent
,"\x01\x5f\x01\x79\x01\x68\x0d\x0a\x51\x57\x4b\x3a\x20\x01\x6e" // 570 QWKPrompt
,"\x0d\x0a\x43\x74\x72\x6c\x2d\x41\x20\x63\x6f\x64\x65\x73\x3a\x20\x7e\x45\x78\x70\x61\x6e\x64\x20\x74\x6f\x20\x41\x4e\x53\x49\x2c"
"\x20\x7e\x4c\x65\x61\x76\x65\x20\x69\x6e\x2c\x20\x6f\x72\x20\x5b\x53\x74\x72\x69\x70\x5d\x3a\x20" // 571 QWKCtrlACodes
......
......@@ -213,9 +213,9 @@ bool sbbs_t::okay_to_upload(uint dirnum)
}
/* get free disk space */
ulong space = getfreediskspace(path, 1024);
byte_count_to_str(space * 1024, str, sizeof(str));
if(space < (ulong)(cfg.min_dspace / 1024)) {
int64_t space = getfreediskspace(path, 1);
byte_estimate_to_str(space, str, sizeof(str), /* units: */1024, /* precision: */1);
if(space < cfg.min_dspace) {
bputs(text[LowDiskSpace]);
lprintf(LOG_ERR, "Disk space is low: %s (%s bytes)", path, str);
if(!dir_op(dirnum))
......
......@@ -336,12 +336,12 @@ int globi(const char *p, int flags,
/* Returns number of files and/or sub-directories in directory (path) */
/* Similar, but not identical, to getfilecount() */
/****************************************************************************/
long getdirsize(const char* path, BOOL include_subdirs, BOOL subdir_only)
size_t getdirsize(const char* path, BOOL include_subdirs, BOOL subdir_only)
{
char match[MAX_PATH+1];
glob_t g;
unsigned gi;
long count=0;
size_t count=0;
if(!isdir(path))
return -1;
......@@ -886,21 +886,10 @@ uint64_t getfilesizetotal(const char *inpath)
#if defined(_WIN32)
typedef BOOL(WINAPI * GetDiskFreeSpaceEx_t)
(LPCTSTR,PULARGE_INTEGER,PULARGE_INTEGER,PULARGE_INTEGER);
static int bit_num(ulong val)
{
int i;
for(i=31;i>=0;i--)
if(val&(1<<i))
return(i);
return(-1);
}
#endif
/* Unit should be a power-of-2 (e.g. 1024 to report kilobytes) or 1 (to report bytes) */
static ulong getdiskspace(const char* path, ulong unit, BOOL freespace)
static uint64_t getdiskspace(const char* path, uint64_t unit, BOOL freespace)
{
#if defined(_WIN32)
char root[16];
......@@ -926,24 +915,7 @@ static ulong getdiskspace(const char* path, ulong unit, BOOL freespace)
NULL)) /* receives the free bytes on disk */
return(0);
if(freespace)
size=avail;
if(unit>1)
size.QuadPart=Int64ShrlMod32(size.QuadPart,bit_num(unit));
#if defined(_ANONYMOUS_STRUCT)
if(size.HighPart)
#else
if(size.u.HighPart)
#endif
return(0xffffffff); /* 4GB max */
#if defined(_ANONYMOUS_STRUCT)
return(size.LowPart);
#else
return(size.u.LowPart);
#endif
return freespace ? size.QuadPart : avail.QuadPart;
}
/* Windows 95 (old way), limited to 2GB */
......@@ -960,14 +932,14 @@ static ulong getdiskspace(const char* path, ulong unit, BOOL freespace)
if(freespace)
TotalNumberOfClusters = NumberOfFreeClusters;
if(unit>1)
TotalNumberOfClusters/=unit;
TotalNumberOfClusters/=(DWORD)unit;
return(TotalNumberOfClusters*SectorsPerCluster*BytesPerSector);
#elif defined(__solaris__) || (defined(__NetBSD_Version__) && (__NetBSD_Version__ >= 300000000 /* NetBSD 3.0 */))
struct statvfs fs;
unsigned long blocks;
uint64_t blocks;
if (statvfs(path, &fs) < 0)
return 0;
......@@ -985,7 +957,7 @@ static ulong getdiskspace(const char* path, ulong unit, BOOL freespace)
#elif defined(__GLIBC__) || defined(BSD)
struct statfs fs;
unsigned long blocks;
uint64_t blocks;
if(statfs(path, &fs) < 0)
return 0;
......@@ -1007,12 +979,12 @@ static ulong getdiskspace(const char* path, ulong unit, BOOL freespace)
#endif
}
ulong getfreediskspace(const char* path, ulong unit)
uint64_t getfreediskspace(const char* path, uint64_t unit)
{
return getdiskspace(path, unit, /* freespace? */TRUE);
}
ulong getdisksize(const char* path, ulong unit)
uint64_t getdisksize(const char* path, uint64_t unit)
{
return getdiskspace(path, unit, /* freespace? */FALSE);
}
......
......@@ -220,9 +220,9 @@ DLLEXPORT int getfattr(const char* filename);
DLLEXPORT int getfmode(const char* filename);
DLLEXPORT ulong getfilecount(const char *path);
DLLEXPORT char* getdirname(const char* path);
DLLEXPORT long getdirsize(const char* path, BOOL include_subdirs, BOOL subdir_only);
DLLEXPORT ulong getdisksize(const char* path, ulong unit);
DLLEXPORT ulong getfreediskspace(const char* path, ulong unit);
DLLEXPORT size_t getdirsize(const char* path, BOOL include_subdirs, BOOL subdir_only);
DLLEXPORT uint64_t getdisksize(const char* path, uint64_t unit);
DLLEXPORT uint64_t getfreediskspace(const char* path, uint64_t unit);
DLLEXPORT uint64_t getfilesizetotal(const char *path);
DLLEXPORT long delfiles(const char *inpath, const char *spec, size_t keep);
DLLEXPORT char* backslash(char* path);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment