Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
cfdd8f3f
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
cfdd8f3f
编写于
2月 25, 2022
作者:
wafwerar
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[TD-13062]<fix>: file system fsync fprintf error.
上级
d1e62818
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
64 addition
and
76 deletion
+64
-76
include/os/osFile.h
include/os/osFile.h
+1
-1
source/os/src/osFile.c
source/os/src/osFile.c
+63
-75
未找到文件。
include/os/osFile.h
浏览文件 @
cfdd8f3f
...
...
@@ -62,7 +62,7 @@ int64_t taosReadFile(TdFilePtr pFile, void *buf, int64_t count);
int64_t
taosPReadFile
(
TdFilePtr
pFile
,
void
*
buf
,
int64_t
count
,
int64_t
offset
);
int64_t
taosWriteFile
(
TdFilePtr
pFile
,
const
void
*
buf
,
int64_t
count
);
void
taosFprintfFile
(
TdFilePtr
pFile
,
const
char
*
format
,
...);
size
_t
taosGetLineFile
(
TdFilePtr
pFile
,
char
**
__restrict__
ptrBuf
);
int64
_t
taosGetLineFile
(
TdFilePtr
pFile
,
char
**
__restrict__
ptrBuf
);
int32_t
taosEOFFile
(
TdFilePtr
pFile
);
int64_t
taosCloseFile
(
TdFilePtr
*
ppFile
);
...
...
source/os/src/osFile.c
浏览文件 @
cfdd8f3f
...
...
@@ -15,31 +15,33 @@
#define ALLOW_FORBID_FUNC
#include "os.h"
#define MAX_FPRINTFLINE_BUFFER_SIZE (1000)
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#include <io.h>
#if defined(_MSDOS)
#define open _open
#endif
#if defined(_WIN32)
extern
int
openA
(
const
char
*
,
int
,
...);
/* MsvcLibX ANSI version of open */
extern
int
openU
(
const
char
*
,
int
,
...);
/* MsvcLibX UTF-8 version of open */
#if defined(_UTF8_SOURCE) || defined(_BSD_SOURCE) || defined(_GNU_SOURCE)
#define open openU
#else
/* _ANSI_SOURCE */
#define open openA
#endif
/* defined(_UTF8_SOURCE) */
#endif
/* defined(_WIN32) */
#include <io.h>
#if defined(_MSDOS)
#define open _open
#endif
#if defined(_WIN32)
extern
int
openA
(
const
char
*
,
int
,
...);
/* MsvcLibX ANSI version of open */
extern
int
openU
(
const
char
*
,
int
,
...);
/* MsvcLibX UTF-8 version of open */
#if defined(_UTF8_SOURCE) || defined(_BSD_SOURCE) || defined(_GNU_SOURCE)
#define open openU
#else
/* _ANSI_SOURCE */
#define open openA
#endif
/* defined(_UTF8_SOURCE) */
#endif
/* defined(_WIN32) */
#else
#include <fcntl.h>
#include <sys/file.h>
#include <sys/sendfile.h>
#include <sys/stat.h>
#include <unistd.h>
#define LINUX_FILE_NO_TEXT_OPTION 0
#define O_TEXT
LINUX_FILE_NO_TEXT_OPTION
#include <fcntl.h>
#include <sys/file.h>
#include <sys/sendfile.h>
#include <sys/stat.h>
#include <unistd.h>
#define LINUX_FILE_NO_TEXT_OPTION 0
#define O_TEXT
LINUX_FILE_NO_TEXT_OPTION
#endif
typedef
int32_t
FileFd
;
...
...
@@ -48,11 +50,9 @@ typedef struct TdFile {
int
refId
;
FileFd
fd
;
FILE
*
fp
;
}
*
TdFilePtr
,
TdFile
;
}
*
TdFilePtr
,
TdFile
;
void
taosGetTmpfilePath
(
const
char
*
inputTmpDir
,
const
char
*
fileNamePrefix
,
char
*
dstPath
)
{
void
taosGetTmpfilePath
(
const
char
*
inputTmpDir
,
const
char
*
fileNamePrefix
,
char
*
dstPath
)
{
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
const
char
*
tdengineTmpFileNamePrefix
=
"tdengine-"
;
char
tmpPath
[
PATH_MAX
];
...
...
@@ -112,11 +112,11 @@ int64_t taosCopyFile(const char *from, const char *to) {
int64_t
bytes
;
// fidfrom = open(from, O_RDONLY);
TdFilePtr
pFileFrom
=
taosOpenFile
(
from
,
TD_FILE_READ
);
TdFilePtr
pFileFrom
=
taosOpenFile
(
from
,
TD_FILE_READ
);
if
(
pFileFrom
==
NULL
)
goto
_err
;
// fidto = open(to, O_WRONLY | O_CREAT | O_EXCL, 0755);
TdFilePtr
pFileTo
=
taosOpenFile
(
to
,
TD_FILE_CTEATE
|
TD_FILE_WRITE
|
TD_FILE_EXCL
);
TdFilePtr
pFileTo
=
taosOpenFile
(
to
,
TD_FILE_CTEATE
|
TD_FILE_WRITE
|
TD_FILE_EXCL
);
if
(
pFileTo
==
NULL
)
goto
_err
;
while
(
true
)
{
...
...
@@ -148,14 +148,14 @@ int32_t taosRenameFile(const char *oldName, const char *newName) {
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
int32_t
code
=
MoveFileEx
(
oldName
,
newName
,
MOVEFILE_REPLACE_EXISTING
|
MOVEFILE_COPY_ALLOWED
);
if
(
code
<
0
)
{
//printf("failed to rename file %s to %s, reason:%s", oldName, newName, strerror(errno));
//
printf("failed to rename file %s to %s, reason:%s", oldName, newName, strerror(errno));
}
return
code
;
#else
int32_t
code
=
rename
(
oldName
,
newName
);
if
(
code
<
0
)
{
//printf("failed to rename file %s to %s, reason:%s", oldName, newName, strerror(errno));
//
printf("failed to rename file %s to %s, reason:%s", oldName, newName, strerror(errno));
}
return
code
;
...
...
@@ -184,25 +184,22 @@ int32_t taosStatFile(const char *path, int64_t *size, int32_t *mtime) {
#endif
}
void
autoDelFileListAdd
(
const
char
*
path
)
{
return
;
}
void
autoDelFileListAdd
(
const
char
*
path
)
{
return
;
}
TdFilePtr
taosOpenFile
(
const
char
*
path
,
int32_t
tdFileOptions
)
{
TdFilePtr
taosOpenFile
(
const
char
*
path
,
int32_t
tdFileOptions
)
{
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
return
NULL
;
#else
int
access
=
O_BINARY
;
char
*
mode
=
NULL
;
access
|=
(
tdFileOptions
&
TD_FILE_CTEATE
)
?
O_CREAT
:
0
;
if
((
tdFileOptions
&
TD_FILE_WRITE
)
&&
(
tdFileOptions
&
TD_FILE_READ
))
{
if
((
tdFileOptions
&
TD_FILE_WRITE
)
&&
(
tdFileOptions
&
TD_FILE_READ
))
{
access
|=
O_RDWR
;
mode
=
(
tdFileOptions
&
TD_FILE_TEXT
)
?
"rt+"
:
"rb+"
;
}
else
if
(
tdFileOptions
&
TD_FILE_WRITE
)
{
}
else
if
(
tdFileOptions
&
TD_FILE_WRITE
)
{
access
|=
O_WRONLY
;
mode
=
(
tdFileOptions
&
TD_FILE_TEXT
)
?
"wt"
:
"wb"
;
}
else
if
(
tdFileOptions
&
TD_FILE_READ
)
{
}
else
if
(
tdFileOptions
&
TD_FILE_READ
)
{
access
|=
O_RDONLY
;
mode
=
(
tdFileOptions
&
TD_FILE_TEXT
)
?
"rt"
:
"rb"
;
}
...
...
@@ -210,14 +207,14 @@ TdFilePtr taosOpenFile(const char *path,int32_t tdFileOptions) {
access
|=
(
tdFileOptions
&
TD_FILE_APPEND
)
?
O_APPEND
:
0
;
access
|=
(
tdFileOptions
&
TD_FILE_TEXT
)
?
O_TEXT
:
0
;
access
|=
(
tdFileOptions
&
TD_FILE_EXCL
)
?
O_EXCL
:
0
;
if
(
tdFileOptions
&
TD_FILE_AUTO_DEL
)
{
if
(
tdFileOptions
&
TD_FILE_AUTO_DEL
)
{
autoDelFileListAdd
(
path
);
}
int
fd
=
open
(
path
,
access
,
S_IRWXU
|
S_IRWXG
|
S_IRWXO
);
if
(
fd
==
-
1
)
{
if
(
fd
==
-
1
)
{
return
NULL
;
}
FILE
*
fp
=
fdopen
(
fd
,
mode
);
FILE
*
fp
=
fdopen
(
fd
,
mode
);
if
(
fp
==
NULL
)
{
close
(
fd
);
return
NULL
;
...
...
@@ -239,10 +236,10 @@ int64_t taosCloseFile(TdFilePtr *ppFile) {
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
return
0
;
#else
if
(
ppFile
==
NULL
||
*
ppFile
==
NULL
||
(
*
ppFile
)
->
fd
==
-
1
)
{
if
(
ppFile
==
NULL
||
*
ppFile
==
NULL
||
(
*
ppFile
)
->
fd
==
-
1
)
{
return
0
;
}
f
sync
((
*
ppFile
)
->
fd
);
f
flush
((
*
ppFile
)
->
fp
);
close
((
*
ppFile
)
->
fd
);
(
*
ppFile
)
->
fd
=
-
1
;
(
*
ppFile
)
->
fp
=
NULL
;
...
...
@@ -254,12 +251,12 @@ int64_t taosCloseFile(TdFilePtr *ppFile) {
}
int64_t
taosReadFile
(
TdFilePtr
pFile
,
void
*
buf
,
int64_t
count
)
{
if
(
pFile
==
NULL
)
{
if
(
pFile
==
NULL
)
{
return
0
;
}
int64_t
leftbytes
=
count
;
int64_t
readbytes
;
char
*
tbuf
=
(
char
*
)
buf
;
char
*
tbuf
=
(
char
*
)
buf
;
while
(
leftbytes
>
0
)
{
readbytes
=
read
(
pFile
->
fd
,
(
void
*
)
tbuf
,
(
uint32_t
)
leftbytes
);
...
...
@@ -281,7 +278,7 @@ int64_t taosReadFile(TdFilePtr pFile, void *buf, int64_t count) {
}
int64_t
taosPReadFile
(
TdFilePtr
pFile
,
void
*
buf
,
int64_t
count
,
int64_t
offset
)
{
if
(
pFile
==
NULL
)
{
if
(
pFile
==
NULL
)
{
return
0
;
}
return
pread
(
pFile
->
fd
,
buf
,
count
,
offset
);
...
...
@@ -290,7 +287,7 @@ int64_t taosPReadFile(TdFilePtr pFile, void *buf, int64_t count, int64_t offset)
int64_t
taosWriteFile
(
TdFilePtr
pFile
,
const
void
*
buf
,
int64_t
count
)
{
int64_t
nleft
=
count
;
int64_t
nwritten
=
0
;
char
*
tbuf
=
(
char
*
)
buf
;
char
*
tbuf
=
(
char
*
)
buf
;
while
(
nleft
>
0
)
{
nwritten
=
write
(
pFile
->
fd
,
(
void
*
)
tbuf
,
(
uint32_t
)
nleft
);
...
...
@@ -417,7 +414,7 @@ int32_t taosFsyncFile(TdFilePtr pFile) {
return
FlushFileBuffers
(
h
);
#else
return
f
sync
(
pFile
->
fd
);
return
f
flush
(
pFile
->
fp
);
#endif
}
...
...
@@ -568,14 +565,11 @@ int64_t taosFSendFile(TdFilePtr pFileOut, TdFilePtr pFileIn, int64_t *offset, in
#endif
#ifdef __GNUC__
__attribute__
((
format
(
printf
,
2
,
3
)))
#endif
void
taosFprintfFile
(
TdFilePtr
pFile
,
const
char
*
format
,
...)
{
char
buffer
[
MAX_FPRINTFLINE_BUFFER_SIZE
]
=
{
0
};
va_list
ap
;
va_start
(
ap
,
format
);
fprintf
(
pFile
->
fp
,
format
,
ap
);
v
fprintf
(
pFile
->
fp
,
format
,
ap
);
va_end
(
ap
);
fflush
(
pFile
->
fp
);
}
...
...
@@ -587,9 +581,7 @@ void *taosMmapReadOnlyFile(TdFilePtr pFile, int64_t length) {
return
ptr
;
}
bool
taosValidFile
(
TdFilePtr
pFile
)
{
return
pFile
!=
NULL
;
}
bool
taosValidFile
(
TdFilePtr
pFile
)
{
return
pFile
!=
NULL
;
}
int32_t
taosUmaskFile
(
int32_t
maskVal
)
{
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
...
...
@@ -599,13 +591,9 @@ int32_t taosUmaskFile(int32_t maskVal) {
#endif
}
int
taosGetErrorFile
(
TdFilePtr
pFile
)
{
return
errno
;
}
size_t
taosGetLineFile
(
TdFilePtr
pFile
,
char
**
__restrict__
ptrBuf
)
{
int32_t
taosGetErrorFile
(
TdFilePtr
pFile
)
{
return
errno
;
}
int64_t
taosGetLineFile
(
TdFilePtr
pFile
,
char
**
__restrict__
ptrBuf
)
{
size_t
len
=
0
;
return
getline
(
ptrBuf
,
&
len
,
pFile
->
fp
);
}
int32_t
taosEOFFile
(
TdFilePtr
pFile
)
{
return
feof
(
pFile
->
fp
);
}
\ No newline at end of file
int32_t
taosEOFFile
(
TdFilePtr
pFile
)
{
return
feof
(
pFile
->
fp
);
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录