FILE * s3_open_bin_read(const char *file_name, const char *in_version, const char **out_comment) { FILE *fp; char version[MAX_VERSION_LEN]; fp = fopen(file_name, "rb"); if (fp == NULL) { E_WARN_SYSTEM("Unable to open %s for reading", file_name); return NULL; } if (fscanf(fp, "%s", version) != 1) { E_ERROR("Premature EOF while reading %s\n", file_name); goto error; } if (strcmp(version, in_version) != 0) { E_ERROR("version mismatch. %s != %s (expected)\n", __FILE__, __LINE__, version, in_version); goto error; } if (bcomment_read(out_comment, fp) != S3_SUCCESS) { goto error; } if (swap_check(fp) != S3_SUCCESS) { goto error; } return fp; error: fclose(fp); return NULL; }
int getStorageStatus(STORAGE_INFO_T *st) { // char tmparray[MAXARRAY][MAXARRSIZE]; char *username, *password; char *apps_ver, *apps_model; st->Capability=0; unsigned long apps_status=0; // count apps_status if (swap_check()) { apps_status|=APPS_STATUS_SWAP; } if (nvram_match("apps_comp", "1")) { apps_status|=APPS_STATUS_FILECOMPLETENESS; } if (nvram_match("apps_disk_free", "1")) { apps_status|=APPS_STATUS_FREESPACE; } if (pids("smbd")) { apps_status|=APPS_STATUS_SAMBAMODE; } if (is_apps_running()) { apps_status|=APPS_STATUS_RUNNING; } if (nvram_match("usb_path1", "storage") || nvram_match("usb_path2", "storage")) { apps_status|=APPS_STATUS_DISCONPORT; } if (nvram_match("apps_dl", "1")) { apps_status|=APPS_STATUS_DMMODE; } if (nvram_match("apps_status_checked", "1")) { apps_status|=APPS_STATUS_CHECKED; } if (nvram_match("usb_mnt_first_path_port", "1")) { apps_status|=APPS_STATUS_USBPORT1; } if (strcmp(nvram_safe_get("mnt_type"), "ntfs") == 0) { apps_status|=APPS_STATUS_FS_NTFS; } if(strcmp(nvram_safe_get("dm_block"), "1") == 0) { apps_status|=APPS_STATUS_BLOCKED; } if(!strcmp(nvram_safe_get("st_samba_mode"), "2") || !strcmp(nvram_safe_get("st_samba_mode"), "4")) { apps_status|=APPS_STATUS_SMBUSER; } if(strcmp(nvram_safe_get("slow_disk"), "1") == 0) { apps_status|=APPS_SLOW_DISK; } st->AppsStatus=apps_status; // disable for tmp printf("\n[infosvr] apps status : %x\n", apps_status); // tmp test if(nvram_invmatch("apps_pool", "") && nvram_invmatch("apps_share", "")) { st->Capability = (unsigned long) atoi(nvram_safe_get("apps_caps")); strcpy(st->AppsPool, nvram_safe_get("usb_mnt_first_path")); strcpy(st->AppsShare, nvram_safe_get("apps_share")); } else { st->Capability=0; st->AppsPool[0]=0; st->AppsShare[0]=0; } st->DiskSize=0; st->DiskStatus=DISK_STATUS_NONE; st->DiskModel[0]=0; // disable for tmp memset(st->PrinterModel1, 0, 32); memset(st->PrinterModel2, 0, 32); if (strncmp(nvram_safe_get("st_ftp_modex"), "2", 1) == 0) { username = nvram_safe_get("acc_username0"); password = nvram_safe_get("acc_password0"); strncpy(st->PrinterModel1, username, strlen(username)); strncpy(st->PrinterModel2, password, strlen(password)); } else { strncpy(st->PrinterModel1, "anonymous", 9); } // copy apps_version to DiskModel apps_ver = nvram_get("apps_version"); if(!apps_ver) { printf("get empty apps ver!"); // tmp test apps_ver = "0.0.0.0"; } strncpy(st->DiskModel, apps_ver, strlen(apps_ver)); // tmp test printf("set apps version as %s\n", apps_ver); // tmp test // copy apps_model_name to Apps_Model_Name apps_model = nvram_safe_get("apps_model_name"); if(!apps_model) { printf("get empty apps model\n"); // tmp test apps_model = "no_model"; } strncpy(st->Apps_Model_Name, apps_model, strlen(apps_model)); // tmp test printf("set apps model as %s\n", apps_model); // tmp test #ifdef NOPARSER // get from page system("wget http://127.0.0.1/diskstatus.asp -O /tmp/diskstatus"); // find claimed ide if ((st->DiskSize=isClaimedIDE(st->DiskModel))) { st->DiskStatus=DISK_STATUS_CLAIMED; printf("chk 14: is claimed IDE\n"); // tmp test } else if ((st->DiskSize=isBlankIDE(st->DiskModel))) { st->DiskStatus=DISK_STATUS_BLANK; } isPrinter(st->PrinterModel1, st->PrinterModel2); #endif printf("Storage: %d %s\n", st->DiskStatus, st->AppsShare); // tmp test return 0; }
static int32 gauden_param_read(float32 *****out_param, int32 *out_n_mgau, int32 *out_n_feat, int32 *out_n_density, int32 **out_veclen, const char *file_name) { char version[1024], tmp; FILE *fp; int32 i, j, k, l, blk, n; int32 n_mgau; int32 n_feat; int32 n_density; int32 *veclen; int32 needs_reorder; float32 ****out; float32 *buf; E_INFO("Reading mixture gaussian parameter: %s\n", file_name); if ((fp = fopen(file_name, "rb")) == NULL) E_FATAL_SYSTEM("fopen(%s,rb) failed\n", file_name); if (fscanf(fp, "%s", version) != 1) E_FATAL("Unable to read version id\n"); if (strcmp(version, GAUDEN_PARAM_VERSION) != 0) E_FATAL("Version mismatch: %s, expecting %s\n", version, GAUDEN_PARAM_VERSION); if (bcomment_read(fp) != S3_SUCCESS) E_FATAL("bcomment_read() failed\n"); if ((needs_reorder = swap_check(fp)) < 0) E_FATAL("swap_check() failed\n"); /* #Codebooks */ if (fread_retry(&n_mgau, sizeof(uint32), 1, fp) != 1) E_FATAL("Error reading #codebooks\n"); if (needs_reorder) { SWAP_INT32(&n_mgau); } *out_n_mgau = n_mgau; /* #Features/codebook */ if (fread_retry(&n_feat, sizeof(uint32), 1, fp) != 1) E_FATAL("Error reading #features/codebook\n"); if (needs_reorder) { SWAP_INT32(&n_feat); } *out_n_feat = n_feat; /* #Gaussian densities/feature in each codebook */ if (fread_retry(&n_density, sizeof(uint32), 1, fp) != 1) E_FATAL("Error reading #densities/codebook-feature\n"); if (needs_reorder) { SWAP_INT32(&n_density); } *out_n_density = n_density; /* #Dimensions in each feature stream */ veclen = ckd_calloc(n_feat, sizeof(uint32)); *out_veclen = veclen; if (fread_retry(veclen, sizeof(uint32), n_feat, fp) != n_feat) E_FATAL("Error reading feature vector lengths\n"); if (needs_reorder) { for (i = 0; i < n_feat; i++) SWAP_INT32(&veclen[i]); } /* blk = total vector length of all feature streams */ for (i = 0, blk = 0; i < n_feat; i++) blk += veclen[i]; /* #Floats to follow; for the ENTIRE SET of CODEBOOKS */ if (fread_retry(&n, sizeof(uint32), 1, fp) != 1) E_FATAL("Error reading #floats\n"); if (needs_reorder) { SWAP_INT32(&n); } assert(n == n_mgau * n_density * blk); /* Allocate memory for mixture gaussian densities */ out = (float32 ****) ckd_calloc_3d (n_mgau, n_feat, n_density, sizeof(float32 *)); buf = (float32 *) ckd_calloc (n, sizeof(float)); for (i = 0, l = 0; i < n_mgau; i++) { for (j = 0; j < n_feat; j++) { for (k = 0; k < n_density; k++) { out[i][j][k] = &buf[l]; l += veclen[j]; } } } /* Read mixture gaussian densities data */ if (fread_retry (buf, sizeof(float32), n, fp) != n) E_FATAL("Error reading gaussian data\n"); if (needs_reorder) for (i = 0; i < n; i++) SWAP_FLOAT32(&buf[i]); E_INFO("%d codebook, %d feature, size", n_mgau, n_feat); for (i = 0; i < n_feat; i++) printf (" %dx%d", n_density, veclen[i]); printf ("\n"); if (fread (&tmp, 1, 1, fp) == 1) E_WARN("Non-empty file beyond end of data\n"); *out_param = out; fclose(fp); return 0; }