int32_t Shell_pwd(int32_t argc, char *argv[] ) { /* Body */ bool print_usage, shorthelp = FALSE; int32_t error = 0, return_code = SHELL_EXIT_SUCCESS; MQX_FILE_PTR fs_ptr; SHELL_CONTEXT_PTR shell_ptr = Shell_get_context( argv ); print_usage = Shell_check_help_request(argc, argv, &shorthelp ); if (!print_usage) { if (argc > 1) { printf("Error, invalid number of parameters\n"); return_code = SHELL_EXIT_ERROR; print_usage=TRUE; } else { fs_ptr = Shell_get_current_filesystem(argv); if (fs_ptr == NULL) { printf("Error, file system not mounted\n" ); return_code = SHELL_EXIT_ERROR; } else { printf("%s%s\n", shell_ptr->CURRENT_DEVICE_NAME, shell_ptr->CURRENT_DIR); } } } if (print_usage) { if (shorthelp) { printf("%s \n", argv[0]); } else { printf("Usage: %s \n", argv[0]); } } return return_code; }
int32_t Shell_disect(int32_t argc, char *argv[] ) { /* Body */ int32_t return_code = SHELL_EXIT_SUCCESS; bool print_usage, shorthelp = FALSE; uint32_t sector,num_sectors; int32_t offset=0; MQX_FILE_PTR fd, fs; uint32_t e,i; unsigned char *buffer; print_usage = Shell_check_help_request(argc, argv, &shorthelp ); if (!print_usage) { if ((argc < 2) || (argc > 5)) { printf("Error, invalid number of parameters\n"); return_code = SHELL_EXIT_ERROR; print_usage=TRUE; } else if ( !Shell_parse_uint_32(argv[1], (uint32_t *) &offset )) { printf("Error, invalid length\n"); return_code = SHELL_EXIT_ERROR; print_usage=TRUE; } else { num_sectors = 1; if (argc >= 3) { if ( !Shell_parse_uint_32(argv[2], (uint32_t *) &num_sectors )) { num_sectors = 1; } } if (argc >= 4) { fd = fopen(argv[3], "r"); if (!fd) { printf("Error, unable to open file %s.\n", argv[1] ); return_code = SHELL_EXIT_ERROR; } } else { fs = Shell_get_current_filesystem(argv); _io_ioctl(fs, IO_IOCTL_GET_DEVICE_HANDLE, &fd); } if (fd) { buffer = _mem_alloc(SECTOR_SIZE); if (buffer) { for(sector=0;sector<num_sectors;sector++) { if (fseek(fd, offset+sector, IO_SEEK_SET) == IO_ERROR) { printf("Error, unable to seek to sector %s.\n", argv[1] ); return_code = SHELL_EXIT_ERROR; } else if (_io_read(fd, (char *) buffer, 1) != 1) { printf("Error, unable to read sector %s.\n", argv[1] ); return_code = SHELL_EXIT_ERROR; } else { printf("\nSector # %d\n",offset+sector); for (e=0;e<16;e++) { for (i=0;i<32;i++) { printf("%02x ",(uint32_t) buffer[e*32+i]); } printf("\n"); } } } _mem_free(buffer); } } printf("\n"); if (argc >= 4) { fclose(fd); } } } if (print_usage) { if (shorthelp) { printf("%s <sector> [<device>]\n", argv[0]); } else { printf("Usage: %s <sector> [<device>]\n", argv[0]); printf(" <sector> = sector number\n"); printf(" <device> = low level device\n"); } } return return_code; } /* Endbody */
int32_t Shell_dir(int32_t argc, char *argv[] ) { /* Body */ bool print_usage, shorthelp = FALSE; int32_t return_code = SHELL_EXIT_SUCCESS; int32_t len; MQX_FILE_PTR fs_ptr; char *path_ptr, *mode_ptr; void *dir_ptr; char *buffer = NULL; SHELL_CONTEXT_PTR shell_ptr = Shell_get_context( argv ); int32_t error = 0; print_usage = Shell_check_help_request(argc, argv, &shorthelp ); if (!print_usage) { if (argc > 3) { printf("Error, invalid number of parameters\n"); return_code = SHELL_EXIT_ERROR; print_usage=TRUE; } else { path_ptr ="*.*"; mode_ptr = "m"; if (argc >= 2) { path_ptr = argv[1]; if (argc== 3) { mode_ptr = argv[2]; } } fs_ptr = Shell_get_current_filesystem(argv); /* check if filesystem is mounted */ if (fs_ptr == NULL) { printf("Error, file system not mounted\n"); return_code = SHELL_EXIT_ERROR; } else { buffer = _mem_alloc(BUFFER_SIZE); error = ioctl(fs_ptr, IO_IOCTL_CHANGE_CURRENT_DIR, shell_ptr->CURRENT_DIR); if (buffer && !error) { dir_ptr = _io_mfs_dir_open(fs_ptr, path_ptr, mode_ptr ); if (dir_ptr == NULL) { printf("File not found.\n"); return_code = SHELL_EXIT_ERROR; } else { while ((_io_is_fs_valid(fs_ptr)) && (len = _io_mfs_dir_read(dir_ptr, buffer, BUFFER_SIZE)) > 0) { printf(buffer); } _io_mfs_dir_close(dir_ptr); } _mem_free(buffer); } else { if(buffer == NULL){ printf("Error, unable to allocate space.\n" ); } else { printf("Error, directory does not exist.\n" ); } return_code = SHELL_EXIT_ERROR; } } } } if (print_usage) { if (shorthelp) { printf("%s [<filespec>] [<attr>]]\n", argv[0]); } else { printf("Usage: %s [<filespec> [<attr>]]\n", argv[0]); printf(" <filespec> = files to list\n"); printf(" <attr> = attributes of files: adhrsv*\n"); } } return return_code; } /* Endbody */
int_32 Shell_type(int_32 argc, char_ptr argv[] ) { /* Body */ boolean print_usage, shorthelp = FALSE; int_32 return_code = SHELL_EXIT_SUCCESS; MQX_FILE_PTR fd; char_ptr abs_path; _mqx_int c; SHELL_CONTEXT_PTR shell_ptr = Shell_get_context( argv ); int_32 error = 0; print_usage = Shell_check_help_request(argc, argv, &shorthelp ); if (!print_usage) { if (argc == 2) { /* check if filesystem is mounted */ if (NULL == Shell_get_current_filesystem(argv)) { printf("Error, file system not mounted\n" ); return_code = SHELL_EXIT_ERROR; } else if (MFS_alloc_path(&abs_path) != MFS_NO_ERROR) { printf("Error, unable to allocate memory for paths\n" ); return_code = SHELL_EXIT_ERROR; } else { error = _io_rel2abs(abs_path,shell_ptr->CURRENT_DIR,(char *) argv[1],PATHNAME_SIZE,shell_ptr->CURRENT_DEVICE_NAME); if(!error) { fd = fopen(abs_path, "r"); } MFS_free_path(abs_path); if (fd && !error) { do { c = fgetc(fd); if (c!= IO_EOF) { fputc((char)c, stdout); } } while (c!=IO_EOF); fclose(fd); printf("\n"); } else { printf("Error, unable to open file %s.\n", argv[1] ); return_code = SHELL_EXIT_ERROR; } } } else { printf("Error, %s invoked with incorrect number of arguments\n", argv[0]); return_code = SHELL_EXIT_ERROR; print_usage = TRUE; } } if (print_usage) { if (shorthelp) { printf("%s <filename>\n", argv[0]); } else { printf("Usage: %s <filename>\n", argv[0]); printf(" <filename> = filename to display\n"); } } return return_code; } /* Endbody */
int_32 Shell_di(int_32 argc, char_ptr argv[] ) { /* Body */ boolean print_usage, shorthelp = FALSE; int_32 return_code = SHELL_EXIT_SUCCESS; int_32 offset; MQX_FILE_PTR fd, fs; uint_32 backup=0; uchar_ptr buffer=NULL; print_usage = Shell_check_help_request(argc, argv, &shorthelp ); if (!print_usage) { if ((argc < 2 ) || (argc > 3)) { printf("Invalid number of parameters\n"); return_code = SHELL_EXIT_ERROR; print_usage=TRUE; } else if ( !Shell_parse_uint_32(argv[1], (uint_32_ptr) &offset )) { printf("Error, invalid length\n"); return_code = SHELL_EXIT_ERROR; print_usage=TRUE; } else { buffer = _mem_alloc(SECTOR_SIZE); if (buffer==NULL) { printf("Error, unable to allocate sector buffer\n"); return SHELL_EXIT_ERROR; } if (argc==3) { fd = fopen(argv[2], "b"); } else { fs = Shell_get_current_filesystem(argv); _io_ioctl(fs, IO_IOCTL_GET_DEVICE_HANDLE, &fd); } if (fd) { if (fseek(fd, offset, IO_SEEK_SET) == IO_ERROR) { printf("Error, unable to seek to sector %s.\n", argv[1] ); return_code = SHELL_EXIT_ERROR; } else if (_io_read(fd, (char_ptr) buffer, 1) != 1) { printf("Error, unable to read sector %s.\n", argv[1] ); return_code = SHELL_EXIT_ERROR; } if (return_code == SHELL_EXIT_SUCCESS) { printf("\n"); backup = print_bpb(buffer); if (backup) { if (fseek(fd, backup, IO_SEEK_SET) == IO_ERROR) { printf("Error, unable to seek to sector %s.\n", argv[1] ); return_code = SHELL_EXIT_ERROR; } else if (_io_read(fd, (char_ptr) buffer, 1) != 1) { printf("Error, unable to read sector %s.\n", argv[1] ); return_code = SHELL_EXIT_ERROR; } if (return_code == SHELL_EXIT_SUCCESS) { printf("\n"); print_bpb(buffer); } } } if (fseek(fd, 1, IO_SEEK_SET) == IO_ERROR) { printf("Error, unable to seek to sector %s.\n", argv[1] ); return_code = SHELL_EXIT_ERROR; } else if (_io_read(fd, (char_ptr) buffer, 1) != 1) { printf("Error, unable to read sector %s.\n", argv[1] ); return_code = SHELL_EXIT_ERROR; } if (return_code == SHELL_EXIT_SUCCESS) { printf("\n"); print_fsi(buffer); } if (argc==3) { fclose(fd); } } _mem_free(buffer); } } if (print_usage) { if (shorthelp) { printf("%s <sector> [<device>]\n", argv[0]); } else { printf("Usage: %s <sector> [<device>]\n", argv[0]); printf(" <sector> = sector number\n"); printf(" <device> = low level device\n"); } } return return_code; } /* Endbody */
int_32 Shell_dirent(int_32 argc, char_ptr argv[] ) { /* Body */ boolean print_usage, shorthelp = FALSE; int_32 return_code = SHELL_EXIT_SUCCESS; uint_32 sector,num_sectors; int_32 offset; MQX_FILE_PTR fd, fs; uint_32 e; uchar_ptr buffer; MFS_DIR_ENTRY_PTR dirents; print_usage = Shell_check_help_request(argc, argv, &shorthelp ); if (!print_usage) { if ((argc < 2) || (argc > 4)) { printf("Error, invalid number of parameters\n"); return_code = SHELL_EXIT_ERROR; print_usage=TRUE; } else if ( !Shell_parse_uint_32(argv[1], (uint_32_ptr) &offset )) { printf("Error, invalid length\n"); return_code = SHELL_EXIT_ERROR; print_usage=TRUE; } else { num_sectors = 1; if (argc >= 3) { if ( !Shell_parse_uint_32(argv[2], (uint_32_ptr) &num_sectors )) { num_sectors = 1; } } if (argc == 4) { fd = fopen(argv[3], "r"); if (!fd) { printf("Error, unable to open file %s.\n", argv[1] ); return_code = SHELL_EXIT_ERROR; } } else { fs = Shell_get_current_filesystem(argv); _io_ioctl(fs, IO_IOCTL_GET_DEVICE_HANDLE, &fd); } if (fd) { buffer = _mem_alloc(SECTOR_SIZE); if (buffer) { for(sector=0;sector<num_sectors;sector++) { if (fseek(fd, offset+sector, IO_SEEK_SET) == IO_ERROR) { printf("Error, unable to seek to sector %s.\n", argv[1] ); return_code = SHELL_EXIT_ERROR; } else if (_io_read(fd, (char_ptr) buffer, 1) !=1) { printf("Error, unable to read sector %s.\n", argv[1] ); return_code = SHELL_EXIT_ERROR; } else if (!is_zero(buffer, SECTOR_SIZE)) { printf("\nEntry # %d",offset+sector); dirents = (MFS_DIR_ENTRY_PTR) buffer; for (e=0;e<DIRENTS_PER_SECTOR;e++) { print_dirent(&dirents[e]); } printf("\n"); } } _mem_free(buffer); } else { printf("Error, unable to allocate sector buffer.\n" ); return_code = SHELL_EXIT_ERROR; } if (argc >= 4) { fclose(fd); } } } } if (print_usage) { if (shorthelp) { printf("%s <sector> [<device>]\n", argv[0]); } else { printf("Usage: %s <sector> [<device>]\n", argv[0]); printf(" <sector> = sector number\n"); printf(" <device> = low level device\n"); } } return return_code; } /* Endbody */
int32_t Shell_del(int32_t argc, char *argv[] ) { /* Body */ bool print_usage, shorthelp = FALSE, temp; int32_t error = 0, return_code = SHELL_EXIT_SUCCESS; MQX_FILE_PTR fs_ptr; SHELL_CONTEXT_PTR shell_ptr = Shell_get_context( argv ); char *abs_path; print_usage = Shell_check_help_request(argc, argv, &shorthelp ); if (!print_usage) { if (argc != 2) { printf("Error, invalid number of parameters\n"); return_code = SHELL_EXIT_ERROR; print_usage=TRUE; } /* check if filesystem is mounted */ else if (NULL == Shell_get_current_filesystem(argv)) { printf("Error, file system not mounted\n" ); return_code = SHELL_EXIT_ERROR; } else { if (MFS_alloc_path(&abs_path) != MFS_NO_ERROR) { printf("Error, unable to allocate memory for paths\n" ); return_code = SHELL_EXIT_ERROR; } else { _io_get_dev_for_path(abs_path,&temp,PATHNAME_SIZE,(char *)argv[1],Shell_get_current_filesystem_name(shell_ptr)); fs_ptr = _io_get_fs_by_name(abs_path); if (fs_ptr == NULL) { printf("Error, file system not mounted\n" ); return_code = SHELL_EXIT_ERROR; } else { error = _io_rel2abs(abs_path,shell_ptr->CURRENT_DIR,(char *) argv[1],PATHNAME_SIZE,Shell_get_current_filesystem_name(shell_ptr)); if (!error) { error = ioctl(fs_ptr, IO_IOCTL_DELETE_FILE, (void *) abs_path); } if (error) { printf("Error deleting file %s\n", argv[1]); } } MFS_free_path(abs_path); } } } if (print_usage) { if (shorthelp) { printf("%s <file> \n", argv[0]); } else { printf("Usage: %s <file>\n", argv[0]); printf(" <file> = name of file to delete\n"); } } return return_code; }
int_32 Shell_search_file_r(int_32 argc, char_ptr argv[] ) { /* Body */ boolean print_usage, shorthelp = FALSE; int_32 return_code = SHELL_EXIT_SUCCESS; int_32 len; MQX_FILE_PTR fs_ptr; char_ptr path_ptr, mode_ptr; pointer dir_ptr; char_ptr buffer = NULL; SHELL_CONTEXT_PTR shell_ptr = Shell_get_context( argv ); int_32 error = 0; char_ptr file_name,source_name; MFS_SEARCH_DATA search_data; pointer search_ptr; DIR_STRUCT_PTR dir_file; // wk @130405 --> dir_file = _mem_alloc_zero( sizeof( DIR_STRUCT )); // wk @130405 --> print_usage = Shell_check_help_request(argc, argv, &shorthelp ); if (!print_usage) { if (argc > 2) { printf("Error, invalid number of parameters\n"); return_code = SHELL_EXIT_ERROR; print_usage=TRUE; } else { path_ptr ="*.*"; mode_ptr = "m"; source_name=argv[1]; fs_ptr = Shell_get_current_filesystem(argv); /* check if filesystem is mounted */ if (fs_ptr == NULL) { printf("Error, file system not mounted\n"); return_code = SHELL_EXIT_ERROR; } else { buffer = _mem_alloc(BUFFER_SIZE); error = ioctl(fs_ptr, IO_IOCTL_CHANGE_CURRENT_DIR, shell_ptr->CURRENT_DIR); if (buffer && !error) { dir_ptr = _io_mfs_dir_open(fs_ptr, path_ptr, mode_ptr ); if (dir_ptr == NULL) { printf("File not found.\n"); return_code = SHELL_EXIT_ERROR; } else { // while ((_io_is_fs_valid(fs_ptr)) && (len = _io_mfs_dir_read_wk(dir_ptr, buffer, BUFFER_SIZE )) > 0) { // wk @130405-->old while ((_io_is_fs_valid(fs_ptr)) && (len = _io_mfs_dir_read_wk1(dir_ptr, buffer, BUFFER_SIZE,dir_file )) > 0) { // printf ("%-12.12s %6lu \n" // ,dir_ptr_g->SEARCH_DATA.NAME, dir_ptr_g->SEARCH_DATA.FILE_SIZE); // file_name=dir_ptr_g->SEARCH_DATA.NAME; // wk @130405-->old printf ("%-12.12s %6lu \n" ,dir_file->SEARCH_DATA.NAME, dir_file->SEARCH_DATA.FILE_SIZE); // file_name=dir_ptr_g->SEARCH_DATA.NAME; // wk @130405-->old file_name=dir_file->SEARCH_DATA.NAME; if(argc==2) { while(*(source_name)!='\0') if(*(file_name++)!= *(source_name++)) goto next; error=33; // WK --> 文件找到 break; } next: source_name=argv[1]; } if(argc==2) printf("error=%d if /t33表示文件找到\n",error); _io_mfs_dir_close(dir_ptr); } _mem_free(buffer); _mem_free(dir_file); } else { if(buffer == NULL){ printf("Error, unable to allocate space.\n" ); } else { printf("Error, directory does not exist.\n" ); } return_code = SHELL_EXIT_ERROR; } } } } if (print_usage) { if (shorthelp) { printf("%s [<filename>]\n", argv[0]); } else { printf("Usage: %s [<filespec> [<attr>]]\n", argv[0]); printf(" <filename> = filename what want to fine\n"); } } return return_code; } /* Endbody */
int32_t Shell_create(int32_t argc, char *argv[] ) { /* Body */ bool print_usage, shorthelp = FALSE; int32_t return_code = SHELL_EXIT_SUCCESS; char *mode; int fd = -1; char *abs_path; SHELL_CONTEXT_PTR shell_ptr = Shell_get_context( argv ); int32_t error = 0; print_usage = Shell_check_help_request(argc, argv, &shorthelp ); if (!print_usage) { if ((argc < 2) || (argc > 3)) { fprintf(shell_ptr->STDOUT, "Error, invalid number of parameters\n"); return_code = SHELL_EXIT_ERROR; print_usage = TRUE; } /* check if filesystem is mounted */ else if (0 > Shell_get_current_filesystem(argv)) { fprintf(shell_ptr->STDOUT, "Error, file system not mounted\n" ); return_code = SHELL_EXIT_ERROR; } else { /*if (argc != 3) { mode = "a"; } else { mode = argv[2]; } */ if (MFS_alloc_path(&abs_path) != MFS_NO_ERROR) { fprintf(shell_ptr->STDOUT, "Error, unable to allocate memory for paths\n" ); return_code = SHELL_EXIT_ERROR; } else { error = _io_rel2abs(abs_path,shell_ptr->CURRENT_DIR,(char *) argv[1],PATHNAME_SIZE,shell_ptr->CURRENT_DEVICE_NAME); if(!error) { fd = open(abs_path, O_WRONLY | O_CREAT); } MFS_free_path(abs_path); if (0 <= fd && !error) { close(fd); } else { fprintf(shell_ptr->STDOUT, "Error, unable to open file %s.\n", argv[1] ); return_code = SHELL_EXIT_ERROR; } } } } if (print_usage) { if (shorthelp) { fprintf(shell_ptr->STDOUT, "%s <filename> [<mode>] \n", argv[0]); } else { fprintf(shell_ptr->STDOUT, "Usage: %s <filename> [<mode>]\n", argv[0]); fprintf(shell_ptr->STDOUT, " <filename> = filename to create\n"); fprintf(shell_ptr->STDOUT, " <bytes> = open mode\n"); } } return return_code; } /* Endbody */
int32_t Shell_compare(int32_t argc, char *argv[] ) { /* Body */ bool print_usage, shorthelp = FALSE; int32_t size1, size2, return_code = SHELL_EXIT_SUCCESS; MQX_FILE_PTR in_fd_1=NULL, in_fd_2=NULL; char *file1=NULL, *file2=NULL; SHELL_CONTEXT_PTR shell_ptr = Shell_get_context( argv ); int32_t error = 0; print_usage = Shell_check_help_request(argc, argv, &shorthelp ); if (!print_usage) { if (argc != 3) { printf("Error, invalid number of parameters\n"); return_code = SHELL_EXIT_ERROR; print_usage=TRUE; } /* check if filesystem is mounted */ else if (NULL == Shell_get_current_filesystem(argv)) { printf("Error, file system not mounted\n"); return_code = SHELL_EXIT_ERROR; } else if (MFS_alloc_path(&file1) != MFS_NO_ERROR) { printf("Error, unable to allocate memory for paths\n" ); return_code = SHELL_EXIT_ERROR; } else { error = _io_rel2abs(file1,shell_ptr->CURRENT_DIR,(char *) argv[1],PATHNAME_SIZE,shell_ptr->CURRENT_DEVICE_NAME); if(!error) { in_fd_1 = fopen(file1, "r"); } error = _io_rel2abs(file1,shell_ptr->CURRENT_DIR,(char *) argv[2],PATHNAME_SIZE,shell_ptr->CURRENT_DEVICE_NAME); if(!error) { in_fd_2 = fopen(file1, "r"); } MFS_free_path(file1); if (in_fd_1 == NULL) { printf("Error, unable to open file %s\n", argv[1] ); return_code = SHELL_EXIT_ERROR; } else if (in_fd_2 == NULL) { printf("Error, unable to open file %s\n", argv[2] ); return_code = SHELL_EXIT_ERROR; } else { file1 = _mem_alloc_zero(COMPARE_BLOCK_SIZE); file2 = _mem_alloc_zero(COMPARE_BLOCK_SIZE); if ((file1==NULL) || (file2==NULL)) { printf("Error, unable to allocate buffer space" ); return_code = SHELL_EXIT_ERROR; } else { do { size1 = read(in_fd_1, file1, COMPARE_BLOCK_SIZE); size2 = read(in_fd_2, file2, COMPARE_BLOCK_SIZE); if (size1!=size2) { printf("Compare failed, files have different sizes\n" ); return_code = SHELL_EXIT_ERROR; } else if (size1 > 0) { if (memcmp(file1,file2,COMPARE_BLOCK_SIZE)!=0) { printf("Compare failed, files are different\n" ); return_code = SHELL_EXIT_ERROR; } } } while ((size1>0) && (return_code == SHELL_EXIT_SUCCESS)); if (return_code == SHELL_EXIT_SUCCESS) { printf("The files are identical\n" ); } } if (file1) _mem_free(file1); if (file2) _mem_free(file2); } if (in_fd_1) fclose(in_fd_1); if (in_fd_2) fclose(in_fd_2); } } if (print_usage) { if (shorthelp) { printf("%s <file1> <file2> \n", argv[0]); } else { printf("Usage: %s <file1> <file2>\n", argv[0]); printf(" <file1> = first file to compare\n"); printf(" <file2> = second file to compare\n"); } } return return_code; } /* Endbody */
int_32 Shell_write_binary(int_32 argc, char_ptr argv[] ,uint_32 num,uchar_ptr data) { /* Body */ boolean print_usage, shorthelp = FALSE; int_32 return_code = SHELL_EXIT_SUCCESS; uint_32 count=0, i; int_32 offset=0; int_32 seek_mode=0; char c; MQX_FILE_PTR fd = NULL; char_ptr abs_path; boolean cache_enabled=TRUE; SHELL_CONTEXT_PTR shell_ptr = Shell_get_context( argv ); char buf[SHELL_BLOCK_SIZE]; char * argv5_p; int_32 error = 0; _mqx_int bi; /* wk @130514 --> */ uint_32 nums;uchar left; /* wk @130514 --> */ print_usage = Shell_check_help_request(argc, argv, &shorthelp ); // wk @130405 --> 简化程序减小时间 if (!print_usage) { if ((argc < 3)) { printf("Error, invalid number of parameters\n"); return_code = SHELL_EXIT_ERROR; print_usage=TRUE; } /* check if filesystem is mounted */ else if (NULL == Shell_get_current_filesystem(argv)) { printf("Error, file system not mounted\n"); return_code = SHELL_EXIT_ERROR; } else { count = 0; offset = 0; seek_mode = IO_SEEK_CUR; // 默认模式 if (argc >= 4) { // if (! Shell_parse_uint_32(argv[2], &count )) {// 检查输入长度 // printf("Error, invalid length\n"); // return_code = SHELL_EXIT_ERROR; // print_usage=TRUE; // } else { if (argc >= 4) { if (strcmp(argv[2], "begin") == 0) { seek_mode = IO_SEEK_SET; } else if (strcmp(argv[2], "end") == 0) { seek_mode = IO_SEEK_END; } else if (strcmp(argv[2], "current") == 0) { seek_mode = IO_SEEK_CUR; } else { printf("Error, invalid seek type\n"); return_code = SHELL_EXIT_ERROR; print_usage=TRUE; } if (return_code == SHELL_EXIT_SUCCESS) { if (! Shell_parse_int_32(argv[3], &offset )) { printf("Error, invalid seek value\n"); return_code = SHELL_EXIT_ERROR; print_usage=TRUE; } } } } } } if (return_code == SHELL_EXIT_SUCCESS) { if (MFS_alloc_path(&abs_path) != MFS_NO_ERROR) { printf("Error, unable to allocate memory for paths\n" ); return_code = SHELL_EXIT_ERROR; } else { error = _io_rel2abs(abs_path,shell_ptr->CURRENT_DIR,(char *) argv[1],PATHNAME_SIZE,shell_ptr->CURRENT_DEVICE_NAME); if(!error) { fd = fopen(abs_path, "a"); } if (fd && !error) { if (fseek(fd, offset, seek_mode ) != IO_ERROR) { // generate data to buf // argv5_p = (char*)argv[5];// by dx // for (i = 0, c = '0', bi = 0; i < count;i++) {// 写入txt,从字符0到z // // buf[bi++] = c; // // if (bi > SHELL_BLOCK_SIZE - 1) { // write(fd, buf, SHELL_BLOCK_SIZE); // bi = 0; // } // // if (c == 'z') // c='0'; // else // c++; // } // // if (bi) // count = ( strlen(argv5_p)<count )?( strlen(argv5_p) ):(count);// 修改长度,若超过最大长度则用最大长度 // write(fd, argv5_p, count);// 写入SD,相应路径 /* wk @130405 --> 写我二进制数据 */ // for(i = 0; i < num; i++) // { //// write(fd,data+i,1); // } /* wk @130514 --> */ nums=num>>7; left=(uchar)num&0x7f; for(uint_32 i=0;i<nums;i++) write(fd,&data[i<<7],SHELL_BLOCK_SIZE); write(fd,&data[nums<<7],left); /* wk @130514 --> end*/ // write(fd,data,num); /* wk @130405 --> 写二进制数据 <--END */ fclose(fd); } else { printf("Error, unable to seek file %s.\n", argv[1] ); return_code = SHELL_EXIT_ERROR; } } else { printf("Error, unable to open file %s.\n", argv[1] ); return_code = SHELL_EXIT_ERROR; } MFS_free_path(abs_path); }
int32_t Shell_df(int32_t argc, char *argv[]) { /* Body */ bool print_usage; bool shorthelp = FALSE; int32_t return_code = SHELL_EXIT_SUCCESS; SHELL_CONTEXT_PTR shell_ptr = Shell_get_context(argv); int fs; int64_t space; int32_t clusters; uint32_t cluster_size; int32_t error = 0; char *fs_name; print_usage = Shell_check_help_request(argc, argv, &shorthelp); if (!print_usage) { if (argc > 2) { fprintf(shell_ptr->STDOUT, "Error, invalid number of parameters\n"); return_code = SHELL_EXIT_ERROR; print_usage=TRUE; } } if (print_usage) { if (shorthelp) { fprintf(shell_ptr->STDOUT, "%s [<filesystem>]\n", argv[0]); } else { fprintf(shell_ptr->STDOUT, "Usage: %s [filesystem]\n", argv[0]); fprintf(shell_ptr->STDOUT, " <filesystem> = filesystem to query for free space\n"); } return return_code; } if (argc == 2) { fs_name = argv[1]; fs = _io_get_fs_by_name(fs_name); } else { fs_name = Shell_get_current_filesystem_name(shell_ptr); fs = Shell_get_current_filesystem(argv); } /* check if filesystem is mounted */ if (0 > fs) { fprintf(shell_ptr->STDOUT, "Error, file system not mounted\n"); return return_code = SHELL_EXIT_ERROR; } error = ioctl(fs, IO_IOCTL_FREE_SPACE, &space); if (0 > error) { fprintf(shell_ptr->STDOUT, "Error, could not get free space\n"); return return_code = SHELL_EXIT_ERROR; } error = ioctl(fs, IO_IOCTL_FREE_CLUSTERS, &clusters); if (0 > error) { fprintf(shell_ptr->STDOUT, "Error, could not get free space\n"); return return_code = SHELL_EXIT_ERROR; } error = ioctl(fs, IO_IOCTL_GET_CLUSTER_SIZE, &cluster_size); if (0 > error) { fprintf(shell_ptr->STDOUT, "Error, could not get free space\n"); return return_code = SHELL_EXIT_ERROR; } fprintf(shell_ptr->STDOUT, "Free disk space on %s\n", fs_name); fprintf(shell_ptr->STDOUT, "%ld clusters, %ld bytes each\n", (long int)clusters, (long int)cluster_size); fprintf(shell_ptr->STDOUT, "%lu KB\n", (unsigned long int)(space>>10)); return return_code; } /* Endbody */
int_32 Shell_create(int_32 argc, char_ptr argv[] ) { /* Body */ boolean print_usage, shorthelp = FALSE; int_32 return_code = SHELL_EXIT_SUCCESS; char_ptr mode; MQX_FILE_PTR fd = NULL; char_ptr abs_path; SHELL_CONTEXT_PTR shell_ptr = Shell_get_context( argv ); int_32 error = 0; print_usage = Shell_check_help_request(argc, argv, &shorthelp ); if (!print_usage) { if ((argc < 2) || (argc > 3)) { printf("Error, invalid number of parameters\n"); return_code = SHELL_EXIT_ERROR; print_usage = TRUE; } /* check if filesystem is mounted */ else if (NULL == Shell_get_current_filesystem(argv)) { printf("Error, file system not mounted\n" ); return_code = SHELL_EXIT_ERROR; } else { if (argc != 3) { mode = "a"; } else { mode = argv[2]; } if (MFS_alloc_path(&abs_path) != MFS_NO_ERROR) { printf("Error, unable to allocate memory for paths\n" ); return_code = SHELL_EXIT_ERROR; } else { error = _io_rel2abs(abs_path,shell_ptr->CURRENT_DIR,(char *) argv[1],PATHNAME_SIZE,shell_ptr->CURRENT_DEVICE_NAME); if(!error) { fd = fopen(abs_path, mode); } MFS_free_path(abs_path); if (fd && !error) { fclose(fd); } else { printf("Error, unable to open file %s.\n", argv[1] ); return_code = SHELL_EXIT_ERROR; } } } } if (print_usage) { if (shorthelp) { printf("%s <filename> [<mode>] \n", argv[0]); } else { printf("Usage: %s <filename> [<mode>]\n", argv[0]); printf(" <filename> = filename to create\n"); printf(" <bytes> = open mode\n"); } } return return_code; } /* Endbody */