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
46b1a03e
Commit
46b1a03e
authored
Jun 22, 2009
by
Rusty Russell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ccanize tdb further, and add simple test.
parent
2c67a284
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
64 additions
and
5 deletions
+64
-5
ccan/tdb/io.c
ccan/tdb/io.c
+3
-3
ccan/tdb/open.c
ccan/tdb/open.c
+1
-0
ccan/tdb/tdb.h
ccan/tdb/tdb.h
+2
-0
ccan/tdb/tdb_private.h
ccan/tdb/tdb_private.h
+6
-1
ccan/tdb/test/run.c
ccan/tdb/test/run.c
+48
-0
ccan/tdb/transaction.c
ccan/tdb/transaction.c
+1
-1
config.h
config.h
+3
-0
No files found.
ccan/tdb/io.c
View file @
46b1a03e
...
...
@@ -189,7 +189,7 @@ int tdb_munmap(struct tdb_context *tdb)
if
(
tdb
->
flags
&
TDB_INTERNAL
)
return
0
;
#if
def
HAVE_MMAP
#if HAVE_MMAP
if
(
tdb
->
map_ptr
)
{
int
ret
=
munmap
(
tdb
->
map_ptr
,
tdb
->
map_size
);
if
(
ret
!=
0
)
...
...
@@ -205,11 +205,11 @@ void tdb_mmap(struct tdb_context *tdb)
if
(
tdb
->
flags
&
TDB_INTERNAL
)
return
;
#if
def
HAVE_MMAP
#if HAVE_MMAP
if
(
!
(
tdb
->
flags
&
TDB_NOMMAP
))
{
tdb
->
map_ptr
=
mmap
(
NULL
,
tdb
->
map_size
,
PROT_READ
|
(
tdb
->
read_only
?
0
:
PROT_WRITE
),
MAP_SHARED
|
MAP_FILE
,
tdb
->
fd
,
0
);
MAP_SHARED
,
tdb
->
fd
,
0
);
/*
* NB. When mmap fails it returns MAP_FAILED *NOT* NULL !!!!
...
...
ccan/tdb/open.c
View file @
46b1a03e
...
...
@@ -159,6 +159,7 @@ struct tdb_context *tdb_open_ex(const char *name, int hash_size, int tdb_flags,
errno
=
ENOMEM
;
goto
fail
;
}
tdb_io_init
(
tdb
);
tdb
->
fd
=
-
1
;
tdb
->
name
=
NULL
;
...
...
ccan/tdb/tdb.h
View file @
46b1a03e
...
...
@@ -33,6 +33,8 @@ extern "C" {
#ifndef _SAMBA_BUILD_
/* For mode_t */
#include <sys/types.h>
/* For O_* flags. */
#include <sys/stat.h>
/* For sig_atomic_t. */
#include <signal.h>
#endif
...
...
ccan/tdb/tdb_private.h
View file @
46b1a03e
#ifndef TDB_PRIVATE_H
#define TDB_PRIVATE_H
/*
Unix SMB/CIFS implementation.
...
...
@@ -42,10 +44,12 @@
#include <string.h>
#include <errno.h>
#include <stdio.h>
#include <utime.h>
#include "config.h"
#endif
#include "tdb.h"
#if
ndef
HAVE_GETPAGESIZE
#if HAVE_GETPAGESIZE
#define getpagesize() 0x2000
#endif
...
...
@@ -225,3 +229,4 @@ int tdb_rec_free_read(struct tdb_context *tdb, tdb_off_t off,
struct
list_struct
*
rec
);
#endif
ccan/tdb/test/run.c
0 → 100644
View file @
46b1a03e
#define _XOPEN_SOURCE 500
#include "tdb/tdb.h"
#include "tdb/io.c"
#include "tdb/tdb.c"
#include "tdb/lock.c"
#include "tdb/freelist.c"
#include "tdb/traverse.c"
#include "tdb/transaction.c"
#include "tdb/error.c"
#include "tdb/open.c"
#include "tap/tap.h"
#include <stdlib.h>
#include <err.h>
int
main
(
int
argc
,
char
*
argv
[])
{
struct
tdb_context
*
tdb
;
TDB_DATA
key
,
data
;
plan_tests
(
10
);
tdb
=
tdb_open
(
"/tmp/test.tdb"
,
1024
,
TDB_CLEAR_IF_FIRST
,
O_CREAT
|
O_TRUNC
|
O_RDWR
,
0600
);
ok1
(
tdb
);
key
.
dsize
=
strlen
(
"hi"
);
key
.
dptr
=
(
void
*
)
"hi"
;
data
.
dsize
=
strlen
(
"world"
);
data
.
dptr
=
(
void
*
)
"world"
;
ok1
(
tdb_store
(
tdb
,
key
,
data
,
TDB_MODIFY
)
<
0
);
ok1
(
tdb_error
(
tdb
)
==
TDB_ERR_NOEXIST
);
ok1
(
tdb_store
(
tdb
,
key
,
data
,
TDB_INSERT
)
==
0
);
ok1
(
tdb_store
(
tdb
,
key
,
data
,
TDB_INSERT
)
<
0
);
ok1
(
tdb_error
(
tdb
)
==
TDB_ERR_EXISTS
);
ok1
(
tdb_store
(
tdb
,
key
,
data
,
TDB_MODIFY
)
==
0
);
data
=
tdb_fetch
(
tdb
,
key
);
ok1
(
data
.
dsize
==
strlen
(
"world"
));
ok1
(
memcmp
(
data
.
dptr
,
"world"
,
strlen
(
"world"
))
==
0
);
free
(
data
.
dptr
);
key
.
dsize
++
;
data
=
tdb_fetch
(
tdb
,
key
);
ok1
(
data
.
dptr
==
NULL
);
tdb_close
(
tdb
);
return
exit_status
();
}
ccan/tdb/transaction.c
View file @
46b1a03e
...
...
@@ -989,7 +989,7 @@ int tdb_transaction_commit(struct tdb_context *tdb)
not be backed up (as tdb rounding to block sizes means that
file size changes are quite rare too). The following forces
mtime changes when a transaction completes */
#if
def
HAVE_UTIME
#if HAVE_UTIME
utime
(
tdb
->
name
,
NULL
);
#endif
...
...
config.h
View file @
46b1a03e
...
...
@@ -8,3 +8,6 @@
#define HAVE_BUILTIN_CHOOSE_EXPR 1
#define HAVE_LITTLE_ENDIAN 1
#define HAVE_BIG_ENDIAN 0
#define HAVE_MMAP 1
#define HAVE_GETPAGESIZE 1
#define HAVE_UTIME 1
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