]>
Commit | Line | Data |
---|---|---|
1 | --- grub-0.95/grub/asmstub.c.odirect 2004-11-30 16:58:06.577019488 -0500 | |
2 | +++ grub-0.95/grub/asmstub.c 2004-11-30 16:59:56.057375944 -0500 | |
3 | @@ -53,6 +53,9 @@ | |
4 | # ifndef BLKFLSBUF | |
5 | # define BLKFLSBUF _IO (0x12,97) /* flush buffer cache */ | |
6 | # endif /* ! BLKFLSBUF */ | |
7 | +# ifndef O_DIRECT | |
8 | +# define O_DIRECT 040000 | |
9 | +# endif /* ! O_DIRECT */ | |
10 | #endif /* __linux__ */ | |
11 | ||
12 | /* We want to prevent any circularararity in our stubs, as well as | |
13 | @@ -764,7 +767,7 @@ | |
14 | { | |
15 | /* The unpartitioned device name: /dev/XdX */ | |
16 | char *devname = device_map[drive]; | |
17 | - char buf[512]; | |
18 | + char * buf, * buf_unaligned; | |
19 | ||
20 | if (! devname) | |
21 | return -1; | |
22 | @@ -775,13 +778,13 @@ | |
23 | ||
24 | /* Open read/write, or read-only if that failed. */ | |
25 | if (! read_only) | |
26 | - disks[drive].flags = open (devname, O_RDWR); | |
27 | + disks[drive].flags = open (devname, O_RDWR | O_DIRECT); | |
28 | ||
29 | if (disks[drive].flags == -1) | |
30 | { | |
31 | if (read_only || errno == EACCES || errno == EROFS || errno == EPERM) | |
32 | { | |
33 | - disks[drive].flags = open (devname, O_RDONLY); | |
34 | + disks[drive].flags = open (devname, O_RDONLY | O_DIRECT); | |
35 | if (disks[drive].flags == -1) | |
36 | { | |
37 | assign_device_name (drive, 0); | |
38 | @@ -795,6 +798,10 @@ | |
39 | } | |
40 | } | |
41 | ||
42 | + buf_unaligned = malloc((512 * sizeof(char)) + 4095); | |
43 | + buf = (char *) (((unsigned long)buf_unaligned + 4096 - 1) & | |
44 | + (~(4096-1))); | |
45 | + | |
46 | /* Attempt to read the first sector. */ | |
47 | if (read (disks[drive].flags, buf, 512) != 512) | |
48 | { | |
49 | @@ -806,6 +813,7 @@ | |
50 | ||
51 | if (disks[drive].flags != -1) | |
52 | get_drive_geometry (&disks[drive], device_map, drive); | |
53 | + free(buf_unaligned); | |
54 | } | |
55 | ||
56 | if (disks[drive].flags == -1) | |
57 | @@ -827,24 +835,34 @@ | |
58 | nread (int fd, char *buf, size_t len) | |
59 | { | |
60 | int size = len; | |
61 | + char * buf_unaligned, * buff, * obuff; | |
62 | + int ret; | |
63 | + | |
64 | + buf_unaligned = malloc((len * sizeof(char)) + 4095); | |
65 | + obuff = buff = (char *) (((unsigned long)buf_unaligned + 4096 - 1) & | |
66 | + (~(4096-1))); | |
67 | + | |
68 | ||
69 | while (len) | |
70 | { | |
71 | - int ret = read (fd, buf, len); | |
72 | + ret = read (fd, buff, len); | |
73 | ||
74 | if (ret <= 0) | |
75 | { | |
76 | if (errno == EINTR) | |
77 | continue; | |
78 | else | |
79 | - return ret; | |
80 | + break; | |
81 | } | |
82 | ||
83 | len -= ret; | |
84 | - buf += ret; | |
85 | + buff += ret; | |
86 | } | |
87 | ||
88 | - return size; | |
89 | + if (!len) ret = size; | |
90 | + | |
91 | + buf = memcpy(buf, obuff, size); | |
92 | + return ret; | |
93 | } | |
94 | ||
95 | /* Write LEN bytes from BUF to FD. Return less than or equal to zero if an | |
96 | @@ -853,10 +871,18 @@ | |
97 | nwrite (int fd, char *buf, size_t len) | |
98 | { | |
99 | int size = len; | |
100 | + char * buf_unaligned, * buff; | |
101 | + | |
102 | + buf_unaligned = malloc((len * sizeof(char)) + 4095); | |
103 | + buff = (char *) (((unsigned long)buf_unaligned + 4096 - 1) & | |
104 | + (~(4096-1))); | |
105 | ||
106 | while (len) | |
107 | { | |
108 | - int ret = write (fd, buf, len); | |
109 | + int ret; | |
110 | + | |
111 | + memcpy(buff, buf, len); | |
112 | + ret = write (fd, buff, len); | |
113 | ||
114 | if (ret <= 0) | |
115 | { |