Linux环境下,HDD使用判定
1 static eRESULT GetHDDStatus() 2 { 3 FILE *fstream = NULL; 4 char command_str[50]; 5 char buff[256]; 6 char strtmp[256]; 7 char find_Status[50] = "Status: "; 8 char find_Mediatype[50] = "Media type: HDD"; 9 char find_key[50] = "Operational"; 10 int flg = 0; 11 int icnt = 0; 12 13 memset(buff, 0, sizeof(buff)); 14 memset(command_str, 0, sizeof(command_str)); 15 16 sprintf(command_str, "amCLI --list all"); 17 if(NULL == (fstream = popen(command_str, "r"))) { 18 fprintf(stderr,"Failed: %s", strerror(errno)); 19 msgwrt(PGNAME, MSG_ERROR, "%s", stderr); 20 return NG; 21 } 22 else { 23 while(NULL != fgets(buff, sizeof(buff), fstream)) { 24 /* "Status"行情报判定 */ 25 if (strstr(buff, find_Status)) { 26 memset(strtmp, 0, sizeof(strtmp)); 27 icnt = 0; 28 while(fgets(strtmp, sizeof(strtmp), fstream) != NULL) { 29 icnt++; 30 if (icnt > 5) { 31 break; 32 } 33 /* "Media type: HDD"情报判定 */ 34 if (strstr(strtmp, find_Mediatype)) { 35 /* '\n'删除、HDD状态判定 */ 36 buff[strlen(buff) - 1] = 0; 37 if (strcmp((strchr(buff, ':') + 2), find_key) != 0) { 38 flg = 1; 39 } 40 break; 41 } 42 } 43 } 44 } 45 } 46 pclose(fstream); 47 48 return OK; 49 }