~ubuntu-branches/ubuntu/trusty/grub2/trusty

« back to all changes in this revision

Viewing changes to grub-core/fs/squash4.c

  • Committer: Package Import Robot
  • Author(s): Colin Watson
  • Date: 2014-01-16 15:18:04 UTC
  • mfrom: (17.6.38 experimental)
  • Revision ID: package-import@ubuntu.com-20140116151804-3foouk7fpqcq3sxx
Tags: 2.02~beta2-2
* Convert patch handling to git-dpm.
* Add bi-endian support to ELF parser (Tomohiro B Berry).
* Adjust restore_mkdevicemap.patch to mark get_kfreebsd_version as static,
  to appease "gcc -Werror=missing-prototypes".
* Cherry-pick from upstream:
  - Change grub-macbless' manual page section to 8.
* Install grub-glue-efi, grub-macbless, grub-render-label, and
  grub-syslinux2cfg.
* grub-shell: Pass -no-pad to xorriso when building floppy images.

Show diffs side-by-side

added added

removed removed

Lines of Context:
71
71
  grub_uint64_t diroffset;
72
72
  grub_uint64_t unk1offset;
73
73
  grub_uint64_t unk2offset;
74
 
} __attribute__ ((packed));
 
74
} GRUB_PACKED;
75
75
 
76
76
/* Chunk-based */
77
77
struct grub_squash_inode
89
89
      grub_uint32_t offset;
90
90
      grub_uint32_t size;
91
91
      grub_uint32_t block_size[0];
92
 
    }  __attribute__ ((packed)) file;
 
92
    }  GRUB_PACKED file;
93
93
    struct {
94
94
      grub_uint64_t chunk;
95
95
      grub_uint64_t size;
98
98
      grub_uint32_t offset;
99
99
      grub_uint32_t dummy3;
100
100
      grub_uint32_t block_size[0];
101
 
    }  __attribute__ ((packed)) long_file;
 
101
    }  GRUB_PACKED long_file;
102
102
    struct {
103
103
      grub_uint32_t chunk;
104
104
      grub_uint32_t dummy;
105
105
      grub_uint16_t size;
106
106
      grub_uint16_t offset;
107
 
    } __attribute__ ((packed)) dir;
 
107
    } GRUB_PACKED dir;
108
108
    struct {
109
109
      grub_uint32_t dummy1;
110
110
      grub_uint32_t size;
112
112
      grub_uint32_t dummy2;
113
113
      grub_uint16_t dummy3;
114
114
      grub_uint16_t offset;
115
 
    } __attribute__ ((packed)) long_dir;
 
115
    } GRUB_PACKED long_dir;
116
116
    struct {
117
117
      grub_uint32_t dummy;
118
118
      grub_uint32_t namelen;
119
119
      char name[0];
120
 
    } __attribute__ ((packed)) symlink;
121
 
  }  __attribute__ ((packed));
122
 
} __attribute__ ((packed));
 
120
    } GRUB_PACKED symlink;
 
121
  }  GRUB_PACKED;
 
122
} GRUB_PACKED;
123
123
 
124
124
struct grub_squash_cache_inode
125
125
{
137
137
  grub_uint32_t nelems;
138
138
  grub_uint32_t ino_chunk;
139
139
  grub_uint32_t dummy;
140
 
} __attribute__ ((packed));
 
140
} GRUB_PACKED;
141
141
 
142
142
struct grub_squash_dirent
143
143
{
147
147
  /* Actually the value is the length of name - 1.  */
148
148
  grub_uint16_t namelen;
149
149
  char name[0];
150
 
} __attribute__ ((packed));
 
150
} GRUB_PACKED;
151
151
 
152
152
enum
153
153
  {
164
164
  grub_uint64_t offset;
165
165
  grub_uint32_t size;
166
166
  grub_uint32_t dummy;
167
 
} __attribute__ ((packed));
 
167
} GRUB_PACKED;
168
168
 
169
169
enum
170
170
  {
478
478
 
479
479
static int
480
480
grub_squash_iterate_dir (grub_fshelp_node_t dir,
481
 
                         int NESTED_FUNC_ATTR
482
 
                         (*hook) (const char *filename,
483
 
                                  enum grub_fshelp_filetype filetype,
484
 
                                  grub_fshelp_node_t node))
 
481
                         grub_fshelp_iterate_dir_hook_t hook, void *hook_data)
