Changeset View
Changeset View
Standalone View
Standalone View
head/sys/compat/linsysfs/linsysfs.c
/*- | /*- | ||||
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD | * SPDX-License-Identifier: BSD-2-Clause-FreeBSD | ||||
* | * | ||||
* Copyright (c) 2006 IronPort Systems | * Copyright (c) 2006 IronPort Systems | ||||
* Copyright (c) 2017 Carlos Neira cneirabustos@gmail.com | |||||
dchagin: Ar you really need this line? As I rewrote most of the patch? ) | |||||
cneirabustos_gmail.comAuthorUnsubmitted Done Inline ActionsThank you very much @dchagin, the patch looks nicer now!. Thanks for your help on this one. cneirabustos_gmail.com: Thank you very much @dchagin, the patch looks nicer now!. Thanks for your help on this one. | |||||
* All rights reserved. | * All rights reserved. | ||||
* | * | ||||
* Redistribution and use in source and binary forms, with or without | * Redistribution and use in source and binary forms, with or without | ||||
* modification, are permitted provided that the following conditions | * modification, are permitted provided that the following conditions | ||||
* are met: | * are met: | ||||
* 1. Redistributions of source code must retain the above copyright | * 1. Redistributions of source code must retain the above copyright | ||||
* notice, this list of conditions and the following disclaimer. | * notice, this list of conditions and the following disclaimer. | ||||
* 2. Redistributions in binary form must reproduce the above copyright | * 2. Redistributions in binary form must reproduce the above copyright | ||||
Show All 13 Lines | |||||
* 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/systm.h> | #include <sys/systm.h> | ||||
#include <sys/ctype.h> | |||||
#include <sys/kernel.h> | #include <sys/kernel.h> | ||||
#include <sys/malloc.h> | #include <sys/malloc.h> | ||||
#include <sys/mount.h> | #include <sys/mount.h> | ||||
#include <sys/sbuf.h> | #include <sys/sbuf.h> | ||||
#include <sys/smp.h> | #include <sys/smp.h> | ||||
#include <sys/socket.h> | #include <sys/socket.h> | ||||
#include <sys/bus.h> | #include <sys/bus.h> | ||||
#include <sys/pciio.h> | #include <sys/pciio.h> | ||||
#include <dev/pci/pcivar.h> | #include <dev/pci/pcivar.h> | ||||
#include <dev/pci/pcireg.h> | #include <dev/pci/pcireg.h> | ||||
#include <net/if.h> | #include <net/if.h> | ||||
#include <net/if_var.h> | |||||
#include <net/if_dl.h> | |||||
#include <compat/linux/linux.h> | |||||
#include <compat/linux/linux_common.h> | |||||
#include <compat/linux/linux_util.h> | #include <compat/linux/linux_util.h> | ||||
#include <fs/pseudofs/pseudofs.h> | #include <fs/pseudofs/pseudofs.h> | ||||
struct scsi_host_queue { | struct scsi_host_queue { | ||||
TAILQ_ENTRY(scsi_host_queue) scsi_host_next; | TAILQ_ENTRY(scsi_host_queue) scsi_host_next; | ||||
char *path; | char *path; | ||||
char *name; | char *name; | ||||
}; | }; | ||||
TAILQ_HEAD(,scsi_host_queue) scsi_host_q; | TAILQ_HEAD(,scsi_host_queue) scsi_host_q; | ||||
static int host_number = 0; | static int host_number = 0; | ||||
static int | static int | ||||
atoi(const char *str) | atoi(const char *str) | ||||
{ | { | ||||
return (int)strtol(str, (char **)NULL, 10); | return (int)strtol(str, (char **)NULL, 10); | ||||
} | } | ||||
static int | |||||
linsysfs_ifnet_addr(PFS_FILL_ARGS) | |||||
{ | |||||
struct l_sockaddr lsa; | |||||
struct ifnet *ifp; | |||||
ifp = ifname_linux_to_bsd(td, pn->pn_parent->pn_name, NULL); | |||||
if (ifp == NULL) | |||||
return (ENOENT); | |||||
if (linux_ifhwaddr(ifp, &lsa) != 0) | |||||
return (ENOENT); | |||||
sbuf_printf(sb, "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx\n", | |||||
lsa.sa_data[0], lsa.sa_data[1], lsa.sa_data[2], | |||||
lsa.sa_data[3], lsa.sa_data[4], lsa.sa_data[5]); | |||||
return (0); | |||||
} | |||||
static int | |||||
linsysfs_ifnet_addrlen(PFS_FILL_ARGS) | |||||
{ | |||||
sbuf_printf(sb, "%d\n", LINUX_IFHWADDRLEN); | |||||
return (0); | |||||
} | |||||
static int | |||||
linsysfs_ifnet_flags(PFS_FILL_ARGS) | |||||
{ | |||||
struct ifnet *ifp; | |||||
unsigned short flags; | |||||
ifp = ifname_linux_to_bsd(td, pn->pn_parent->pn_name, NULL); | |||||
if (ifp == NULL) | |||||
return (ENOENT); | |||||
linux_ifflags(ifp, &flags); | |||||
sbuf_printf(sb, "0x%x\n", flags); | |||||
return (0); | |||||
} | |||||
static int | |||||
linsysfs_ifnet_ifindex(PFS_FILL_ARGS) | |||||
{ | |||||
struct ifnet *ifp; | |||||
ifp = ifname_linux_to_bsd(td, pn->pn_parent->pn_name, NULL); | |||||
if (ifp == NULL) | |||||
return (ENOENT); | |||||
sbuf_printf(sb, "%u\n", ifp->if_index); | |||||
return (0); | |||||
} | |||||
static int | |||||
linsysfs_ifnet_mtu(PFS_FILL_ARGS) | |||||
{ | |||||
struct ifnet *ifp; | |||||
ifp = ifname_linux_to_bsd(td, pn->pn_parent->pn_name, NULL); | |||||
if (ifp == NULL) | |||||
return (ENOENT); | |||||
sbuf_printf(sb, "%u\n", ifp->if_mtu); | |||||
return (0); | |||||
} | |||||
static int | |||||
linsysfs_ifnet_tx_queue_len(PFS_FILL_ARGS) | |||||
{ | |||||
/* XXX */ | |||||
sbuf_printf(sb, "1000\n"); | |||||
return (0); | |||||
} | |||||
static int | |||||
linsysfs_ifnet_type(PFS_FILL_ARGS) | |||||
{ | |||||
struct l_sockaddr lsa; | |||||
struct ifnet *ifp; | |||||
ifp = ifname_linux_to_bsd(td, pn->pn_parent->pn_name, NULL); | |||||
if (ifp == NULL) | |||||
return (ENOENT); | |||||
if (linux_ifhwaddr(ifp, &lsa) != 0) | |||||
return (ENOENT); | |||||
sbuf_printf(sb, "%d\n", lsa.sa_family); | |||||
return (0); | |||||
} | |||||
static void | |||||
linsysfs_listnics(struct pfs_node *dir) | |||||
{ | |||||
struct pfs_node *nic; | |||||
struct pfs_node *lo; | |||||
nic = pfs_create_dir(dir, "eth0", NULL, NULL, NULL, 0); | |||||
pfs_create_file(nic, "address", &linsysfs_ifnet_addr, | |||||
NULL, NULL, NULL, PFS_RD); | |||||
pfs_create_file(nic, "addr_len", &linsysfs_ifnet_addrlen, | |||||
NULL, NULL, NULL, PFS_RD); | |||||
pfs_create_file(nic, "flags", &linsysfs_ifnet_flags, | |||||
NULL, NULL, NULL, PFS_RD); | |||||
pfs_create_file(nic, "ifindex", &linsysfs_ifnet_ifindex, | |||||
NULL, NULL, NULL, PFS_RD); | |||||
pfs_create_file(nic, "mtu", &linsysfs_ifnet_mtu, | |||||
NULL, NULL, NULL, PFS_RD); | |||||
pfs_create_file(nic, "tx_queue_len", &linsysfs_ifnet_tx_queue_len, | |||||
NULL, NULL, NULL, PFS_RD); | |||||
pfs_create_file(nic, "type", &linsysfs_ifnet_type, | |||||
NULL, NULL, NULL, PFS_RD); | |||||
lo = pfs_create_dir(dir, "lo", NULL, NULL, NULL, 0); | |||||
pfs_create_file(lo, "address", &linsysfs_ifnet_addr, | |||||
NULL, NULL, NULL, PFS_RD); | |||||
pfs_create_file(lo, "addr_len", &linsysfs_ifnet_addrlen, | |||||
NULL, NULL, NULL, PFS_RD); | |||||
pfs_create_file(lo, "flags", &linsysfs_ifnet_flags, | |||||
NULL, NULL, NULL, PFS_RD); | |||||
pfs_create_file(lo, "ifindex", &linsysfs_ifnet_ifindex, | |||||
NULL, NULL, NULL, PFS_RD); | |||||
pfs_create_file(lo, "mtu", &linsysfs_ifnet_mtu, | |||||
NULL, NULL, NULL, PFS_RD); | |||||
pfs_create_file(lo, "tx_queue_len", &linsysfs_ifnet_tx_queue_len, | |||||
NULL, NULL, NULL, PFS_RD); | |||||
pfs_create_file(lo, "type", &linsysfs_ifnet_type, | |||||
NULL, NULL, NULL, PFS_RD); | |||||
} | |||||
/* | /* | ||||
* Filler function for proc_name | * Filler function for proc_name | ||||
*/ | */ | ||||
static int | static int | ||||
linsysfs_scsiname(PFS_FILL_ARGS) | linsysfs_scsiname(PFS_FILL_ARGS) | ||||
{ | { | ||||
struct scsi_host_queue *scsi_host; | struct scsi_host_queue *scsi_host; | ||||
int index; | int index; | ||||
▲ Show 20 Lines • Show All 395 Lines • ▼ Show 20 Lines | |||||
linsysfs_init(PFS_INIT_ARGS) | linsysfs_init(PFS_INIT_ARGS) | ||||
{ | { | ||||
struct pfs_node *root; | struct pfs_node *root; | ||||
struct pfs_node *class; | struct pfs_node *class; | ||||
struct pfs_node *dir, *sys, *cpu; | struct pfs_node *dir, *sys, *cpu; | ||||
struct pfs_node *drm; | struct pfs_node *drm; | ||||
struct pfs_node *pci; | struct pfs_node *pci; | ||||
struct pfs_node *scsi; | struct pfs_node *scsi; | ||||
struct pfs_node *net; | |||||
struct pfs_node *devdir, *chardev; | struct pfs_node *devdir, *chardev; | ||||
devclass_t devclass; | devclass_t devclass; | ||||
device_t dev; | device_t dev; | ||||
TAILQ_INIT(&scsi_host_q); | TAILQ_INIT(&scsi_host_q); | ||||
root = pi->pi_root; | root = pi->pi_root; | ||||
/* /sys/class/... */ | /* /sys/class/... */ | ||||
class = pfs_create_dir(root, "class", NULL, NULL, NULL, 0); | class = pfs_create_dir(root, "class", NULL, NULL, NULL, 0); | ||||
scsi = pfs_create_dir(class, "scsi_host", NULL, NULL, NULL, 0); | scsi = pfs_create_dir(class, "scsi_host", NULL, NULL, NULL, 0); | ||||
drm = pfs_create_dir(class, "drm", NULL, NULL, NULL, 0); | drm = pfs_create_dir(class, "drm", NULL, NULL, NULL, 0); | ||||
/* /sys/class/net/.. */ | |||||
net = pfs_create_dir(class, "net", NULL, NULL, NULL, 0); | |||||
/* /sys/dev/... */ | /* /sys/dev/... */ | ||||
devdir = pfs_create_dir(root, "dev", NULL, NULL, NULL, 0); | devdir = pfs_create_dir(root, "dev", NULL, NULL, NULL, 0); | ||||
chardev = pfs_create_dir(devdir, "char", NULL, NULL, NULL, 0); | chardev = pfs_create_dir(devdir, "char", NULL, NULL, NULL, 0); | ||||
/* /sys/devices/... */ | /* /sys/devices/... */ | ||||
dir = pfs_create_dir(root, "devices", NULL, NULL, NULL, 0); | dir = pfs_create_dir(root, "devices", NULL, NULL, NULL, 0); | ||||
pci = pfs_create_dir(dir, "pci0000:00", NULL, NULL, NULL, 0); | pci = pfs_create_dir(dir, "pci0000:00", NULL, NULL, NULL, 0); | ||||
Show All 14 Lines | linsysfs_init(PFS_INIT_ARGS) | ||||
pfs_create_file(cpu, "online", &linsysfs_cpuonline, | pfs_create_file(cpu, "online", &linsysfs_cpuonline, | ||||
NULL, NULL, NULL, PFS_RD); | NULL, NULL, NULL, PFS_RD); | ||||
pfs_create_file(cpu, "possible", &linsysfs_cpuonline, | pfs_create_file(cpu, "possible", &linsysfs_cpuonline, | ||||
NULL, NULL, NULL, PFS_RD); | NULL, NULL, NULL, PFS_RD); | ||||
pfs_create_file(cpu, "present", &linsysfs_cpuonline, | pfs_create_file(cpu, "present", &linsysfs_cpuonline, | ||||
NULL, NULL, NULL, PFS_RD); | NULL, NULL, NULL, PFS_RD); | ||||
linsysfs_listcpus(cpu); | linsysfs_listcpus(cpu); | ||||
linsysfs_listnics(net); | |||||
return (0); | return (0); | ||||
} | } | ||||
/* | /* | ||||
* Destructor | * Destructor | ||||
*/ | */ | ||||
static int | static int | ||||
Show All 20 Lines |
Ar you really need this line? As I rewrote most of the patch? )