And by using opendev(3) tunefs can accept disk UID's.
Any actual tunefs(8) guru's out there who can explain what this
might break?
Inspired by oga@'s work on atactl.
This is the last use of opendisk(3) in the tree. Any reason to
keep it if this goes in? ports?
.... Ken
Index: tunefs.c
===================================================================
RCS file: /cvs/src/sbin/tunefs/tunefs.c,v
retrieving revision 1.30
diff -u -p -r1.30 tunefs.c
--- tunefs.c 27 Oct 2009 23:59:34 -0000 1.30
+++ tunefs.c 5 May 2011 03:52:44 -0000
@@ -71,7 +71,6 @@ static void bwrite(daddr64_t, char *, in
static void bread(daddr64_t, char *, int, const char *);
static int getnum(const char *, const char *, int, int);
static void getsb(struct fs *, const char *);
-static int openpartition(const char *, int, char *, size_t);
static void usage(void);
int
@@ -79,8 +78,8 @@ main(int argc, char *argv[])
{
#define OPTSTRING "AFNe:g:h:m:o:"
int i, ch, Aflag, Fflag, Nflag, openflags;
- const char *special, *chg[2];
- char device[MAXPATHLEN];
+ const char *chg[2];
+ char *special;
int maxbpg, minfree, optim;
int avgfilesize, avgfpdir;
@@ -151,10 +150,8 @@ main(int argc, char *argv[])
openflags = Nflag ? O_RDONLY : O_RDWR;
if (Fflag)
fi = open(special, openflags);
- else {
- fi = openpartition(special, openflags, device, sizeof(device));
- special = device;
- }
+ else
+ fi = opendev(special, openflags, OPENDEV_PART, &special);
if (fi == -1)
err(1, "%s", special);
getsb(&sblock, special);
@@ -270,7 +267,8 @@ getsb(struct fs *fs, const char *file)
for (i = 0; ; i++) {
if (sblock_try[i] == -1)
- errx(5, "cannot find filesystem superblock");
+ errx(5, "cannot find filesystem superblock on '%s'",
+ file);
bread(sblock_try[i] / dev_bsize, (char *)fs, SBLOCKSIZE, file);
switch(fs->fs_magic) {
case FS_UFS2_MAGIC:
@@ -316,29 +314,4 @@ bread(daddr64_t blk, char *buffer, int c
err(4, "%s: seeking to %lld", file, (long long)offset);
if ((i = read(fi, buffer, cnt)) != cnt)
errx(5, "%s: short read", file);
-}
-
-static int
-openpartition(const char *name, int flags, char *device, size_t devicelen)
-{
- char rawspec[MAXPATHLEN], *p;
- struct fstab *fs;
- int fd, oerrno;
-
- fs = getfsfile(name);
- if (fs) {
- if ((p = strrchr(fs->fs_spec, '/')) != NULL) {
- snprintf(rawspec, sizeof(rawspec), "%.*s/r%s",
- (int)(p - fs->fs_spec), fs->fs_spec, p + 1);
- name = rawspec;
- } else
- name = fs->fs_spec;
- }
- fd = opendisk(name, flags, device, devicelen, 0);
- if (fd == -1 && errno == ENOENT) {
- oerrno = errno;
- strlcpy(device, name, devicelen);
- errno = oerrno;
- }
- return (fd);
}