485
482
{
486
483
  grub_uint32_t off;
487
484
  grub_uint32_t endoff;
514
511
      return 0;
515
512
    grub_memcpy (node, dir,
516
513
                 sizeof (*node) + dir->stsize * sizeof (dir->stack[0]));
517
 
    if (hook (".", GRUB_FSHELP_DIR, node))
 
514
    if (hook (".", GRUB_FSHELP_DIR, node, hook_data))
518
515
      return 1;
519
516
 
520
517
    if (dir->stsize != 1)
536
533
        if (err)
537
534
          return 0;
538
535
 
539
 
        if (hook ("..", GRUB_FSHELP_DIR, node))
 
536
        if (hook ("..", GRUB_FSHELP_DIR, node, hook_data))
540
537
          return 1;
541
538
      }
542
539
  }
604
601
          node->stack[node->stsize].ino_chunk = grub_le_to_cpu32 (dh.ino_chunk);
605
602
          node->stack[node->stsize].ino_offset = grub_le_to_cpu16 (di.ino_offset);
606
603
          node->stsize++;
607
 
          r = hook (buf, filetype, node);
 
604
          r = hook (buf, filetype, node, hook_data);
608
605
 
609
606
          grub_free (buf);
610
607
          if (r)
640
637
}
641
638
 
642
639
 
 
640
/* Context for grub_squash_dir.  */
 
641
struct grub_squash_dir_ctx
 
642
{
 
643
  grub_fs_dir_hook_t hook;
 
644
  void *hook_data;
 
645
};
 
646
 
 
647
/* Helper for grub_squash_dir.  */
 
648
static int
 
649
grub_squash_dir_iter (const char *filename, enum grub_fshelp_filetype filetype,
 
650
                      grub_fshelp_node_t node, void *data)
 
651
{
 
652
  struct grub_squash_dir_ctx *ctx = data;
 
653
  struct grub_dirhook_info info;
 
654
 
 
655
  grub_memset (&info, 0, sizeof (info));
 
656
  info.dir = ((filetype & GRUB_FSHELP_TYPE_MASK) == GRUB_FSHELP_DIR);
 
657
  info.mtimeset = 1;
 
658
  info.mtime = grub_le_to_cpu32 (node->ino.mtime);
 
659
  grub_free (node);
 
660
  return ctx->hook (filename, &info, ctx->hook_data);
 
661
}
 
662
 
643
663
static grub_err_t
644
664
grub_squash_dir (grub_device_t device, const char *path,
645
 
               int (*hook) (const char *filename,
646
 
                            const struct grub_dirhook_info *info))
 
665
                 grub_fs_dir_hook_t hook, void *hook_data)
647
666
{
648
 
  auto int NESTED_FUNC_ATTR iterate (const char *filename,
649
 
                                     enum grub_fshelp_filetype filetype,
650
 
                                     grub_fshelp_node_t node);
651
 
 
652
 
  int NESTED_FUNC_ATTR iterate (const char *filename,
653
 
                                enum grub_fshelp_filetype filetype,
654
 
                                grub_fshelp_node_t node)
655
 
    {
656
 
      struct grub_dirhook_info info;
657
 
      grub_memset (&info, 0, sizeof (info));
658
 
      info.dir = ((filetype & GRUB_FSHELP_TYPE_MASK) == GRUB_FSHELP_DIR);
659
 
      info.mtimeset = 1;
660
 
      info.mtime = grub_le_to_cpu32 (node->ino.mtime);
661
 
      grub_free (node);
662
 
      return hook (filename, &info);
663
 
    }
664
 
 
 
667
  struct grub_squash_dir_ctx ctx = { hook, hook_data };
665
668
  struct grub_squash_data *data = 0;
666
669
  struct grub_fshelp_node *fdiro = 0;
667
670
  struct grub_fshelp_node root;
678
681
  grub_fshelp_find_file (path, &root, &fdiro, grub_squash_iterate_dir,
679
682
                         grub_squash_read_symlink, GRUB_FSHELP_DIR);
680
683
  if (!grub_errno)
681
 
    grub_squash_iterate_dir (fdiro, iterate);
 
684
    grub_squash_iterate_dir (fdiro, grub_squash_dir_iter, &ctx);
682
685
 
683
686
  squash_unmount (data);
684
687