Skip to contentSkip to conversation

Enable writing to ATA devices, fix several bugs

PATCH In review Pavel Roskin 4 participants 17 messages Jul 3, 2008 – Jul 21, 2008

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Enable writing to ATA devices, fix several bugs

We have save_env now, so we can use the write capability. This also fixes the last compiler warning in GRUB.

Sorry, Marco, please ignore the previous message, as it didn't get to the list.

ChangeLog:

* disk/ata.c (grub_ata_pio_write): Check status before writing, like we do in grub_ata_pio_read().

(grub_ata_readwrite): Always write individual sectors. Fix the sector count for the remainder.

(grub_ata_write): Enable writing to ATA devices. Correctly report error for ATAPI devices.
---

 disk/ata.c |   19 +++++++++++--------
 1 files changed, 11 insertions(+), 8 deletions(-)
disk/ata.c +11 -8
index 02c4b06..c9b0498 100644
@@ -187,6 +187,9 @@ grub_ata_pio_write (struct grub_ata_device *dev, char *buf,
   grub_uint16_t *buf16 = (grub_uint16_t *) buf;
   unsigned int i;
 
+  if (grub_ata_regget (dev, GRUB_ATA_REG_STATUS) & 1)
+    return grub_ata_regget (dev, GRUB_ATA_REG_ERROR);
+
   /* Wait until the device is ready to write.  */
   grub_ata_wait_drq (dev);
 
@@ -562,10 +565,9 @@ grub_ata_readwrite (grub_disk_t disk, grub_disk_addr_t sector,
       /* Write sectors.  */
       grub_ata_regset (dev, GRUB_ATA_REG_CMD, cmd_write);
       grub_ata_wait ();
-      for (sect = 0; sect < batch; sect++)
+      for (sect = 0; sect < (size % batch); sect++)
 	{
-	  if (grub_ata_pio_write (dev, buf,
-				  (size % batch) * GRUB_DISK_SECTOR_SIZE))
+	  if (grub_ata_pio_write (dev, buf, GRUB_DISK_SECTOR_SIZE))
 	    return grub_error (GRUB_ERR_WRITE_ERROR, "ATA write error");
 	  buf += GRUB_DISK_SECTOR_SIZE;
 	}
@@ -705,11 +707,12 @@ grub_ata_write (grub_disk_t disk,
 		grub_size_t size,
 		const char *buf)
 {
-#if 1
-  return GRUB_ERR_NOT_IMPLEMENTED_YET;
-#else
-  return grub_ata_readwrite (disk, sector, size, (char *) buf, 1);
-#endif
+  struct grub_ata_device *dev = (struct grub_ata_device *) disk->data;
+
+  if (! dev->atapi)
+    return grub_ata_readwrite (disk, sector, size, (char *) buf, 1);
+
+  return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, "ATAPI write not supported");
 }
 
 static struct grub_disk_dev grub_atadisk_dev =
#1 lore raw

disk/ata.c grub_ata_pio_write (struct grub_ata_device *dev, char *buf, · line 191

Quoted 2 lines · Pavel Roskin
disk/ata.c +2 -0
+  if (grub_ata_regget (dev, GRUB_ATA_REG_STATUS) & 1)
+    return grub_ata_regget (dev, GRUB_ATA_REG_ERROR);

May I suggest a macro to describe this "1"?

Signature · 5 lines
Robert Millan

<GPLv2> I know my rights; I want my phone call!
<DRM> What good is a phone call… if you are unable to speak?
(as seen on /.)
#2 lore raw
In reply to Pavel Roskin
Quoted 2 lines · Pavel Roskin

We have save_env now, so we can use the write capability. This also fixes the last compiler warning in GRUB.

Great!

Quoted 2 lines

Sorry, Marco, please ignore the previous message, as it didn't get to the list.

The more patches I get, the better ;-)

Quoted 7 lines

ChangeLog:

* disk/ata.c (grub_ata_pio_write): Check status before writing, like we do in grub_ata_pio_read().

(grub_ata_readwrite): Always write individual sectors. Fix the sector count for the remainder.

Why?

Quoted 2 lines

(grub_ata_write): Enable writing to ATA devices. Correctly report error for ATAPI devices.

Great! Did you test this?

If you can fix Roberts comment, it would be great! Can you commit it afterwards?

--
Marco

#3 lore raw
Quoted 11 lines · Marco Gerards

The more patches I get, the better ;-)

