mirror of
git://sourceware.org/git/lvm2.git
synced 2024-10-27 01:55:10 +03:00
o dev_cache_t program works
This commit is contained in:
parent
721128e86d
commit
43b7b8cf69
6
configure
vendored
6
configure
vendored
@ -1317,7 +1317,7 @@ else
|
||||
int main() {
|
||||
|
||||
/* Ultrix mips cc rejects this. */
|
||||
typedef int charset[2]; const charset x = {0,0};
|
||||
typedef int charset[2]; const charset x;
|
||||
/* SunOS 4.1.1 cc rejects this. */
|
||||
char const *const *ccp;
|
||||
char **p;
|
||||
@ -1392,7 +1392,7 @@ for ac_kw in inline __inline__ __inline; do
|
||||
#include "confdefs.h"
|
||||
|
||||
int main() {
|
||||
} int $ac_kw foo() {
|
||||
} $ac_kw foo() {
|
||||
; return 0; }
|
||||
EOF
|
||||
if { (eval echo configure:1399: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
|
||||
@ -2160,6 +2160,7 @@ lib/Makefile \
|
||||
man/Makefile \
|
||||
tools/Makefile \
|
||||
test/mm/Makefile \
|
||||
test/device/Makefile \
|
||||
test/format1/Makefile \
|
||||
" | sed "s/:[^ ]*//g"` conftest*; exit 1' 1 2 15
|
||||
EOF
|
||||
@ -2257,6 +2258,7 @@ lib/Makefile \
|
||||
man/Makefile \
|
||||
tools/Makefile \
|
||||
test/mm/Makefile \
|
||||
test/device/Makefile \
|
||||
test/format1/Makefile \
|
||||
"}
|
||||
EOF
|
||||
|
@ -136,5 +136,6 @@ lib/Makefile \
|
||||
man/Makefile \
|
||||
tools/Makefile \
|
||||
test/mm/Makefile \
|
||||
test/device/Makefile \
|
||||
test/format1/Makefile \
|
||||
)
|
||||
|
@ -188,7 +188,7 @@ void *hash_get_data(struct hash_table *t, struct hash_node *n)
|
||||
|
||||
static struct hash_node *_next_slot(struct hash_table *t, unsigned int s)
|
||||
{
|
||||
struct hash_node *c = 0;
|
||||
struct hash_node *c = NULL;
|
||||
int i;
|
||||
|
||||
for (i = s; i < t->num_slots && !c; i++)
|
||||
@ -204,6 +204,7 @@ struct hash_node *hash_get_first(struct hash_table *t)
|
||||
|
||||
struct hash_node *hash_get_next(struct hash_table *t, struct hash_node *n)
|
||||
{
|
||||
return n->next ? n->next : _next_slot(t, _hash(n->key) + 1);
|
||||
unsigned int h = _hash(n->key) & (t->num_slots - 1);
|
||||
return n->next ? n->next : _next_slot(t, h + 1);
|
||||
}
|
||||
|
||||
|
@ -46,6 +46,8 @@ static struct {
|
||||
#define _alloc(x) pool_alloc(_cache.mem, (x))
|
||||
#define _free(x) pool_free(_cache.mem, (x))
|
||||
|
||||
static int _dir_scan(const char *dir);
|
||||
|
||||
/*
|
||||
* return a new path for the destination of the path.
|
||||
*/
|
||||
@ -90,9 +92,8 @@ static void _collapse_slashes(char *str)
|
||||
*str = *ptr;
|
||||
}
|
||||
|
||||
static struct device *_create_dev(const char *path)
|
||||
static struct device *_create_dev(const char *path, struct stat *info)
|
||||
{
|
||||
struct stat info;
|
||||
struct device *dev;
|
||||
char *name = pool_strdup(_cache.mem, path);
|
||||
|
||||
@ -103,31 +104,13 @@ static struct device *_create_dev(const char *path)
|
||||
|
||||
_collapse_slashes(name);
|
||||
|
||||
if (stat(name, &info) < 0) {
|
||||
log_sys_err("stat");
|
||||
goto bad;
|
||||
}
|
||||
|
||||
if (S_ISLNK(info.st_mode)) {
|
||||
log_debug("%s is a symbolic link, following\n", name);
|
||||
if (!(name = _follow_link(name, &info))) {
|
||||
stack;
|
||||
goto bad;
|
||||
}
|
||||
}
|
||||
|
||||
if (!S_ISBLK(info.st_mode)) {
|
||||
log_debug("%s is not a block device\n", name);
|
||||
goto bad;
|
||||
}
|
||||
|
||||
if (!(dev = _alloc(sizeof(*dev)))) {
|
||||
stack;
|
||||
goto bad;
|
||||
}
|
||||
|
||||
dev->name = name;
|
||||
dev->dev = info.st_rdev;
|
||||
dev->dev = info->st_rdev;
|
||||
return dev;
|
||||
|
||||
bad:
|
||||
@ -135,28 +118,75 @@ static struct device *_create_dev(const char *path)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static struct device *_add(const char *dir, const char *path)
|
||||
static int _insert(const char *path, int recurse)
|
||||
{
|
||||
struct device *d;
|
||||
int len = strlen(dir) + strlen(path) + 2;
|
||||
char *buffer = dbg_malloc(len);
|
||||
struct stat info;
|
||||
struct device *dev;
|
||||
|
||||
snprintf(buffer, len, "%s/%s", dir, path);
|
||||
d = dev_cache_get(buffer, NULL);
|
||||
dbg_free(buffer);
|
||||
log_debug("dev-cache adding %s", path);
|
||||
|
||||
return d;
|
||||
if (stat(path, &info) < 0) {
|
||||
log_sys_err("stat");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (S_ISDIR(info.st_mode)) {
|
||||
if (recurse)
|
||||
return _dir_scan(path);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (S_ISLNK(info.st_mode)) {
|
||||
log_debug("%s is a symbolic link, following", path);
|
||||
if (!(path = _follow_link(path, &info))) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (!S_ISBLK(info.st_mode)) {
|
||||
log_debug("%s is not a block device", path);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!(dev = _create_dev(path, &info))) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
|
||||
hash_insert(_cache.devices, path, dev);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static char *_join(const char *dir, const char *name)
|
||||
{
|
||||
int len = strlen(dir) + strlen(name) + 2;
|
||||
char *r = dbg_malloc(len);
|
||||
if (r)
|
||||
snprintf(r, len, "%s/%s", dir, name);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
static int _dir_scan(const char *dir)
|
||||
{
|
||||
int n, dirent_count;
|
||||
struct dirent **dirent;
|
||||
char *path;
|
||||
|
||||
dirent_count = scandir(dir, &dirent, NULL, alphasort);
|
||||
if (dirent_count > 0) {
|
||||
for (n = 0; n < dirent_count; n++) {
|
||||
_add(dir, dirent[n]->d_name);
|
||||
if (dirent[n]->d_name[0] == '.') {
|
||||
free(dirent[n]);
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((path = _join(dir, dirent[n]->d_name)))
|
||||
_insert(path, 1);
|
||||
|
||||
dbg_free(path);
|
||||
free(dirent[n]);
|
||||
}
|
||||
free(dirent);
|
||||
@ -217,21 +247,14 @@ int dev_cache_add_dir(const char *path)
|
||||
return 1;
|
||||
}
|
||||
|
||||
struct device *_insert_new(const char *name)
|
||||
{
|
||||
struct device *d = _create_dev(name);
|
||||
if (!d || !hash_insert(_cache.devices, name, d))
|
||||
return NULL;
|
||||
|
||||
return d;
|
||||
}
|
||||
|
||||
struct device *dev_cache_get(const char *name, struct dev_filter *f)
|
||||
{
|
||||
struct device *d = (struct device *) hash_lookup(_cache.devices, name);
|
||||
|
||||
if (!d && (d = _create_dev(name)))
|
||||
hash_insert(_cache.devices, name, d);
|
||||
if (!d) {
|
||||
_insert(name, 0);
|
||||
d = (struct device *) hash_lookup(_cache.devices, name);
|
||||
}
|
||||
|
||||
return (d && (!f || f->passes_filter(f, d))) ? d : NULL;
|
||||
}
|
||||
|
20
old-tests/device/Makefile.in
Normal file
20
old-tests/device/Makefile.in
Normal file
@ -0,0 +1,20 @@
|
||||
#
|
||||
# Copyright (C) 2001 Sistina Software (UK) Limited
|
||||
#
|
||||
# This file is released under the GPL.
|
||||
#
|
||||
|
||||
srcdir = @srcdir@
|
||||
top_srcdir = @top_srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
SOURCES=\
|
||||
dev_cache_t.c
|
||||
|
||||
TARGETS=dev_cache_t
|
||||
|
||||
include ../../make.tmpl
|
||||
|
||||
dev_cache_t: dev_cache_t.o $(top_srcdir)/lib/liblvm.a
|
||||
$(CC) -o dev_cache_t dev_cache_t.o -L$(top_srcdir)/lib -llvm
|
||||
|
48
old-tests/device/dev_cache_t.c
Normal file
48
old-tests/device/dev_cache_t.c
Normal file
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (C) 2001 Sistina Software (UK) Limited
|
||||
*
|
||||
* This file is released under the GPL.
|
||||
*/
|
||||
|
||||
#include "dbg_malloc.h"
|
||||
#include "dev-cache.h"
|
||||
#include "log.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
struct device *dev;
|
||||
struct dev_iter *iter;
|
||||
|
||||
init_log(stderr);
|
||||
init_debug(_LOG_DEBUG);
|
||||
|
||||
if (!dev_cache_init()) {
|
||||
log_error("couldn't initialise dev_cache_init failed\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
for (i = 1; i < argc; i++) {
|
||||
if (!dev_cache_add_dir(argv[i])) {
|
||||
log_error("couldn't add '%s' to dev_cache\n", argv[i]);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
if (!(iter = dev_iter_create(NULL))) {
|
||||
log_error("couldn't create iterator\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
while ((dev = dev_iter_get(iter)))
|
||||
printf("%s\n", dev->name);
|
||||
|
||||
dev_iter_destroy(iter);
|
||||
dev_cache_exit();
|
||||
|
||||
dump_memory();
|
||||
fin_log();
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user