int32_t Shell_flush_cache(int32_t argc, char *argv[] ) { /* Body */ bool print_usage, shorthelp = FALSE; int32_t return_code = SHELL_EXIT_SUCCESS; int fd; char *name_ptr = NULL; SHELL_CONTEXT_PTR shell_ptr = Shell_get_context(argv); 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; } else { if (argc==2) { name_ptr = argv[1]; } else { name_ptr = Shell_get_current_filesystem_name(argv); } if (_nio_supp_validate_device(name_ptr)) { fd = open(name_ptr, O_RDWR); if (0 > fd) { fprintf(shell_ptr->STDOUT, "Error, unable to access file system\n" ); return_code = SHELL_EXIT_ERROR; } else { write(fd, NULL, 0); //This flushes fd. close(fd); } } } } if (print_usage) { if (shorthelp) { fprintf(shell_ptr->STDOUT, "%s <filesys:>\n", argv[0]); } else { fprintf(shell_ptr->STDOUT, "Usage: %s <filesys:>\n", argv[0]); fprintf(shell_ptr->STDOUT, " filesys: = name of MFS file system\n"); } } return return_code; } /* Endbody */
int_32 Shell_cd(int_32 argc, char_ptr argv[] ) { /* Body */ boolean print_usage, shorthelp = FALSE, dev_in_path = FALSE; int_32 error = 0, return_code = SHELL_EXIT_SUCCESS; MQX_FILE_PTR fs_ptr; char_ptr abs_path = NULL; SHELL_CONTEXT_PTR shell_ptr = Shell_get_context( argv ); int_16 devlen = 0; 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 { if (MFS_alloc_path(&abs_path) != MFS_NO_ERROR) { printf("Error, unable to allocate memory for paths\n" ); return_code = SHELL_EXIT_ERROR; } else { devlen = _io_get_dev_for_path(abs_path, &dev_in_path, 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("Device \"%s\" not available\n", abs_path); 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) { // check if path exist error = ioctl(fs_ptr, IO_IOCTL_CHECK_DIR_EXIST,(pointer)abs_path ); } if (error) { printf("Error changing directory %s\n", argv[1]); } else { if(dev_in_path == TRUE) { // there is device name in input path //separate device name abs_path[devlen] = '\0'; Shell_set_current_filesystem_by_name(argv,abs_path); // add "\" back to the string abs_path[devlen] = '\\'; } // change shell current dir strcpy(shell_ptr->CURRENT_DIR,abs_path+devlen); } } MFS_free_path(abs_path); } } } if (print_usage) { if (shorthelp) { printf("%s <directory> \n", argv[0]); } else { printf("Usage: %s <directory>\n", argv[0]); printf(" <directory> = name of directory to change to\n"); } } return return_code; }
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 */
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; }
int32_t Shell_cache(int32_t argc, char *argv[] ) { SHELL_CONTEXT_PTR shell_ptr = Shell_get_context(argv); bool print_usage, shorthelp = FALSE; int32_t return_code = SHELL_EXIT_SUCCESS; int32_t i; int fd; char *name_ptr = NULL; bool on = TRUE; print_usage = Shell_check_help_request(argc, argv, &shorthelp ); if (!print_usage) { if (argc > 3) { fprintf(shell_ptr->STDOUT, "Error, invalid number of parameters\n"); return_code = SHELL_EXIT_ERROR; print_usage=TRUE; } else { for (i=1;i<argc;i++) { if (strcmp("on", argv[i])==0) { on = TRUE; } else if (strcmp("off", argv[i])==0) { on = FALSE; } else if (_nio_supp_validate_device(argv[i])) { name_ptr = argv[i]; } else { fprintf(shell_ptr->STDOUT, "Error, invalid parameter\n"); return_code = SHELL_EXIT_ERROR; print_usage = TRUE; break; } } if (return_code == SHELL_EXIT_SUCCESS) { if (name_ptr==NULL) { name_ptr = Shell_get_current_filesystem_name(argv); } fd = open(name_ptr, O_RDWR); if (0 > fd) { fprintf(shell_ptr->STDOUT, "Error, unable to access file system\n" ); return_code = SHELL_EXIT_ERROR; } else { if (0 > ioctl(fd, (on ? IO_IOCTL_WRITE_CACHE_ON : IO_IOCTL_WRITE_CACHE_OFF), NULL)) { fprintf(shell_ptr->STDOUT, "Error, unable to set cache\n" ); } close(fd); } } } } if (print_usage) { if (shorthelp) { fprintf(shell_ptr->STDOUT, "%s [on|off] [<filesys:>]\n", argv[0]); } else { fprintf(shell_ptr->STDOUT, "Usage: %s [on|off] [<filesys:>]\n", argv[0]); fprintf(shell_ptr->STDOUT, " <filesys:> = name of MFS file system\n"); } } return return_code; }