- mount: info printing added
This commit is contained in:
		
							parent
							
								
									9363db67f8
								
							
						
					
					
						commit
						d07827a66a
					
				@ -1,9 +1,9 @@
 | 
			
		||||
#include <stddef.h>
 | 
			
		||||
#include <memory.h>
 | 
			
		||||
#include "mount.h"
 | 
			
		||||
#include "../MassStorage.h"
 | 
			
		||||
#include "../mbr/mbr.h"
 | 
			
		||||
#include "../fs/fat32/fat32.h"
 | 
			
		||||
#include "../mbr/mbr.h"
 | 
			
		||||
#include <memory.h>
 | 
			
		||||
#include <stddef.h>
 | 
			
		||||
 | 
			
		||||
#define AUTOMOUNT_SECTOR_SIZE (512)
 | 
			
		||||
 | 
			
		||||
@ -37,8 +37,7 @@ static int mnt_mount_volume(MassStorage * mstg, const PartEntry * part) {
 | 
			
		||||
                fat32_get_volume_label(ctrl, next_entry->mnt_name, MNT_MAX_MOUNT_NAME_LENGTH); // get volume name
 | 
			
		||||
                next_entry->driver = fat32_driver;                                             // assign driver
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
            break;
 | 
			
		||||
        } break;
 | 
			
		||||
        default: // unmountable file system's found on the disk
 | 
			
		||||
            MSG("Unknown file system type: %d, cannot mount!\n", part->part_type);
 | 
			
		||||
            break;
 | 
			
		||||
@ -158,10 +157,11 @@ Mnt_Volume * mnt_get_volume_by_path(const char * volpath, const char ** path) {
 | 
			
		||||
 */
 | 
			
		||||
Mnt_File *mnt_alloc_file_helper() {
 | 
			
		||||
    Mnt_File *slot = NULL;
 | 
			
		||||
    for (uint8_t i = 0; i < MNT_MAX_OPEN_FILES; i++) {
 | 
			
		||||
    for (uint8_t i = 0; (i < MNT_MAX_OPEN_FILES) && (ftab.open_files < MNT_MAX_OPEN_FILES); i++) {
 | 
			
		||||
        if (ftab.files[i].ctrl_word == MNT_FTAB_BLOCK_FREE) {
 | 
			
		||||
            ftab.files[i].ctrl_word = MNT_FTAB_BLOCK_OCCUPIED;
 | 
			
		||||
            slot = ftab.files + i;
 | 
			
		||||
            ftab.open_files++;
 | 
			
		||||
            break;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
@ -173,7 +173,10 @@ Mnt_File * mnt_alloc_file_helper() {
 | 
			
		||||
 * @param helper pointer to helper
 | 
			
		||||
 */
 | 
			
		||||
void mnt_free_file_helper(Mnt_File *file) {
 | 
			
		||||
    if (ftab.open_files > 0) {
 | 
			
		||||
        file->ctrl_word = MNT_FTAB_BLOCK_FREE;
 | 
			
		||||
        ftab.open_files--;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// -----------------------
 | 
			
		||||
@ -212,7 +215,11 @@ Mnt_File * mnt_open(const char * path) {
 | 
			
		||||
        file = mnt_alloc_file_helper();
 | 
			
		||||
        if (file != NULL) {
 | 
			
		||||
            file->vol = vol;
 | 
			
		||||
            (vol->driver).open(vol->fs_control_block_area, relpath, file->helper);
 | 
			
		||||
            int success = (vol->driver).open(vol->fs_control_block_area, relpath, file->helper);
 | 
			
		||||
            if (success != 0) { // release file helper if could not open file
 | 
			
		||||
                mnt_free_file_helper(file);
 | 
			
		||||
                file = NULL;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    return file;
 | 
			
		||||
@ -244,3 +251,33 @@ int mnt_seek(Mnt_File * file, unsigned long pos) {
 | 
			
		||||
void mnt_close(Mnt_File *file) {
 | 
			
		||||
    mnt_free_file_helper(file);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// --------------
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Get file system name from type ID.
 | 
			
		||||
 * @param fst file system type ID
 | 
			
		||||
 * @return file system name
 | 
			
		||||
 */
 | 
			
		||||
static inline const char *mnt_fs_type_to_str(uint8_t fst) {
 | 
			
		||||
    switch (fst) {
 | 
			
		||||
        case FAT32_CHS_PART_ID:
 | 
			
		||||
        case FAT32_LBA_PART_ID:
 | 
			
		||||
            return "FAT32";
 | 
			
		||||
        default:
 | 
			
		||||
            return "N/A";
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Print state and statistical infromation.
 | 
			
		||||
 */
 | 
			
		||||
void mnt_print_info() {
 | 
			
		||||
    MSG("\n\n---- MOUNT/FILES stats ----\n");
 | 
			
		||||
    MSG(" Mounted volumes: %u\n", mtab.mounted_vols);
 | 
			
		||||
    for (uint32_t i = 0; i < mtab.mounted_vols; i++) {
 | 
			
		||||
        MSG("  /%s   %.3f MB\n", mtab.vols[i].mnt_name, mtab.vols[i].part_size * 1E-06);
 | 
			
		||||
    }
 | 
			
		||||
    MSG(" Open files: %u\n\n", ftab.open_files);
 | 
			
		||||
    MSG("---------------------------\n\n");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -31,6 +31,7 @@ typedef struct {
 | 
			
		||||
 | 
			
		||||
typedef struct {
 | 
			
		||||
    Mnt_File files[MNT_MAX_OPEN_FILES]; // file helpers
 | 
			
		||||
    uint8_t open_files; // number of open files
 | 
			
		||||
} Mnt_FileTable;
 | 
			
		||||
 | 
			
		||||
int mnt_automount_disk(MassStorage * mstg); // attempt to automount volumes
 | 
			
		||||
@ -45,4 +46,6 @@ int mnt_seek(Mnt_File * file, unsigned long pos);
 | 
			
		||||
 | 
			
		||||
void mnt_close(Mnt_File * file);
 | 
			
		||||
 | 
			
		||||
void mnt_print_info();
 | 
			
		||||
 | 
			
		||||
#endif //EMBPART_MOUNT_H
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user