Changeset View
Changeset View
Standalone View
Standalone View
sys/geom/geom_phys2disk.c
- This file was added.
/*- | |||||
* Copyright (c) 2017 Wheel Systems | |||||
* All rights reserved. | |||||
* | |||||
* This software was developed by Pawel Jakub Dawidek and Mariusz Zaborski | |||||
* under sponsorship from Wheel Systems. | |||||
* | |||||
* Redistribution and use in source and binary forms, with or without | |||||
* modification, are permitted provided that the following conditions | |||||
* are met: | |||||
* 1. Redistributions of source code must retain the above copyright | |||||
* notice, this list of conditions and the following disclaimer. | |||||
* 2. Redistributions in binary form must reproduce the above copyright | |||||
* notice, this list of conditions and the following disclaimer in the | |||||
* documentation and/or other materials provided with the distribution. | |||||
* | |||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND | |||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE | |||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||||
* SUCH DAMAGE. | |||||
*/ | |||||
#include <sys/cdefs.h> | |||||
__FBSDID("$FreeBSD$"); | |||||
#include <sys/ctype.h> | |||||
#include <sys/param.h> | |||||
#include <sys/kernel.h> | |||||
#include <sys/systm.h> | |||||
#include <sys/sysctl.h> | |||||
#include <geom/geom_phys2disk.h> | |||||
static char disk_phys2unit[1024]; | |||||
SYSCTL_STRING(_kern, OID_AUTO, phys2unit, CTLFLAG_RDTUN, | |||||
disk_phys2unit, 0, "Disk connection to unit mapping"); | |||||
static int | |||||
disk_unit(const char *phys) | |||||
{ | |||||
int unit; | |||||
char *ptr; | |||||
ptr = strstr(disk_phys2unit, phys); | |||||
if (ptr == NULL) | |||||
return (-1); | |||||
ptr += strlen(phys); | |||||
if (ptr >= disk_phys2unit + sizeof(disk_phys2unit) - 1) { | |||||
printf("%s: Invalid kern.phys2unit value.\n", __func__); | |||||
return (-1); | |||||
} | |||||
if (*ptr < '0' || *ptr > '9') { | |||||
printf("%s: Invalid kern.phys2unit value.\n", __func__); | |||||
return (-1); | |||||
} | |||||
unit = 0; | |||||
for (; ptr <= disk_phys2unit + sizeof(disk_phys2unit) - 1; ptr++) { | |||||
if (*ptr < '0' || *ptr > '9') | |||||
break; | |||||
unit *= 10; | |||||
unit += *ptr - '0'; | |||||
} | |||||
return (unit); | |||||
} | |||||
int | |||||
disk_unit_cam(u_int bus, u_int target, u_int lun, off_t mediasize) | |||||
{ | |||||
char phys[16]; | |||||
(void)snprintf(phys, sizeof(phys), "b%ut%ul%u=", bus, target, lun); | |||||
return (disk_unit(phys)); | |||||
} | |||||
int | |||||
disk_unit_mfi(uint8_t enclindex, uint8_t slot) | |||||
{ | |||||
char phys[32]; | |||||
(void)snprintf(phys, sizeof(phys), "E%u:S%u=", enclindex, slot); | |||||
return (disk_unit(phys)); | |||||
} |