Automount initial steps
This commit is contained in:
		
							parent
							
								
									8b8dcbe170
								
							
						
					
					
						commit
						af2db137f9
					
				@ -12,4 +12,7 @@ add_library(embpart embpart.c
 | 
				
			|||||||
        MassStorage.c
 | 
					        MassStorage.c
 | 
				
			||||||
        MassStorage.h
 | 
					        MassStorage.h
 | 
				
			||||||
        file_interface.c
 | 
					        file_interface.c
 | 
				
			||||||
        file_interface.h)
 | 
					        file_interface.h
 | 
				
			||||||
 | 
					        mount/mount.c
 | 
				
			||||||
 | 
					        mount/mount.h
 | 
				
			||||||
 | 
					        fs/fs_driver.h)
 | 
				
			||||||
@ -1,7 +1,3 @@
 | 
				
			|||||||
//
 | 
					 | 
				
			||||||
// Created by epagris on 2023.09.28..
 | 
					 | 
				
			||||||
//
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#include <memory.h>
 | 
					#include <memory.h>
 | 
				
			||||||
#include <stdbool.h>
 | 
					#include <stdbool.h>
 | 
				
			||||||
#include "fat32.h"
 | 
					#include "fat32.h"
 | 
				
			||||||
@ -655,3 +651,7 @@ uint32_t fat32_read_file_stream(const Fat32_CtrlBlock *ctrl, Fat32_FileHelper *f
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    return read_len;
 | 
					    return read_len;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// ----------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Fs_Driver fat32_driver = { (fs_drv_open) fat32_open_file };
 | 
				
			||||||
@ -6,6 +6,7 @@
 | 
				
			|||||||
#ifdef __linux
 | 
					#ifdef __linux
 | 
				
			||||||
#include <stdio.h>
 | 
					#include <stdio.h>
 | 
				
			||||||
#include "../../MassStorage.h"
 | 
					#include "../../MassStorage.h"
 | 
				
			||||||
 | 
					#include "../fs_driver.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define MSG(...) printf(__VA_ARGS__)
 | 
					#define MSG(...) printf(__VA_ARGS__)
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
@ -100,12 +101,14 @@ typedef struct {
 | 
				
			|||||||
} Fat32_SeekHint;
 | 
					} Fat32_SeekHint;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
typedef struct {
 | 
					typedef struct {
 | 
				
			||||||
    const Fat32_CtrlBlock * ctrl; // pointer FAT32 control block
 | 
					    const Fat32_CtrlBlock * ctrl; // pointer to FAT32 control block
 | 
				
			||||||
    Fat32_SeekHint last_pos; // last read position
 | 
					    Fat32_SeekHint last_pos; // last read position
 | 
				
			||||||
    uint32_t entry_ba; // FileEntry byte address on the mass storage
 | 
					    uint32_t entry_ba; // FileEntry byte address on the mass storage
 | 
				
			||||||
    uint32_t size; // file size
 | 
					    uint32_t size; // file size
 | 
				
			||||||
} Fat32_FileHelper;
 | 
					} Fat32_FileHelper;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					extern Fs_Driver fat32_driver;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int fat32_load(Fat32_CtrlBlock *ctrl, uint32_t bpb_s, const MassStorage * mstg);
 | 
					int fat32_load(Fat32_CtrlBlock *ctrl, uint32_t bpb_s, const MassStorage * mstg);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int fat32_list_dir(const Fat32_CtrlBlock *ctrl, const char * dir);
 | 
					int fat32_list_dir(const Fat32_CtrlBlock *ctrl, const char * dir);
 | 
				
			||||||
