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

📄 tstsh.c

📁 ertfs文件系统里面既有完整ucos程序
💻 C
📖 第 1 页 / 共 3 页
字号:
    }
}

/* DIFF PATH PATH */ 
int dodiff(int agc, char **agv)                                  /*__fn__*/
{
    PCFD in_fd;
    PCFD in_fd1;
    int nread;
    int nread1;
    int i;
    char buff[256];
    char buff1[256];
    BOOLEAN forever = TRUE;         /* use this for while(forever) to quiet anal compilers */

    if (agc == 2)
    {
        if ((in_fd = po_open(*agv, (PO_BINARY|PO_RDONLY), (PS_IWRITE | PS_IREAD) ) ) < 0)
        {
            tm_printf_2("Cant open %s\n", *agv);
            return(0);
        }
        if ((in_fd1 = po_open(*(agv+1), (PO_BINARY|PO_RDONLY), (PS_IWRITE | PS_IREAD) ) ) < 0)
        {
            tm_printf_2("Cant open %s\n", *(agv+1));
            return(0);
        }
        while (forever)
        {
            nread = po_read(in_fd,(byte*)buff,(word)255);
            if (nread > 0)
            {
                nread1 = po_read(in_fd1,(byte*)buff1,(word)nread);
                if (nread1 != nread)
                {
difffail:
                    tm_printf("Files are different\n");    
                    po_close (in_fd);
                    po_close (in_fd);
                    return(0);
                }
                for(i = 0; i < nread; i++)
                {
                    if (buff[i] != buff1[i])
                        goto difffail;
                }
            }
            else
                break;
        }
        nread1 = po_read(in_fd1,(byte*)buff1,(word)nread);
        if (nread1 <= 0)
            tm_printf_3("(%s) (%s) Files are the same\n", *agv, *(agv+1));    
        else
        {
            tm_printf_3("%s is larger than %s\n", *(agv+1), *agv);
            goto difffail;
        }
        po_close(in_fd);
        po_close(in_fd1);
        return(1);
   }
   else
   {
       tm_printf("Usage: DIFF PATH PATH\n");
   }
    return (0);
}


/* FILLFILE PATH PATTERN NTIMES */ 
int dofillfile(int agc, char **agv)                                 /*__fn__*/
{
    PCFD out_fd;
    char  workbuf[255];
    word bufflen;    
    int ncopies;

    if (agc == 3)
    {
        ncopies = (int) tc_atoi( *(agv+2) );
        if (!ncopies)
        {
             tm_printf("NTIMES is Invalid., Check your pattern (try quotes)\n");
             return(0);
        }

        if ((out_fd = po_open(*agv,(word) (PO_BINARY|PO_WRONLY|PO_CREAT),(word) (PS_IWRITE | PS_IREAD) ) ) < 0)
        {
            tm_printf_2("Cant open %s\n", *agv);
            return(0);
        }
        tc_strcpy(workbuf, *(agv+1));
        tc_strcat(workbuf, "\r\n");
        bufflen = (word) tc_strlen(workbuf);
        
        while (ncopies--)
        {
            if (po_write(out_fd,(byte*)workbuf,(word)bufflen) != (int)bufflen)
            {
                tm_printf("Write failure\n");
                po_close(out_fd);
                return(0);
            }
        }
        po_close(out_fd);
        return(1);
    }
    else
    {
        tm_printf("Usage: FILLFILE PATH PATTERN int\n");
        return(0);
    }
}

/* STAT PATH */ 
int dostat(int agc, char **agv)                                    /*__fn__*/
{
struct stat st;
    if (agc == 1)
    {
        if (pc_stat(*agv, &st)==0)
        {
            tm_printf_3("DRIVENO: %02d SIZE: %7ld", st.st_dev, st.st_size);
            tm_printf_3(" DATE:%02d-%02d",(st.st_atime.date >> 5 ) & 0xf,/* Month */(st.st_atime.date & 0x1f)/* Day */);
            tm_printf_2("-%02d",80 +(st.st_atime.date >> 9) & 0xff); /* Year */
            tm_printf_3("  TIME:%02d:%02d\n",(st.st_atime.time >> 11) & 0x1f,/* Hour */(st.st_atime.time >> 5) & 0x3f); /* Minute */
            tm_printf_3("OPTIMAL BLOCK SIZE: %7ld FILE size (BLOCKS): %7ld\n",st.st_blksize,st.st_blocks);
            tm_printf("MODE BITS :");
            if (st.st_mode&S_IFDIR)
                tm_printf("S_IFDIR|");
            if (st.st_mode&S_IFREG)
                tm_printf("S_IFREG|");
            if (st.st_mode&S_IWRITE)
                tm_printf("S_IWRITE|");
            if (st.st_mode&S_IREAD)
                tm_printf("S_IREAD\n");
            tm_printf("\n");

             return (1);
        }
        else
        {
            tm_printf("FSTAT failed\n");
            return(0);
        }
    }
    tm_printf("Usage: FSTAT D:PATH\n");
    return (0);
}

