summaryrefslogtreecommitdiffstats
path: root/lib/libufs
diff options
context:
space:
mode:
authorjmallett <jmallett@FreeBSD.org>2003-01-19 00:43:17 +0000
committerjmallett <jmallett@FreeBSD.org>2003-01-19 00:43:17 +0000
commit0a0a65bb423dc414c3e1520986bcbff86a7a1220 (patch)
tree3812cc63a17efcafd391f4e30d9ffc028ebd44e2 /lib/libufs
parentc4382c90c1c40b6c974e885d944fe12334f1cf29 (diff)
downloadFreeBSD-src-0a0a65bb423dc414c3e1520986bcbff86a7a1220.zip
FreeBSD-src-0a0a65bb423dc414c3e1520986bcbff86a7a1220.tar.gz
Hunt for a disk to operate on, if we're passed a partition mountpoint, etc.
Concept reviewed by: phk
Diffstat (limited to 'lib/libufs')
-rw-r--r--lib/libufs/libufs.h1
-rw-r--r--lib/libufs/type.c42
2 files changed, 41 insertions, 2 deletions
diff --git a/lib/libufs/libufs.h b/lib/libufs/libufs.h
index c2f11a9..266f787 100644
--- a/lib/libufs/libufs.h
+++ b/lib/libufs/libufs.h
@@ -80,6 +80,7 @@ struct uufsd {
/* superblock as buffer */
} d_sbunion;
const char *d_error; /* human readable disk error */
+ int d_mine; /* internal flags */
#define d_fs d_sbunion.d_fs
#define d_sb d_sbunion.d_sb
};
diff --git a/lib/libufs/type.c b/lib/libufs/type.c
index 622cba8..d3182d3 100644
--- a/lib/libufs/type.c
+++ b/lib/libufs/type.c
@@ -39,6 +39,8 @@ __FBSDID("$FreeBSD$");
#include <errno.h>
#include <fcntl.h>
+#include <fstab.h>
+#include <paths.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -46,6 +48,9 @@ __FBSDID("$FreeBSD$");
#include <libufs.h>
+/* Internally, track the 'name' value, it's ours. */
+#define MINE_NAME 0x01
+
struct uufsd *
ufs_disk_ctor(const char *name)
{
@@ -96,19 +101,42 @@ ufs_disk_close(struct uufsd *disk)
free(disk->d_inoblock);
disk->d_inoblock = NULL;
}
+ if (disk->d_mine & MINE_NAME) {
+ free((char *)(uintptr_t)disk->d_name);
+ disk->d_name = NULL;
+ }
return 0;
}
int
ufs_disk_fillout(struct uufsd *disk, const char *name)
{
+ struct stat st;
+ struct fstab *fs;
+ const char *oname;
+ char dev[MAXPATHLEN];
int fd;
ERROR(disk, NULL);
+ oname = name;
+ fs = getfsfile(name);
+ if (fs != NULL)
+ name = fs->fs_spec;
+again: if (stat(name, &st) < 0) {
+ if (*name != '/') {
+ if (*name == 'r')
+ name++;
+ snprintf(dev, sizeof(dev), "%s%s", _PATH_DEV, name);
+ name = dev;
+ goto again;
+ }
+ ERROR(disk, "could not find special device");
+ return -1;
+ }
fd = open(name, O_RDONLY);
if (fd == -1) {
- ERROR(disk, "failed to open disk for reading");
+ ERROR(disk, "could not open special device");
return -1;
}
@@ -117,10 +145,20 @@ ufs_disk_fillout(struct uufsd *disk, const char *name)
disk->d_inoblock = NULL;
disk->d_inomin = 0;
disk->d_inomax = 0;
- disk->d_name = name;
+ disk->d_mine = 0;
disk->d_ufs = 0;
disk->d_error = NULL;
+ if (oname != name) {
+ name = strdup(name);
+ if (name == NULL) {
+ ERROR(disk, "could not allocate memory for disk name");
+ return -1;
+ }
+ disk->d_mine |= MINE_NAME;
+ }
+ disk->d_name = name;
+
if (sbread(disk) == -1) {
ERROR(disk, "could not read superblock to fill out disk");
return -1;
OpenPOWER on IntegriCloud