Quoted 7 lines

ChangeLog:

* disk/ata.c (grub_ata_pio_write): Check status before writing, like we do in grub_ata_pio_read().

(grub_ata_readwrite): Always write individual sectors. Fix the sector count for the remainder.

Why?

Because we do it elsewhere. I assume you forgot to convert the code for writing, but you meant to do it:

r1335 | marco_g | 2007-11-03 08:25:19 -0400 (Sat, 03 Nov 2007) | 6 lines

2007-11-03 Marco Gerards <[email protected]>

* disk/ata.c (grub_ata_readwrite): Call grub_ata_pio_read and grub_ata_pio_write once for every single sector, instead of for multiple sectors.

I guess it's safer. We can explore some optimization, but first we should make it reliable.

Quoted 4 lines
Quoted 2 lines

(grub_ata_write): Enable writing to ATA devices. Correctly report error for ATAPI devices.

Great! Did you test this?

Yes, I tested this part. env_save didn't report any error originally, so I introduced grub_error(), and env_save started reporting the error. Then I enabled writing and tested it in qemu.

I cannot get the ata module to recognize the hard drive on my test machine, so more work is needed to test it on the real hardware.

Quoted 2 lines

If you can fix Roberts comment, it would be great! Can you commit it afterwards?

Sure.

If you check Linux include/linux/ata.h, 1 is ATA_ERR, and we really need ata_ok(), which checks multiple flags. So it's clearly material for a separate patch.

Signature · 2 lines
Regards,
Pavel Roskin
#4 lore raw
Quoted 19 lines · Pavel Roskin
Quoted 11 lines · Marco Gerards

The more patches I get, the better ;-)

Quoted 7 lines

ChangeLog:

* disk/ata.c (grub_ata_pio_write): Check status before writing, like we do in grub_ata_pio_read().

(grub_ata_readwrite): Always write individual sectors. Fix the sector count for the remainder.

Why?

Because we do it elsewhere. I assume you forgot to convert the code for writing, but you meant to do it:

r1335 | marco_g | 2007-11-03 08:25:19 -0400 (Sat, 03 Nov 2007) | 6 lines

Quoted 8 lines

2007-11-03 Marco Gerards <[email protected]>

* disk/ata.c (grub_ata_readwrite): Call grub_ata_pio_read and grub_ata_pio_write once for every single sector, instead of for multiple sectors.

I guess it's safer. We can explore some optimization, but first we should make it reliable.

Ah right :-)

Quoted 11 lines
Quoted 4 lines
Quoted 2 lines

(grub_ata_write): Enable writing to ATA devices. Correctly report error for ATAPI devices.

Great! Did you test this?

Yes, I tested this part. env_save didn't report any error originally, so I introduced grub_error(), and env_save started reporting the error. Then I enabled writing and tested it in qemu.

I cannot get the ata module to recognize the hard drive on my test machine, so more work is needed to test it on the real hardware.

Right, this needs more work. I will have another look at ATA soon :-)

For me ATA support worked on real hardware. I will have to try it on more hardware.

Quoted 8 lines
Quoted 2 lines

If you can fix Roberts comment, it would be great! Can you commit it afterwards?

Sure.

If you check Linux include/linux/ata.h, 1 is ATA_ERR, and we really need ata_ok(), which checks multiple flags. So it's clearly material for a separate patch.

No, I cannot check the Linux code. AFAIK this can cause copyright problems. But I agree that more and better error checking is required.

--
Marco

#5 lore raw

Quoting Marco Gerards <[email protected]>:

Quoted 4 lines
Quoted 2 lines

I cannot get the ata module to recognize the hard drive on my test machine, so more work is needed to test it on the real hardware.

Right, this needs more work. I will have another look at ATA soon :-)

That would be great!

Quoted 7 lines
Quoted 3 lines

If you check Linux include/linux/ata.h, 1 is ATA_ERR, and we really need ata_ok(), which checks multiple flags. So it's clearly material for a separate patch.

No, I cannot check the Linux code. AFAIK this can cause copyright problems. But I agree that more and better error checking is required.

I know. That's why I'll write it from specifications or maybe I'll take it from the GNU/Hurd code.

