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_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 */
int32_t ftpsrv_list(FTPSRV_SESSION_STRUCT* session) { int32_t length; char* path; void* dir_ptr; uint32_t sock; char* dir_param; char* full_path; char* temp; uint32_t path_length; uint32_t wrong_path; if (session->cmd_arg == NULL) { path = ""; } else { rtcs_url_decode(session->cmd_arg); path = rtcs_path_strip_delimiters(session->cmd_arg); } /* Translate relative path to absolute. */ full_path = ftpsrv_get_full_path(session, path, &wrong_path); if (full_path == NULL) { if (wrong_path) { session->message = (char*) ftpsrvmsg_no_file; } else { session->message = (char*) ftpsrvmsg_no_memory; } return(FTPSRV_ERROR); } path_length = strlen(full_path); /* Allocate space for path + appendix, copy full path and add appendix to it. */ /* This is required because MFS cannot list directories, only files. */ temp = RTCS_mem_alloc_zero(path_length+sizeof(FTPSRV_PATH_APPENDIX)); _mem_copy(full_path, temp, path_length); _mem_copy(FTPSRV_PATH_APPENDIX, temp+path_length, sizeof(FTPSRV_PATH_APPENDIX)-1); _mem_free(full_path); full_path = temp; /* Open directory. Unix format for LIST command, simple file list for NLIST. */ if (!strcmp(session->command, "LIST")) { /* Unix */ dir_param = "u*"; } else { /* File list */ dir_param = "f*"; } /* Open directory, get list, cleanup and return. */ dir_ptr = _io_mfs_dir_open(session->fs_ptr, full_path, dir_param); if (dir_ptr == NULL) { session->message = (char*) ftpsrvmsg_no_file; return(FTPSRV_ERROR); } /* Send initialization message */ ftpsrv_send_msg(session, ftpsrvmsg_opening_datacon); /* Open data connection */ sock = ftpsrv_open_data_connection(session); if (sock == RTCS_SOCKET_ERROR) { session->message = (char*) ftpsrvmsg_locerr; _mem_free(full_path); _io_mfs_dir_close(dir_ptr); return(FTPSRV_ERROR); } /* Send data (directory listing). */ while ((length = _io_mfs_dir_read(dir_ptr, session->buffer, FTPSRV_BUF_SIZE)) > 0) { /* If we are in root do not list "one level up" nor "current dir" link */ if ((strstr(session->buffer, " .. ") || strstr(session->buffer, " . ")) && !strcmp(session->cur_dir, "\\")) { _mem_zero(session->buffer, length); } else { if (send(sock, session->buffer, length, 0) != length) { ftpsrv_send_msg(session, ftpsrvmsg_writefail); break; } } } /* Cleanup */ closesocket(sock); _io_mfs_dir_close(dir_ptr); _mem_free(full_path); session->message = (char*) ftpsrvmsg_trans_complete; return FTPSRV_OK; }