bytetolba.c
1.4 KB
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
#include <ultra64.h>
#include "../org/include/leodefine.h"
#include "../org/include/leodrive.h"
#ifndef _LONGCMD
#include <leo.h>
#else
#include <leosp.h>
#endif
extern s32 __leoActive;
/* export from leo_tbl.c */
extern u16 LEOVZONE_TBL[DISK_TYPES][VZONES_PER_DRV];
extern u16 LEOBYTE_TBL2[ZONES_PER_DRV];
extern u8 LEOVZONE_PZONEHD_TBL[DISK_TYPES][VZONES_PER_DRV];
extern u8 LEOdisk_type;
extern u16 leoLba_to_vzone(u32 lba);
s32 LeoByteToLBA(s32 startlba, u32 nbytes, s32 *lba)
{
u32 reslba;
u32 byte_p_blk;
u16 zone,vzone;
u8 flag;
/*
* Check for existence of Leo Manager
*/
if (!__leoActive) {
return(-1);
}
#ifdef _DEBUG
if (startlba > MAX_L_LBA)
return LEO_ERROR_LBA_OUT_OF_RANGE;
#endif
reslba = 0;
flag = vzone = 1;
/*
* Add system blocks
*/
startlba += 24;
while (nbytes)
{
if (flag
|| (startlba == LEOVZONE_TBL[LEOdisk_type][vzone]))
{
vzone = leoLba_to_vzone(startlba);
zone = LEOVZONE_PZONEHD_TBL[LEOdisk_type][vzone];
if (zone > (u8)7)
zone -= (u8)7;
byte_p_blk = LEOBYTE_TBL2[zone];
}
if (nbytes < byte_p_blk)
nbytes = 0;
else
nbytes -= byte_p_blk;
reslba++;
startlba++;
if ((nbytes) && (startlba > (u32)MAX_P_LBA))
return LEO_ERROR_LBA_OUT_OF_RANGE;
flag = 0;
}
*lba = reslba;
return LEO_ERROR_GOOD;
} /* LeoByteToLBA() */