Changeset View
Changeset View
Standalone View
Standalone View
sys/kern/subr_devstat.c
Show All 26 Lines | |||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||||
* SUCH DAMAGE. | * SUCH DAMAGE. | ||||
*/ | */ | ||||
#include <sys/cdefs.h> | #include <sys/cdefs.h> | ||||
__FBSDID("$FreeBSD$"); | __FBSDID("$FreeBSD$"); | ||||
#include <sys/param.h> | #include <sys/param.h> | ||||
#include <sys/disk.h> | |||||
#include <sys/kernel.h> | #include <sys/kernel.h> | ||||
#include <sys/systm.h> | #include <sys/systm.h> | ||||
#include <sys/bio.h> | #include <sys/bio.h> | ||||
#include <sys/devicestat.h> | #include <sys/devicestat.h> | ||||
#include <sys/sdt.h> | #include <sys/sdt.h> | ||||
#include <sys/sysctl.h> | #include <sys/sysctl.h> | ||||
#include <sys/malloc.h> | #include <sys/malloc.h> | ||||
#include <sys/lock.h> | #include <sys/lock.h> | ||||
▲ Show 20 Lines • Show All 425 Lines • ▼ Show 20 Lines | |||||
/* | /* | ||||
* Allocator for struct devstat structures. We sub-allocate these from pages | * Allocator for struct devstat structures. We sub-allocate these from pages | ||||
* which we get from malloc. These pages are exported for mmap(2)'ing through | * which we get from malloc. These pages are exported for mmap(2)'ing through | ||||
* a miniature device driver | * a miniature device driver | ||||
*/ | */ | ||||
#define statsperpage (PAGE_SIZE / sizeof(struct devstat)) | #define statsperpage (PAGE_SIZE / sizeof(struct devstat)) | ||||
static d_ioctl_t devstat_ioctl; | |||||
static d_mmap_t devstat_mmap; | static d_mmap_t devstat_mmap; | ||||
static struct cdevsw devstat_cdevsw = { | static struct cdevsw devstat_cdevsw = { | ||||
.d_version = D_VERSION, | .d_version = D_VERSION, | ||||
.d_ioctl = devstat_ioctl, | |||||
.d_mmap = devstat_mmap, | .d_mmap = devstat_mmap, | ||||
.d_name = "devstat", | .d_name = "devstat", | ||||
}; | }; | ||||
struct statspage { | struct statspage { | ||||
TAILQ_ENTRY(statspage) list; | TAILQ_ENTRY(statspage) list; | ||||
struct devstat *stat; | struct devstat *stat; | ||||
u_int nfree; | u_int nfree; | ||||
}; | }; | ||||
static size_t pagelist_pages = 0; | |||||
static TAILQ_HEAD(, statspage) pagelist = TAILQ_HEAD_INITIALIZER(pagelist); | static TAILQ_HEAD(, statspage) pagelist = TAILQ_HEAD_INITIALIZER(pagelist); | ||||
static MALLOC_DEFINE(M_DEVSTAT, "devstat", "Device statistics"); | static MALLOC_DEFINE(M_DEVSTAT, "devstat", "Device statistics"); | ||||
static int | static int | ||||
devstat_ioctl(struct cdev *dev, u_long cmd, caddr_t data, int fflag, | |||||
struct thread *td) | |||||
{ | |||||
int error = ENOTTY; | |||||
switch (cmd) { | |||||
case DIOCGMEDIASIZE: | |||||
error = 0; | |||||
*(off_t *)data = pagelist_pages * PAGE_SIZE; | |||||
mav: Double semicolon. | |||||
break; | |||||
} | |||||
return (error); | |||||
} | |||||
static int | |||||
devstat_mmap(struct cdev *dev, vm_ooffset_t offset, vm_paddr_t *paddr, | devstat_mmap(struct cdev *dev, vm_ooffset_t offset, vm_paddr_t *paddr, | ||||
int nprot, vm_memattr_t *memattr) | int nprot, vm_memattr_t *memattr) | ||||
{ | { | ||||
struct statspage *spp; | struct statspage *spp; | ||||
if (nprot != VM_PROT_READ) | if (nprot != VM_PROT_READ) | ||||
return (-1); | return (-1); | ||||
mtx_lock(&devstat_mutex); | mtx_lock(&devstat_mutex); | ||||
▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | for (;;) { | ||||
if (spp == NULL) { | if (spp == NULL) { | ||||
spp = spp2; | spp = spp2; | ||||
/* | /* | ||||
* It would make more sense to add the new page at the | * It would make more sense to add the new page at the | ||||
* head but the order on the list determine the | * head but the order on the list determine the | ||||
* sequence of the mapping so we can't do that. | * sequence of the mapping so we can't do that. | ||||
*/ | */ | ||||
pagelist_pages++; | |||||
TAILQ_INSERT_TAIL(&pagelist, spp, list); | TAILQ_INSERT_TAIL(&pagelist, spp, list); | ||||
} else | } else | ||||
break; | break; | ||||
} | } | ||||
dsp = spp->stat; | dsp = spp->stat; | ||||
for (u = 0; u < statsperpage; u++) { | for (u = 0; u < statsperpage; u++) { | ||||
if (dsp->allocated == 0) | if (dsp->allocated == 0) | ||||
break; | break; | ||||
Show All 29 Lines |
Double semicolon.