/* FORMAT D:*/ 
void prompt_user(char *prompt, char *buf)
{
        tm_printf(prompt);
        tm_gets(buf);
}

int doformat(int agc, char **agv)                                    /*__fn__*/
{
char buf[10];
char working_buffer[100];
DDRIVE *pdr;
int driveno;
dword partition_list[3];
char path[10];
DEV_GEOMETRY geometry;


    prompt_user("Enter the drive to format as A:, B: etc ", path);
    driveno = pc_parse_raw_drive(path);
    if (driveno == -1 || !(pdr = pc_drno_to_drive_struct(driveno)))
    {
inval:
        prompt_user("Invalid drive Press return to exit", working_buffer);
        return(-1);
    }

    if ( !(pdr->drive_flags&DRIVE_FLAGS_VALID) )
        goto inval;

    //               int driveno, BOOLEAN ok_to_automount, BOOLEAN raw_access_requested, BOOLEAN call_crit_err
    // call it twice to clear change conditions
    if (!check_media(driveno, FALSE, TRUE, FALSE))
    if (!check_media(driveno, FALSE, TRUE, FALSE))
    {
        prompt_user("Check media failed. Press return to exit", working_buffer);
        return(-1);
    }

    /* This must be called before calling the later routines */
    if (!pc_get_media_parms(path, &geometry))
    {
        prompt_user("get media geometry failed. Press return to exit", working_buffer);
        return(-1);
    }

    /* Call the low level media format. Don't do this if formatting a 
       volume that is the second partition on the drive */
    prompt_user("Press Y to format media", buf);
    if (buf[0] == 'Y')
    {
        tm_printf("Calling media format\n");
        if (!pc_format_media(path, &geometry))
        {
           prompt_user("Media format failed press return to exit", working_buffer);
           return(-1);
        }
    }

    /* Partition the drive if it needs it */
    if ( pdr->drive_flags&DRIVE_FLAGS_PARTITIONED )
    {
        prompt_user("Press Y to partition media", buf);
        if (buf[0] == 'Y')
        {
			if (geometry.dev_geometry_lbas)
			{
				do
				{
	     			prompt_user("Press Y to USE LBA formatting, N to use CHS", buf);
				}
				while ( (buf[0] != 'Y') && (buf[0] != 'N') );

		        if (buf[0] == 'N')
        		{
					geometry.dev_geometry_lbas = 0;
				}
			}

			if (geometry.dev_geometry_lbas)
			{
	           tm_printf_2("The drive is contains %ld lbas\n", geometry.dev_geometry_lbas);
    	       prompt_user("Select the number of lbas for the first partition :", working_buffer);
        	   partition_list[0]  = (dword)tc_atol(working_buffer);
	           partition_list[1]  = 0;

    	       if (partition_list[0] != geometry.dev_geometry_lbas)
        	   {
            	   tm_printf_2("There are %ld lbas remaining \n", 
	                   geometry.dev_geometry_lbas - partition_list[0]);
    	           prompt_user("Select the number of lbas for the second partition :", working_buffer);
        	       partition_list[1]  = (dword)tc_atol(working_buffer);
				   partition_list[2]  = 0;
	            }
	           if ((partition_list[0] == 0) || ((dword)(partition_list[0]+partition_list[1])  > geometry.dev_geometry_lbas))
    	       {
        	       prompt_user("Bad input press return to exit", working_buffer);
            	    return(-1);
	            }
			}
			else
			{
        		tm_printf_2("The drive contains %d cylinders\n", geometry.dev_geometry_cylinders);
        		prompt_user("Select the number of cyls for the first partition :", working_buffer);
        		partition_list[0]  = (word)tc_atoi(working_buffer);
        		partition_list[1]  = 0;

        		if (partition_list[0] != geometry.dev_geometry_cylinders)
        		{
            		tm_printf_2("There are %d cylinders remaining \n", 
                		geometry.dev_geometry_cylinders - partition_list[0]);
            		prompt_user("Select the number of cyls for the second partition :", working_buffer);
            		partition_list[1]  = (dword)tc_atol(working_buffer);
					partition_list[2]  = 0;
        		}
	           if ((partition_list[0] == 0) || ((dword)(partition_list[0]+partition_list[1])  > geometry.dev_geometry_cylinders))
    	       {
        	       prompt_user("Bad input press return to exit", working_buffer);
            	    return(-1);
	            }
			}
            if (!pc_partition_media(path, &geometry, &partition_list[0]))
            {
               prompt_user("Media partition failed press return to exit", working_buffer);
               return(-1);
            }
        }
    }

    /* Put the DOS format */
    prompt_user("Press Y to format the volume", buf);
    if (buf[0] == 'Y')
    {

        if (!pc_format_volume(path, &geometry))
        {
           prompt_user("Format voulme failed press return to exit", working_buffer);
           return(-1);
        }
    }
    return (0);
}


/* GETATTR PATH*/ 
int dogetattr(int agc, char **agv)                                    /*__fn__*/
{
byte attr;

    if (agc == 1)
    {
        if (pc_get_attributes(*agv, &attr))
        {
            tm_printf("Attributes: ");
            if (attr & ARDONLY)
                tm_printf("ARDONLY|");
            if (attr & AHIDDEN)
                tm_printf("AHIDDEN|");
            if (attr & ASYSTEM)
                tm_printf("ASYSTEM|");
            if (attr & AVOLUME)
                tm_printf("AVOLUME|");
            if (attr & ADIRENT)
                tm_printf("ADIRENT|");
            if (attr & ARCHIVE)
                tm_printf("ARCHIVE|");
            if (attr == ANORMAL)
                tm_printf("NORMAL FILE (No bits set)");
            tm_printf("\n");
            return(0);
        }
        else
        {
            tm_printf("get attributes failed\n");
            return(0);
        }
    }
    tm_printf("Usage: GETATTR D:PATH\n");
    return (0);
}

/* GETATTR PATH*/ 
int dosetattr(int agc, char **agv)                                    /*__fn__*/
{
byte attr;

    attr = 0;
    if (agc == 2)
    {
        if (!pc_get_attributes(*agv, &attr))
        {
            tm_printf("Can't get attributes\n");
            return(0);
        }

        if (tc_strcmp(*(agv+1),"RDONLY")==0)
            attr |= ARDONLY;
        else if (tc_strcmp(*(agv+1),"HIDDEN")==0)
            attr |= AHIDDEN;
        else if (tc_strcmp(*(agv+1),"SYSTEM")==0)
            attr |= ASYSTEM;
        else if (tc_strcmp(*(agv+1),"ARCHIVE")==0)
            attr |= ARCHIVE;
        else if (tc_strcmp(*(agv+1),"NORMAL")==0)
            attr =  ANORMAL;
        else
            goto usage;

        if (pc_set_attributes(*agv, attr))
            return(0);
        else
        {
            tm_printf("Set attributes failed\n");
            return(0);
        }
    }
usage:
    tm_printf("Usage: SETATTR D:PATH RDONLY|HIDDEN|SYSTEM|ARCHIVE|NORMAL\n");

    return (0);
}

BOOLEAN pc_gets(int fd, char *buf)                                     /*__fn__*/
{
int i;
char c;
int ncopied = 0;
    
    /* We use ncopied to throw away any leading/ trailing newlines */
    *buf = '\0';

    for (i = 0; i < 80; i++)
    {
        if (po_read(fd, (byte*) &c, 1) != 1)
            return(FALSE);
        if (c == '\n' || c == '\r')
        {
            if (ncopied)
                return(TRUE);
        }
        else
        {
            *buf++ = c;
            *buf = '\0';
            ncopied += 1;
        }
    }
    return(FALSE);
}

/* Return 1 if buffer starts with the string in buffer */
int compare(char *constant, char *buffer)                           /*__fn__*/
{
    if (!*constant)
        return(0);

    while (*constant && *buffer == *constant)
    {
        buffer++;
        constant++;
    }
    if (!*constant)      /* If at \0 we found a match */
        return(1);
    else
        return(0);
}

/* Long to Decimal converter */    
/* Note dest buffer must hold at least 15 bytes */
void int_tostring(long num, char *dest)                              /*__fn__*/
{
    long digit;
    char *olddest;
    char *p;
    int base;

    olddest = dest;
    
    base = 10;

    dest += 15;    
    *dest = '\0';

    /* Convert num to a string going from dest[15] backwards */    
    /* Nasty little ItoA algorith */
    do
    {
        digit = num % base;
        *(--dest) =
          (char)(digit<10 ? (char)(digit + '0') : (char)((digit-10) + 'A'));
        num = num / base;
    }
    while (num);

    /* Now put the converted string at the beginning of the buffer */
    for (p = olddest; *dest;)
        *p++ = *dest++;
    *p = '\0';
}

⌨️ 快捷键说明

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