📄 tstsh.c
字号:
}
/* LSTOPEN */
int dolstop(int agc, char **agv) /*__fn__*/
{
int i;
ARGSUSED_INT(agc);
ARGSUSED_PVOID((PFVOID)agv);
for (i = 0 ; i < MAXRND; i++)
{
if (rnds[i].fd != -1)
tm_printf_3("%i: %s\n",rnds[i].fd,rnds[i].name);
}
return (1);
}
/* MKDIR PATH */
int domkdir(int agc, char **agv) /*__fn__*/
{
if (agc == 1)
{
if (pc_mkdir(*agv))
return (1);
else
return(0);
}
tm_printf("Usage: MKDIR D:PATH\n");
return (0);
}
/* RMDIR PATH */
int dormdir(int agc, char **agv) /*__fn__*/
{
if (agc == 1)
{
if (pc_rmdir(*agv))
return (1);
else
return(0);
}
tm_printf("Usage: RMDIR D:PATH\n");
return (0);
}
/* DELTREE PATH */
int dodeltree(int agc, char **agv) /*__fn__*/
{
if (agc == 1)
{
if (pc_deltree(*agv))
return (1);
else
return(0);
}
tm_printf("Usage: DELTREE D:PATH\n");
return (0);
}
/* DELETE PATH */
char rmfil[EMAXPATH];
char rmpath[EMAXPATH];
char tfile[EMAXPATH];
int dorm(int agc, char **agv) /*__fn__*/
{
DSTAT statobj;
if (agc == 1)
{
/* Get the path */
tc_strcpy(&rmfil[0],*agv);
if (pc_gfirst(&statobj, &rmfil[0]))
{
do
{
/* Construct the path to the current entry */
pc_mfile((byte*) &tfile[0],(byte*) &statobj.fname[0], (byte*) &statobj.fext[0]);
pc_mpath((byte*)&rmpath[0],(byte*) &statobj.path[0],(byte*)&tfile[0] );
if (!pc_isdir(rmpath) && !pc_isvol(rmpath))
{
tm_printf_2("deleting --> %s\n",rmpath);
if (!pc_unlink( rmpath ) )
tm_printf_2("Can not delete:%s\n",rmpath);
}
} while(pc_gnext(&statobj));
pc_gdone(&statobj);
}
return(1);
}
tm_printf("Usage: DELETE D:PATH\n");
return(0);
}
/* RENAME PATH NEWNAME */
int domv(int agc, char **agv) /*__fn__*/
{
if (agc == 2)
{
if (pc_mv(*agv , *(agv+1) ))
return (1);
else
return(0);
}
tm_printf("Usage: RENAME PATH NEWNAME \n");
return (0);
}
/* CD PATH */
int docwd(int agc, char **agv) /*__fn__*/
{
char lbuff[100];
if (agc == 1)
{
if (pc_set_cwd(*agv))
return(1);
else
{
tm_printf("?\n");
return(0);
}
}
else
{
if (pc_pwd(*agv,lbuff))
{
tm_printf_2("%s\n", lbuff);
return(1);
}
else
{
tm_printf("?\n");
return(0);
}
}
}
/* DIR PATH */
int dols(int agc, char **agv) /*__fn__*/
{
int fcount;
char *ppath;
dword blocks_total, blocks_free;
dword nfree;
ppath = 0;
if (agc == 1)
ppath = *agv;
else
{
/* get the working dir of the default dir */
if (pc_pwd("",(char *)shell_buf))
{
ppath = (char *)shell_buf;
/* If not the root add a \\ */
if (!(ppath[1] == '\\' && ppath[2] == '\0'))
tc_strcat(ppath, "\\");
#if (VFAT)
tc_strcat(ppath, "*");
#else
tc_strcat(ppath, "*.*");
#endif
}
}
/* These two lines added to make DIR A: display DIR A:*.* */
if (ppath[1] == ':' && ppath[2] == '\0')
tc_strcat(ppath,"*.*");
if (ppath)
{
/* ======================================== */
/* These two lines added to make DIR A: display DIR A:*.* */
if (ppath[1] == ':' && ppath[2] == '\0')
tc_strcat(ppath,"*.*");
/* End.. of change */
/* ======================================== */
/* Now do the dir */
fcount = pc_seedir(ppath);
/* And print the bytes remaining */
nfree = pc_free(ppath, &blocks_total, &blocks_free);
tm_printf_3(" %-6d File(s) %-8ld KBytes free\n", fcount,\
blocks_free/2 );
}
else
tm_printf("Usage: DIR PATH\n");
return(1);
}
/* List directory, and return number of matching file */
/* List directory, and return number of matching file */
/* List directory, and return number of matching file */
int pc_seedir(char *path) /*__fn__*/
{
char *dirstr;
int fcount = 0;
DSTAT statobj;
/* Get the first match */
if (pc_gfirst(&statobj, path))
{
while (TRUE)
{
fcount++;
if (statobj.fattribute & AVOLUME)
dirstr = "<VOL>";
else if (statobj.fattribute & ADIRENT)
dirstr = "<DIR>";
else
dirstr = " ";
tm_printf_3("%-8s.%-3s", &(statobj.fname[0]), &(statobj.fext[0]));
tm_printf_3(" %10ld %5s", statobj.fsize, dirstr);
tm_printf_2(" %02d",(statobj.fdate >> 5 ) & 0xf); /* Month */
tm_printf_2("-%02d",(statobj.fdate & 0x1f)); /* Day */
tm_printf_2("-%02d",80 +(statobj.fdate >> 9) & 0xff); /* Year */
tm_printf_2(" %02d",(statobj.ftime >> 11) & 0x1f); /* Hour */
tm_printf_2(":%02d",(statobj.ftime >> 5) & 0x3f); /* Minute */
#if (VFAT)
tm_printf_2(" - %s\n", statobj.lfname);
#else
tm_printf(" \n");
#endif
/* Get the next */
if (!pc_gnext(&statobj))
break;
}
/* Call gdone to free up internal resources used by statobj */
pc_gdone(&statobj);
}
return(fcount);
}
/* CAT PATH */
int docat(int agc, char **agv) /*__fn__*/
{
PCFD fd;
int nread;
if (agc == 1)
{
if ((fd = po_open(*agv, (word)(PO_BINARY|PO_RDONLY),(word) (PS_IWRITE | PS_IREAD) ) ) < 0)
{
tm_printf_2("Cant open %s\n", *agv);
return(0);
}
else
{
do
{
nread = po_read(fd,(byte*)shell_buf,512);
shell_buf[nread] = '\0';
tm_printf((char *)shell_buf);
}while(nread > 0);
po_close(fd);
return(1);
}
}
else
{
tm_printf("Usage: CAT PATH\n");
return(0);
}
}
#if (INCLUDE_CHKDSK)
void check_disk(char *drive_id, int write_chains);
/* */
int dochkdsk(int agc, char **agv) /*__fn__*/
{
int write_chains;
if (agc != 2)
{
tm_printf("Usage: CHKDSK DRIVE: WRITECHAINS\n");
tm_printf("Example:CHKDSK A: 1\n");
tm_printf("Runs chkdsk on A: writes lost chains\n");
tm_printf("Example:CHKDSK A: 0\n");
tm_printf("Runs chkdsk on A: does not write lost chains\n");
return(0);
}
write_chains = (int) tc_atoi( *(agv+1) );
check_disk(*agv, write_chains);
return(0);
}
#endif
/* CAT PATH */
int dochsize(int agc, char **agv) /*__fn__*/
{
PCFD fd;
long newsize;
if (agc == 2)
{
if ((fd = po_open(*agv, (word)(PO_BINARY|PO_WRONLY),(word) (PS_IWRITE | PS_IREAD) ) ) < 0)
{
tm_printf_2("Cant open %s\n", *agv);
return(0);
}
newsize = tc_atol( *(agv+1) );
if (po_chsize(fd, newsize) != 0)
tm_printf("Change size function failed\n");
po_close(fd);
return(1);
}
else
{
tm_printf("Usage: CHSIZE PATH NEWSIZE\n");
return(0);
}
}
/* COPY PATH PATH */
int docopy(int agc, char **agv) /*__fn__*/
{
PCFD in_fd;
PCFD out_fd;
word nread;
BOOLEAN forever = TRUE; /* use this for while(forever) to quiet anal compilers */
if (agc == 2)
{
if ((in_fd = po_open(*agv,(word) (PO_BINARY|PO_RDONLY),(word) (PS_IWRITE | PS_IREAD) ) ) < 0)
{
tm_printf_2("Cant open %s\n", *agv);
return(0);
}
if ((out_fd = po_open(*(agv+1),(word) (PO_BINARY|PO_WRONLY|PO_CREAT),(word) (PS_IWRITE | PS_IREAD) ) ) < 0)
{
tm_printf_2("Cant open %s\n", *(agv+1));
return(0);
}
while (forever)
{
nread = (word)po_read(in_fd,(byte*)shell_buf, 1024);
if (nread > 0 && nread != (word)~0)
{
if (po_write(out_fd,(byte*)shell_buf,(word)nread) != (int)nread)
{
tm_printf("Write failure\n");
break;
}
}
else
break;
}
po_close(in_fd);
po_close(out_fd);
return(1);
}
else
{
tm_printf("Usage: COPY FROMPATH TOPATH\n");
return(0);
}
}
/* 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)
{
#if defined(ERTFS_SA)
tm_printf(prompt);
tm_gets(buf);
#else
tm_cputs(prompt);
tm_gets(buf);
#endif
}
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')
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -