1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
#include <dolphin/card.h>
#include "__card.h"
s32 __CARDRawReadAsync(s32 chan, void* buf, s32 length, s32 offset, CARDCallback callback) {
CARDControl* card;
s32 result;
ASSERTLINE(59, buf && ((u32) buf % 32) == 0);
result = __CARDGetControlBlock(chan, &card);
if (result < 0) {
return __CARDPutControlBlock(card, result);
}
ASSERTLINE(67, 0 < length && (length % CARD_SEG_SIZE) == 0 && length < CARD_MAX_SIZE);
ASSERTLINE(68, (offset % card->sectorSize) == 0);
DCInvalidateRange(buf, length);
result = __CARDRead(chan, offset, length, buf, callback);
if (result < 0) {
__CARDPutControlBlock(card, result);
}
return result;
}
s32 __CARDRawRead(s32 chan, void* buf, s32 length, s32 offset) {
s32 result = __CARDRawReadAsync(chan, buf, length, offset, __CARDSyncCallback);
if (result < 0) {
return result;
}
return __CARDSync(chan);
}
static void EraseCallback(s32 chan, s32 result) {
CARDControl* card;
CARDCallback callback;
card = &__CARDBlock[chan];
callback = card->apiCallback;
card->apiCallback = NULL;
__CARDPutControlBlock(card, result);
ASSERTLINE(117, callback);
callback(chan, result);
}
s32 __CARDRawEraseAsync(s32 chan, s32 offset, CARDCallback callback) {
CARDControl* card;
s32 result;
result = __CARDGetControlBlock(chan, &card);
if (result < 0) {
return __CARDPutControlBlock(card, result);
}
if (offset % card->sectorSize) {
return __CARDPutControlBlock(card, CARD_RESULT_FATAL_ERROR);
}
if ((card->size * 1024 * 1024) / 8 <= offset) {
return __CARDPutControlBlock(card, CARD_RESULT_LIMIT);
}
card->apiCallback = callback ? callback : __CARDDefaultApiCallback;
result = __CARDEraseSector(chan, offset, EraseCallback);
if (result < 0) {
__CARDPutControlBlock(card, result);
}
return result;
}
s32 __CARDRawErase(s32 chan, s32 offset) {
s32 result = __CARDRawEraseAsync(chan, offset, __CARDSyncCallback);
if (result < 0) {
return result;
}
return __CARDSync(chan);
}
|