23 #include "sysconfig.h" 39 static char *fsize2str(t_size size)
41 static char szstr[SIZE_STR_LEN+1];
43 return size2str(szstr, size);
46 static char *fsize2lstr(
unsigned long size)
48 #define FSIZE_LSTR_LEN 10 49 static char szstr[FSIZE_LSTR_LEN+1];
51 tsnprintf(szstr, FSIZE_LSTR_LEN+1,
"%10ld", size);
58 static unsigned int now_time;
60 static char *fdate2str(t_time datetime)
62 #define FDATA_STR_LEN ((unsigned int)sizeof("HH:MM:DD")) 63 static char dtstr[FDATA_STR_LEN+1];
64 static t_time now_time;
68 unixtime.
sec = datetime;
72 if((datetime/(24*60*60)) == (now_time/(24*60*60))) {
73 tsprintf((
char *)dtstr,
"%02d:%02d:%02d",
78 tsprintf((
char *)dtstr,
"%02d/%02d/%02d",
87 static char *fdate2lstr(t_time datetime)
89 #define FDATA_LSTR_LEN ((unsigned int)sizeof("YYYY/MM/DD HH:MM:DD")) 90 static char dtstr[FDATA_LSTR_LEN+1];
94 unixtime.
sec = datetime;
98 tsnprintf(dtstr, FDATA_LSTR_LEN,
"%04d/%02d/%02d %02d:%02d:%02d",
109 static void print_fresult(
char *path, FRESULT fr)
138 case FR_INVALID_NAME:
150 case FR_INVALID_OBJECT:
154 case FR_WRITE_PROTECTED:
158 case FR_INVALID_DRIVE:
166 case FR_NO_FILESYSTEM:
170 case FR_MKFS_ABORTED:
182 case FR_NOT_ENOUGH_CORE:
186 case FR_TOO_MANY_OPEN_FILES:
187 tprintf(
"too many open files\n");
190 case FR_INVALID_PARAMETER:
191 tprintf(
"invalid parameter\n");
195 tprintf(
"undifined error(%d)\n", fr);
200 static unsigned long acc_size;
201 static unsigned short acc_files;
202 static unsigned short acc_dirs;
204 static int scan_files(
unsigned char* path,
unsigned int len)
216 if((finfo.fattrib & AM_DIR) != 0) {
219 (void)
strncopy(path+i+1, (
unsigned char *)&finfo.fname[0], len);
220 res = scan_files(path, len - i -1);
222 if (res != FR_OK)
break;
225 acc_size += finfo.fsize;
237 static int mount(
int argc,
uchar *argv[]);
245 .usage_str =
"[<drive> <device_name> [fsname]]" 248 static int mount(
int argc,
uchar *argv[])
254 int drv =
dstoi(argv[1]);
255 if(
mount_storage(drv, (
char *)argv[2], (
char *)argv[3]) == 0) {
256 tprintf(
"Drive %d: %s %s\n", drv, argv[2], argv[3]);
258 }
else if(argc > 2) {
259 int drv =
dstoi(argv[1]);
261 tprintf(
"Drive %d: %s\n", drv, argv[2]);
267 tprintf(
"%d: %8s %s\n", i, devname, fsname);
276 static int umount(
int argc,
uchar *argv[]);
284 .usage_str =
"<drive>" 287 static int umount(
int argc,
uchar *argv[])
293 drv =
dstoi(argv[1]);
296 print_command_usage(&com_file_umount);
304 static char defdrive[FF_MAX_LFN+1] =
"0:/";
305 #define FSECTSIZE FF_MIN_SS 307 static int diskfree(
int argc,
uchar *argv[]);
315 .usage_str =
"[drive]" 318 static int diskfree(
int argc,
uchar *argv[])
323 unsigned char *path = (
unsigned char *)defdrive;
326 path = (
unsigned char *)argv[1];
329 tprintf(
"Disk %s\n", (
char *)path);
331 acc_size = acc_files = acc_dirs = 0;
339 print_fresult((
char *)path, fr);
344 tprintf(
"getfree_file() fs = 0\n");
349 "Bytes/Cluster : %ld\n" 350 "Number of FATs : %ld\n" 351 "Root DIR entries : %ld\n" 352 "Sectors/FAT : %ld\n" 353 "FAT start (lba) : %ld\n" 354 "DIR start (lba,clustor) : %ld\n" 355 "Data start (lba) : %ld\n",
356 (
unsigned long)fs->fs_type,
357 (
unsigned long)fs->csize * FSECTSIZE,
358 (
unsigned long)fs->n_fats,
359 (
unsigned long)fs->n_rootdir,
360 (
unsigned long)fs->fsize,
361 (
unsigned long)fs->fatbase,
362 (
unsigned long)fs->dirbase,
363 (
unsigned long)fs->database
366 fr = scan_files(path, FF_MAX_LFN);
368 print_fresult((
char *)path, fr);
372 tprintf(
"%d files, %lu bytes (%s)\n" 379 fsize2str((
unsigned long)numcl * fs->csize * FSECTSIZE));
385 static int format(
int argc,
uchar *argv[]);
393 .usage_str =
"<drive>" 396 static int format(
int argc,
uchar *argv[])
402 print_command_usage(&com_format);
406 tprintf(
"Formatting drive %s...", argv[1]);
407 fr = mkfs_file((
unsigned char *)argv[1], FM_FAT32, FSECTSIZE);
411 print_fresult(path, fr);
421 #if FF_USE_CHMOD != 0 422 static int chmod(
int argc,
uchar *argv[]);
430 .usage_str =
"<file> <mode(0x01=RDO,0x02=HID,0x04=SYS,0x10=DIR,0x20=ARC)>" 433 static int chmod(
int argc,
uchar *argv[])
436 unsigned char mode = 0;
439 print_command_usage(&com_chmod);
443 mode =
hstoi(argv[2]);
444 fr = chmod_file(argv[1], mode);
446 print_fresult((
char *)argv[1], fr);
453 static int dir(
int argc,
uchar *argv[]);
461 .usage_str =
"[path]" 464 static int dir(
int argc,
uchar *argv[])
470 unsigned short s1, s2;
472 unsigned char *path = (
unsigned char *)defdrive;
474 unsigned char cstr[FF_MAX_LFN + 1];
477 finfo.fsize = FF_MAX_LFN;
482 path = (
unsigned char *)argv[1];
487 tprintf(
"Cannot open \"%s\"\n", path);
497 if((fr != FR_OK) || !finfo.fname[0]) {
498 print_fresult((
char *)path, fr);
501 if((finfo.fattrib & AM_DIR) != 0) {
508 XDUMP(0x01, (
unsigned char *)str,
strleng((
uchar *)str));
509 XDUMP(0x01, (
unsigned char *)cstr,
strleng(cstr));
510 tprintf(
"%c", ((finfo.fattrib & AM_DIR) != 0) ?
'D' :
'-');
512 fdate2str(finfo.fdatetime),
513 ((finfo.fattrib & AM_DIR) != 0) ?
" " : fsize2str(finfo.fsize),
518 tprintf(
"%4d File %s\n", (
int)s1, fsize2str(p1));
522 fsize2str((p1 * fs->csize/2)*1024));
533 static int dirv(
int argc,
uchar *argv[]);
541 .usage_str =
"[path]" 544 static int dirv(
int argc,
uchar *argv[])
550 unsigned short s1, s2;
552 unsigned char *path = (
unsigned char *)defdrive;
554 unsigned char cstr[FF_MAX_LFN + 1];
557 finfo.fsize = FF_MAX_LFN;
562 path = (
unsigned char *)argv[1];
567 tprintf(
"Cannot open \"%s\"\n", path);
577 if((fr != FR_OK) || !finfo.fname[0]) {
578 print_fresult((
char *)path, fr);
581 if((finfo.fattrib & AM_DIR) != 0) {
588 XDUMP(0x01, (
unsigned char *)str,
strleng((
uchar *)str));
589 XDUMP(0x01, (
unsigned char *)cstr,
strleng(cstr));
591 ((finfo.fattrib & AM_DIR) != 0) ?
'D' :
'-',
592 ((finfo.fattrib & AM_RDO) != 0) ?
'R' :
'-',
593 ((finfo.fattrib & AM_HID) != 0) ?
'H' :
'-',
594 ((finfo.fattrib & AM_SYS) != 0) ?
'S' :
'-',
595 ((finfo.fattrib & AM_ARC) != 0) ?
'A' :
'-');
597 fdate2lstr(finfo.fdatetime),
598 ((finfo.fattrib & AM_DIR) != 0) ?
" " : fsize2str(finfo.fsize),
599 ((finfo.fattrib & AM_DIR) != 0) ?
" " : fsize2lstr(finfo.fsize),
603 tprintf(
"%4d File %s\n", (
int)s1, fsize2str(p1));
607 fsize2str((p1 * fs->csize/2)*1024));
618 static int delete(
int argc,
uchar *argv[]);
626 .usage_str =
"<file_name>" 629 static int delete(
int argc,
uchar *argv[])
637 print_fresult((
char *)argv[1], fr);
640 print_command_usage(&com_file_delete);
648 #define FDSIZE FSECTSIZE 650 static int fdump(
int argc,
uchar *argv[]);
658 .usage_str =
"<file_name> [start [end]]" 661 static int fdump(
int argc,
uchar *argv[])
664 unsigned char fdbuf[16];
666 unsigned int ed = st + FDSIZE - 1;
670 print_command_usage(&com_file_fdump);
675 fd =
open_file((
unsigned char *)argv[1], FA_READ);
677 tprintf(
"Cannot open \"%s\"\n", argv[1]);
696 for(dp=st; dp<=ed; dp+=16) {
703 if(((ed+1) - dp) < 16) {
704 rlen = ((ed+1) - dp);
709 tprintf(
"Cannot read \"%s\"\n", argv[1]);
737 for(i=0; i<16; i++) {
739 if(((
' ' <= *p) && (*p <=
'Z'))
740 || ((
'a' <= *p) && (*p <=
'z'))) {
753 if(rd == ASCII_CTRL_C) {
767 static int operation(
int argc,
uchar *argv[]);
774 .command = operation,
775 .usage_str =
"<file_name>" 778 static int operation(
int argc,
uchar *argv[])
784 rt = do_file_operation((
unsigned char *)argv[1], argv[2]);
786 rt = do_file_operation((
unsigned char *)argv[1], 0);
789 print_command_usage(&com_file_operation);
798 static int batch(
int argc,
uchar *argv[]);
806 .usage_str =
"<file_name>" 809 static int batch(
int argc,
uchar *argv[])
816 print_command_usage(&com_file_batch);
823 #ifdef GSC_SHELL_USE_FWTEST // $gsc ファイル書き込みテストコマンド(fwtest)を有効にする 824 static int fwtest(
int argc,
uchar *argv[]);
835 #define FWNAME "fwtest.dat" 837 static int fwtest(
int argc,
uchar *argv[])
842 static unsigned char wbuf[FWSIZE];
846 for(i=0; i<FWSIZE; i++) {
847 wbuf[i] = (i & 0xff);
855 fd =
open_file(fname, FA_WRITE | FA_CREATE_ALWAYS);
857 tprintf(
"File open error \"%s\"\n", fname);
862 tprintf(
"File write error(%d)\n", rt);
880 #if FF_USE_CHMOD != 0 889 #ifdef GSC_SHELL_USE_FWTEST 897 .manual_str =
"File strage operation commands",
898 .sublist = com_file_list
static const struct st_shell_command com_file_dirv
ドライブのファイルリスト詳細を表示する
unsigned int fattime(void)
FAT 現在実時間を取得する
unsigned char uchar
GadgetSeedの文字(列)は unsigned char 型となる
static const struct st_shell_command com_file_mount
デバイスをマウントする
static const struct st_shell_command com_file_batch
バッチファイルを実行する
static const struct st_shell_command com_file_fdump
ファイルの内容をダンプ表示する
t_ssize seek_file(int fd, t_ssize offset, int whence)
ファイルアクセス位置の設定
static const struct st_shell_command com_file_operation
ファイルをアプリケーションで実行する
int unmount_storage(int drvno)
ストレージデバイスをアンマウントする
int get_storage_device_name(int drv, char **devname, char **fsname)
マウントされているデバイス名を取得する
int cgetcnw(unsigned char *rd)
標準入力より1文字を取得する(待ち無し)
t_ssize write_file(int fd, const void *buf, t_size count)
ファイルにデータを書き込む
int close_file(int fd)
ファイルを閉じる
FS_DIR * opendir_file(const uchar *name)
ディレクトリを開く
static const struct st_shell_command com_file_umount
デバイスをアンマウントする
int closedir_file(FS_DIR *dir)
ディレクトリを閉じる
static const struct st_shell_command com_file_delete
ファイルを削除する
unsigned int hstou(uchar *str)
16進数文字列 unsigned int 変換
int mount_storage(int drvno, const char *devname, const char *fsname)
ストレージデバイスをマウントする
int dstoi(uchar *str)
10進数文字列 int 変換
int open_file(const uchar *path, int flags)
ファイルを開く
unsigned int strleng(const uchar *str)
文字列長
int tsprintf(char *str, const char *fmt,...)
簡易sprintf
void unixtime_to_datetime(struct st_datetime *datetime, struct st_systime *unixtime)
UNIX時間より時刻を求める
int cputc(unsigned char td)
標準出力より1文字を出力する
int tprintf(const char *fmt,...)
簡易printf
static const struct st_shell_command com_file_diskfree
ドライブの空き容量を表示する
uchar * sjisstr_to_utf8str(uchar *utf8str, uchar *sjisstr, unsigned int count)
SJIS 文字列から UTF-8 文字列へ変換
int readdir_file(FS_DIR *dir, FS_FILEINFO *finfo)
ディレクトリを読み出す
#define GSC_FS_VOLUME_NUM
$gsc 最大ストレージデバイスボリューム数
uchar * strncopy(uchar *dest, const uchar *src, unsigned int n)
文字列コピー
int hstoi(uchar *str)
16進数文字列 int 変換
int exec_batch(uchar *path)
バッチファイルを実行する
int getfree_file(const uchar *path, unsigned long *sect, void **fs)
論理ドライブの未使用クラスタ数を取得する
t_ssize read_file(int fd, void *buf, t_size count)
ファイルからデータを読み出す
#define SEEK_END
ファイルサイズに加算
static const struct st_shell_command com_file_dir
ドライブのファイルリストを表示する
int unlink_file(const uchar *path)
ファイルを消去する
int tsnprintf(char *str, unsigned int size, const char *fmt,...)
簡易snprintf