📄 vfsutil.c
字号:
char mode[FILENAMEMAX + 1];
/* scan out the index, file name and mode to pass to vfopen() */
arg1 = nextarg(((GEN_IO) pio)->inbuf);
if (arg1)
{
arg2 = nextarg(arg1);
if (arg2)
arg3 = nextarg(arg2);
}
/* if three args are not present, tell the user how to do the command */
if (!arg3 || !*arg3)
{
ns_printf(pio,"usage:vfsvfopen <index> <file name> <mode>\n");
return 1;
}
/* get and verify index */
if (vfs_unit_scan_index(pio,arg1,&index))
return 1;
/* get and verify file_name */
if (vfs_unit_scan_file_name(pio,arg2,file_name))
return 1;
/* get and verify mode */
if (vfs_unit_scan_file_name(pio,arg3,mode))
return 1;
ns_printf(pio,"calling vfopen(%s,%s) index 0x%x\n",file_name,mode,index);
vfd = vfopen(file_name,mode);
ns_printf(pio,"vfopen() returned %p\n",vfd);
ns_printf(pio,"get_vfopen_error() returned %d\n",get_vfopen_error());
vfs_unit_test_fds[index] = vfd;
return 0;
}
/* FUNCTION: vfs_unit_vfclose()
*
* PARAM1: void *pio
*
* RETURNS:
*/
int vfs_unit_vfclose(void * pio)
{
char * arg1;
unsigned int index;
/* scan out the index */
arg1 = nextarg(((GEN_IO) pio)->inbuf);
/* if arg not present, tell the user how to do the command */
if (!arg1 || !*arg1)
{
ns_printf(pio,"usage:vfsvfclose <index>\n");
return 1;
}
/* get and verify index */
if (vfs_unit_scan_index(pio,arg1,&index))
return 1;
ns_printf(pio,"calling vfclose(%p) index 0x%x\n",
vfs_unit_test_fds[index],index);
vfclose(vfs_unit_test_fds[index]);
vfs_unit_test_fds[index] = 0;
return 0;
}
/* FUNCTION: vfs_unit_vunlink()
*
* PARAM1: void *pio
*
* RETURNS:
*/
int vfs_unit_vunlink(void * pio)
{
char * arg1;
int rc;
char file_name[FILENAMEMAX + 1];
/* scan out the file name */
arg1 = nextarg(((GEN_IO) pio)->inbuf);
/* if arg not present, tell the user how to do the command */
if (!arg1 || !*arg1)
{
ns_printf(pio,"usage:vfsvunlink <file name>\n");
return 1;
}
/* get and verify file_name */
if (vfs_unit_scan_file_name(pio,arg1,file_name))
return 1;
ns_printf(pio,"calling vunlink(%s)\n",file_name);
rc = vunlink(file_name);
ns_printf(pio,"vunlink() returned %d\n",rc);
return 0;
}
/* FUNCTION: vfs_unit_vfread()
*
* PARAM1: void *pio
*
* RETURNS:
*/
int vfs_unit_vfread(void * pio)
{
char * arg1;
char * arg2 = NULL;
unsigned int index;
unsigned int count;
int rc;
char in_buf[256];
/* scan out the index and count */
arg1 = nextarg(((GEN_IO) pio)->inbuf);
if (arg1)
{
arg2 = nextarg(arg1);
}
/* if two args are not present, tell the user how to do the command */
if (!arg2 || !*arg2)
{
ns_printf(pio,"usage:vfsvfread <index> <count>\n");
return 1;
}
/* get and verify index */
if (vfs_unit_scan_index(pio,arg1,&index))
return 1;
/* get byte count to read */
count = atoh(arg2);
if (count > sizeof(in_buf))
{
ns_printf(pio,"bad count 0x%x\n",count);
return 1;
}
ns_printf(pio,"calling vfread() of 0x%x bytes fd %p\n",
count,vfs_unit_test_fds[index]);
rc = vfread(in_buf,1,count,vfs_unit_test_fds[index]);
ns_printf(pio,"vfread() returned %d\n",rc);
hexdump(pio,in_buf,count);
return 0;
}
/* FUNCTION: vfs_unit_vfwrite()
*
* PARAM1: void *pio
*
* RETURNS:
*/
int vfs_unit_vfwrite(void * pio)
{
char * arg1;
char * arg2 = NULL;
unsigned int index;
int count;
unsigned int line_len;
unsigned long byte_count = 0;
int i;
int len;
int rc;
char out_buf[30];
/* scan out the index and count */
arg1 = nextarg(((GEN_IO) pio)->inbuf);
if (arg1)
{
arg2 = nextarg(arg1);
}
/* if two args are not present, tell the user how to do the command */
if (!arg2 || !*arg2)
{
ns_printf(pio,"usage:vfsvfwrite <index> <count>\n");
return 1;
}
/* get and verify index */
if (vfs_unit_scan_index(pio,arg1,&index))
return 1;
/* get line count to write */
count = (int) atoh(arg2);
ns_printf(pio,"calling vfwrite() of 0x%x lines fd %p\n",
count,vfs_unit_test_fds[index]);
for (i = 0; i < count; i++)
{
sprintf_t(out_buf,"line number = %x ",i);
len = strlen(out_buf);
/* pad out buffer to constant length */
for (; len < 24; len++)
{
out_buf[len] = (char) ('A' + ((i + len) % 26));
}
out_buf[len] = 0;
line_len = strlen(out_buf);
rc = vfwrite(out_buf,1,line_len,vfs_unit_test_fds[index]);
if (rc != (int) line_len)
{
ns_printf(pio,"vfwrite() returned %d\n",rc);
break;
}
byte_count += line_len;
}
ns_printf(pio,"%ld (0x%lx) bytes written\n",byte_count,byte_count);
return 0;
}
/* FUNCTION: vfs_unit_vfseek()
*
* PARAM1: void *pio
*
* RETURNS:
*/
int vfs_unit_vfseek(void * pio)
{
char * arg1;
char * arg2 = NULL;
char * arg3 = NULL;
unsigned int index;
unsigned long offset;
unsigned int mode;
int rc;
/* scan out the index, offset and mode */
arg1 = nextarg(((GEN_IO) pio)->inbuf);
if (arg1)
{
arg2 = nextarg(arg1);
if (arg2)
arg3 = nextarg(arg2);
}
/* if three args are not present, tell the user how to do the command */
if (!arg3 || !*arg3)
{
ns_printf(pio,"usage:vfsfseek <index> <offset> <mode>\n");
return 1;
}
/* get and verify index */
if (vfs_unit_scan_index(pio,arg1,&index))
return 1;
/* get offset and mode */
offset = atohl(arg2);
mode = atoh(arg3);
ns_printf(pio,"calling vfseek(%p,0x%lx,0x%x)\n",
vfs_unit_test_fds[index],offset,mode);
rc = vfseek(vfs_unit_test_fds[index],offset,mode);
ns_printf(pio,"vfseek() returned %d\n",rc);
return 0;
}
/* FUNCTION: vfs_unit_vftell()
*
* PARAM1: void *pio
*
* RETURNS:
*/
int vfs_unit_vftell(void * pio)
{
char * arg1;
unsigned int index;
long rc;
/* scan out the index, offset and mode */
arg1 = nextarg(((GEN_IO) pio)->inbuf);
/* if arg not present, tell the user how to do the command */
if (!arg1 || !*arg1)
{
ns_printf(pio,"usage:vfsftell <index>\n");
return 1;
}
/* get and verify index */
if (vfs_unit_scan_index(pio,arg1,&index))
return 1;
ns_printf(pio,"calling vftell(%p)\n",vfs_unit_test_fds[index]);
rc = vftell(vfs_unit_test_fds[index]);
ns_printf(pio,"vftell() returned %ld\n",rc);
return 0;
}
/* FUNCTION: vfs_unit_vgetc()
*
* PARAM1: void *pio
*
* RETURNS:
*/
int vfs_unit_vgetc(void * pio)
{
char * arg1;
char * arg2 = NULL;
unsigned int index;
unsigned int count;
unsigned int i;
int rc;
char in_buf[256];
/* scan out the index and count */
arg1 = nextarg(((GEN_IO) pio)->inbuf);
if (arg1)
{
arg2 = nextarg(arg1);
}
/* if two args are not present, tell the user how to do the command */
if (!arg2 || !*arg2)
{
ns_printf(pio,"usage:vfsvgetc <index> <count>\n");
return 1;
}
/* get and verify index */
if (vfs_unit_scan_index(pio,arg1,&index))
return 1;
/* get byte count to read */
count = atoh(arg2);
if (count > sizeof(in_buf))
{
ns_printf(pio,"bad count 0x%x\n",count);
return 1;
}
ns_printf(pio,"calling vgetc() of 0x%x times on fd %p\n",
count,vfs_unit_test_fds[index]);
for (i = 0; i < count; ++i)
{
rc = vgetc(vfs_unit_test_fds[index]);
if (rc == EOF)
break;
in_buf[i] = (char) rc;
}
ns_printf(pio,"%d (0x%x) bytes read\n",i,i);
hexdump(pio,in_buf,i);
return 0;
}
/* FUNCTION: vfs_unit_vferror()
*
* PARAM1: void *pio
*
* RETURNS:
*/
int vfs_unit_vferror(void * pio)
{
char * arg1;
unsigned int index;
int rc;
/* scan out the index, offset and mode */
arg1 = nextarg(((GEN_IO) pio)->inbuf);
/* if arg not present, tell the user how to do the command */
if (!arg1 || !*arg1)
{
ns_printf(pio,"usage:vfsferror <index>\n");
return 1;
}
/* get and verify index */
if (vfs_unit_scan_index(pio,arg1,&index))
return 1;
ns_printf(pio,"calling vferror(%p)\n",vfs_unit_test_fds[index]);
rc = vferror(vfs_unit_test_fds[index]);
ns_printf(pio,"vferror() returned %d\n",rc);
return 0;
}
/* FUNCTION: vfs_unit_vclearerr()
*
* PARAM1: void *pio
*
* RETURNS:
*/
int vfs_unit_vclearerr(void * pio)
{
char * arg1;
unsigned int index;
/* scan out the index, offset and mode */
arg1 = nextarg(((GEN_IO) pio)->inbuf);
/* if arg not present, tell the user how to do the command */
if (!arg1 || !*arg1)
{
ns_printf(pio,"usage:vfsclearerr <index>\n");
return 1;
}
/* get and verify index */
if (vfs_unit_scan_index(pio,arg1,&index))
return 1;
ns_printf(pio,"calling vclearerr(%p)\n",vfs_unit_test_fds[index]);
vclearerr(vfs_unit_test_fds[index]);
return 0;
}
extern int vfs_log_file_name;
/* FUNCTION: vfs_tog_log_file_name()
*
* PARAM1: void *pio
*
* RETURNS:
*/
int vfs_tog_log_file_name(void * pio)
{
vfs_log_file_name = !vfs_log_file_name;
ns_printf(pio,"file name logging is %s\n",
vfs_log_file_name ? "on" : "off");
return 0;
}
#ifdef AMD_NET186
/* defined in net186 flash.c */
void PostLEDs(unsigned char value);
/* FUNCTION: vfs_led_test()
*
* PARAM1: void *pio
*
* RETURNS:
*/
int vfs_led_test(void * pio)
{
char * arg1;
unsigned int value;
/* scan out the value */
arg1 = nextarg(((GEN_IO) pio)->inbuf);
/* if arg not present, tell the user how to do the command */
if (!arg1 || !*arg1)
{
ns_printf(pio,"usage:vfsled <LED value>\n");
return 1;
}
/* get line count to write */
value = atoh(arg1);
ns_printf(pio,"calling PostLEDs(0x%x)\n",value);
PostLEDs((unsigned char) (value & 0xff));
return 0;
}
#endif /* AMD_NET186 */
#endif /* VFS_UNIT_TEST */
struct menu_op vfs_menu[] =
{
"vfs", stooges, "VFS commands",
"vfsfilelist", vfs_file_list, "display vfs_file structure info",
#ifdef HT_RWVFS
"vfssetflag", vfs_set_flag, "set bit in vfs_file flags field",
"vfsclearflag", vfs_clear_flag, "clear bit in vfs_file flags field",
#ifdef HT_SYNCDEV
"vfssync", vfs_do_sync, "sync the VFS to backing store",
#endif
#endif /* HT_RWVFS */
"vfsopenlist", vfs_open_list, "list currently open VFS files",
#ifdef VFS_UNIT_TEST
"vfsunitlist", vfs_unit_list, "list unit test VFILE array",
"vfsvfopen", vfs_unit_vfopen, "vfsvfopen <index> <file name> <mode>",
"vfsvfclose", vfs_unit_vfclose, "vfsvfclose <index>",
"vfsvunlink", vfs_unit_vunlink, "vfsvunlink <file name>",
"vfsvfread", vfs_unit_vfread, "vfsvfread <index> <count>",
"vfsvfwrite", vfs_unit_vfwrite, "vfsvfwrite <index> <count>",
"vfsvfseek", vfs_unit_vfseek, "vfsvfseek <index> <offset> <mode>",
"vfsvftell", vfs_unit_vftell, "vfsvftell <index>",
"vfsvgetc", vfs_unit_vgetc, "vfsvgetc <index> <count>",
"vfsvferror", vfs_unit_vferror, "vfsferror <index>",
"vfsvclearerr", vfs_unit_vclearerr, "vfsclearerr <index>",
"vfslogname", vfs_tog_log_file_name, "toggle display of passed file names",
#ifdef AMD_NET186
"vfsled", vfs_led_test, "vfsled <led value>",
#endif /* AMD_NET186 */
#endif /* VFS_UNIT_TEST */
NULL
};
#endif /* IN_MENUS */
/* FUNCTION: vfs_init()
*
* PARAM1:
*
* RETURNS:
*/
void vfs_init()
{
#ifdef HT_SYNCDEV /* Do we support sync to flash device? */
#ifdef HT_RWVFS
vfs_lock();
/* restore the RAM resident VFS from whatever backing store has
been provided */
vfs_restore();
vfs_unlock();
#endif /* HT_RWVFS */
#endif /* HT_SYNCDEV */
#ifdef INCLUDE_NVPARMS
strncpy(vfs_root_path, vfs_nvparms.httppath, HTPATHMAX);
#endif /* INCLUDE_NVPARMS */
}
#endif /* VFS_FILES */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -