-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathStMichael_mbr_check.c
99 lines (83 loc) · 2.26 KB
/
StMichael_mbr_check.c
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/* Saint Michael, Linux Kernel Module -> mbr checks
* Verions: 0.12
*
* October 22, 2005
*
*
* Copyright (C) 2005 Rodrigo Rubira Branco ([email protected])
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
* USA.
*
*
*
*/
#include <linux/module.h>
#include <linux/kernel.h>
#include <asm/io.h> /* functions inb(), outb() - StMichael_mbr_check.c */
#include <linux/delay.h> /* macro ndelay() */
#include "StMichael_mbr.h"
#ifdef MBRCHECK
/*
Return value:
0 - Sucess
>0 - Error code
*/
int mbr_read( short *inbuf )
{
int timeout, status, error, i;
timeout = 1000;
do
{
status = inb( IDE_STATUS );
if ( (status & 0x88 ) == 0x00 )
break;
} while ( --timeout );
if ( ! timeout )
return -EBUSY;
outb( 0xE0, IDE_DEVICE ); // master disk, LBA addressing
ndelay( 400 ); // delay for 400 nanoseconds
status = inb( IDE_STATUS );
if ( unlikely((status & 0xC8 ) != 0x40 ))
return -EFAULT;
outb( 1, IDE_SECTOR_COUNT );
outb( 0, IDE_SECTOR_LOW );
outb( 0, IDE_SECTOR_MID );
outb( 0, IDE_SECTOR_HIGH );
outb( 0xE0, IDE_DEVICE );
outb( CMD_READ_SECTOR, IDE_COMMAND );
error = 0;
ndelay( 400 ); // delay for 400 nanoseconds
status = inb( IDE_STATUS ); // was any error info posted?
if ( (status & 0x81) == 0x01 )
{
error = inb( IDE_ERROR );
return error;
}
timeout = 1000000;
do
{
status = inb( IDE_STATUS );
if ( (status & 0x88) == 0x08 )
break;
} while ( --timeout );
if ( ! timeout )
return -EFAULT;
for (i = 0; i < 256; i++)
inbuf[i] = inw( IDE_DATA );
status = inb( IDE_STATUS );
return 0; //SUCCESS
}
#endif