Signature · 2 lines
Regards,
Pavel Roskin
#6 lore raw
Quoted 13 lines · Pavel Roskin

Quoting Marco Gerards <[email protected]>:

Quoted 4 lines
Quoted 2 lines

I cannot get the ata module to recognize the hard drive on my test machine, so more work is needed to test it on the real hardware.

Right, this needs more work. I will have another look at ATA soon :-)

That would be great!

Quoted 4 lines
Quoted 3 lines

If you check Linux include/linux/ata.h, 1 is ATA_ERR, and we really need ata_ok(), which checks multiple flags. So it's clearly material for a separate patch.

Quoted 6 lines
Quoted 3 lines

No, I cannot check the Linux code. AFAIK this can cause copyright problems. But I agree that more and better error checking is required.

I know. That's why I'll write it from specifications or maybe I'll take it from the GNU/Hurd code.

Taking it from Specifications will be better.

I think the ATA driver of GNU Mach comes from Linux 2.0 or so. So that won't change anything for us ;(.

--
Marco

#7 lore raw
Quoted 9 lines · Marco Gerards
Quoted 2 lines · Pavel Roskin

I know. That's why I'll write it from specifications or maybe I'll take it from the GNU/Hurd code.

Taking it from Specifications will be better.

I think the ATA driver of GNU Mach comes from Linux 2.0 or so. So that won't change anything for us ;(.

I don't think choosing consistent names could be interpreted as a copyright violation (except by companies like SCO, but then all bets are off).

Anyway, if I ever have a chance to touch the GRUB ATA code again, I'll use FreeBSD as a reference. Using specification is probably not the best idea because we need GRUB to work on the real life hardware, and we need to be prepared to handle known quirks in popular hardware.

Signature · 2 lines
Regards,
Pavel Roskin
#8 lore raw
Quoted 6 lines · Pavel Roskin
Quoted 5 lines · Marco Gerards
Quoted 2 lines · Pavel Roskin

I know. That's why I'll write it from specifications or maybe I'll take it from the GNU/Hurd code.

Quoted 8 lines
Quoted 4 lines

Taking it from Specifications will be better.

I think the ATA driver of GNU Mach comes from Linux 2.0 or so. So that won't change anything for us ;(.

I don't think choosing consistent names could be interpreted as a copyright violation (except by companies like SCO, but then all bets are off).

No, you are right. But it means that you have a look at the Linux ATA code. If you copy Linux names into our code, people could claim that we looked at Linux and based our code on it.

Quoted 4 lines

Anyway, if I ever have a chance to touch the GRUB ATA code again, I'll use FreeBSD as a reference. Using specification is probably not the best idea because we need GRUB to work on the real life hardware, and we need to be prepared to handle known quirks in popular hardware.

We were talking about not looking at copyrighted code as a reference... But looking at FreeBSD would be better than looking at Linux if we want to avoid possible copyright problems.

--
Marco

#9 lore raw
Quoted 13 lines · Marco Gerards
Quoted 11 lines · Pavel Roskin
Quoted 9 lines · Marco Gerards
Quoted 2 lines · Pavel Roskin

I know. That's why I'll write it from specifications or maybe I'll take it from the GNU/Hurd code.

Taking it from Specifications will be better.

I think the ATA driver of GNU Mach comes from Linux 2.0 or so. So that won't change anything for us ;(.

Quoted 7 lines
Quoted 3 lines

I don't think choosing consistent names could be interpreted as a copyright violation (except by companies like SCO, but then all bets are off).

No, you are right. But it means that you have a look at the Linux ATA code. If you copy Linux names into our code, people could claim that we looked at Linux and based our code on it.

So what? Aren't both Linux and GRUB under the GPL? That _should_ mean that we can look at their code and put it into GRUB ("create a derivative work") either as-is or modified.

Quoted 9 lines
Quoted 5 lines

Anyway, if I ever have a chance to touch the GRUB ATA code again, I'll use FreeBSD as a reference. Using specification is probably not the best idea because we need GRUB to work on the real life hardware, and we need to be prepared to handle known quirks in popular hardware.

We were talking about not looking at copyrighted code as a reference... But looking at FreeBSD would be better than looking at Linux if we want to avoid possible copyright problems.

I still don't understand this: the GPL includes an irrevocable grant as long as the license is obeyed. As for copyright problems, Linux has had several clashes (SCO et al), but in each and every instance people has raised against the attacker, defended Linux and won in court. I say it "offers" quite good copyright shielding.

