/*
URL: svn://svnanon.samba.org/samba/branches/SAMBA_4_0/source/lib/tdb/common
Rev: 23590
Last Changed Date: 2007-06-22 13:36:10 -0400 (Fri, 22 Jun 2007)
*/
/*
trivial database library - standalone version
Copyright (C) Andrew Tridgell 1999-2005
Copyright (C) Jeremy Allison 2000-2006
Copyright (C) Paul `Rusty' Russell 2000
** NOTE! The following LGPL license applies to the tdb
** library. This does NOT imply that all of Samba is released
** under the LGPL
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifdef CONFIG_STAND_ALONE
#define HAVE_MMAP
#define HAVE_STRDUP
#define HAVE_SYS_MMAN_H
#define HAVE_UTIME_H
#define HAVE_UTIME
#endif
#define _XOPEN_SOURCE 600
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stddef.h>
#include <errno.h>
#include <string.h>
#ifdef HAVE_SYS_SELECT_H
#include <sys/select.h>
#endif
#include <sys/time.h>
#include <sys/types.h>
#include <time.h>
#ifdef HAVE_UTIME_H
#include <utime.h>
#endif
#include <sys/stat.h>
#include <sys/file.h>
#include <fcntl.h>
#ifdef HAVE_SYS_MMAN_H
#include <sys/mman.h>
#endif
#ifndef MAP_FILE
#define MAP_FILE 0
#endif
#ifndef MAP_FAILED
#define MAP_FAILED ((void *)-1)
#endif
#ifndef HAVE_STRDUP
#define strdup rep_strdup
static char *rep_strdup(const char *s)
{
char *ret;
int length;
if (!s)
return NULL;
if (!length)
length = strlen(s);
ret = malloc(length + 1);
if (ret) {
strncpy(ret, s, length);
ret[length] = '\0';
}
return ret;
}
#endif
#ifndef PRINTF_ATTRIBUTE
#if (__GNUC__ >= 3) && (__GNUC_MINOR__ >= 1 )
/** Use gcc attribute to check printf fns. a1 is the 1-based index of
* the parameter containing the format, and a2 the index of the first
* argument. Note that some gcc 2.x versions don't handle this
* properly **/
#define PRINTF_ATTRIBUTE(a1, a2) __attribute__ ((format (__printf__, a1, a2)))
#else
#define PRINTF_ATTRIBUTE(a1, a2)
#endif
#endif
typedef int bool;
#include "tdb.h"
#ifndef u32
#define u32 unsigned
#endif
#ifndef HAVE_GETPAGESIZE
#define getpagesize() 0x2000
#endif
typedef u32 tdb_len_t;
typedef u32 tdb_off_t;
#ifndef offsetof
#define offsetof(t,f) ((unsigned int)&((t *)0)->f)
#endif
#define TDB_MAGIC_FOOD "TDB file\n"
#define TDB_VERSION (0x26011967 + 6)
#define TDB_MAGIC (0x26011999U)
#define TDB_FREE_MAGIC (~TDB_MAGIC)
#define TDB_DEAD_MAGIC (0xFEE1DEAD)
#define TDB_RECOVERY_MAGIC (0xf53bc0e7U)
#define TDB_ALIGNMENT 4
#define MIN_REC_SIZE (2*sizeof(struct list_struct) + TDB_ALIGNMENT)
#define DEFAULT_HASH_SIZE 131
#define FREELIST_TOP (sizeof(struct tdb_header))
#define TDB_ALIGN(x,a) (((x) + (a)-1) & ~((a)-1))
#define TDB_BYTEREV(x) (((((x)&0xff)<<24)|((x)&0xFF00)<<8)|(((x)>>8)&0xFF00)|((x)>>24))
#define TDB_DEAD(r) ((r)->magic == TDB_DEAD_MAGIC)
#define TDB_BAD_MAGIC(r) ((r)->magic != TDB_MAGIC && !TDB_DEAD(r))
#define TDB_HASH_TOP(hash) (FREELIST_TOP + (BUCKET(hash)+1)*sizeof(tdb_off_t))
#define TDB_HASHTABLE_SIZE(tdb) ((tdb->header.hash_size+1)*sizeof(tdb_off_t))
#define TDB_DATA_START(hash_size) TDB_HASH_TOP(hash_size-1)
#define TDB_RECOVERY_HEAD offsetof(struct tdb_header, recovery_start)
#define TDB_SEQNUM_OFS offsetof(struct tdb_header, sequence_number)
#define TDB_PAD_BYTE 0x42
#define TDB_PAD_U32 0x42424242
/* NB assumes there is a local variable called "tdb" that is the
* current context, also takes doubly-parenthesized print-style
* argument. */
#define TDB_LOG(x) tdb->log.log_fn x
/* lock offsets */
#define GLOBAL_LOCK 0
#define ACTIVE_LOCK 4
#define TRANSACTION_LOCK 8
/* free memory if the pointer is valid and zero the pointer */
#ifndef SAFE_FREE
#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); (x)=NULL;} } while(0)
#endif
#define BUCKET(hash) ((hash) % tdb->header.hash_size)
#define DOCONV() (tdb->flags & TDB_CONVERT)
#define CONVERT(x) (DOCONV() ? tdb_convert(&x, sizeof(x)) : &x)
/* the body of the database is made of one list_struct for the free space
plus a separate data list for each hash value */
struct list_struct {
tdb_off_t next; /* offset of the next record in the list */
tdb_len_t rec_len; /* total byte length of record */
tdb_len_t key_len; /* byte length of key */
tdb_len_t data_len; /* byte length of data */
u32 full_hash; /* the full 32 bit hash of the key */
u32 magic; /* try to catch errors */
/* the following union is implied:
union {
char record[rec_len];
struct {
char key[key_len];
char data[data_len];
}
u32 totalsize; (tailer)
}
*/
};
/* this is stored at the front of every database */
struct tdb_header {
char magic_food[32]; /* for /etc/magic */
u32 version; /* version of the code */
u32 hash_size; /* number of hash entries */
tdb_off_t rwlocks; /* obsolete - kept to detect old formats */
tdb_off_t recovery_start; /* offset of transaction recovery region */
tdb_off_t sequence_number; /* used when TDB_SEQNUM is set */
tdb_off_t reserved[29];
};
struct tdb_lock_type {
int list;
u32 count;
u32 ltype;
};
struct tdb_traverse_lock {
struct tdb_traverse_lock *next;
u32 off;
u32 hash;
int lock_rw;
};
struct tdb_methods {
int (*tdb_read)(struct tdb_context *, tdb_off_t , void *, tdb_len_t , int );
int (*tdb_write)(struct tdb_context *, tdb_off_t, const void *, tdb_len_t);
void (*next_hash_chain)(struct tdb_context *, u32 *);
int (*tdb_oob)(struct tdb_context *, tdb_off_t , int );
int (*tdb_expand_file)(struct tdb_context *, tdb_off_t , tdb_off_t );
int (*tdb_brlock)(struct tdb_context *, tdb_off_t , int, int, int, size_t);
};
struct tdb_context {
char *name; /* the name of the database */
void *map_ptr; /* where it is currently mapped */
int fd; /* open file descriptor for the database */
tdb_len_t map_size; /* how much space has been mapped */
int read_only; /* opened read-only */
int traverse_read; /* read-only traversal */
struct tdb_lock_type global_lock;
int num_lockrecs;
struct tdb_lock_type *lockrecs; /* only real locks, all with count>0 */
enum TDB_ERROR ecode; /* error code for last tdb error */
struct tdb_header header; /* a cached copy of the header */
u32 flags; /* the flags passed to tdb_open */
struct tdb_traverse_lock travlocks; /* current traversal locks */
struct tdb_context *next; /* all tdbs to avoid multiple opens */
dev_t device; /* uniquely identifies this tdb */
ino_t inode; /* uniquely identifies this tdb */
struct tdb_logging_context log;
unsigned int (*hash_fn)(TDB_DATA *key);
int open_flags; /* flags used in the open - needed by reopen */
unsigned int num_locks; /* number of chain locks held */
const struct tdb_methods *methods;
struct tdb_transaction *transaction;
int page_size;
int max_dead_records;
bool have_transaction_lock;
};
/*
internal prototypes
*/
static int tdb_munmap(struct tdb_context *tdb);
static void tdb_mmap(struct tdb_context *tdb);
static int tdb_lock(struct tdb_context *tdb, int list, int ltype);
static int tdb_unlock(struct tdb_context *tdb, int list, int ltype);
static int tdb_brlock(struct tdb_context *tdb, tdb_off_t offset, int rw_type, int lck_type, int probe, size_t len);
static int tdb_transaction_lock(struct tdb_context *tdb, int ltype);
static int tdb_transaction_unlock(struct tdb_context *tdb);
static int tdb_brlock_upgrade(struct tdb_context *tdb, tdb_off_t off
没有合适的资源?快使用搜索试试~ 我知道了~
fuse-ext2-0.0.7
需积分: 10 4 下载量 176 浏览量
2017-05-17
12:18:39
上传
评论
收藏 557KB GZ 举报
温馨提示
共417个文件
t:184个
c:139个
h:35个
fuse-ext2-0.0.7,Linux下挂载ntfs文件系统
资源推荐
资源详情
资源评论
收起资源包目录
fuse-ext2-0.0.7 (417个子文件)
fuse-ext2.1 3KB
configure.ac 5KB
Makefile.am 3KB
Makefile.am 2KB
Makefile.am 1KB
Makefile.am 546B
Makefile.am 398B
Makefile.am 263B
Makefile.am 235B
._Makefile.am 167B
Makefile.am 164B
Makefile.am 160B
Makefile.am 139B
Makefile.am 97B
Makefile.am 18B
AUTHORS 263B
MACOSX.build 958B
tdb.c 110KB
mke2fs.c 52KB
extent.c 48KB
probe.c 45KB
profile.c 41KB
inode.c 21KB
icount.c 20KB
fstest.c 19KB
unix_io.c 19KB
fuse-ext2.install.c 14KB
undo_io.c 14KB
test_io.c 14KB
block.c 14KB
devname.c 13KB
initialize.c 13KB
mkjournal.c 13KB
fileio.c 11KB
ext2-fileio.c 11KB
gen_bitmap.c 11KB
openfs.c 11KB
fuse-ext2.wait.c 11KB
closefs.c 11KB
tag.c 10KB
read.c 10KB
swapfs.c 10KB
ismounted.c 9KB
fuse-ext2.c 9KB
rw_bitmaps.c 8KB
feature.c 8KB
op_rename.c 8KB
imager.c 8KB
bmap.c 8KB
gen_uuid.c 8KB
inode_io.c 7KB
csum.c 7KB
fstest.c 7KB
util.c 7KB
alloc.c 7KB
ext2_err.c 7KB
getsize.c 6KB
badblocks.c 6KB
error_message.c 6KB
dir_iterate.c 6KB
alloc_tables.c 6KB
bb_inode.c 6KB
dblist.c 6KB
dirhash.c 6KB
res_gdt.c 6KB
dev.c 5KB
op_create.c 5KB
namei.c 5KB
devno.c 5KB
getsize.c 5KB
bitmaps.c 4KB
fuse-ext2.uninstall.c 4KB
cache.c 4KB
uuid_time.c 4KB
save.c 4KB
finddev.c 4KB
op_rmdir.c 4KB
op_statfs.c 4KB
link.c 4KB
op_readdir.c 3KB
get_pathname.c 3KB
fuse-ext2.probe.c 3KB
com_right.c 3KB
op_mkdir.c 3KB
ext_attr.c 3KB
crc16.c 3KB
vnode_hash.c 3KB
op_link.c 3KB
resolve.c 3KB
llseek.c 3KB
llseek.c 3KB
dirblock.c 3KB
alloc_stats.c 3KB
mkdir.c 3KB
op_unlink.c 3KB
expanddir.c 3KB
e2label.c 3KB
unparse.c 2KB
check_desc.c 2KB
parse.c 2KB
共 417 条
- 1
- 2
- 3
- 4
- 5
资源评论
GouplovXim
- 粉丝: 7
- 资源: 5
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功