示例#1
0
/*
** Function used to init session structure
**
** IN:
**      FTPSRV_SESSION_STRUCT* session - session structure pointer
**      FTPSRV_STRUCT *server - pointer to server structure (needed for session parameters)
**      const int sock - socket handle used for communication with client
**
** OUT:
**      none
**
** Return Value: 
**      none
*/
static void ftpsrv_ses_init(FTPSRV_STRUCT *server, FTPSRV_SESSION_STRUCT *session, const int sock)
{
    if (server && session)
    {
        /* Some buffer of arbitrary size so we can get filesystem pointer */
        char      dev_name[16] = {0};

        /* Init session structure */
        session->control_sock = sock;
        session->connected = TRUE;
        session->auth_tbl = server->params.auth_table;
        session->root_dir = (char*) server->params.root_dir;
        session->cur_dir = RTCS_mem_alloc_zero(sizeof("\\"));
        session->cur_dir[0] = '\\';
        session->start_time = RTCS_time_get();

        _io_get_dev_for_path(dev_name, NULL, 16, session->root_dir, NULL);
        session->fs_ptr = _io_get_fs_by_name(dev_name);
        session->msg_queue = RTCS_mem_alloc_zero(sizeof(LWMSGQ_STRUCT) + FTPSRV_NUM_MESSAGES*sizeof(FTPSRV_TRANSFER_MSG)*sizeof(_mqx_max_type));
        if (session->msg_queue != NULL)
        {
            _lwmsgq_init(session->msg_queue, FTPSRV_NUM_MESSAGES, sizeof(FTPSRV_TRANSFER_MSG)/sizeof(_mqx_max_type));
        }
    }
}
示例#2
0
int32_t  Shell_format(int32_t argc, char *argv[] )
{ /* Body */
   bool                    print_usage, shorthelp = FALSE;
   int32_t                     return_code = SHELL_EXIT_SUCCESS;
   int32_t                     error_code = IO_ERROR;
   MQX_FILE_PTR               fs_ptr = NULL;
   char                   *volume_ptr[SFILENAME_SIZE];
   uint64_t                    big_number;
   uint32_t                    small_number;
   
   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;
      } else  {
         if (argc == 3)  {
            memcpy (volume_ptr, argv[2], SFILENAME_SIZE);
         } else  {
            volume_ptr[0] = 0;
         }
         fs_ptr = _io_get_fs_by_name(argv[1]);
         if (fs_ptr == NULL)  {
            printf("Error, file system %s not found\n", argv[1] );
            return_code = SHELL_EXIT_ERROR;
         } else {
            printf("\nFormatting...\n");
            error_code = ioctl(fs_ptr, IO_IOCTL_DEFAULT_FORMAT,  NULL);
            if ( !error_code && (*volume_ptr)) {
               error_code = ioctl(fs_ptr, IO_IOCTL_SET_VOLUME,  (void *) volume_ptr);
            }       
            if (error_code) {
               printf("Error while formatting: 0x%x\n", error_code);
            } else  {
               /* print disk information */
               error_code = ioctl(fs_ptr, IO_IOCTL_GET_VOLUME, (uint32_t*)volume_ptr);
               printf("Done. Volume name is %s\n", volume_ptr);
               ioctl(fs_ptr, IO_IOCTL_FREE_SPACE, &big_number);
               for (small_number = 0; big_number > 128 * 1024; big_number >>= 10) small_number++;
               printf("Free disk space: %lu %s\n", (uint32_t)big_number, BYTE_SIZES[small_number]);
            } 
         }
      }
   }
      
   if (print_usage)  {
      if (shorthelp)  {
         printf("%s <drive:> [<volume label>]\n", argv[0]);
      } else  {
         printf("Usage: %s <drive:> [<volume label>]\n", argv[0]);
         printf("   <drive:> = specifies the drive name (followed by a colon)\n");
         printf("   <volume label>  = specifies the volume label\n");
      }
   }
   return return_code;
}
示例#3
0
文件: fs_walker.c 项目: NeoXiong/MP3
/*
 * Get next short file name in alphabatic order.
 * 
 * file_name: 	full path name, will be update if file found, 
 *				it is expected that the caller should clear it before the calling. 
 */
int get_next_file_name(char_ptr dir, char_ptr file_name) {
	MQX_FILE_PTR fs_ptr = NULL;

	mfs_dir_set_callback(NULL, cb_file);
	set_search_direction(DIR_SEARCH_DIRECTION_NEXT);

	fs_ptr = _io_get_fs_by_name(dir);

	mfs_dir_r(fs_ptr, dir);

	if (tmp_file_name[0] != '\0') {
		if (0 != strcmp(cur_file_name, tmp_file_name)) { //update cur_file_name
			strcpy(cur_file_name, tmp_file_name);
		}
		// reset the tmp_file_name for next search
		tmp_file_name[0] = '\0';
	}

	if ((cur_file_name[0] != '\0') && // something found, there is possibility 
									   //that the cur_file_name was not updated.
			(0 == strcmp(name_record, cur_file_name))) { //to the end

		// reset cur_file_name for a new search from the beginning
		cur_file_name[0] = '\0';
		mfs_dir_r(fs_ptr, dir); // re-search from the beginning

		if (tmp_file_name[0] != '\0') {
			if (0 != strcmp(cur_file_name, tmp_file_name)) {
				strcpy(cur_file_name, tmp_file_name);
			}
			tmp_file_name[0] = '\0';
		}
	}

	if (cur_file_name[0] != '\0') { //someting found
		strcpy(name_record, cur_file_name);
		strcpy(file_name, path_name); // path_name is like "a:\*"
		file_name[strlen(file_name) - 1] = '\0'; // remove the "*"
		strcat(file_name, cur_file_name);
	}

	return 0;
}
示例#4
0
文件: fs_walker.c 项目: NeoXiong/MP3
int get_prev_file_name(char_ptr dir, char_ptr file_name) {
	MQX_FILE_PTR fs_ptr = NULL;

	mfs_dir_set_callback(NULL, cb_file);
	set_search_direction(DIR_SEARCH_DIRECTION_PREV);

	fs_ptr = _io_get_fs_by_name(dir);

	mfs_dir_r(fs_ptr, dir);

	if (tmp_file_name[0] != '\0') {
		if (0 != strcmp(cur_file_name, tmp_file_name)) {
			strcpy(cur_file_name, tmp_file_name);
		}
		tmp_file_name[0] = '\0';
	}

	if ((cur_file_name[0] != '\0') && // something found
			(0 == strcmp(name_record, cur_file_name))) { //to the beginning
		// reset cur_file_name to a max value for a new search from the ending
		cur_file_name[0] = 0xFF;
		mfs_dir_r(fs_ptr, dir); // re-search from the beginning

		if (tmp_file_name[0] != '\0') {
			if (0 != strcmp(cur_file_name, tmp_file_name)) {
				strcpy(cur_file_name, tmp_file_name);
			}
			tmp_file_name[0] = '\0';
		}
	}

	if (cur_file_name[0] != '\0' && cur_file_name[0] != 0xFF) { //someting found
		strcpy(name_record, cur_file_name);

		strcpy(file_name, path_name); // path_name is like "a:\*"
		file_name[strlen(file_name) - 1] = '\0'; // remove the "*"
		strcat(file_name, cur_file_name);
	}

	return 0;
}
示例#5
0
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;
}
示例#6
0
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;
}
示例#7
0
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 */