source: uKadecot/trunk/pfatfs/diskio.c@ 108

Last change on this file since 108 was 108, checked in by coas-nagasima, 9 years ago

MIMEプロパティの変更

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/x-chdr; charset=SHIFT_JIS
File size: 3.8 KB
RevLine 
[101]1/*-----------------------------------------------------------------------*/
2/* PFF - Low level disk control module for Win32 (C)ChaN, 2014 */
3/*-----------------------------------------------------------------------*/
4
5#include <string.h>
6#include "pffconf.h"
7#include "diskio.h"
8
9/*--------------------------------------------------------------------------
10
11 Module Private Functions
12
13---------------------------------------------------------------------------*/
14
15#define MAX_DRIVES 1 /* Max number of physical drives to be used */
16
17#define SZ_RAMDISK 768 /* Size of RAM disk [kB] */
18#define SS_RAMDISK 512 /* Sector size of RAM disk [byte] */
19
20#ifndef _MSC_VER
21#define RamDisk ((unsigned char *)0xfff00000)
22#else
23#include <windows.h>
24#include <tchar.h>
25#include <winioctl.h>
26
27unsigned char RamDisk[SZ_RAMDISK * 1024];
28#endif
29
30typedef struct {
31 DSTATUS status;
32 WORD sz_sector;
33 DWORD wofs;
34 DWORD wip;
35 DWORD n_sectors;
36} STAT;
37
38static volatile
39STAT Stat[MAX_DRIVES];
40
41static
42BYTE Buffer[SS_RAMDISK];
43
44static
45int get_status(volatile STAT *stat) {
46 stat->sz_sector = SS_RAMDISK;
47 if(stat->sz_sector < _MIN_SS || stat->sz_sector > _MAX_SS) return 0;
48 stat->n_sectors = SZ_RAMDISK * 1024 / SS_RAMDISK;
49 stat->status = 0;
50 return 1;
51}
52
53/*-----------------------------------------------------------------------*/
54/* Initialize Disk Drive */
55/*-----------------------------------------------------------------------*/
56DSTATUS disk_initialize (void)
57{
58 DSTATUS sta;
59#ifdef _MSC_VER
60 HANDLE h;
61 DWORD br;
62
63 h = CreateFile(_T("..\\..\\..\\..\\uip\\apps\\webserver\\httpd-fs.bin"), GENERIC_READ, 0, 0, OPEN_EXISTING, 0, 0);
64 if (h != INVALID_HANDLE_VALUE) {
65 ReadFile(h, RamDisk, sizeof(RamDisk), &br, 0);
66 CloseHandle(h);
67 }
68#endif
69 get_status(&Stat[0]);
70 sta = Stat[0].status;
71 Stat[0].wip = 0;
72
73 return sta;
74}
75
76/*-----------------------------------------------------------------------*/
77/* Get Disk Status */
78/*-----------------------------------------------------------------------*/
79DSTATUS disk_get_status (void)
80{
81 return Stat[0].status;
82}
83
84/*-----------------------------------------------------------------------*/
85/* Read Partial Sector */
86/*-----------------------------------------------------------------------*/
87DRESULT disk_readp (
88 BYTE* buff, /* Data read buffer */
89 DWORD sector, /* Sector number (LBA) */
90 UINT offset, /* Offset in the sector */
91 UINT count /* Byte count */
92)
93{
94 DRESULT res;
95 int dofs;
96
97
98 if(Stat[0].status & STA_NOINIT) return RES_NOTRDY;
99
100 if(sector >= Stat[0].n_sectors || !count || offset + count > Stat[0].sz_sector/* || Stat[0].wip*/) {
101 res = RES_PARERR;
102 }
103 else {
104 if(buff) {
105 dofs = sector * Stat[0].sz_sector;
106 memcpy(buff, &RamDisk[dofs + offset], count);
107 res = RES_OK;
108 }
109 else {
110 res = RES_OK;
111 }
112 }
113
114 return res;
115}
116
117/*-----------------------------------------------------------------------*/
118/* Write Partial Sector */
119/*-----------------------------------------------------------------------*/
120DRESULT disk_writep (
121 const BYTE* buff, /* Pointer to the write data */
122 DWORD sc /* Sector number (LBA), Number of bytes to send */
123)
124{
125 DRESULT res;
126 int dofs;
127
128 if(Stat[0].status & STA_NOINIT) return RES_NOTRDY;
129
130 if(!buff) {
131 if(sc) {
132 Stat[0].wip = sc;
133 Stat[0].wofs = 0;
134 memset(Buffer, 0, sizeof Buffer);
135 res = RES_OK;
136 }
137 else {
138 if(Stat[0].wip) {
139 dofs = Stat[0].wip * Stat[0].sz_sector;
140 memcpy(RamDisk + dofs, Buffer, Stat[0].sz_sector);
141 Stat[0].wip = 0;
142 res = RES_OK;
143 }
144 else {
145 res = RES_OK;
146 }
147 }
148 }
149 else {
150 if(Stat[0].wofs + sc > Stat[0].sz_sector) sc = Stat[0].sz_sector - Stat[0].wofs;
151 memcpy(&Buffer[Stat[0].wofs], buff, sc);
152 Stat[0].wofs += sc;
153 res = RES_OK;
154 }
155
156 return res;
157}
Note: See TracBrowser for help on using the repository browser.