⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fstest.c

📁 操作系统SunOS 4.1.3版本的源码
💻 C
📖 第 1 页 / 共 2 页
字号:
static char     sccsid[] = "@(#)fstest.c 1.1 7/30/92 Copyright 1984 Sun Micro"; /* * this progam writes two files with random data, and then  * compares them. The file sizes are 1/2MB each for a hard disk.  * If any errors occur in the process, we log errors and stop.  */#include <stdio.h>#ifdef	 SVR4#include <unistd.h>#endif	 SVR4#include <sys/types.h>#include <sys/errno.h>#include <sys/stat.h>#include <sys/time.h>#include <sys/ioctl.h>#ifdef	 SVR4#include <sys/fcntl.h>#else#include <sys/file.h>#endif	 SVR4#include <sys/param.h>#ifdef   SVR4#include <sys/fs/ufs_fs.h>#else#include <ufs/fs.h>#endif	 SVR4#include <signal.h>#ifdef	 SVR4#include <sys/statvfs.h>#include <sys/statfs.h>#else#include <sys/vfs.h>#endif	 SVR4#include <sys/mount.h>#ifdef	 SVR4#include <sys/dkio.h>#include <sys/mntent.h>#include <sys/mnttab.h>#else#include <sun/dkio.h>#include <mntent.h>#endif	 SVR4#include "fstest.h"#include "fstest_msg.h"#include "sdrtns.h"             /* sundiag standard header file*/#include "../../../lib/include/libonline.h"   /* online library include */#define MAXTRIES 300#define TIME_MAX 16#ifdef SVR4struct mnttab *dupmnttab();#else SVR4void freemntlist();struct mntent * dupmntent();void freemntent();#endif SVR4extern int      process_disk_args();extern int	routine_usage();extern int      errno;                      /* system error number */extern char    *mktemp();int             auto_mount = 0;int		oldmask=0;int             drive = 0, files_open = 0, ind;int		display_read_data = FALSE, sd_quick_test = FALSE;int             file1_bad = FALSE, reread_block = FALSE;int             cmp_error = FILE1_CMP_ERROR;int             recompare = FALSE, already_recompared = FALSE;int             reread = FALSE, read_retry = FALSE;int             data_pattern = 100, usr_selected_pattern = FALSE;int		return_code = 0, failed = FALSE;int 		bsize = BSIZE, maxblock = MAXBLOCK;char		device_diskname[32]="";char	       *device = device_diskname;char            *name1, *name2;char            testing_devices[MAX_DRIVES * 5] = {""};char		tmp_dir[100];u_long          pattern, block_patterns[MAXBLOCK];u_long          d_buf[3][BSIZE / sizeof(u_long)];#ifdef SVR4u_long     *b1 = d_buf[0], *b2 = d_buf[1], *b3 = d_buf[2];#elseint u_long     *b1 = d_buf[0], *b2 = d_buf[1], *b3 = d_buf[2];#endif SVR4main(argc, argv)    int             argc;    char           *argv[];{    char	diskname[8];    int		i;    int		pid, cpattern;    versionid = "3.33"; 		/* SCCS version id */    diskname[0] = '\0';         /* initialize to null string */    strcpy(device, testing[0].device);    device_name = device;    test_init(argc, argv, process_disk_args, routine_usage, test_usage_msg);    strcpy(diskname, device);    get_devices(diskname);    for (i = drive; strcmp(testing[i].device, "") && i < MAX_DRIVES ;i++) {        strcpy(device, testing[i].device);        if (!testing[i].file1_created) {		name1 = testing[i].name1;		name2 = testing[i].name2;		name1 = mktemp(name1);		name2 = mktemp(name2);        }        send_message(0, VERBOSE, open_file_msg, device,                      testing[i].name1, testing[i].name2);#ifndef SVR4	enter_critical(); /* enter critical code area */#endif SVR4        if ((testing[i].fd1=open(testing[i].name1,OMODE1,0660)) == EOF)            send_message(-FILE1_OPEN_ERROR, ERROR, flag_err_msg, "open",                         testing[i].name1, device, errmsg(errno));	testing[i].file1_created = TRUE;	files_open++;	if ((testing[i].fd2=open(testing[i].name2,OMODE1,0660)) == EOF)            send_message(-FILE2_OPEN_ERROR, ERROR, flag_err_msg, "open",                         testing[i].name2, device, errmsg(errno));	testing[i].file2_created = TRUE;	testing[i].blocks_written = 0;	files_open++;#ifndef SVR4	exit_critical(); /* exit critical code area */#endif SVR4    }    if (!usr_selected_pattern) {        if (++data_pattern > DATA_RANDOM)	    data_pattern = DATA_SEQUENTAL;         pattern = -1;    }    cpattern = -1;    pid = getpid();    while (files_open) {        switch (data_pattern) {        case DATA_SEQUENTAL:	    cpattern++;       /*	* The pattern will contain the	* pid in upper 16 bits and block 	* number in lower 16 bits of word.	* Start with pattern = 0x----0000	* End with pattern   = 0x----03ff	* (The hyphens will have the pid)	* The layout of each pattern will be	*	*       31                                     0	*        |                                     |	* WORD  [....|....|....|....|....|....|....|....]        *	 <------ pid ----- > < --- blkno. ---- >	*	* Each block is 512 Bytes. The test writes 1024	* blocks. So it will write 1/2 MB of data into 	* each file.	*/	    pattern = ((pid&0xffff) << 16) | (cpattern&0xffff);	    break;        case DATA_ZERO:	    pattern = 0;	    break;        case DATA_ONES:	    pattern = 0xffffffff;	    break;        case DATA_A:	    pattern = 0xaaaaaaaa;	    break;        case DATA_5:	    pattern = 0x55555555;	    break;        case DATA_RANDOM:#           ifdef SVR4	    pattern = rand();#           else	    pattern = random();#           endif        }        lfill(b1, bsize, pattern);        for (i= drive; strcmp(testing[i].device, "") && i < MAX_DRIVES; i++) {	    if (testing[i].fd1) {	        strcpy(device, testing[i].device);	        block_patterns[testing[i].blocks_written] = pattern;	        if (write(testing[i].fd1, b1, bsize) != bsize) 		    transfer_error("Write", testing[i].name1,			           FILE1_WRITE_ERROR,                                    testing[i].blocks_written);	        if (write(testing[i].fd2, b1, bsize) != bsize) 		    transfer_error("Write", testing[i].name2,			           FILE2_WRITE_ERROR,                                    testing[i].blocks_written);	        if (++testing[i].blocks_written >= testing[i].blocks) {		   send_message(0, VERBOSE, "Closing %s, blocks written = %d.",                                testing[i].device,                                 testing[i].blocks_written);	            if (testing[i].fd1 = close(testing[i].fd1))                         send_message(-FILE1_CLOSE_ERROR, ERROR, flag_err_msg,                                      "close", testing[i].name1, device,                                      errmsg(errno));		    files_open--;		    if (testing[i].fd2 = close(testing[i].fd2))                         send_message(-FILE2_CLOSE_ERROR, ERROR, flag_err_msg,                                      "close", testing[i].name2, device,                                      errmsg(errno));		    files_open--;	        }	    }        }    }    if (!quick_test)        sleep(10);    for (i = drive; strcmp(testing[i].device, "") && i < MAX_DRIVES ; i++) {	strcpy(device, testing[i].device);	if ((testing[i].fd1 = open(testing[i].name1, OMODE2)) == EOF)            send_message(-FILE1_REOPEN_ERROR, ERROR, flag_err_msg, "reopen",                         testing[i].name1, device, errmsg(errno));	files_open++;	if ((testing[i].fd2 = open(testing[i].name2, OMODE2)) == EOF)            send_message(-FILE2_REOPEN_ERROR, ERROR, flag_err_msg, "reopen",                         testing[i].name2, device, errmsg(errno));	testing[i].blocks_read = 0;	files_open++;    }    while (files_open) {	for (i = drive; strcmp(testing[i].device, "") && i < MAX_DRIVES; i++) {	    if (testing[i].fd1) {	        strcpy(device, testing[i].device);	        lfill(b3, bsize, block_patterns[testing[i].blocks_read]);		if (read_retry)                     send_message(0, ERROR, reread_err_msg,                                 testing[i].blocks_read, device);		if (read(testing[i].fd1, b1, bsize) != bsize) 		    transfer_error("Read", testing[i].name1,			         FILE1_READ_ERROR, testing[i].blocks_read);	        file1_bad = lcmp(b1, b3, bsize);		if (read(testing[i].fd2, b2, bsize) != bsize) 		    transfer_error("Read", testing[i].name2,			         FILE2_READ_ERROR, testing[i].blocks_read);		if ((ind = lcmp(b1, b2, bsize)) || file1_bad) {		    compare_error();		    while (recompare) {		        recompare = FALSE;                        send_message(0, ERROR, recompare_msg,                                     testing[i].blocks_read, device);		        file1_bad = lcmp(b1, b3, bsize);		        if ((ind = lcmp(b1, b2, bsize)) || file1_bad) 			    compare_error();		        else                            send_message(0, ERROR, good_recomp_msg,				         testing[i].blocks_read, device);		    }	        } else if (read_retry) {		    read_retry = FALSE;                    send_message(0, ERROR, recompare2_msg,		                 testing[i].blocks_read, device);	        }	        if (++testing[i].blocks_read >= testing[i].blocks) {		    send_message(0,VERBOSE,"Closing %s, blocks read = %d.",                            testing[i].device, testing[i].blocks_read);		    if (testing[i].fd1 = close(testing[i].fd1))                         send_message(-FILE1_RECLOSE_ERROR, ERROR, flag_err_msg,                                     "reclose", testing[i].name1,                                     device, errmsg(errno));		    files_open--;		    if (testing[i].fd2 = close(testing[i].fd2))                         send_message(-FILE2_RECLOSE_ERROR, ERROR, flag_err_msg,                                     "reclose", testing[i].name2,                                     device, errmsg(errno));		    files_open--;		}	    }	    if (reread_block)	    {	        reread_block = FALSE;		i--;	    }	}    }    clean_up();    sleep(10);    if (failed) 	exit(return_code);    test_end();		/* Sundiag normal exit */}get_dir(name)char	*name;{  FILE	*mtabp;  int length;#ifdef SVR4  struct mnttab mnt;   /*   * Initially set return_code to a sentinel value so that   * we know whether we have status yet.   */  return_code = 1;    sync();    if ((mtabp = fopen("/etc/mnttab","r")) == NULL)	send_message(-FS_PROBE_ERROR, ERROR, mount_err_msg, name);    length = strlen(name);    while ((getmntent(mtabp,&mnt)) != -1) {	if (!strcmp(mnt.mnt_fstype, MNTTYPE_UFS)) { /* 4.2 file system only */	    if (!strncmp(mnt.mnt_special+5, name, length)) { /* the right drive */		if (strstr(mnt.mnt_mntopts, MNTOPT_RW) != NULL) { /* be writable */		    do_stat(mnt.mnt_mountp, mnt.mnt_special);		    if ( return_code == 0 )			break; /* There is enough space! */	   	}		else {		    return_code = -NOT_WRITABLE_ERROR;		    break;		}	    }	}	else		return_code = -1;	/* Not a 4.2 file system */    }#else  struct mntent	*mnt;   /*   * Initially set return_code to a sentinel value so that   * we know whether we have status yet.   */  return_code = 1;  sync();  if ((mtabp = setmntent(MOUNTED, "r")) == NULL)	send_message(-FS_PROBE_ERROR, ERROR, mount_err_msg, name);  length = strlen(name);  while ((mnt = getmntent(mtabp)) != NULL) {    if (!strcmp(mnt->mnt_type, MNTTYPE_42)) {   /* 4.2 file system only */      if (!strncmp(mnt->mnt_fsname+5, name, length)) { /* the right drive */	  if ( hasmntopt(mnt, MNTOPT_RW) != (char *)0) {    /* must be writable */		do_stat(mnt->mnt_dir, mnt->mnt_fsname) ;		if ( return_code == 0 )			break; /* There is enough space! */      }      else	   return_code = -NOT_WRITABLE_ERROR;	   /* remember that we had a read-only fs mounted */      }    }     else      return_code = -NOT_WRITABLE_ERROR;  /* not a 4.2 file system */  }  endmntent(mtabp);#endif SVR4  if (return_code == 1)      auto_mnt(name);}do_stat(dir,name)char *dir, *name;{# ifdef SVR4  struct statvfs fs ;# else  struct statfs	fs;# endif  int free;# ifdef SVR4  if (statvfs(dir,&fs) < 0)# else  if (statfs(dir, &fs) < 0) # endif    send_message(-FS_PROBE_ERROR, ERROR, free_err_msg, name);  else {#ifdef SVR4    if ((free = fs.f_bavail*fs.f_frsize/1024) >= 1024) {#else SVR4    if ((free = fs.f_bavail*fs.f_bsize/1024) >= 1024) {#endif SVR4      if (free < 2048) {        maxblock = 10;      }      strcpy(testing[drive].directory, dir);      if ( auto_mount == FALSE )      	strcat(testing[drive].directory, "/tmp");      if (access(testing[drive].directory, F_OK))	  mkdir(testing[drive].directory, 0600);      testing[drive].space = free;      return_code = 0;  /* must be enough free blocks */    }    else {	/* must be not enough free blocks */	return_code = -NOT_ENOUGH_FREE_ERROR;    }  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -