Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
ccan
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mirror
ccan
Commits
9e837118
Commit
9e837118
authored
Apr 07, 2009
by
Rusty Russell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Change arguments to crcsync code.
parent
5ed7afb3
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
22 additions
and
27 deletions
+22
-27
ccan/crcsync/crcsync.c
ccan/crcsync/crcsync.c
+12
-17
ccan/crcsync/crcsync.h
ccan/crcsync/crcsync.h
+4
-4
ccan/crcsync/test/run-crash.c
ccan/crcsync/test/run-crash.c
+2
-2
ccan/crcsync/test/run.c
ccan/crcsync/test/run.c
+4
-4
No files found.
ccan/crcsync/crcsync.c
View file @
9e837118
...
...
@@ -35,8 +35,8 @@ struct crc_context {
int
have_match
;
/* Final block is special (if a different size) */
size_t
fina
l_size
;
uint32_t
fina
l_crc
;
size_t
tai
l_size
;
uint32_t
tai
l_crc
;
/* Uncrc tab. */
uint32_t
uncrc_tab
[
256
];
...
...
@@ -66,25 +66,20 @@ static void init_uncrc_tab(uint32_t uncrc_tab[], unsigned int wsize)
struct
crc_context
*
crc_context_new
(
size_t
block_size
,
unsigned
crcbits
,
const
uint32_t
crc
[],
unsigned
num_crcs
,
size_t
fina
l_size
)
size_t
tai
l_size
)
{
struct
crc_context
*
ctx
;
assert
(
num_crcs
>
0
);
assert
(
block_size
>
0
);
assert
(
final_size
>
0
);
assert
(
final_size
<=
block_size
);
assert
(
tail_size
<
block_size
);
ctx
=
malloc
(
sizeof
(
*
ctx
)
+
sizeof
(
crc
[
0
])
*
num_crcs
);
if
(
ctx
)
{
ctx
->
block_size
=
block_size
;
if
(
final_size
!=
block_size
)
{
ctx
->
final_size
=
final_size
;
ctx
->
final_crc
=
crc
[
--
num_crcs
];
}
else
{
/* If this is 0, we never compare against it. */
ctx
->
final_size
=
0
;
}
ctx
->
tail_size
=
tail_size
;
if
(
tail_size
)
ctx
->
tail_crc
=
crc
[
--
num_crcs
];
/* Technically, 1 << 32 is undefined. */
if
(
crcbits
>=
32
)
...
...
@@ -123,12 +118,12 @@ static int crc_matches(const struct crc_context *ctx)
return
-
1
;
}
static
bool
fina
l_matches
(
const
struct
crc_context
*
ctx
)
static
bool
tai
l_matches
(
const
struct
crc_context
*
ctx
)
{
if
(
ctx
->
literal_bytes
!=
ctx
->
fina
l_size
)
if
(
ctx
->
literal_bytes
!=
ctx
->
tai
l_size
)
return
false
;
return
(
ctx
->
running_crc
&
ctx
->
crcmask
)
==
ctx
->
fina
l_crc
;
return
(
ctx
->
running_crc
&
ctx
->
crcmask
)
==
ctx
->
tai
l_crc
;
}
static
uint32_t
crc_add_byte
(
uint32_t
crc
,
uint8_t
newbyte
)
...
...
@@ -197,7 +192,7 @@ size_t crc_read_block(struct crc_context *ctx, long *result,
old
=
buf
;
/* We don't roll this csum, we only look for it after
* a block match. It's simpler and faster. */
if
(
fina
l_matches
(
ctx
))
{
if
(
tai
l_matches
(
ctx
))
{
crcmatch
=
ctx
->
num_crcs
;
goto
have_match
;
}
...
...
@@ -217,7 +212,7 @@ size_t crc_read_block(struct crc_context *ctx, long *result,
have_match:
*
result
=
-
crcmatch
-
1
;
if
(
crcmatch
==
ctx
->
num_crcs
)
assert
(
ctx
->
literal_bytes
==
ctx
->
fina
l_size
);
assert
(
ctx
->
literal_bytes
==
ctx
->
tai
l_size
);
else
assert
(
ctx
->
literal_bytes
==
ctx
->
block_size
);
ctx
->
literal_bytes
=
0
;
...
...
ccan/crcsync/crcsync.h
View file @
9e837118
...
...
@@ -19,14 +19,14 @@ void crc_of_blocks(const void *data, size_t len, unsigned int blocksize,
/**
* crc_context_new - allocate and initialize state for crc_find_block
* @blocksize: the sie of each block
* @blocksize: the si
z
e of each block
* @crcbits: the bits valid in the CRCs (<= 32)
* @crc: array of block crcs
* @crc: array of block crcs
(including final block, if any)
* @num_crcs: number of block crcs
* @
final_size: the final block size (<=
blocksize).
* @
tail_size: the size of final partial block, if any (<
blocksize).
*
* Returns an allocated pointer to the structure for crc_find_block,
* or NULL. Makes a copy of @crc
and @num_crcs
.
* or NULL. Makes a copy of @crc.
*/
struct
crc_context
*
crc_context_new
(
size_t
blocksize
,
unsigned
crcbits
,
const
uint32_t
crc
[],
unsigned
num_crcs
,
...
...
ccan/crcsync/test/run-crash.c
View file @
9e837118
...
...
@@ -55,14 +55,14 @@ int main(int argc, char *argv[])
size_t
ndigested
;
size_t
offset
=
0
;
size_t
len2
=
strlen
(
data2
);
size_t
finalsize
=
strlen
(
data1
)
%
BLOCKSIZE
?:
BLOCKSIZE
;
size_t
tailsize
=
strlen
(
data1
)
%
BLOCKSIZE
;
int
expected_i
=
0
;
plan_tests
(
ARRAY_SIZE
(
expected
)
+
2
);
crcblocks
(
&
crc_info1
,
data1
,
strlen
(
data1
),
BLOCKSIZE
);
crcctx
=
crc_context_new
(
BLOCKSIZE
,
30
,
crc_info1
.
crcs
,
crc_info1
.
block_count
,
fina
lsize
);
tai
lsize
);
while
(
offset
<
len2
)
{
ndigested
=
crc_read_block
(
crcctx
,
&
result
,
data2
+
offset
,
len2
-
offset
);
...
...
ccan/crcsync/test/run.c
View file @
9e837118
...
...
@@ -65,17 +65,17 @@ static void test_sync(const char *buffer1, size_t len1,
const
struct
result
results
[],
size_t
num_results
)
{
struct
crc_context
*
ctx
;
size_t
used
,
ret
,
i
,
curr_literal
,
fina
lsize
;
size_t
used
,
ret
,
i
,
curr_literal
,
tai
lsize
;
long
result
;
uint32_t
crcs
[
num_blocks
(
len1
,
block_size
)];
crc_of_blocks
(
buffer1
,
len1
,
block_size
,
32
,
crcs
);
finalsize
=
len1
%
block_size
?:
block_size
;
tailsize
=
len1
%
block_size
;
/* Normal method. */
ctx
=
crc_context_new
(
block_size
,
32
,
crcs
,
ARRAY_SIZE
(
crcs
),
fina
lsize
);
tai
lsize
);
curr_literal
=
0
;
for
(
used
=
0
,
i
=
0
;
used
<
len2
;
used
+=
ret
)
{
...
...
@@ -94,7 +94,7 @@ static void test_sync(const char *buffer1, size_t len1,
/* Byte-at-a-time method. */
ctx
=
crc_context_new
(
block_size
,
32
,
crcs
,
ARRAY_SIZE
(
crcs
),
fina
lsize
);
tai
lsize
);
curr_literal
=
0
;
for
(
used
=
0
,
i
=
0
;
used
<
len2
;
used
+=
ret
)
{
...
...
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