@ -120,4 +123,5 @@ uint32_t fat32_seek_stream(const Fat32_CtrlBlock *ctrl, uint32_t pos, Fat32_File
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
uint32_t fat32_read_file_stream(const Fat32_CtrlBlock *ctrl, Fat32_FileHelper *file_helper, uint32_t len, uint8_t *p);
 | 
					uint32_t fat32_read_file_stream(const Fat32_CtrlBlock *ctrl, Fat32_FileHelper *file_helper, uint32_t len, uint8_t *p);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif //EMBPART_FAT32_H
 | 
					#endif //EMBPART_FAT32_H
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										15
									
								
								fs/fs_driver.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								fs/fs_driver.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,15 @@
 | 
				
			|||||||
 | 
					#ifndef EMBPART_FS_DRIVER_H
 | 
				
			||||||
 | 
					#define EMBPART_FS_DRIVER_H
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					typedef int (*fs_drv_open)(const void * ctrl, const char * path, void * file);
 | 
				
			||||||
 | 
					typedef int (*fs_drv_seek)(const void * ctrl, void * file, unsigned long pos);
 | 
				
			||||||
 | 
					typedef int (*fs_drv_read)(const void * ctrl, void * file, unsigned long len, void * buf);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// File system driver
 | 
				
			||||||
 | 
					typedef struct {
 | 
				
			||||||
 | 
					    fs_drv_open open;
 | 
				
			||||||
 | 
					    fs_drv_seek seek;
 | 
				
			||||||
 | 
					    fs_drv_read read;
 | 
				
			||||||
 | 
					} Fs_Driver;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#endif //EMBPART_FS_DRIVER_H
 | 
				
			||||||
							
								
								
									
										13
									
								
								mbr/mbr.c
									
									
									
									
									
								
							
							
						
						
									
										13
									
								
								mbr/mbr.c
									
									
									
									
									
								
							@ -1,7 +1,18 @@
 | 
				
			|||||||
#include "mbr.h"
 | 
					#include "mbr.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <stddef.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define MBR_PART_TABLE_OFFSET (446)
 | 
					#define MBR_PART_TABLE_OFFSET (446)
 | 
				
			||||||
 | 
					#define MBR_BOOT_SIGNATURE_OFFSET (510)
 | 
				
			||||||
 | 
					#define MBR_BOOT_SIGNATURE0 (0x55)
 | 
				
			||||||
 | 
					#define MBR_BOOT_SIGNATURE1 (0xAA)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const PartEntry *mbr_get_partitions(const uint8_t *mbr_sec) {
 | 
					const PartEntry *mbr_get_partitions(const uint8_t *mbr_sec) {
 | 
				
			||||||
    return (PartEntry *)(mbr_sec + MBR_PART_TABLE_OFFSET);
 | 
					    // check if disk is MBR type
 | 
				
			||||||
 | 
					    if ((mbr_sec[MBR_BOOT_SIGNATURE_OFFSET] != MBR_BOOT_SIGNATURE0) ||
 | 
				
			||||||
 | 
					        (mbr_sec[MBR_BOOT_SIGNATURE_OFFSET + 1] != MBR_BOOT_SIGNATURE1)) {
 | 
				
			||||||
 | 
					        return NULL; // if not
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					        return (PartEntry *) (mbr_sec + MBR_PART_TABLE_OFFSET); // if it is
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -12,7 +12,7 @@ typedef struct {
 | 
				
			|||||||
    uint8_t chsa_la[3]; // CHS address of last absolute sector in partition
 | 
					    uint8_t chsa_la[3]; // CHS address of last absolute sector in partition
 | 
				
			||||||
    uint32_t lba_fa; // LBA of first absolute sector
 | 
					    uint32_t lba_fa; // LBA of first absolute sector
 | 
				
			||||||
    uint32_t sector_count; // number of sectors the partition includes
 | 
					    uint32_t sector_count; // number of sectors the partition includes
 | 
				
			||||||
} PartEntry;
 | 
					} __attribute__((packed)) PartEntry;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Get pointer to partition table
 | 
					 * Get pointer to partition table
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										5
									
								
								mount/mount.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								mount/mount.c
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,5 @@
 | 
				
			|||||||
 | 
					#include "mount.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int mnt_automount_disk() {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										19
									
								
								mount/mount.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								mount/mount.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,19 @@
 | 
				
			|||||||
 | 
					#ifndef EMBPART_MOUNT_H
 | 
				
			||||||
 | 
					#define EMBPART_MOUNT_H
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <stdint.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define MNT_MAX_MOUNTED_VOLUMES (4)
 | 
				
			||||||
 | 
					#define MNT_MAX_MOUNT_NAME_LENGTH (15)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					typedef struct {
 | 
				
			||||||
 | 
					    void * fs_control_block; // pointer to file system control block
 | 
				
			||||||
 | 
					    uint32_t part_size; // partition size
 | 
				
			||||||
 | 
					    char mnt_name[MNT_MAX_MOUNT_NAME_LENGTH + 1]; // name of the mount
 | 
				
			||||||
 | 
					} Mnt_MountEntry;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					typedef struct {
 | 
				
			||||||
 | 
					    Mnt_MountEntry vols[MNT_MAX_MOUNTED_VOLUMES]; // volume slots
 | 
				
			||||||
 | 
					} Mnt_MountTable;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#endif //EMBPART_MOUNT_H
 | 
				
			||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user