1/* 2 * ---------------------------------------------------------------------------- 3 * "THE BEER-WARE LICENSE" (Revision 42): 4 * <phk@FreeBSD.ORG> wrote this file. As long as you retain this notice you 5 * can do whatever you want with this stuff. If we meet some day, and you think 6 * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp 7 * ---------------------------------------------------------------------------- 8 *
| 1/* 2 * ---------------------------------------------------------------------------- 3 * "THE BEER-WARE LICENSE" (Revision 42): 4 * <phk@FreeBSD.ORG> wrote this file. As long as you retain this notice you 5 * can do whatever you want with this stuff. If we meet some day, and you think 6 * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp 7 * ---------------------------------------------------------------------------- 8 *
|
9 * $FreeBSD: head/sys/kern/subr_disk.c 62617 2000-07-05 06:01:33Z imp $
| 9 * $FreeBSD: head/sys/kern/subr_disk.c 64880 2000-08-20 21:34:39Z phk $
|
10 * 11 */ 12
| 10 * 11 */ 12
|
| 13#include "opt_devfs.h" 14
|
13#include <sys/param.h> 14#include <sys/systm.h> 15#include <sys/kernel.h> 16#include <sys/sysctl.h> 17#include <sys/bio.h> 18#include <sys/conf.h> 19#include <sys/disk.h> 20#include <sys/malloc.h> 21#include <sys/sysctl.h> 22#include <machine/md_var.h> 23
| 15#include <sys/param.h> 16#include <sys/systm.h> 17#include <sys/kernel.h> 18#include <sys/sysctl.h> 19#include <sys/bio.h> 20#include <sys/conf.h> 21#include <sys/disk.h> 22#include <sys/malloc.h> 23#include <sys/sysctl.h> 24#include <machine/md_var.h> 25
|
| 26#ifdef DEVFS 27#include <sys/eventhandler.h> 28#include <fs/devfs/devfs.h> 29#include <sys/ctype.h> 30#endif 31
|
24MALLOC_DEFINE(M_DISK, "disk", "disk data"); 25 26static d_strategy_t diskstrategy; 27static d_open_t diskopen; 28static d_close_t diskclose; 29static d_ioctl_t diskioctl; 30static d_psize_t diskpsize; 31 32static LIST_HEAD(, disk) disklist = LIST_HEAD_INITIALIZER(&disklist);
| 32MALLOC_DEFINE(M_DISK, "disk", "disk data"); 33 34static d_strategy_t diskstrategy; 35static d_open_t diskopen; 36static d_close_t diskclose; 37static d_ioctl_t diskioctl; 38static d_psize_t diskpsize; 39 40static LIST_HEAD(, disk) disklist = LIST_HEAD_INITIALIZER(&disklist);
|
33
| 41 42#ifdef DEVFS
|
34static void
| 43static void
|
| 44disk_clone(void *arg, char *name, int namelen, dev_t *dev) 45{ 46 struct disk *dp; 47 char const *d; 48 int i, u, s, p; 49 dev_t pdev; 50 51 if (*dev != NODEV) 52 return; 53 54 LIST_FOREACH(dp, &disklist, d_list) { 55 d = dp->d_devsw->d_name; 56 i = strlen(d); 57 if (bcmp(d, name, i) != 0) 58 continue; 59 u = 0; 60 if (!isdigit(name[i])) 61 continue; 62 while (isdigit(name[i])) { 63 u *= 10; 64 u += name[i++] - '0'; 65 } 66 p = RAW_PART; 67 s = WHOLE_DISK_SLICE; 68 pdev = makedev(dp->d_devsw->d_maj, dkmakeminor(u, s, p)); 69 if (pdev->si_disk == NULL) 70 continue; 71 if (name[i] != '\0') { 72 if (name[i] == 's') { 73 s = 0; 74 i++; 75 if (!isdigit(name[i])) 76 continue; 77 while (isdigit(name[i])) { 78 s *= 10; 79 s += name[i++] - '0'; 80 } 81 s += BASE_SLICE - 1; 82 } else { 83 s = COMPATIBILITY_SLICE; 84 } 85 if (name[i] == '\0') 86 ; 87 else if (name[i] < 'a' || name[i] > 'h') 88 continue; 89 else 90 p = name[i] - 'a'; 91 } 92 93 *dev = make_dev(pdev->si_devsw, dkmakeminor(u, s, p), 94 UID_ROOT, GID_OPERATOR, 0640, name); 95 return; 96 } 97} 98#endif 99 100static void
|
35inherit_raw(dev_t pdev, dev_t dev) 36{ 37 dev->si_disk = pdev->si_disk; 38 dev->si_drv1 = pdev->si_drv1; 39 dev->si_drv2 = pdev->si_drv2; 40 dev->si_iosize_max = pdev->si_iosize_max; 41 dev->si_bsize_phys = pdev->si_bsize_phys; 42 dev->si_bsize_best = pdev->si_bsize_best; 43} 44 45dev_t 46disk_create(int unit, struct disk *dp, int flags, struct cdevsw *cdevsw, struct cdevsw *proto) 47{
| 101inherit_raw(dev_t pdev, dev_t dev) 102{ 103 dev->si_disk = pdev->si_disk; 104 dev->si_drv1 = pdev->si_drv1; 105 dev->si_drv2 = pdev->si_drv2; 106 dev->si_iosize_max = pdev->si_iosize_max; 107 dev->si_bsize_phys = pdev->si_bsize_phys; 108 dev->si_bsize_best = pdev->si_bsize_best; 109} 110 111dev_t 112disk_create(int unit, struct disk *dp, int flags, struct cdevsw *cdevsw, struct cdevsw *proto) 113{
|
| 114 static int once;
|
48 dev_t dev; 49 50 bzero(dp, sizeof(*dp)); 51 52 dev = makedev(cdevsw->d_maj, 0); 53 if (!devsw(dev)) { 54 *proto = *cdevsw; 55 proto->d_open = diskopen; 56 proto->d_close = diskclose; 57 proto->d_ioctl = diskioctl; 58 proto->d_strategy = diskstrategy; 59 proto->d_psize = diskpsize; 60 cdevsw_add(proto); 61 } 62 63 if (bootverbose) 64 printf("Creating DISK %s%d\n", cdevsw->d_name, unit); 65 dev = make_dev(proto, dkmakeminor(unit, WHOLE_DISK_SLICE, RAW_PART),
| 115 dev_t dev; 116 117 bzero(dp, sizeof(*dp)); 118 119 dev = makedev(cdevsw->d_maj, 0); 120 if (!devsw(dev)) { 121 *proto = *cdevsw; 122 proto->d_open = diskopen; 123 proto->d_close = diskclose; 124 proto->d_ioctl = diskioctl; 125 proto->d_strategy = diskstrategy; 126 proto->d_psize = diskpsize; 127 cdevsw_add(proto); 128 } 129 130 if (bootverbose) 131 printf("Creating DISK %s%d\n", cdevsw->d_name, unit); 132 dev = make_dev(proto, dkmakeminor(unit, WHOLE_DISK_SLICE, RAW_PART),
|
66 0, 0, 0, "%s%d", cdevsw->d_name, unit);
| 133 UID_ROOT, GID_OPERATOR, 0640, "%s%d", cdevsw->d_name, unit);
|
67 68 dev->si_disk = dp; 69 dp->d_dev = dev; 70 dp->d_dsflags = flags; 71 dp->d_devsw = cdevsw; 72 LIST_INSERT_HEAD(&disklist, dp, d_list);
| 134 135 dev->si_disk = dp; 136 dp->d_dev = dev; 137 dp->d_dsflags = flags; 138 dp->d_devsw = cdevsw; 139 LIST_INSERT_HEAD(&disklist, dp, d_list);
|
| 140 if (!once) { 141#ifdef DEVFS 142 EVENTHANDLER_REGISTER(devfs_clone, disk_clone, 0, 1000); 143#endif 144 once++; 145 }
|
73 return (dev); 74} 75 76int 77disk_dumpcheck(dev_t dev, u_int *count, u_int *blkno, u_int *secsize) 78{ 79 struct disk *dp; 80 struct disklabel *dl;
--- 218 unchanged lines hidden --- | 146 return (dev); 147} 148 149int 150disk_dumpcheck(dev_t dev, u_int *count, u_int *blkno, u_int *secsize) 151{ 152 struct disk *dp; 153 struct disklabel *dl;
--- 218 unchanged lines hidden --- |