Habbit

#10 lore raw
Quoted 18 lines · Javier Martín
Quoted 17 lines · Marco Gerards
Quoted 14 lines · Pavel Roskin
Quoted 9 lines · Marco Gerards
Quoted 2 lines · Pavel Roskin

I know. That's why I'll write it from specifications or maybe I'll take it from the GNU/Hurd code.

Taking it from Specifications will be better.

I think the ATA driver of GNU Mach comes from Linux 2.0 or so. So that won't change anything for us ;(.

I don't think choosing consistent names could be interpreted as a copyright violation (except by companies like SCO, but then all bets are off).

Quoted 6 lines
Quoted 3 lines

No, you are right. But it means that you have a look at the Linux ATA code. If you copy Linux names into our code, people could claim that we looked at Linux and based our code on it.

So what? Aren't both Linux and GRUB under the GPL? That _should_ mean that we can look at their code and put it into GRUB ("create a derivative work") either as-is or modified.

For GRUB 2 we require copyright assignments.

Quoted 5 lines
Quoted 5 lines
Quoted 4 lines

Anyway, if I ever have a chance to touch the GRUB ATA code again, I'll use FreeBSD as a reference. Using specification is probably not the best idea because we need GRUB to work on the real life hardware, and we need to be prepared to handle known quirks in popular hardware.

Quoted 8 lines
Quoted 3 lines

We were talking about not looking at copyrighted code as a reference... But looking at FreeBSD would be better than looking at Linux if we want to avoid possible copyright problems.

I still don't understand this: the GPL includes an irrevocable grant as long as the license is obeyed. As for copyright problems, Linux has had several clashes (SCO et al), but in each and every instance people has raised against the attacker, defended Linux and won in court. I say it "offers" quite good copyright shielding.

This isn't about licenses. This is about copyright.

--
Marco

#11 lore raw
Quoted 37 lines · Marco Gerards
Quoted 18 lines · Javier Martín
Quoted 17 lines · Marco Gerards
Quoted 14 lines · Pavel Roskin
Quoted 9 lines · Marco Gerards
Quoted 2 lines · Pavel Roskin

I know. That's why I'll write it from specifications or maybe I'll take it from the GNU/Hurd code.

Taking it from Specifications will be better.

I think the ATA driver of GNU Mach comes from Linux 2.0 or so. So that won't change anything for us ;(.

I don't think choosing consistent names could be interpreted as a copyright violation (except by companies like SCO, but then all bets are off).

Quoted 6 lines
Quoted 3 lines

No, you are right. But it means that you have a look at the Linux ATA code. If you copy Linux names into our code, people could claim that we looked at Linux and based our code on it.

So what? Aren't both Linux and GRUB under the GPL? That _should_ mean that we can look at their code and put it into GRUB ("create a derivative work") either as-is or modified.

For GRUB 2 we require copyright assignments.

Quoted 8 lines
Quoted 8 lines
Quoted 4 lines

Anyway, if I ever have a chance to touch the GRUB ATA code again, I'll use FreeBSD as a reference. Using specification is probably not the best idea because we need GRUB to work on the real life hardware, and we need to be prepared to handle known quirks in popular hardware.

We were talking about not looking at copyrighted code as a reference... But looking at FreeBSD would be better than looking at Linux if we want to avoid possible copyright problems.

Quoted 7 lines
Quoted 5 lines

I still don't understand this: the GPL includes an irrevocable grant as long as the license is obeyed. As for copyright problems, Linux has had several clashes (SCO et al), but in each and every instance people has raised against the attacker, defended Linux and won in court. I say it "offers" quite good copyright shielding.

This isn't about licenses. This is about copyright.

I know, I know... What I'm asking is _why_ this whole obsession about copyright assignments. Is there a page in the wiki explaining it?

#13 lore raw
In reply to Marco Gerards
Quoted 7 lines · Marco Gerards
Quoted 3 lines · Javier Martín

So what? Aren't both Linux and GRUB under the GPL? That _should_ mean that we can look at their code and put it into GRUB ("create a derivative work") either as-is or modified.

For GRUB 2 we require copyright assignments.

