1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
15:
16:
17: 18: 19: 20: 21:
22:
23: #include "sdisk.h"
24:
25: 26: 27:
28: EXPORT void memAbort(DrvTab *drv)
29: {
30:
31: }
32:
33: 34: 35:
36: LOCAL ER memRWblks(DrvTab *drv, W blk, W cnt, void *mptr, BOOL write)
37: {
38: void* madr;
39:
40:
41: blk *= drv->SecSize;
42: cnt *= drv->SecSize;
43:
44:
45: madr = (void*)(drv->IOB + blk);
46: if (write) {
47: if (mptr != NULL) MEMCPY(madr, mptr, cnt);
48: else MEMSET(madr, 0, cnt);
49: } else {
50: MEMCPY(mptr, madr, cnt);
51: }
52: return E_OK;
53: }
54:
55: 56: 57:
58: EXPORT INT memReadWrite(DrvTab *drv, W blk, W cnt, void *mptr, BOOL write)
59: {
60: ER er;
61:
62:
63:
64:
65: er = memRWblks(drv, blk, cnt, mptr, write);
66: if (er >= E_OK) return cnt;
67: return er;
68: }
69:
70: 71: 72:
73: EXPORT ER memFormat(DrvTab *drv, DiskFormat *fmt, W dcnt)
74: {
75: ER er;
76: W blk, cnt;
77:
78: if (*fmt == DiskFmt_MEMINIT) {
79:
80: if (dcnt < sizeof(DiskFormat) + sizeof(W) * 2)
81: {er = E_PAR; goto E_EXIT;}
82:
83: fmt++;
84: blk = ((W*)fmt)[0];
85: cnt = ((W*)fmt)[1];
86: if (cnt < 0 || blk < 512 || blk > 8192 || (blk % 512) != 0)
87: {er = E_PAR; goto E_EXIT;}
88:
89: if (drv->IOB != 0) {
90: Kfree((void*)drv->IOB);
91: drv->IOB = 0;
92: }
93: er = E_OK;
94: if (cnt > 0) {
95: if ((drv->IOB = (UW)Kcalloc(blk, cnt)) == 0) {
96: er = E_NOMEM;
97: cnt = 0;
98: }
99: }
100: drv->MiscPar = cnt * blk;
101: drv->SecSize = blk;
102: drv->nXSec = drv->nSec = (cnt < 0x10000) ? cnt : 0xffff;
103: drv->s.SUnit[0].EndBlock = cnt;
104:
105: } else if (*fmt == DiskFmt_MEM) {
106:
107: blk = drv->s.SUnit[ 0].StartBlock;
108: cnt = drv->s.SUnit[ 0].EndBlock - blk;
109:
110:
111:
112:
113:
114: er = memRWblks(drv, blk, cnt, NULL, TRUE);
115: } else {
116: er = E_PAR;
117: }
118: if (er >= E_OK) return E_OK;
119:
120: E_EXIT:
121: return er;
122: }
123:
124: 125: 126:
127: EXPORT ER memIdentify(DrvTab *drv, BOOL check)
128: {
129: W sz;
130:
131:
132: drv->MediaOK = TRUE;
133:
134: if (check) return E_OK;
135:
136: sz = drv->MiscPar;
137: sz /= drv->SecSize;
138:
139:
140: drv->nXSec = drv->nSec = (sz < 0x10000) ? sz : 0xffff;
141: drv->nXHead = drv->nHead = 1;
142: drv->nXCyl = drv->nCyl = 1;
143:
144:
145: drv->s.SUnit[0].SystemId = DSID_NONE;
146: drv->s.SUnit[0].StartBlock = 0;
147: drv->s.SUnit[0].EndBlock = sz;
148: drv->s.SUnit[0].OpenCnt = 0;
149: return E_OK;
150: }
151: 152: 153:
154: EXPORT ER memDiskInit(DrvTab *drv)
155: {
156:
157: drv->nSUnit = 0;
158: return E_OK;
159: }
160: 161: 162:
163: EXPORT ER memMisc(DrvTab *drv, W cmd)
164: {
165: #if 0
166: switch(cmd) {
167: case DC_TSKINIT:
168: case DC_TSKTMO:
169: case DC_DRVCHG:
170: case DC_OPEN:
171: case DC_CLOSE:
172: case DC_CLOSEALL:
173: }
174: #endif
175: return E_OK;
176: }