X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=blobdiff_plain;f=gears%2Fservices%2Fdevfile%2Fdevfile_guest_fd_tracker.h;fp=gears%2Fservices%2Fdevfile%2Fdevfile_guest_fd_tracker.h;h=27ef088a7c8e68eeb2ab1a19f1c4ee37d5d763e8;hb=de0aa03dbd9812a48cab6d899ab41b7f2cc593b5;hp=0000000000000000000000000000000000000000;hpb=f460aeead9da6649a7a75e0f7df3149e62b48f15;p=palacios.git diff --git a/gears/services/devfile/devfile_guest_fd_tracker.h b/gears/services/devfile/devfile_guest_fd_tracker.h new file mode 100644 index 0000000..27ef088 --- /dev/null +++ b/gears/services/devfile/devfile_guest_fd_tracker.h @@ -0,0 +1,129 @@ +/* + Device File Virtualization Guest Preload Library Helpers + + (c) Akhil Guliani and William Gross, 2015 + + Adapted from MPI module (c) 2012 Peter Dinda + +*/ + +#define MAX_DEV_NAME_LENGTH 80 +#define MAX_DEVICES 100 + +//PYTHONSCRIPTBREAK1 +#define DEV_COUNT 9 +//PYTHONSCRIPTBREAK2 + +#include +#include +#include +#include + + + +#define MIN(a,b) \ + ({ __typeof__ (a) _a = (a); \ + __typeof__ (b) _b = (b); \ + _a < _b ? _a : _b; }) + + +char *strcpy(char *dest, const char *src) +{ + unsigned i; + for (i=0; src[i] != '\0'; ++i) + dest[i] = src[i]; + dest[i] = '\0'; + return dest; +} + +size_t strlen(const char * str) +{ + const char *s; + for (s = str; *s; ++s) {} + return(s - str); +} + + +//taken from: https://stuff.mit.edu/afs/sipb/project/tcl80/src/tcl8.0/compat/strstr.c +char* strstr(const char* string,char* substring) + // register char *string; /* String to search. */ + // char *substring; /* Substring to try to find in string. */ +{ + register char *a, *b; + + /* First scan quickly through the two strings looking for a + * * single-character match. When it's found, then compare the + * * rest of the substring. + * */ + + b = substring; + if (*b == 0) { + return (char*)string; + } + for ( ; *string != 0; string += 1) { + if (*string != *b) { + continue; + } + a = (char*)string; + while (1) { + if (*b == 0) { + return (char*)string; + } + if (*a++ != *b++) { + break; + } + } + b = substring; + } + return (char *) 0; +} + + +//Used to keep track of the active file descriptor for the supported devices +//Initially the fd is -1 to indicate that the device has not yet been opened +typedef struct dev_file_fd_tracker { + char devName[MAX_DEV_NAME_LENGTH]; + int devFD; +} dev_tracker; + + +dev_tracker dtrack[] = { +//PYTHONSCRIPTBREAK3 +{"/dev/urandom",-1}, +{"/dev/input/mouse0",-1}, +{"/dev/input/event0",-1}, +{"/dev/input/event1",-1}, +{"/dev/ttyS0",-1}, +{"/dev/ttyS1",-1}, +{"/dev/ttyS2",-1}, +{"/dev/ttyS3",-1}, +{"/dev/newDevice",-1} +//PYTHONSCRIPTBREAK4 + +}; + +//returns -1, means no match is found +//other than -1, is the index in the dtracker array of the match +int check_name(const char* path, dev_tracker tracker[]){ + int i; + for(i=0; i