#include #include #include #include #include #include #include #include #include "entry.h" #define MOUNT_POINT "/tmp/mountpoint/" #define CONFIG_FILE "wemlinux.cfg" const char* fstypes[]={"ext2", "ext3", "ext4", "btrfs", "fat", "vfat", "ntfs"}; //#define STUB typedef struct { char device_name[16][16]; char device_type[16][16]; int n; } device_list_t; typedef struct { device_list_t installed; device_list_t not_installed; } config_device_t; int test_file(const char* base) { char tf[256]; FILE* f = NULL; sprintf(tf,"%s/%s", base, CONFIG_FILE); f=fopen(tf, "r"); if(f) fclose(f); return f!=NULL; } int testdevice(struct dirent *ent, config_device_t* cd) { char tmp[256], tmp2[256], mp[256]; int i; if(!strncmp("sd", ent->d_name, 2) && strncmp("sda", ent->d_name, 3) && strlen(ent->d_name)==4 && ent->d_name[3]>='0' && ent->d_name[3]<='9') { sprintf(tmp, "/dev/%s",ent->d_name); sprintf(mp, MOUNT_POINT "%s", ent->d_name); mkdir(mp, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); for(i=0; iinstalled.device_name[cd->installed.n], ent->d_name); strcpy(cd->installed.device_type[cd->installed.n], fstypes[i]); cd->installed.n++; }else { strcpy(cd->not_installed.device_name[cd->not_installed.n], ent->d_name); strcpy(cd->not_installed.device_type[cd->not_installed.n], fstypes[i]); cd->not_installed.n++; } } } } } int filter(config_device_t *cd) { DIR *dir; struct dirent *ent; mkdir(MOUNT_POINT, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); if ((dir = opendir ("/dev/")) != NULL) { /* print all the files and directories within directory */ while ((ent = readdir (dir)) != NULL) { if(testdevice(ent, cd)) { } } closedir (dir); } else { /* could not open directory */ perror (""); return EXIT_FAILURE; } } int main(int argc, char** argv) { int i; os_entries_t os; #ifndef STUB config_device_t cd; cd.installed.n=cd.not_installed.n=0; if(argc>1 && !strcmp(argv[1], "-l")) filter(&cd); printf("Installes (%d):\n", cd.installed.n); for(i=0; i=0 && choice