grub-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Read Sectors


From: Julio Alberto Cruz Barroso
Subject: RE: Read Sectors
Date: Tue, 25 Oct 2011 10:45:29 -0400

I used this with success:

--------------
11.3 How to specify block lists

A block list is used for specifying a file that doesn't appear in the 
filesystem, like a chainloader. The syntax is 
[offset]+length[,[offset]+length].... Here is an example:

     0+100,200+1,300+300
This represents that GRUB should read blocks 0 through 99, block 200, and 
blocks 300 through 599. If you omit an offset, then GRUB assumes the offset is 
zero.

Like the file name syntax (see File name syntax), if a blocklist does not 
contain a device name, then GRUB uses GRUB's root device. So (hd0,2)+1 is the 
same as +1 when the root device is ‘(hd0,2)’.
---------------

Regards,

JC

-----Original Message-----
From: address@hidden [mailto:address@hidden On Behalf Of Julio Alberto Cruz 
Barroso
Sent: Tuesday, October 25, 2011 9:09 AM
To: The development of GNU GRUB
Subject: RE: Read Sectors

OK, OK. 

I use the following function to read files with success:

---------------------------------------
static int 
smtt_send_file(char * pathname)
{
 static unsigned char Buffer[FILE_BUFFER_SIZE];
 grub_file_t file = 0;
 grub_off_t ofs, len;
 unsigned long long bytes_sent = 0;
 file = grub_file_open (pathname);
 
 if (!file)
    {
      grub_dprintf ("mcu","cannot open file %s", pathname);
      return -1;
    }


grub_dprintf ("mcu","file size : %lld \n", (unsigned long long) file->size);




ofs = 0;
len = file->size;

file->offset = 0;


while (len)
    {
      grub_ssize_t sz;
      sz = grub_file_read (file, Buffer, (len > FILE_BUFFER_SIZE) ? 
FILE_BUFFER_SIZE : len);
      if (sz < 0)
        {
          grub_dprintf ("mcu","read error at offset %llu: %s\n", ofs, 
grub_errmsg);
          break;
        }
#ifdef MCUDEBUG
     grub_getkey();
      grub_printf ("sending pack %llu \n", ofs);
#endif
      if(!smtt_send_package ( Buffer, sz))
        {
          bytes_sent +=sz;
          if ((sz == 0))
          break;
          ofs += sz;
          len -= sz;
        }
        else
        {
          grub_dprintf("mcu", "Error Sending Package\n");
          break;
        }
    }
//grub_printf ("file size : %lld \n", (unsigned long long) file->size);
//grub_printf ("Bytes Sends: %lld \n", bytes_sent);
grub_file_close (file);

return 0;
}
---------------------------------------------------------

Now, I need to read the OS partition sectors (not files). For example, from 
sector 1 to sector 500. 

I'm not sure which function to use to get this. For example, the functions 
"read" and "write" in a C/C++ Linux program.

Julio



-----Original Message-----
From: address@hidden [mailto:address@hidden On Behalf Of Vladimir 
'f-coder/phcoder' Serbinenko
Sent: Wednesday, October 12, 2011 9:49 PM
To: The development of GNU GRUB
Subject: Re: Read Sectors

On 12.10.2011 05:03, Julio Alberto Cruz Barroso wrote:
>
> Dear all,
>
>  
>
> I have a module to read some byte sectors from a OS partition to get a 
> HASH and validate the OS.
>
>  
>
> I try to use grub_file_open and grub_disk_open function without success.
>
And I'm telepath to know what exactly the code you're trying. And if you code 
for anything have a look around for the use of the function in question e.g. in 
ntldr.c
>
>  
>
> My system have two (2) compact flash (hard disk). The system must boot 
> with one CF or two CF (with priority setup).
>
>  
>
> Thanks all,
>
>  
>
> Julio
>
>
> _______________________________________________
> Grub-devel mailing list
> address@hidden
> https://lists.gnu.org/mailman/listinfo/grub-devel


--
Regards
Vladimir 'φ-coder/phcoder' Serbinenko


_______________________________________________
Grub-devel mailing list
address@hidden
https://lists.gnu.org/mailman/listinfo/grub-devel

reply via email to

[Prev in Thread] Current Thread [Next in Thread]