o get mmap image working

This commit is contained in:
David Voswinkel 2009-05-24 20:28:10 +02:00
parent c8afff5630
commit ce5d1de968
5 changed files with 56 additions and 32 deletions

View File

@ -14,4 +14,5 @@ $(bin): $(objs)
gcc $(cflags) -c $<
clean:
rm $(bin) *.o

View File

@ -19,6 +19,18 @@ filesize 4194304
*/
/*
mkfs.vfat 3.0.1 (23 Nov 2008)
disk00.vfat has 64 heads and 32 sectors per track,
logical sector size is 512,
using 0xf8 media descriptor, with 8192 sectors;
file system has 2 12-bit FATs and 4 sectors per cluster.
FAT size is 6 sectors, and provides 2036 clusters.
Root directory contains 512 slots.
Volume ID is 7b45fab8, no volume label.
*/
/* Interface
** Scratch Buffer
@ -46,9 +58,18 @@ return 1 byte
/* Initialize Disk Drive */
/*-----------------------------------------------------------------------*/
#define IMAGE_NAME "disk00.vfat"
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/mman.h>
int image_addr;
#define IMAGE_NAME "disk01.vfat"
int *image_addr;
DSTATUS disk_initialize (BYTE drv) {
if (drv) return STA_NOINIT; /* Supports only single drive */
@ -57,13 +78,24 @@ DSTATUS disk_initialize (BYTE drv) {
/* map image */
int fd = open(IMAGE_NAME, O_RDWR);
if (fd == -1) {
perror("Error opening file for writing");
exit(EXIT_FAILURE);
}
int fd = open(IMAGE_NAME,);
int size = fseek(END);
fseek(0);
image_addr = mmap(0,fd,)
int size = lseek(fd,0,SEEK_END);
lseek(fd,0,SEEK_SET);
printf("Open Image (size %i)\n",size);
//image_addr = mmap(0,fd,)
image_addr = mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
if (image_addr == MAP_FAILED) {
close(fd);
perror("Error mmapping the file");
exit(EXIT_FAILURE);
}
Stat &= ~STA_NOINIT; /* When device goes ready, clear STA_NOINIT */
return Stat;
@ -95,23 +127,12 @@ DRESULT disk_read (
if (drv || !count) return RES_PARERR;
if (Stat & STA_NOINIT) return RES_NOTRDY;
printf("disk_read: sector=%i count=%i\n",sector,count);
DWORD offset = sector * 512;
DWORD size = count * 512;
int size = count * 512;
printf("disk_read: addr=%p offset=%i size=%i\n",image_addr,offset,size);
printf("disk_read: sector=%li count=%i addr=%p size=%i\n",sector,count,image_addr + offset,size);
memcpy(buff,image_addr + offset,size);
/* Issue Read Setor(s) command */
/*
write_ata(REG_COUNT, count);
write_ata(REG_SECTOR, (BYTE)sector);
write_ata(REG_CYLL, (BYTE)(sector >> 8));
write_ata(REG_CYLH, (BYTE)(sector >> 16));
write_ata(REG_DEV, ((BYTE)(sector >> 24) & 0x0F) | LBA);
write_ata(REG_COMMAND, CMD_READ);
*/
//printf("%x %x %x %x\n",buff[0],buff[1],buff[2],buff[3]);
return RES_OK;
}

View File

@ -25,7 +25,7 @@
#ifndef _FATFS
#define _FATFS
#define _WORD_ACCESS 1
#define _WORD_ACCESS 0
/* The _WORD_ACCESS option defines which access method is used to the word
/ data in the FAT structure.
/
@ -64,7 +64,7 @@
/* To enable string functions, set _USE_STRFUNC to 1 or 2. */
#define _USE_MKFS 1
#define _USE_MKFS 0
/* To enable f_mkfs function, set _USE_MKFS to 1 and set _FS_READONLY to 0 */
@ -72,7 +72,7 @@
/* To enable f_forward function, set _USE_FORWARD to 1 and set _FS_TINY to 1. */
#define _DRIVES 2
#define _DRIVES 1
/* Number of volumes (logical drives) to be used. */
@ -81,13 +81,13 @@
/* 512 for memroy card and hard disk, 1024 for floppy disk, 2048 for MO disk */
#define _MULTI_PARTITION 0
#define _MULTI_PARTITION 1
/* When _MULTI_PARTITION is set to 0, each volume is bound to the same physical
/ drive number and can mount only first primaly partition. When it is set to 1,
/ each volume is tied to the partitions listed in Drives[]. */
#define _CODE_PAGE 932
#define _CODE_PAGE 858
/* The _CODE_PAGE specifies the OEM code page to be used on the target system.
/ When it is non LFN configuration, there is no difference between SBCS code
/ pages. When LFN is enabled, the code page must always be set correctly.

Binary file not shown.

View File

@ -54,7 +54,8 @@ DWORD get_fattime ()
struct tm * ptm;
time ( &rawtime );
ptm = gmtime ( &rawtime );
return ((DWORD)(ptm->tm_year - 80) << 25)
return ((DWORD)(ptm->tm_year - 80) << 25)
| ((DWORD)(ptm->tm_mon +1) << 21)
| ((DWORD)ptm->tm_mday << 16)
| ((DWORD)ptm->tm_hour << 11)
@ -117,6 +118,7 @@ FRESULT scan_files (char* path)
if ((res = f_opendir(&dirs, path)) == FR_OK) {
i = strlen(path);
printf("Ok\n");
while (((res = f_readdir(&dirs, &finfo)) == FR_OK) && finfo.fname[0]) {
if (finfo.fattrib & AM_DIR) {
acc_dirs++;
@ -130,7 +132,7 @@ FRESULT scan_files (char* path)
}
}
}
printf("scan_files ret\n");
return res;
}
@ -157,7 +159,7 @@ void _put_rc (FRESULT rc)
"MKFS_ABORTED",
"TIMEOUT"
};
printf("rc=%u FR_%s\n", (WORD)rc, str[rc]);
printf("rc=%i FR_%s\n", (WORD)rc, str[rc]);
}
static
@ -173,7 +175,7 @@ void put_rc (FRESULT rc)
for (p = str, i = 0; i != rc && *p; i++) {
while(*p++);
}
xprintf("rc=%u FR_%s\n", (WORD)rc, p);
printf("rc=%u FR_%s\n", (WORD)rc, p);
}