Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
W
wendelin.core
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
Joshua
wendelin.core
Commits
92d6dbf0
Commit
92d6dbf0
authored
Jul 09, 2019
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
56411971
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
43 additions
and
5 deletions
+43
-5
bigfile/tests/test_virtmem.c
bigfile/tests/test_virtmem.c
+43
-5
No files found.
bigfile/tests/test_virtmem.c
View file @
92d6dbf0
...
...
@@ -1139,6 +1139,25 @@ void *mmapfile_mmap_setup_read(BigFile *file, blk_t blk, size_t blklen, VMA *vma
return
addr
;
}
int
mmapfile_storeblk
(
BigFile
*
file
,
blk_t
blk
,
const
void
*
buf
)
{
BigFileMMap
*
f
=
upcast
(
BigFileMMap
*
,
file
);
size_t
n
=
f
->
blksize
;
off_t
at
=
blk
*
f
->
blksize
;
while
(
n
>
0
)
{
ssize_t
wrote
;
wrote
=
pwrite
(
f
->
fd
,
buf
,
n
,
at
);
if
(
wrote
==
-
1
)
return
-
1
;
BUG_ON
(
wrote
>
n
);
n
-=
wrote
;
buf
+=
wrote
;
}
return
0
;
}
void
mmapfile_release
(
BigFile
*
file
)
{
BigFileMMap
*
f
=
upcast
(
BigFileMMap
*
,
file
);
int
err
;
...
...
@@ -1149,8 +1168,8 @@ void mmapfile_release(BigFile *file) {
static
const
struct
bigfile_ops
mmapfile_ops
=
{
.
loadblk
=
NULL
,
// .storeblk = mmapfile_storeblk,
.
mmap_setup_read
=
mmapfile_mmap_setup_read
,
.
storeblk
=
mmapfile_storeblk
,
.
release
=
mmapfile_release
,
};
...
...
@@ -1173,21 +1192,40 @@ void test_file_access_mmapbase(void)
/* ensure we are starting from new ram */
ok1
(
list_empty
(
&
ram
->
lru_list
));
/* setup mmaped
id
file */
/* setup mmaped file */
char
path
[]
=
"/tmp/bigfile_mmap.XXXXXX"
;
fd
=
mkstemp
(
path
);
ok1
(
fd
!=
-
1
);
err
=
unlink
(
path
);
ok1
(
!
err
);
// XXX write data
BigFileMMap
file
id
=
{
BigFileMMap
file
=
{
.
blksize
=
ram
->
pagesize
,
/* artificially blksize = pagesize */
.
file_ops
=
&
mmapfile_ops
,
.
fd
=
fd
,
};
err
=
fileh_open
(
fh
,
&
fileid
,
ram
);
/* fstore stores date into file[blk] */
void
fstore
(
blk_t
blk
,
blk_t
data
)
{
blk_t
*
buf
;
int
i
;
buf
=
malloc
(
file
.
blksize
);
BUG_ON
(
!
buf
);
for
(
i
=
0
;
i
<
file
.
blksize
/
sizeof
(
*
buf
);
i
++
)
buf
[
i
]
=
data
;
err
=
file
.
file_ops
->
storeblk
(
&
file
,
blk
,
buf
);
BUG_ON
(
err
);
free
(
buf
);
}
/* initialize file[100 +4) */
fstore
(
100
,
100
);
fstore
(
101
,
101
);
fstore
(
102
,
102
);
fstore
(
103
,
103
);
err
=
fileh_open
(
fh
,
&
file
,
ram
);
ok1
(
!
err
);
/* implicitly use fileh=fh */
...
...
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