static int DumpDumpHeader(int dumpfd, register Volume * vp, afs_int32 fromtime) { int code = 0; afs_int32 dumpTimes[2]; if (verbose) fprintf(stderr, "dumping dump header\n"); if (!code) code = DumpDouble(dumpfd, D_DUMPHEADER, DUMPBEGINMAGIC, DUMPVERSION); if (!code) code = DumpInt32(dumpfd, 'v', V_id(vp)); if (!code) code = DumpString(dumpfd, 'n', V_name(vp)); dumpTimes[0] = fromtime; dumpTimes[1] = V_backupDate(vp); /* Until the time the clone was made */ if (!code) code = DumpArrayInt32(dumpfd, 't', (afs_uint32 *) dumpTimes, 2); return code; }
static int DumpVnode(int dumpfd, struct VnodeDiskObject *v, int volid, int vnodeNumber, int dumpEverything, struct Volume *vp) { int code = 0; IHandle_t *ihP; FdHandle_t *fdP; if (verbose) fprintf(stderr, "dumping vnode %d\n", vnodeNumber); if (!v || v->type == vNull) return code; if (!code) code = DumpDouble(dumpfd, D_VNODE, vnodeNumber, v->uniquifier); if (!dumpEverything) return code; if (!code) code = DumpByte(dumpfd, 't', (byte) v->type); if (!code) code = DumpShort(dumpfd, 'l', v->linkCount); /* May not need this */ if (!code) code = DumpInt32(dumpfd, 'v', v->dataVersion); if (!code) code = DumpInt32(dumpfd, 'm', v->unixModifyTime); if (!code) code = DumpInt32(dumpfd, 'a', v->author); if (!code) code = DumpInt32(dumpfd, 'o', v->owner); if (!code && v->group) code = DumpInt32(dumpfd, 'g', v->group); /* default group is 0 */ if (!code) code = DumpShort(dumpfd, 'b', v->modeBits); if (!code) code = DumpInt32(dumpfd, 'p', v->parent); if (!code) code = DumpInt32(dumpfd, 's', v->serverModifyTime); if (v->type == vDirectory) { acl_HtonACL(VVnodeDiskACL(v)); if (!code) code = DumpByteString(dumpfd, 'A', (byte *) VVnodeDiskACL(v), VAclDiskSize(v)); } if (VNDISK_GET_INO(v)) { IH_INIT(ihP, V_device(vp), V_parentId(vp), VNDISK_GET_INO(v)); fdP = IH_OPEN(ihP); if (fdP == NULL) { fprintf(stderr, "Unable to open inode %s for vnode %u (volume %i); not dumped, error %d\n", PrintInode(NULL, VNDISK_GET_INO(v)), vnodeNumber, volid, errno); } else { if (verbose) fprintf(stderr, "about to dump inode %s for vnode %u\n", PrintInode(NULL, VNDISK_GET_INO(v)), vnodeNumber); code = DumpFile(dumpfd, vnodeNumber, fdP, v); FDH_CLOSE(fdP); } IH_RELEASE(ihP); } if (verbose) fprintf(stderr, "done dumping vnode %d\n", vnodeNumber); return code; }
static int DumpFile(int dumpfd, int vnode, FdHandle_t * handleP, struct VnodeDiskObject *v) { int code = 0, failed_seek = 0, failed_write = 0; afs_int32 pad = 0; afs_int32 offset = 0; afs_sfsize_t n, nbytes, howMany, howBig; byte *p; #ifndef AFS_NT40_ENV struct afs_stat status; #endif afs_sfsize_t size, tmpsize; #ifdef AFS_AIX_ENV #include <sys/statfs.h> struct statfs tstatfs; #endif if (verbose) fprintf(stderr, "dumping file for vnode %d\n", vnode); #ifdef AFS_NT40_ENV howBig = _filelength(handleP->fd_fd); howMany = 4096; #else afs_fstat(handleP->fd_fd, &status); howBig = status.st_size; #ifdef AFS_AIX_ENV /* Unfortunately in AIX valuable fields such as st_blksize are * gone from the stat structure. */ fstatfs(handleP->fd_fd, &tstatfs); howMany = tstatfs.f_bsize; #else howMany = status.st_blksize; #endif /* AFS_AIX_ENV */ #endif /* AFS_NT40_ENV */ size = FDH_SIZE(handleP); if (verbose) fprintf(stderr, " howBig = %u, howMany = %u, fdh size = %u\n", howBig, howMany, size); #ifdef AFS_LARGEFILE_ENV { afs_uint32 hi, lo; SplitInt64(size, hi, lo); if (hi == 0L) { code = DumpInt32(dumpfd, 'f', lo); } else { code = DumpDouble(dumpfd, 'h', hi, lo); } } #else /* !AFS_LARGEFILE_ENV */ code = DumpInt32(dumpfd, 'f', size); #endif /* !AFS_LARGEFILE_ENV */ if (code) { return VOLSERDUMPERROR; } p = (unsigned char *)malloc(howMany); if (!p) { fprintf(stderr, "out of memory!\n"); return VOLSERDUMPERROR; } /* loop through whole file, while we still have bytes left, and no errors, in chunks of howMany bytes */ for (nbytes = size; (nbytes && !failed_write); nbytes -= howMany) { if (nbytes < howMany) howMany = nbytes; /* Read the data - unless we know we can't */ n = (failed_seek ? 0 : FDH_READ(handleP, p, howMany)); /* If read any good data and we null padded previously, log the * amount that we had null padded. */ if ((n > 0) && pad) { fprintf(stderr, "Null padding file %d bytes at offset %u\n", pad, offset); pad = 0; } /* If didn't read enough data, null padd the rest of the buffer. This * can happen if, for instance, the media has some bad spots. We don't * want to quit the dump, so we start null padding. */ if (n < howMany) { if (verbose) fprintf(stderr, " read %u instead of %u bytes.\n", n, howMany); /* Record the read error */ if (n < 0) { n = 0; fprintf(stderr, "Error %d reading inode %s for vnode %d\n", errno, PrintInode(NULL, handleP->fd_ih->ih_ino), vnode); } else if (!pad) { fprintf(stderr, "Error reading inode %s for vnode %d\n", PrintInode(NULL, handleP->fd_ih->ih_ino), vnode); } /* Pad the rest of the buffer with zeros. Remember offset we started * padding. Keep total tally of padding. */ memset(p + n, 0, howMany - n); if (!pad) offset = (howBig - nbytes) + n; pad += (howMany - n); /* Now seek over the data we could not get. An error here means we * can't do the next read. */ failed_seek = FDH_SEEK(handleP, ((size - nbytes) + howMany), SEEK_SET); if (failed_seek != ((size - nbytes) + howMany)) { if (failed_seek < 0) { fprintf(stderr, "Error %d seeking in inode %s for vnode %d\n", errno, PrintInode(NULL, handleP->fd_ih->ih_ino), vnode); } else { fprintf(stderr, "Error seeking in inode %s for vnode %d\n", PrintInode(NULL, handleP->fd_ih->ih_ino), vnode); failed_seek = -1; } } else { failed_seek = 0; } } /* Now write the data out */ if (write(dumpfd, (char *)p, howMany) != howMany) failed_write = VOLSERDUMPERROR; } if (pad) { /* Any padding we hadn't reported yet */ fprintf(stderr, "Null padding file: %d bytes at offset %u\n", pad, offset); } free(p); return failed_write; }
int main(int argc, char* argv[]) { int i, frameWidth, polyDiv2, N, N2, depth, cosTW; double beta, ACH_Difference, sampFreq, trueFreq, exactFreq, exactFreqDiff; short *FFT_S_short; double *FFT_S, *FFT_T, *MagC, *MagL, *MagR, *ACH, *ArgC, *ArgL, *ArgR, *PhaseLR; int FFT_S_Offset; bool useTaperWindow, recoverAfterTaperWindow, useNorm, direction, usePolyphase, simpleMode, isMirror, isComplex; CFFT_Object *fftObj; CFFT_SelfTestResult selfTestResult; FILE *testSignalFile; // *************************************************** printf("ExactFFT TEST \"C\" 7.10, (c) TESLA, 2014"); // *************************************************** // * КОНСТРУКТОР // *************************************************** frameWidth = 4096; beta = 28; // 28 polyDiv2 = 1; cosTW = BLACKMAN_HARRIS_92dbPS; fftObj = CFFT_Constructor_Cosine(frameWidth, cosTW, polyDiv2); //fftObj = CFFT_Constructor_Kaiser(frameWidth, beta, polyDiv2); // *************************************************** // * САМОДИАГНОСТИКА // *************************************************** ACH_Difference = 1000; selfTestResult = SelfTest_RND(ACH_Difference, fftObj); FFT_S = (double *)calloc((frameWidth << 1), sizeof(double)); FFT_S_short = (short *)calloc((frameWidth << 1), sizeof(short)); FFT_T = (double *)calloc((frameWidth << 1), sizeof(double)); // (Количество точек FFT / 2) - количество гармоник вместе с нулевой N = fftObj->N; N2 = N >> 1; // Массивы результатов Фурье-анализа MagC = (double *)calloc(N, sizeof(double)); MagL = (double *)calloc(N2, sizeof(double)); MagR = (double *)calloc(N2, sizeof(double)); ACH = (double *)calloc(N2, sizeof(double)); ArgC = (double *)calloc(N, sizeof(double)); ArgL = (double *)calloc(N2, sizeof(double)); ArgR = (double *)calloc(N2, sizeof(double)); PhaseLR = (double *)calloc(N2, sizeof(double)); testSignalFile = GetStreamPointer(NULL, "3600_Hz_STEREO_36000_SampleRate_36_deg_65536.raw", FALSE); if(testSignalFile == NULL) { printf("\nCan't open 3600_Hz_STEREO_36000_SampleRate_36_deg_65536.raw!"); return 1; } fread(FFT_S_short, sizeof(short), (frameWidth << 1), testSignalFile); for(i = 0; i < (frameWidth << 1); ++i) { FFT_S[i] = (double)FFT_S_short[i]; } DumpDouble(FFT_S, (frameWidth << 1), DUMP_NAME, "FFT_S.double"); // Прямой прогон FFT useTaperWindow = TRUE; FFT_S_Offset = 0; recoverAfterTaperWindow = FALSE; useNorm = TRUE; direction = TRUE; usePolyphase = FALSE; isMirror = TRUE; CFFT_Process(FFT_S, FFT_S_Offset, FFT_T, useTaperWindow, recoverAfterTaperWindow, useNorm, direction, usePolyphase, fftObj); DumpDouble(FFT_T, (frameWidth << 1), DUMP_NAME, "FFT_T.double"); CFFT_Explore(FFT_T, MagL, MagR, ACH, ArgL, ArgR, PhaseLR, usePolyphase, fftObj); DumpDouble(MagL, N2, DUMP_NAME, "MagL.double"); DumpDouble(MagR, N2, DUMP_NAME, "MagR.double"); DumpDouble(PhaseLR, N2, DUMP_NAME, "PhaseLR.double"); CFFT_ComplexExplore(FFT_T, MagC, ArgC, usePolyphase, isMirror, fftObj); DumpDouble(MagC, N, DUMP_NAME, "MagC.double"); DumpDouble(ArgC, N, DUMP_NAME, "ArgC.double"); fclose(testSignalFile); // Вычисление точной частоты sampFreq = 36000; trueFreq = 3600; depth = 20; isComplex = FALSE; exactFreq = ExactFreqAuto(MagL, depth, sampFreq, isComplex, fftObj); exactFreqDiff = fabs(exactFreq - trueFreq); DumpDouble(&exactFreq, 1, DUMP_NAME, "exactFreq.double"); DumpDouble(&trueFreq, 1, DUMP_NAME, "trueFreq.double"); DumpDouble(&exactFreqDiff, 1, DUMP_NAME, "exactFreqDiff.double"); // *************************************************** // * ДЕСТРУКТОР // *************************************************** SAFE_DELETE(FFT_S); SAFE_DELETE(FFT_S_short); SAFE_DELETE(FFT_T); SAFE_DELETE(MagC); SAFE_DELETE(MagL); SAFE_DELETE(MagR); SAFE_DELETE(ACH); SAFE_DELETE(ArgC); SAFE_DELETE(ArgL); SAFE_DELETE(ArgR); SAFE_DELETE(PhaseLR); CFFT_Destructor(fftObj); return 0; }