diff --git a/src/kit/shell/src/shellEngine.c b/src/kit/shell/src/shellEngine.c index a986f2d3cb038557904c7b1309225491b0a57ea1..716a317fca03f4a3d8c1067e1eba781208689901 100644 --- a/src/kit/shell/src/shellEngine.c +++ b/src/kit/shell/src/shellEngine.c @@ -470,7 +470,7 @@ static int dumpResultToFile(const char* fname, TAOS_RES* tres) { wordexp_t full_path; - if (wordexp(fname, &full_path, 0) != 0) { + if (wordexp((char *)fname, &full_path, 0) != 0) { fprintf(stderr, "ERROR: invalid file name: %s\n", fname); return -1; } diff --git a/src/os/inc/osWindows.h b/src/os/inc/osWindows.h index 1f3b1b02e3c0f5698a27a080d3b6721f0669bbbe..6f96e4d1c80f5f376684f758140be16cc9498b65 100644 --- a/src/os/inc/osWindows.h +++ b/src/os/inc/osWindows.h @@ -201,13 +201,15 @@ int gettimeofday(struct timeval *ptv, void *pTimeZone); typedef struct { int we_wordc; - char **we_wordv; + char *we_wordv[1]; int we_offs; - char wordPos[20]; + char wordPos[1025]; } wordexp_t; -int wordexp(const char *words, wordexp_t *pwordexp, int flags); +int wordexp(char *words, wordexp_t *pwordexp, int flags); void wordfree(wordexp_t *pwordexp); +char *realpath(char *path, char *resolved_path); + #define openlog(a, b, c) #define closelog() #define LOG_ERR 0 diff --git a/src/os/src/detail/osSysinfo.c b/src/os/src/detail/osSysinfo.c index 25b0edae72a2a043eb8d993afe8644d8c9775e6e..f12ec93bf7725d013fa2f53d148de783e854d3bf 100644 --- a/src/os/src/detail/osSysinfo.c +++ b/src/os/src/detail/osSysinfo.c @@ -18,6 +18,7 @@ #include "tconfig.h" #include "tglobal.h" #include "tulog.h" +#include "taoserror.h" #ifndef TAOS_OS_FUNC_SYSINFO @@ -320,11 +321,12 @@ int32_t taosGetDiskSize(char *dataDir, SysDiskSize *diskSize) { struct statvfs info; if (statvfs(tsDataDir, &info)) { uError("failed to get disk size, dataDir:%s errno:%s", tsDataDir, strerror(errno)); - return false; + terrno = TAOS_SYSTEM_ERROR(errno); + return -1; } else { diskSize->tsize = info.f_blocks * info.f_frsize; diskSize->avail = info.f_bavail * info.f_frsize; - return true; + return 0; } } diff --git a/src/os/src/windows/wSysinfo.c b/src/os/src/windows/wSysinfo.c index 2c5993336592b95ed5dec4615668eb4785a2abb1..48fb3c13a8fe80332cfc26f893d6a21f1cdd902e 100644 --- a/src/os/src/windows/wSysinfo.c +++ b/src/os/src/windows/wSysinfo.c @@ -21,6 +21,7 @@ #include "ttimer.h" #include "tulog.h" #include "tutil.h" +#include "taoserror.h" #if (_WIN64) #include #include @@ -126,34 +127,21 @@ bool taosGetCpuUsage(float *sysCpuUsage, float *procCpuUsage) { return true; } -void taosGetDisk() { - const double unit = 1024 * 1024 * 1024; - BOOL fResult; +int32_t taosGetDiskSize(char *dataDir, SysDiskSize *diskSize) { unsigned _int64 i64FreeBytesToCaller; unsigned _int64 i64TotalBytes; unsigned _int64 i64FreeBytes; - if (tscEmbedded) { - fResult = GetDiskFreeSpaceExA(tsDataDir, (PULARGE_INTEGER)&i64FreeBytesToCaller, (PULARGE_INTEGER)&i64TotalBytes, - (PULARGE_INTEGER)&i64FreeBytes); - if (fResult) { - tsTotalDataDirGB = (float)(i64TotalBytes / unit); - tsAvailDataDirGB = (float)(i64FreeBytes / unit); - } - } - - fResult = GetDiskFreeSpaceExA(tsLogDir, (PULARGE_INTEGER)&i64FreeBytesToCaller, (PULARGE_INTEGER)&i64TotalBytes, - (PULARGE_INTEGER)&i64FreeBytes); + BOOL fResult = GetDiskFreeSpaceExA(dataDir, (PULARGE_INTEGER)&i64FreeBytesToCaller, (PULARGE_INTEGER)&i64TotalBytes, + (PULARGE_INTEGER)&i64FreeBytes); if (fResult) { - tsTotalLogDirGB = (float)(i64TotalBytes / unit); - tsAvailLogDirGB = (float)(i64FreeBytes / unit); - } - - fResult = GetDiskFreeSpaceExA(tsTempDir, (PULARGE_INTEGER)&i64FreeBytesToCaller, (PULARGE_INTEGER)&i64TotalBytes, - (PULARGE_INTEGER)&i64FreeBytes); - if (fResult) { - tsTotalTmpDirGB = (float)(i64TotalBytes / unit); - tsAvailTmpDirectorySpace = (float)(i64FreeBytes / unit); + diskSize->tsize = (int64_t)(i64TotalBytes); + diskSize->avail = (int64_t)(i64FreeBytes); + return 0; + } else { + uError("failed to get disk size, dataDir:%s errno:%s", tsDataDir, strerror(errno)); + terrno = TAOS_SYSTEM_ERROR(errno); + return -1; } } @@ -205,7 +193,7 @@ void taosGetSystemInfo() { tsTotalMemoryMB = taosGetTotalMemory(); float tmp1, tmp2; - taosGetDisk(); + // taosGetDisk(); taosGetBandSpeed(&tmp1); taosGetCpuUsage(&tmp1, &tmp2); taosGetProcIO(&tmp1, &tmp2); diff --git a/src/os/src/windows/wWordexp.c b/src/os/src/windows/wWordexp.c index bb9acde25a5de6c334f512fc8994edffdf5c59a3..fca283cb339d6cdb48f789bf20de1c69b724f10f 100644 --- a/src/os/src/windows/wWordexp.c +++ b/src/os/src/windows/wWordexp.c @@ -21,13 +21,24 @@ #include "tulog.h" #include "tutil.h" -int wordexp(const char *words, wordexp_t *pwordexp, int flags) { +int wordexp(char *words, wordexp_t *pwordexp, int flags) { pwordexp->we_offs = 0; pwordexp->we_wordc = 1; - pwordexp->we_wordv = (char **)(pwordexp->wordPos); - pwordexp->we_wordv[0] = (char *)words; + pwordexp->we_wordv[0] = pwordexp->wordPos; + + memset(pwordexp->wordPos, 0, 1025); + if (_fullpath(words, pwordexp->wordPos, 1024) == NULL) { + pwordexp->we_wordv[0] = words; + uError("failed to parse relative path:%s to abs path", words); + return -1; + } + + uTrace("parse relative path:%s to abs path:%s", words, pwordexp->wordPos); return 0; } void wordfree(wordexp_t *pwordexp) {} +char *realpath(char *path, char *resolved_path) { + return _fullpath(path, resolved_path, TSDB_FILENAME_LEN - 1); +} \ No newline at end of file diff --git a/src/tfs/src/tdisk.c b/src/tfs/src/tdisk.c index 2f821375f2b6b87c50d5f52249ec13ff92b706d9..7cdaf7fd099db85c988077296ade2da7440be8a1 100644 --- a/src/tfs/src/tdisk.c +++ b/src/tfs/src/tdisk.c @@ -42,17 +42,17 @@ SDisk *tfsFreeDisk(SDisk *pDisk) { int tfsUpdateDiskInfo(SDisk *pDisk) { ASSERT(pDisk != NULL); - struct statvfs dstat; - if (statvfs(pDisk->dir, &dstat) < 0) { + SysDiskSize diskSize = {0}; + + int code = taosGetDiskSize(pDisk->dir, &diskSize); + if (code != 0) { fError("failed to update disk information at level %d id %d dir %s since %s", pDisk->level, pDisk->id, pDisk->dir, strerror(errno)); terrno = TAOS_SYSTEM_ERROR(errno); - pDisk->dmeta.size = 0; - pDisk->dmeta.free = 0; - return -1; - } else { - pDisk->dmeta.size = dstat.f_blocks * dstat.f_frsize; - pDisk->dmeta.free = dstat.f_bavail * dstat.f_frsize; - return 0; } + + pDisk->dmeta.size = diskSize.tsize; + pDisk->dmeta.free = diskSize.tsize - diskSize.avail; + + return code; } \ No newline at end of file diff --git a/src/tfs/src/tfs.c b/src/tfs/src/tfs.c index 803cfa6d0e789d9984e7cca30b014ed2ff7d04ef..9d384892a01f68475837bfd8824ecee6212c5a57 100644 --- a/src/tfs/src/tfs.c +++ b/src/tfs/src/tfs.c @@ -21,9 +21,6 @@ #include "tfs.h" #include "tfsint.h" -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wformat-truncation" - typedef struct { pthread_spinlock_t lock; SFSMeta meta; @@ -582,19 +579,17 @@ void taosGetDisk() { if (tscEmbedded) { tfsUpdateInfo(&fsMeta); - tsTotalDataDirGB = (float)fsMeta.tsize / unit; - tsAvailDataDirGB = (float)fsMeta.avail / unit; + tsTotalDataDirGB = (float)(fsMeta.tsize / unit); + tsAvailDataDirGB = (float)(fsMeta.avail / unit); } - if (taosGetDiskSize(tsLogDir, &diskSize)) { - tsTotalLogDirGB = (float)diskSize.tsize / unit; - tsAvailLogDirGB = (float)diskSize.avail / unit; + if (taosGetDiskSize(tsLogDir, &diskSize) == 0) { + tsTotalLogDirGB = (float)(diskSize.tsize / unit); + tsAvailLogDirGB = (float)(diskSize.avail / unit); } - if (taosGetDiskSize("/tmp", &diskSize)) { - tsTotalTmpDirGB = (float)diskSize.tsize / unit; - tsAvailTmpDirectorySpace = (float)diskSize.avail / unit; + if (taosGetDiskSize("/tmp", &diskSize) == 0) { + tsTotalTmpDirGB = (float)(diskSize.tsize / unit); + tsAvailTmpDirectorySpace = (float)(diskSize.avail / unit); } } - -#pragma GCC diagnostic pop \ No newline at end of file diff --git a/src/tsdb/inc/tsdbFile.h b/src/tsdb/inc/tsdbFile.h index cb5c78ca841cf4d5602c435ca020810861caffb4..132e90f8d1fdaad8812c34d872cca19f79d417df 100644 --- a/src/tsdb/inc/tsdbFile.h +++ b/src/tsdb/inc/tsdbFile.h @@ -133,7 +133,7 @@ static FORCE_INLINE int tsdbAppendMFile(SMFile* pMFile, void* buf, int64_t nbyte pMFile->info.size += nbyte; - return nbyte; + return (int)nbyte; } static FORCE_INLINE int tsdbRemoveMFile(SMFile* pMFile) { return tfsremove(TSDB_FILE_F(pMFile)); } @@ -246,7 +246,7 @@ static FORCE_INLINE int tsdbAppendDFile(SDFile* pDFile, void* buf, int64_t nbyte pDFile->info.size += nbyte; - return nbyte; + return (int)nbyte; } static FORCE_INLINE int tsdbRemoveDFile(SDFile* pDFile) { return tfsremove(TSDB_FILE_F(pDFile)); } diff --git a/src/tsdb/src/tsdbCommit.c b/src/tsdb/src/tsdbCommit.c index 6c5d3ae015907816f795c70e61c33210465a7b15..e329cf74cd185858855f7264a5e8ca615a1b3233 100644 --- a/src/tsdb/src/tsdbCommit.c +++ b/src/tsdb/src/tsdbCommit.c @@ -205,9 +205,9 @@ void tsdbGetRtnSnap(STsdbRepo *pRepo, SRtn *pRtn) { maxKey = now - pCfg->keep1 * tsMsPerDay[pCfg->precision]; pRtn->minKey = minKey; - pRtn->minFid = TSDB_KEY_FID(minKey, pCfg->daysPerFile, pCfg->precision); - pRtn->midFid = TSDB_KEY_FID(midKey, pCfg->daysPerFile, pCfg->precision); - pRtn->maxFid = TSDB_KEY_FID(maxKey, pCfg->daysPerFile, pCfg->precision); + pRtn->minFid = (int)(TSDB_KEY_FID(minKey, pCfg->daysPerFile, pCfg->precision)); + pRtn->midFid = (int)(TSDB_KEY_FID(midKey, pCfg->daysPerFile, pCfg->precision)); + pRtn->maxFid = (int)(TSDB_KEY_FID(maxKey, pCfg->daysPerFile, pCfg->precision)); } static int tsdbUpdateMetaRecord(STsdbFS *pfs, SMFile *pMFile, uint64_t uid, void *cont, int contLen) { @@ -571,7 +571,7 @@ static int tsdbNextCommitFid(SCommitH *pCommith) { if (nextKey == TSDB_DATA_TIMESTAMP_NULL) { continue; } else { - int tfid = TSDB_KEY_FID(nextKey, pCfg->daysPerFile, pCfg->precision); + int tfid = (int)(TSDB_KEY_FID(nextKey, pCfg->daysPerFile, pCfg->precision)); if (fid == TSDB_IVLD_FID || fid > tfid) { fid = tfid; } @@ -950,7 +950,7 @@ static int tsdbWriteBlockIdx(SCommitH *pCommih) { } tsdbUpdateDFileMagic(pHeadf, POINTER_SHIFT(TSDB_COMMIT_BUF(pCommih), tlen - sizeof(TSCKSUM))); - pHeadf->info.offset = offset; + pHeadf->info.offset = (uint32_t)offset; pHeadf->info.len = tlen; return 0; diff --git a/src/tsdb/src/tsdbFS.c b/src/tsdb/src/tsdbFS.c index 9196fecfcd8423919810f89f2ff205c9b9dc57bc..20f0d1909e1505876d269545a35dcbaffbf056be 100644 --- a/src/tsdb/src/tsdbFS.c +++ b/src/tsdb/src/tsdbFS.c @@ -13,7 +13,9 @@ * along with this program. If not, see . */ +#include "os.h" #include "tsdbint.h" +#include typedef enum { TSDB_TXN_TEMP_FILE = 0, TSDB_TXN_CURR_FILE } TSDB_TXN_FILE_T; static const char *tsdbTxnFname[] = {"current.t", "current"}; @@ -162,7 +164,7 @@ static void tsdbSetStatusMFile(SFSStatus *pStatus, const SMFile *pMFile) { ASSERT(pStatus->pmf == NULL); pStatus->pmf = &(pStatus->mf); - tsdbInitMFileEx(pStatus->pmf, pMFile); + tsdbInitMFileEx(pStatus->pmf, (SMFile *)pMFile); } static int tsdbAddDFileSetToStatus(SFSStatus *pStatus, const SDFileSet *pSet) { @@ -590,7 +592,7 @@ static int tsdbOpenFSFromCurrent(STsdbRepo *pRepo) { goto _err; } - int nread = taosRead(fd, buffer, TSDB_FILE_HEAD_SIZE); + int nread = (int)taosRead(fd, buffer, TSDB_FILE_HEAD_SIZE); if (nread < 0) { tsdbError("vgId:%d failed to read %d bytes from file %s since %s", REPO_ID(pRepo), TSDB_FILENAME_LEN, current, strerror(errno)); @@ -624,7 +626,7 @@ static int tsdbOpenFSFromCurrent(STsdbRepo *pRepo) { goto _err; } - nread = taosRead(fd, buffer, fsheader.len); + nread = (int)taosRead(fd, buffer, fsheader.len); if (nread < 0) { tsdbError("vgId:%d failed to read file %s since %s", REPO_ID(pRepo), current, strerror(errno)); terrno = TAOS_SYSTEM_ERROR(errno); @@ -763,7 +765,7 @@ int tsdbLoadMetaCache(STsdbRepo *pRepo, bool recoverMeta) { } if (recoverMeta) { - pBuf = malloc(maxBufSize); + pBuf = malloc((size_t)maxBufSize); if (pBuf == NULL) { terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; tsdbCloseMFile(pMFile); @@ -780,7 +782,7 @@ int tsdbLoadMetaCache(STsdbRepo *pRepo, bool recoverMeta) { return -1; } - int nread = tsdbReadMFile(pMFile, pBuf, pRecord->size); + int nread = (int)tsdbReadMFile(pMFile, pBuf, pRecord->size); if (nread < 0) { tsdbError("vgId:%d failed to read file %s since %s", REPO_ID(pRepo), TSDB_FILE_FULL_NAME(pMFile), tstrerror(terrno)); @@ -798,7 +800,7 @@ int tsdbLoadMetaCache(STsdbRepo *pRepo, bool recoverMeta) { return -1; } - if (tsdbRestoreTable(pRepo, pBuf, pRecord->size) < 0) { + if (tsdbRestoreTable(pRepo, pBuf, (size_t)pRecord->size) < 0) { tsdbError("vgId:%d failed to restore table, uid %" PRId64 ", since %s" PRIu64, REPO_ID(pRepo), pRecord->uid, tstrerror(terrno)); tfree(pBuf); diff --git a/src/tsdb/src/tsdbSync.c b/src/tsdb/src/tsdbSync.c index 7ac5a323305e0a3f1a21c56c252de8734b466d73..2b290ae18093d537fe083f7d25df3871ea009f49 100644 --- a/src/tsdb/src/tsdbSync.c +++ b/src/tsdb/src/tsdbSync.c @@ -149,10 +149,10 @@ static int32_t tsdbSyncSendMeta(SSyncH *pSynch) { return -1; } - int32_t writeLen = mf.info.size; + int32_t writeLen = (int32_t)mf.info.size; tsdbInfo("vgId:%d, metafile:%s will be sent, size:%d", REPO_ID(pRepo), mf.f.aname, writeLen); - int32_t ret = taosSendFile(pSynch->socketFd, TSDB_FILE_FD(&mf), 0, writeLen); + int32_t ret = (int32_t)taosSendFile(pSynch->socketFd, TSDB_FILE_FD(&mf), 0, writeLen); if (ret != writeLen) { terrno = TAOS_SYSTEM_ERROR(errno); tsdbError("vgId:%d, failed to send metafile since %s, ret:%d writeLen:%d", REPO_ID(pRepo), tstrerror(terrno), ret, @@ -213,7 +213,7 @@ static int32_t tsdbSyncRecvMeta(SSyncH *pSynch) { tsdbInfo("vgId:%d, metafile:%s is created", REPO_ID(pRepo), mf.f.aname); - int32_t readLen = pSynch->pmf->info.size; + int32_t readLen = (int32_t)pSynch->pmf->info.size; int32_t ret = taosCopyFds(pSynch->socketFd, TSDB_FILE_FD(&mf), readLen); if (ret != readLen) { terrno = TAOS_SYSTEM_ERROR(errno); @@ -458,7 +458,7 @@ static int32_t tsdbSyncRecvDFileSetArray(SSyncH *pSynch) { tsdbInfo("vgId:%d, file:%s will be received, osize:%" PRIu64 " rsize:%" PRIu64, REPO_ID(pRepo), pDFile->f.aname, pDFile->info.size, pRDFile->info.size); - int32_t writeLen = pRDFile->info.size; + int32_t writeLen = (int32_t)pRDFile->info.size; int32_t ret = taosCopyFds(pSynch->socketFd, pDFile->fd, writeLen); if (ret != writeLen) { terrno = TAOS_SYSTEM_ERROR(errno); @@ -570,10 +570,10 @@ static int32_t tsdbSyncSendDFileSet(SSyncH *pSynch, SDFileSet *pSet) { return -1; } - int32_t writeLen = df.info.size; + int32_t writeLen = (int32_t)df.info.size; tsdbInfo("vgId:%d, file:%s will be sent, size:%d", REPO_ID(pRepo), df.f.aname, writeLen); - int32_t ret = taosSendFile(pSynch->socketFd, TSDB_FILE_FD(&df), 0, writeLen); + int32_t ret = (int32_t)taosSendFile(pSynch->socketFd, TSDB_FILE_FD(&df), 0, writeLen); if (ret != writeLen) { terrno = TAOS_SYSTEM_ERROR(errno); tsdbError("vgId:%d, failed to send file:%s since %s, ret:%d writeLen:%d", REPO_ID(pRepo), df.f.aname,