[PATCH 3/5] Remove unused isys files.
David Shea
dshea at redhat.com
Fri Jan 31 15:23:24 UTC 2014
cppcheck found a bunch of functions in isys that weren't used anywhere.
None of these functions have wrappers exposed through python, and in
each case removing the unused functions emptied the C file, so let's
dump the files.
---
pyanaconda/isys/Makefile.am | 3 +-
pyanaconda/isys/eddsupport.c | 340 -------------------------------------------
pyanaconda/isys/eddsupport.h | 28 ----
pyanaconda/isys/ethtool.c | 121 ---------------
pyanaconda/isys/ethtool.h | 41 ------
pyanaconda/isys/isys.c | 3 -
pyanaconda/isys/lang.c | 60 --------
pyanaconda/isys/lang.h | 25 ----
pyanaconda/isys/linkdetect.c | 204 --------------------------
9 files changed, 1 insertion(+), 824 deletions(-)
delete mode 100644 pyanaconda/isys/eddsupport.c
delete mode 100644 pyanaconda/isys/eddsupport.h
delete mode 100644 pyanaconda/isys/ethtool.c
delete mode 100644 pyanaconda/isys/ethtool.h
delete mode 100644 pyanaconda/isys/lang.c
delete mode 100644 pyanaconda/isys/lang.h
delete mode 100644 pyanaconda/isys/linkdetect.c
diff --git a/pyanaconda/isys/Makefile.am b/pyanaconda/isys/Makefile.am
index 99b2223..f04429d 100644
--- a/pyanaconda/isys/Makefile.am
+++ b/pyanaconda/isys/Makefile.am
@@ -19,8 +19,7 @@
pkgpyexecdir = $(pyexecdir)/py$(PACKAGE_NAME)
-ISYS_SRCS = devices.c lang.c \
- isofs.c linkdetect.c ethtool.c eddsupport.c
+ISYS_SRCS = devices.c isofs.c
dist_noinst_HEADERS = $(srcdir)/*.h
diff --git a/pyanaconda/isys/eddsupport.c b/pyanaconda/isys/eddsupport.c
deleted file mode 100644
index 0e0a4b5..0000000
--- a/pyanaconda/isys/eddsupport.c
+++ /dev/null
@@ -1,340 +0,0 @@
-/*
- * eddsupport.c - handling of mapping disk drives in Linux to disk drives
- * according to the BIOS using the edd kernel module
- *
- * Copyright (C) 2004 Dell, Inc. All rights reserved.
- * Copyright (C) 2004 Red Hat, Inc. All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- * Author(s): Rezwanul_Kabir at Dell.com
- * Jeremy Katz <katzj at redhat.com>
- */
-
-#include "config.h"
-
-#include <ctype.h>
-#include <dirent.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <stdint.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <sys/reboot.h>
-#include <sys/types.h>
-#include <linux/types.h>
-
-
-#include "eddsupport.h"
-#include "devices.h"
-#include "isys.h"
-
-#define EDD_DIR "/sys/firmware/edd"
-#define SIG_FILE "mbr_signature"
-#define MBRSIG_OFFSET 0x1b8
-
-#define HASH_TABLE_SIZE 17
-
-
-struct diskMapEntry{
- uint32_t key;
- char *diskname;
- struct diskMapEntry *next;
-};
-
-struct diskMapTable {
- struct diskMapEntry **table;
- int tableSize;
-};
-
-static struct diskMapTable *mbrSigToName = NULL;
-static int diskHashInit = 0;
-
-
-
-static struct diskMapTable* initializeHashTable(int);
-static int insertHashItem(struct diskMapTable *, struct diskMapEntry *);
-static struct diskMapEntry* lookupHashItem(struct diskMapTable *, uint32_t);
-static int addToHashTable(struct diskMapTable *, uint32_t , char *);
-static struct device ** createDiskList();
-static int mapBiosDisks(struct device ** , const char *);
-static int readDiskSig(char *, uint32_t *);
-static int readMbrSig(char *, uint32_t *);
-
-/* This is the top level function that creates a disk list present in the
- * system, checks to see if unique signatures exist on the disks at offset
- * 0x1b8. If a unique signature exists then it will map BIOS disks to their
- * corresponding hd/sd device names. Otherwise, we'll avoid mapping drives.
- */
-
-int probeBiosDisks() {
- struct device ** devices = NULL;
-
- devices = createDiskList();
- if(!devices){
-#ifdef STANDALONE
- fprintf(stderr, "No disks!\n");
-#endif
- return -1;
- }
-
- if(!mapBiosDisks(devices, EDD_DIR)){
-#ifdef STANDALONE
- fprintf(stderr, "WARNING: couldn't map BIOS disks\n");
-#endif
- return -1;
- }
- return 0;
-}
-
-
-static struct device ** createDiskList(){
- return getDevices (DEVICE_DISK);
-}
-
-static int readDiskSig(char *device, uint32_t *disksig) {
- int fd, rc;
- char devnodeName[64];
-
- snprintf(devnodeName, sizeof(devnodeName), "/dev/%s", device);
- fd = open(devnodeName, O_RDONLY);
- if (fd < 0) {
-#ifdef STANDALONE
- fprintf(stderr, "Error opening device %s: %s\n ", device,
- strerror(errno));
-#endif
- return -errno;
- }
-
- rc = lseek(fd, MBRSIG_OFFSET, SEEK_SET);
- if (rc < 0){
- close(fd);
-
-#ifdef STANDALONE
- fprintf(stderr, "Error seeking to MBRSIG_OFFSET in %s: %s\n",
- device, strerror(errno));
-#endif
- return -1;
- }
-
- rc = read(fd, disksig, sizeof(uint32_t));
- if (rc < sizeof(uint32_t)) {
- close(fd);
-
-#ifdef STANDALONE
- fprintf(stderr, "Failed to read signature from %s\n", device);
-#endif
- return -1;
- }
-
- close(fd);
- return 0;
-}
-
-static int mapBiosDisks(struct device** devices,const char *path) {
- DIR *dirHandle;
- struct dirent *entry;
- char * sigFileName;
- uint32_t mbrSig, biosNum, currentSig;
- struct device **currentDev, **foundDisk;
- int i, rc, dm_nr, highest_dm;
-
- dirHandle = opendir(path);
- if(!dirHandle){
-#ifdef STANDALONE
- fprintf(stderr, "Failed to open directory %s: %s\n", path,
- strerror(errno));
-#endif
- return 0;
- }
-
- mbrSigToName = initializeHashTable(HASH_TABLE_SIZE);
- if(!mbrSigToName){
-#ifdef STANDALONE
- fprintf(stderr, "Error initializing mbrSigToName table\n");
-#endif
- closedir(dirHandle);
- return 0;
- }
-
- while ((entry = readdir(dirHandle)) != NULL) {
- if(!strncmp(entry->d_name,".",1) || !strncmp(entry->d_name,"..",2)) {
- continue;
- }
- sscanf((entry->d_name+9), "%x", &biosNum);
-
- sigFileName = malloc(strlen(path) + strlen(entry->d_name) + 20);
- sprintf(sigFileName, "%s/%s/%s", path, entry->d_name, SIG_FILE);
- if (readMbrSig(sigFileName, &mbrSig) == 0) {
- for (currentDev = devices, i = 0, foundDisk=NULL, highest_dm=-1;
- (*currentDev) != NULL;
- currentDev++) {
- if (!(*currentDev)->device)
- continue;
-
- if ((rc=readDiskSig((*currentDev)->device, ¤tSig)) < 0) {
- if (rc == -ENOMEDIUM || rc == -ENXIO)
- continue;
- closedir(dirHandle);
- return 0;
- }
-
- if (mbrSig == currentSig) {
- /* When we have a fakeraid setup we will find multiple hits
- a number for the raw disks (1 when striping, 2 when
- mirroring, more with raid on raid like raid 01 or 10)
- and a number for the dm devices (normally only one dm
- device will match, but more with raid on raid).
- Since with raid on raid the last dm device created
- will be the top layer raid, we want the highest matching
- dm device. */
- if (!strncmp((*currentDev)->device, "dm-", 3) &&
- sscanf((*currentDev)->device+3, "%d", &dm_nr) == 1) {
- if (dm_nr > highest_dm) {
- highest_dm = dm_nr;
- foundDisk=currentDev;
- i = 1;
- }
- } else if (!foundDisk ||
- strncmp((*foundDisk)->device, "dm-", 3)) {
- foundDisk=currentDev;
- i++;
- }
- }
- }
-
- if (i==1) {
- if(!addToHashTable(mbrSigToName, (uint32_t)biosNum,
- (*foundDisk)->device)) {
- closedir(dirHandle);
- return 0;
- }
- }
- }
- }
- closedir(dirHandle);
- return 1;
-}
-
-
-static int readMbrSig(char *filename, uint32_t *int_sig){
- FILE* fh;
-
- fh = fopen(filename,"r");
- if(fh == NULL) {
-#ifdef STANDALONE
- fprintf(stderr, "Error opening mbr_signature file %s: %s\n", filename,
- strerror(errno));
-#endif
- return -1;
- }
- fseek(fh, 0, SEEK_SET);
- if (fscanf(fh, "%x", int_sig) != 1) {
-#ifdef STANDALONE
- fprintf(stderr, "Error reading %s\n", filename);
-#endif
- fclose(fh);
- return -1;
- }
-
- fclose(fh);
- return 0;
-}
-
-
-static struct diskMapTable* initializeHashTable(int size) {
- struct diskMapTable *hashTable;
-
- hashTable = malloc(sizeof(struct diskMapTable));
- hashTable->tableSize = size;
- hashTable->table = malloc(sizeof(struct diskMapEntry *) * size);
- memset(hashTable->table,0,(sizeof(struct diskMapEntry *) * size));
- return hashTable;
-}
-
-
-static int insertHashItem(struct diskMapTable *hashTable,
- struct diskMapEntry *hashItem) {
- int index;
-
- index = (hashItem->key) % (hashTable->tableSize);
-
- if(hashTable->table[index] == NULL){
- hashTable->table[index] = hashItem;
- return index;
- } else {
- hashItem->next = hashTable->table[index];
- hashTable->table[index] = hashItem;
- return index;
- }
-}
-
-
-static struct diskMapEntry * lookupHashItem(struct diskMapTable *hashTable,
- uint32_t itemKey) {
- int index;
- struct diskMapEntry *hashItem;
-
- index = itemKey % (hashTable->tableSize);
- for (hashItem = hashTable->table[index];
- (hashItem != NULL) && (hashItem->key != itemKey);
- hashItem = hashItem->next) {
- ;
- }
- return hashItem;
-}
-
-
-static int addToHashTable(struct diskMapTable *hashTable,
- uint32_t itemKey, char *diskName) {
- int index;
- struct diskMapEntry *diskSigToNameEntry;
-
- diskSigToNameEntry = malloc(sizeof(struct diskMapEntry));
- diskSigToNameEntry->next = NULL;
- diskSigToNameEntry->key = itemKey;
- diskSigToNameEntry->diskname = diskName;
-
- if ((index = insertHashItem(hashTable, diskSigToNameEntry)) < 0){
-#ifdef STANDALONE
- fprintf(stderr, "Unable to insert item\n");
-#endif
- return 0;
- } else {
- return 1;
- }
-}
-
-
-char * getBiosDisk(char *biosStr) {
- uint32_t biosNum;
- struct diskMapEntry * disk;
-
- if (diskHashInit == 0) {
- probeBiosDisks();
- diskHashInit = 1;
- }
-
- if (mbrSigToName == NULL)
- return NULL;
-
- sscanf(biosStr,"%x",&biosNum);
- disk = lookupHashItem(mbrSigToName, biosNum);
- if (disk) return disk->diskname;
-
- return NULL;
-}
diff --git a/pyanaconda/isys/eddsupport.h b/pyanaconda/isys/eddsupport.h
deleted file mode 100644
index 77fc4c4..0000000
--- a/pyanaconda/isys/eddsupport.h
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * eddsupport.h
- *
- * Copyright (C) 2007 Red Hat, Inc. All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef EDDSUPPORT_H
-#define EDDSUPPORT_H
-
-int probeBiosDisks();
-char* getBiosDisk(char *);
-
-#endif
-
-
diff --git a/pyanaconda/isys/ethtool.c b/pyanaconda/isys/ethtool.c
deleted file mode 100644
index fa4838f..0000000
--- a/pyanaconda/isys/ethtool.c
+++ /dev/null
@@ -1,121 +0,0 @@
-/*
- * ethtool.c - setting of basic ethtool options
- *
- * Copyright (C) 2003 Red Hat, Inc. All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- * Author(s): Jeremy Katz <katzj at redhat.com>
- */
-
-#include "config.h"
-
-#include <errno.h>
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <unistd.h>
-
-#include <sys/ioctl.h>
-#include <sys/socket.h>
-#include <sys/types.h>
-#include <net/if.h>
-
-#include <linux/sockios.h>
-#include "ethtool.h"
-
-static int set_intf_up(struct ifreq ifr, int sock) {
- if (ioctl(sock, SIOCGIFFLAGS, &ifr) < 0) {
- return (-1);
- }
- ifr.ifr_flags |= (IFF_UP | IFF_RUNNING);
- if (ioctl(sock, SIOCSIFFLAGS, &ifr) < 0) {
- fprintf(stderr, "failed to bring up interface %s: %s", ifr.ifr_name,
- strerror(errno));
- return -1;
- }
- return (0);
-}
-
-int setEthtoolSettings(char * dev, ethtool_speed speed,
- ethtool_duplex duplex) {
- int sock, err;
- struct ethtool_cmd ecmd;
- struct ifreq ifr;
-
- if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
- perror("Unable to create socket");
- return -1;
- }
-
- /* Setup our control structures. */
- memset(&ifr, 0, sizeof(ifr));
- strcpy(ifr.ifr_name, dev);
-
- if (set_intf_up(ifr, sock) == -1) {
- fprintf(stderr, "unable to bring up interface %s: %s", dev,
- strerror(errno));
- return -1;
- }
-
- ecmd.cmd = ETHTOOL_GSET;
- ifr.ifr_data = (caddr_t)&ecmd;
- err = ioctl(sock, SIOCETHTOOL, &ifr);
- if (err < 0) {
- perror("Unable to get settings via ethtool. Not setting");
- return -1;
- }
-
- if (speed != ETHTOOL_SPEED_UNSPEC)
- ecmd.speed = speed;
- if (duplex != ETHTOOL_DUPLEX_UNSPEC)
- ecmd.duplex = duplex;
- if ((duplex != ETHTOOL_DUPLEX_UNSPEC) || (speed != ETHTOOL_SPEED_UNSPEC))
- ecmd.autoneg = AUTONEG_DISABLE;
-
- ecmd.cmd = ETHTOOL_SSET;
- ifr.ifr_data = (caddr_t)&ecmd;
- err = ioctl(sock, SIOCETHTOOL, &ifr);
- if (err < 0) {
- // perror("Unable to set settings via ethtool. Not setting");
- return -1;
- }
-
- return 0;
-}
-
-int identifyNIC(char *iface, int seconds) {
- int sock;
- struct ethtool_value edata;
- struct ifreq ifr;
-
- if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
- perror("Unable to create socket");
- return -1;
- }
-
- memset(&ifr, 0, sizeof(ifr));
- memset(&edata, 0, sizeof(edata));
-
- strcpy(ifr.ifr_name, iface);
- edata.cmd = ETHTOOL_PHYS_ID;
- edata.data = seconds;
- ifr.ifr_data = (caddr_t) &edata;
-
- if (ioctl(sock, SIOCETHTOOL, &ifr) < 0) {
- perror("Unable to identify NIC");
- }
-
- return 0;
-}
diff --git a/pyanaconda/isys/ethtool.h b/pyanaconda/isys/ethtool.h
deleted file mode 100644
index 57b4ffc..0000000
--- a/pyanaconda/isys/ethtool.h
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * net.h
- *
- * Copyright (C) 2007 Red Hat, Inc. All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef ISYSNET_H
-#define ISYSNET_H
-
-#include <linux/types.h>
-#include <linux/ethtool.h>
-
-/* returns 1 for link, 0 for no link, -1 for unknown */
-int get_link_status(char *ifname);
-
-typedef enum ethtool_speed_t { ETHTOOL_SPEED_UNSPEC = -1,
- ETHTOOL_SPEED_10 = SPEED_10,
- ETHTOOL_SPEED_100 = SPEED_100,
- ETHTOOL_SPEED_1000 = SPEED_1000 } ethtool_speed;
-typedef enum ethtool_duplex_t { ETHTOOL_DUPLEX_UNSPEC = -1,
- ETHTOOL_DUPLEX_HALF = DUPLEX_HALF,
- ETHTOOL_DUPLEX_FULL = DUPLEX_FULL } ethtool_duplex;
-
-/* set ethtool settings */
-int setEthtoolSettings(char * dev, ethtool_speed speed, ethtool_duplex duplex);
-int identifyNIC(char *iface, int seconds);
-
-#endif
diff --git a/pyanaconda/isys/isys.c b/pyanaconda/isys/isys.c
index e22a754..569cd35 100644
--- a/pyanaconda/isys/isys.c
+++ b/pyanaconda/isys/isys.c
@@ -68,9 +68,6 @@
#endif
#include "isys.h"
-#include "ethtool.h"
-#include "lang.h"
-#include "eddsupport.h"
#ifndef CDROMEJECT
#define CDROMEJECT 0x5309
diff --git a/pyanaconda/isys/lang.c b/pyanaconda/isys/lang.c
deleted file mode 100644
index 9487ddc..0000000
--- a/pyanaconda/isys/lang.c
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * lang.c
- *
- * Copyright (C) 2007 Red Hat, Inc. All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "config.h"
-
-#include <alloca.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/ioctl.h>
-#include <sys/stat.h>
-#include <unistd.h>
-
-#include <linux/keyboard.h>
-#ifdef NR_KEYS
-#undef NR_KEYS
-#define NR_KEYS 128
-#endif
-
-#include <zlib.h>
-
-#include "linux/kd.h"
-
-#include "isys.h"
-#include "lang.h"
-
-int isysSetUnicodeKeymap(void) {
- int console;
-
-#if defined (__s390__) || defined (__s390x__)
- return 0;
-#endif
- console = open("/dev/console", O_RDWR);
- if (console < 0)
- return -EACCES;
-
- /* place keyboard in unicode mode */
- ioctl(console, KDSKBMODE, K_UNICODE);
- close(console);
- return 0;
-}
-
diff --git a/pyanaconda/isys/lang.h b/pyanaconda/isys/lang.h
deleted file mode 100644
index aac821a..0000000
--- a/pyanaconda/isys/lang.h
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * lang.h
- *
- * Copyright (C) 2007 Red Hat, Inc. All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef ISYS_LANG_H
-#define ISYS_LANG_H
-
-int isysSetUnicodeKeymap(void);
-
-#endif
diff --git a/pyanaconda/isys/linkdetect.c b/pyanaconda/isys/linkdetect.c
deleted file mode 100644
index f8f9b50..0000000
--- a/pyanaconda/isys/linkdetect.c
+++ /dev/null
@@ -1,204 +0,0 @@
-/*
- * linkdetect.c - simple link detection
- *
- * pulls code from mii-tool.c in net-toools and ethtool so
- * that we can do everything that jgarzik says we should check
- *
- * Copyright (C) 2002, 2003 Red Hat, Inc. All rights reserved.
- * Portions Copyright (C) 2000 David A. Hinds -- dhinds at pcmcia.sourceforge.org
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- * Author(s): Jeremy Katz <katzj at redhat.com>
- */
-
-#include "config.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdint.h>
-#include <sys/ioctl.h>
-#include <string.h>
-#include <unistd.h>
-#include <errno.h>
-
-#include <sys/socket.h>
-#include <sys/types.h>
-#include <net/if.h>
-
-#include <linux/sockios.h>
-#include <linux/mii.h>
-#include <linux/ethtool.h>
-#include "ethtool.h"
-
-static struct ifreq ifr;
-
-static int mdio_read(int skfd, uint16_t location)
-{
- struct mii_ioctl_data mii;
-
- memset(&mii, 0, sizeof(mii));
- memcpy(&mii, &ifr.ifr_data, sizeof(mii));
- mii.reg_num = location;
- memcpy(&ifr.ifr_data, &mii, sizeof(mii));
-
- if (ioctl(skfd, SIOCGMIIREG, &ifr) < 0) {
-#ifdef STANDALONE
- fprintf(stderr, "SIOCGMIIREG on %s failed: %s\n", ifr.ifr_name,
- strerror(errno));
-#endif
- return -1;
- } else {
- memcpy(&mii, &ifr.ifr_data, sizeof(mii));
- }
-
- return mii.val_out;
-}
-
-/* we don't need writing right now */
-#if 0
-static void mdio_write(int skfd, int location, int value)
-{
- struct mii_ioctl_data *mii = (struct mii_ioctl_data *)&ifr.ifr_data;
- mii->reg_num = location;
- mii->val_in = value;
- if (ioctl(skfd, SIOCSMIIREG, &ifr) < 0) {
-#ifdef STANDALONE
- fprintf(stderr, "SIOCSMIIREG on %s failed: %s\n", ifr.ifr_name,
- strerror(errno));
-#endif
- }
-}
-#endif
-
-
-
-static int get_mii_link_status(int sock) {
- int i, mii_val[32];
-
- if (ioctl(sock, SIOCGMIIPHY, &ifr) < 0) {
- if (errno != ENODEV)
-#ifdef STANDALONE
- fprintf(stderr, "SIOCGMIIPHY on '%s' failed: %s\n",
- ifr.ifr_name, strerror(errno));
-#endif
- return -1;
- }
-
- /* Some bits in the BMSR are latched, but we can't rely on being
- the only reader, so only the current values are meaningful */
- mdio_read(sock, MII_BMSR);
- for (i = 0; i < 8; i++)
- mii_val[i] = mdio_read(sock, i);
-
- if (mii_val[MII_BMCR] == 0xffff) {
-#ifdef STANDALONE
- fprintf(stderr, " No MII transceiver present!.\n");
-#endif
- return -1;
- }
-
- if (mii_val[MII_BMSR] & BMSR_LSTATUS)
- return 1;
- else
- return 0;
-}
-
-static int get_ethtool_link_status(int sock) {
- struct ethtool_value edata;
- int rc;
-
- edata.cmd = ETHTOOL_GLINK;
- ifr.ifr_data = (caddr_t)&edata;
- rc = ioctl(sock, SIOCETHTOOL, &ifr);
- if (rc == 0) {
- return edata.data;
- } else if (errno != EOPNOTSUPP) {
-#ifdef STANDALONE
- fprintf(stderr, "Cannot get link status (%d): %s\n", errno, strerror(errno));
-#endif
- }
-
- return -1;
-}
-
-
-
-int get_link_status(char * devname) {
- int sock, rc;
-
- if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
-#ifdef STANDALONE
- fprintf(stderr, "Error creating socket: %s\n", strerror(errno));
-#endif
- return -1;
- }
-
- /* make sure interface is up and activated */
- memset(&ifr, 0, sizeof(ifr));
- strcpy(ifr.ifr_name, devname);
-
- if (ioctl(sock, SIOCGIFFLAGS, &ifr) < 0) {
- return -1;
- }
-
- ifr.ifr_flags |= (IFF_UP | IFF_RUNNING);
-
- if (ioctl(sock, SIOCSIFFLAGS, &ifr) < 0) {
- return -1;
- }
-
- /* Setup our control structures. */
- memset(&ifr, 0, sizeof(ifr));
- strcpy(ifr.ifr_name, devname);
-
- /* check for link with both ethtool and mii registers. ethtool is
- * supposed to be the One True Way (tm), but it seems to not work
- * with much yet :/ */
-
- rc = get_ethtool_link_status(sock);
-#ifdef STANDALONE
- printf("ethtool link status of %s is: %d\n", devname, rc);
-#endif
- if (rc == 1) {
- close(sock);
- return 1;
- }
-
- rc = get_mii_link_status(sock);
-#ifdef STANDALONE
- printf("MII link status of %s is: %d\n", devname, rc);
-#endif
- if (rc == 1) {
- close(sock);
- return 1;
- }
-
- return 0;
-}
-
-#ifdef STANDALONE
-/* hooray for stupid test programs! */
-int main(int argc, char **argv) {
- char * dev;
-
- if (argc >= 2)
- dev = argv[1];
- else
- dev = strdup("eth0");
-
- printf("link status of %s is %d\n", dev, get_link_status(dev));
- return 0;
-}
-#endif
--
1.8.5.3
More information about the anaconda-patches
mailing list