GadgetSeed  0.9.6
com_file.c
[詳解]
1 /** @file
2  @brief ファイル操作コマンド
3 
4  @date 2007.07.14
5  @author Takashi SHUDO
6 
7  @section file_command fileコマンド
8 
9  file コマンドには以下のサブコマンドがあります。
10 
11  | サブコマンド | 機能 | 詳細 |
12  |:------------------|:------------------------------|:----------------------|
13  | mount | @copybrief com_file_mount | @ref com_file_mount |
14  | umount | @copybrief com_file_umount | @ref com_file_umount |
15  | free | @copybrief com_file_diskfree | @ref com_file_diskfree |
16  | dir | @copybrief com_file_dir | @ref com_file_dir |
17  | delete | @copybrief com_file_delete | @ref com_file_delete |
18  | fdump | @copybrief com_file_fdump | @ref com_file_fdump |
19  | operation | @copybrief com_file_operation | @ref com_file_operation |
20  | batch | @copybrief com_file_batch | @ref com_file_batch |
21 */
22 
23 #include "sysconfig.h"
24 #include "shell.h"
25 #include "device.h"
26 #include "fs.h"
27 #include "str.h"
28 #include "tprintf.h"
29 #include "tkprintf.h"
30 
31 #include "storage.h"
32 #include "file.h"
33 #include "charcode.h"
34 
35 //#define DEBUGTBITS 0x01
36 #include "dtprintf.h"
37 
38 
39 static char *fsize2str(t_size size)
40 {
41  static char szstr[SIZE_STR_LEN+1];
42 
43  return size2str(szstr, size);
44 }
45 
46 static char *fsize2lstr(unsigned long size)
47 {
48 #define FSIZE_LSTR_LEN 10
49  static char szstr[FSIZE_LSTR_LEN+1];
50 
51  tsnprintf(szstr, FSIZE_LSTR_LEN+1, "%10ld", size);
52 
53  return &szstr[0];
54 }
55 
56 #include "datetime.h"
57 
58 static unsigned int now_time;
59 
60 static char *fdate2str(t_time datetime)
61 {
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;
65  struct st_systime unixtime;
66  struct st_datetime dt;
67 
68  unixtime.sec = datetime;
69  unixtime.usec = 0;
70  unixtime_to_datetime(&dt, &unixtime);
71 
72  if((datetime/(24*60*60)) == (now_time/(24*60*60))) {
73  tsprintf((char *)dtstr, "%02d:%02d:%02d",
74  dt.hour,
75  dt.min,
76  dt.sec);
77  } else {
78  tsprintf((char *)dtstr, "%02d/%02d/%02d",
79  dt.year - 2000,
80  dt.month,
81  dt.day);
82  }
83 
84  return &dtstr[0];
85 }
86 
87 static char *fdate2lstr(t_time datetime)
88 {
89 #define FDATA_LSTR_LEN ((unsigned int)sizeof("YYYY/MM/DD HH:MM:DD"))
90  static char dtstr[FDATA_LSTR_LEN+1];
91  struct st_systime unixtime;
92  struct st_datetime dt;
93 
94  unixtime.sec = datetime;
95  unixtime.usec = 0;
96  unixtime_to_datetime(&dt, &unixtime);
97 
98  tsnprintf(dtstr, FDATA_LSTR_LEN, "%04d/%02d/%02d %02d:%02d:%02d",
99  dt.year,
100  dt.month,
101  dt.day,
102  dt.hour,
103  dt.min,
104  dt.sec);
105 
106  return &dtstr[0];
107 }
108 
109 static void print_fresult(char *path, FRESULT fr)
110 {
111  tprintf("%s ", path);
112 
113  switch(fr) {
114  case FR_OK: /* 0 */
115  tprintf("OK\n");
116  break;
117 
118  case FR_DISK_ERR: /* 1 */
119  tprintf("disk error\n");
120  break;
121 
122  case FR_INT_ERR: /* 2 */
123  tprintf("int error\n");
124  break;
125 
126  case FR_NOT_READY: /* 3 */
127  tprintf("not ready\n");
128  break;
129 
130  case FR_NO_FILE: /* 4 */
131  tprintf("no file\n");
132  break;
133 
134  case FR_NO_PATH: /* 5 */
135  tprintf("no path\n");
136  break;
137 
138  case FR_INVALID_NAME: /* 6 */
139  tprintf("invalid name\n");
140  break;
141 
142  case FR_DENIED: /* 7 */
143  tprintf("denied\n");
144  break;
145 
146  case FR_EXIST: /* 8 */
147  tprintf("exist\n");
148  break;
149 
150  case FR_INVALID_OBJECT: /* 9 */
151  tprintf("invalid object\n");
152  break;
153 
154  case FR_WRITE_PROTECTED:/* 10 */
155  tprintf("Write protected\n");
156  break;
157 
158  case FR_INVALID_DRIVE: /* 11 */
159  tprintf("invalid drive\n");
160  break;
161 
162  case FR_NOT_ENABLED: /* 12 */
163  tprintf("not enabled\n");
164  break;
165 
166  case FR_NO_FILESYSTEM: /* 13 */
167  tprintf("no filesystem\n");
168  break;
169 
170  case FR_MKFS_ABORTED: /* 14 */
171  tprintf("mkfs aborted\n");
172  break;
173 
174  case FR_TIMEOUT: /* 15 */
175  tprintf("timeout\n");
176  break;
177 
178  case FR_LOCKED: /* 16 */
179  tprintf("locked\n");
180  break;
181 
182  case FR_NOT_ENOUGH_CORE:/* 17 */
183  tprintf("not enough core\n");
184  break;
185 
186  case FR_TOO_MANY_OPEN_FILES:/* 18 */
187  tprintf("too many open files\n");
188  break;
189 
190  case FR_INVALID_PARAMETER:/* 19 */
191  tprintf("invalid parameter\n");
192  break;
193 
194  default:
195  tprintf("undifined error(%d)\n", fr);
196  break;
197  }
198 }
199 
200 static unsigned long acc_size;
201 static unsigned short acc_files;
202 static unsigned short acc_dirs;
203 
204 static int scan_files(unsigned char* path, unsigned int len)
205 {
206  FS_DIR *dir;
207  FS_FILEINFO finfo;
208  int res = 0;
209  int i;
210 
211  dir = opendir_file(path);
212  if(dir != 0) {
213  i = strleng(path);
214  while(((res = readdir_file(dir, &finfo)) == FR_OK) &&
215  finfo.fname[0]) {
216  if((finfo.fattrib & AM_DIR) != 0) {
217  acc_dirs++;
218  *(path+i) = '/';
219  (void)strncopy(path+i+1, (unsigned char *)&finfo.fname[0], len);
220  res = scan_files(path, len - i -1);
221  *(path+i) = '\0';
222  if (res != FR_OK) break;
223  } else {
224  acc_files++;
225  acc_size += finfo.fsize;
226  }
227  }
228 
229  closedir_file(dir);
230  }
231 
232  return res;
233 }
234 
235 #include "str.h"
236 
237 static int mount(int argc, uchar *argv[]);
238 
239 /**
240  @brief デバイスをマウントする
241 */
242 static const struct st_shell_command com_file_mount = {
243  .name = "mount",
244  .command = mount,
245  .usage_str = "[<drive> <device_name> [fsname]]"
246 };
247 
248 static int mount(int argc, uchar *argv[])
249 {
250  char *devname;
251  char *fsname;
252 
253  if(argc > 3) {
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]);
257  }
258  } else if(argc > 2) {
259  int drv = dstoi(argv[1]);
260  if(mount_storage(drv, (char *)argv[2], FSNAME_VFAT) == 0) {
261  tprintf("Drive %d: %s\n", drv, argv[2]);
262  }
263  } else {
264  int i;
265  for(i=0; i<GSC_FS_VOLUME_NUM; i++) {
266  if(get_storage_device_name(i, &devname, &fsname) == 0) {
267  tprintf("%d: %8s %s\n", i, devname, fsname);
268  }
269  }
270  }
271 
272  return 0;
273 }
274 
275 
276 static int umount(int argc, uchar *argv[]);
277 
278 /**
279  @brief デバイスをアンマウントする
280 */
281 static const struct st_shell_command com_file_umount = {
282  .name = "umount",
283  .command = umount,
284  .usage_str = "<drive>"
285 };
286 
287 static int umount(int argc, uchar *argv[])
288 {
289  int rt = 0;
290  int drv;
291 
292  if(argc > 1) {
293  drv = dstoi(argv[1]);
294  rt = unmount_storage(drv);
295  } else {
296  print_command_usage(&com_file_umount);
297  }
298 
299  return rt;
300 }
301 
302 
303 
304 static char defdrive[FF_MAX_LFN+1] = "0:/";
305 #define FSECTSIZE FF_MIN_SS
306 
307 static int diskfree(int argc, uchar *argv[]);
308 
309 /**
310  @brief ドライブの空き容量を表示する
311 */
312 static const struct st_shell_command com_file_diskfree = {
313  .name = "free",
314  .command = diskfree,
315  .usage_str = "[drive]"
316 };
317 
318 static int diskfree(int argc, uchar *argv[])
319 {
320  FATFS *fs;
321  int fr;
322  unsigned long numcl;
323  unsigned char *path = (unsigned char *)defdrive;
324 
325  if(argc > 1) {
326  path = (unsigned char *)argv[1];
327  }
328 
329  tprintf("Disk %s\n", (char *)path);
330 
331  acc_size = acc_files = acc_dirs = 0;
332 
333  fr = getfree_file(path, &numcl, (void **)&fs);
334  if(fr == -1) {
335  tprintf("Not supported\n");
336  return 0;
337  }
338  if(fr) {
339  print_fresult((char *)path, fr);
340  return 0;
341  }
342 
343  if(fs == 0) {
344  tprintf("getfree_file() fs = 0\n");
345  return 0;
346  }
347 
348  tprintf("FAT type : %ld\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
364  );
365 
366  fr = scan_files(path, FF_MAX_LFN);
367  if(fr) {
368  print_fresult((char *)path, fr);
369  return 0;
370  }
371 
372  tprintf("%d files, %lu bytes (%s)\n"
373  "%d folders\n"
374  "%s available\n",
375  (int)acc_files,
376  acc_size,
377  fsize2str(acc_size),
378  (int)acc_dirs,
379  fsize2str((unsigned long)numcl * fs->csize * FSECTSIZE));
380 
381  return 0;
382 }
383 
384 #if FF_USE_MKFS != 0
385 static int format(int argc, uchar *argv[]);
386 
387 /**
388  @brief ドライブをフォマットする
389 */
390 static const struct st_shell_command com_format = {
391  .name = "format",
392  .command = format,
393  .usage_str = "<drive>"
394 };
395 
396 static int format(int argc, uchar *argv[])
397 {
398  int fr;
399  char path[4];
400 
401  if(argc < 2) {
402  print_command_usage(&com_format);
403  return 0;
404  }
405 
406  tprintf("Formatting drive %s...", argv[1]);
407  fr = mkfs_file((unsigned char *)argv[1], FM_FAT32, FSECTSIZE);
408  if(fr) {
409  tprintf("\n");
410  tsnprintf(path, 3, "%s:", argv[1]);
411  print_fresult(path, fr);
412  return 0;
413  } else {
414  tprintf("\nDone\n");
415  }
416 
417  return 0;
418 }
419 #endif
420 
421 #if FF_USE_CHMOD != 0
422 static int chmod(int argc, uchar *argv[]);
423 
424 /**
425  @brief ファイル属性を設定する
426 */
427 static const struct st_shell_command com_chmod = {
428  .name = "chmod",
429  .command = chmod,
430  .usage_str = "<file> <mode(0x01=RDO,0x02=HID,0x04=SYS,0x10=DIR,0x20=ARC)>"
431 };
432 
433 static int chmod(int argc, uchar *argv[])
434 {
435  int fr;
436  unsigned char mode = 0;
437 
438  if(argc < 2) {
439  print_command_usage(&com_chmod);
440  return 0;
441  }
442 
443  mode = hstoi(argv[2]);
444  fr = chmod_file(argv[1], mode);
445  if(fr) {
446  print_fresult((char *)argv[1], fr);
447  }
448 
449  return 0;
450 }
451 #endif
452 
453 static int dir(int argc, uchar *argv[]);
454 
455 /**
456  @brief ドライブのファイルリストを表示する
457 */
458 static const struct st_shell_command com_file_dir = {
459  .name = "dir",
460  .command = dir,
461  .usage_str = "[path]"
462 };
463 
464 static int dir(int argc, uchar *argv[])
465 {
466  int fr;
467  FS_DIR *dir;
468  FS_FILEINFO finfo;
469  unsigned long p1;
470  unsigned short s1, s2;
471  FATFS *fs;
472  unsigned char *path = (unsigned char *)defdrive;
473  uchar *str;
474  unsigned char cstr[FF_MAX_LFN + 1];
475 
476  str = finfo.fname;
477  finfo.fsize = FF_MAX_LFN;
478 
479  now_time = fattime();
480 
481  if(argc > 1) {
482  path = (unsigned char *)argv[1];
483  }
484 
485  dir = opendir_file(path);
486  if(dir == 0) {
487  tprintf("Cannot open \"%s\"\n", path);
488  return 0;
489  }
490 
491  p1 = 0;
492  s1 = 0;
493  s2 = 0;
494 
495  for(;;) {
496  fr = readdir_file(dir, &finfo);
497  if((fr != FR_OK) || !finfo.fname[0]) {
498  print_fresult((char *)path, fr);
499  break;
500  }
501  if((finfo.fattrib & AM_DIR) != 0) {
502  s2++;
503  } else {
504  s1++;
505  p1 += finfo.fsize;
506  }
507  (void)sjisstr_to_utf8str(cstr, (uchar *)str, FF_MAX_LFN);
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' : '-');
511  tprintf(" %s %s %s",
512  fdate2str(finfo.fdatetime),
513  ((finfo.fattrib & AM_DIR) != 0) ? " " : fsize2str(finfo.fsize),
514  cstr);
515  tprintf("\n");
516  }
517 
518  tprintf("%4d File %s\n", (int)s1, fsize2str(p1));
519  tprintf("%4d Dir", (int)s2);
520  if(getfree_file(path, &p1, (void **)&fs) == FR_OK) {
521  tprintf(" %s free\n",
522  fsize2str((p1 * fs->csize/2)*1024));
523  } else {
524  tprintf("\n");
525  }
526 
527  closedir_file(dir);
528 
529  return 0;
530 }
531 
532 
533 static int dirv(int argc, uchar *argv[]);
534 
535 /**
536  @brief ドライブのファイルリスト詳細を表示する
537 */
538 static const struct st_shell_command com_file_dirv = {
539  .name = "dirv",
540  .command = dirv,
541  .usage_str = "[path]"
542 };
543 
544 static int dirv(int argc, uchar *argv[])
545 {
546  int fr;
547  FS_DIR *dir;
548  FS_FILEINFO finfo;
549  unsigned long p1;
550  unsigned short s1, s2;
551  FATFS *fs;
552  unsigned char *path = (unsigned char *)defdrive;
553  uchar *str;
554  unsigned char cstr[FF_MAX_LFN + 1];
555 
556  str = finfo.fname;
557  finfo.fsize = FF_MAX_LFN;
558 
559  now_time = fattime();
560 
561  if(argc > 1) {
562  path = (unsigned char *)argv[1];
563  }
564 
565  dir = opendir_file(path);
566  if(dir == 0) {
567  tprintf("Cannot open \"%s\"\n", path);
568  return 0;
569  }
570 
571  p1 = 0;
572  s1 = 0;
573  s2 = 0;
574 
575  for(;;) {
576  fr = readdir_file(dir, &finfo);
577  if((fr != FR_OK) || !finfo.fname[0]) {
578  print_fresult((char *)path, fr);
579  break;
580  }
581  if((finfo.fattrib & AM_DIR) != 0) {
582  s2++;
583  } else {
584  s1++;
585  p1 += finfo.fsize;
586  }
587  (void)sjisstr_to_utf8str(cstr, (uchar *)str, FF_MAX_LFN);
588  XDUMP(0x01, (unsigned char *)str, strleng((uchar *)str));
589  XDUMP(0x01, (unsigned char *)cstr, strleng(cstr));
590  tprintf("%c%c%c%c%c",
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' : '-');
596  tprintf(" %s %s %s %s",
597  fdate2lstr(finfo.fdatetime),
598  ((finfo.fattrib & AM_DIR) != 0) ? " " : fsize2str(finfo.fsize),
599  ((finfo.fattrib & AM_DIR) != 0) ? " " : fsize2lstr(finfo.fsize),
600  cstr);
601  tprintf("\n");
602  }
603  tprintf("%4d File %s\n", (int)s1, fsize2str(p1));
604  tprintf("%4d Dir", (int)s2);
605  if(getfree_file(path, &p1, (void **)&fs) == FR_OK) {
606  tprintf(" %s free\n",
607  fsize2str((p1 * fs->csize/2)*1024));
608  } else {
609  tprintf("\n");
610  }
611 
612  closedir_file(dir);
613 
614  return 0;
615 }
616 
617 
618 static int delete(int argc, uchar *argv[]);
619 
620 /**
621  @brief ファイルを削除する
622 */
623 static const struct st_shell_command com_file_delete = {
624  .name = "delete",
625  .command = delete,
626  .usage_str = "<file_name>"
627 };
628 
629 static int delete(int argc, uchar *argv[])
630 {
631  int fr;
632 
633  if(argc > 1) {
634  fr = unlink_file((unsigned char *)argv[1]);
635 
636  if(fr) {
637  print_fresult((char *)argv[1], fr);
638  }
639  } else {
640  print_command_usage(&com_file_delete);
641  }
642 
643  return 0;
644 }
645 
646 
647 
648 #define FDSIZE FSECTSIZE
649 
650 static int fdump(int argc, uchar *argv[]);
651 
652 /**
653  @brief ファイルの内容をダンプ表示する
654 */
655 static const struct st_shell_command com_file_fdump = {
656  .name = "fdump",
657  .command = fdump,
658  .usage_str = "<file_name> [start [end]]"
659 };
660 
661 static int fdump(int argc, uchar *argv[])
662 {
663  int fd;
664  unsigned char fdbuf[16];
665  unsigned int st = 0;
666  unsigned int ed = st + FDSIZE - 1;
667  unsigned int dp;
668 
669  if(argc < 2) {
670  print_command_usage(&com_file_fdump);
671  return 0;
672  }
673 
674  if(argc > 1) {
675  fd = open_file((unsigned char *)argv[1], FA_READ);
676  if(fd < 0) {
677  tprintf("Cannot open \"%s\"\n", argv[1]);
678  goto exit;
679  }
680  }
681 
682  ed = seek_file(fd, 0, SEEK_END);
683 
684  if(argc > 2) {
685  st = hstou(argv[2]);
686  if(argc > 3) {
687  ed = hstou(argv[3]);
688  if(ed <= st) {
689  goto exit;
690  }
691  }
692  }
693 
694  (void)seek_file(fd, st, SEEK_SET);
695 
696  for(dp=st; dp<=ed; dp+=16) {
697  unsigned char *p;
698  int i;
699  int fr;
700  uchar rd;
701  int rlen = 16;
702 
703  if(((ed+1) - dp) < 16) {
704  rlen = ((ed+1) - dp);
705  }
706 
707  fr = read_file(fd, fdbuf, rlen);
708  if(fr < 0) {
709  tprintf("Cannot read \"%s\"\n", argv[1]);
710  goto close;
711  }
712 
713  p=fdbuf;
714  tprintf("%08X : ", dp);
715 
716  for(i=0; i<8; i++) {
717  if(i < fr) {
718  tprintf("%02X ", (int)*p);
719  } else {
720  tprintf(" ");
721  }
722  p++;
723  }
724  tprintf(" ");
725  for(i=0; i<8; i++) {
726  if(i < (fr-8)) {
727  tprintf("%02X ", (int)*p);
728  } else {
729  tprintf(" ");
730  }
731  p++;
732  }
733 
734  p=fdbuf;
735  tprintf(" \"");
736 
737  for(i=0; i<16; i++) {
738  if(i < fr) {
739  if(((' ' <= *p) && (*p <= 'Z'))
740  || (('a' <= *p) && (*p <= 'z'))) {
741  cputc(*p);
742  } else {
743  cputc('.');
744  }
745  } else {
746  break;
747  }
748  p++;
749  }
750  tprintf("\"\n");
751 
752  if(cgetcnw(&rd) != 0) {
753  if(rd == ASCII_CTRL_C) {
754  tprintf("Abort.\n");
755  goto close;
756  }
757  }
758  }
759 
760 close:
761  close_file(fd);
762 exit:
763  return 0;
764 }
765 
766 
767 static int operation(int argc, uchar *argv[]);
768 
769 /**
770  @brief ファイルをアプリケーションで実行する
771 */
772 static const struct st_shell_command com_file_operation = {
773  .name = "operation",
774  .command = operation,
775  .usage_str = "<file_name>"
776 };
777 
778 static int operation(int argc, uchar *argv[])
779 {
780  int rt = 0;
781 
782  if(argc > 1) {
783  if(argc > 2) {
784  rt = do_file_operation((unsigned char *)argv[1], argv[2]);
785  } else {
786  rt = do_file_operation((unsigned char *)argv[1], 0);
787  }
788  } else {
789  print_command_usage(&com_file_operation);
790  }
791 
792  return rt;
793 }
794 
795 
796 #include "batch.h"
797 
798 static int batch(int argc, uchar *argv[]);
799 
800 /**
801  @brief バッチファイルを実行する
802 */
803 static const struct st_shell_command com_file_batch = {
804  .name = "batch",
805  .command = batch,
806  .usage_str = "<file_name>"
807 };
808 
809 static int batch(int argc, uchar *argv[])
810 {
811  int rt = 0;
812 
813  if(argc > 1) {
814  exec_batch(argv[1]);
815  } else {
816  print_command_usage(&com_file_batch);
817  }
818 
819  return rt;
820 }
821 
822 //#define GSC_SHELL_USE_FWTEST
823 #ifdef GSC_SHELL_USE_FWTEST // $gsc ファイル書き込みテストコマンド(fwtest)を有効にする
824 static int fwtest(int argc, uchar *argv[]);
825 
826 /**
827  @brief ファイル作成書き込みテスト
828 */
829 static const struct st_shell_command com_file_fwtest = {
830  .name = "fwtest",
831  .command = fwtest,
832 };
833 
834 #define FWSIZE 1024
835 #define FWNAME "fwtest.dat"
836 
837 static int fwtest(int argc, uchar *argv[])
838 {
839  int fd = 0;
840  int rt = 0;
841  int i;
842  static unsigned char wbuf[FWSIZE];
843  static const uchar *dfname = (uchar *)FWNAME;
844  uchar *fname = (uchar *)dfname;
845 
846  for(i=0; i<FWSIZE; i++) {
847  wbuf[i] = (i & 0xff);
848  }
849  //xdump(wbuf, FWSIZE);
850 
851  if(argc > 1) {
852  fname = argv[1];
853  }
854 
855  fd = open_file(fname, FA_WRITE | FA_CREATE_ALWAYS);
856  if(fd < 0) {
857  tprintf("File open error \"%s\"\n", fname);
858  return -1;
859  }
860  rt = write_file(fd, wbuf, FWSIZE);
861  if(rt != FWSIZE) {
862  tprintf("File write error(%d)\n", rt);
863  close_file(fd);
864  return -1;
865  }
866  close_file(fd);
867 
868  return 0;
869 }
870 #endif
871 
872 
873 static const struct st_shell_command * const com_file_list[] = {
877 #if FF_USE_MKFS != 0
878  &com_format,
879 #endif
880 #if FF_USE_CHMOD != 0
881  &com_chmod,
882 #endif
883  &com_file_dir,
884  &com_file_dirv,
889 #ifdef GSC_SHELL_USE_FWTEST
890  &com_file_fwtest,
891 #endif
892  0
893 };
894 
895 const struct st_shell_command com_file = {
896  .name = "file",
897  .manual_str = "File strage operation commands",
898  .sublist = com_file_list
899 }; ///< ファイル操作
static const struct st_shell_command com_file_dirv
ドライブのファイルリスト詳細を表示する
Definition: com_file.c:538
unsigned int fattime(void)
FAT 現在実時間を取得する
Definition: datetime.c:775
unsigned char uchar
GadgetSeedの文字(列)は unsigned char 型となる
Definition: str.h:13
static const struct st_shell_command com_file_mount
デバイスをマウントする
Definition: com_file.c:242
時刻構造体
Definition: datetime.h:29
static const struct st_shell_command com_file_batch
バッチファイルを実行する
Definition: com_file.c:803
シェルコマンド構造体
Definition: shell.h:33
static const struct st_shell_command com_file_fdump
ファイルの内容をダンプ表示する
Definition: com_file.c:655
コマンドシェル
Definition: fs.h:44
t_ssize seek_file(int fd, t_ssize offset, int whence)
ファイルアクセス位置の設定
Definition: file.c:244
static const struct st_shell_command com_file_operation
ファイルをアプリケーションで実行する
Definition: com_file.c:772
int unmount_storage(int drvno)
ストレージデバイスをアンマウントする
Definition: storage.c:119
アプリケーション(タスク)デバッグ用マクロ
システム時間
Definition: datetime.h:40
文字コード処理
int get_storage_device_name(int drv, char **devname, char **fsname)
マウントされているデバイス名を取得する
Definition: storage.c:195
ファイルシステムAPI
int cgetcnw(unsigned char *rd)
標準入力より1文字を取得する(待ち無し)
Definition: console.c:235
文字列処理
t_ssize write_file(int fd, const void *buf, t_size count)
ファイルにデータを書き込む
Definition: file.c:216
int close_file(int fd)
ファイルを閉じる
Definition: file.c:297
ファイル
FS_DIR * opendir_file(const uchar *name)
ディレクトリを開く
Definition: file.c:329
char sec
Definition: datetime.h:36
日付時刻
static const struct st_shell_command com_file_umount
デバイスをアンマウントする
Definition: com_file.c:281
int closedir_file(FS_DIR *dir)
ディレクトリを閉じる
Definition: file.c:382
static const struct st_shell_command com_file_delete
ファイルを削除する
Definition: com_file.c:623
unsigned int hstou(uchar *str)
16進数文字列 unsigned int 変換
Definition: str.c:180
カーネル用機能限定printf
int mount_storage(int drvno, const char *devname, const char *fsname)
ストレージデバイスをマウントする
Definition: storage.c:64
int dstoi(uchar *str)
10進数文字列 int 変換
Definition: str.c:523
int open_file(const uchar *path, int flags)
ファイルを開く
Definition: file.c:144
unsigned int strleng(const uchar *str)
文字列長
Definition: str.c:657
uchar name[12]
コマンド名文字列
Definition: shell.h:34
int tsprintf(char *str, const char *fmt,...)
簡易sprintf
Definition: tprintf.c:36
void unixtime_to_datetime(struct st_datetime *datetime, struct st_systime *unixtime)
UNIX時間より時刻を求める
Definition: datetime.c:658
int cputc(unsigned char td)
標準出力より1文字を出力する
Definition: console.c:163
外部記憶装置管理
int tprintf(const char *fmt,...)
簡易printf
Definition: tprintf.c:85
static const struct st_shell_command com_file_diskfree
ドライブの空き容量を表示する
Definition: com_file.c:312
uchar * sjisstr_to_utf8str(uchar *utf8str, uchar *sjisstr, unsigned int count)
SJIS 文字列から UTF-8 文字列へ変換
Definition: charcode.c:73
#define SEEK_SET
設定
Definition: device.h:21
int readdir_file(FS_DIR *dir, FS_FILEINFO *finfo)
ディレクトリを読み出す
Definition: file.c:356
Definition: fs.h:37
#define GSC_FS_VOLUME_NUM
$gsc 最大ストレージデバイスボリューム数
Definition: storage.h:15
uchar * strncopy(uchar *dest, const uchar *src, unsigned int n)
文字列コピー
Definition: str.c:632
int hstoi(uchar *str)
16進数文字列 int 変換
Definition: str.c:145
int exec_batch(uchar *path)
バッチファイルを実行する
Definition: batch.c:55
int getfree_file(const uchar *path, unsigned long *sect, void **fs)
論理ドライブの未使用クラスタ数を取得する
Definition: file.c:437
バッチ処理
t_ssize read_file(int fd, void *buf, t_size count)
ファイルからデータを読み出す
Definition: file.c:188
デバイスドライバAPI
#define SEEK_END
ファイルサイズに加算
Definition: device.h:23
static const struct st_shell_command com_file_dir
ドライブのファイルリストを表示する
Definition: com_file.c:458
機能限定printf
int unlink_file(const uchar *path)
ファイルを消去する
Definition: file.c:489
int tsnprintf(char *str, unsigned int size, const char *fmt,...)
簡易snprintf
Definition: tprintf.c:60