Part of Slepp's ProjectsPastebinTURLImagebinFilebin
Feedback -- English French German Japanese
Create Upload Newest Tools Donate
Sign In | Create Account

Unbenannt
Saturday, March 8th, 2008 at 11:27:56pm UTC 

  1. Index: firmware/drivers/ata.c
  2. ===================================================================
  3. --- firmware/drivers/ata.c      (revision 16519)
  4. +++ firmware/drivers/ata.c      (working copy)
  5. @@ -89,6 +89,7 @@
  6.  static long last_user_activity = -1;
  7.  long last_disk_activity = -1;
  8.  
  9. +static unsigned long total_sectors;
  10.  static int multisectors; /* number of supported multisectors */
  11.  static unsigned short identify_info[SECTOR_SIZE/2];
  12.  
  13. @@ -284,6 +285,11 @@
  14.      mutex_lock(&ata_mtx);
  15.  #endif
  16.  
  17. +    if (start + incount > total_sectors) {
  18. +        ret = -1;
  19. +        goto error;
  20. +    }
  21. +
  22.      last_disk_activity = current_tick;
  23.      spinup_start = current_tick;
  24.  
  25. @@ -293,16 +299,14 @@
  26.          spinup = true;
  27.          if (poweroff) {
  28.              if (ata_power_on()) {
  29. -                mutex_unlock(&ata_mtx);
  30. -                ata_led(false);
  31. -                return -1;
  32. +                ret = -2;
  33. +                goto error;
  34.              }
  35.          }
  36.          else {
  37.              if (perform_soft_reset()) {
  38. -                mutex_unlock(&ata_mtx);
  39. -                ata_led(false);
  40. -                return -1;
  41. +                ret = -2;
  42. +                goto error;
  43.              }
  44.          }
  45.      }
  46. @@ -312,9 +316,8 @@
  47.      SET_REG(ATA_SELECT, ata_device);
  48.      if (!wait_for_rdy())
  49.      {
  50. -        mutex_unlock(&ata_mtx);
  51. -        ata_led(false);
  52. -        return -2;
  53. +        ret = -3;
  54. +        goto error;
  55.      }
  56.  
  57.   retry:
  58. @@ -371,7 +374,7 @@
  59.                     We choose alternative 2.
  60.                  */
  61.                  perform_soft_reset();
  62. -                ret = -4;
  63. +                ret = -5;
  64.                  goto retry;
  65.              }
  66.  
  67. @@ -403,7 +406,7 @@
  68.              */
  69.              if ( status & (STATUS_BSY | STATUS_ERR | STATUS_DF) ) {
  70.                  perform_soft_reset();
  71. -                ret = -5;
  72. +                ret = -6;
  73.                  goto retry;
  74.              }
  75.  
  76. @@ -415,13 +418,14 @@
  77.  
  78.          if(!ret && !wait_for_end_of_transfer()) {
  79.              perform_soft_reset();
  80. -            ret = -3;
  81. +            ret = -4;
  82.              goto retry;
  83.          }
  84.          break;
  85.      }
  86. +
  87. +  error:
  88.      ata_led(false);
  89. -
  90.  #ifndef MAX_PHYS_SECTOR_SIZE
  91.      mutex_unlock(&ata_mtx);
  92.  #endif
  93. @@ -489,6 +493,9 @@
  94.      mutex_lock(&ata_mtx);
  95.  #endif
  96.      
  97. +    if (start + count > total_sectors)
  98. +        panicf("Writing past end of disk");
  99. +
  100.      last_disk_activity = current_tick;
  101.      spinup_start = current_tick;
  102.  
  103. @@ -498,16 +505,14 @@
  104.          spinup = true;
  105.          if (poweroff) {
  106.              if (ata_power_on()) {
  107. -                mutex_unlock(&ata_mtx);
  108. -                ata_led(false);
  109. -                return -1;
  110. +                ret = -1;
  111. +                goto error;
  112.              }
  113.          }
  114.          else {
  115.              if (perform_soft_reset()) {
  116. -                mutex_unlock(&ata_mtx);
  117. -                ata_led(false);
  118. -                return -1;
  119. +                ret = -1;
  120. +                goto error;
  121.              }
  122.          }
  123.      }
  124. @@ -515,9 +520,8 @@
  125.      SET_REG(ATA_SELECT, ata_device);
  126.      if (!wait_for_rdy())
  127.      {
  128. -        mutex_unlock(&ata_mtx);
  129. -        ata_led(false);
  130. -        return -2;
  131. +        ret = -2;
  132. +        goto error;
  133.      }
  134.  
  135.  #ifdef HAVE_LBA48
  136. @@ -575,8 +579,8 @@
  137.          ret = -4;
  138.      }
  139.  
  140. +  error:
  141.      ata_led(false);
  142. -
  143.  #ifndef MAX_PHYS_SECTOR_SIZE
  144.      mutex_unlock(&ata_mtx);
  145.  #endif
  146. @@ -1240,11 +1244,16 @@
  147.                     phys_sector_mult * SECTOR_SIZE);
  148.  #endif
  149.  
  150. +        total_sectors = identify_info[60] | (identify_info[60] << 16);
  151. +
  152.  #ifdef HAVE_LBA48
  153. -        if (identify_info[83] & 0x0400 /* 48 bit address support */
  154. -            && identify_info[60] == 0xFFFF  /* and disk size >= 128 GiB */
  155. -            && identify_info[61] == 0x0FFF) /* (needs BigLBA addressing) */
  156. -        {
  157. +        if (identify_info[83] & 0x0400       /* 48 bit address support */
  158. +            && total_sectors == 0x0FFFFFFF)  /* and disk size >= 128 GiB */
  159. +        {                                    /* (needs BigLBA addressing) */
  160. +            if (identify_info[102] || identify_info[103])
  161. +                panicf("Unsupported disk size, >= 2^32 sectors");
  162. +               
  163. +            total_sectors = identify_info[100] | (identify_info[101] << 16);
  164.              lba48 = true; /* use BigLBA */
  165.          }
  166.  #endif

Update the Post

Either update this post and resubmit it with changes, or make a new post.

You may also comment on this post.

update paste below
details of the post (optional)

Note: Only the paste content is required, though the following information can be useful to others.

Save name / title?

(space separated, optional)



Please note that information posted here will expire by default in one month. If you do not want it to expire, please set the expiry time above. If it is set to expire, web search engines will not be allowed to index it prior to it expiring. Items that are not marked to expire will be indexable by search engines. Be careful with your passwords. All illegal activities will be reported and any information will be handed over to the authorities, so be good.

comments powered by Disqus