Also, Linux is under GPLv2 and GRUB is under GPLv3. This means that Linux developers could object that their code is restricted further than GPLv2 allows, e.g. there are additional anti-DRM provisions that the recipients of the GRUB code has to fulfill.

That said, I cannot imagine that copying of variable names could be treated as a copyright violation. For instance, Wine reimplements Windows API, and they just have to use the same names.

Signature · 2 lines
Regards,
Pavel Roskin
#14 lore raw
Quoted 9 lines · Pavel Roskin
Quoted 7 lines · Marco Gerards
Quoted 3 lines · Javier Martín

So what? Aren't both Linux and GRUB under the GPL? That _should_ mean that we can look at their code and put it into GRUB ("create a derivative work") either as-is or modified.

For GRUB 2 we require copyright assignments.

Quoted 8 lines

Also, Linux is under GPLv2 and GRUB is under GPLv3. This means that Linux developers could object that their code is restricted further than GPLv2 allows, e.g. there are additional anti-DRM provisions that the recipients of the GRUB code has to fulfill.

That said, I cannot imagine that copying of variable names could be treated as a copyright violation. For instance, Wine reimplements Windows API, and they just have to use the same names.

Please do not put words in my mouth, that is not what I said. I said looking at Linux *code* should be avoided. If you have a look at the ATA *code*, you might copy their algorithms or whatever. I am asking you to be careful. Looking at code might give you an idea about how to solve a problem, you might even implement this and legally... well, I am not sure when you violate copyright or when not. I cannot tell if you looked at their code if you opened the files, study the variable names and how they are used.

--
Marco

#12 lore raw
In reply to Javier Martín
Quoted 44 lines · Javier Martín
Quoted 43 lines · Marco Gerards
Quoted 18 lines · Javier Martín
Quoted 17 lines · Marco Gerards
Quoted 14 lines · Pavel Roskin
Quoted 9 lines · Marco Gerards
Quoted 2 lines · Pavel Roskin

I know. That's why I'll write it from specifications or maybe I'll take it from the GNU/Hurd code.

Taking it from Specifications will be better.

I think the ATA driver of GNU Mach comes from Linux 2.0 or so. So that won't change anything for us ;(.

I don't think choosing consistent names could be interpreted as a copyright violation (except by companies like SCO, but then all bets are off).

Quoted 6 lines
Quoted 3 lines

No, you are right. But it means that you have a look at the Linux ATA code. If you copy Linux names into our code, people could claim that we looked at Linux and based our code on it.

So what? Aren't both Linux and GRUB under the GPL? That _should_ mean that we can look at their code and put it into GRUB ("create a derivative work") either as-is or modified.

For GRUB 2 we require copyright assignments.

Quoted 13 lines
Quoted 8 lines
Quoted 4 lines

Anyway, if I ever have a chance to touch the GRUB ATA code again, I'll use FreeBSD as a reference. Using specification is probably not the best idea because we need GRUB to work on the real life hardware, and we need to be prepared to handle known quirks in popular hardware.

We were talking about not looking at copyrighted code as a reference... But looking at FreeBSD would be better than looking at Linux if we want to avoid possible copyright problems.

I still don't understand this: the GPL includes an irrevocable grant as long as the license is obeyed. As for copyright problems, Linux has had several clashes (SCO et al), but in each and every instance people has raised against the attacker, defended Linux and won in court. I say it "offers" quite good copyright shielding.

Quoted 3 lines
Quoted 1 line

This isn't about licenses. This is about copyright.

I know, I know... What I'm asking is _why_ this whole obsession about copyright assignments. Is there a page in the wiki explaining it?

I think I explained this already and I do not want to keep repeating everything I said several times. There is not wiki page, but there is a document about this for GNU maintainers:

http://www.gnu.org/prep/maintain/maintain.html#Copyright-Papers

--
Marco

#15 lore raw
In reply to Marco Gerards
Quoted 2 lines · Marco Gerards

Please do not put words in my mouth, that is not what I said. I said looking at Linux *code* should be avoided.

I agree with you. I was referring to what I did, not to what you said.

Signature · 2 lines
Regards,
Pavel Roskin
#16 lore raw
Quoted 6 lines · Pavel Roskin
Quoted 2 lines · Marco Gerards

Please do not put words in my mouth, that is not what I said. I said looking at Linux *code* should be avoided.

I agree with you. I was referring to what I did, not to what you said.

Good :-)

--
Marco