- bind wd_softc to f->f_devdata.

- allow to have BSDFFS, EXT2FS and DOSFS on disk drive.
- the bootloader name is becoming unappropriate.
This commit is contained in:
nisimura 2008-04-09 06:07:57 +00:00
parent 9bad45d03e
commit 2553846738
2 changed files with 70 additions and 6 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: atawd.c,v 1.3 2008/04/09 00:20:35 nisimura Exp $ */
/* $NetBSD: atawd.c,v 1.4 2008/04/09 06:07:57 nisimura Exp $ */
#include <sys/types.h>
#include <sys/param.h>
@ -47,6 +47,7 @@ int ndisk;
int wdopen(struct open_file *, ...);
int wdclose(struct open_file *);
int wdstrategy(void *, int, daddr_t, size_t, void *, size_t *);
int parsefstype(void *);
static int wd_get_params(struct wd_softc *);
static int wdgetdisklabel(struct wd_softc *);
@ -87,13 +88,15 @@ wdopen(struct open_file *f, ...)
if (pp->p_size == 0 || pp->p_fstype == FS_UNUSED)
return ENXIO;
wd->sc_part = part;
f->f_devdata = wd;
return 0;
}
int
wdclose(struct open_file *f)
{
f->f_devdata = NULL;
return 0;
}
@ -312,6 +315,16 @@ wdgetdisklabel(struct wd_softc *wd)
return 0;
}
int
parsefstype(void *data)
{
struct wd_softc *wd = data;
struct disklabel *lp = &wd->sc_label;
struct partition *pp = &lp->d_partitions[wd->sc_part];
return pp->p_fstype;
}
static int
atac_wait_for_ready(struct atac_channel *chp)
{

View File

@ -1,4 +1,4 @@
/* $NetBSD: devopen.c,v 1.5 2007/11/29 04:00:17 nisimura Exp $ */
/* $NetBSD: devopen.c,v 1.6 2008/04/09 06:07:57 nisimura Exp $ */
/*-
* Copyright (c) 2007 The NetBSD Foundation, Inc.
@ -38,22 +38,38 @@
#include <sys/param.h>
#include <sys/disklabel.h>
#include <netinet/in.h>
#include <lib/libsa/stand.h>
#include <lib/libsa/nfs.h>
#include <lib/libsa/ufs.h>
#include <lib/libsa/ext2fs.h>
#include <lib/libsa/dosfs.h>
#include <lib/libkern/libkern.h>
int net_open(struct open_file *, ...);
int net_close(struct open_file *);
int net_strategy(void *, int, daddr_t, size_t, void *, size_t *);
int wdopen(struct open_file *, ...);
int wdclose(struct open_file *);
int wdstrategy(void *, int, daddr_t, size_t, void *, size_t *);
int parsefstype(void *);
static void parseunit(const char *, int *, int *, char **);
struct devsw devsw[] = {
{ "net", net_strategy, net_open, net_close, noioctl },
{ "dsk", wdstrategy, wdopen, wdclose, noioctl },
};
int ndevs = sizeof(devsw) / sizeof(devsw[0]);
struct fs_ops ops_nfs = FS_OPS(nfs);
struct fs_ops fssw[] = {
FS_OPS(nfs),
FS_OPS(ffsv1),
FS_OPS(ext2fs),
FS_OPS(dosfs),
};
struct fs_ops file_system[1];
int nfsys = 1;
@ -63,7 +79,7 @@ devopen(of, name, file)
const char *name;
char **file;
{
int error;
int error, unit, part;
extern char bootfile[]; /* handed by DHCP */
if (of->f_flags != F_READ)
@ -73,10 +89,26 @@ devopen(of, name, file)
of->f_dev = &devsw[0];
if ((error = net_open(of, name)) != 0)
return error;
file_system[0] = ops_nfs;
file_system[0] = fssw[0];
*file = bootfile; /* resolved fname */
return 0; /* NFS */
}
if (name[0] == 'w' && name[1] == 'd') {
parseunit(&name[2], &unit, &part, file);
of->f_dev = &devsw[1];
if ((error = wdopen(of, unit, part)) != 0)
return error;
switch (parsefstype(of->f_devdata)) {
default:
case FS_BSDFFS:
file_system[0] = fssw[1]; break;
case FS_EX2FS:
file_system[0] = fssw[2]; break;
case FS_MSDOS:
file_system[0] = fssw[3]; break;
}
return 0;
}
return ENOENT;
}
@ -90,3 +122,22 @@ noioctl(f, cmd, data)
return EINVAL;
}
static void
parseunit(const char *name, int *unitp, int *partp, char **pathp)
{
const char *p = name;
int unit, part;
unit = part = -1;
while (*p != ':' && *p != '\0') {
if (unit == -1 && *p >= '0' && *p <= '9')
unit = *p - '0';
if (part == -1 && *p >= 'a' && *p < 'a' + 16)
part = *p - 'a';
p += 1;
}
*unitp = (unit == -1) ? 0 : unit;
*partp = (part == -1) ? 0 : part;
*pathp = (*p == ':') ? (char *)p + 1 : NULL;
}