1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-01-02 01:18:26 +03:00

o Remove redundant symlink-handling code.

o When opening device, return error if its cached name is incorrect (eg if
  it's changed since the cache was generated).  This prevents use until
  the cache is rebuilt (eg with vgscan).  Doesn't catch every case.
This commit is contained in:
Alasdair Kergon 2002-01-23 18:55:01 +00:00
parent d518bc39f3
commit 610c25e8b1
2 changed files with 12 additions and 40 deletions

View File

@ -120,28 +120,6 @@ static int _insert_dev(const char *path, dev_t d)
return 1;
}
/*
* return a new path for the destination of the link.
*/
static char *_follow_link(const char *path, struct stat *info)
{
char buffer[PATH_MAX + 1];
int n;
n = readlink(path, buffer, sizeof(buffer) - 1);
if (n <= 0)
return NULL;
buffer[n] = '\0';
if (stat(buffer, info) < 0) {
log_sys_very_verbose("stat", buffer);
return NULL;
}
return pool_strdup(_cache.mem, buffer);
}
static char *_join(const char *dir, const char *name)
{
int len = strlen(dir) + strlen(name) + 2;
@ -208,7 +186,6 @@ static int _insert_dir(const char *dir)
static int _insert(const char *path, int rec)
{
struct stat info;
char *actual_path;
int r = 0;
if (stat(path, &info) < 0) {
@ -216,22 +193,6 @@ static int _insert(const char *path, int rec)
return 0;
}
/* follow symlinks if neccessary. */
if (S_ISLNK(info.st_mode)) {
log_debug("%s: Following symbolic link", path);
if (!(actual_path = _follow_link(path, &info))) {
stack;
return 0;
}
if (stat(actual_path, &info) < 0) {
log_sys_very_verbose("stat", actual_path);
return 0;
}
dbg_free(actual_path);
}
if (S_ISDIR(info.st_mode)) { /* add a directory */
if (rec)
r = _insert_dir(path);

View File

@ -64,19 +64,30 @@ int dev_get_sectsize(struct device *dev, uint32_t *size)
int dev_open(struct device *dev, int flags)
{
struct stat buf;
const char *name = dev_name(dev);
/* FIXME Check flags (eg is write now reqd?) */
if (dev->fd >= 0) {
log_error("Device '%s' has already been opened", name);
return 0;
}
if ((stat(name, &buf) < 0) || (buf.st_rdev != dev->dev)) {
log_error("%s: stat failed: Has device name changed?", name);
return 0;
}
if ((dev->fd = open(name, flags)) < 0) {
log_sys_error("open", name);
return 0;
}
if ((fstat(dev->fd, &buf) < 0) || (buf.st_rdev != dev->dev)) {
log_error("%s: fstat failed: Has device name changed?", name);
dev_close(dev->fd);
return 0;
}
return 1;
}