grub-devel
[Top][All Lists]
Advanced

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

Problem with the blocklist command


From: Bean
Subject: Problem with the blocklist command
Date: Tue, 31 Jul 2007 16:29:28 +0800

Hi,

I notice that the output of blocklist command is quite strange. After
some debuging, I think
the problem may be caused by the compiler.

static grub_err_t
grub_cmd_blocklist (struct grub_arg_list *state __attribute__ ((unused)),
                    int argc, char **args)
{
  grub_file_t file;
  char buf[GRUB_DISK_SECTOR_SIZE];
  unsigned long start_sector = 0;
  unsigned num_sectors = 0;
  int num_entries = 0;
  grub_disk_addr_t part_start = 0;
  auto void read_blocklist (grub_disk_addr_t sector, unsigned offset,
                            unsigned length);
  auto void print_blocklist (grub_disk_addr_t sector, unsigned num,
                             unsigned offset, unsigned length);

  void read_blocklist (grub_disk_addr_t sector, unsigned offset,
                       unsigned length)
    {
      grub_printf("2- %llu\n", part_start);
      if (num_sectors > 0)
        {
          if (start_sector + num_sectors == sector
              && offset == 0 && length == GRUB_DISK_SECTOR_SIZE)
            {
              num_sectors++;
              return;
            }
        
          print_blocklist (start_sector, num_sectors, 0, 0);
          num_sectors = 0;
        }

      if (offset == 0 && length == GRUB_DISK_SECTOR_SIZE)
        {
          start_sector = sector;
          num_sectors++;
        }
      else
        print_blocklist (sector, 0, offset, length);
    }

  void print_blocklist (grub_disk_addr_t sector, unsigned num,
                        unsigned offset, unsigned length)
    {
      grub_printf("3- %llu\n", part_start);
      if (num_entries++)
        grub_printf (",");

      grub_printf ("%llu", sector - part_start);
      if (num > 0)
        grub_printf ("+%u", num);
      if (offset != 0 || length != 0)
        grub_printf ("[%u-%u]", offset, offset + length);
    }

  if (argc < 1)
    return grub_error (GRUB_ERR_BAD_ARGUMENT, "no file specified");

  file = grub_file_open (args[0]);
  if (! file)
    return grub_errno;

  if (! file->device->disk)
    return grub_error (GRUB_ERR_BAD_DEVICE,
                       "this command is available only for disk devices.");

  if (file->device->disk->partition)
    part_start = grub_partition_get_start (file->device->disk->partition);
  grub_printf("1- %llu\n", part_start);

  file->read_hook = read_blocklist;

  while (grub_file_read (file, buf, sizeof (buf)) > 0)
    ;

  if (num_sectors > 0)
    print_blocklist (start_sector, num_sectors, 0, 0);

  grub_file_close (file);

  return grub_errno;
}

I blocklist a very small file, it shows
1- 32
2- 32
3- 17294103305076670291

If I define part_start as a global variable, the ouput is ok.

I don't know if this is a compiler related bug, my gcc version is

gcc version 4.1.2 20061028 (prerelease) (Debian 4.1.1-19)

btw, I'm curious to know how local variable part_start is passed to
hook function
read_blocklist.

--
Bean




reply via email to

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