📄 fstest.c
字号:
get_devices(diskname)char *diskname;{ int i = drive; strcpy(testing[i].device, diskname); get_dir(diskname); if ( return_code < 0 ) error_exit(diskname); if (testing[i].space > maxblock) testing[i].blocks = maxblock; else testing[i].blocks = testing[i].space; testing[i].fd1 = 0; strcpy(testing[i].name1, testing[i].directory); strcat(testing[i].name1, "/"); strcat(testing[i].name1, NAME1); testing[i].file1_created = FALSE; testing[i].fd2 = 0; strcpy(testing[i].name2, testing[i].directory); strcat(testing[i].name2, "/"); strcat(testing[i].name2, NAME2); testing[i].file2_created = FALSE; testing[i].blocks_written = 0; testing[i++].blocks_read = 0; if ( i < MAX_DRIVES ) strcpy(testing[i].device, ""); for (i = drive; strcmp(testing[i].device, "") && i < MAX_DRIVES; i++) { strcat(testing_devices, " "); strcat(testing_devices, testing[i].device); if (quick_test || sd_quick_test) testing[i].blocks = 2; send_message(0, DEBUG, debug_info_msg, testing[i].device, testing[i].directory, testing[i].space, testing[i].blocks, testing[i].fd1, testing[i].name1, testing[i].file1_created, testing[i].fd2, testing[i].name2, testing[i].file2_created, testing[i].blocks_written,testing[i].blocks_read); }}transfer_error(type, filename, code, rec) char *type; char *filename; int code, rec;{ send_message(-code, ERROR, transfer_err_msg, type, device, filename, rec, errmsg(errno));}compare_error(){char msg_buffer[100];char *msg = msg_buffer; if (file1_bad) { ind = file1_bad; file1_bad = FALSE; cmp_error = FILE1_BAD; sprintf(msg, "'%s'", testing[drive].name1); } else sprintf(msg, "between '%s' and '%s'", testing[drive].name1, testing[drive].name2); if (display_read_data || run_on_error) { failed = TRUE; return_code = cmp_error; send_message(0, ERROR, "Compare error on %s %s, blk %d, offset %d.", device, msg, testing[drive].blocks_read, bsize - sizeof(u_long) * ind); /* compare error */ display_data(); } else send_message(-cmp_error, ERROR, "Compare error on %s %s, blk %d, offset %d.", device, msg, testing[drive].blocks_read, bsize - sizeof(u_long) * ind);}display_data(){ int i; char ch[20]; send_message(0, CONSOLE, display1_msg, testing[drive].blocks_read, device, block_patterns[testing[drive].blocks_read]); send_message(0, CONSOLE, display2_msg, device, testing[drive].name1); for (i = 0; i < 8; i++) { send_message(0, CONSOLE, data_msg, d_buf[0][i + ((bsize - sizeof(u_long) * ind) / sizeof(u_long))]); } send_message(0, CONSOLE, display2_msg, device, testing[drive].name2); for (i = 0; i < 8; i++) { send_message(0, CONSOLE, data_msg, d_buf[1][i + ((bsize - sizeof(u_long) * ind) / sizeof(u_long))]); } send_message(0, CONSOLE, "\n"); if (!run_on_error) { send_message(0, CONSOLE, "\nContinue check? y/n: "); scanf("%s", ch); if (ch[0] == 'n') { send_message(0, CONSOLE, "Remove test files? y/n: "); scanf("%s", ch); if (ch[0] == 'y') { clean_up(); exit(cmp_error); } else exit(LEAVE_FILES); } send_message(0, CONSOLE, "Redo the compare? y/n "); scanf("%s", ch); if (ch[0] == 'y') { recompare = TRUE; } else { send_message(0, CONSOLE, "Reread the same blocks? y/n "); scanf("%s", ch); if (ch[0] == 'y') { lseek(testing[drive].fd1, -(bsize), 1); lseek(testing[drive].fd2, -(bsize), 1); testing[drive].blocks_read--; reread_block = TRUE; read_retry = TRUE; } else read_retry = FALSE; } } else { /* run_on_error */ if (!already_recompared) { already_recompared = TRUE; recompare = TRUE; } else { if (!reread) { reread = TRUE; lseek(testing[drive].fd1, -(bsize), 1); lseek(testing[drive].fd2, -(bsize), 1); testing[drive].blocks_read--; reread_block = TRUE; read_retry = TRUE; } else { read_retry = FALSE; already_recompared = FALSE; reread = FALSE; send_message(0, CONSOLE, continue_msg); } } }}/* * lcmp : compares the contents of two memory buffers, one 32-bit(u_long) * word at a time. This comparison starts at the low end of the buffer, and * proceeds towards high. * * * return : the size of the buffer, in the unit of 32-bit(u_long), less the * offset from starting address to the first location that does not compare. * 0 if everything compares. * * note: the residue(after divided by sizeof(u_long)) won't be compared. */lcmp(add1, add2, count) register u_long *add1, *add2; register u_long count;{ count /= sizeof(u_long); /* to be sure */ while (count--) if (*add1++ != *add2++) return (++count); return (0); /* everything compares */}/* * lfill : fills "count" bytes of memory, starting at "add" with "pattern" * ,32-bit (u_long) word at a time. The residue(after divided by * sizeof(u_long)) will not be filled. * * return: this function always return the integer -1. */int lfill(add, count, pattern) register u_long *add; register u_long count, pattern;{ count /= sizeof(u_long); /* to be sure */ while (count--) *add++ = pattern;}process_disk_args(argv, arrcount) char *argv[]; int arrcount;{ if (strncmp(argv[arrcount], "p=", 2) == 0) { usr_selected_pattern = TRUE; if (argv[arrcount][2] == 's') data_pattern = DATA_SEQUENTAL; if (argv[arrcount][2] == '0') data_pattern = DATA_ZERO; if (argv[arrcount][2] == '1') data_pattern = DATA_ONES; if (argv[arrcount][2] == 'a') data_pattern = DATA_A; if (argv[arrcount][2] == '5') data_pattern = DATA_5; if (argv[arrcount][2] == 'r') data_pattern = DATA_RANDOM; } else if (strncmp(argv[arrcount],"D=", 2) == 0) { /* sundiag */ strcpy(device, &argv[arrcount][2]); /* set diskname */ verbose = FALSE; } else return (FALSE); return (TRUE);}routine_usage(){ (void) send_message(0, CONSOLE, routine_msg);}/* * This function auto mounts partitions on the disk device, * if a file system exists on it and checks if it has enough * space. */auto_mnt(name)char *name;{ char nbuf[25]; struct fs fs; int partition, fd; for ( partition = 'a' ; partition <= 'h' ; partition++ ) { if ( partition == 'b' ) continue; /* Ignore partition 'b' */ sprintf(nbuf, "/dev/%s%c", name, partition); /* check to see if a file system exists here. */ if ( (fd = open(nbuf, O_RDWR)) > 0 ) { /* Device open succeeded ! */ lseek(fd, BBSIZE, 0); /* Go to start of super block */ read(fd, &fs, sizeof(fs)); close(fd); if ( fs.fs_magic != FS_MAGIC ) {/* No fs */ return_code = -NOFS_ERROR; continue; /* No file system here! */ } } else { /* Partition does not exist! */ return_code = -OPENDEV_ERROR; continue; } if (access("/tmp", F_OK)) mkdir("/tmp", 0600); /* Build the temporary directory name */ sprintf(tmp_dir,"/tmp/%s%c.XXXXXX", name, partition); strcpy(tmp_dir,mktemp(tmp_dir)); /* Now that the device exists, try mounting it! */ return_code = mnt(nbuf); if (return_code >= 0) {/* now check for enough space */ do_stat(tmp_dir, nbuf); if (return_code < 0) {/* Try next partition */ auto_mount = FALSE; unmnt(tmp_dir); } else break; /* Success! */ } }}/* * The actual mount. */mnt(nbuf)char *nbuf;{#ifndef SVR4 struct ufs_args args; enter_critical(); /* enter critical code area */#endif mkdir(tmp_dir, 0600);#ifdef SVR4 if ( mount(nbuf,tmp_dir, MS_DATA, "ufs") )#else args.fspec = nbuf; if ( mount(MNTTYPE_42, tmp_dir, M_NEWTYPE, &args) )#endif SVR4 { /* problems mounting? */ rmdir(tmp_dir); return(-AUTO_MNT_ERROR); /* Try next partition */ } auto_mount = TRUE; /* successful mount */#ifndef SVR4 exit_critical(); /* exit critical code area */#endif SVR4 return(0);}/* * The actual unmount and removal * of temporary directory. */unmnt(tmp_dir)char *tmp_dir;{#ifdef SVR4 if ( umount(tmp_dir) < 0)#else enter_critical(); /* enter critical code area */ if (unmount(tmp_dir) < 0)#endif SVR4 send_message(-AUTO_UNMNT_ERROR, ERROR, unmnt_err_msg, tmp_dir, errno == EBUSY ? "busy" : "not mounted"); rmdir(tmp_dir);#ifndef SVR4 exit_critical(); /* exit critical code area */#endif SVR4 return(0);}/* * Print error message and exit */error_exit(diskname)char *diskname;{ switch (return_code) { case 0: break; case -NOT_ENOUGH_FREE_ERROR :/* not enough free blocks on drive */ send_message(-NOT_ENOUGH_FREE_ERROR, ERROR, blocks_err_msg, diskname); case -NOT_WRITABLE_ERROR: /* no writable partition on drive */ send_message(-NOT_WRITABLE_ERROR, ERROR, pwrite_err_msg, diskname); case -NOFS_ERROR : send_message(-NOFS_ERROR, ERROR, nofs_err_msg, diskname); case -AUTO_MNT_ERROR : send_message(-AUTO_MNT_ERROR, ERROR, auto_mnt_err_msg, diskname); case -OPENDEV_ERROR : send_message(-OPENDEV_ERROR, ERROR, opendev_err_msg, diskname); }}#ifndef SVR4/* * This function is called just before executing * some critical part of the code. The SIGINT * signal when/if received while executing this * part of the code will be temporarily blocked * and serviced at a later stage(in exit_critical()). */enter_critical(){ oldmask = sigblock(sigmask(SIGINT));}/* * This function is called just after executing * some critical part of the code. The SIGINT * signal will be unblocked and the old signal * mask will be restored, so that the interrupts * may be serviced as originally intended. */exit_critical(){ (void) sigsetmask(oldmask);}#endif SVR4clean_up(){ int i; name1 = testing[0].name1; name2 = testing[0].name2; for (i = drive; strcmp(testing[i].device, "") && i < MAX_DRIVES; i++) { strcpy(device, testing[i].device); if (testing[i].file1_created) { if (testing[i].fd1 > 0) testing[i].fd1 = close(testing[i].fd1); testing[i].file1_created = FALSE; if (unlink(testing[i].name1)) send_message(-FILE1_UNLINK_ERROR, ERROR, flag_err_msg, "unlink", testing[i].name1, device, errmsg(errno)); } if (testing[i].file2_created) { if (testing[i].fd2 > 0) testing[i].fd2 = close(testing[i].fd2); testing[i].file2_created = FALSE; if (unlink(testing[i].name2)) { send_message(-FILE2_UNLINK_ERROR, ERROR, flag_err_msg, "unlink", testing[i].name2, device, errmsg(errno)); } } } if ( auto_mount == TRUE ) { auto_mount = FALSE; unmnt(tmp_dir); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -