-
Notifications
You must be signed in to change notification settings - Fork 80
/
0001-GRUB-fixes.patch
1696 lines (1543 loc) · 50.1 KB
/
0001-GRUB-fixes.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
From c5c5b86e7baf3454358f02590675244f8875ab13 Mon Sep 17 00:00:00 2001
From: Pete Batard <pete@akeo.ie>
Date: Fri, 29 Nov 2024 16:46:25 +0000
Subject: [PATCH] GRUB fixes
---
grub-core/fs/affs.c | 2 ++
grub-core/fs/bfs.c | 2 ++
grub-core/fs/btrfs.c | 52 +++++++++++++++++-----------
grub-core/fs/cbfs.c | 2 +-
grub-core/fs/cpio_common.c | 2 +-
grub-core/fs/erofs.c | 6 ++++
grub-core/fs/f2fs.c | 2 ++
grub-core/fs/fat.c | 8 +++--
grub-core/fs/hfs.c | 6 ++++
grub-core/fs/hfsplus.c | 2 ++
grub-core/fs/hfspluscomp.c | 4 +++
grub-core/fs/iso9660.c | 38 +++++++++++++-------
grub-core/fs/jfs.c | 6 ++--
grub-core/fs/nilfs2.c | 4 ++-
grub-core/fs/ntfs.c | 2 ++
grub-core/fs/proc.c | 2 +-
grub-core/fs/reiserfs.c | 16 ++++++++-
grub-core/fs/sfs.c | 4 ++-
grub-core/fs/squash4.c | 10 ++++--
grub-core/fs/tar.c | 2 +-
grub-core/fs/udf.c | 2 ++
grub-core/fs/ufs.c | 2 ++
grub-core/fs/xfs.c | 2 ++
grub-core/fs/zfs/zfs.c | 6 ++--
grub-core/fs/zfs/zfs_lz4.c | 2 ++
grub-core/kern/misc.c | 12 +++----
grub-core/lib/posix_wrap/limits.h | 12 +++++++
grub-core/lib/xzembed/xz_dec_lzma2.c | 2 ++
grub-core/lib/xzembed/xz_stream.h | 2 +-
grub-core/lib/zstd/bitstream.h | 2 +-
grub-core/lib/zstd/fse_decompress.c | 3 +-
grub-core/lib/zstd/huf_decompress.c | 2 +-
grub-core/lib/zstd/mem.h | 14 ++++++--
grub-core/lib/zstd/xxhash.c | 7 ++--
grub-core/lib/zstd/zstd_common.c | 3 +-
grub-core/lib/zstd/zstd_decompress.c | 1 -
grub-core/lib/zstd/zstd_internal.h | 14 +++++++-
include/grub/arm64/types.h | 4 +++
include/grub/btrfs.h | 3 +-
include/grub/exfat.h | 2 ++
include/grub/fat.h | 2 ++
include/grub/hfs.h | 2 ++
include/grub/hfsplus.h | 6 ++++
include/grub/misc.h | 5 +++
include/grub/ntfs.h | 2 ++
include/grub/safemath.h | 24 +++++++++++++
include/grub/term.h | 4 +--
include/grub/types.h | 42 +++++++++++++++-------
include/grub/unicode.h | 2 ++
include/grub/x86_64/types.h | 2 +-
include/grub/zfs/zap_leaf.h | 2 ++
include/grub/zfs/zio.h | 2 ++
52 files changed, 277 insertions(+), 87 deletions(-)
diff --git a/grub-core/fs/affs.c b/grub-core/fs/affs.c
index ed606b3f1..3f298a696 100644
--- a/grub-core/fs/affs.c
+++ b/grub-core/fs/affs.c
@@ -30,6 +30,7 @@
GRUB_MOD_LICENSE ("GPLv3+");
/* The affs bootblock. */
+PRAGMA_BEGIN_PACKED
struct grub_affs_bblock
{
grub_uint8_t type[3];
@@ -77,6 +78,7 @@ struct grub_affs_file
grub_uint32_t extension;
grub_uint32_t type;
} GRUB_PACKED;
+PRAGMA_END_PACKED
/* The location of `struct grub_affs_file' relative to the end of a
file header block. */
diff --git a/grub-core/fs/bfs.c b/grub-core/fs/bfs.c
index 9bc478ce8..2b415387a 100644
--- a/grub-core/fs/bfs.c
+++ b/grub-core/fs/bfs.c
@@ -69,6 +69,7 @@ GRUB_MOD_LICENSE ("GPLv3+");
#define DOUBLE_INDIRECT_SHIFT 2
#define LOG_EXTENT_SIZE 3
+PRAGMA_BEGIN_PACKED
struct grub_bfs_extent
{
grub_uint32_t ag;
@@ -167,6 +168,7 @@ struct grub_bfs_btree_node
grub_uint16_t total_key_len;
#endif
} GRUB_PACKED;
+PRAGMA_END_PACKED
struct grub_bfs_data
{
diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c
index ba0c58352..b2299e94b 100644
--- a/grub-core/fs/btrfs.c
+++ b/grub-core/fs/btrfs.c
@@ -63,6 +63,7 @@ GRUB_MOD_LICENSE ("GPLv3+");
typedef grub_uint8_t grub_btrfs_checksum_t[0x20];
typedef grub_uint16_t grub_btrfs_uuid_t[8];
+PRAGMA_BEGIN_PACKED
struct grub_btrfs_device
{
grub_uint64_t device_id;
@@ -97,6 +98,7 @@ struct btrfs_header
grub_uint32_t nitems;
grub_uint8_t level;
} GRUB_PACKED;
+PRAGMA_END_PACKED
struct grub_btrfs_device_desc
{
@@ -111,8 +113,8 @@ struct grub_btrfs_data
grub_uint64_t inode;
struct grub_btrfs_device_desc *devices_attached;
- unsigned n_devices_attached;
- unsigned n_devices_allocated;
+ grub_size_t n_devices_attached;
+ grub_size_t n_devices_allocated;
/* Cached extent data. */
grub_uint64_t extstart;
@@ -123,6 +125,7 @@ struct grub_btrfs_data
struct grub_btrfs_extent_data *extent;
};
+PRAGMA_BEGIN_PACKED
struct grub_btrfs_chunk_item
{
grub_uint64_t size;
@@ -175,22 +178,24 @@ struct grub_btrfs_dir_item
#define GRUB_BTRFS_DIR_ITEM_TYPE_DIRECTORY 2
#define GRUB_BTRFS_DIR_ITEM_TYPE_SYMLINK 7
grub_uint8_t type;
- char name[0];
+ char name[1];
} GRUB_PACKED;
+PRAGMA_END_PACKED
struct grub_btrfs_leaf_descriptor
{
- unsigned depth;
- unsigned allocated;
+ grub_size_t depth;
+ grub_size_t allocated;
struct
{
grub_disk_addr_t addr;
- unsigned iter;
- unsigned maxiter;
+ grub_size_t iter;
+ grub_size_t maxiter;
int leaf;
} *data;
};
+PRAGMA_BEGIN_PACKED
struct grub_btrfs_time
{
grub_int64_t sec;
@@ -225,6 +230,7 @@ struct grub_btrfs_extent_data
};
};
} GRUB_PACKED;
+PRAGMA_END_PACKED
#define GRUB_BTRFS_EXTENT_INLINE 0
#define GRUB_BTRFS_EXTENT_REGULAR 1
@@ -697,7 +703,7 @@ struct raid56_buffer {
int data_is_valid;
};
-static void
+static grub_err_t
rebuild_raid5 (char *dest, struct raid56_buffer *buffers,
grub_uint64_t nstripes, grub_uint64_t csize)
{
@@ -709,7 +715,7 @@ rebuild_raid5 (char *dest, struct raid56_buffer *buffers,
if (i == nstripes)
{
grub_dprintf ("btrfs", "called rebuild_raid5(), but all disks are OK\n");
- return;
+ return GRUB_ERR_NONE;
}
grub_dprintf ("btrfs", "rebuilding RAID 5 stripe #%" PRIuGRUB_UINT64_T "\n", i);
@@ -725,8 +731,10 @@ rebuild_raid5 (char *dest, struct raid56_buffer *buffers,
} else
grub_crypto_xor (dest, dest, buffers[i].buf, csize);
}
+ return GRUB_ERR_NONE;
}
+#ifndef NO_RAID6_RECOVERY
static grub_err_t
raid6_recover_read_buffer (void *data, int disk_nr,
grub_uint64_t addr __attribute__ ((unused)),
@@ -741,15 +749,20 @@ raid6_recover_read_buffer (void *data, int disk_nr,
return grub_errno = GRUB_ERR_NONE;
}
+#endif
-static void
+static grub_err_t
rebuild_raid6 (struct raid56_buffer *buffers, grub_uint64_t nstripes,
grub_uint64_t csize, grub_uint64_t parities_pos, void *dest,
grub_uint64_t stripen)
{
- grub_raid6_recover_gen (buffers, nstripes, stripen, parities_pos,
- dest, 0, csize, 0, raid6_recover_read_buffer);
+#ifdef NO_RAID6_RECOVERY
+ return GRUB_ERR_NOT_IMPLEMENTED_YET;
+#else
+ return grub_raid6_recover_gen (buffers, nstripes, stripen, parities_pos,
+ dest, 0, csize, 0, raid6_recover_read_buffer);
+#endif
}
static grub_err_t
@@ -843,11 +856,10 @@ raid56_read_retry (struct grub_btrfs_data *data,
/* We have enough disks. So, rebuild the data. */
if (chunk_type & GRUB_BTRFS_CHUNK_TYPE_RAID5)
- rebuild_raid5 (buf, buffers, nstripes, csize);
+ ret = rebuild_raid5 (buf, buffers, nstripes, csize);
else
- rebuild_raid6 (buffers, nstripes, csize, parities_pos, buf, stripen);
+ ret = rebuild_raid6 (buffers, nstripes, csize, parities_pos, buf, stripen);
- ret = GRUB_ERR_NONE;
cleanup:
if (buffers)
for (i = 0; i < nstripes; i++)
@@ -965,8 +977,8 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data, grub_disk_addr_t addr,
"couldn't find the chunk descriptor");
}
- nstripes = grub_le_to_cpu16 (chunk->nstripes) ? : 1;
- chunk_stripe_length = grub_le_to_cpu64 (chunk->stripe_length) ? : 512;
+ nstripes = grub_le_to_cpu16 (chunk->nstripes) ? grub_le_to_cpu16(chunk->nstripes) : 1;
+ chunk_stripe_length = grub_le_to_cpu64 (chunk->stripe_length) ? grub_le_to_cpu64(chunk->stripe_length) : 512;
grub_dprintf ("btrfs", "chunk 0x%" PRIxGRUB_UINT64_T
"+0x%" PRIxGRUB_UINT64_T
" (%d stripes (%d substripes) of %"
@@ -1052,13 +1064,13 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data, grub_disk_addr_t addr,
grub_uint64_t middle, high;
grub_uint64_t low;
grub_uint16_t nsubstripes;
- nsubstripes = grub_le_to_cpu16 (chunk->nsubstripes) ? : 1;
+ nsubstripes = grub_le_to_cpu16 (chunk->nsubstripes) ? grub_le_to_cpu16(chunk->nsubstripes) : 1;
middle = grub_divmod64 (off,
chunk_stripe_length,
&low);
high = grub_divmod64 (middle,
- nstripes / nsubstripes ? : 1,
+ nstripes / nsubstripes ? nstripes / nsubstripes : 1,
&stripen);
stripen *= nsubstripes;
redundancy = nsubstripes;
@@ -1335,7 +1347,7 @@ static void *grub_zstd_malloc (void *state __attribute__((unused)), size_t size)
static void grub_zstd_free (void *state __attribute__((unused)), void *address)
{
- return grub_free (address);
+ grub_free (address);
}
static ZSTD_customMem grub_zstd_allocator (void)
diff --git a/grub-core/fs/cbfs.c b/grub-core/fs/cbfs.c
index 8ab7106af..b391277c7 100644
--- a/grub-core/fs/cbfs.c
+++ b/grub-core/fs/cbfs.c
@@ -44,7 +44,7 @@ struct grub_archelp_data
static grub_err_t
grub_cbfs_find_file (struct grub_archelp_data *data, char **name,
grub_int32_t *mtime,
- grub_uint32_t *mode)
+ grub_archelp_mode_t *mode)
{
grub_size_t offset;
for (;;
diff --git a/grub-core/fs/cpio_common.c b/grub-core/fs/cpio_common.c
index 5d41b6fdb..042870715 100644
--- a/grub-core/fs/cpio_common.c
+++ b/grub-core/fs/cpio_common.c
@@ -43,7 +43,7 @@ struct grub_archelp_data
static grub_err_t
grub_cpio_find_file (struct grub_archelp_data *data, char **name,
- grub_int32_t *mtime, grub_uint32_t *mode)
+ grub_int32_t *mtime, grub_archelp_mode_t *mode)
{
struct head hd;
grub_size_t namesize;
diff --git a/grub-core/fs/erofs.c b/grub-core/fs/erofs.c
index f2a82e988..c56918e71 100644
--- a/grub-core/fs/erofs.c
+++ b/grub-core/fs/erofs.c
@@ -37,6 +37,7 @@ GRUB_MOD_LICENSE ("GPLv3+");
#define EROFS_FEATURE_INCOMPAT_CHUNKED_FILE 0x00000004
#define EROFS_ALL_FEATURE_INCOMPAT EROFS_FEATURE_INCOMPAT_CHUNKED_FILE
+PRAGMA_BEGIN_PACKED
struct grub_erofs_super
{
grub_uint32_t magic;
@@ -71,6 +72,7 @@ struct grub_erofs_super
grub_uint64_t packed_nid;
grub_uint8_t reserved2[24];
} GRUB_PACKED;
+PRAGMA_END_PACKED
#define EROFS_INODE_LAYOUT_COMPACT 0
#define EROFS_INODE_LAYOUT_EXTENDED 1
@@ -87,11 +89,13 @@ struct grub_erofs_super
#define EROFS_I_VERSION_BIT 0
#define EROFS_I_DATALAYOUT_BIT 1
+PRAGMA_BEGIN_PACKED
struct grub_erofs_inode_chunk_info
{
grub_uint16_t format;
grub_uint16_t reserved;
} GRUB_PACKED;
+PRAGMA_END_PACKED
#define EROFS_CHUNK_FORMAT_BLKBITS_MASK 0x001F
#define EROFS_CHUNK_FORMAT_INDEXES 0x0020
@@ -122,6 +126,7 @@ union grub_erofs_inode_i_u
struct grub_erofs_inode_chunk_info c;
};
+PRAGMA_BEGIN_PACKED
struct grub_erofs_inode_compact
{
grub_uint16_t i_format;
@@ -183,6 +188,7 @@ struct grub_erofs_dirent
grub_uint8_t file_type;
grub_uint8_t reserved;
} GRUB_PACKED;
+PRAGMA_END_PACKED
struct grub_erofs_map_blocks
{
diff --git a/grub-core/fs/f2fs.c b/grub-core/fs/f2fs.c
index 855e24618..273ff806d 100644
--- a/grub-core/fs/f2fs.c
+++ b/grub-core/fs/f2fs.c
@@ -132,6 +132,7 @@ enum FILE_TYPE
F2FS_FT_SYMLINK = 7
};
+PRAGMA_BEGIN_PACKED
struct grub_f2fs_superblock
{
grub_uint32_t magic;
@@ -282,6 +283,7 @@ struct grub_f2fs_node
};
grub_uint8_t dummy[40];
} GRUB_PACKED;
+PRAGMA_END_PACKED
struct grub_fshelp_node
{
diff --git a/grub-core/fs/fat.c b/grub-core/fs/fat.c
index c5efed724..0ce1eb6da 100644
--- a/grub-core/fs/fat.c
+++ b/grub-core/fs/fat.c
@@ -76,6 +76,7 @@ enum
{
FLAG_CONTIGUOUS = 2
};
+PRAGMA_BEGIN_PACKED
struct grub_fat_dir_entry
{
grub_uint8_t entry_type;
@@ -116,6 +117,7 @@ struct grub_fat_dir_entry
} GRUB_PACKED volume_label;
} GRUB_PACKED type_specific;
} GRUB_PACKED;
+PRAGMA_END_PACKED
struct grub_fat_dir_node
{
@@ -130,6 +132,7 @@ struct grub_fat_dir_node
typedef struct grub_fat_dir_node grub_fat_dir_node_t;
#else
+PRAGMA_BEGIN_PACKED
struct grub_fat_dir_entry
{
grub_uint8_t name[11];
@@ -157,6 +160,7 @@ struct grub_fat_long_name_entry
grub_uint16_t first_cluster;
grub_uint16_t name3[2];
} GRUB_PACKED;
+PRAGMA_END_PACKED
typedef struct grub_fat_dir_entry grub_fat_dir_node_t;
@@ -728,7 +732,7 @@ grub_fat_iterate_dir_next (grub_fshelp_node_t node,
grub_dprintf ("exfat", "unknown primary type 0x%02x\n",
dir->entry_type);
}
- return grub_errno ? : GRUB_ERR_EOF;
+ return grub_errno ? grub_errno : GRUB_ERR_EOF;
}
/*
@@ -882,7 +886,7 @@ grub_fat_iterate_dir_next (grub_fshelp_node_t node,
return GRUB_ERR_NONE;
}
- return grub_errno ? : GRUB_ERR_EOF;
+ return grub_errno ? grub_errno : GRUB_ERR_EOF;
}
/*
diff --git a/grub-core/fs/hfs.c b/grub-core/fs/hfs.c
index 91dc0e69c..56a44ddae 100644
--- a/grub-core/fs/hfs.c
+++ b/grub-core/fs/hfs.c
@@ -59,6 +59,7 @@ enum grub_hfs_cnid_type
};
/* A node descriptor. This is the header of every node. */
+PRAGMA_BEGIN_PACKED
struct grub_hfs_node
{
grub_uint32_t next;
@@ -84,6 +85,7 @@ struct grub_hfs_treeheader
grub_uint32_t free_nodes;
grub_uint8_t unused[76];
} GRUB_PACKED;
+PRAGMA_END_PACKED
/* The state of a mounted HFS filesystem. */
struct grub_hfs_data
@@ -104,6 +106,7 @@ struct grub_hfs_data
/* The key as used on disk in a catalog tree. This is used to lookup
file/directory nodes by parent directory ID and filename. */
+PRAGMA_BEGIN_PACKED
struct grub_hfs_catalog_key
{
grub_uint8_t unused;
@@ -157,6 +160,7 @@ struct grub_hfs_filerec
in the extent overflow file. */
grub_hfs_datarecord_t extents;
} GRUB_PACKED;
+PRAGMA_END_PACKED
/* A record descriptor, both key and data, used to pass to call back
functions. */
@@ -721,11 +725,13 @@ grub_hfs_iterate_records (struct grub_hfs_data *data, int type, int idx,
for (i = 0; i < reccnt; i++)
{
int pos = (nodesize >> 1) - 1 - i;
+ PRAGMA_BEGIN_PACKED
struct pointer
{
grub_uint8_t keylen;
grub_uint8_t key;
} GRUB_PACKED *pnt;
+ PRAGMA_END_PACKED
grub_uint16_t off = grub_be_to_cpu16 (node->offsets[pos]);
if (off > nodesize - sizeof(*pnt))
continue;
diff --git a/grub-core/fs/hfsplus.c b/grub-core/fs/hfsplus.c
index 295822f69..dd5a39f49 100644
--- a/grub-core/fs/hfsplus.c
+++ b/grub-core/fs/hfsplus.c
@@ -45,6 +45,7 @@ enum grub_hfsplus_btnode_type
};
/* The header of a HFS+ B+ Tree. */
+PRAGMA_BEGIN_PACKED
struct grub_hfsplus_btheader
{
grub_uint16_t depth;
@@ -77,6 +78,7 @@ struct grub_hfsplus_catfile
struct grub_hfsplus_forkdata data;
struct grub_hfsplus_forkdata resource;
} GRUB_PACKED;
+PRAGMA_END_PACKED
/* Filetype information as used in inodes. */
#define GRUB_HFSPLUS_FILEMODE_MASK 0170000
diff --git a/grub-core/fs/hfspluscomp.c b/grub-core/fs/hfspluscomp.c
index 48ae438d8..c5875dc16 100644
--- a/grub-core/fs/hfspluscomp.c
+++ b/grub-core/fs/hfspluscomp.c
@@ -28,6 +28,7 @@
GRUB_MOD_LICENSE ("GPLv3+");
/* big-endian. */
+PRAGMA_BEGIN_PACKED
struct grub_hfsplus_compress_header1
{
grub_uint32_t header_size;
@@ -48,6 +49,7 @@ struct grub_hfsplus_compress_header3
{
grub_uint32_t num_chunks;
} GRUB_PACKED;
+PRAGMA_END_PACKED
/* little-endian. */
struct grub_hfsplus_compress_block_descriptor
@@ -56,6 +58,7 @@ struct grub_hfsplus_compress_block_descriptor
grub_uint32_t size;
};
+PRAGMA_BEGIN_PACKED
struct grub_hfsplus_compress_end_descriptor
{
grub_uint8_t always_the_same[50];
@@ -76,6 +79,7 @@ struct grub_hfsplus_compress_attr
grub_uint32_t uncompressed_inline_size;
grub_uint32_t always_0;
} GRUB_PACKED;
+PRAGMA_END_PACKED
enum
{
diff --git a/grub-core/fs/iso9660.c b/grub-core/fs/iso9660.c
index 8c348b59a..0425ea2bf 100644
--- a/grub-core/fs/iso9660.c
+++ b/grub-core/fs/iso9660.c
@@ -53,6 +53,7 @@ GRUB_MOD_LICENSE ("GPLv3+");
#define GRUB_ISO9660_MAX_CE_HOPS 100000
/* The head of a volume descriptor. */
+PRAGMA_BEGIN_PACKED
struct grub_iso9660_voldesc
{
grub_uint8_t type;
@@ -133,8 +134,18 @@ struct grub_iso9660_susp_entry
{
grub_uint8_t sig[2];
grub_uint8_t len;
- grub_uint8_t version;
- grub_uint8_t data[0];
+/*! MSVC compilers cannot handle a zero sized array in the middle
+ of a struct, and grub_iso9660_susp_entry is reused within
+ grub_iso9660_susp_ce. Therefore, instead of defining:
+ grub_uint8_t version;
+ grub_uint8_t data[];
+ we leverage the fact that these attributes are the same size
+ and use an union. The only gotcha is that the actual
+ payload of u.data[] starts at 1, not 0. */
+ union {
+ grub_uint8_t version;
+ grub_uint8_t data[1];
+ } u;
} GRUB_PACKED;
/* The CE entry. This is used to describe the next block where data
@@ -149,6 +160,7 @@ struct grub_iso9660_susp_ce
grub_uint32_t len;
grub_uint32_t len_be;
} GRUB_PACKED;
+PRAGMA_END_PACKED
struct grub_iso9660_data
{
@@ -473,7 +485,7 @@ set_rockridge (struct grub_iso9660_data *data)
* The 2nd data byte stored how many bytes are skipped every time
* to get to the SUA (System Usage Area).
*/
- data->susp_skip = entry->data[2];
+ data->susp_skip = entry->u.data[1 + 2];
entry = (struct grub_iso9660_susp_entry *) ((char *) entry + entry->len);
/* Iterate over the entries in the SUA area to detect
@@ -624,9 +636,9 @@ susp_iterate_dir (struct grub_iso9660_susp_entry *entry,
/* The flags are stored at the data position 0, here the
filename type is stored. */
/* FIXME: Fix this slightly improper cast. */
- if (entry->data[0] & GRUB_ISO9660_RR_DOT)
+ if (entry->u.data[1 + 0] & GRUB_ISO9660_RR_DOT)
ctx->filename = (char *) ".";
- else if (entry->data[0] & GRUB_ISO9660_RR_DOTDOT)
+ else if (entry->u.data[1 + 0] & GRUB_ISO9660_RR_DOTDOT)
ctx->filename = (char *) "..";
else if (entry->len >= 5)
{
@@ -657,7 +669,7 @@ susp_iterate_dir (struct grub_iso9660_susp_entry *entry,
return grub_errno;
}
ctx->filename_alloc = 1;
- grub_memcpy (ctx->filename + off, (char *) &entry->data[1], csize);
+ grub_memcpy (ctx->filename + off, (char *) &entry->u.data[1 + 1], csize);
ctx->filename[off + csize] = '\0';
}
}
@@ -666,7 +678,7 @@ susp_iterate_dir (struct grub_iso9660_susp_entry *entry,
{
/* At position 0 of the PX record the st_mode information is
stored (little-endian). */
- grub_uint32_t mode = ((entry->data[0] + (entry->data[1] << 8))
+ grub_uint32_t mode = ((entry->u.data[1 + 0] + (entry->u.data[1 + 1] << 8))
& GRUB_ISO9660_FSTYPE_MASK);
switch (mode)
@@ -700,12 +712,12 @@ susp_iterate_dir (struct grub_iso9660_susp_entry *entry,
* "Component Flags"; entry->data[pos + 1] is the length
* of the component.
*/
- csize = entry->data[pos + 1] + 2;
+ csize = entry->u.data[1 + pos + 1] + 2;
if (GRUB_ISO9660_SUSP_HEADER_SZ + 1 + csize > entry->len)
break;
/* The current position is the `Component Flag'. */
- switch (entry->data[pos] & 30)
+ switch (entry->u.data[1 + pos] & 30)
{
case 0:
{
@@ -719,9 +731,9 @@ susp_iterate_dir (struct grub_iso9660_susp_entry *entry,
return grub_errno;
}
- add_part (ctx, (char *) &entry->data[pos + 2],
- entry->data[pos + 1]);
- ctx->was_continue = (entry->data[pos] & 1);
+ add_part (ctx, (char *) &entry->u.data[1 + pos + 2],
+ entry->u.data[1 + pos + 1]);
+ ctx->was_continue = (entry->u.data[1 + pos] & 1);
break;
}
@@ -744,7 +756,7 @@ susp_iterate_dir (struct grub_iso9660_susp_entry *entry,
/* In pos + 1 the length of the `Component Record' is
stored. */
- pos += entry->data[pos + 1] + 2;
+ pos += entry->u.data[1 + pos + 1] + 2;
}
/* Check if `grub_realloc' failed. */
diff --git a/grub-core/fs/jfs.c b/grub-core/fs/jfs.c
index 62e20ef6f..e1a3b8b1a 100644
--- a/grub-core/fs/jfs.c
+++ b/grub-core/fs/jfs.c
@@ -61,6 +61,7 @@ struct grub_jfs_sblock
char volname2[16];
};
+PRAGMA_BEGIN_PACKED
struct grub_jfs_extent
{
/* The length of the extent in filesystem blocks. */
@@ -252,10 +253,11 @@ struct grub_jfs_diropen
char name[256 * GRUB_MAX_UTF8_PER_UTF16 + 1];
grub_uint32_t ino;
} GRUB_PACKED;
-
+PRAGMA_END_PACKED
static grub_dl_t my_mod;
-
+
+
static grub_err_t grub_jfs_lookup_symlink (struct grub_jfs_data *data, grub_uint32_t ino);
static grub_int64_t
diff --git a/grub-core/fs/nilfs2.c b/grub-core/fs/nilfs2.c
index fc7374ead..f62f7788d 100644
--- a/grub-core/fs/nilfs2.c
+++ b/grub-core/fs/nilfs2.c
@@ -132,6 +132,7 @@ struct grub_nilfs2_super_block
grub_uint32_t s_reserved[192];
};
+PRAGMA_BEGIN_PACKED
struct grub_nilfs2_dir_entry
{
grub_uint64_t inode;
@@ -144,6 +145,7 @@ struct grub_nilfs2_dir_entry
char pad;
#endif
} GRUB_PACKED;
+PRAGMA_END_PACKED
enum
{
@@ -753,7 +755,7 @@ static grub_err_t
grub_nilfs2_load_sb (struct grub_nilfs2_data *data)
{
grub_disk_t disk = data->disk;
- struct grub_nilfs2_super_block sb2;
+ struct grub_nilfs2_super_block sb2 = { 0 };
grub_uint64_t partition_size;
int valid[2];
int swp = 0;
diff --git a/grub-core/fs/ntfs.c b/grub-core/fs/ntfs.c
index de435aa14..b44f5381b 100644
--- a/grub-core/fs/ntfs.c
+++ b/grub-core/fs/ntfs.c
@@ -689,6 +689,7 @@ list_file (struct grub_ntfs_file *diro, grub_uint8_t *pos, grub_uint8_t *end_pos
return 0;
}
+PRAGMA_BEGIN_PACKED
struct symlink_descriptor
{
grub_uint32_t type;
@@ -698,6 +699,7 @@ struct symlink_descriptor
grub_uint16_t off2;
grub_uint16_t len2;
} GRUB_PACKED;
+PRAGMA_END_PACKED
static char *
grub_ntfs_read_symlink (grub_fshelp_node_t node)
diff --git a/grub-core/fs/proc.c b/grub-core/fs/proc.c
index 5f516502d..06217f58b 100644
--- a/grub-core/fs/proc.c
+++ b/grub-core/fs/proc.c
@@ -90,7 +90,7 @@ grub_procfs_rewind (struct grub_archelp_data *data)
static grub_err_t
grub_procfs_find_file (struct grub_archelp_data *data, char **name,
grub_int32_t *mtime,
- grub_uint32_t *mode)
+ grub_archelp_mode_t *mode)
{
data->entry = data->next_entry;
if (!data->entry)
diff --git a/grub-core/fs/reiserfs.c b/grub-core/fs/reiserfs.c
index 36b26ac98..3c001897e 100644
--- a/grub-core/fs/reiserfs.c
+++ b/grub-core/fs/reiserfs.c
@@ -42,15 +42,27 @@
GRUB_MOD_LICENSE ("GPLv3+");
+#ifndef _MSC_VER
+#ifndef MIN
#define MIN(a, b) \
({ typeof (a) _a = (a); \
typeof (b) _b = (b); \
_a < _b ? _a : _b; })
-
+#endif
+#ifndef MAX
#define MAX(a, b) \
({ typeof (a) _a = (a); \
typeof (b) _b = (b); \
_a > _b ? _a : _b; })
+#endif
+#else
+#ifndef MIN
+#define MIN(a, b) ((a)<(b)?(a):(b))
+#endif
+#ifndef MAX
+#define MAX(a, b) ((a)>(b)?(a):(b))
+#endif
+#endif
#define REISERFS_SUPER_BLOCK_OFFSET 0x10000
#define REISERFS_MAGIC_LEN 12
@@ -82,6 +94,7 @@ enum grub_reiserfs_item_type
GRUB_REISERFS_UNKNOWN
};
+PRAGMA_BEGIN_PACKED
struct grub_reiserfs_superblock
{
grub_uint32_t block_count;
@@ -217,6 +230,7 @@ struct grub_reiserfs_directory_header
grub_uint16_t location;
grub_uint16_t state;
} GRUB_PACKED;
+PRAGMA_END_PACKED
struct grub_fshelp_node
{
diff --git a/grub-core/fs/sfs.c b/grub-core/fs/sfs.c
index 983e88008..337700914 100644
--- a/grub-core/fs/sfs.c
+++ b/grub-core/fs/sfs.c
@@ -31,6 +31,7 @@
GRUB_MOD_LICENSE ("GPLv3+");
/* The common header for a block. */
+PRAGMA_BEGIN_PACKED
struct grub_sfs_bheader
{
grub_uint8_t magic[4];
@@ -122,8 +123,9 @@ struct grub_sfs_btree
supported. */
struct grub_sfs_btree_node node[1];
} GRUB_PACKED;
+PRAGMA_END_PACKED
+
-
struct cache_entry
{
diff --git a/grub-core/fs/squash4.c b/grub-core/fs/squash4.c
index a30e6ebe1..65798008d 100644
--- a/grub-core/fs/squash4.c
+++ b/grub-core/fs/squash4.c
@@ -51,6 +51,7 @@ GRUB_MOD_LICENSE ("GPLv3+");
unk2 containts one uint64_t
*/
+PRAGMA_BEGIN_PACKED
struct grub_squash_super
{
grub_uint32_t magic;
@@ -89,7 +90,7 @@ struct grub_squash_inode
grub_uint32_t fragment;
grub_uint32_t offset;
grub_uint32_t size;
- grub_uint32_t block_size[0];
+ grub_uint32_t block_size[1];
} GRUB_PACKED file;
struct {
grub_uint64_t chunk;
@@ -98,7 +99,7 @@ struct grub_squash_inode
grub_uint32_t fragment;
grub_uint32_t offset;
grub_uint32_t dummy3;
- grub_uint32_t block_size[0];
+ grub_uint32_t block_size[1];
} GRUB_PACKED long_file;
struct {
grub_uint32_t chunk;
@@ -117,10 +118,11 @@ struct grub_squash_inode
struct {
grub_uint32_t dummy;
grub_uint32_t namelen;
- char name[0];
+ char name[1];
} GRUB_PACKED symlink;
} GRUB_PACKED;
} GRUB_PACKED;
+PRAGMA_END_PACKED
struct grub_squash_cache_inode
{
@@ -131,6 +133,7 @@ struct grub_squash_cache_inode
grub_disk_addr_t *cumulated_block_sizes;
};
+PRAGMA_BEGIN_PACKED
/* Chunk-based. */
struct grub_squash_dirent_header
{
@@ -166,6 +169,7 @@ struct grub_squash_frag_desc
grub_uint32_t size;
grub_uint32_t dummy;
} GRUB_PACKED;
+PRAGMA_END_PACKED
enum
{
diff --git a/grub-core/fs/tar.c b/grub-core/fs/tar.c
index c551ed6b5..b1822f095 100644
--- a/grub-core/fs/tar.c
+++ b/grub-core/fs/tar.c
@@ -72,7 +72,7 @@ struct grub_archelp_data
static grub_err_t
grub_cpio_find_file (struct grub_archelp_data *data, char **name,
grub_int32_t *mtime,
- grub_uint32_t *mode)
+ grub_archelp_mode_t *mode)
{
struct head hd;
int reread = 0, have_longname = 0, have_longlink = 0;
diff --git a/grub-core/fs/udf.c b/grub-core/fs/udf.c
index b836e6107..bfec4ef49 100644
--- a/grub-core/fs/udf.c
+++ b/grub-core/fs/udf.c
@@ -118,6 +118,7 @@ GRUB_MOD_LICENSE ("GPLv3+");
((char *) (_ptr) >= end_ptr || \
((grub_ssize_t) (end_ptr - (char *) (_ptr)) < (grub_ssize_t) sizeof (_struct)))
+PRAGMA_BEGIN_PACKED
struct grub_udf_lb_addr
{
grub_uint32_t block_num;
@@ -375,6 +376,7 @@ struct grub_udf_aed
grub_uint32_t prev_ae;
grub_uint32_t ae_len;
} GRUB_PACKED;
+PRAGMA_END_PACKED
struct grub_udf_data
{
diff --git a/grub-core/fs/ufs.c b/grub-core/fs/ufs.c
index a354c92d9..92d2020a8 100644
--- a/grub-core/fs/ufs.c
+++ b/grub-core/fs/ufs.c
@@ -152,6 +152,7 @@ struct grub_ufs_sblock
grub_uint32_t magic;
};
+PRAGMA_BEGIN_PACKED
#ifdef MODE_UFS2
/* UFS inode. */
struct grub_ufs_inode
@@ -235,6 +236,7 @@ struct grub_ufs_dirent
};
};
} GRUB_PACKED;
+PRAGMA_END_PACKED
/* Information about a "mounted" ufs filesystem. */
struct grub_ufs_data
diff --git a/grub-core/fs/xfs.c b/grub-core/fs/xfs.c
index 8e02ab4a3..48c6c8613 100644
--- a/grub-core/fs/xfs.c
+++ b/grub-core/fs/xfs.c
@@ -107,6 +107,7 @@ GRUB_MOD_LICENSE ("GPLv3+");
XFS_SB_FEAT_INCOMPAT_NEEDSREPAIR | \
XFS_SB_FEAT_INCOMPAT_NREXT64)
+PRAGMA_BEGIN_PACKED
struct grub_xfs_sblock
{
grub_uint8_t magic[4];
@@ -239,6 +240,7 @@ struct grub_xfs_dirblock_tail
grub_uint32_t leaf_count;
grub_uint32_t leaf_stale;
} GRUB_PACKED;
+PRAGMA_END_PACKED
struct grub_fshelp_node
{
diff --git a/grub-core/fs/zfs/zfs.c b/grub-core/fs/zfs/zfs.c
index 3fdf9bda8..753703f54 100644
--- a/grub-core/fs/zfs/zfs.c
+++ b/grub-core/fs/zfs/zfs.c
@@ -254,8 +254,8 @@ struct grub_zfs_data
struct subvolume subvol;
struct grub_zfs_device_desc *devices_attached;
- unsigned n_devices_attached;
- unsigned n_devices_allocated;
+ grub_size_t n_devices_attached;
+ grub_size_t n_devices_allocated;
struct grub_zfs_device_desc *device_original;
uberblock_t current_uberblock;
@@ -2767,7 +2767,9 @@ dnode_get (dnode_end_t * mdn, grub_uint64_t objnum, grub_uint8_t type,
return GRUB_ERR_NONE;
}
+#ifdef __GNUC__
#pragma GCC diagnostic ignored "-Wstrict-aliasing"
+#endif
/*
* Get the file dnode for a given file name where mdn is the meta dnode
diff --git a/grub-core/fs/zfs/zfs_lz4.c b/grub-core/fs/zfs/zfs_lz4.c
index 5453822d0..873445803 100644
--- a/grub-core/fs/zfs/zfs_lz4.c
+++ b/grub-core/fs/zfs/zfs_lz4.c
@@ -74,6 +74,7 @@ static int LZ4_uncompress_unknownOutputSize(const char *source, char *dest,
#define S32 grub_int32_t
#define U64 grub_uint64_t
+PRAGMA_BEGIN_PACKED
typedef struct _U16_S {
U16 v;
} GRUB_PACKED U16_S;
@@ -83,6 +84,7 @@ typedef struct _U32_S {
typedef struct _U64_S {
U64 v;
} GRUB_PACKED U64_S;
+PRAGMA_END_PACKED
#define A64(x) (((U64_S *)(x))->v)
#define A32(x) (((U32_S *)(x))->v)
diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c
index 7cee5d75c..30ff90432 100644
--- a/grub-core/kern/misc.c
+++ b/grub-core/kern/misc.c
@@ -37,7 +37,7 @@ union printf_arg
INT, LONG, LONGLONG,
UNSIGNED_INT = 3, UNSIGNED_LONG, UNSIGNED_LONGLONG,
STRING,
- GUID
+ UUID