diff options
author | Jeff Garzik <jeff@garzik.org> | 2006-11-08 08:02:29 -0500 |
---|---|---|
committer | Jeff Garzik <jeff@garzik.org> | 2006-11-08 08:02:29 -0500 |
commit | 09a311724182f30ee64d48b0f5a52b6cca1f9cd6 (patch) | |
tree | d5ed5f90f3ce4098bab9e485d49b9f5af923541a | |
parent | e5145d5497a2b3f405efd83d460834371c5bff9c (diff) | |
download | dbfs-09a311724182f30ee64d48b0f5a52b6cca1f9cd6.tar.gz |
Minor cleanups and improvements.
- const-ify some function args
- properly indicate to Berkeley DB logging whether or not to syslog
- trim trailing whitespace
-rw-r--r-- | dbdebugfs.c | 3 | ||||
-rw-r--r-- | dbfs-backend.c | 39 | ||||
-rw-r--r-- | dbfs.c | 10 | ||||
-rw-r--r-- | dbfs.h | 5 | ||||
-rw-r--r-- | dbfsck.c | 3 | ||||
-rw-r--r-- | libdbfs.c | 15 | ||||
-rw-r--r-- | mkdbfs.c | 4 | ||||
-rw-r--r-- | xattr.c | 2 |
8 files changed, 49 insertions, 32 deletions
diff --git a/dbdebugfs.c b/dbdebugfs.c index 863da36..c7e6edf 100644 --- a/dbdebugfs.c +++ b/dbdebugfs.c @@ -93,7 +93,8 @@ int main (int argc, char *argv[]) if (!fs) return 1; - rc = dbfs_open(fs, DB_RECOVER | DB_CREATE, DB_CREATE, "dbdebugfs"); + rc = dbfs_open(fs, DB_RECOVER | DB_CREATE, DB_CREATE, + "dbdebugfs", FALSE); if (rc) { perror("dbfsck"); return 1; diff --git a/dbfs-backend.c b/dbfs-backend.c index acad386..8f6053c 100644 --- a/dbfs-backend.c +++ b/dbfs-backend.c @@ -41,7 +41,7 @@ struct dbfs_dirscan_info { void *ent; }; -static int dbfs_data_unref(DB_TXN *txn, dbfs_blk_id_t *id); +static int dbfs_data_unref(DB_TXN *txn, const dbfs_blk_id_t *id); int dbmeta_del(DB_TXN *txn, const char *key_str) { @@ -80,7 +80,7 @@ static int dbfs_mode_type(guint32 mode, enum dbfs_inode_type *itype) return 0; } -static int dbfs_inode_del_data(DB_TXN *txn, struct dbfs_inode *ino) +static int dbfs_inode_del_data(DB_TXN *txn, const struct dbfs_inode *ino) { int i, rc = 0; @@ -93,7 +93,7 @@ static int dbfs_inode_del_data(DB_TXN *txn, struct dbfs_inode *ino) return 0; } -int dbfs_inode_del(DB_TXN *txn, struct dbfs_inode *ino) +int dbfs_inode_del(DB_TXN *txn, const struct dbfs_inode *ino) { guint64 ino_n = GUINT64_FROM_LE(ino->raw_inode->ino); char key[32]; @@ -388,7 +388,8 @@ static int dbfs_name_validate(const char *name) return 0; } -static int dbfs_dir_append(DB_TXN *txn, guint64 parent, guint64 ino_n, const char *name) +static int dbfs_dir_append(DB_TXN *txn, guint64 parent, guint64 ino_n, + const char *name) { struct dbfs_dirscan_info di; struct dbfs_dirent *de; @@ -522,7 +523,8 @@ int dbfs_link(DB_TXN *txn, struct dbfs_inode *ino, guint64 ino_n, return rc; } -int dbfs_unlink(DB_TXN *txn, guint64 parent, const char *name, unsigned long flags) +int dbfs_unlink(DB_TXN *txn, guint64 parent, const char *name, + unsigned long flags) { struct dbfs_inode *ino; guint64 ino_n; @@ -652,8 +654,8 @@ static void ext_list_free(GList *ext_list) g_list_free(ext_list); } -static int dbfs_ext_match(struct dbfs_inode *ino, guint64 off, guint32 rd_size, - GList **ext_list_out) +static int dbfs_ext_match(const struct dbfs_inode *ino, guint64 off, + guint32 rd_size, GList **ext_list_out) { struct dbfs_extent *ext; guint64 pos; @@ -742,18 +744,19 @@ static gboolean is_zero_buf(const void *buf, size_t buflen) return TRUE; } -static gboolean is_null_id(dbfs_blk_id_t *id) +static gboolean is_null_id(const dbfs_blk_id_t *id) { return is_zero_buf(id, DBFS_BLK_ID_LEN); } -static int dbfs_ext_read(DB_TXN *txn, dbfs_blk_id_t *id, void **buf, size_t *buflen) +static int dbfs_ext_read(DB_TXN *txn, const dbfs_blk_id_t *id, void **buf, + size_t *buflen) { DBT key, val; int rc; memset(&key, 0, sizeof(key)); - key.data = id; + key.data = (void *) id; key.size = DBFS_BLK_ID_LEN; memset(&val, 0, sizeof(val)); @@ -838,7 +841,7 @@ out: return rc < 0 ? rc : buflen; } -static int dbfs_write_unique_buf(DB_TXN *txn, DBT *key, const void *buf, +static int dbfs_write_unique_buf(DB_TXN *txn, const DBT *key, const void *buf, size_t buflen) { struct dbfs_hashref ref; @@ -851,7 +854,7 @@ static int dbfs_write_unique_buf(DB_TXN *txn, DBT *key, const void *buf, val.data = &ref; val.size = sizeof(ref); - rc = gfs->hashref->put(gfs->hashref, txn, key, &val, 0); + rc = gfs->hashref->put(gfs->hashref, txn, (DBT *) key, &val, 0); if (rc) return -EIO; @@ -859,7 +862,7 @@ static int dbfs_write_unique_buf(DB_TXN *txn, DBT *key, const void *buf, val.data = (void *) buf; val.size = buflen; - rc = gfs->data->put(gfs->data, txn, key, &val, DB_NOOVERWRITE); + rc = gfs->data->put(gfs->data, txn, (DBT *) key, &val, DB_NOOVERWRITE); if (rc) return -EIO; @@ -909,7 +912,7 @@ static int dbfs_write_buf(DB_TXN *txn, const void *buf, size_t buflen, return rc ? -EIO : 0; } -static int dbfs_data_unref(DB_TXN *txn, dbfs_blk_id_t *id) +static int dbfs_data_unref(DB_TXN *txn, const dbfs_blk_id_t *id) { struct dbfs_hashref *ref; guint32 refs; @@ -920,7 +923,7 @@ static int dbfs_data_unref(DB_TXN *txn, dbfs_blk_id_t *id) return 0; memset(&key, 0, sizeof(key)); - key.data = id; + key.data = (void *) id; key.size = DBFS_BLK_ID_LEN; memset(&val, 0, sizeof(val)); @@ -958,7 +961,7 @@ static int dbfs_inode_realloc(struct dbfs_inode *ino, unsigned int new_n_extents) { struct dbfs_raw_inode *new_raw; - size_t new_size = sizeof(struct dbfs_inode) + + size_t new_size = sizeof(struct dbfs_inode) + (sizeof(struct dbfs_extent) * new_n_extents); new_raw = g_malloc0(new_size); @@ -996,12 +999,12 @@ int dbfs_inode_resize(DB_TXN *txn, struct dbfs_inode *ino, guint64 new_size) rc = dbfs_inode_realloc(ino, new_n_extents); if (rc) return rc; - + for (i = old_n_extents; i < new_n_extents; i++) { g_assert(diff > 0); tmp = MIN(diff, DBFS_MAX_EXT_LEN); - memset(&ino->raw_inode->blocks[i], 0, + memset(&ino->raw_inode->blocks[i], 0, sizeof(struct dbfs_extent)); ino->raw_inode->blocks[i].len = GUINT32_TO_LE(tmp); @@ -99,9 +99,11 @@ static void dbfs_op_init(void *userdata) fs = dbfs_new(); - rc = dbfs_open(fs, DB_RECOVER | DB_CREATE, DB_CREATE, "dbfs"); - if (rc) + rc = dbfs_open(fs, DB_RECOVER | DB_CREATE, DB_CREATE, "dbfs", TRUE); + if (rc) { + syslog(LOG_ERR, "dbfs_open failed"); abort(); /* TODO: improve */ + } gfs = fs; @@ -972,7 +974,7 @@ static void dbfs_op_statfs(fuse_req_t req) { struct statvfs f; struct statfs st; - + if (debugging) syslog(LOG_DEBUG, "ENTER dbfs_op_statfs"); @@ -1114,7 +1116,7 @@ static void dbfs_op_listxattr(fuse_req_t req, fuse_ino_t ino, size_t size) fuse_reply_err(req, ERANGE); else fuse_reply_buf(req, buf, buflen); - + free(buf); return; @@ -150,7 +150,7 @@ extern int dbfs_mknod(DB_TXN *txn, guint64 parent, const char *name, guint32 mode, guint64 rdev, struct dbfs_inode **ino); extern int dbfs_symlink_write(DB_TXN *txn, guint64 ino, const char *link); -extern int dbfs_inode_del(DB_TXN *txn, struct dbfs_inode *ino); +extern int dbfs_inode_del(DB_TXN *txn, const struct dbfs_inode *ino); extern int dbfs_xattr_get(DB_TXN *TXN, guint64 ino_n, const char *name, void **buf_out, size_t *buflen_out); extern int dbfs_xattr_set(DB_TXN *TXN, guint64 ino_n, const char *name, @@ -164,7 +164,8 @@ extern int dbfs_inode_resize(DB_TXN *txn, struct dbfs_inode *ino, guint64 new_si extern int dbfs_rename(DB_TXN *txn, guint64, const char *, guint64, const char *); /* libdbfs.c */ -extern int dbfs_open(struct dbfs *, unsigned int, unsigned int, const char *); +extern int dbfs_open(struct dbfs *, unsigned int, unsigned int, const char *, + gboolean syslog); extern void dbfs_close(struct dbfs *fs); extern struct dbfs *dbfs_new(void); extern void dbfs_free(struct dbfs *fs); @@ -32,7 +32,8 @@ int main (int argc, char *argv[]) if (!fs) return 1; - rc = dbfs_open(fs, DB_RECOVER_FATAL | DB_CREATE, DB_CREATE, "dbfsck"); + rc = dbfs_open(fs, DB_RECOVER_FATAL | DB_CREATE, DB_CREATE, + "dbfsck", FALSE); if (rc) { perror("dbfsck"); return 1; @@ -21,12 +21,19 @@ #include <string.h> #include <stdio.h> #include <errno.h> +#include <syslog.h> #include <glib.h> #include <db.h> #include "dbfs.h" struct dbfs *gfs; +static void dbfs_db_syslog(const DB_ENV *dbenv, const char *errpfx, + const char *msg) +{ + syslog(LOG_WARNING, "%s: %s", errpfx, msg); +} + static int open_db(DB_ENV *env, DB **db_out, const char *name, unsigned int page_size, unsigned int flags) { @@ -65,7 +72,7 @@ static int open_db(DB_ENV *env, DB **db_out, const char *name, } int dbfs_open(struct dbfs *fs, unsigned int env_flags, unsigned int flags, - const char *errpfx) + const char *errpfx, gboolean syslog) { const char *db_home, *db_password; int rc; @@ -86,8 +93,10 @@ int dbfs_open(struct dbfs *fs, unsigned int env_flags, unsigned int flags, return rc; } - /* stderr is wrong; should use syslog instead */ - fs->env->set_errfile(fs->env, stderr); + if (syslog) + fs->env->set_errcall(fs->env, dbfs_db_syslog); + else + fs->env->set_errfile(fs->env, stderr); fs->env->set_errpfx(fs->env, errpfx); if (db_password) { @@ -55,7 +55,7 @@ static int make_root_dir(DB_TXN *txn) rc = dbfs_dir_new(txn, 1, 1, ino); if (rc) goto err_die; - + dbfs_inode_free(ino); return 0; @@ -76,7 +76,7 @@ int main (int argc, char *argv[]) if (!fs) return 1; - int rc = dbfs_open(fs, DB_CREATE, DB_CREATE, "mkdbfs"); + int rc = dbfs_open(fs, DB_CREATE, DB_CREATE, "mkdbfs", FALSE); if (rc) { perror("mkdbfs open"); return 1; @@ -270,7 +270,7 @@ int dbfs_xattr_get(DB_TXN *txn, guint64 ino_n, const char *name, rc = dbfs_xattr_read(txn, ino_n, name, &val); if (rc) return rc; - + *buf_out = val.data; *buflen_out = val.size; |