diff options
author | Joseph Hunkeler <jhunkeler@gmail.com> | 2010-12-04 20:58:54 -0500 |
---|---|---|
committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2010-12-04 20:58:54 -0500 |
commit | 2ccade436d8fe51eea6cb09e6324a921c243f332 (patch) | |
tree | ec94498cfdf91f17157744c9dd0dd6cd15ff4f04 /src | |
parent | d8394383b8ab15653ed02b82996081c8fe07cbd8 (diff) | |
download | NetNuke2-2ccade436d8fe51eea6cb09e6324a921c243f332.tar.gz |
Implementing sysfs SCSI scaning
Diffstat (limited to 'src')
-rw-r--r-- | src/bus.c | 52 | ||||
-rw-r--r-- | src/netnuke.c | 3 | ||||
-rw-r--r-- | src/netnuke.h | 1 |
3 files changed, 55 insertions, 1 deletions
@@ -26,11 +26,63 @@ #include <unistd.h> #include <linux/fs.h> #include <sys/ioctl.h> +#include <errno.h> +#include <dirent.h> #include "netnuke.h" extern char* scsi_device_glob[]; extern char* ide_device_glob[]; +int scanbus_sysfs(nndevice_t** device) +{ + char tmpstr[128]; + const char* scsi_path = "/sys/class/scsi_disk"; + DIR *pdir; + struct dirent *pdent; + DIR *pbdir; + struct dirent *pbent; + + /* scan for scsi devices via sysfs */ + if((access(scsi_path, F_OK)) != 0) + { + COM(self, "Sysfs not available\n"); + return 1; + } + + pdir = opendir(scsi_path); + if(!pdir) + { + COM(self, "fatal opendir: %s\n", strerror(errno)); + exit(1); + } + + while((pdent = readdir(pdir))) + { + if(!strncasecmp(pdent->d_name, ".", 1) || !strncasecmp(pdent->d_name, "..", 2)) + continue; + + sprintf(tmpstr, "%s/%s/device/block", scsi_path, pdent->d_name); + pbdir = opendir(tmpstr); + if(!pbdir) + { + COM(self, "fatal opendir: %s\n", strerror(errno)); + exit(1); + } + + while((pbent = readdir(pbdir))) + { + if(!strncasecmp(pbent->d_name, ".", 1) || !strncasecmp(pbent->d_name, "..", 2)) + continue; + + printf("%s - %s\n", pdent->d_name, pbent->d_name); + } + closedir(pbdir); + } + closedir(pdir); + + return 0; +} + int scanbus(nndevice_t** device, int mask) { int fd = -1; diff --git a/src/netnuke.c b/src/netnuke.c index 973f8b7..682d727 100644 --- a/src/netnuke.c +++ b/src/netnuke.c @@ -226,7 +226,8 @@ int main(int argc, char* argv[]) if(list_flag) { bus_mask = selectbus(bus_flags); - scanbus(device, bus_mask); + //scanbus(device, bus_mask); + scanbus_sysfs(device); exit(0); } diff --git a/src/netnuke.h b/src/netnuke.h index 96aac63..506dfdf 100644 --- a/src/netnuke.h +++ b/src/netnuke.h @@ -55,6 +55,7 @@ void nnrandfree(); unsigned int nngetseed(); unsigned int nnrand(int min, int max); char* randstr(int size); +int scanbus_sysfs(nndevice_t** device); int scanbus(nndevice_t** device,int mask); void showbus(int mask); int selectbus(char** flags); |