Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
I
ioping
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
ioping
Commits
1af60706
Commit
1af60706
authored
Sep 08, 2015
by
Konstantin Khlebnikov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ioping: open files with CreateFile on windows
Signed-off-by:
Konstantin Khlebnikov
<
koct9i@gmail.com
>
parent
91b03350
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
47 additions
and
45 deletions
+47
-45
ioping.c
ioping.c
+47
-45
No files found.
ioping.c
View file @
1af60706
...
@@ -788,26 +788,28 @@ static void aio_setup(void)
...
@@ -788,26 +788,28 @@ static void aio_setup(void)
#ifdef __MINGW32__
#ifdef __MINGW32__
int
create_temp
(
char
*
path
,
char
*
name
)
int
open_file
(
const
char
*
path
,
const
char
*
temp
)
{
{
int
length
=
strlen
(
path
)
+
strlen
(
name
)
+
9
;
char
*
file_path
=
(
char
*
)
path
;
char
*
temp
=
malloc
(
length
);
DWORD
action
=
OPEN_ALWAYS
;
DWORD
action
;
DWORD
attr
=
0
;
DWORD
attr
=
0
;
HANDLE
h
;
HANDLE
h
;
if
(
!
temp
)
if
(
temp
)
{
err
(
2
,
NULL
)
;
int
length
=
strlen
(
path
)
+
strlen
(
temp
)
+
9
;
snprintf
(
temp
,
length
,
"%s
\\
%s"
,
path
,
name
);
file_path
=
malloc
(
length
);
if
(
!
file_path
)
err
(
2
,
NULL
);
if
(
!
keep_file
)
{
snprintf
(
file_path
,
length
,
"%s
\\
%s"
,
path
,
temp
);
strcat
(
temp
,
".XXXXXX"
);
mktemp
(
temp
);
if
(
!
keep_file
)
{
action
=
CREATE_NEW
;
strcat
(
file_path
,
".XXXXXX"
);
attr
|=
FILE_ATTRIBUTE_HIDDEN
|
FILE_FLAG_DELETE_ON_CLOSE
;
mktemp
(
file_path
);
}
else
{
action
=
CREATE_NEW
;
action
=
OPEN_ALWAYS
;
attr
|=
FILE_ATTRIBUTE_HIDDEN
|
FILE_FLAG_DELETE_ON_CLOSE
;
}
}
}
if
(
!
cached
)
if
(
!
cached
)
...
@@ -817,11 +819,13 @@ int create_temp(char *path, char *name)
...
@@ -817,11 +819,13 @@ int create_temp(char *path, char *name)
else
else
attr
|=
FILE_FLAG_SEQUENTIAL_SCAN
;
attr
|=
FILE_FLAG_SEQUENTIAL_SCAN
;
h
=
CreateFile
(
temp
,
GENERIC_READ
|
GENERIC_WRITE
,
h
=
CreateFile
(
file_path
,
GENERIC_READ
|
GENERIC_WRITE
,
FILE_SHARE_READ
|
FILE_SHARE_WRITE
|
FILE_SHARE_DELETE
,
FILE_SHARE_READ
|
FILE_SHARE_WRITE
|
FILE_SHARE_DELETE
,
NULL
,
action
,
attr
,
NULL
);
NULL
,
action
,
attr
,
NULL
);
free
(
temp
);
if
(
file_path
!=
path
)
free
(
file_path
);
if
(
h
==
INVALID_HANDLE_VALUE
)
if
(
h
==
INVALID_HANDLE_VALUE
)
return
-
1
;
return
-
1
;
return
_open_osfhandle
((
long
)
h
,
0
);
return
_open_osfhandle
((
long
)
h
,
0
);
...
@@ -847,19 +851,26 @@ void set_signal(void)
...
@@ -847,19 +851,26 @@ void set_signal(void)
#else
/* __MINGW32__ */
#else
/* __MINGW32__ */
int
create_temp
(
char
*
path
,
char
*
name
)
int
open_file
(
const
char
*
path
,
const
char
*
temp
)
{
{
int
length
=
strlen
(
path
)
+
strlen
(
name
)
+
9
;
char
*
file_path
=
NULL
;
char
*
temp
=
malloc
(
length
);
int
length
,
fd
;
int
fd
;
if
(
!
temp
)
if
(
!
temp
)
{
err
(
2
,
NULL
);
fd
=
open
(
path
,
write_test
?
O_RDWR
:
O_RDONLY
);
if
(
fd
<
0
)
goto
out
;
goto
done
;
}
snprintf
(
temp
,
length
,
"%s/%s"
,
path
,
name
);
length
=
strlen
(
path
)
+
strlen
(
temp
)
+
9
;
file_path
=
malloc
(
length
);
if
(
!
file_path
)
err
(
2
,
NULL
);
snprintf
(
file_path
,
length
,
"%s/%s"
,
path
,
temp
);
if
(
keep_file
)
{
if
(
keep_file
)
{
fd
=
open
(
temp
,
O_RDWR
|
O_CREAT
,
0600
);
fd
=
open
(
file_path
,
O_RDWR
|
O_CREAT
,
0600
);
if
(
fd
<
0
)
if
(
fd
<
0
)
goto
out
;
goto
out
;
goto
done
;
goto
done
;
...
@@ -871,12 +882,12 @@ int create_temp(char *path, char *name)
...
@@ -871,12 +882,12 @@ int create_temp(char *path, char *name)
goto
done
;
goto
done
;
#endif
#endif
strcat
(
temp
,
".XXXXXX"
);
strcat
(
file_path
,
".XXXXXX"
);
fd
=
mkstemp
(
temp
);
fd
=
mkstemp
(
file_path
);
if
(
fd
<
0
)
if
(
fd
<
0
)
goto
out
;
goto
out
;
if
(
unlink
(
temp
))
if
(
unlink
(
file_path
))
err
(
2
,
"unlink
\"
%s
\"
failed"
,
temp
);
err
(
2
,
"unlink
\"
%s
\"
failed"
,
file_path
);
done:
done:
#ifdef HAVE_DIRECT_IO
#ifdef HAVE_DIRECT_IO
...
@@ -884,7 +895,8 @@ done:
...
@@ -884,7 +895,8 @@ done:
errx
(
2
,
"fcntl failed, please retry without -D"
);
errx
(
2
,
"fcntl failed, please retry without -D"
);
#endif
#endif
out:
out:
free
(
temp
);
if
(
file_path
!=
path
)
free
(
file_path
);
return
fd
;
return
fd
;
}
}
...
@@ -931,7 +943,7 @@ int main (int argc, char **argv)
...
@@ -931,7 +943,7 @@ int main (int argc, char **argv)
{
{
ssize_t
ret_size
;
ssize_t
ret_size
;
struct
stat
st
;
struct
stat
st
;
int
ret
,
flags
;
int
ret
;
int
part_request
;
int
part_request
;
long
long
this_time
;
long
long
this_time
;
...
@@ -964,8 +976,6 @@ int main (int argc, char **argv)
...
@@ -964,8 +976,6 @@ int main (int argc, char **argv)
else
if
(
size
>
temp_wsize
)
else
if
(
size
>
temp_wsize
)
temp_wsize
=
size
;
temp_wsize
=
size
;
flags
=
O_RDONLY
;
#if !defined(HAVE_POSIX_FADVICE) && !defined(HAVE_NOCACHE_IO)
#if !defined(HAVE_POSIX_FADVICE) && !defined(HAVE_NOCACHE_IO)
# if defined(HAVE_DIRECT_IO)
# if defined(HAVE_DIRECT_IO)
direct
|=
!
cached
;
direct
|=
!
cached
;
...
@@ -978,25 +988,17 @@ int main (int argc, char **argv)
...
@@ -978,25 +988,17 @@ int main (int argc, char **argv)
# endif
# endif
#endif
#endif
if
(
write_test
)
{
if
(
write_test
)
flags
=
O_RDWR
;
make_request
=
do_pwrite
;
make_request
=
do_pwrite
;
}
if
(
async
)
if
(
async
)
aio_setup
();
aio_setup
();
#ifndef HAVE_DIRECT_IO
if
(
direct
)
if
(
direct
)
#ifdef HAVE_DIRECT_IO
flags
|=
O_DIRECT
;
#else
errx
(
1
,
"direct I/O not supported by this platform"
);
errx
(
1
,
"direct I/O not supported by this platform"
);
#endif
#endif
#ifdef __MINGW32__
flags
|=
O_BINARY
;
#endif
if
(
stat
(
path
,
&
st
))
if
(
stat
(
path
,
&
st
))
err
(
2
,
"stat
\"
%s
\"
failed"
,
path
);
err
(
2
,
"stat
\"
%s
\"
failed"
,
path
);
...
@@ -1008,7 +1010,7 @@ int main (int argc, char **argv)
...
@@ -1008,7 +1010,7 @@ int main (int argc, char **argv)
st
.
st_size
=
offset
+
temp_wsize
;
st
.
st_size
=
offset
+
temp_wsize
;
parse_device
(
st
.
st_dev
);
parse_device
(
st
.
st_dev
);
}
else
if
(
S_ISBLK
(
st
.
st_mode
)
||
S_ISCHR
(
st
.
st_mode
))
{
}
else
if
(
S_ISBLK
(
st
.
st_mode
)
||
S_ISCHR
(
st
.
st_mode
))
{
fd
=
open
(
path
,
flags
);
fd
=
open
_file
(
path
,
NULL
);
if
(
fd
<
0
)
if
(
fd
<
0
)
err
(
2
,
"failed to open
\"
%s
\"
"
,
path
);
err
(
2
,
"failed to open
\"
%s
\"
"
,
path
);
...
@@ -1049,7 +1051,7 @@ int main (int argc, char **argv)
...
@@ -1049,7 +1051,7 @@ int main (int argc, char **argv)
random_memory
(
buf
,
size
);
random_memory
(
buf
,
size
);
if
(
S_ISDIR
(
st
.
st_mode
))
{
if
(
S_ISDIR
(
st
.
st_mode
))
{
fd
=
create_temp
(
path
,
"ioping.tmp"
);
fd
=
open_file
(
path
,
"ioping.tmp"
);
if
(
fd
<
0
)
if
(
fd
<
0
)
err
(
2
,
"failed to create temporary file at
\"
%s
\"
"
,
path
);
err
(
2
,
"failed to create temporary file at
\"
%s
\"
"
,
path
);
if
(
keep_file
)
{
if
(
keep_file
)
{
...
@@ -1075,7 +1077,7 @@ skip_preparation:
...
@@ -1075,7 +1077,7 @@ skip_preparation:
if
(
fsync
(
fd
))
if
(
fsync
(
fd
))
err
(
2
,
"fsync failed"
);
err
(
2
,
"fsync failed"
);
}
else
if
(
S_ISREG
(
st
.
st_mode
))
{
}
else
if
(
S_ISREG
(
st
.
st_mode
))
{
fd
=
open
(
path
,
flags
);
fd
=
open
_file
(
path
,
NULL
);
if
(
fd
<
0
)
if
(
fd
<
0
)
err
(
2
,
"failed to open
\"
%s
\"
"
,
path
);
err
(
2
,
"failed to open
\"
%s
\"
"
,
path
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment