├── .gitattributes
├── .github
└── workflows
│ └── msbuild.yml
├── .gitignore
├── LICENSE
├── NkArc.sln
├── NkArc.vcxproj
├── NkArc.vcxproj.filters
├── README.md
├── about.c
├── disk_info.c
├── enum_disk.c
├── enum_file.c
├── extract_file.c
├── fm.c
├── grub
├── disk
│ ├── diskfilter.c
│ ├── dmraid_nvidia.c
│ ├── ldm.c
│ ├── loopback.c
│ ├── lvm.c
│ ├── mdraid1x_linux.c
│ ├── mdraid_linux.c
│ ├── mdraid_linux_be.c
│ ├── raid5_recover.c
│ ├── raid6_recover.c
│ └── windisk.c
├── fs
│ ├── affs.c
│ ├── afs.c
│ ├── archelp.c
│ ├── bfs.c
│ ├── btrfs.c
│ ├── cpio.c
│ ├── cpio_be.c
│ ├── cpio_common.c
│ ├── erofs.c
│ ├── exfat.c
│ ├── ext2.c
│ ├── f2fs.c
│ ├── fat.c
│ ├── fbfs.c
│ ├── fshelp.c
│ ├── hfs.c
│ ├── hfsplus.c
│ ├── hfspluscomp.c
│ ├── iso9660.c
│ ├── jfs.c
│ ├── lynxfs.c
│ ├── minix.c
│ ├── minix2.c
│ ├── minix2_be.c
│ ├── minix3.c
│ ├── minix3_be.c
│ ├── minix_be.c
│ ├── newc.c
│ ├── nilfs2.c
│ ├── ntfs.c
│ ├── ntfscomp.c
│ ├── odc.c
│ ├── proc.c
│ ├── qnx4.c
│ ├── qnx6.c
│ ├── reiserfs.c
│ ├── romfs.c
│ ├── sfs.c
│ ├── squash4.c
│ ├── tar.c
│ ├── udf.c
│ ├── uefi.c
│ ├── ufs.c
│ ├── ufs2.c
│ ├── ufs_be.c
│ ├── wim.c
│ ├── xfs.c
│ ├── zfs
│ │ ├── zfs.c
│ │ ├── zfs_fletcher.c
│ │ ├── zfs_lz4.c
│ │ ├── zfs_lzjb.c
│ │ ├── zfs_sha256.c
│ │ └── zfs_zstd.c
│ └── zip.c
├── io
│ ├── dmg.c
│ ├── gzio.c
│ ├── lz4io.c
│ ├── lzma.c
│ ├── lzopio.c
│ ├── qcow.c
│ ├── vdi.c
│ ├── vhd.c
│ ├── vhdx.c
│ ├── xzio.c
│ └── zstd.c
├── kern
│ ├── disk.c
│ ├── dl.c
│ ├── efi.c
│ ├── err.c
│ ├── file.c
│ ├── fs.c
│ ├── list.c
│ ├── misc.c
│ ├── mm.c
│ ├── partition.c
│ └── time.c
├── lib
│ ├── LzmaDec.c
│ ├── adler32.c
│ ├── bzip2
│ │ ├── bz_version.h
│ │ ├── bzlib.c
│ │ ├── bzlib.h
│ │ ├── bzlib_private.h
│ │ ├── crctable.c
│ │ ├── decompress.c
│ │ ├── huffman.c
│ │ └── randtable.c
│ ├── charset.c
│ ├── crc.c
│ ├── crc64.c
│ ├── crypto.c
│ ├── datetime.c
│ ├── libgcrypt
│ │ ├── gcry_crc.c
│ │ ├── gcry_md5.c
│ │ ├── gcry_sha1.c
│ │ ├── gcry_sha256.c
│ │ └── gcry_wrap.h
│ ├── lz4
│ │ ├── lz4.c
│ │ └── lz4.h
│ ├── minilzo
│ │ ├── lzoconf.h
│ │ ├── lzodefs.h
│ │ ├── minilzo.c
│ │ └── minilzo.h
│ ├── miniz
│ │ ├── miniz.c
│ │ └── miniz.h
│ ├── mscompress
│ │ ├── huffman.c
│ │ ├── lzx.c
│ │ ├── mscompress.h
│ │ └── xpress.c
│ ├── progress.c
│ ├── vbox
│ │ ├── vbox.c
│ │ └── vbox.h
│ ├── xzembed
│ │ ├── xz.h
│ │ ├── xz_config.h
│ │ ├── xz_dec_bcj.c
│ │ ├── xz_dec_lzma2.c
│ │ ├── xz_dec_stream.c
│ │ ├── xz_lzma2.h
│ │ ├── xz_private.h
│ │ └── xz_stream.h
│ └── zstd
│ │ ├── common
│ │ ├── allocations.h
│ │ ├── bits.h
│ │ ├── bitstream.h
│ │ ├── compiler.h
│ │ ├── cpu.h
│ │ ├── debug.c
│ │ ├── debug.h
│ │ ├── entropy_common.c
│ │ ├── error_private.c
│ │ ├── error_private.h
│ │ ├── fse.h
│ │ ├── fse_decompress.c
│ │ ├── huf.h
│ │ ├── mem.h
│ │ ├── pool.c
│ │ ├── pool.h
│ │ ├── portability_macros.h
│ │ ├── xxhash.c
│ │ ├── xxhash.h
│ │ ├── zstd_common.c
│ │ ├── zstd_deps.h
│ │ ├── zstd_internal.h
│ │ └── zstd_trace.h
│ │ ├── decompress
│ │ ├── huf_decompress.c
│ │ ├── huf_decompress_amd64.S
│ │ ├── zstd_ddict.c
│ │ ├── zstd_ddict.h
│ │ ├── zstd_decompress.c
│ │ ├── zstd_decompress_block.c
│ │ ├── zstd_decompress_block.h
│ │ └── zstd_decompress_internal.h
│ │ ├── zdict.h
│ │ ├── zstd.h
│ │ └── zstd_errors.h
└── partmap
│ ├── acorn.c
│ ├── amiga.c
│ ├── apple.c
│ ├── bsdlabel.c
│ ├── dfly.c
│ ├── dvh.c
│ ├── gpt.c
│ ├── msdos.c
│ ├── plan.c
│ ├── sun.c
│ └── sunpc.c
├── hash_file.c
├── hex_view.c
├── icons
├── arc.png
├── bin.png
├── cd.png
├── copy.png
├── dir.png
├── doc.png
├── empty.png
├── error.png
├── fdd.png
├── file.png
├── font.png
├── fw.png
├── hdd.png
├── image.png
├── info.png
├── iso.png
├── link.png
├── lock.png
├── music.png
├── net.png
├── ok.png
├── pc.png
├── pdf.png
├── refresh.png
├── rm.png
├── server.png
├── settings.png
├── txt.png
├── unknown.png
├── unlock.png
├── up.png
├── video.png
└── win.png
├── img_view.c
├── include
├── config.h
├── dl.h
├── grub
│ ├── acorn_filecore.h
│ ├── archelp.h
│ ├── bsdlabel.h
│ ├── btrfs.h
│ ├── charset.h
│ ├── crypto.h
│ ├── datetime.h
│ ├── deflate.h
│ ├── disk.h
│ ├── diskfilter.h
│ ├── efi.h
│ ├── err.h
│ ├── exfat.h
│ ├── fat.h
│ ├── fbfs.h
│ ├── file.h
│ ├── fs.h
│ ├── fshelp.h
│ ├── gpt_partition.h
│ ├── hfs.h
│ ├── hfsplus.h
│ ├── lib
│ │ ├── LzmaDec.h
│ │ ├── LzmaTypes.h
│ │ └── crc.h
│ ├── list.h
│ ├── lvm.h
│ ├── misc.h
│ ├── mm.h
│ ├── msdos_partition.h
│ ├── ntfs.h
│ ├── partition.h
│ ├── procfs.h
│ ├── safemath.h
│ ├── symbol.h
│ ├── time.h
│ ├── types.h
│ ├── udf.h
│ └── zfs
│ │ ├── dmu.h
│ │ ├── dmu_objset.h
│ │ ├── dnode.h
│ │ ├── dsl_dataset.h
│ │ ├── dsl_dir.h
│ │ ├── sa_impl.h
│ │ ├── spa.h
│ │ ├── uberblock_impl.h
│ │ ├── vdev_impl.h
│ │ ├── zap_impl.h
│ │ ├── zap_leaf.h
│ │ ├── zfs.h
│ │ ├── zfs_acl.h
│ │ ├── zfs_znode.h
│ │ ├── zil.h
│ │ ├── zio.h
│ │ └── zio_checksum.h
├── lang.h
├── loopback.h
├── nkctx.h
├── nuklear.h
├── nuklear_gdip.h
├── resource.h
└── version.h
├── lang.c
├── main.c
├── mount_file.c
├── nkctx.c
├── nuklear.c
├── nuklear.ico
├── nuklear.rc
└── packages.config
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
--------------------------------------------------------------------------------
/.github/workflows/msbuild.yml:
--------------------------------------------------------------------------------
1 | name: MSBuild
2 |
3 | on:
4 | workflow_dispatch:
5 | push:
6 | branches:
7 | - "master"
8 |
9 | env:
10 | # Path to the solution file relative to the root of the project.
11 | SOLUTION_FILE_PATH: .
12 |
13 | jobs:
14 | build:
15 | runs-on: windows-latest
16 |
17 | steps:
18 | - uses: actions/checkout@v4
19 |
20 | - name: Add MSBuild to PATH
21 | uses: microsoft/setup-msbuild@v2
22 |
23 | - name: Restore NuGet packages
24 | working-directory: ${{env.GITHUB_WORKSPACE}}
25 | run: nuget restore ${{env.SOLUTION_FILE_PATH}}
26 |
27 | - name: Build
28 | working-directory: ${{env.GITHUB_WORKSPACE}}
29 | # Add additional options to the MSBuild command line here (like platform or verbosity level).
30 | # See https://docs.microsoft.com/visualstudio/msbuild/msbuild-command-line-reference
31 | run: |
32 | msbuild /m /p:Configuration=Release /p:platform=x64 ${{env.SOLUTION_FILE_PATH}}
33 | msbuild /m /p:Configuration=Release /p:platform=x86 ${{env.SOLUTION_FILE_PATH}}
34 | md NkArc
35 | md NkArc\x64
36 | move x64\Release\NkArc.exe NkArc\x64\NkArc.exe
37 | md NkArc\x86
38 | move Win32\Release\NkArc.exe NkArc\x86\NkArc.exe
39 | copy LICENSE NkArc\LICENSE
40 |
41 | - name: Create ZIP
42 | uses: thedoctor0/zip-release@master
43 | with:
44 | type: 'zip'
45 | filename: 'NkArc.zip'
46 | directory: '.'
47 | path: 'NkArc'
48 |
49 | - name: Delete old release
50 | continue-on-error: true
51 | working-directory: ${{env.GITHUB_WORKSPACE}}
52 | run: |
53 | gh release delete latest --cleanup-tag --yes
54 | env:
55 | GH_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
56 |
57 | - name: Release
58 | working-directory: ${{env.GITHUB_WORKSPACE}}
59 | run: |
60 | gh release create latest NkArc.zip --latest -t "Development Build"
61 | env:
62 | GH_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
63 |
--------------------------------------------------------------------------------
/NkArc.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 17
4 | VisualStudioVersion = 17.7.34031.279
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "NkArc", "NkArc.vcxproj", "{1945F0F0-9D0B-46AC-BADE-99B7EE7CCDA7}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|x64 = Debug|x64
11 | Debug|x86 = Debug|x86
12 | Release|x64 = Release|x64
13 | Release|x86 = Release|x86
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {1945F0F0-9D0B-46AC-BADE-99B7EE7CCDA7}.Debug|x64.ActiveCfg = Debug|x64
17 | {1945F0F0-9D0B-46AC-BADE-99B7EE7CCDA7}.Debug|x64.Build.0 = Debug|x64
18 | {1945F0F0-9D0B-46AC-BADE-99B7EE7CCDA7}.Debug|x86.ActiveCfg = Debug|Win32
19 | {1945F0F0-9D0B-46AC-BADE-99B7EE7CCDA7}.Debug|x86.Build.0 = Debug|Win32
20 | {1945F0F0-9D0B-46AC-BADE-99B7EE7CCDA7}.Release|x64.ActiveCfg = Release|x64
21 | {1945F0F0-9D0B-46AC-BADE-99B7EE7CCDA7}.Release|x64.Build.0 = Release|x64
22 | {1945F0F0-9D0B-46AC-BADE-99B7EE7CCDA7}.Release|x86.ActiveCfg = Release|Win32
23 | {1945F0F0-9D0B-46AC-BADE-99B7EE7CCDA7}.Release|x86.Build.0 = Release|Win32
24 | EndGlobalSection
25 | GlobalSection(SolutionProperties) = preSolution
26 | HideSolutionNode = FALSE
27 | EndGlobalSection
28 | GlobalSection(ExtensibilityGlobals) = postSolution
29 | SolutionGuid = {5EDBFD62-9335-4C05-8C45-F64FEEF20826}
30 | EndGlobalSection
31 | EndGlobal
32 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |

4 |
NkArc
5 |

6 |

7 |
8 |
9 |
10 | NkArc is a versatile multi filesystem explorer for Windows based on the GRUB2 code.
11 |
12 | ## Supported Filesystems
13 | (Read-Only, No Encryption)
14 | - **Linux**: Btrfs (zlib, lzo, zstd), EROFS (lz4), ext2/3/4, F2FS, JFS, NILFS2, ReiserFS, XFS
15 | - **Windows**: FAT12/16/32, exFAT, NTFS
16 | - **macOS**: HFS, HFS+
17 | - **UNIX**: MINIX1/2/3, QNX4/6, UFS1/2, ZFS (lz4, lzjb, zle, zlib, zstd)
18 | - **CD/DVD**: ISO9660, UDF
19 | - **Other**: Fbinst1.6/1.7, AFFS, AFS, BFS, LynxFS, romfs, SFS (Amiga Smart FileSystem)
20 | - **Archive**: cpio, SquashFS, tar, WIM (lzx, Xpress), zip
21 | - **Compression**: gz, lz4, lzma, lzop, xz, zstd
22 | - **Virtual Disk**: VHD (Fixed/Dynamic), VHDX (Fixed/Dynamic), VDI (Fixed/Dynamic), QCOW1/2/3, DMG (zlib/bzip2)
23 | ## Supported Dynamic Disks
24 | - **Windows**: LDM (Logical Disk Manager)
25 | - **Linux**: LVM (Logical Volume Manager)
26 | - **RAID**: mdraid09, mdraid1x, raid5_rec, raid6_rec, dmraid_nvidia
27 | ## Supported Partition Tables
28 | - MBR, GPT, Apple, BSD, ACRON, Amiga, DragonFly, DVH, Plan9, SUN
29 |
30 | ## Planned Features
31 | - [ ] Dokan/WinFsp support
32 | - [ ] APFS
33 | - [ ] ReFS
34 | - [ ] 7z
35 | - [ ] VMDK
36 | - [ ] LUKS encrypted disk support
37 | - [ ] Bitlocker encrypted disk support
38 |
39 | ## Credits
40 | - [GRUB2](https://www.gnu.org/software/grub/)
41 | - [Nuklear](https://github.com/Immediate-Mode-UI/Nuklear) - GUI
42 | - [Paper Icon](https://github.com/snwh/paper-icon-theme) - Icons
43 | - [VirtualBox](https://www.virtualbox.org) - VHD & VHDX support
44 | - [wimboot](https://github.com/ipxe/wimboot) - WIM support
45 | - [Miniz](https://github.com/richgel999/miniz) - ZIP support
46 | - [VC-LTL5 & YY-Thunks](https://github.com/Chuyu-Team)
47 |
--------------------------------------------------------------------------------
/about.c:
--------------------------------------------------------------------------------
1 | /*
2 | * NkArc
3 | * Copyright (C) 2023 A1ive
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #include
20 | #include
21 | #include "version.h"
22 |
23 | #include
24 | #include
25 | #include
26 | #include
27 |
28 | BOOL
29 | nkctx_about_popup(struct nk_context* ctx, float width, float height)
30 | {
31 | if (!nk_popup_begin(ctx, NK_POPUP_STATIC, GET_STR(LANG_STR_ABOUT),
32 | NK_WINDOW_CLOSABLE,
33 | nk_rect(width / 3.0f, height / 3.0f, width / 3.0f, height / 3.0f)))
34 | return FALSE;
35 |
36 | nk_layout_row_dynamic(ctx, 0, 1);
37 | nk_label(ctx, NKGUI_NAME, NK_TEXT_CENTERED);
38 | nk_label(ctx, NKGUI_COPYRIGHT, NK_TEXT_CENTERED);
39 | nk_label(ctx, "v"NKGUI_VERSION_STR, NK_TEXT_CENTERED);
40 | nk_label(ctx, "Build. " __DATE__ " " __TIME__, NK_TEXT_CENTERED);
41 |
42 | nk_label(ctx, "Supported Filesystems:", NK_TEXT_LEFT);
43 | grub_fs_t fs;
44 | FOR_FILESYSTEMS(fs)
45 | {
46 | nk_label(ctx, fs->name, NK_TEXT_RIGHT);
47 | }
48 | grub_partition_map_t partmap;
49 | nk_label(ctx, "Supported Partition Maps:", NK_TEXT_LEFT);
50 | FOR_PARTITION_MAPS(partmap)
51 | {
52 | nk_label(ctx, partmap->name, NK_TEXT_RIGHT);
53 | }
54 | grub_diskfilter_t df;
55 | nk_label(ctx, "Supported Disk Filters:", NK_TEXT_LEFT);
56 | FOR_LIST_ELEMENTS(df, grub_diskfilter_list)
57 | {
58 | nk_label(ctx, df->name, NK_TEXT_RIGHT);
59 | }
60 |
61 | nk_popup_end(ctx);
62 | return TRUE;
63 | }
64 |
--------------------------------------------------------------------------------
/enum_disk.c:
--------------------------------------------------------------------------------
1 | /*
2 | * NkArc
3 | * Copyright (C) 2023 A1ive
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #include
20 | #include
21 | #include
22 | #include
23 |
24 | #include
25 | #include
26 |
27 | static int
28 | callback_enum_disk(const char* name, void* data)
29 | {
30 | grub_disk_t disk = NULL;
31 | grub_fs_t fs = NULL;
32 | struct nkctx_disk** tail = (struct nkctx_disk**)data;
33 | struct nkctx_disk* info = calloc(1, sizeof(struct nkctx_disk));
34 |
35 | if (!info)
36 | return 0;
37 |
38 | disk = grub_disk_open(name);
39 | if (!disk)
40 | {
41 | free(info);
42 | return 0;
43 | }
44 |
45 | info->index = ++nk.disk_count;
46 | info->name = grub_strdup(name);
47 |
48 | info->path = grub_xasprintf("(%s)/", name);
49 | info->icon = IDR_PNG_UNKNOWN;
50 |
51 | if (disk->partition)
52 | info->is_partition = TRUE;
53 | else
54 | info->icon = IDR_PNG_HDD;
55 |
56 | if (disk->dev->id == GRUB_DISK_DEVICE_LOOPBACK_ID)
57 | info->is_loopback = TRUE;
58 |
59 | info->size = grub_disk_native_sectors(disk);
60 | if (info->size == GRUB_DISK_SIZE_UNKNOWN)
61 | strcpy_s(info->desc, ARRAY_SIZE(info->desc), GET_STR(LANG_STR_UNKNOWN));
62 | else
63 | strcpy_s(info->desc, ARRAY_SIZE(info->desc),
64 | grub_get_human_size(info->size << GRUB_DISK_SECTOR_BITS, GRUB_HUMAN_SIZE_SHORT));
65 |
66 | fs = grub_fs_probe(disk);
67 | if (fs)
68 | {
69 | info->icon = IDR_PNG_HDD;
70 | info->fs = fs->name;
71 | strcat_s(info->desc, ARRAY_SIZE(info->desc), " ");
72 | strcat_s(info->desc, ARRAY_SIZE(info->desc), fs->name);
73 | if (fs->fs_label)
74 | fs->fs_label(disk, &info->label);
75 | if (info->label && info->label[0])
76 | {
77 | strcat_s(info->desc, ARRAY_SIZE(info->desc), " [");
78 | strcat_s(info->desc, ARRAY_SIZE(info->desc), info->label);
79 | strcat_s(info->desc, ARRAY_SIZE(info->desc), "]");
80 | }
81 | }
82 |
83 | switch (disk->dev->id)
84 | {
85 | case GRUB_DISK_DEVICE_CRYPTODISK_ID:
86 | info->icon = IDR_PNG_LOCK;
87 | break;
88 | case GRUB_DISK_DEVICE_DISKFILTER_ID:
89 | info->icon = IDR_PNG_SERVER;
90 | break;
91 | case GRUB_DISK_DEVICE_LOOPBACK_ID:
92 | info->icon = IDR_PNG_LINK;
93 | break;
94 | case GRUB_DISK_DEVICE_PROCFS_ID:
95 | info->icon = IDR_PNG_DIR;
96 | break;
97 | }
98 |
99 | grub_disk_close(disk);
100 |
101 | if (*tail)
102 | (*tail)->next = info;
103 | else
104 | nk.disks = info;
105 | *tail = info;
106 |
107 | grub_errno = GRUB_ERR_NONE;
108 | return 0;
109 | }
110 |
111 | void
112 | nkctx_enum_disk(void)
113 | {
114 | struct nkctx_disk* tail = NULL;
115 | nk.disk_count = 0;
116 | grub_disk_iterate(callback_enum_disk, &tail);
117 | grub_snprintf(nk.status, ARRAY_SIZE(nk.status), "Found %lu disk(s)", nk.disk_count);
118 | }
119 |
120 | void
121 | nkctx_free_disk(void)
122 | {
123 | struct nkctx_disk* p = nk.disks;
124 | while (p)
125 | {
126 | struct nkctx_disk* next = p->next;
127 | free(p->name);
128 | free(p->path);
129 | free(p->label);
130 | free(p);
131 | p = next;
132 | }
133 | nk.disks = NULL;
134 | nk.disk_count = 0;
135 | nk.disk_index = 0;
136 | nkctx_unset_path();
137 | }
138 |
139 |
--------------------------------------------------------------------------------
/grub/disk/mdraid_linux_be.c:
--------------------------------------------------------------------------------
1 | #define MODE_BIGENDIAN 1
2 | #include "mdraid_linux.c"
3 |
--------------------------------------------------------------------------------
/grub/disk/raid5_recover.c:
--------------------------------------------------------------------------------
1 | /* raid5_recover.c - module to recover from faulty RAID4/5 arrays. */
2 | /*
3 | * GRUB -- GRand Unified Bootloader
4 | * Copyright (C) 2006,2007,2008 Free Software Foundation, Inc.
5 | *
6 | * GRUB is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * GRUB is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with GRUB. If not, see .
18 | */
19 |
20 | #include
21 | #include
22 | #include
23 | #include
24 | #include
25 | #include
26 | #include
27 |
28 | GRUB_MOD_LICENSE("GPLv3+");
29 |
30 | static grub_err_t
31 | grub_raid5_recover(struct grub_diskfilter_segment* array, int disknr,
32 | char* buf, grub_disk_addr_t sector, grub_size_t size)
33 | {
34 | char* buf2;
35 | int i;
36 |
37 | size <<= GRUB_DISK_SECTOR_BITS;
38 | buf2 = grub_malloc(size);
39 | if (!buf2)
40 | return grub_errno;
41 |
42 | grub_memset(buf, 0, size);
43 |
44 | for (i = 0; i < (int)array->node_count; i++)
45 | {
46 | grub_err_t err;
47 |
48 | if (i == disknr)
49 | continue;
50 |
51 | err = grub_diskfilter_read_node(&array->nodes[i], sector,
52 | size >> GRUB_DISK_SECTOR_BITS, buf2);
53 |
54 | if (err)
55 | {
56 | grub_free(buf2);
57 | return err;
58 | }
59 |
60 | grub_crypto_xor(buf, buf, buf2, size);
61 | }
62 |
63 | grub_free(buf2);
64 |
65 | return GRUB_ERR_NONE;
66 | }
67 |
68 | GRUB_MOD_INIT(raid5rec)
69 | {
70 | grub_raid5_recover_func = grub_raid5_recover;
71 | }
72 |
73 | GRUB_MOD_FINI(raid5rec)
74 | {
75 | grub_raid5_recover_func = 0;
76 | }
77 |
--------------------------------------------------------------------------------
/grub/fs/afs.c:
--------------------------------------------------------------------------------
1 | #define MODE_AFS 1
2 | #include "bfs.c"
3 |
4 |
--------------------------------------------------------------------------------
/grub/fs/cpio.c:
--------------------------------------------------------------------------------
1 | /* cpio.c - cpio and tar filesystem. */
2 | /*
3 | * GRUB -- GRand Unified Bootloader
4 | * Copyright (C) 2007,2008,2009,2013 Free Software Foundation, Inc.
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | */
19 |
20 | #include
21 |
22 | /* cpio support */
23 | #define ALIGN_CPIO(x) (ALIGN_UP ((x), 2))
24 | #define MAGIC "\xc7\x71"
25 | GRUB_PACKED_START
26 | struct head
27 | {
28 | grub_uint16_t magic[1];
29 | grub_uint16_t dev;
30 | grub_uint16_t ino;
31 | grub_uint16_t mode[1];
32 | grub_uint16_t uid;
33 | grub_uint16_t gid;
34 | grub_uint16_t nlink;
35 | grub_uint16_t rdev;
36 | grub_uint16_t mtime[2];
37 | grub_uint16_t namesize[1];
38 | grub_uint16_t filesize[2];
39 | };
40 | GRUB_PACKED_END
41 |
42 | static inline unsigned long long
43 | read_number(const grub_uint16_t* arr, grub_size_t size)
44 | {
45 | long long ret = 0;
46 | while (size--)
47 | ret = (ret << 16) | grub_le_to_cpu16(*arr++);
48 | return ret;
49 | }
50 |
51 | #define FSNAME "cpiofs"
52 |
53 | #include "cpio_common.c"
54 |
55 | GRUB_MOD_INIT(cpio)
56 | {
57 | grub_fs_register(&grub_cpio_fs);
58 | }
59 |
60 | GRUB_MOD_FINI(cpio)
61 | {
62 | grub_fs_unregister(&grub_cpio_fs);
63 | }
64 |
--------------------------------------------------------------------------------
/grub/fs/cpio_be.c:
--------------------------------------------------------------------------------
1 | /* cpio.c - cpio and tar filesystem. */
2 | /*
3 | * GRUB -- GRand Unified Bootloader
4 | * Copyright (C) 2007,2008,2009,2013 Free Software Foundation, Inc.
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | */
19 |
20 | #include
21 |
22 | #define ALIGN_CPIO(x) (ALIGN_UP ((x), 2))
23 | #define MAGIC "\x71\xc7"
24 |
25 | GRUB_PACKED_START
26 | struct head
27 | {
28 | grub_uint16_t magic[1];
29 | grub_uint16_t dev;
30 | grub_uint16_t ino;
31 | grub_uint16_t mode[1];
32 | grub_uint16_t uid;
33 | grub_uint16_t gid;
34 | grub_uint16_t nlink;
35 | grub_uint16_t rdev;
36 | grub_uint16_t mtime[2];
37 | grub_uint16_t namesize[1];
38 | grub_uint16_t filesize[2];
39 | };
40 | GRUB_PACKED_END
41 |
42 | static inline unsigned long long
43 | read_number(const grub_uint16_t* arr, grub_size_t size)
44 | {
45 | long long ret = 0;
46 | while (size--)
47 | ret = (ret << 16) | grub_be_to_cpu16(*arr++);
48 | return ret;
49 | }
50 |
51 | #define FSNAME "cpiofs_be"
52 |
53 | #include "cpio_common.c"
54 |
55 | GRUB_MOD_INIT(cpio_be)
56 | {
57 | grub_fs_register(&grub_cpio_fs);
58 | }
59 |
60 | GRUB_MOD_FINI(cpio_be)
61 | {
62 | grub_fs_unregister(&grub_cpio_fs);
63 | }
64 |
--------------------------------------------------------------------------------
/grub/fs/exfat.c:
--------------------------------------------------------------------------------
1 | #define MODE_EXFAT 1
2 | #include "fat.c"
3 |
--------------------------------------------------------------------------------
/grub/fs/minix2.c:
--------------------------------------------------------------------------------
1 | #define MODE_MINIX2 1
2 | #include "minix.c"
3 |
--------------------------------------------------------------------------------
/grub/fs/minix2_be.c:
--------------------------------------------------------------------------------
1 | #define MODE_MINIX2 1
2 | #define MODE_BIGENDIAN 1
3 | #include "minix.c"
4 |
--------------------------------------------------------------------------------
/grub/fs/minix3.c:
--------------------------------------------------------------------------------
1 | #define MODE_MINIX3 1
2 | #include "minix.c"
3 |
--------------------------------------------------------------------------------
/grub/fs/minix3_be.c:
--------------------------------------------------------------------------------
1 | #define MODE_MINIX3 1
2 | #define MODE_BIGENDIAN 1
3 | #include "minix.c"
4 |
--------------------------------------------------------------------------------
/grub/fs/minix_be.c:
--------------------------------------------------------------------------------
1 | #define MODE_BIGENDIAN 1
2 | #include "minix.c"
3 |
--------------------------------------------------------------------------------
/grub/fs/newc.c:
--------------------------------------------------------------------------------
1 | /* cpio.c - cpio and tar filesystem. */
2 | /*
3 | * GRUB -- GRand Unified Bootloader
4 | * Copyright (C) 2007,2008,2009,2013 Free Software Foundation, Inc.
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | */
19 |
20 | #include
21 |
22 | #define ALIGN_CPIO(x) (ALIGN_UP ((x), 4))
23 | #define MAGIC "070701"
24 | #define MAGIC2 "070702"
25 | GRUB_PACKED_START
26 | struct head
27 | {
28 | char magic[6];
29 | char ino[8];
30 | char mode[8];
31 | char uid[8];
32 | char gid[8];
33 | char nlink[8];
34 | char mtime[8];
35 | char filesize[8];
36 | char devmajor[8];
37 | char devminor[8];
38 | char rdevmajor[8];
39 | char rdevminor[8];
40 | char namesize[8];
41 | char check[8];
42 | };
43 | GRUB_PACKED_END
44 |
45 | static inline unsigned long long
46 | read_number(const char* str, grub_size_t size)
47 | {
48 | unsigned long long ret = 0;
49 | while (size-- && grub_isxdigit(*str))
50 | {
51 | char dig = *str++;
52 | if (dig >= '0' && dig <= '9')
53 | dig &= 0xf;
54 | else if (dig >= 'a' && dig <= 'f')
55 | dig -= 'a' - 10;
56 | else
57 | dig -= 'A' - 10;
58 | ret = (ret << 4) | (dig);
59 | }
60 | return ret;
61 | }
62 |
63 | #define FSNAME "newc"
64 |
65 | #include "cpio_common.c"
66 |
67 | GRUB_MOD_INIT(newc)
68 | {
69 | grub_fs_register(&grub_cpio_fs);
70 | }
71 |
72 | GRUB_MOD_FINI(newc)
73 | {
74 | grub_fs_unregister(&grub_cpio_fs);
75 | }
76 |
--------------------------------------------------------------------------------
/grub/fs/odc.c:
--------------------------------------------------------------------------------
1 | /* cpio.c - cpio and tar filesystem. */
2 | /*
3 | * GRUB -- GRand Unified Bootloader
4 | * Copyright (C) 2007,2008,2009,2013 Free Software Foundation, Inc.
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | */
19 |
20 | #include
21 |
22 | #define ALIGN_CPIO(x) x
23 |
24 | #define MAGIC "070707"
25 | GRUB_PACKED_START
26 | struct head
27 | {
28 | char magic[6];
29 | char dev[6];
30 | char ino[6];
31 | char mode[6];
32 | char uid[6];
33 | char gid[6];
34 | char nlink[6];
35 | char rdev[6];
36 | char mtime[11];
37 | char namesize[6];
38 | char filesize[11];
39 | };
40 | GRUB_PACKED_END
41 |
42 | static inline unsigned long long
43 | read_number(const char* str, grub_size_t size)
44 | {
45 | unsigned long long ret = 0;
46 | while (size-- && *str >= '0' && *str <= '7')
47 | ret = (ret << 3) | (*str++ & 0xf);
48 | return ret;
49 | }
50 |
51 | #define FSNAME "odc"
52 |
53 | #include "cpio_common.c"
54 |
55 | GRUB_MOD_INIT(odc)
56 | {
57 | grub_fs_register(&grub_cpio_fs);
58 | }
59 |
60 | GRUB_MOD_FINI(odc)
61 | {
62 | grub_fs_unregister(&grub_cpio_fs);
63 | }
64 |
--------------------------------------------------------------------------------
/grub/fs/uefi.c:
--------------------------------------------------------------------------------
1 | /*
2 | * NkArc
3 | * Copyright (C) 2023 A1ive
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #include
20 | #include
21 | #include
22 | #include
23 | #include
24 | #include
25 |
26 | GRUB_MOD_LICENSE("GPLv3+");
27 |
28 | struct efivars_data
29 | {
30 | DWORD size;
31 | char* name;
32 | void* data;
33 | };
34 |
35 | static struct grub_procfs_entry* efivars;
36 | static grub_size_t efivars_count;
37 |
38 | static char* efivars_get_contents (struct grub_procfs_entry* this, grub_size_t* sz)
39 | {
40 | struct efivars_data* data = this->data;
41 | void* buf = grub_malloc(data->size);
42 | *sz = 0;
43 | if (!buf)
44 | return NULL;
45 | grub_memcpy(buf, data->data, data->size);
46 | *sz = data->size;
47 | return buf;
48 | }
49 |
50 | GRUB_MOD_INIT(efivars)
51 | {
52 | efivars = NULL;
53 | efivars_count = 0;
54 | if (!grub_is_efi_boot())
55 | return;
56 | ULONG ptr_size = 0;
57 | grub_size_t i;
58 | PVARIABLE_NAME p;
59 | PVARIABLE_NAME data = grub_efi_enum_variable(&ptr_size);
60 | if (!data)
61 | return;
62 | for (PVARIABLE_NAME p = data;
63 | p->NextEntryOffset && ((LPBYTE)p < (LPBYTE)data + ptr_size);
64 | p = (PVARIABLE_NAME)((LPBYTE)p + p->NextEntryOffset))
65 | {
66 | efivars_count++;
67 | }
68 | efivars = grub_calloc(efivars_count, sizeof(struct grub_procfs_entry));
69 | for (p = data, i = 0;
70 | p->NextEntryOffset && ((LPBYTE)p < (LPBYTE)data + ptr_size);
71 | p = (PVARIABLE_NAME)((LPBYTE)p + p->NextEntryOffset), i++)
72 | {
73 | grub_size_t len = wcslen(p->Name) + 1;
74 | char* name = grub_calloc(4, len);
75 | *grub_utf16_to_utf8((grub_uint8_t*)name, p->Name, len) = 0;
76 | struct efivars_data* ctx = grub_malloc(sizeof(struct efivars_data));
77 | ctx->name = grub_xasprintf("efi/{%08lX-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}/%s",
78 | p->VendorGuid.Data1, p->VendorGuid.Data2, p->VendorGuid.Data3,
79 | p->VendorGuid.Data4[0], p->VendorGuid.Data4[1], p->VendorGuid.Data4[2], p->VendorGuid.Data4[3],
80 | p->VendorGuid.Data4[4], p->VendorGuid.Data4[5], p->VendorGuid.Data4[6], p->VendorGuid.Data4[7],
81 | name);
82 | grub_free(name);
83 | ctx->data = grub_efi_get_variable_alloc(name, &p->VendorGuid, &ctx->size, NULL);
84 | efivars[i].name = ctx->name;
85 | efivars[i].data = ctx;
86 | efivars[i].get_contents = efivars_get_contents;
87 | grub_procfs_register(efivars[i].name, &efivars[i]);
88 | }
89 | }
90 |
91 | GRUB_MOD_FINI(efivars)
92 | {
93 | for (grub_size_t i = 0; i < efivars_count; i++)
94 | {
95 | grub_procfs_unregister(&efivars[i]);
96 | struct efivars_data* ctx = efivars[i].data;
97 | grub_free(ctx->name);
98 | grub_free(ctx->data);
99 | }
100 | grub_free(efivars);
101 | efivars = NULL;
102 | efivars_count = 0;
103 | }
104 |
--------------------------------------------------------------------------------
/grub/fs/ufs2.c:
--------------------------------------------------------------------------------
1 | /* ufs2.c - Unix File System 2 */
2 | #define MODE_UFS2 1
3 | #include "ufs.c"
4 |
--------------------------------------------------------------------------------
/grub/fs/ufs_be.c:
--------------------------------------------------------------------------------
1 | #define MODE_BIGENDIAN 1
2 | #include "ufs.c"
3 |
--------------------------------------------------------------------------------
/grub/fs/zfs/zfs_fletcher.c:
--------------------------------------------------------------------------------
1 | /*
2 | * GRUB -- GRand Unified Bootloader
3 | * Copyright (C) 1999,2000,2001,2002,2003,2004,2009 Free Software Foundation, Inc.
4 | * Copyright 2007 Sun Microsystems, Inc.
5 | *
6 | * GRUB is free software; you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation; either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * GRUB is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with GRUB. If not, see .
18 | */
19 |
20 | #include
21 | #include
22 | #include
23 | #include
24 | #include
25 | #include
26 | #include
27 | #include
28 | #include
29 | #include
30 | #include
31 | #include
32 | #include
33 | #include
34 | #include
35 | #include
36 | #include
37 | #include
38 | #include
39 |
40 | void
41 | fletcher_2(const void* buf, grub_uint64_t size, grub_zfs_endian_t endian,
42 | zio_cksum_t* zcp)
43 | {
44 | const grub_uint64_t* ip = buf;
45 | const grub_uint64_t* ipend = ip + (size / sizeof(grub_uint64_t));
46 | grub_uint64_t a0, b0, a1, b1;
47 |
48 | for (a0 = b0 = a1 = b1 = 0; ip < ipend; ip += 2)
49 | {
50 | a0 += grub_zfs_to_cpu64(ip[0], endian);
51 | a1 += grub_zfs_to_cpu64(ip[1], endian);
52 | b0 += a0;
53 | b1 += a1;
54 | }
55 |
56 | zcp->zc_word[0] = grub_cpu_to_zfs64(a0, endian);
57 | zcp->zc_word[1] = grub_cpu_to_zfs64(a1, endian);
58 | zcp->zc_word[2] = grub_cpu_to_zfs64(b0, endian);
59 | zcp->zc_word[3] = grub_cpu_to_zfs64(b1, endian);
60 | }
61 |
62 | void
63 | fletcher_4(const void* buf, grub_uint64_t size, grub_zfs_endian_t endian,
64 | zio_cksum_t* zcp)
65 | {
66 | const grub_uint32_t* ip = buf;
67 | const grub_uint32_t* ipend = ip + (size / sizeof(grub_uint32_t));
68 | grub_uint64_t a, b, c, d;
69 |
70 | for (a = b = c = d = 0; ip < ipend; ip++)
71 | {
72 | a += grub_zfs_to_cpu32(ip[0], endian);;
73 | b += a;
74 | c += b;
75 | d += c;
76 | }
77 |
78 | zcp->zc_word[0] = grub_cpu_to_zfs64(a, endian);
79 | zcp->zc_word[1] = grub_cpu_to_zfs64(b, endian);
80 | zcp->zc_word[2] = grub_cpu_to_zfs64(c, endian);
81 | zcp->zc_word[3] = grub_cpu_to_zfs64(d, endian);
82 | }
83 |
--------------------------------------------------------------------------------
/grub/fs/zfs/zfs_lzjb.c:
--------------------------------------------------------------------------------
1 | /*
2 | * GRUB -- GRand Unified Bootloader
3 | * Copyright (C) 1999,2000,2001,2002,2003,2004,2009 Free Software Foundation, Inc.
4 | * Copyright 2007 Sun Microsystems, Inc.
5 | *
6 | * GRUB is free software; you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation; either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * GRUB is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with GRUB. If not, see .
18 | */
19 |
20 | #include
21 | #include
22 | #include
23 | #include
24 | #include
25 | #include
26 | #include
27 | #include
28 | #include
29 | #include
30 | #include
31 | #include
32 | #include
33 | #include
34 | #include
35 | #include
36 | #include
37 | #include
38 | #include
39 |
40 | #define MATCH_BITS 6
41 | #define MATCH_MIN 3
42 | #define OFFSET_MASK ((1 << (16 - MATCH_BITS)) - 1)
43 |
44 | /*
45 | * Decompression Entry - lzjb
46 | */
47 | #ifndef NBBY
48 | #define NBBY 8
49 | #endif
50 |
51 | grub_err_t
52 | lzjb_decompress(void* s_start, void* d_start, grub_size_t s_len,
53 | grub_size_t d_len);
54 |
55 | grub_err_t
56 | lzjb_decompress(void* s_start, void* d_start, grub_size_t s_len,
57 | grub_size_t d_len)
58 | {
59 | grub_uint8_t* src = s_start;
60 | grub_uint8_t* dst = d_start;
61 | grub_uint8_t* d_end = (grub_uint8_t*)d_start + d_len;
62 | grub_uint8_t* s_end = (grub_uint8_t*)s_start + s_len;
63 | grub_uint8_t* cpy, copymap = 0;
64 | int copymask = 1 << (NBBY - 1);
65 |
66 | while (dst < d_end && src < s_end)
67 | {
68 | if ((copymask <<= 1) == (1 << NBBY))
69 | {
70 | copymask = 1;
71 | copymap = *src++;
72 | }
73 | if (src >= s_end)
74 | return grub_error(GRUB_ERR_BAD_FS, "lzjb decompression failed");
75 | if (copymap & copymask)
76 | {
77 | int mlen = (src[0] >> (NBBY - MATCH_BITS)) + MATCH_MIN;
78 | int offset = ((src[0] << NBBY) | src[1]) & OFFSET_MASK;
79 | src += 2;
80 | cpy = dst - offset;
81 | if (src > s_end || cpy < (grub_uint8_t*)d_start)
82 | return grub_error(GRUB_ERR_BAD_FS, "lzjb decompression failed");
83 | while (--mlen >= 0 && dst < d_end)
84 | *dst++ = *cpy++;
85 | }
86 | else
87 | *dst++ = *src++;
88 | }
89 | if (dst < d_end)
90 | return grub_error(GRUB_ERR_BAD_FS, "lzjb decompression failed");
91 | return GRUB_ERR_NONE;
92 | }
93 |
--------------------------------------------------------------------------------
/grub/kern/err.c:
--------------------------------------------------------------------------------
1 | /* err.c - error handling routines */
2 | /*
3 | * GRUB -- GRand Unified Bootloader
4 | * Copyright (C) 2002,2005,2007,2008 Free Software Foundation, Inc.
5 | *
6 | * GRUB is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * GRUB is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with GRUB. If not, see .
18 | */
19 |
20 | #include
21 | #include
22 | #include
23 | #include
24 | #include
25 |
26 | #define GRUB_ERROR_STACK_SIZE 10
27 |
28 | grub_err_t grub_errno;
29 | char grub_errmsg[GRUB_MAX_ERRMSG];
30 | int grub_err_printed_errors;
31 |
32 | static struct grub_error_saved grub_error_stack_items[GRUB_ERROR_STACK_SIZE];
33 |
34 | static int grub_error_stack_pos;
35 | static int grub_error_stack_assert;
36 |
37 | grub_err_t
38 | grub_error(grub_err_t n, const char* fmt, ...)
39 | {
40 | va_list ap;
41 |
42 | grub_errno = n;
43 |
44 | va_start(ap, fmt);
45 | vsnprintf(grub_errmsg, sizeof(grub_errmsg), fmt, ap);
46 | va_end(ap);
47 |
48 | return n;
49 | }
50 |
51 | void
52 | grub_error_push(void)
53 | {
54 | /* Only add items to stack, if there is enough room. */
55 | if (grub_error_stack_pos < GRUB_ERROR_STACK_SIZE)
56 | {
57 | /* Copy active error message to stack. */
58 | grub_error_stack_items[grub_error_stack_pos].grub_errno = grub_errno;
59 | memcpy(grub_error_stack_items[grub_error_stack_pos].errmsg,
60 | grub_errmsg,
61 | sizeof(grub_errmsg));
62 |
63 | /* Advance to next error stack position. */
64 | grub_error_stack_pos++;
65 | }
66 | else
67 | {
68 | /* There is no room for new error message. Discard new error message
69 | and mark error stack assertion flag. */
70 | grub_error_stack_assert = 1;
71 | }
72 |
73 | /* Allow further operation of other components by resetting
74 | active errno to GRUB_ERR_NONE. */
75 | grub_errno = GRUB_ERR_NONE;
76 | }
77 |
78 | int
79 | grub_error_pop(void)
80 | {
81 | if (grub_error_stack_pos > 0)
82 | {
83 | /* Pop error message from error stack to current active error. */
84 | grub_error_stack_pos--;
85 |
86 | grub_errno = grub_error_stack_items[grub_error_stack_pos].grub_errno;
87 | memcpy(grub_errmsg,
88 | grub_error_stack_items[grub_error_stack_pos].errmsg,
89 | sizeof(grub_errmsg));
90 |
91 | return 1;
92 | }
93 | else
94 | {
95 | /* There is no more items on error stack, reset to no error state. */
96 | grub_errno = GRUB_ERR_NONE;
97 |
98 | return 0;
99 | }
100 | }
101 |
102 | void
103 | grub_print_error(void)
104 | {
105 | /* Print error messages in reverse order. First print active error message
106 | and then empty error stack. */
107 | do
108 | {
109 | if (grub_errno != GRUB_ERR_NONE)
110 | {
111 | grub_err_printf("error: %s.\n", grub_errmsg);
112 | grub_err_printed_errors++;
113 | }
114 | } while (grub_error_pop());
115 |
116 | /* If there was an assert while using error stack, report about it. */
117 | if (grub_error_stack_assert)
118 | {
119 | grub_err_printf("assert: error stack overflow detected!\n");
120 | grub_error_stack_assert = 0;
121 | }
122 | }
123 |
--------------------------------------------------------------------------------
/grub/kern/list.c:
--------------------------------------------------------------------------------
1 | /* list.c - grub list function */
2 | /*
3 | * GRUB -- GRand Unified Bootloader
4 | * Copyright (C) 2009 Free Software Foundation, Inc.
5 | *
6 | * GRUB is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * GRUB is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with GRUB. If not, see .
18 | */
19 |
20 | #include
21 | #include
22 | #include
23 |
24 | void *
25 | grub_named_list_find (grub_named_list_t head, const char *name)
26 | {
27 | grub_named_list_t item;
28 |
29 | FOR_LIST_ELEMENTS (item, head)
30 | if (grub_strcmp (item->name, name) == 0)
31 | return item;
32 |
33 | return NULL;
34 | }
35 |
36 | void
37 | grub_list_push (grub_list_t *head, grub_list_t item)
38 | {
39 | item->prev = head;
40 | if (*head)
41 | (*head)->prev = &item->next;
42 | item->next = *head;
43 | *head = item;
44 | }
45 |
46 | void
47 | grub_list_remove (grub_list_t item)
48 | {
49 | if (item->prev)
50 | *item->prev = item->next;
51 | if (item->next)
52 | item->next->prev = item->prev;
53 | item->next = 0;
54 | item->prev = 0;
55 | }
56 |
--------------------------------------------------------------------------------
/grub/kern/mm.c:
--------------------------------------------------------------------------------
1 | /* mm.c - functions for memory manager */
2 | /*
3 | * GRUB -- GRand Unified Bootloader
4 | * Copyright (C) 2002,2005,2007,2008,2009 Free Software Foundation, Inc.
5 | *
6 | * GRUB is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * GRUB is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with GRUB. If not, see .
18 | */
19 |
20 | /*
21 | The design of this memory manager.
22 |
23 | This is a simple implementation of malloc with a few extensions. These are
24 | the extensions:
25 |
26 | - memalign is implemented efficiently.
27 |
28 | - multiple regions may be used as free space. They may not be
29 | contiguous.
30 |
31 | - if existing regions are insufficient to satisfy an allocation, a new
32 | region can be requested from firmware.
33 |
34 | Regions are managed by a singly linked list, and the meta information is
35 | stored in the beginning of each region. Space after the meta information
36 | is used to allocate memory.
37 |
38 | The memory space is used as cells instead of bytes for simplicity. This
39 | is important for some CPUs which may not access multiple bytes at a time
40 | when the first byte is not aligned at a certain boundary (typically,
41 | 4-byte or 8-byte). The size of each cell is equal to the size of struct
42 | grub_mm_header, so the header of each allocated/free block fits into one
43 | cell precisely. One cell is 16 bytes on 32-bit platforms and 32 bytes
44 | on 64-bit platforms.
45 |
46 | There are two types of blocks: allocated blocks and free blocks.
47 |
48 | In allocated blocks, the header of each block has only its size. Note that
49 | this size is based on cells but not on bytes. The header is located right
50 | before the returned pointer, that is, the header resides at the previous
51 | cell.
52 |
53 | Free blocks constitutes a ring, using a singly linked list. The first free
54 | block is pointed to by the meta information of a region. The allocator
55 | attempts to pick up the second block instead of the first one. This is
56 | a typical optimization against defragmentation, and makes the
57 | implementation a bit easier.
58 |
59 | For safety, both allocated blocks and free ones are marked by magic
60 | numbers. Whenever anything unexpected is detected, GRUB aborts the
61 | operation.
62 | */
63 |
64 | #include
65 | #include
66 | #include
67 | #include
68 | #include
69 | #include
70 |
71 | #include
72 |
73 | void* grub_calloc (grub_size_t nmemb, grub_size_t size)
74 | {
75 | void* ptr = calloc(nmemb, size);
76 | if (!ptr)
77 | grub_error(GRUB_ERR_OUT_OF_MEMORY, "out of memory");
78 | return ptr;
79 | }
80 |
81 | void* grub_malloc (grub_size_t size)
82 | {
83 | void* ptr = malloc(size);
84 | if (!ptr)
85 | grub_error(GRUB_ERR_OUT_OF_MEMORY, "out of memory");
86 | return ptr;
87 | }
88 |
89 | void* grub_zalloc (grub_size_t size)
90 | {
91 | return grub_calloc(1, size);
92 | }
93 |
94 | void grub_free (void* ptr)
95 | {
96 | free(ptr);
97 | }
98 |
99 | void* grub_realloc (void* ptr, grub_size_t size)
100 | {
101 | void* new_ptr = realloc(ptr, size);
102 | if (!new_ptr)
103 | grub_error(GRUB_ERR_OUT_OF_MEMORY, "out of memory");
104 | return new_ptr;
105 | }
106 |
--------------------------------------------------------------------------------
/grub/kern/time.c:
--------------------------------------------------------------------------------
1 | /* time.c - kernel time functions */
2 | /*
3 | * GRUB -- GRand Unified Bootloader
4 | * Copyright (C) 2008 Free Software Foundation, Inc.
5 | *
6 | * GRUB is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * GRUB is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with GRUB. If not, see .
18 | */
19 |
20 | #include
21 | #include
22 | #include
23 |
24 | #include
25 |
26 | grub_err_t
27 | grub_get_datetime(struct grub_datetime* datetime)
28 | {
29 | struct tm* mytm;
30 | time_t mytime;
31 |
32 | mytime = time(&mytime);
33 | if (gmtime_s(mytm, &mytime) == 0)
34 | {
35 | datetime->year = mytm->tm_year + 1900;
36 | datetime->month = mytm->tm_mon + 1;
37 | datetime->day = mytm->tm_mday;
38 | datetime->hour = mytm->tm_hour;
39 | datetime->minute = mytm->tm_min;
40 | datetime->second = mytm->tm_sec;
41 | }
42 | else
43 | memset(datetime, 0, sizeof(*datetime));
44 |
45 | return GRUB_ERR_NONE;
46 | }
47 |
48 | grub_err_t
49 | grub_set_datetime(struct grub_datetime* datetime __attribute__((unused)))
50 | {
51 | return grub_error(GRUB_ERR_NOT_IMPLEMENTED_YET,
52 | "no clock setting routine available");
53 | }
54 |
55 | grub_uint64_t
56 | grub_get_time_ms(void)
57 | {
58 | FILETIME cr, ex, ke, us;
59 | ULARGE_INTEGER us_ul;
60 |
61 | GetProcessTimes(GetCurrentProcess(), &cr, &ex, &ke, &us);
62 | us_ul.LowPart = us.dwLowDateTime;
63 | us_ul.HighPart = us.dwHighDateTime;
64 |
65 | return us_ul.QuadPart / 10000;
66 | }
67 |
68 | void
69 | grub_millisleep(grub_uint32_t ms)
70 | {
71 | Sleep(ms);
72 | }
73 |
--------------------------------------------------------------------------------
/grub/lib/adler32.c:
--------------------------------------------------------------------------------
1 | /*
2 | * GRUB -- GRand Unified Bootloader
3 | * Copyright (C) 2022 Free Software Foundation, Inc.
4 | *
5 | * GRUB is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * GRUB is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with GRUB. If not, see .
17 | */
18 |
19 | #include
20 | #include
21 |
22 | struct adler32_context
23 | {
24 | grub_uint16_t a, b;
25 | grub_uint32_t c;
26 | };
27 |
28 | static void
29 | adler32_init(void* context)
30 | {
31 | struct adler32_context* ctx = context;
32 |
33 | ctx->a = 1;
34 | ctx->b = 0;
35 | }
36 |
37 | #define MOD 65521
38 |
39 | static grub_uint16_t
40 | mod_add(grub_uint16_t a, grub_uint16_t b)
41 | {
42 | if ((grub_uint32_t)a + (grub_uint32_t)b >= MOD)
43 | return a + b - MOD;
44 | return a + b;
45 | }
46 |
47 | static void
48 | adler32_write(void* context, const void* inbuf, grub_size_t inlen)
49 | {
50 | struct adler32_context* ctx = context;
51 | const grub_uint8_t* ptr = inbuf;
52 |
53 | while (inlen)
54 | {
55 | ctx->a = mod_add(ctx->a, *ptr);
56 | ctx->b = mod_add(ctx->a, ctx->b);
57 | inlen--;
58 | ptr++;
59 | }
60 | }
61 |
62 | static void
63 | adler32_final(void* context)
64 | {
65 | (void)context;
66 | }
67 |
68 | static grub_uint8_t*
69 | adler32_read(void* context)
70 | {
71 | struct adler32_context* ctx = context;
72 | if (ctx->a > MOD)
73 | ctx->a -= MOD;
74 | if (ctx->b > MOD)
75 | ctx->b -= MOD;
76 | ctx->c = grub_cpu_to_be32(ctx->a | (ctx->b << 16));
77 | return (grub_uint8_t*)&ctx->c;
78 | }
79 |
80 | gcry_md_spec_t _gcry_digest_spec_adler32 =
81 | {
82 | "ADLER32", 0, 0, 0, 4,
83 | adler32_init, adler32_write, adler32_final, adler32_read,
84 | sizeof(struct adler32_context),
85 | .blocksize = 64
86 | };
87 |
--------------------------------------------------------------------------------
/grub/lib/bzip2/bz_version.h:
--------------------------------------------------------------------------------
1 | #define BZ_VERSION "1.1.0"
2 |
--------------------------------------------------------------------------------
/grub/lib/bzip2/randtable.c:
--------------------------------------------------------------------------------
1 |
2 | /*-------------------------------------------------------------*/
3 | /*--- Table for randomising repetitive blocks ---*/
4 | /*--- randtable.c ---*/
5 | /*-------------------------------------------------------------*/
6 |
7 | /* ------------------------------------------------------------------
8 | This file is part of bzip2/libbzip2, a program and library for
9 | lossless, block-sorting data compression.
10 |
11 | bzip2/libbzip2 version 1.1.0 of 6 September 2010
12 | Copyright (C) 1996-2010 Julian Seward
13 |
14 | Please read the WARNING, DISCLAIMER and PATENTS sections in the
15 | README file.
16 |
17 | This program is released under the terms of the license contained
18 | in the file LICENSE.
19 | ------------------------------------------------------------------ */
20 |
21 |
22 | #include "bzlib_private.h"
23 |
24 |
25 | /*---------------------------------------------*/
26 | Int32 BZ2_rNums[512] = {
27 | 619, 720, 127, 481, 931, 816, 813, 233, 566, 247,
28 | 985, 724, 205, 454, 863, 491, 741, 242, 949, 214,
29 | 733, 859, 335, 708, 621, 574, 73, 654, 730, 472,
30 | 419, 436, 278, 496, 867, 210, 399, 680, 480, 51,
31 | 878, 465, 811, 169, 869, 675, 611, 697, 867, 561,
32 | 862, 687, 507, 283, 482, 129, 807, 591, 733, 623,
33 | 150, 238, 59, 379, 684, 877, 625, 169, 643, 105,
34 | 170, 607, 520, 932, 727, 476, 693, 425, 174, 647,
35 | 73, 122, 335, 530, 442, 853, 695, 249, 445, 515,
36 | 909, 545, 703, 919, 874, 474, 882, 500, 594, 612,
37 | 641, 801, 220, 162, 819, 984, 589, 513, 495, 799,
38 | 161, 604, 958, 533, 221, 400, 386, 867, 600, 782,
39 | 382, 596, 414, 171, 516, 375, 682, 485, 911, 276,
40 | 98, 553, 163, 354, 666, 933, 424, 341, 533, 870,
41 | 227, 730, 475, 186, 263, 647, 537, 686, 600, 224,
42 | 469, 68, 770, 919, 190, 373, 294, 822, 808, 206,
43 | 184, 943, 795, 384, 383, 461, 404, 758, 839, 887,
44 | 715, 67, 618, 276, 204, 918, 873, 777, 604, 560,
45 | 951, 160, 578, 722, 79, 804, 96, 409, 713, 940,
46 | 652, 934, 970, 447, 318, 353, 859, 672, 112, 785,
47 | 645, 863, 803, 350, 139, 93, 354, 99, 820, 908,
48 | 609, 772, 154, 274, 580, 184, 79, 626, 630, 742,
49 | 653, 282, 762, 623, 680, 81, 927, 626, 789, 125,
50 | 411, 521, 938, 300, 821, 78, 343, 175, 128, 250,
51 | 170, 774, 972, 275, 999, 639, 495, 78, 352, 126,
52 | 857, 956, 358, 619, 580, 124, 737, 594, 701, 612,
53 | 669, 112, 134, 694, 363, 992, 809, 743, 168, 974,
54 | 944, 375, 748, 52, 600, 747, 642, 182, 862, 81,
55 | 344, 805, 988, 739, 511, 655, 814, 334, 249, 515,
56 | 897, 955, 664, 981, 649, 113, 974, 459, 893, 228,
57 | 433, 837, 553, 268, 926, 240, 102, 654, 459, 51,
58 | 686, 754, 806, 760, 493, 403, 415, 394, 687, 700,
59 | 946, 670, 656, 610, 738, 392, 760, 799, 887, 653,
60 | 978, 321, 576, 617, 626, 502, 894, 679, 243, 440,
61 | 680, 879, 194, 572, 640, 724, 926, 56, 204, 700,
62 | 707, 151, 457, 449, 797, 195, 791, 558, 945, 679,
63 | 297, 59, 87, 824, 713, 663, 412, 693, 342, 606,
64 | 134, 108, 571, 364, 631, 212, 174, 643, 304, 329,
65 | 343, 97, 430, 751, 497, 314, 983, 374, 822, 928,
66 | 140, 206, 73, 263, 980, 736, 876, 478, 430, 305,
67 | 170, 514, 364, 692, 829, 82, 855, 953, 676, 246,
68 | 369, 970, 294, 750, 807, 827, 150, 790, 288, 923,
69 | 804, 378, 215, 828, 592, 281, 565, 555, 710, 82,
70 | 896, 831, 547, 261, 524, 462, 293, 465, 502, 56,
71 | 661, 821, 976, 991, 658, 869, 905, 758, 745, 193,
72 | 768, 550, 608, 933, 378, 286, 215, 979, 792, 961,
73 | 61, 688, 793, 644, 986, 403, 106, 366, 905, 644,
74 | 372, 567, 466, 434, 645, 210, 389, 550, 919, 135,
75 | 780, 773, 635, 389, 707, 100, 626, 958, 165, 504,
76 | 920, 176, 193, 713, 857, 265, 203, 50, 668, 108,
77 | 645, 990, 626, 197, 510, 357, 358, 850, 858, 364,
78 | 936, 638
79 | };
80 |
81 |
82 | /*-------------------------------------------------------------*/
83 | /*--- end randtable.c ---*/
84 | /*-------------------------------------------------------------*/
85 |
--------------------------------------------------------------------------------
/grub/lib/crc.c:
--------------------------------------------------------------------------------
1 | /* crc.c - crc function */
2 | /*
3 | * GRUB -- GRand Unified Bootloader
4 | * Copyright (C) 2008 Free Software Foundation, Inc.
5 | *
6 | * GRUB is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * GRUB is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with GRUB. If not, see .
18 | */
19 |
20 | #include
21 | #include
22 |
23 | static grub_uint32_t crc32c_table[256];
24 |
25 | /* Helper for init_crc32c_table. */
26 | static grub_uint32_t
27 | reflect(grub_uint32_t ref, int len)
28 | {
29 | grub_uint32_t result = 0;
30 | int i;
31 |
32 | for (i = 1; i <= len; i++)
33 | {
34 | if (ref & 1)
35 | result |= 1 << (len - i);
36 | ref >>= 1;
37 | }
38 |
39 | return result;
40 | }
41 |
42 | static void
43 | init_crc32c_table(void)
44 | {
45 | grub_uint32_t polynomial = 0x1edc6f41;
46 | int i, j;
47 |
48 | for (i = 0; i < 256; i++)
49 | {
50 | crc32c_table[i] = reflect(i, 8) << 24;
51 | for (j = 0; j < 8; j++)
52 | crc32c_table[i] = (crc32c_table[i] << 1) ^
53 | (crc32c_table[i] & (1 << 31) ? polynomial : 0);
54 | crc32c_table[i] = reflect(crc32c_table[i], 32);
55 | }
56 | }
57 |
58 | grub_uint32_t
59 | grub_getcrc32c(grub_uint32_t crc, const void* buf, int size)
60 | {
61 | int i;
62 | const grub_uint8_t* data = buf;
63 |
64 | if (!crc32c_table[1])
65 | init_crc32c_table();
66 |
67 | crc ^= 0xffffffff;
68 |
69 | for (i = 0; i < size; i++)
70 | {
71 | crc = (crc >> 8) ^ crc32c_table[(crc & 0xFF) ^ *data];
72 | data++;
73 | }
74 |
75 | return crc ^ 0xffffffff;
76 | }
77 |
--------------------------------------------------------------------------------
/grub/lib/crc64.c:
--------------------------------------------------------------------------------
1 | /* crc64.c - crc64 function */
2 | /*
3 | * GRUB -- GRand Unified Bootloader
4 | * Copyright (C) 2008,2011 Free Software Foundation, Inc.
5 | *
6 | * GRUB is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * GRUB is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with GRUB. If not, see .
18 | */
19 |
20 | #include
21 | #include
22 |
23 | GRUB_MOD_LICENSE("GPLv3+");
24 |
25 | static grub_uint64_t crc64_table[256];
26 |
27 | /* Helper for init_crc64_table. */
28 | static grub_uint64_t
29 | reflect(grub_uint64_t ref, int len)
30 | {
31 | grub_uint64_t result = 0;
32 | int i;
33 |
34 | for (i = 1; i <= len; i++)
35 | {
36 | if (ref & 1)
37 | result |= 1ULL << (len - i);
38 | ref >>= 1;
39 | }
40 |
41 | return result;
42 | }
43 |
44 | static void
45 | init_crc64_table(void)
46 | {
47 | grub_uint64_t polynomial = 0x42f0e1eba9ea3693ULL;
48 | int i, j;
49 |
50 | for (i = 0; i < 256; i++)
51 | {
52 | crc64_table[i] = reflect(i, 8) << 56;
53 | for (j = 0; j < 8; j++)
54 | {
55 | crc64_table[i] = (crc64_table[i] << 1) ^
56 | (crc64_table[i] & (1ULL << 63) ? polynomial : 0);
57 | }
58 | crc64_table[i] = reflect(crc64_table[i], 64);
59 | }
60 | }
61 |
62 | static void
63 | crc64_init(void* context)
64 | {
65 | if (!crc64_table[1])
66 | init_crc64_table();
67 | *(grub_uint64_t*)context = 0;
68 | }
69 |
70 | static void
71 | crc64_write(void* context, const void* buf, grub_size_t size)
72 | {
73 | unsigned i;
74 | const grub_uint8_t* data = buf;
75 | grub_uint64_t crc = ~grub_le_to_cpu64(*(grub_uint64_t*)context);
76 |
77 | for (i = 0; i < size; i++)
78 | {
79 | crc = (crc >> 8) ^ crc64_table[(crc & 0xFF) ^ *data];
80 | data++;
81 | }
82 |
83 | *(grub_uint64_t*)context = grub_cpu_to_le64(~crc);
84 | }
85 |
86 | static grub_uint8_t*
87 | crc64_read(void* context)
88 | {
89 | return context;
90 | }
91 |
92 | static void
93 | crc64_final(void* context __attribute__((unused)))
94 | {
95 | }
96 |
97 | gcry_md_spec_t _gcry_digest_spec_crc64 =
98 | {
99 | "CRC64", 0, 0, 0, 8,
100 | crc64_init, crc64_write, crc64_final, crc64_read,
101 | sizeof(grub_uint64_t),
102 | .blocksize = 64
103 | };
104 |
--------------------------------------------------------------------------------
/grub/lib/crypto.c:
--------------------------------------------------------------------------------
1 | /*
2 | * NkArc
3 | * Copyright (C) 2023 A1ive
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #include
20 | #include
21 | #include
22 | #include "libgcrypt/gcry_wrap.h"
23 |
24 | void
25 | _gcry_burn_stack(int bytes)
26 | {
27 | char buf[64];
28 |
29 | wipememory(buf, sizeof buf);
30 | bytes -= sizeof buf;
31 | if (bytes > 0)
32 | _gcry_burn_stack(bytes);
33 | }
34 |
35 | void
36 | grub_crypto_hash(const gcry_md_spec_t* hash, void* out, const void* in, grub_size_t inlen)
37 | {
38 | GRUB_PROPERLY_ALIGNED_ARRAY(ctx, GRUB_CRYPTO_MAX_MD_CONTEXT_SIZE);
39 |
40 | if (hash->contextsize > sizeof(ctx))
41 | {
42 | grub_fatal("Too large md context");
43 | }
44 | hash->init(&ctx);
45 | hash->write(&ctx, in, inlen);
46 | hash->final(&ctx);
47 | grub_memcpy(out, hash->read(&ctx), hash->mdlen);
48 | }
49 |
50 | const gcry_md_spec_t*
51 | grub_crypto_lookup_md_by_name(const char* name)
52 | {
53 | const gcry_md_spec_t* md = NULL;
54 | if (grub_strcasecmp(name, "ADLER32") == 0)
55 | md = GRUB_MD_ADLER32;
56 | else if (grub_strcasecmp(name, "CRC32") == 0)
57 | md = GRUB_MD_CRC32;
58 | else if (grub_strcasecmp(name, "CRC64") == 0)
59 | md = GRUB_MD_CRC64;
60 | else if (grub_strcasecmp(name, "SHA1") == 0)
61 | md = GRUB_MD_SHA1;
62 | else if (grub_strcasecmp(name, "SHA256") == 0)
63 | md = GRUB_MD_SHA256;
64 | else if (grub_strcasecmp(name, "MD5") == 0)
65 | md = GRUB_MD_MD5;
66 | return md;
67 | }
68 |
--------------------------------------------------------------------------------
/grub/lib/datetime.c:
--------------------------------------------------------------------------------
1 | /* datetime.c - Module for common datetime function. */
2 | /*
3 | * GRUB -- GRand Unified Bootloader
4 | * Copyright (C) 2008 Free Software Foundation, Inc.
5 | *
6 | * GRUB is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * GRUB is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with GRUB. If not, see .
18 | */
19 |
20 | #include
21 | #include
22 | #include
23 | #include
24 |
25 | static const char* const grub_weekday_names[] =
26 | {
27 | "Sunday",
28 | "Monday",
29 | "Tuesday",
30 | "Wednesday",
31 | "Thursday",
32 | "Friday",
33 | "Saturday",
34 | };
35 |
36 | int
37 | grub_get_weekday(struct grub_datetime* datetime)
38 | {
39 | unsigned a, y, m;
40 |
41 | if (datetime->month <= 2)
42 | a = 1;
43 | else
44 | a = 0;
45 | y = datetime->year - a;
46 | m = datetime->month + 12 * a - 2;
47 |
48 | return (datetime->day + y + y / 4 - y / 100 + y / 400 + (31 * m / 12)) % 7;
49 | }
50 |
51 | const char*
52 | grub_get_weekday_name(struct grub_datetime* datetime)
53 | {
54 | return _(grub_weekday_names[grub_get_weekday(datetime)]);
55 | }
56 |
57 | #define SECPERMIN 60
58 | #define SECPERHOUR (60*SECPERMIN)
59 | #define SECPERDAY (24*SECPERHOUR)
60 | #define DAYSPERYEAR 365
61 | #define DAYSPER4YEARS (4*DAYSPERYEAR+1)
62 |
63 |
64 | void
65 | grub_unixtime2datetime(grub_int64_t nix, struct grub_datetime* datetime)
66 | {
67 | int i;
68 | grub_uint8_t months[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
69 | /* In the period of validity of unixtime all years divisible by 4
70 | are bissextile*/
71 | /* Convenience: let's have 3 consecutive non-bissextile years
72 | at the beginning of the counting date. So count from 1901. */
73 | int days_epoch;
74 | /* Number of days since 1st Januar, 1901. */
75 | unsigned days;
76 | /* Seconds into current day. */
77 | unsigned secs_in_day;
78 |
79 | /* Transform C divisions and modulos to mathematical ones */
80 | if (nix < 0)
81 | /*
82 | * The result of division here shouldn't be larger than GRUB_INT_MAX.
83 | * So, it's safe to store the result back in an int.
84 | */
85 | days_epoch = -(grub_divmod64(((grub_int64_t)(SECPERDAY)-nix - 1), SECPERDAY, NULL));
86 | else
87 | days_epoch = grub_divmod64(nix, SECPERDAY, NULL);
88 |
89 | secs_in_day = nix - days_epoch * SECPERDAY;
90 | days = days_epoch + 69 * DAYSPERYEAR + 17;
91 |
92 | datetime->year = 1901 + 4 * (days / DAYSPER4YEARS);
93 | days %= DAYSPER4YEARS;
94 | /* On 31st December of bissextile years 365 days from the beginning
95 | of the year elapsed but year isn't finished yet */
96 | if (days / DAYSPERYEAR == 4)
97 | {
98 | datetime->year += 3;
99 | days -= 3 * DAYSPERYEAR;
100 | }
101 | else
102 | {
103 | datetime->year += days / DAYSPERYEAR;
104 | days %= DAYSPERYEAR;
105 | }
106 | for (i = 0; i < 12
107 | && days >= (i == 1 && datetime->year % 4 == 0
108 | ? 29U : months[i]); i++)
109 | days -= (i == 1 && datetime->year % 4 == 0
110 | ? 29U : months[i]);
111 | datetime->month = i + 1;
112 | datetime->day = 1 + days;
113 | datetime->hour = (secs_in_day / SECPERHOUR);
114 | secs_in_day %= SECPERHOUR;
115 | datetime->minute = secs_in_day / SECPERMIN;
116 | datetime->second = secs_in_day % SECPERMIN;
117 | }
118 |
--------------------------------------------------------------------------------
/grub/lib/libgcrypt/gcry_wrap.h:
--------------------------------------------------------------------------------
1 | /*
2 | * GRUB -- GRand Unified Bootloader
3 | * Copyright (C) 2009 Free Software Foundation, Inc.
4 | *
5 | * GRUB is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * GRUB is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with GRUB. If not, see .
17 | */
18 |
19 | #ifndef GRUB_GCRY_TYPES_HEADER
20 | #define GRUB_GCRY_TYPES_HEADER 1
21 |
22 | #include
23 |
24 | #undef WORDS_BIGENDIAN
25 |
26 | typedef grub_uint64_t u64;
27 | typedef grub_uint32_t u32;
28 | typedef grub_uint16_t u16;
29 | typedef grub_uint8_t byte;
30 |
31 | /* Functions for loading and storing unaligned u32 values of different
32 | endianness. */
33 | static inline u32 buf_get_be32(const void* _buf)
34 | {
35 | const byte* in = _buf;
36 | return ((u32)in[0] << 24) | ((u32)in[1] << 16) |
37 | ((u32)in[2] << 8) | (u32)in[3];
38 | }
39 |
40 | static inline u32 buf_get_le32(const void* _buf)
41 | {
42 | const byte* in = _buf;
43 | return ((u32)in[3] << 24) | ((u32)in[2] << 16) |
44 | ((u32)in[1] << 8) | (u32)in[0];
45 | }
46 |
47 | static inline void buf_put_be32(void* _buf, u32 val)
48 | {
49 | byte* out = _buf;
50 | out[0] = (byte)(val >> 24);
51 | out[1] = (byte)(val >> 16);
52 | out[2] = (byte)(val >> 8);
53 | out[3] = (byte)val;
54 | }
55 |
56 | static inline void buf_put_le32(void* _buf, u32 val)
57 | {
58 | byte* out = _buf;
59 | out[3] = (byte)(val >> 24);
60 | out[2] = (byte)(val >> 16);
61 | out[1] = (byte)(val >> 8);
62 | out[0] = (byte)val;
63 | }
64 |
65 | /* Functions for loading and storing unaligned u64 values of different
66 | endianness. */
67 | static inline u64 buf_get_be64(const void* _buf)
68 | {
69 | const byte* in = _buf;
70 | return ((u64)in[0] << 56) | ((u64)in[1] << 48) |
71 | ((u64)in[2] << 40) | ((u64)in[3] << 32) |
72 | ((u64)in[4] << 24) | ((u64)in[5] << 16) |
73 | ((u64)in[6] << 8) | (u64)in[7];
74 | }
75 |
76 | static inline u64 buf_get_le64(const void* _buf)
77 | {
78 | const byte* in = _buf;
79 | return ((u64)in[7] << 56) | ((u64)in[6] << 48) |
80 | ((u64)in[5] << 40) | ((u64)in[4] << 32) |
81 | ((u64)in[3] << 24) | ((u64)in[2] << 16) |
82 | ((u64)in[1] << 8) | (u64)in[0];
83 | }
84 |
85 | static inline void buf_put_be64(void* _buf, u64 val)
86 | {
87 | byte* out = _buf;
88 | out[0] = (byte)(val >> 56);
89 | out[1] = (byte)(val >> 48);
90 | out[2] = (byte)(val >> 40);
91 | out[3] = (byte)(val >> 32);
92 | out[4] = (byte)(val >> 24);
93 | out[5] = (byte)(val >> 16);
94 | out[6] = (byte)(val >> 8);
95 | out[7] = (byte)val;
96 | }
97 |
98 | static inline void buf_put_le64(void* _buf, u64 val)
99 | {
100 | byte* out = _buf;
101 | out[7] = (byte)(val >> 56);
102 | out[6] = (byte)(val >> 48);
103 | out[5] = (byte)(val >> 40);
104 | out[4] = (byte)(val >> 32);
105 | out[3] = (byte)(val >> 24);
106 | out[2] = (byte)(val >> 16);
107 | out[1] = (byte)(val >> 8);
108 | out[0] = (byte)val;
109 | }
110 |
111 | #endif
112 |
--------------------------------------------------------------------------------
/grub/lib/lz4/lz4.h:
--------------------------------------------------------------------------------
1 | /*
2 | * LZ4 - Fast LZ compression algorithm
3 | * Copyright (C) 2011-2016, Yann Collet.
4 | * BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions are
7 | * met:
8 | * * Redistributions of source code must retain the above copyright
9 | * notice, this list of conditions and the following disclaimer.
10 | * * Redistributions in binary form must reproduce the above
11 | * copyright notice, this list of conditions and the following disclaimer
12 | * in the documentation and/or other materials provided with the
13 | * distribution.
14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
15 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
17 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
18 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
19 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
20 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 | * You can contact the author at :
26 | * - LZ4 homepage : http://www.lz4.org
27 | * - LZ4 source repository : https://github.com/lz4/lz4
28 | */
29 |
30 | #ifndef __LZ4_H__
31 | #define __LZ4_H__
32 |
33 | int
34 | LZ4_decompress_safe (const char *source, char *dest, int compressedSize,
35 | int maxDecompressedSize);
36 |
37 | int
38 | LZ4_decompress_safe_partial (const char *src, char *dst, int compressedSize,
39 | int targetOutputSize, int dstCapacity);
40 |
41 | int
42 | LZ4_decompress_fast (const char *source, char *dest, int originalSize);
43 |
44 | int
45 | LZ4_decompress_safe_usingDict (const char *source, char *dest,
46 | int compressedSize, int maxOutputSize,
47 | const char *dictStart, int dictSize);
48 |
49 | int
50 | LZ4_decompress_fast_usingDict (const char *source, char *dest, int originalSize,
51 | const char *dictStart, int dictSize);
52 |
53 | #endif
--------------------------------------------------------------------------------
/grub/lib/minilzo/minilzo.h:
--------------------------------------------------------------------------------
1 | /* minilzo.h -- mini subset of the LZO real-time data compression library
2 |
3 | This file is part of the LZO real-time data compression library.
4 |
5 | Copyright (C) 1996-2017 Markus Franz Xaver Johannes Oberhumer
6 | All Rights Reserved.
7 |
8 | The LZO library is free software; you can redistribute it and/or
9 | modify it under the terms of the GNU General Public License as
10 | published by the Free Software Foundation; either version 2 of
11 | the License, or (at your option) any later version.
12 |
13 | The LZO library is distributed in the hope that it will be useful,
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | GNU General Public License for more details.
17 |
18 | You should have received a copy of the GNU General Public License
19 | along with the LZO library; see the file COPYING.
20 | If not, write to the Free Software Foundation, Inc.,
21 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 |
23 | Markus F.X.J. Oberhumer
24 |
25 | http://www.oberhumer.com/opensource/lzo/
26 | */
27 |
28 | /*
29 | * NOTE:
30 | * the full LZO package can be found at
31 | * http://www.oberhumer.com/opensource/lzo/
32 | */
33 |
34 |
35 | #ifndef __MINILZO_H_INCLUDED
36 | #define __MINILZO_H_INCLUDED 1
37 |
38 | #define MINILZO_VERSION 0x20a0 /* 2.10 */
39 |
40 | #if defined(__LZOCONF_H_INCLUDED)
41 | # error "you cannot use both LZO and miniLZO"
42 | #endif
43 |
44 | /* internal Autoconf configuration file - only used when building miniLZO */
45 | #ifdef MINILZO_HAVE_CONFIG_H
46 | # include
47 | #endif
48 | #include
49 | #include
50 |
51 | #ifndef __LZODEFS_H_INCLUDED
52 | #include "lzodefs.h"
53 | #endif
54 | #undef LZO_HAVE_CONFIG_H
55 | #include "lzoconf.h"
56 |
57 | #if !defined(LZO_VERSION) || (LZO_VERSION != MINILZO_VERSION)
58 | # error "version mismatch in header files"
59 | #endif
60 |
61 |
62 | #ifdef __cplusplus
63 | extern "C" {
64 | #endif
65 |
66 |
67 | /***********************************************************************
68 | //
69 | ************************************************************************/
70 |
71 | /* Memory required for the wrkmem parameter.
72 | * When the required size is 0, you can also pass a NULL pointer.
73 | */
74 |
75 | #define LZO1X_MEM_COMPRESS LZO1X_1_MEM_COMPRESS
76 | #define LZO1X_1_MEM_COMPRESS ((lzo_uint32_t) (16384L * lzo_sizeof_dict_t))
77 | #define LZO1X_MEM_DECOMPRESS (0)
78 |
79 |
80 | /* compression */
81 | LZO_EXTERN(int)
82 | lzo1x_1_compress ( const lzo_bytep src, lzo_uint src_len,
83 | lzo_bytep dst, lzo_uintp dst_len,
84 | lzo_voidp wrkmem );
85 |
86 | /* decompression */
87 | LZO_EXTERN(int)
88 | lzo1x_decompress ( const lzo_bytep src, lzo_uint src_len,
89 | lzo_bytep dst, lzo_uintp dst_len,
90 | lzo_voidp wrkmem /* NOT USED */ );
91 |
92 | /* safe decompression with overrun testing */
93 | LZO_EXTERN(int)
94 | lzo1x_decompress_safe ( const lzo_bytep src, lzo_uint src_len,
95 | lzo_bytep dst, lzo_uintp dst_len,
96 | lzo_voidp wrkmem /* NOT USED */ );
97 |
98 |
99 | #ifdef __cplusplus
100 | } /* extern "C" */
101 | #endif
102 |
103 | #endif /* already included */
104 |
105 |
106 | /* vim:set ts=4 sw=4 et: */
107 |
--------------------------------------------------------------------------------
/grub/lib/mscompress/mscompress.h:
--------------------------------------------------------------------------------
1 | /*
2 | * GRUB -- GRand Unified Bootloader
3 | * Copyright (C) 2022 Free Software Foundation, Inc.
4 | *
5 | * GRUB is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * GRUB is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with GRUB. If not, see .
17 | */
18 |
19 | #ifndef GRUB_MSCOMPRESS_HEADER
20 | #define GRUB_MSCOMPRESS_HEADER 1
21 |
22 | #include
23 | #include
24 |
25 | /** Maximum length of a Huffman symbol (in bits) */
26 | #define HUFFMAN_BITS 16
27 |
28 | /** Raw huffman symbol */
29 | typedef grub_uint16_t huffman_raw_symbol_t;
30 |
31 | /** Quick lookup length for a Huffman symbol (in bits)
32 | *
33 | * This is a policy decision.
34 | */
35 | #define HUFFMAN_QL_BITS 7
36 |
37 | /** Quick lookup shift */
38 | #define HUFFMAN_QL_SHIFT (HUFFMAN_BITS - HUFFMAN_QL_BITS)
39 |
40 | /** A Huffman-coded set of symbols of a given length */
41 | struct huffman_symbols
42 | {
43 | /** Length of Huffman-coded symbols (in bits) */
44 | grub_uint8_t bits;
45 | /** Shift to normalise symbols of this length to HUFFMAN_BITS bits */
46 | grub_uint8_t shift;
47 | /** Number of Huffman-coded symbols having this length */
48 | grub_uint16_t freq;
49 | /** First symbol of this length (normalised to HUFFMAN_BITS bits)
50 | *
51 | * Stored as a 32-bit value to allow the value
52 | * (1<bits;
85 | }
86 |
87 | /**
88 | * Get Huffman symbol value
89 | *
90 | * @v sym Huffman symbol set
91 | * @v huf Raw input value (normalised to HUFFMAN_BITS bits)
92 | * @ret raw Raw symbol value
93 | */
94 | static inline __attribute__((always_inline)) huffman_raw_symbol_t
95 | grub_huffman_raw(struct huffman_symbols* sym, unsigned int huf)
96 | {
97 | return sym->raw[huf >> sym->shift];
98 | }
99 |
100 | int
101 | grub_huffman_alphabet(struct huffman_alphabet* alphabet,
102 | grub_uint8_t* lengths, unsigned int count);
103 |
104 | struct huffman_symbols*
105 | grub_huffman_sym(struct huffman_alphabet* alphabet, unsigned int huf);
106 |
107 | grub_ssize_t
108 | grub_lzx_decompress(const void* data, grub_size_t len, void* buf);
109 |
110 | grub_ssize_t
111 | grub_xca_decompress(const void* data, grub_size_t len, void* buf);
112 |
113 | #endif /* ! GRUB_MSCOMPRESS_HEADER */
114 |
--------------------------------------------------------------------------------
/grub/lib/progress.c:
--------------------------------------------------------------------------------
1 | /* progress.c - show loading progress */
2 | /*
3 | * GRUB -- GRand Unified Bootloader
4 | * Copyright (C) 2013 Free Software Foundation, Inc.
5 | *
6 | * GRUB is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * GRUB is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with GRUB. If not, see .
18 | */
19 |
20 | #include
21 | #include
22 | #include
23 | #include
24 | #include
25 |
26 | #include
27 |
28 | GRUB_MOD_LICENSE("GPLv3+");
29 |
30 | #define UPDATE_INTERVAL 800
31 |
32 | static grub_err_t
33 | grub_file_progress_hook_real(grub_disk_addr_t sector __attribute__((unused)),
34 | unsigned offset __attribute__((unused)),
35 | unsigned length,
36 | char* buf __attribute__((unused)), void* data)
37 | {
38 | static int call_depth = 0;
39 | grub_uint64_t now;
40 | static grub_uint64_t last_progress_update_time;
41 | grub_file_t file = data;
42 |
43 | file->progress_offset += length;
44 |
45 | if (call_depth)
46 | return GRUB_ERR_NONE;
47 |
48 | if (!nk.progress)
49 | return GRUB_ERR_NONE;
50 |
51 | call_depth = 1;
52 | now = grub_get_time_ms();
53 |
54 | if (((now - last_progress_update_time > UPDATE_INTERVAL) &&
55 | (file->progress_offset - file->offset > 0)) ||
56 | (file->progress_offset == file->size))
57 | {
58 | const char* partial_file_name;
59 |
60 | unsigned long long percent;
61 | grub_uint64_t current_speed;
62 |
63 | if (now - file->last_progress_time < 10)
64 | current_speed = 0;
65 | else
66 | current_speed = grub_divmod64((file->progress_offset
67 | - file->last_progress_offset)
68 | * 100ULL * 1000ULL,
69 | now - file->last_progress_time, 0);
70 |
71 | if (file->size == 0)
72 | percent = 100;
73 | else
74 | percent = grub_divmod64(100 * file->progress_offset,
75 | file->size, 0);
76 |
77 | /* grub_net_fs_open() saves off partial file structure before name is initialized.
78 | It already saves passed file name in net structure so just use it in this case.
79 | */
80 | if (file->name) /* grub_file_open() may leave it as NULL */
81 | partial_file_name = grub_strrchr(file->name, '/');
82 | else
83 | partial_file_name = NULL;
84 | if (partial_file_name)
85 | partial_file_name++;
86 | else
87 | partial_file_name = "";
88 |
89 | file->estimated_speed = (file->estimated_speed + current_speed) >> 1;
90 |
91 | static char buffer[80];
92 | grub_snprintf(buffer, sizeof(buffer), "[ %.20s %s %llu%% ",
93 | partial_file_name,
94 | grub_get_human_size(file->progress_offset, GRUB_HUMAN_SIZE_NORMAL),
95 | (unsigned long long) percent);
96 | char* ptr = buffer + grub_strlen(buffer);
97 | grub_snprintf(ptr, sizeof(buffer) - (ptr - buffer), "%s ]",
98 | grub_get_human_size(file->estimated_speed, GRUB_HUMAN_SIZE_SPEED));
99 | memset(nk.progress_info, 0, sizeof(nk.progress_info));
100 | grub_utf8_to_utf16(nk.progress_info, 95, (grub_uint8_t*)buffer, -1, NULL);
101 | SetWindowTextW(GetDlgItem(nk.progress_wnd, IDC_PROG_TEXT), nk.progress_info);
102 |
103 | file->last_progress_offset = file->progress_offset;
104 | file->last_progress_time = now;
105 | last_progress_update_time = now;
106 | }
107 | call_depth = 0;
108 |
109 | return GRUB_ERR_NONE;
110 | }
111 |
112 | GRUB_MOD_INIT(progress)
113 | {
114 | grub_file_progress_hook = grub_file_progress_hook_real;
115 | }
116 |
117 | GRUB_MOD_FINI(progress)
118 | {
119 | grub_file_progress_hook = 0;
120 | }
121 |
--------------------------------------------------------------------------------
/grub/lib/xzembed/xz_private.h:
--------------------------------------------------------------------------------
1 | /* xz_private.h - Private includes and definitions */
2 | /*
3 | * GRUB -- GRand Unified Bootloader
4 | * Copyright (C) 2010 Free Software Foundation, Inc.
5 | *
6 | * GRUB is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * GRUB is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with GRUB. If not, see .
18 | */
19 | /*
20 | * This file is based on code from XZ embedded project
21 | * http://tukaani.org/xz/embedded.html
22 | */
23 |
24 | #ifndef XZ_PRIVATE_H
25 | #define XZ_PRIVATE_H
26 |
27 | /*
28 | * For userspace builds, use a separate header to define the required
29 | * macros and functions. This makes it easier to adapt the code into
30 | * different environments and avoids clutter in the Linux kernel tree.
31 | */
32 | #include "xz_config.h"
33 |
34 | /*
35 | * If any of the BCJ filter decoders are wanted, define XZ_DEC_BCJ.
36 | * XZ_DEC_BCJ is used to enable generic support for BCJ decoders.
37 | */
38 | #ifndef XZ_DEC_BCJ
39 | # if defined(XZ_DEC_X86) || defined(XZ_DEC_POWERPC) \
40 | || defined(XZ_DEC_IA64) || defined(XZ_DEC_ARM) \
41 | || defined(XZ_DEC_ARM) || defined(XZ_DEC_ARMTHUMB) \
42 | || defined(XZ_DEC_SPARC)
43 | # define XZ_DEC_BCJ
44 | # endif
45 | #endif
46 |
47 | /*
48 | * Allocate memory for LZMA2 decoder. xz_dec_lzma2_reset() must be used
49 | * before calling xz_dec_lzma2_run().
50 | */
51 | struct xz_dec_lzma2 * xz_dec_lzma2_create(
52 | uint32_t dict_max);
53 |
54 | /*
55 | * Decode the LZMA2 properties (one byte) and reset the decoder. Return
56 | * XZ_OK on success, XZ_MEMLIMIT_ERROR if the preallocated dictionary is not
57 | * big enough, and XZ_OPTIONS_ERROR if props indicates something that this
58 | * decoder doesn't support.
59 | */
60 | enum xz_ret xz_dec_lzma2_reset(
61 | struct xz_dec_lzma2 *s, uint8_t props);
62 |
63 | /* Decode raw LZMA2 stream from b->in to b->out. */
64 | enum xz_ret xz_dec_lzma2_run(
65 | struct xz_dec_lzma2 *s, struct xz_buf *b);
66 |
67 | /* Free the memory allocated for the LZMA2 decoder. */
68 | void xz_dec_lzma2_end(struct xz_dec_lzma2 *s);
69 |
70 | /*
71 | * Allocate memory for BCJ decoders. xz_dec_bcj_reset() must be used before
72 | * calling xz_dec_bcj_run().
73 | */
74 | struct xz_dec_bcj * xz_dec_bcj_create(bool single_call);
75 |
76 | /*
77 | * Decode the Filter ID of a BCJ filter. This implementation doesn't
78 | * support custom start offsets, so no decoding of Filter Properties
79 | * is needed. Returns XZ_OK if the given Filter ID is supported.
80 | * Otherwise XZ_OPTIONS_ERROR is returned.
81 | */
82 | enum xz_ret xz_dec_bcj_reset(
83 | struct xz_dec_bcj *s, uint8_t id);
84 |
85 | /*
86 | * Decode raw BCJ + LZMA2 stream. This must be used only if there actually is
87 | * a BCJ filter in the chain. If the chain has only LZMA2, xz_dec_lzma2_run()
88 | * must be called directly.
89 | */
90 | enum xz_ret xz_dec_bcj_run(struct xz_dec_bcj *s,
91 | struct xz_dec_lzma2 *lzma2, struct xz_buf *b);
92 |
93 | /* Free the memory allocated for the BCJ filters. */
94 | #define xz_dec_bcj_end(s) kfree(s)
95 |
96 | #endif
97 |
--------------------------------------------------------------------------------
/grub/lib/xzembed/xz_stream.h:
--------------------------------------------------------------------------------
1 | /* xz_stream.h - Definitions for handling the .xz file format */
2 | /*
3 | * GRUB -- GRand Unified Bootloader
4 | * Copyright (C) 2010 Free Software Foundation, Inc.
5 | *
6 | * GRUB is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * GRUB is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with GRUB. If not, see .
18 | */
19 | /*
20 | * This file is based on code from XZ embedded project
21 | * http://tukaani.org/xz/embedded.html
22 | */
23 |
24 | #ifndef XZ_STREAM_H
25 | #define XZ_STREAM_H
26 |
27 | /*
28 | * See the .xz file format specification at
29 | * http://tukaani.org/xz/xz-file-format.txt
30 | * to understand the container format.
31 | */
32 |
33 | #define STREAM_HEADER_SIZE 12
34 |
35 | #define HEADER_MAGIC "\xFD" "7zXZ\0"
36 | #define HEADER_MAGIC_SIZE 6
37 |
38 | #define FOOTER_MAGIC "YZ"
39 | #define FOOTER_MAGIC_SIZE 2
40 |
41 | /*
42 | * Variable-length integer can hold a 63-bit unsigned integer, or a special
43 | * value to indicate that the value is unknown.
44 | */
45 | typedef uint64_t vli_type;
46 |
47 | #define VLI_MAX ((vli_type)-1 / 2)
48 | #define VLI_UNKNOWN ((vli_type)-1)
49 |
50 | /* Maximum encoded size of a VLI */
51 | #define VLI_BYTES_MAX (sizeof(vli_type) * 8 / 7)
52 |
53 | #endif
54 |
--------------------------------------------------------------------------------
/grub/lib/zstd/common/allocations.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) Meta Platforms, Inc. and affiliates.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under both the BSD-style license (found in the
6 | * LICENSE file in the root directory of this source tree) and the GPLv2 (found
7 | * in the COPYING file in the root directory of this source tree).
8 | * You may select, at your option, one of the above-listed licenses.
9 | */
10 |
11 | /* This file provides custom allocation primitives
12 | */
13 |
14 | #define ZSTD_DEPS_NEED_MALLOC
15 | #include "zstd_deps.h" /* ZSTD_malloc, ZSTD_calloc, ZSTD_free, ZSTD_memset */
16 |
17 | #include "compiler.h" /* MEM_STATIC */
18 | #define ZSTD_STATIC_LINKING_ONLY
19 | #include "../zstd.h" /* ZSTD_customMem */
20 |
21 | #ifndef ZSTD_ALLOCATIONS_H
22 | #define ZSTD_ALLOCATIONS_H
23 |
24 | /* custom memory allocation functions */
25 |
26 | MEM_STATIC void* ZSTD_customMalloc(size_t size, ZSTD_customMem customMem)
27 | {
28 | if (customMem.customAlloc)
29 | return customMem.customAlloc(customMem.opaque, size);
30 | return ZSTD_malloc(size);
31 | }
32 |
33 | MEM_STATIC void* ZSTD_customCalloc(size_t size, ZSTD_customMem customMem)
34 | {
35 | if (customMem.customAlloc) {
36 | /* calloc implemented as malloc+memset;
37 | * not as efficient as calloc, but next best guess for custom malloc */
38 | void* const ptr = customMem.customAlloc(customMem.opaque, size);
39 | ZSTD_memset(ptr, 0, size);
40 | return ptr;
41 | }
42 | return ZSTD_calloc(1, size);
43 | }
44 |
45 | MEM_STATIC void ZSTD_customFree(void* ptr, ZSTD_customMem customMem)
46 | {
47 | if (ptr!=NULL) {
48 | if (customMem.customFree)
49 | customMem.customFree(customMem.opaque, ptr);
50 | else
51 | ZSTD_free(ptr);
52 | }
53 | }
54 |
55 | #endif /* ZSTD_ALLOCATIONS_H */
56 |
--------------------------------------------------------------------------------
/grub/lib/zstd/common/debug.c:
--------------------------------------------------------------------------------
1 | /* ******************************************************************
2 | * debug
3 | * Part of FSE library
4 | * Copyright (c) Meta Platforms, Inc. and affiliates.
5 | *
6 | * You can contact the author at :
7 | * - Source repository : https://github.com/Cyan4973/FiniteStateEntropy
8 | *
9 | * This source code is licensed under both the BSD-style license (found in the
10 | * LICENSE file in the root directory of this source tree) and the GPLv2 (found
11 | * in the COPYING file in the root directory of this source tree).
12 | * You may select, at your option, one of the above-listed licenses.
13 | ****************************************************************** */
14 |
15 |
16 | /*
17 | * This module only hosts one global variable
18 | * which can be used to dynamically influence the verbosity of traces,
19 | * such as DEBUGLOG and RAWLOG
20 | */
21 |
22 | #include "debug.h"
23 |
24 | #if !defined(ZSTD_LINUX_KERNEL) || (DEBUGLEVEL>=2)
25 | /* We only use this when DEBUGLEVEL>=2, but we get -Werror=pedantic errors if a
26 | * translation unit is empty. So remove this from Linux kernel builds, but
27 | * otherwise just leave it in.
28 | */
29 | int g_debuglevel = DEBUGLEVEL;
30 | #endif
31 |
--------------------------------------------------------------------------------
/grub/lib/zstd/common/error_private.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) Meta Platforms, Inc. and affiliates.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under both the BSD-style license (found in the
6 | * LICENSE file in the root directory of this source tree) and the GPLv2 (found
7 | * in the COPYING file in the root directory of this source tree).
8 | * You may select, at your option, one of the above-listed licenses.
9 | */
10 |
11 | /* The purpose of this file is to have a single list of error strings embedded in binary */
12 |
13 | #include "error_private.h"
14 |
15 | const char* ERR_getErrorString(ERR_enum code)
16 | {
17 | #ifdef ZSTD_STRIP_ERROR_STRINGS
18 | (void)code;
19 | return "Error strings stripped";
20 | #else
21 | static const char* const notErrorCode = "Unspecified error code";
22 | switch( code )
23 | {
24 | case PREFIX(no_error): return "No error detected";
25 | case PREFIX(GENERIC): return "Error (generic)";
26 | case PREFIX(prefix_unknown): return "Unknown frame descriptor";
27 | case PREFIX(version_unsupported): return "Version not supported";
28 | case PREFIX(frameParameter_unsupported): return "Unsupported frame parameter";
29 | case PREFIX(frameParameter_windowTooLarge): return "Frame requires too much memory for decoding";
30 | case PREFIX(corruption_detected): return "Data corruption detected";
31 | case PREFIX(checksum_wrong): return "Restored data doesn't match checksum";
32 | case PREFIX(literals_headerWrong): return "Header of Literals' block doesn't respect format specification";
33 | case PREFIX(parameter_unsupported): return "Unsupported parameter";
34 | case PREFIX(parameter_combination_unsupported): return "Unsupported combination of parameters";
35 | case PREFIX(parameter_outOfBound): return "Parameter is out of bound";
36 | case PREFIX(init_missing): return "Context should be init first";
37 | case PREFIX(memory_allocation): return "Allocation error : not enough memory";
38 | case PREFIX(workSpace_tooSmall): return "workSpace buffer is not large enough";
39 | case PREFIX(stage_wrong): return "Operation not authorized at current processing stage";
40 | case PREFIX(tableLog_tooLarge): return "tableLog requires too much memory : unsupported";
41 | case PREFIX(maxSymbolValue_tooLarge): return "Unsupported max Symbol Value : too large";
42 | case PREFIX(maxSymbolValue_tooSmall): return "Specified maxSymbolValue is too small";
43 | case PREFIX(stabilityCondition_notRespected): return "pledged buffer stability condition is not respected";
44 | case PREFIX(dictionary_corrupted): return "Dictionary is corrupted";
45 | case PREFIX(dictionary_wrong): return "Dictionary mismatch";
46 | case PREFIX(dictionaryCreation_failed): return "Cannot create Dictionary from provided samples";
47 | case PREFIX(dstSize_tooSmall): return "Destination buffer is too small";
48 | case PREFIX(srcSize_wrong): return "Src size is incorrect";
49 | case PREFIX(dstBuffer_null): return "Operation on NULL destination buffer";
50 | case PREFIX(noForwardProgress_destFull): return "Operation made no progress over multiple calls, due to output buffer being full";
51 | case PREFIX(noForwardProgress_inputEmpty): return "Operation made no progress over multiple calls, due to input being empty";
52 | /* following error codes are not stable and may be removed or changed in a future version */
53 | case PREFIX(frameIndex_tooLarge): return "Frame index is too large";
54 | case PREFIX(seekableIO): return "An I/O error occurred when reading/seeking";
55 | case PREFIX(dstBuffer_wrong): return "Destination buffer is wrong";
56 | case PREFIX(srcBuffer_wrong): return "Source buffer is wrong";
57 | case PREFIX(sequenceProducer_failed): return "Block-level external sequence producer returned an error code";
58 | case PREFIX(externalSequences_invalid): return "External sequences are not valid";
59 | case PREFIX(maxCode):
60 | default: return notErrorCode;
61 | }
62 | #endif
63 | }
64 |
--------------------------------------------------------------------------------
/grub/lib/zstd/common/pool.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) Meta Platforms, Inc. and affiliates.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under both the BSD-style license (found in the
6 | * LICENSE file in the root directory of this source tree) and the GPLv2 (found
7 | * in the COPYING file in the root directory of this source tree).
8 | * You may select, at your option, one of the above-listed licenses.
9 | */
10 |
11 | #ifndef POOL_H
12 | #define POOL_H
13 |
14 | #if defined (__cplusplus)
15 | extern "C" {
16 | #endif
17 |
18 |
19 | #include "zstd_deps.h"
20 | #define ZSTD_STATIC_LINKING_ONLY /* ZSTD_customMem */
21 | #include "../zstd.h"
22 |
23 | typedef struct POOL_ctx_s POOL_ctx;
24 |
25 | /*! POOL_create() :
26 | * Create a thread pool with at most `numThreads` threads.
27 | * `numThreads` must be at least 1.
28 | * The maximum number of queued jobs before blocking is `queueSize`.
29 | * @return : POOL_ctx pointer on success, else NULL.
30 | */
31 | POOL_ctx* POOL_create(size_t numThreads, size_t queueSize);
32 |
33 | POOL_ctx* POOL_create_advanced(size_t numThreads, size_t queueSize,
34 | ZSTD_customMem customMem);
35 |
36 | /*! POOL_free() :
37 | * Free a thread pool returned by POOL_create().
38 | */
39 | void POOL_free(POOL_ctx* ctx);
40 |
41 |
42 | /*! POOL_joinJobs() :
43 | * Waits for all queued jobs to finish executing.
44 | */
45 | void POOL_joinJobs(POOL_ctx* ctx);
46 |
47 | /*! POOL_resize() :
48 | * Expands or shrinks pool's number of threads.
49 | * This is more efficient than releasing + creating a new context,
50 | * since it tries to preserve and reuse existing threads.
51 | * `numThreads` must be at least 1.
52 | * @return : 0 when resize was successful,
53 | * !0 (typically 1) if there is an error.
54 | * note : only numThreads can be resized, queueSize remains unchanged.
55 | */
56 | int POOL_resize(POOL_ctx* ctx, size_t numThreads);
57 |
58 | /*! POOL_sizeof() :
59 | * @return threadpool memory usage
60 | * note : compatible with NULL (returns 0 in this case)
61 | */
62 | size_t POOL_sizeof(const POOL_ctx* ctx);
63 |
64 | /*! POOL_function :
65 | * The function type that can be added to a thread pool.
66 | */
67 | typedef void (*POOL_function)(void*);
68 |
69 | /*! POOL_add() :
70 | * Add the job `function(opaque)` to the thread pool. `ctx` must be valid.
71 | * Possibly blocks until there is room in the queue.
72 | * Note : The function may be executed asynchronously,
73 | * therefore, `opaque` must live until function has been completed.
74 | */
75 | void POOL_add(POOL_ctx* ctx, POOL_function function, void* opaque);
76 |
77 |
78 | /*! POOL_tryAdd() :
79 | * Add the job `function(opaque)` to thread pool _if_ a queue slot is available.
80 | * Returns immediately even if not (does not block).
81 | * @return : 1 if successful, 0 if not.
82 | */
83 | int POOL_tryAdd(POOL_ctx* ctx, POOL_function function, void* opaque);
84 |
85 |
86 | #if defined (__cplusplus)
87 | }
88 | #endif
89 |
90 | #endif
91 |
--------------------------------------------------------------------------------
/grub/lib/zstd/common/xxhash.c:
--------------------------------------------------------------------------------
1 | /*
2 | * xxHash - Fast Hash algorithm
3 | * Copyright (c) Meta Platforms, Inc. and affiliates.
4 | *
5 | * You can contact the author at :
6 | * - xxHash homepage: https://cyan4973.github.io/xxHash/
7 | * - xxHash source repository : https://github.com/Cyan4973/xxHash
8 | *
9 | * This source code is licensed under both the BSD-style license (found in the
10 | * LICENSE file in the root directory of this source tree) and the GPLv2 (found
11 | * in the COPYING file in the root directory of this source tree).
12 | * You may select, at your option, one of the above-listed licenses.
13 | */
14 |
15 |
16 |
17 | /*
18 | * xxhash.c instantiates functions defined in xxhash.h
19 | */
20 |
21 | #define XXH_STATIC_LINKING_ONLY /* access advanced declarations */
22 | #define XXH_IMPLEMENTATION /* access definitions */
23 |
24 | #include "xxhash.h"
25 |
--------------------------------------------------------------------------------
/grub/lib/zstd/common/zstd_common.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) Meta Platforms, Inc. and affiliates.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under both the BSD-style license (found in the
6 | * LICENSE file in the root directory of this source tree) and the GPLv2 (found
7 | * in the COPYING file in the root directory of this source tree).
8 | * You may select, at your option, one of the above-listed licenses.
9 | */
10 |
11 |
12 |
13 | /*-*************************************
14 | * Dependencies
15 | ***************************************/
16 | #define ZSTD_DEPS_NEED_MALLOC
17 | #include "error_private.h"
18 | #include "zstd_internal.h"
19 |
20 |
21 | /*-****************************************
22 | * Version
23 | ******************************************/
24 | unsigned ZSTD_versionNumber(void) { return ZSTD_VERSION_NUMBER; }
25 |
26 | const char* ZSTD_versionString(void) { return ZSTD_VERSION_STRING; }
27 |
28 |
29 | /*-****************************************
30 | * ZSTD Error Management
31 | ******************************************/
32 | #undef ZSTD_isError /* defined within zstd_internal.h */
33 | /*! ZSTD_isError() :
34 | * tells if a return value is an error code
35 | * symbol is required for external callers */
36 | unsigned ZSTD_isError(size_t code) { return ERR_isError(code); }
37 |
38 | /*! ZSTD_getErrorName() :
39 | * provides error code string from function result (useful for debugging) */
40 | const char* ZSTD_getErrorName(size_t code) { return ERR_getErrorName(code); }
41 |
42 | /*! ZSTD_getError() :
43 | * convert a `size_t` function result into a proper ZSTD_errorCode enum */
44 | ZSTD_ErrorCode ZSTD_getErrorCode(size_t code) { return ERR_getErrorCode(code); }
45 |
46 | /*! ZSTD_getErrorString() :
47 | * provides error code string from enum */
48 | const char* ZSTD_getErrorString(ZSTD_ErrorCode code) { return ERR_getErrorString(code); }
49 |
--------------------------------------------------------------------------------
/grub/lib/zstd/common/zstd_deps.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) Meta Platforms, Inc. and affiliates.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under both the BSD-style license (found in the
6 | * LICENSE file in the root directory of this source tree) and the GPLv2 (found
7 | * in the COPYING file in the root directory of this source tree).
8 | * You may select, at your option, one of the above-listed licenses.
9 | */
10 |
11 | /* This file provides common libc dependencies that zstd requires.
12 | * The purpose is to allow replacing this file with a custom implementation
13 | * to compile zstd without libc support.
14 | */
15 |
16 | /* Need:
17 | * NULL
18 | * INT_MAX
19 | * UINT_MAX
20 | * ZSTD_memcpy()
21 | * ZSTD_memset()
22 | * ZSTD_memmove()
23 | */
24 | #ifndef ZSTD_DEPS_COMMON
25 | #define ZSTD_DEPS_COMMON
26 |
27 | #include
28 | #include
29 | #include
30 |
31 | #if defined(__GNUC__) && __GNUC__ >= 4
32 | # define ZSTD_memcpy(d,s,l) __builtin_memcpy((d),(s),(l))
33 | # define ZSTD_memmove(d,s,l) __builtin_memmove((d),(s),(l))
34 | # define ZSTD_memset(p,v,l) __builtin_memset((p),(v),(l))
35 | #else
36 | # define ZSTD_memcpy(d,s,l) memcpy((d),(s),(l))
37 | # define ZSTD_memmove(d,s,l) memmove((d),(s),(l))
38 | # define ZSTD_memset(p,v,l) memset((p),(v),(l))
39 | #endif
40 |
41 | #endif /* ZSTD_DEPS_COMMON */
42 |
43 | /* Need:
44 | * ZSTD_malloc()
45 | * ZSTD_free()
46 | * ZSTD_calloc()
47 | */
48 | #ifdef ZSTD_DEPS_NEED_MALLOC
49 | #ifndef ZSTD_DEPS_MALLOC
50 | #define ZSTD_DEPS_MALLOC
51 |
52 | #include
53 |
54 | #define ZSTD_malloc(s) malloc(s)
55 | #define ZSTD_calloc(n,s) calloc((n), (s))
56 | #define ZSTD_free(p) free((p))
57 |
58 | #endif /* ZSTD_DEPS_MALLOC */
59 | #endif /* ZSTD_DEPS_NEED_MALLOC */
60 |
61 | /*
62 | * Provides 64-bit math support.
63 | * Need:
64 | * U64 ZSTD_div64(U64 dividend, U32 divisor)
65 | */
66 | #ifdef ZSTD_DEPS_NEED_MATH64
67 | #ifndef ZSTD_DEPS_MATH64
68 | #define ZSTD_DEPS_MATH64
69 |
70 | #define ZSTD_div64(dividend, divisor) ((dividend) / (divisor))
71 |
72 | #endif /* ZSTD_DEPS_MATH64 */
73 | #endif /* ZSTD_DEPS_NEED_MATH64 */
74 |
75 | /* Need:
76 | * assert()
77 | */
78 | #ifdef ZSTD_DEPS_NEED_ASSERT
79 | #ifndef ZSTD_DEPS_ASSERT
80 | #define ZSTD_DEPS_ASSERT
81 |
82 | #include
83 |
84 | #endif /* ZSTD_DEPS_ASSERT */
85 | #endif /* ZSTD_DEPS_NEED_ASSERT */
86 |
87 | /* Need:
88 | * ZSTD_DEBUG_PRINT()
89 | */
90 | #ifdef ZSTD_DEPS_NEED_IO
91 | #ifndef ZSTD_DEPS_IO
92 | #define ZSTD_DEPS_IO
93 |
94 | #include
95 | #define ZSTD_DEBUG_PRINT(...) fprintf(stderr, __VA_ARGS__)
96 |
97 | #endif /* ZSTD_DEPS_IO */
98 | #endif /* ZSTD_DEPS_NEED_IO */
99 |
100 | /* Only requested when is known to be present.
101 | * Need:
102 | * intptr_t
103 | */
104 | #ifdef ZSTD_DEPS_NEED_STDINT
105 | #ifndef ZSTD_DEPS_STDINT
106 | #define ZSTD_DEPS_STDINT
107 |
108 | #include
109 |
110 | #endif /* ZSTD_DEPS_STDINT */
111 | #endif /* ZSTD_DEPS_NEED_STDINT */
112 |
--------------------------------------------------------------------------------
/grub/lib/zstd/decompress/zstd_ddict.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) Meta Platforms, Inc. and affiliates.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under both the BSD-style license (found in the
6 | * LICENSE file in the root directory of this source tree) and the GPLv2 (found
7 | * in the COPYING file in the root directory of this source tree).
8 | * You may select, at your option, one of the above-listed licenses.
9 | */
10 |
11 |
12 | #ifndef ZSTD_DDICT_H
13 | #define ZSTD_DDICT_H
14 |
15 | /*-*******************************************************
16 | * Dependencies
17 | *********************************************************/
18 | #include "../common/zstd_deps.h" /* size_t */
19 | #include "../zstd.h" /* ZSTD_DDict, and several public functions */
20 |
21 |
22 | /*-*******************************************************
23 | * Interface
24 | *********************************************************/
25 |
26 | /* note: several prototypes are already published in `zstd.h` :
27 | * ZSTD_createDDict()
28 | * ZSTD_createDDict_byReference()
29 | * ZSTD_createDDict_advanced()
30 | * ZSTD_freeDDict()
31 | * ZSTD_initStaticDDict()
32 | * ZSTD_sizeof_DDict()
33 | * ZSTD_estimateDDictSize()
34 | * ZSTD_getDictID_fromDict()
35 | */
36 |
37 | const void* ZSTD_DDict_dictContent(const ZSTD_DDict* ddict);
38 | size_t ZSTD_DDict_dictSize(const ZSTD_DDict* ddict);
39 |
40 | void ZSTD_copyDDictParameters(ZSTD_DCtx* dctx, const ZSTD_DDict* ddict);
41 |
42 |
43 |
44 | #endif /* ZSTD_DDICT_H */
45 |
--------------------------------------------------------------------------------
/grub/lib/zstd/decompress/zstd_decompress_block.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) Meta Platforms, Inc. and affiliates.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under both the BSD-style license (found in the
6 | * LICENSE file in the root directory of this source tree) and the GPLv2 (found
7 | * in the COPYING file in the root directory of this source tree).
8 | * You may select, at your option, one of the above-listed licenses.
9 | */
10 |
11 |
12 | #ifndef ZSTD_DEC_BLOCK_H
13 | #define ZSTD_DEC_BLOCK_H
14 |
15 | /*-*******************************************************
16 | * Dependencies
17 | *********************************************************/
18 | #include "../common/zstd_deps.h" /* size_t */
19 | #include "../zstd.h" /* DCtx, and some public functions */
20 | #include "../common/zstd_internal.h" /* blockProperties_t, and some public functions */
21 | #include "zstd_decompress_internal.h" /* ZSTD_seqSymbol */
22 |
23 |
24 | /* === Prototypes === */
25 |
26 | /* note: prototypes already published within `zstd.h` :
27 | * ZSTD_decompressBlock()
28 | */
29 |
30 | /* note: prototypes already published within `zstd_internal.h` :
31 | * ZSTD_getcBlockSize()
32 | * ZSTD_decodeSeqHeaders()
33 | */
34 |
35 |
36 | /* Streaming state is used to inform allocation of the literal buffer */
37 | typedef enum {
38 | not_streaming = 0,
39 | is_streaming = 1
40 | } streaming_operation;
41 |
42 | /* ZSTD_decompressBlock_internal() :
43 | * decompress block, starting at `src`,
44 | * into destination buffer `dst`.
45 | * @return : decompressed block size,
46 | * or an error code (which can be tested using ZSTD_isError())
47 | */
48 | size_t ZSTD_decompressBlock_internal(ZSTD_DCtx* dctx,
49 | void* dst, size_t dstCapacity,
50 | const void* src, size_t srcSize, const streaming_operation streaming);
51 |
52 | /* ZSTD_buildFSETable() :
53 | * generate FSE decoding table for one symbol (ll, ml or off)
54 | * this function must be called with valid parameters only
55 | * (dt is large enough, normalizedCounter distribution total is a power of 2, max is within range, etc.)
56 | * in which case it cannot fail.
57 | * The workspace must be 4-byte aligned and at least ZSTD_BUILD_FSE_TABLE_WKSP_SIZE bytes, which is
58 | * defined in zstd_decompress_internal.h.
59 | * Internal use only.
60 | */
61 | void ZSTD_buildFSETable(ZSTD_seqSymbol* dt,
62 | const short* normalizedCounter, unsigned maxSymbolValue,
63 | const U32* baseValue, const U8* nbAdditionalBits,
64 | unsigned tableLog, void* wksp, size_t wkspSize,
65 | int bmi2);
66 |
67 | /* Internal definition of ZSTD_decompressBlock() to avoid deprecation warnings. */
68 | size_t ZSTD_decompressBlock_deprecated(ZSTD_DCtx* dctx,
69 | void* dst, size_t dstCapacity,
70 | const void* src, size_t srcSize);
71 |
72 |
73 | #endif /* ZSTD_DEC_BLOCK_H */
74 |
--------------------------------------------------------------------------------
/grub/partmap/dvh.c:
--------------------------------------------------------------------------------
1 | /*
2 | * GRUB -- GRand Unified Bootloader
3 | * Copyright (C) 2002,2005,2006,2007,2011 Free Software Foundation, Inc.
4 | *
5 | * GRUB is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * GRUB is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with GRUB. If not, see .
17 | */
18 |
19 | #include
20 | #include
21 | #include
22 | #include
23 | #include
24 | #include
25 | #include
26 |
27 | GRUB_MOD_LICENSE("GPLv3+");
28 |
29 | #define DVH_MAGIC 0x0be5a941
30 |
31 | GRUB_PACKED_START
32 | struct grub_dvh_partition_descriptor
33 | {
34 | grub_uint32_t length;
35 | grub_uint32_t start;
36 | grub_uint32_t type;
37 | };
38 | GRUB_PACKED_END
39 |
40 | GRUB_PACKED_START
41 | struct grub_dvh_block
42 | {
43 | grub_uint32_t magic;
44 | grub_uint8_t unused[308];
45 | struct grub_dvh_partition_descriptor parts[16];
46 | grub_uint32_t checksum;
47 | grub_uint32_t unused2;
48 | };
49 | GRUB_PACKED_END
50 |
51 | static struct grub_partition_map grub_dvh_partition_map;
52 |
53 | /* Verify checksum (true=ok). */
54 | static int
55 | grub_dvh_is_valid(grub_uint32_t* label)
56 | {
57 | grub_uint32_t* pos;
58 | grub_uint32_t sum = 0;
59 |
60 | for (pos = label;
61 | pos < (label + sizeof(struct grub_dvh_block) / 4);
62 | pos++)
63 | sum += grub_be_to_cpu32(*pos);
64 |
65 | return !sum;
66 | }
67 |
68 | static grub_err_t
69 | dvh_partition_map_iterate(grub_disk_t disk,
70 | grub_partition_iterate_hook_t hook, void* hook_data)
71 | {
72 | struct grub_partition p;
73 | union
74 | {
75 | struct grub_dvh_block dvh;
76 | grub_uint32_t raw[0];
77 | } block;
78 | unsigned partnum;
79 | grub_err_t err;
80 |
81 | p.partmap = &grub_dvh_partition_map;
82 | err = grub_disk_read(disk, 0, 0, sizeof(struct grub_dvh_block),
83 | &block);
84 | if (err)
85 | return err;
86 |
87 | if (DVH_MAGIC != grub_be_to_cpu32(block.dvh.magic))
88 | return grub_error(GRUB_ERR_BAD_PART_TABLE, "not a dvh partition table");
89 |
90 | if (!grub_dvh_is_valid(block.raw))
91 | return grub_error(GRUB_ERR_BAD_PART_TABLE, "invalid checksum");
92 |
93 | /* Maybe another error value would be better, because partition
94 | table _is_ recognized but invalid. */
95 | for (partnum = 0; partnum < ARRAY_SIZE(block.dvh.parts); partnum++)
96 | {
97 | if (block.dvh.parts[partnum].length == 0)
98 | continue;
99 |
100 | if (partnum == 10)
101 | continue;
102 |
103 | p.start = grub_be_to_cpu32(block.dvh.parts[partnum].start);
104 | p.len = grub_be_to_cpu32(block.dvh.parts[partnum].length);
105 | p.number = p.index = partnum;
106 | if (hook(disk, &p, hook_data))
107 | break;
108 | }
109 |
110 | return grub_errno;
111 | }
112 |
113 | /* Partition map type. */
114 | static struct grub_partition_map grub_dvh_partition_map =
115 | {
116 | .name = "dvh",
117 | .iterate = dvh_partition_map_iterate,
118 | };
119 |
120 | GRUB_MOD_INIT(part_dvh)
121 | {
122 | grub_partition_map_register(&grub_dvh_partition_map);
123 | }
124 |
125 | GRUB_MOD_FINI(part_dvh)
126 | {
127 | grub_partition_map_unregister(&grub_dvh_partition_map);
128 | }
129 |
--------------------------------------------------------------------------------
/grub/partmap/plan.c:
--------------------------------------------------------------------------------
1 | /*
2 | * GRUB -- GRand Unified Bootloader
3 | * Copyright (C) 2010 Free Software Foundation, Inc.
4 | *
5 | * GRUB is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * GRUB is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with GRUB. If not, see .
17 | */
18 |
19 | #include
20 | #include
21 | #include
22 | #include
23 | #include
24 | #include
25 | #include
26 |
27 | GRUB_MOD_LICENSE("GPLv3+");
28 |
29 | static struct grub_partition_map grub_plan_partition_map;
30 |
31 | static grub_err_t
32 | plan_partition_map_iterate(grub_disk_t disk,
33 | grub_partition_iterate_hook_t hook,
34 | void* hook_data)
35 | {
36 | struct grub_partition p;
37 | int ptr = 0;
38 | grub_err_t err;
39 |
40 | p.partmap = &grub_plan_partition_map;
41 | p.msdostype = 0;
42 |
43 | for (p.number = 0; ; p.number++)
44 | {
45 | char sig[sizeof("part ") - 1];
46 | char c;
47 |
48 | p.offset = (ptr >> GRUB_DISK_SECTOR_BITS) + 1;
49 | p.index = ptr & (GRUB_DISK_SECTOR_SIZE - 1);
50 |
51 | err = grub_disk_read(disk, 1, ptr, sizeof(sig), sig);
52 | if (err)
53 | return err;
54 | if (grub_memcmp(sig, "part ", sizeof("part ") - 1) != 0)
55 | break;
56 | ptr += sizeof(sig);
57 | do
58 | {
59 | err = grub_disk_read(disk, 1, ptr, 1, &c);
60 | if (err)
61 | return err;
62 | ptr++;
63 | } while (grub_isdigit(c) || grub_isalpha(c));
64 | if (c != ' ')
65 | break;
66 | p.start = 0;
67 | while (1)
68 | {
69 | err = grub_disk_read(disk, 1, ptr, 1, &c);
70 | if (err)
71 | return err;
72 | ptr++;
73 | if (!grub_isdigit(c))
74 | break;
75 | p.start = p.start * 10 + (c - '0');
76 | }
77 | if (c != ' ')
78 | break;
79 | p.len = 0;
80 | while (1)
81 | {
82 | err = grub_disk_read(disk, 1, ptr, 1, &c);
83 | if (err)
84 | return err;
85 | ptr++;
86 | if (!grub_isdigit(c))
87 | break;
88 | p.len = p.len * 10 + (c - '0');
89 | }
90 | if (c != '\n')
91 | break;
92 | p.len -= p.start;
93 | if (hook(disk, &p, hook_data))
94 | return grub_errno;
95 | }
96 | if (p.number == 0)
97 | return grub_error(GRUB_ERR_BAD_PART_TABLE, "not a plan partition table");
98 |
99 | return GRUB_ERR_NONE;
100 | }
101 |
102 | /* Partition map type. */
103 | static struct grub_partition_map grub_plan_partition_map =
104 | {
105 | .name = "plan",
106 | .iterate = plan_partition_map_iterate,
107 | };
108 |
109 | GRUB_MOD_INIT(part_plan)
110 | {
111 | grub_partition_map_register(&grub_plan_partition_map);
112 | }
113 |
114 | GRUB_MOD_FINI(part_plan)
115 | {
116 | grub_partition_map_unregister(&grub_plan_partition_map);
117 | }
118 |
119 |
--------------------------------------------------------------------------------
/icons/arc.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/a1ive/NkArc/542297e75cfa4b0f53690decaa9b034922317ad6/icons/arc.png
--------------------------------------------------------------------------------
/icons/bin.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/a1ive/NkArc/542297e75cfa4b0f53690decaa9b034922317ad6/icons/bin.png
--------------------------------------------------------------------------------
/icons/cd.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/a1ive/NkArc/542297e75cfa4b0f53690decaa9b034922317ad6/icons/cd.png
--------------------------------------------------------------------------------
/icons/copy.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/a1ive/NkArc/542297e75cfa4b0f53690decaa9b034922317ad6/icons/copy.png
--------------------------------------------------------------------------------
/icons/dir.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/a1ive/NkArc/542297e75cfa4b0f53690decaa9b034922317ad6/icons/dir.png
--------------------------------------------------------------------------------
/icons/doc.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/a1ive/NkArc/542297e75cfa4b0f53690decaa9b034922317ad6/icons/doc.png
--------------------------------------------------------------------------------
/icons/empty.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/a1ive/NkArc/542297e75cfa4b0f53690decaa9b034922317ad6/icons/empty.png
--------------------------------------------------------------------------------
/icons/error.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/a1ive/NkArc/542297e75cfa4b0f53690decaa9b034922317ad6/icons/error.png
--------------------------------------------------------------------------------
/icons/fdd.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/a1ive/NkArc/542297e75cfa4b0f53690decaa9b034922317ad6/icons/fdd.png
--------------------------------------------------------------------------------
/icons/file.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/a1ive/NkArc/542297e75cfa4b0f53690decaa9b034922317ad6/icons/file.png
--------------------------------------------------------------------------------
/icons/font.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/a1ive/NkArc/542297e75cfa4b0f53690decaa9b034922317ad6/icons/font.png
--------------------------------------------------------------------------------
/icons/fw.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/a1ive/NkArc/542297e75cfa4b0f53690decaa9b034922317ad6/icons/fw.png
--------------------------------------------------------------------------------
/icons/hdd.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/a1ive/NkArc/542297e75cfa4b0f53690decaa9b034922317ad6/icons/hdd.png
--------------------------------------------------------------------------------
/icons/image.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/a1ive/NkArc/542297e75cfa4b0f53690decaa9b034922317ad6/icons/image.png
--------------------------------------------------------------------------------
/icons/info.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/a1ive/NkArc/542297e75cfa4b0f53690decaa9b034922317ad6/icons/info.png
--------------------------------------------------------------------------------
/icons/iso.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/a1ive/NkArc/542297e75cfa4b0f53690decaa9b034922317ad6/icons/iso.png
--------------------------------------------------------------------------------
/icons/link.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/a1ive/NkArc/542297e75cfa4b0f53690decaa9b034922317ad6/icons/link.png
--------------------------------------------------------------------------------
/icons/lock.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/a1ive/NkArc/542297e75cfa4b0f53690decaa9b034922317ad6/icons/lock.png
--------------------------------------------------------------------------------
/icons/music.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/a1ive/NkArc/542297e75cfa4b0f53690decaa9b034922317ad6/icons/music.png
--------------------------------------------------------------------------------
/icons/net.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/a1ive/NkArc/542297e75cfa4b0f53690decaa9b034922317ad6/icons/net.png
--------------------------------------------------------------------------------
/icons/ok.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/a1ive/NkArc/542297e75cfa4b0f53690decaa9b034922317ad6/icons/ok.png
--------------------------------------------------------------------------------
/icons/pc.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/a1ive/NkArc/542297e75cfa4b0f53690decaa9b034922317ad6/icons/pc.png
--------------------------------------------------------------------------------
/icons/pdf.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/a1ive/NkArc/542297e75cfa4b0f53690decaa9b034922317ad6/icons/pdf.png
--------------------------------------------------------------------------------
/icons/refresh.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/a1ive/NkArc/542297e75cfa4b0f53690decaa9b034922317ad6/icons/refresh.png
--------------------------------------------------------------------------------
/icons/rm.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/a1ive/NkArc/542297e75cfa4b0f53690decaa9b034922317ad6/icons/rm.png
--------------------------------------------------------------------------------
/icons/server.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/a1ive/NkArc/542297e75cfa4b0f53690decaa9b034922317ad6/icons/server.png
--------------------------------------------------------------------------------
/icons/settings.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/a1ive/NkArc/542297e75cfa4b0f53690decaa9b034922317ad6/icons/settings.png
--------------------------------------------------------------------------------
/icons/txt.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/a1ive/NkArc/542297e75cfa4b0f53690decaa9b034922317ad6/icons/txt.png
--------------------------------------------------------------------------------
/icons/unknown.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/a1ive/NkArc/542297e75cfa4b0f53690decaa9b034922317ad6/icons/unknown.png
--------------------------------------------------------------------------------
/icons/unlock.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/a1ive/NkArc/542297e75cfa4b0f53690decaa9b034922317ad6/icons/unlock.png
--------------------------------------------------------------------------------
/icons/up.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/a1ive/NkArc/542297e75cfa4b0f53690decaa9b034922317ad6/icons/up.png
--------------------------------------------------------------------------------
/icons/video.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/a1ive/NkArc/542297e75cfa4b0f53690decaa9b034922317ad6/icons/video.png
--------------------------------------------------------------------------------
/icons/win.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/a1ive/NkArc/542297e75cfa4b0f53690decaa9b034922317ad6/icons/win.png
--------------------------------------------------------------------------------
/include/config.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #pragma warning(disable: 4146) // "unary minus operator applied to unsigned type, result still unsigned"
4 | #pragma warning(disable: 4244) // "Conversion from X to Y, possible loss of data"
5 | #pragma warning(disable: 4267) // "Conversion from X to Y, possible loss of data"
6 | #pragma warning(disable: 4334) // "Result of 32-bit shift implicitly converted to 64 bits"
7 |
8 | #if defined(_M_X64) || defined(__x86_64__)
9 | #define GRUB_TARGET_CPU "x86_64"
10 | #elif defined(_M_IX86) || defined(__i386__)
11 | #define GRUB_TARGET_CPU "i386"
12 | #elif defined (_M_ARM) || defined(__arm__)
13 | #define GRUB_TARGET_CPU "arm"
14 | #elif defined (_M_ARM64) || defined(__aarch64__)
15 | #define GRUB_TARGET_CPU "arm64"
16 | #elif defined (_M_RISCV64) || (defined (__riscv) && (__riscv_xlen == 64))
17 | #define GRUB_TARGET_CPU "riscv64"
18 | #else
19 | #error Usupported architecture
20 | #endif
21 |
22 | #if !defined(_LARGEFILE_SOURCE)
23 | #define _LARGEFILE_SOURCE
24 | #endif
25 | #define _FILE_OFFSET_BITS 64
26 | #define PACKAGE_STRING "GRUB 2.0"
27 |
28 | #define GRUB_PLATFORM "emu"
29 | #define GRUB_MACHINE_EMU
30 | #define GRUB_KERNEL
31 |
32 | //#define GRUB_UTIL
33 |
34 | #define N_(x) x
35 | #define _(x) x
36 |
37 | #define __attribute__(x)
38 | #define __attribute(x)
39 |
40 | #define GRUB_MOD_LICENSE(x)
41 |
42 | #define GRUB_MOD_INIT(x) \
43 | void grub_module_init_##x(void)
44 |
45 | #define GRUB_MOD_FINI(x) \
46 | void grub_module_fini_##x(void)
47 |
48 | #if !defined(__CHAR_BIT__)
49 | #define __CHAR_BIT__ 8
50 | #endif
51 |
--------------------------------------------------------------------------------
/include/dl.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | void
4 | grub_module_init(void);
5 |
6 | void
7 | grub_module_fini(void);
8 |
--------------------------------------------------------------------------------
/include/grub/acorn_filecore.h:
--------------------------------------------------------------------------------
1 | /*
2 | * GRUB -- GRand Unified Bootloader
3 | * Copyright (C) 2004,2005,2007 Free Software Foundation, Inc.
4 | *
5 | * GRUB is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * GRUB is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with GRUB. If not, see .
17 | */
18 |
19 | #ifndef GRUB_ACORN_FILECORE_HEADER
20 | #define GRUB_ACORN_FILECORE_HEADER 1
21 |
22 | #include
23 |
24 | struct grub_filecore_disc_record
25 | {
26 | grub_uint8_t log2secsize;
27 | grub_uint8_t secspertrack;
28 | grub_uint8_t heads;
29 | grub_uint8_t density;
30 | grub_uint8_t idlen;
31 | grub_uint8_t log2bpmb;
32 | grub_uint8_t skew;
33 | grub_uint8_t bootoption;
34 | /* In bits 0-5, flags in bits 6 and 7. */
35 | grub_uint8_t lowsector;
36 | grub_uint8_t nzones;
37 | grub_uint16_t zone_spare;
38 | grub_uint32_t root_address;
39 | /* Disc size in bytes. */
40 | grub_uint32_t disc_size;
41 | grub_uint16_t cycle_id;
42 | char disc_name[10];
43 | /* Yes, it is 32 bits! */
44 | grub_uint32_t disctype;
45 | /* Most significant part of the disc size. */
46 | grub_uint32_t disc_size2;
47 | grub_uint8_t share_size;
48 | grub_uint8_t big_flag;
49 | grub_uint8_t reserved[18];
50 | };
51 |
52 | #endif /* ! GRUB_ACORN_FILECORE_HEADER */
53 |
--------------------------------------------------------------------------------
/include/grub/archelp.h:
--------------------------------------------------------------------------------
1 | /* archelp.h -- Archive helper functions */
2 | /*
3 | * GRUB -- GRand Unified Bootloader
4 | * Copyright (C) 2013 Free Software Foundation, Inc.
5 | *
6 | * GRUB is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * GRUB is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with GRUB. If not, see .
18 | */
19 |
20 | #ifndef GRUB_ARCHELP_HEADER
21 | #define GRUB_ARCHELP_HEADER 1
22 |
23 | #include
24 | #include
25 |
26 | typedef enum
27 | {
28 | GRUB_ARCHELP_ATTR_TYPE = 0160000,
29 | GRUB_ARCHELP_ATTR_FILE = 0100000,
30 | GRUB_ARCHELP_ATTR_DIR = 0040000,
31 | GRUB_ARCHELP_ATTR_LNK = 0120000,
32 | GRUB_ARCHELP_ATTR_NOTIME = 0x80000000,
33 | GRUB_ARCHELP_ATTR_END = 0xffffffff
34 | } grub_archelp_mode_t;
35 |
36 | struct grub_archelp_data;
37 |
38 | struct grub_archelp_ops
39 | {
40 | grub_err_t
41 | (*find_file) (struct grub_archelp_data* data, char** name,
42 | grub_int32_t* mtime,
43 | grub_archelp_mode_t* mode);
44 |
45 | char*
46 | (*get_link_target) (struct grub_archelp_data* data);
47 |
48 | void
49 | (*rewind) (struct grub_archelp_data* data);
50 | };
51 |
52 | grub_err_t
53 | grub_archelp_dir(struct grub_archelp_data* data,
54 | struct grub_archelp_ops* ops,
55 | const char* path_in,
56 | grub_fs_dir_hook_t hook, void* hook_data);
57 |
58 | grub_err_t
59 | grub_archelp_open(struct grub_archelp_data* data,
60 | struct grub_archelp_ops* ops,
61 | const char* name_in);
62 |
63 | #endif
64 |
--------------------------------------------------------------------------------
/include/grub/bsdlabel.h:
--------------------------------------------------------------------------------
1 | /*
2 | * GRUB -- GRand Unified Bootloader
3 | * Copyright (C) 1999,2000,2001,2002,2004,2007 Free Software Foundation, Inc.
4 | *
5 | * GRUB is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * GRUB is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with GRUB. If not, see .
17 | */
18 |
19 | #ifndef GRUB_BSDLABEL_PARTITION_HEADER
20 | #define GRUB_BSDLABEL_PARTITION_HEADER 1
21 |
22 | #include
23 |
24 | /* Constants for BSD disk label. */
25 | #define GRUB_PC_PARTITION_BSD_LABEL_SECTOR 1
26 | #define GRUB_PC_PARTITION_BSD_LABEL_MAGIC 0x82564557
27 |
28 | /* BSD partition types. */
29 | enum
30 | {
31 | GRUB_PC_PARTITION_BSD_TYPE_UNUSED = 0,
32 | GRUB_PC_PARTITION_BSD_TYPE_SWAP = 1,
33 | GRUB_PC_PARTITION_BSD_TYPE_V6 = 2,
34 | GRUB_PC_PARTITION_BSD_TYPE_V7 = 3,
35 | GRUB_PC_PARTITION_BSD_TYPE_SYSV = 4,
36 | GRUB_PC_PARTITION_BSD_TYPE_V71K = 5,
37 | GRUB_PC_PARTITION_BSD_TYPE_V8 = 6,
38 | GRUB_PC_PARTITION_BSD_TYPE_BSDFFS = 7,
39 | GRUB_PC_PARTITION_BSD_TYPE_MSDOS = 8,
40 | GRUB_PC_PARTITION_BSD_TYPE_BSDLFS = 9,
41 | GRUB_PC_PARTITION_BSD_TYPE_OTHER = 10,
42 | GRUB_PC_PARTITION_BSD_TYPE_HPFS = 11,
43 | GRUB_PC_PARTITION_BSD_TYPE_ISO9660 = 12,
44 | GRUB_PC_PARTITION_BSD_TYPE_BOOT = 13
45 | };
46 |
47 | /* FreeBSD-specific types. */
48 | enum
49 | {
50 | GRUB_PC_PARTITION_FREEBSD_TYPE_VINUM = 14,
51 | GRUB_PC_PARTITION_FREEBSD_TYPE_RAID = 15,
52 | GRUB_PC_PARTITION_FREEBSD_TYPE_JFS2 = 21
53 | };
54 |
55 | /* NetBSD-specific types. */
56 | enum
57 | {
58 | GRUB_PC_PARTITION_NETBSD_TYPE_ADOS = 14,
59 | GRUB_PC_PARTITION_NETBSD_TYPE_HFS = 15,
60 | GRUB_PC_PARTITION_NETBSD_TYPE_FILECORE = 16,
61 | GRUB_PC_PARTITION_NETBSD_TYPE_EXT2FS = 17,
62 | GRUB_PC_PARTITION_NETBSD_TYPE_NTFS = 18,
63 | GRUB_PC_PARTITION_NETBSD_TYPE_RAID = 19,
64 | GRUB_PC_PARTITION_NETBSD_TYPE_CCD = 20,
65 | GRUB_PC_PARTITION_NETBSD_TYPE_JFS2 = 21,
66 | GRUB_PC_PARTITION_NETBSD_TYPE_APPLEUFS = 22
67 | };
68 |
69 | /* OpenBSD-specific types. */
70 | enum
71 | {
72 | GRUB_PC_PARTITION_OPENBSD_TYPE_ADOS = 14,
73 | GRUB_PC_PARTITION_OPENBSD_TYPE_HFS = 15,
74 | GRUB_PC_PARTITION_OPENBSD_TYPE_FILECORE = 16,
75 | GRUB_PC_PARTITION_OPENBSD_TYPE_EXT2FS = 17,
76 | GRUB_PC_PARTITION_OPENBSD_TYPE_NTFS = 18,
77 | GRUB_PC_PARTITION_OPENBSD_TYPE_RAID = 19
78 | };
79 |
80 | #define GRUB_PC_PARTITION_BSD_LABEL_WHOLE_DISK_PARTITION 2
81 |
82 | /* The BSD partition entry. */
83 | GRUB_PACKED_START
84 | struct grub_partition_bsd_entry
85 | {
86 | grub_uint32_t size;
87 | grub_uint32_t offset;
88 | grub_uint32_t fragment_size;
89 | grub_uint8_t fs_type;
90 | grub_uint8_t fs_fragments;
91 | grub_uint16_t fs_cylinders;
92 | };
93 | GRUB_PACKED_END
94 |
95 | /* The BSD disk label. Only define members useful for GRUB. */
96 | GRUB_PACKED_START
97 | struct grub_partition_bsd_disk_label
98 | {
99 | grub_uint32_t magic;
100 | grub_uint16_t type;
101 | grub_uint8_t unused1[18];
102 | grub_uint8_t packname[16];
103 | grub_uint8_t unused2[92];
104 | grub_uint32_t magic2;
105 | grub_uint16_t checksum;
106 | grub_uint16_t num_partitions;
107 | grub_uint32_t boot_size;
108 | grub_uint32_t superblock_size;
109 | };
110 | GRUB_PACKED_END
111 |
112 | #endif /* ! GRUB_PC_PARTITION_HEADER */
113 |
--------------------------------------------------------------------------------
/include/grub/btrfs.h:
--------------------------------------------------------------------------------
1 | /* btrfs.c - B-tree file system. */
2 | /*
3 | * GRUB -- GRand Unified Bootloader
4 | * Copyright (C) 2010,2011,2012,2013 Free Software Foundation, Inc.
5 | *
6 | * GRUB is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * GRUB is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with GRUB. If not, see .
18 | */
19 |
20 | #ifndef GRUB_BTRFS_H
21 | #define GRUB_BTRFS_H 1
22 |
23 | #include
24 |
25 | enum
26 | {
27 | GRUB_BTRFS_ITEM_TYPE_INODE_ITEM = 0x01,
28 | GRUB_BTRFS_ITEM_TYPE_INODE_REF = 0x0c,
29 | GRUB_BTRFS_ITEM_TYPE_DIR_ITEM = 0x54,
30 | GRUB_BTRFS_ITEM_TYPE_EXTENT_ITEM = 0x6c,
31 | GRUB_BTRFS_ITEM_TYPE_ROOT_ITEM = 0x84,
32 | GRUB_BTRFS_ITEM_TYPE_ROOT_BACKREF = 0x90,
33 | GRUB_BTRFS_ITEM_TYPE_DEVICE = 0xd8,
34 | GRUB_BTRFS_ITEM_TYPE_CHUNK = 0xe4
35 | };
36 |
37 | enum
38 | {
39 | GRUB_BTRFS_ROOT_VOL_OBJECTID = 5,
40 | GRUB_BTRFS_TREE_ROOT_OBJECTID = 0x100,
41 | };
42 |
43 | struct grub_btrfs_root_item
44 | {
45 | grub_uint8_t dummy[0xb0];
46 | grub_uint64_t tree;
47 | grub_uint64_t inode;
48 | };
49 |
50 | GRUB_PACKED_START
51 | struct grub_btrfs_key
52 | {
53 | grub_uint64_t object_id;
54 | grub_uint8_t type;
55 | grub_uint64_t offset;
56 | };
57 | GRUB_PACKED_END
58 |
59 | struct grub_btrfs_root_backref
60 | {
61 | grub_uint64_t inode_id;
62 | grub_uint64_t seqnr;
63 | grub_uint16_t n;
64 | char name[0];
65 | };
66 |
67 | struct grub_btrfs_inode_ref
68 | {
69 | grub_uint64_t idxid;
70 | grub_uint16_t n;
71 | char name[0];
72 | };
73 |
74 | #endif
75 |
--------------------------------------------------------------------------------
/include/grub/deflate.h:
--------------------------------------------------------------------------------
1 | /*
2 | * GRUB -- GRand Unified Bootloader
3 | * Copyright (C) 2010 Free Software Foundation, Inc.
4 | *
5 | * GRUB is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * GRUB is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with GRUB. If not, see .
17 | */
18 |
19 | #ifndef GRUB_DEFLATE_HEADER
20 | #define GRUB_DEFLATE_HEADER 1
21 |
22 | #include
23 |
24 | grub_ssize_t
25 | grub_zlib_decompress(char* inbuf, grub_size_t insize, grub_off_t off,
26 | char* outbuf, grub_size_t outsize);
27 |
28 | grub_ssize_t
29 | grub_deflate_decompress(char* inbuf, grub_size_t insize, grub_off_t off,
30 | char* outbuf, grub_size_t outsize);
31 |
32 | #endif
33 |
--------------------------------------------------------------------------------
/include/grub/efi.h:
--------------------------------------------------------------------------------
1 | /*
2 | * NkArc
3 | * Copyright (C) 2023 A1ive
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #ifndef GRUB_EFI_HEADER
20 | #define GRUB_EFI_HEADER 1
21 |
22 | #include
23 |
24 | #define EFI_VARIABLE_NON_VOLATILE 0x00000001
25 | #define EFI_VARIABLE_BOOTSERVICE_ACCESS 0x00000002
26 | #define EFI_VARIABLE_RUNTIME_ACCESS 0x00000004
27 | #define EFI_VARIABLE_HARDWARE_ERROR_RECORD 0x00000008
28 | #define EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS 0x00000010
29 | #define EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS 0x00000020
30 | #define EFI_VARIABLE_APPEND_WRITE 0x00000040
31 | #define EFI_VARIABLE_ENHANCED_AUTHENTICATED_ACCESS 0x00000080
32 |
33 | typedef struct _VARIABLE_NAME
34 | {
35 | ULONG NextEntryOffset;
36 | GUID VendorGuid;
37 | WCHAR Name[ANYSIZE_ARRAY];
38 | } VARIABLE_NAME, *PVARIABLE_NAME;
39 |
40 | GUID EFI_GV_GUID;
41 | GUID EFI_EMPTY_GUID;
42 |
43 | DWORD
44 | grub_efi_get_variable(LPCWSTR name, LPGUID guid,
45 | PVOID buf, DWORD size, PDWORD attr);
46 |
47 | VOID*
48 | grub_efi_get_variable_alloc(const char* name, LPGUID guid, PDWORD size, PDWORD attr);
49 |
50 | PVARIABLE_NAME
51 | grub_efi_enum_variable(PULONG size);
52 |
53 | BOOL
54 | grub_is_efi_boot(VOID);
55 |
56 | #endif /* ! GRUB_EFI_HEADER */
57 |
--------------------------------------------------------------------------------
/include/grub/err.h:
--------------------------------------------------------------------------------
1 | /* err.h - error numbers and prototypes */
2 | /*
3 | * GRUB -- GRand Unified Bootloader
4 | * Copyright (C) 2002,2005,2007,2008 Free Software Foundation, Inc.
5 | *
6 | * GRUB is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * GRUB is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with GRUB. If not, see .
18 | */
19 |
20 | #ifndef GRUB_ERR_HEADER
21 | #define GRUB_ERR_HEADER 1
22 |
23 | #include
24 | #include
25 |
26 | #define GRUB_MAX_ERRMSG 256
27 |
28 | typedef enum
29 | {
30 | GRUB_ERR_NONE = 0,
31 | GRUB_ERR_TEST_FAILURE,
32 | GRUB_ERR_BAD_MODULE,
33 | GRUB_ERR_OUT_OF_MEMORY,
34 | GRUB_ERR_BAD_FILE_TYPE,
35 | GRUB_ERR_FILE_NOT_FOUND,
36 | GRUB_ERR_FILE_READ_ERROR,
37 | GRUB_ERR_BAD_FILENAME,
38 | GRUB_ERR_UNKNOWN_FS,
39 | GRUB_ERR_BAD_FS,
40 | GRUB_ERR_BAD_NUMBER,
41 | GRUB_ERR_OUT_OF_RANGE,
42 | GRUB_ERR_UNKNOWN_DEVICE,
43 | GRUB_ERR_BAD_DEVICE,
44 | GRUB_ERR_READ_ERROR,
45 | GRUB_ERR_WRITE_ERROR,
46 | GRUB_ERR_UNKNOWN_COMMAND,
47 | GRUB_ERR_INVALID_COMMAND,
48 | GRUB_ERR_BAD_ARGUMENT,
49 | GRUB_ERR_BAD_PART_TABLE,
50 | GRUB_ERR_UNKNOWN_OS,
51 | GRUB_ERR_BAD_OS,
52 | GRUB_ERR_NO_KERNEL,
53 | GRUB_ERR_BAD_FONT,
54 | GRUB_ERR_NOT_IMPLEMENTED_YET,
55 | GRUB_ERR_SYMLINK_LOOP,
56 | GRUB_ERR_BAD_COMPRESSED_DATA,
57 | GRUB_ERR_MENU,
58 | GRUB_ERR_TIMEOUT,
59 | GRUB_ERR_IO,
60 | GRUB_ERR_ACCESS_DENIED,
61 | GRUB_ERR_EXTRACTOR,
62 | GRUB_ERR_NET_BAD_ADDRESS,
63 | GRUB_ERR_NET_ROUTE_LOOP,
64 | GRUB_ERR_NET_NO_ROUTE,
65 | GRUB_ERR_NET_NO_ANSWER,
66 | GRUB_ERR_NET_NO_CARD,
67 | GRUB_ERR_WAIT,
68 | GRUB_ERR_BUG,
69 | GRUB_ERR_NET_PORT_CLOSED,
70 | GRUB_ERR_NET_INVALID_RESPONSE,
71 | GRUB_ERR_NET_UNKNOWN_ERROR,
72 | GRUB_ERR_NET_PACKET_TOO_BIG,
73 | GRUB_ERR_NET_NO_DOMAIN,
74 | GRUB_ERR_EOF,
75 | GRUB_ERR_BAD_SIGNATURE,
76 | GRUB_ERR_BAD_FIRMWARE
77 | }
78 | grub_err_t;
79 |
80 | struct grub_error_saved
81 | {
82 | grub_err_t grub_errno;
83 | char errmsg[GRUB_MAX_ERRMSG];
84 | };
85 |
86 | extern grub_err_t EXPORT_VAR(grub_errno);
87 | extern char EXPORT_VAR(grub_errmsg)[GRUB_MAX_ERRMSG];
88 |
89 | grub_err_t EXPORT_FUNC(grub_error) (grub_err_t n, _Printf_format_string_ const char *fmt, ...);
90 | _Noreturn
91 | void EXPORT_FUNC(grub_fatal) (_Printf_format_string_ const char *fmt, ...);
92 | void EXPORT_FUNC(grub_error_push) (void);
93 | int EXPORT_FUNC(grub_error_pop) (void);
94 | void EXPORT_FUNC(grub_print_error) (void);
95 | extern int EXPORT_VAR(grub_err_printed_errors);
96 | int grub_err_printf (_Printf_format_string_ const char *fmt, ...);
97 |
98 | #endif /* ! GRUB_ERR_HEADER */
99 |
--------------------------------------------------------------------------------
/include/grub/exfat.h:
--------------------------------------------------------------------------------
1 | /*
2 | * GRUB -- GRand Unified Bootloader
3 | * Copyright (C) 2013 Free Software Foundation, Inc.
4 | *
5 | * GRUB is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * GRUB is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with GRUB. If not, see .
17 | */
18 |
19 | #ifndef GRUB_EXFAT_H
20 | #define GRUB_EXFAT_H 1
21 |
22 | #include
23 |
24 | GRUB_PACKED_START
25 | struct grub_exfat_bpb
26 | {
27 | grub_uint8_t jmp_boot[3];
28 | grub_uint8_t oem_name[8];
29 | grub_uint8_t mbz[53];
30 | grub_uint64_t num_hidden_sectors;
31 | grub_uint64_t num_total_sectors;
32 | grub_uint32_t num_reserved_sectors;
33 | grub_uint32_t sectors_per_fat;
34 | grub_uint32_t cluster_offset;
35 | grub_uint32_t cluster_count;
36 | grub_uint32_t root_cluster;
37 | grub_uint32_t num_serial;
38 | grub_uint16_t fs_revision;
39 | grub_uint16_t volume_flags;
40 | grub_uint8_t bytes_per_sector_shift;
41 | grub_uint8_t sectors_per_cluster_shift;
42 | grub_uint8_t num_fats;
43 | grub_uint8_t num_ph_drive;
44 | grub_uint8_t reserved[8];
45 | };
46 | GRUB_PACKED_END
47 |
48 | #ifdef GRUB_UTIL
49 | #include
50 |
51 | grub_disk_addr_t
52 | grub_exfat_get_cluster_sector(grub_disk_t disk, grub_uint64_t* sec_per_lcn);
53 | #endif
54 |
55 | #endif
56 |
--------------------------------------------------------------------------------
/include/grub/fat.h:
--------------------------------------------------------------------------------
1 | /*
2 | * GRUB -- GRand Unified Bootloader
3 | * Copyright (C) 2000,2001,2002,2003,2004,2005,2007,2008,2009 Free Software Foundation, Inc.
4 | *
5 | * GRUB is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * GRUB is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with GRUB. If not, see .
17 | */
18 |
19 | #ifndef GRUB_FAT_H
20 | #define GRUB_FAT_H 1
21 |
22 | #include
23 |
24 | GRUB_PACKED_START
25 | struct grub_fat_bpb
26 | {
27 | grub_uint8_t jmp_boot[3];
28 | grub_uint8_t oem_name[8];
29 | grub_uint16_t bytes_per_sector;
30 | grub_uint8_t sectors_per_cluster;
31 | grub_uint16_t num_reserved_sectors;
32 | grub_uint8_t num_fats; /* 0x10 */
33 | grub_uint16_t num_root_entries;
34 | grub_uint16_t num_total_sectors_16;
35 | grub_uint8_t media; /* 0x15 */
36 | grub_uint16_t sectors_per_fat_16;
37 | grub_uint16_t sectors_per_track; /* 0x18 */
38 | grub_uint16_t num_heads; /* 0x1A */
39 | grub_uint32_t num_hidden_sectors; /* 0x1C */
40 | grub_uint32_t num_total_sectors_32; /* 0x20 */
41 | GRUB_PACKED_START
42 | union
43 | {
44 | GRUB_PACKED_START
45 | struct
46 | {
47 | grub_uint8_t num_ph_drive;
48 | grub_uint8_t reserved;
49 | grub_uint8_t boot_sig;
50 | grub_uint32_t num_serial;
51 | grub_uint8_t label[11];
52 | grub_uint8_t fstype[8];
53 | } fat12_or_fat16;
54 | GRUB_PACKED_END
55 | GRUB_PACKED_START
56 | struct
57 | {
58 | grub_uint32_t sectors_per_fat_32;
59 | grub_uint16_t extended_flags;
60 | grub_uint16_t fs_version;
61 | grub_uint32_t root_cluster;
62 | grub_uint16_t fs_info;
63 | grub_uint16_t backup_boot_sector;
64 | grub_uint8_t reserved[12];
65 | grub_uint8_t num_ph_drive;
66 | grub_uint8_t reserved1;
67 | grub_uint8_t boot_sig;
68 | grub_uint32_t num_serial;
69 | grub_uint8_t label[11];
70 | grub_uint8_t fstype[8];
71 | } fat32;
72 | GRUB_PACKED_END
73 | } version_specific;
74 | GRUB_PACKED_END
75 | };
76 | GRUB_PACKED_END
77 |
78 | #ifdef GRUB_UTIL
79 | #include
80 |
81 | grub_disk_addr_t
82 | grub_fat_get_cluster_sector(grub_disk_t disk, grub_uint64_t* sec_per_lcn);
83 | #endif
84 |
85 | #endif
86 |
--------------------------------------------------------------------------------
/include/grub/fbfs.h:
--------------------------------------------------------------------------------
1 | /*
2 | * NkArc
3 | * Copyright (C) 2023 A1ive
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #ifndef _FBFS_HEADER
20 | #define _FBFS_HEADER 1
21 |
22 | #include
23 |
24 | #define FB_MAGIC "FBBF"
25 | #define FB_MAGIC_LONG 0x46424246
26 |
27 | #define FB_AR_MAGIC "FBAR"
28 | #define FB_AR_MAGIC_LONG 0x52414246
29 |
30 | GRUB_PACKED_START
31 | struct fb_mbr
32 | {
33 | grub_uint8_t jmp_code;
34 | grub_uint8_t jmp_ofs;
35 | grub_uint8_t boot_code[0x1ab];
36 | grub_uint8_t max_sec; /* 0x1ad */
37 | grub_uint16_t lba; /* 0x1ae */
38 | grub_uint8_t spt; /* 0x1b0 */
39 | grub_uint8_t heads; /* 0x1b1 */
40 | grub_uint16_t boot_base; /* 0x1b2 */
41 | grub_uint32_t fb_magic; /* 0x1b4 */
42 | grub_uint8_t mbr_table[0x46]; /* 0x1b8 */
43 | grub_uint16_t end_magic; /* 0x1fe */
44 | };
45 | GRUB_PACKED_END
46 |
47 | GRUB_PACKED_START
48 | struct fb_data
49 | {
50 | grub_uint16_t boot_size; /* 0x200 */
51 | grub_uint16_t flags; /* 0x202 */
52 | grub_uint8_t ver_major; /* 0x204 */
53 | grub_uint8_t ver_minor; /* 0x205 */
54 | grub_uint16_t list_used; /* 0x206 */
55 | grub_uint16_t list_size; /* 0x208 */
56 | grub_uint16_t pri_size; /* 0x20a */
57 | grub_uint32_t ext_size; /* 0x20c */
58 | };
59 | GRUB_PACKED_END
60 |
61 | GRUB_PACKED_START
62 | struct fb_ar_data
63 | {
64 | grub_uint32_t ar_magic; /* 0x200 */
65 | grub_uint8_t ver_major; /* 0x204 */
66 | grub_uint8_t ver_minor; /* 0x205 */
67 | grub_uint16_t list_used; /* 0x206 */
68 | grub_uint16_t list_size; /* 0x208 */
69 | grub_uint16_t pri_size; /* 0x20a */
70 | grub_uint32_t ext_size; /* 0x20c */
71 | };
72 | GRUB_PACKED_END
73 |
74 | GRUB_PACKED_START
75 | struct fbm_file
76 | {
77 | grub_uint8_t size;
78 | grub_uint8_t flag;
79 | grub_uint32_t data_start;
80 | grub_uint32_t data_size;
81 | grub_uint32_t data_time;
82 | char name[1];
83 | };
84 | GRUB_PACKED_END
85 |
86 | #endif
87 |
--------------------------------------------------------------------------------
/include/grub/fs.h:
--------------------------------------------------------------------------------
1 | /* fs.h - filesystem manager */
2 | /*
3 | * GRUB -- GRand Unified Bootloader
4 | * Copyright (C) 2002,2003,2004,2007,2008,2009 Free Software Foundation, Inc.
5 | *
6 | * GRUB is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * GRUB is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with GRUB. If not, see .
18 | */
19 |
20 | #ifndef GRUB_FS_HEADER
21 | #define GRUB_FS_HEADER 1
22 |
23 | #include
24 | #include
25 | #include
26 | #include
27 |
28 | /* Forward declaration is required, because of mutual reference. */
29 | struct grub_file;
30 |
31 | struct grub_dirhook_info
32 | {
33 | unsigned dir : 1;
34 | unsigned mtimeset : 1;
35 | unsigned case_insensitive : 1;
36 | unsigned inodeset : 1;
37 | unsigned symlink : 1;
38 | grub_int64_t mtime;
39 | grub_uint64_t inode;
40 | };
41 |
42 | typedef int (*grub_fs_dir_hook_t) (const char* filename,
43 | const struct grub_dirhook_info* info,
44 | void* data);
45 |
46 | /* Filesystem descriptor. */
47 | struct grub_fs
48 | {
49 | /* The next filesystem. */
50 | struct grub_fs* next;
51 | struct grub_fs** prev;
52 |
53 | /* My name. */
54 | const char* name;
55 |
56 | /* Call HOOK with each file under DIR. */
57 | grub_err_t(*fs_dir) (grub_disk_t disk, const char* path,
58 | grub_fs_dir_hook_t hook, void* hook_data);
59 |
60 | /* Open a file named NAME and initialize FILE. */
61 | grub_err_t(*fs_open) (struct grub_file* file, const char* name);
62 |
63 | /* Read LEN bytes data from FILE into BUF. */
64 | grub_ssize_t(*fs_read) (struct grub_file* file, char* buf, grub_size_t len);
65 |
66 | /* Close the file FILE. */
67 | grub_err_t(*fs_close) (struct grub_file* file);
68 |
69 | /* Return the label of the disk DISK in LABEL. The label is
70 | returned in a grub_malloc'ed buffer and should be freed by the
71 | caller. */
72 | grub_err_t(*fs_label) (grub_disk_t disk, char** label);
73 |
74 | /* Return the uuid of the disk DISK in UUID. The uuid is
75 | returned in a grub_malloc'ed buffer and should be freed by the
76 | caller. */
77 | grub_err_t(*fs_uuid) (grub_disk_t disk, char** uuid);
78 |
79 | /* Get writing time of filesystem. */
80 | grub_err_t(*fs_mtime) (grub_disk_t disk, grub_int64_t* timebuf);
81 | };
82 | typedef struct grub_fs* grub_fs_t;
83 |
84 | /* This is special, because block lists are not files in usual sense. */
85 | extern struct grub_fs grub_fs_blocklist;
86 |
87 | extern grub_fs_t EXPORT_VAR(grub_fs_list);
88 |
89 | static inline void
90 | grub_fs_register(grub_fs_t fs)
91 | {
92 | grub_list_push(GRUB_AS_LIST_P(&grub_fs_list), GRUB_AS_LIST(fs));
93 | }
94 |
95 | static inline void
96 | grub_fs_unregister(grub_fs_t fs)
97 | {
98 | grub_list_remove(GRUB_AS_LIST(fs));
99 | }
100 |
101 | #define FOR_FILESYSTEMS(var) FOR_LIST_ELEMENTS((var), (grub_fs_list))
102 |
103 | grub_fs_t EXPORT_FUNC(grub_fs_probe) (grub_disk_t disk);
104 |
105 | #endif /* ! GRUB_FS_HEADER */
106 |
--------------------------------------------------------------------------------
/include/grub/fshelp.h:
--------------------------------------------------------------------------------
1 | /* fshelp.h -- Filesystem helper functions */
2 | /*
3 | * GRUB -- GRand Unified Bootloader
4 | * Copyright (C) 2004,2005,2006,2007,2008 Free Software Foundation, Inc.
5 | *
6 | * GRUB is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * GRUB is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with GRUB. If not, see .
18 | */
19 |
20 | #ifndef GRUB_FSHELP_HEADER
21 | #define GRUB_FSHELP_HEADER 1
22 |
23 | #include
24 | #include
25 | #include
26 | #include
27 |
28 | typedef struct grub_fshelp_node* grub_fshelp_node_t;
29 |
30 | #define GRUB_FSHELP_CASE_INSENSITIVE 0x100
31 | #define GRUB_FSHELP_TYPE_MASK 0xff
32 | #define GRUB_FSHELP_FLAGS_MASK 0x100
33 |
34 | enum grub_fshelp_filetype
35 | {
36 | GRUB_FSHELP_UNKNOWN,
37 | GRUB_FSHELP_REG,
38 | GRUB_FSHELP_DIR,
39 | GRUB_FSHELP_SYMLINK
40 | };
41 |
42 | typedef int (*grub_fshelp_iterate_dir_hook_t) (const char* filename,
43 | enum grub_fshelp_filetype filetype,
44 | grub_fshelp_node_t node,
45 | void* data);
46 |
47 | /* Lookup the node PATH. The node ROOTNODE describes the root of the
48 | directory tree. The node found is returned in FOUNDNODE, which is
49 | either a ROOTNODE or a new malloc'ed node. ITERATE_DIR is used to
50 | iterate over all directory entries in the current node.
51 | READ_SYMLINK is used to read the symlink if a node is a symlink.
52 | EXPECTTYPE is the type node that is expected by the called, an
53 | error is generated if the node is not of the expected type. */
54 | grub_err_t
55 | EXPORT_FUNC(grub_fshelp_find_file) (const char* path,
56 | grub_fshelp_node_t rootnode,
57 | grub_fshelp_node_t* foundnode,
58 | int (*iterate_dir) (grub_fshelp_node_t dir,
59 | grub_fshelp_iterate_dir_hook_t hook,
60 | void* hook_data),
61 | char* (*read_symlink) (grub_fshelp_node_t node),
62 | enum grub_fshelp_filetype expect);
63 |
64 |
65 | grub_err_t
66 | EXPORT_FUNC(grub_fshelp_find_file_lookup) (const char* path,
67 | grub_fshelp_node_t rootnode,
68 | grub_fshelp_node_t* foundnode,
69 | grub_err_t(*lookup_file) (grub_fshelp_node_t dir,
70 | const char* name,
71 | grub_fshelp_node_t* foundnode,
72 | enum grub_fshelp_filetype* foundtype),
73 | char* (*read_symlink) (grub_fshelp_node_t node),
74 | enum grub_fshelp_filetype expect);
75 |
76 | /* Read LEN bytes from the file NODE on disk DISK into the buffer BUF,
77 | beginning with the block POS. READ_HOOK should be set before
78 | reading a block from the file. GET_BLOCK is used to translate file
79 | blocks to disk blocks. The file is FILESIZE bytes big and the
80 | blocks have a size of LOG2BLOCKSIZE (in log2). */
81 | grub_ssize_t
82 | EXPORT_FUNC(grub_fshelp_read_file) (grub_disk_t disk, grub_fshelp_node_t node,
83 | grub_disk_read_hook_t read_hook,
84 | void* read_hook_data,
85 | grub_off_t pos, grub_size_t len, char* buf,
86 | grub_disk_addr_t(*get_block) (grub_fshelp_node_t node,
87 | grub_disk_addr_t block),
88 | grub_off_t filesize, int log2blocksize,
89 | grub_disk_addr_t blocks_start);
90 |
91 | #endif /* ! GRUB_FSHELP_HEADER */
92 |
--------------------------------------------------------------------------------
/include/grub/gpt_partition.h:
--------------------------------------------------------------------------------
1 | /*
2 | * GRUB -- GRand Unified Bootloader
3 | * Copyright (C) 2002,2005,2006,2007,2008 Free Software Foundation, Inc.
4 | *
5 | * GRUB is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * GRUB is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with GRUB. If not, see .
17 | */
18 |
19 | #ifndef GRUB_GPT_PARTITION_HEADER
20 | #define GRUB_GPT_PARTITION_HEADER 1
21 |
22 | #include
23 | #include
24 | #include
25 |
26 | #define GRUB_GPT_PARTITION_TYPE_EMPTY \
27 | { 0x0, 0x0, 0x0, \
28 | { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 } \
29 | }
30 |
31 | #define GRUB_GPT_PARTITION_TYPE_BIOS_BOOT \
32 | { grub_cpu_to_le32_compile_time (0x21686148), \
33 | grub_cpu_to_le16_compile_time (0x6449), \
34 | grub_cpu_to_le16_compile_time (0x6e6f), \
35 | { 0x74, 0x4e, 0x65, 0x65, 0x64, 0x45, 0x46, 0x49 } \
36 | }
37 |
38 | #define GRUB_GPT_PARTITION_TYPE_LDM \
39 | { grub_cpu_to_le32_compile_time (0x5808C8AAU),\
40 | grub_cpu_to_le16_compile_time (0x7E8F), \
41 | grub_cpu_to_le16_compile_time (0x42E0), \
42 | { 0x85, 0xD2, 0xE1, 0xE9, 0x04, 0x34, 0xCF, 0xB3 } \
43 | }
44 |
45 | GRUB_PACKED_START
46 | struct grub_gpt_header
47 | {
48 | grub_uint8_t magic[8];
49 | grub_uint32_t version;
50 | grub_uint32_t headersize;
51 | grub_uint32_t crc32;
52 | grub_uint32_t unused1;
53 | grub_uint64_t primary;
54 | grub_uint64_t backup;
55 | grub_uint64_t start;
56 | grub_uint64_t end;
57 | grub_uint8_t guid[16];
58 | grub_uint64_t partitions;
59 | grub_uint32_t maxpart;
60 | grub_uint32_t partentry_size;
61 | grub_uint32_t partentry_crc32;
62 | };
63 | GRUB_PACKED_END
64 |
65 | struct grub_gpt_partentry
66 | {
67 | grub_guid_t type;
68 | grub_guid_t guid;
69 | grub_uint64_t start;
70 | grub_uint64_t end;
71 | grub_uint64_t attrib;
72 | char name[72];
73 | };
74 |
75 | grub_err_t
76 | grub_gpt_partition_map_iterate(grub_disk_t disk,
77 | grub_partition_iterate_hook_t hook,
78 | void* hook_data);
79 |
80 | #endif /* ! GRUB_GPT_PARTITION_HEADER */
81 |
--------------------------------------------------------------------------------
/include/grub/hfs.h:
--------------------------------------------------------------------------------
1 | /*
2 | * GRUB -- GRand Unified Bootloader
3 | * Copyright (C) 2005,2006,2007 Free Software Foundation, Inc.
4 | *
5 | * GRUB is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * GRUB is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with GRUB. If not, see .
17 | */
18 |
19 | #ifndef GRUB_HFS_HEADER
20 | #define GRUB_HFS_HEADER 1
21 |
22 | #include
23 |
24 | #define GRUB_HFS_MAGIC 0x4244
25 |
26 | /* A single extent. A file consists of one or more extents. */
27 | GRUB_PACKED_START
28 | struct grub_hfs_extent
29 | {
30 | /* The first physical block. */
31 | grub_uint16_t first_block;
32 | grub_uint16_t count;
33 | };
34 | GRUB_PACKED_END
35 |
36 | /* HFS stores extents in groups of 3. */
37 | typedef struct grub_hfs_extent grub_hfs_datarecord_t[3];
38 |
39 | /* The HFS superblock (The official name is `Master Directory
40 | Block'). */
41 | GRUB_PACKED_START
42 | struct grub_hfs_sblock
43 | {
44 | grub_uint16_t magic;
45 | grub_uint32_t ctime;
46 | grub_uint32_t mtime;
47 | grub_uint8_t unused[10];
48 | grub_uint32_t blksz;
49 | grub_uint8_t unused2[4];
50 | grub_uint16_t first_block;
51 | grub_uint8_t unused4[6];
52 |
53 | /* A pascal style string that holds the volumename. */
54 | grub_uint8_t volname[28];
55 |
56 | grub_uint8_t unused5[28];
57 |
58 | grub_uint32_t ppc_bootdir;
59 | grub_uint32_t intel_bootfile;
60 | /* Folder opened when disk is mounted. Unused by GRUB. */
61 | grub_uint32_t showfolder;
62 | grub_uint32_t os9folder;
63 | grub_uint8_t unused6[4];
64 | grub_uint32_t osxfolder;
65 |
66 | grub_uint64_t num_serial;
67 | grub_uint16_t embed_sig;
68 | struct grub_hfs_extent embed_extent;
69 | grub_uint8_t unused7[4];
70 | grub_hfs_datarecord_t extent_recs;
71 | grub_uint32_t catalog_size;
72 | grub_hfs_datarecord_t catalog_recs;
73 | };
74 | GRUB_PACKED_END
75 |
76 | #endif /* ! GRUB_HFS_HEADER */
77 |
--------------------------------------------------------------------------------
/include/grub/lib/crc.h:
--------------------------------------------------------------------------------
1 | /* crc.h - prototypes for crc */
2 | /*
3 | * GRUB -- GRand Unified Bootloader
4 | * Copyright (C) 2008 Free Software Foundation, Inc.
5 | *
6 | * GRUB is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * GRUB is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with GRUB. If not, see .
18 | */
19 |
20 | #ifndef GRUB_CRC_H
21 | #define GRUB_CRC_H 1
22 |
23 | #include
24 |
25 | grub_uint32_t grub_getcrc32c(grub_uint32_t crc, const void* buf, int size);
26 |
27 | #endif /* ! GRUB_CRC_H */
28 |
--------------------------------------------------------------------------------
/include/grub/list.h:
--------------------------------------------------------------------------------
1 | /* list.h - header for grub list */
2 | /*
3 | * GRUB -- GRand Unified Bootloader
4 | * Copyright (C) 2009 Free Software Foundation, Inc.
5 | *
6 | * GRUB is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * GRUB is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with GRUB. If not, see .
18 | */
19 |
20 | #ifndef GRUB_LIST_HEADER
21 | #define GRUB_LIST_HEADER 1
22 |
23 | #include
24 | #include
25 |
26 | struct grub_list
27 | {
28 | struct grub_list *next;
29 | struct grub_list **prev;
30 | };
31 | typedef struct grub_list *grub_list_t;
32 |
33 | void EXPORT_FUNC(grub_list_push) (grub_list_t *head, grub_list_t item);
34 | void EXPORT_FUNC(grub_list_remove) (grub_list_t item);
35 |
36 | #define FOR_LIST_ELEMENTS(var, list) for ((var) = (list); (var); (var) = (var)->next)
37 | #define FOR_LIST_ELEMENTS_NEXT(var, list) for ((var) = (var)->next; (var); (var) = (var)->next)
38 | #define FOR_LIST_ELEMENTS_SAFE(var, nxt, list) for ((var) = (list), (nxt) = ((var) ? (var)->next : 0); (var); (var) = (nxt), ((nxt) = (var) ? (var)->next : 0))
39 |
40 | static inline void *
41 | grub_bad_type_cast_real (int line, const char *file)
42 | {
43 | grub_fatal ("error:%s:%u: bad type cast between incompatible grub types",
44 | file, line);
45 | return (void*)0;
46 | }
47 |
48 | #define grub_bad_type_cast() grub_bad_type_cast_real(__LINE__, __FILE__)
49 |
50 | #define GRUB_FIELD_MATCH(ptr, type, field) \
51 | ((char *) &(ptr)->field == (char *) &((type) (ptr))->field)
52 |
53 | #define GRUB_AS_LIST(ptr) \
54 | (GRUB_FIELD_MATCH (ptr, grub_list_t, next) && GRUB_FIELD_MATCH (ptr, grub_list_t, prev) ? \
55 | (grub_list_t) ptr : (grub_list_t) grub_bad_type_cast ())
56 |
57 | #define GRUB_AS_LIST_P(pptr) \
58 | (GRUB_FIELD_MATCH (*pptr, grub_list_t, next) && GRUB_FIELD_MATCH (*pptr, grub_list_t, prev) ? \
59 | (grub_list_t *) (void *) pptr : (grub_list_t *) grub_bad_type_cast ())
60 |
61 | struct grub_named_list
62 | {
63 | struct grub_named_list *next;
64 | struct grub_named_list **prev;
65 | char *name;
66 | };
67 | typedef struct grub_named_list *grub_named_list_t;
68 |
69 | void * EXPORT_FUNC(grub_named_list_find) (grub_named_list_t head,
70 | const char *name);
71 |
72 | #define GRUB_AS_NAMED_LIST(ptr) \
73 | ((GRUB_FIELD_MATCH (ptr, grub_named_list_t, next) \
74 | && GRUB_FIELD_MATCH (ptr, grub_named_list_t, prev) \
75 | && GRUB_FIELD_MATCH (ptr, grub_named_list_t, name))? \
76 | (grub_named_list_t) ptr : (grub_named_list_t) grub_bad_type_cast ())
77 |
78 | #define GRUB_AS_NAMED_LIST_P(pptr) \
79 | ((GRUB_FIELD_MATCH (*pptr, grub_named_list_t, next) \
80 | && GRUB_FIELD_MATCH (*pptr, grub_named_list_t, prev) \
81 | && GRUB_FIELD_MATCH (*pptr, grub_named_list_t, name))? \
82 | (grub_named_list_t *) (void *) pptr : (grub_named_list_t *) grub_bad_type_cast ())
83 |
84 | #endif /* ! GRUB_LIST_HEADER */
85 |
--------------------------------------------------------------------------------
/include/grub/lvm.h:
--------------------------------------------------------------------------------
1 | /* lvm.h - On disk structures for LVM. */
2 | /*
3 | * GRUB -- GRand Unified Bootloader
4 | * Copyright (C) 2006,2007 Free Software Foundation, Inc.
5 | *
6 | * GRUB is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * GRUB is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with GRUB. If not, see .
18 | */
19 |
20 | #ifndef GRUB_LVM_H
21 | #define GRUB_LVM_H 1
22 |
23 | #include
24 | #include
25 |
26 | /* Length of ID string, excluding terminating zero. */
27 | #define GRUB_LVM_ID_STRLEN 38
28 |
29 | #define GRUB_LVM_LABEL_SIZE GRUB_DISK_SECTOR_SIZE
30 | #define GRUB_LVM_LABEL_SCAN_SECTORS 4L
31 |
32 | #define GRUB_LVM_LABEL_ID "LABELONE"
33 | #define GRUB_LVM_LVM2_LABEL "LVM2 001"
34 |
35 | #define GRUB_LVM_ID_LEN 32
36 |
37 | /* On disk - 32 bytes */
38 | GRUB_PACKED_START
39 | struct grub_lvm_label_header
40 | {
41 | grub_int8_t id[8]; /* LABELONE */
42 | grub_uint64_t sector_xl; /* Sector number of this label */
43 | grub_uint32_t crc_xl; /* From next field to end of sector */
44 | grub_uint32_t offset_xl; /* Offset from start of struct to contents */
45 | grub_int8_t type[8]; /* LVM2 001 */
46 | };
47 | GRUB_PACKED_END
48 |
49 | /* On disk */
50 | GRUB_PACKED_START
51 | struct grub_lvm_disk_locn
52 | {
53 | grub_uint64_t offset; /* Offset in bytes to start sector */
54 | grub_uint64_t size; /* Bytes */
55 | };
56 | GRUB_PACKED_END
57 |
58 | /* Fields with the suffix _xl should be xlate'd wherever they appear */
59 | /* On disk */
60 | GRUB_PACKED_START
61 | struct grub_lvm_pv_header
62 | {
63 | grub_int8_t pv_uuid[GRUB_LVM_ID_LEN];
64 |
65 | /* This size can be overridden if PV belongs to a VG */
66 | grub_uint64_t device_size_xl; /* Bytes */
67 |
68 | /* NULL-terminated list of data areas followed by */
69 | /* NULL-terminated list of metadata area headers */
70 | struct grub_lvm_disk_locn disk_areas_xl[0]; /* Two lists */
71 | };
72 | GRUB_PACKED_END
73 |
74 | #define GRUB_LVM_FMTT_MAGIC "\040\114\126\115\062\040\170\133\065\101\045\162\060\116\052\076"
75 | #define GRUB_LVM_FMTT_VERSION 1
76 | #define GRUB_LVM_MDA_HEADER_SIZE 512
77 |
78 | /* On disk */
79 | GRUB_PACKED_START
80 | struct grub_lvm_raw_locn
81 | {
82 | grub_uint64_t offset; /* Offset in bytes to start sector */
83 | grub_uint64_t size; /* Bytes */
84 | grub_uint32_t checksum;
85 | grub_uint32_t filler;
86 | };
87 | GRUB_PACKED_END
88 |
89 | /* On disk */
90 | /* Structure size limited to one sector */
91 | GRUB_PACKED_START
92 | struct grub_lvm_mda_header
93 | {
94 | grub_uint32_t checksum_xl; /* Checksum of rest of mda_header */
95 | grub_int8_t magic[16]; /* To aid scans for metadata */
96 | grub_uint32_t version;
97 | grub_uint64_t start; /* Absolute start byte of mda_header */
98 | grub_uint64_t size; /* Size of metadata area */
99 |
100 | struct grub_lvm_raw_locn raw_locns[0]; /* NULL-terminated list */
101 | };
102 | GRUB_PACKED_END
103 |
104 | #endif /* ! GRUB_LVM_H */
105 |
--------------------------------------------------------------------------------
/include/grub/mm.h:
--------------------------------------------------------------------------------
1 | /* mm.h - prototypes and declarations for memory manager */
2 | /*
3 | * GRUB -- GRand Unified Bootloader
4 | * Copyright (C) 2002,2007 Free Software Foundation, Inc.
5 | *
6 | * GRUB is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * GRUB is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with GRUB. If not, see .
18 | */
19 |
20 | #ifndef GRUB_MM_H
21 | #define GRUB_MM_H 1
22 |
23 | #include
24 | #include
25 | #include
26 | #include
27 |
28 | #ifndef NULL
29 | # define NULL ((void *) 0)
30 | #endif
31 |
32 | void *EXPORT_FUNC(grub_calloc) (grub_size_t nmemb, grub_size_t size);
33 | void *EXPORT_FUNC(grub_malloc) (grub_size_t size);
34 | void *EXPORT_FUNC(grub_zalloc) (grub_size_t size);
35 | void EXPORT_FUNC(grub_free) (void *ptr);
36 | void *EXPORT_FUNC(grub_realloc) (void *ptr, grub_size_t size);
37 |
38 | #endif /* ! GRUB_MM_H */
39 |
--------------------------------------------------------------------------------
/include/grub/partition.h:
--------------------------------------------------------------------------------
1 | /*
2 | * GRUB -- GRand Unified Bootloader
3 | * Copyright (C) 1999,2000,2001,2002,2004,2006,2007 Free Software Foundation, Inc.
4 | *
5 | * GRUB is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * GRUB is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with GRUB. If not, see .
17 | */
18 |
19 | #ifndef GRUB_PART_HEADER
20 | #define GRUB_PART_HEADER 1
21 |
22 | #include
23 |
24 | struct grub_disk;
25 |
26 | typedef struct grub_partition* grub_partition_t;
27 |
28 | typedef int (*grub_partition_iterate_hook_t) (struct grub_disk* disk,
29 | const grub_partition_t partition,
30 | void* data);
31 |
32 | /* Partition map type. */
33 | struct grub_partition_map
34 | {
35 | /* The next partition map type. */
36 | struct grub_partition_map* next;
37 | struct grub_partition_map** prev;
38 |
39 | /* The name of the partition map type. */
40 | const char* name;
41 |
42 | /* Call HOOK with each partition, until HOOK returns non-zero. */
43 | grub_err_t(*iterate) (struct grub_disk* disk,
44 | grub_partition_iterate_hook_t hook, void* hook_data);
45 | };
46 | typedef struct grub_partition_map* grub_partition_map_t;
47 |
48 | /* Partition description. */
49 | struct grub_partition
50 | {
51 | /* The partition number. */
52 | int number;
53 |
54 | /* The start sector (relative to parent). */
55 | grub_disk_addr_t start;
56 |
57 | /* The length in sector units. */
58 | grub_uint64_t len;
59 |
60 | /* The offset of the partition table. */
61 | grub_disk_addr_t offset;
62 |
63 | /* The index of this partition in the partition table. */
64 | int index;
65 |
66 | /* Parent partition (physically contains this partition). */
67 | struct grub_partition* parent;
68 |
69 | /* The type partition map. */
70 | grub_partition_map_t partmap;
71 |
72 | /* The type of partition when it's on MSDOS.
73 | Used for embedding detection. */
74 | grub_uint8_t msdostype;
75 | };
76 |
77 | grub_partition_t EXPORT_FUNC(grub_partition_probe) (struct grub_disk* disk,
78 | const char* str);
79 | int EXPORT_FUNC(grub_partition_iterate) (struct grub_disk* disk,
80 | grub_partition_iterate_hook_t hook,
81 | void* hook_data);
82 | char* EXPORT_FUNC(grub_partition_get_name) (const grub_partition_t partition);
83 |
84 | extern grub_partition_map_t EXPORT_VAR(grub_partition_map_list);
85 |
86 | static inline void
87 | grub_partition_map_register(grub_partition_map_t partmap)
88 | {
89 | grub_list_push(GRUB_AS_LIST_P(&grub_partition_map_list),
90 | GRUB_AS_LIST(partmap));
91 | }
92 |
93 | static inline void
94 | grub_partition_map_unregister(grub_partition_map_t partmap)
95 | {
96 | grub_list_remove(GRUB_AS_LIST(partmap));
97 | }
98 |
99 | #define FOR_PARTITION_MAPS(var) FOR_LIST_ELEMENTS((var), (grub_partition_map_list))
100 |
101 | static inline grub_disk_addr_t
102 | grub_partition_get_start(const grub_partition_t p)
103 | {
104 | grub_partition_t part;
105 | grub_uint64_t part_start = 0;
106 |
107 | for (part = p; part; part = part->parent)
108 | part_start += part->start;
109 |
110 | return part_start;
111 | }
112 |
113 | static inline grub_uint64_t
114 | grub_partition_get_len(const grub_partition_t p)
115 | {
116 | return p->len;
117 | }
118 |
119 | #endif /* ! GRUB_PART_HEADER */
120 |
--------------------------------------------------------------------------------
/include/grub/procfs.h:
--------------------------------------------------------------------------------
1 | /*
2 | * GRUB -- GRand Unified Bootloader
3 | * Copyright (C) 2013 Free Software Foundation, Inc.
4 | *
5 | * GRUB is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * GRUB is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with GRUB. If not, see .
17 | */
18 |
19 | #ifndef GRUB_PROCFS_HEADER
20 | #define GRUB_PROCFS_HEADER 1
21 |
22 | #include
23 | #include
24 |
25 | struct grub_procfs_entry
26 | {
27 | struct grub_procfs_entry *next;
28 | struct grub_procfs_entry **prev;
29 |
30 | const char *name;
31 | void* data;
32 | char* (*get_contents) (struct grub_procfs_entry* this, grub_size_t *sz);
33 | };
34 |
35 | extern struct grub_procfs_entry *grub_procfs_entries;
36 |
37 | static inline void
38 | grub_procfs_register (const char *name __attribute__ ((unused)),
39 | struct grub_procfs_entry *entry)
40 | {
41 | grub_list_push (GRUB_AS_LIST_P (&grub_procfs_entries),
42 | GRUB_AS_LIST (entry));
43 | }
44 |
45 | static inline void
46 | grub_procfs_unregister (struct grub_procfs_entry *entry)
47 | {
48 | grub_list_remove (GRUB_AS_LIST (entry));
49 | }
50 |
51 | #endif
52 |
--------------------------------------------------------------------------------
/include/grub/safemath.h:
--------------------------------------------------------------------------------
1 | /*
2 | * GRUB -- GRand Unified Bootloader
3 | * Copyright (C) 2020 Free Software Foundation, Inc.
4 | *
5 | * GRUB is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * GRUB is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with GRUB. If not, see .
17 | *
18 | * Arithmetic operations that protect against overflow.
19 | */
20 |
21 | #ifndef GRUB_SAFEMATH_H
22 | #define GRUB_SAFEMATH_H 1
23 |
24 | #include
25 |
26 | #define grub_add(a, b, res) (UIntPtrAdd(a, b, (UINT_PTR *)res) != S_OK)
27 | #define grub_sub(a, b, res) (UIntPtrSub(a, b, (UINT_PTR *)res) != S_OK)
28 | #define grub_mul(a, b, res) (UIntPtrMult(a, b, (UINT_PTR *)res) != S_OK)
29 |
30 | #endif /* GRUB_SAFEMATH_H */
31 |
--------------------------------------------------------------------------------
/include/grub/symbol.h:
--------------------------------------------------------------------------------
1 | /*
2 | * GRUB -- GRand Unified Bootloader
3 | * Copyright (C) 1999,2000,2001,2002,2006,2007,2008,2009 Free Software Foundation, Inc.
4 | *
5 | * GRUB is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * GRUB is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with GRUB. If not, see .
17 | */
18 |
19 | #ifndef GRUB_SYMBOL_HEADER
20 | #define GRUB_SYMBOL_HEADER 1
21 |
22 | #include
23 |
24 | /* Apple assembler requires local labels to start with a capital L */
25 | #define LOCAL(sym) L_ ## sym
26 |
27 |
28 | /* Mark an exported symbol. */
29 | # define EXPORT_FUNC(x) x
30 | # define EXPORT_VAR(x) x
31 |
32 | #endif /* ! GRUB_SYMBOL_HEADER */
33 |
--------------------------------------------------------------------------------
/include/grub/time.h:
--------------------------------------------------------------------------------
1 | /*
2 | * GRUB -- GRand Unified Bootloader
3 | * Copyright (C) 2007, 2008 Free Software Foundation, Inc.
4 | *
5 | * GRUB is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * GRUB is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with GRUB. If not, see .
17 | */
18 |
19 | #ifndef KERNEL_TIME_HEADER
20 | #define KERNEL_TIME_HEADER 1
21 |
22 | #include
23 | #include
24 |
25 | static inline void
26 | grub_cpu_idle(void)
27 | {
28 | }
29 |
30 | #define NSEC_PER_SEC ((grub_int64_t) 1000000000)
31 |
32 | void EXPORT_FUNC(grub_millisleep) (grub_uint32_t ms);
33 | grub_uint64_t EXPORT_FUNC(grub_get_time_ms) (void);
34 |
35 | static __inline void
36 | grub_sleep(grub_uint32_t s)
37 | {
38 | grub_millisleep(1000 * s);
39 | }
40 |
41 | #endif /* ! KERNEL_TIME_HEADER */
42 |
--------------------------------------------------------------------------------
/include/grub/udf.h:
--------------------------------------------------------------------------------
1 | /*
2 | * GRUB -- GRand Unified Bootloader
3 | * Copyright (C) 2013 Free Software Foundation, Inc.
4 | *
5 | * GRUB is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * GRUB is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with GRUB. If not, see .
17 | */
18 |
19 | #ifndef GRUB_UDF_H
20 | #define GRUB_UDF_H 1
21 |
22 | #include
23 |
24 | #ifdef GRUB_UTIL
25 | #include
26 |
27 | grub_disk_addr_t
28 | grub_udf_get_cluster_sector(grub_disk_t disk, grub_uint64_t* sec_per_lcn);
29 | #endif
30 | #endif
31 |
--------------------------------------------------------------------------------
/include/grub/zfs/dmu_objset.h:
--------------------------------------------------------------------------------
1 | /*
2 | * GRUB -- GRand Unified Bootloader
3 | * Copyright (C) 1999,2000,2001,2002,2003,2004 Free Software Foundation, Inc.
4 | * Copyright (C) 2010 Robert Millan
5 | *
6 | * GRUB is free software; you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation; either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * GRUB is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with GRUB. If not, see .
18 | */
19 | /*
20 | * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
21 | * Use is subject to license terms.
22 | */
23 |
24 | #ifndef _SYS_DMU_OBJSET_H
25 | #define _SYS_DMU_OBJSET_H
26 |
27 | #include
28 | #include
29 |
30 | #define OBJSET_PHYS_SIZE 2048
31 | #define OBJSET_PHYS_SIZE_V14 1024
32 |
33 | typedef struct objset_phys
34 | {
35 | dnode_phys_t os_meta_dnode;
36 | zil_header_t os_zil_header;
37 | grub_uint64_t os_type;
38 | grub_uint64_t os_flags;
39 | char os_pad[OBJSET_PHYS_SIZE - sizeof(dnode_phys_t) * 3 -
40 | sizeof(zil_header_t) - sizeof(grub_uint64_t) * 2];
41 | dnode_phys_t os_userused_dnode;
42 | dnode_phys_t os_groupused_dnode;
43 | } objset_phys_t;
44 |
45 | #endif /* _SYS_DMU_OBJSET_H */
46 |
--------------------------------------------------------------------------------
/include/grub/zfs/dnode.h:
--------------------------------------------------------------------------------
1 | /*
2 | * GRUB -- GRand Unified Bootloader
3 | * Copyright (C) 1999,2000,2001,2002,2003,2004 Free Software Foundation, Inc.
4 | *
5 | * GRUB is free software; you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation; either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * GRUB is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with GRUB. If not, see .
17 | */
18 | /*
19 | * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
20 | * Use is subject to license terms.
21 | */
22 |
23 | #ifndef _SYS_DNODE_H
24 | #define _SYS_DNODE_H
25 |
26 | #include
27 |
28 | /*
29 | * Fixed constants.
30 | */
31 | #define DNODE_SHIFT 9 /* 512 bytes */
32 | #define DNODE_BLOCK_SHIFT 14 /* 16k */
33 | #define DNODE_CORE_SIZE 64 /* 64 bytes for dnode sans blkptrs */
34 |
35 | /*
36 | * Derived constants.
37 | */
38 | #define DNODE_SIZE (1 << DNODE_SHIFT)
39 | #define DN_MAX_NBLKPTR ((DNODE_SIZE - DNODE_CORE_SIZE) >> SPA_BLKPTRSHIFT)
40 | #define DN_MAX_BONUSLEN (DNODE_SIZE - DNODE_CORE_SIZE - (1 << SPA_BLKPTRSHIFT))
41 |
42 | #define DNODES_PER_BLOCK_SHIFT (DNODE_BLOCK_SHIFT - DNODE_SHIFT)
43 | #define DNODES_PER_BLOCK (1ULL << DNODES_PER_BLOCK_SHIFT)
44 |
45 | #define DNODE_FLAG_SPILL_BLKPTR (1<<2)
46 |
47 | #define DN_BONUS(dnp) ((void*)((dnp)->dn_bonus + \
48 | (((dnp)->dn_nblkptr - 1) * sizeof (blkptr_t))))
49 |
50 | typedef struct dnode_phys
51 | {
52 | grub_uint8_t dn_type; /* dmu_object_type_t */
53 | grub_uint8_t dn_indblkshift; /* ln2(indirect block size) */
54 | grub_uint8_t dn_nlevels; /* 1=dn_blkptr->data blocks */
55 | grub_uint8_t dn_nblkptr; /* length of dn_blkptr */
56 | grub_uint8_t dn_bonustype; /* type of data in bonus buffer */
57 | grub_uint8_t dn_checksum; /* ZIO_CHECKSUM type */
58 | grub_uint8_t dn_compress; /* ZIO_COMPRESS type */
59 | grub_uint8_t dn_flags; /* DNODE_FLAG_* */
60 | grub_uint16_t dn_datablkszsec; /* data block size in 512b sectors */
61 | grub_uint16_t dn_bonuslen; /* length of dn_bonus */
62 | grub_uint8_t dn_pad2[4];
63 |
64 | /* accounting is protected by dn_dirty_mtx */
65 | grub_uint64_t dn_maxblkid; /* largest allocated block ID */
66 | grub_uint64_t dn_used; /* bytes (or sectors) of disk space */
67 |
68 | grub_uint64_t dn_pad3[4];
69 |
70 | blkptr_t dn_blkptr[1];
71 | grub_uint8_t dn_bonus[DN_MAX_BONUSLEN - sizeof (blkptr_t)];
72 | blkptr_t dn_spill;
73 | } dnode_phys_t;
74 |
75 | #endif /* _SYS_DNODE_H */
76 |
--------------------------------------------------------------------------------
/include/grub/zfs/dsl_dataset.h:
--------------------------------------------------------------------------------
1 | /*
2 | * GRUB -- GRand Unified Bootloader
3 | * Copyright (C) 1999,2000,2001,2002,2003,2004 Free Software Foundation, Inc.
4 | *
5 | * GRUB is free software; you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation; either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * GRUB is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with GRUB. If not, see .
17 | */
18 | /*
19 | * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
20 | * Use is subject to license terms.
21 | */
22 |
23 | #ifndef _SYS_DSL_DATASET_H
24 | #define _SYS_DSL_DATASET_H
25 |
26 | #include
27 |
28 | typedef struct dsl_dataset_phys
29 | {
30 | grub_uint64_t ds_dir_obj;
31 | grub_uint64_t ds_prev_snap_obj;
32 | grub_uint64_t ds_prev_snap_txg;
33 | grub_uint64_t ds_next_snap_obj;
34 | grub_uint64_t ds_snapnames_zapobj; /* zap obj of snaps; ==0 for snaps */
35 | grub_uint64_t ds_num_children; /* clone/snap children; ==0 for head */
36 | grub_uint64_t ds_creation_time; /* seconds since 1970 */
37 | grub_uint64_t ds_creation_txg;
38 | grub_uint64_t ds_deadlist_obj;
39 | grub_uint64_t ds_used_bytes;
40 | grub_uint64_t ds_compressed_bytes;
41 | grub_uint64_t ds_uncompressed_bytes;
42 | grub_uint64_t ds_unique_bytes; /* only relevant to snapshots */
43 | /*
44 | * The ds_fsid_guid is a 56-bit ID that can change to avoid
45 | * collisions. The ds_guid is a 64-bit ID that will never
46 | * change, so there is a small probability that it will collide.
47 | */
48 | grub_uint64_t ds_fsid_guid;
49 | grub_uint64_t ds_guid;
50 | grub_uint64_t ds_flags;
51 | blkptr_t ds_bp;
52 | grub_uint64_t ds_pad[8]; /* pad out to 320 bytes for good measure */
53 | } dsl_dataset_phys_t;
54 |
55 | #endif /* _SYS_DSL_DATASET_H */
56 |
--------------------------------------------------------------------------------
/include/grub/zfs/dsl_dir.h:
--------------------------------------------------------------------------------
1 | /*
2 | * GRUB -- GRand Unified Bootloader
3 | * Copyright (C) 1999,2000,2001,2002,2003,2004 Free Software Foundation, Inc.
4 | *
5 | * GRUB is free software; you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation; either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * GRUB is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with GRUB. If not, see .
17 | */
18 | /*
19 | * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
20 | * Use is subject to license terms.
21 | */
22 |
23 | #ifndef _SYS_DSL_DIR_H
24 | #define _SYS_DSL_DIR_H
25 |
26 | #include
27 |
28 | typedef struct dsl_dir_phys
29 | {
30 | grub_uint64_t dd_creation_time; /* not actually used */
31 | grub_uint64_t dd_head_dataset_obj;
32 | grub_uint64_t dd_parent_obj;
33 | grub_uint64_t dd_clone_parent_obj;
34 | grub_uint64_t dd_child_dir_zapobj;
35 | /*
36 | * how much space our children are accounting for; for leaf
37 | * datasets, == physical space used by fs + snaps
38 | */
39 | grub_uint64_t dd_used_bytes;
40 | grub_uint64_t dd_compressed_bytes;
41 | grub_uint64_t dd_uncompressed_bytes;
42 | /* Administrative quota setting */
43 | grub_uint64_t dd_quota;
44 | /* Administrative reservation setting */
45 | grub_uint64_t dd_reserved;
46 | grub_uint64_t dd_props_zapobj;
47 | grub_uint64_t dd_deleg_zapobj; /* dataset permissions */
48 | grub_uint64_t unused[7];
49 | grub_uint64_t keychain;
50 | grub_uint64_t unused2[12];
51 | } dsl_dir_phys_t;
52 |
53 | #endif /* _SYS_DSL_DIR_H */
54 |
--------------------------------------------------------------------------------
/include/grub/zfs/sa_impl.h:
--------------------------------------------------------------------------------
1 | /*
2 | * GRUB -- GRand Unified Bootloader
3 | * Copyright (C) 1999,2000,2001,2002,2003,2004 Free Software Foundation, Inc.
4 | *
5 | * GRUB is free software; you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation; either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * GRUB is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with GRUB. If not, see .
17 | */
18 | /*
19 | * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
20 | * Use is subject to license terms.
21 | */
22 | #ifndef _SYS_SA_IMPL_H
23 | #define _SYS_SA_IMPL_H
24 |
25 | #include
26 |
27 | typedef struct sa_hdr_phys
28 | {
29 | grub_uint32_t sa_magic;
30 | grub_uint16_t sa_layout_info;
31 | grub_uint16_t sa_lengths[1];
32 | } sa_hdr_phys_t;
33 |
34 | #define SA_HDR_SIZE(hdr) BF32_GET_SB(hdr->sa_layout_info, 10, 16, 3, 0)
35 | #define SA_TYPE_OFFSET 0x0
36 | #define SA_SIZE_OFFSET 0x8
37 | #define SA_MTIME_OFFSET 0x38
38 | #define SA_SYMLINK_OFFSET 0xa0
39 |
40 | #endif /* _SYS_SA_IMPL_H */
41 |
--------------------------------------------------------------------------------
/include/grub/zfs/uberblock_impl.h:
--------------------------------------------------------------------------------
1 | /*
2 | * GRUB -- GRand Unified Bootloader
3 | * Copyright (C) 1999,2000,2001,2002,2003,2004 Free Software Foundation, Inc.
4 | *
5 | * GRUB is free software; you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation; either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * GRUB is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with GRUB. If not, see .
17 | */
18 | /*
19 | * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
20 | * Use is subject to license terms.
21 | */
22 |
23 | #ifndef _SYS_UBERBLOCK_IMPL_H
24 | #define _SYS_UBERBLOCK_IMPL_H
25 |
26 | #include
27 |
28 | /*
29 | * The uberblock version is incremented whenever an incompatible on-disk
30 | * format change is made to the SPA, DMU, or ZAP.
31 | *
32 | * Note: the first two fields should never be moved. When a storage pool
33 | * is opened, the uberblock must be read off the disk before the version
34 | * can be checked. If the ub_version field is moved, we may not detect
35 | * version mismatch. If the ub_magic field is moved, applications that
36 | * expect the magic number in the first word won't work.
37 | */
38 | #define UBERBLOCK_MAGIC 0x00bab10c /* oo-ba-bloc! */
39 | #define UBERBLOCK_SHIFT 10 /* up to 1K */
40 |
41 | typedef struct uberblock
42 | {
43 | grub_uint64_t ub_magic; /* UBERBLOCK_MAGIC */
44 | grub_uint64_t ub_version; /* ZFS_VERSION */
45 | grub_uint64_t ub_txg; /* txg of last sync */
46 | grub_uint64_t ub_guid_sum; /* sum of all vdev guids */
47 | grub_uint64_t ub_timestamp; /* UTC time of last sync */
48 | blkptr_t ub_rootbp; /* MOS objset_phys_t */
49 | } uberblock_t;
50 |
51 | #define UBERBLOCK_SIZE (1ULL << UBERBLOCK_SHIFT)
52 | #define VDEV_UBERBLOCK_SHIFT UBERBLOCK_SHIFT
53 |
54 | /* XXX Uberblock_phys_t is no longer in the kernel zfs */
55 | typedef struct uberblock_phys
56 | {
57 | uberblock_t ubp_uberblock;
58 | char ubp_pad[UBERBLOCK_SIZE - sizeof (uberblock_t) -
59 | sizeof (zio_eck_t)];
60 | zio_eck_t ubp_zec;
61 | } uberblock_phys_t;
62 |
63 | #endif /* _SYS_UBERBLOCK_IMPL_H */
64 |
--------------------------------------------------------------------------------
/include/grub/zfs/vdev_impl.h:
--------------------------------------------------------------------------------
1 | /*
2 | * GRUB -- GRand Unified Bootloader
3 | * Copyright (C) 1999,2000,2001,2002,2003,2004 Free Software Foundation, Inc.
4 | *
5 | * GRUB is free software; you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation; either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * GRUB is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with GRUB. If not, see .
17 | */
18 | /*
19 | * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
20 | * Use is subject to license terms.
21 | */
22 |
23 | #ifndef _SYS_VDEV_IMPL_H
24 | #define _SYS_VDEV_IMPL_H
25 |
26 | #include
27 |
28 | #define VDEV_SKIP_SIZE (8 << 10)
29 | #define VDEV_BOOT_HEADER_SIZE (8 << 10)
30 | #define VDEV_PHYS_SIZE (112 << 10)
31 | #define VDEV_UBERBLOCK_RING (128 << 10)
32 |
33 | /* ZFS boot block */
34 | #define VDEV_BOOT_MAGIC 0x2f5b007b10cULL
35 | #define VDEV_BOOT_VERSION 1 /* version number */
36 |
37 | typedef struct vdev_boot_header
38 | {
39 | grub_uint64_t vb_magic; /* VDEV_BOOT_MAGIC */
40 | grub_uint64_t vb_version; /* VDEV_BOOT_VERSION */
41 | grub_uint64_t vb_offset; /* start offset (bytes) */
42 | grub_uint64_t vb_size; /* size (bytes) */
43 | char vb_pad[VDEV_BOOT_HEADER_SIZE - 4 * sizeof (grub_uint64_t)];
44 | } vdev_boot_header_t;
45 |
46 | typedef struct vdev_phys
47 | {
48 | char vp_nvlist[VDEV_PHYS_SIZE - sizeof (zio_eck_t)];
49 | zio_eck_t vp_zbt;
50 | } vdev_phys_t;
51 |
52 | typedef struct vdev_label
53 | {
54 | char vl_pad[VDEV_SKIP_SIZE]; /* 8K */
55 | vdev_boot_header_t vl_boot_header; /* 8K */
56 | vdev_phys_t vl_vdev_phys; /* 112K */
57 | char vl_uberblock[VDEV_UBERBLOCK_RING]; /* 128K */
58 | } vdev_label_t; /* 256K total */
59 |
60 | /*
61 | * Size and offset of embedded boot loader region on each label.
62 | * The total size of the first two labels plus the boot area is 4MB.
63 | */
64 | #define VDEV_BOOT_OFFSET (2 * sizeof (vdev_label_t))
65 | #define VDEV_BOOT_SIZE (7ULL << 19) /* 3.5M */
66 |
67 | /*
68 | * Size of label regions at the start and end of each leaf device.
69 | */
70 | #define VDEV_LABEL_START_SIZE (2 * sizeof (vdev_label_t) + VDEV_BOOT_SIZE)
71 | #define VDEV_LABEL_END_SIZE (2 * sizeof (vdev_label_t))
72 | #define VDEV_LABELS 4
73 |
74 | #endif /* _SYS_VDEV_IMPL_H */
75 |
--------------------------------------------------------------------------------
/include/grub/zfs/zap_leaf.h:
--------------------------------------------------------------------------------
1 | /*
2 | * GRUB -- GRand Unified Bootloader
3 | * Copyright (C) 1999,2000,2001,2002,2003,2004 Free Software Foundation, Inc.
4 | *
5 | * GRUB is free software; you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation; either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * GRUB is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with GRUB. If not, see .
17 | */
18 | /*
19 | * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
20 | * Use is subject to license terms.
21 | */
22 |
23 | #ifndef _SYS_ZAP_LEAF_H
24 | #define _SYS_ZAP_LEAF_H
25 |
26 | #include
27 |
28 | #define ZAP_LEAF_MAGIC 0x2AB1EAF
29 |
30 | /* chunk size = 24 bytes */
31 | #define ZAP_LEAF_CHUNKSIZE 24
32 |
33 | /*
34 | * The amount of space within the chunk available for the array is:
35 | * chunk size - space for type (1) - space for next pointer (2)
36 | */
37 | #define ZAP_LEAF_ARRAY_BYTES (ZAP_LEAF_CHUNKSIZE - 3)
38 |
39 | typedef enum zap_chunk_type
40 | {
41 | ZAP_CHUNK_FREE = 253,
42 | ZAP_CHUNK_ENTRY = 252,
43 | ZAP_CHUNK_ARRAY = 251,
44 | ZAP_CHUNK_TYPE_MAX = 250
45 | } zap_chunk_type_t;
46 |
47 | /*
48 | * TAKE NOTE:
49 | * If zap_leaf_phys_t is modified, zap_leaf_byteswap() must be modified.
50 | */
51 | typedef struct zap_leaf_phys
52 | {
53 | struct zap_leaf_header
54 | {
55 | grub_uint64_t lh_block_type; /* ZBT_LEAF */
56 | grub_uint64_t lh_pad1;
57 | grub_uint64_t lh_prefix; /* hash prefix of this leaf */
58 | grub_uint32_t lh_magic; /* ZAP_LEAF_MAGIC */
59 | grub_uint16_t lh_nfree; /* number free chunks */
60 | grub_uint16_t lh_nentries; /* number of entries */
61 | grub_uint16_t lh_prefix_len; /* num bits used to id this */
62 |
63 | /* above is accessable to zap, below is zap_leaf private */
64 |
65 | grub_uint16_t lh_freelist; /* chunk head of free list */
66 | grub_uint8_t lh_pad2[12];
67 | } l_hdr; /* 2 24-byte chunks */
68 |
69 | /*
70 | * The header is followed by a hash table with
71 | * ZAP_LEAF_HASH_NUMENTRIES(zap) entries. The hash table is
72 | * followed by an array of ZAP_LEAF_NUMCHUNKS(zap)
73 | * zap_leaf_chunk structures. These structures are accessed
74 | * with the ZAP_LEAF_CHUNK() macro.
75 | */
76 |
77 | grub_uint16_t l_hash[0];
78 | } zap_leaf_phys_t;
79 |
80 | typedef union zap_leaf_chunk
81 | {
82 | struct zap_leaf_entry
83 | {
84 | grub_uint8_t le_type; /* always ZAP_CHUNK_ENTRY */
85 | grub_uint8_t le_int_size; /* size of ints */
86 | grub_uint16_t le_next; /* next entry in hash chain */
87 | grub_uint16_t le_name_chunk; /* first chunk of the name */
88 | grub_uint16_t le_name_length; /* bytes in name, incl null */
89 | grub_uint16_t le_value_chunk; /* first chunk of the value */
90 | grub_uint16_t le_value_length; /* value length in ints */
91 | grub_uint32_t le_cd; /* collision differentiator */
92 | grub_uint64_t le_hash; /* hash value of the name */
93 | } l_entry;
94 | struct zap_leaf_array
95 | {
96 | grub_uint8_t la_type; /* always ZAP_CHUNK_ARRAY */
97 | GRUB_PACKED_START
98 | union
99 | {
100 | grub_uint8_t la_array[ZAP_LEAF_ARRAY_BYTES];
101 | grub_uint64_t la_array64;
102 | };
103 | GRUB_PACKED_END
104 | grub_uint16_t la_next; /* next blk or CHAIN_END */
105 | } l_array;
106 | struct zap_leaf_free
107 | {
108 | grub_uint8_t lf_type; /* always ZAP_CHUNK_FREE */
109 | grub_uint8_t lf_pad[ZAP_LEAF_ARRAY_BYTES];
110 | grub_uint16_t lf_next; /* next in free list, or CHAIN_END */
111 | } l_free;
112 | } zap_leaf_chunk_t;
113 |
114 | #endif /* _SYS_ZAP_LEAF_H */
115 |
--------------------------------------------------------------------------------
/include/grub/zfs/zfs_acl.h:
--------------------------------------------------------------------------------
1 | /*
2 | * GRUB -- GRand Unified Bootloader
3 | * Copyright (C) 1999,2000,2001,2002,2003,2004 Free Software Foundation, Inc.
4 | *
5 | * GRUB is free software; you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation; either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * GRUB is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with GRUB. If not, see .
17 | */
18 | /*
19 | * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
20 | * Use is subject to license terms.
21 | */
22 |
23 | #ifndef _SYS_FS_ZFS_ACL_H
24 | #define _SYS_FS_ZFS_ACL_H
25 |
26 | #include
27 |
28 | #ifndef _UID_T
29 | #define _UID_T
30 | typedef unsigned int uid_t; /* UID type */
31 | #endif /* _UID_T */
32 |
33 | typedef struct zfs_oldace
34 | {
35 | grub_uint32_t z_fuid; /* "who" */
36 | grub_uint32_t z_access_mask; /* access mask */
37 | grub_uint16_t z_flags; /* flags, i.e inheritance */
38 | grub_uint16_t z_type; /* type of entry allow/deny */
39 | } zfs_oldace_t;
40 |
41 | #define ACE_SLOT_CNT 6
42 |
43 | typedef struct zfs_znode_acl_v0
44 | {
45 | grub_uint64_t z_acl_extern_obj; /* ext acl pieces */
46 | grub_uint32_t z_acl_count; /* Number of ACEs */
47 | grub_uint16_t z_acl_version; /* acl version */
48 | grub_uint16_t z_acl_pad; /* pad */
49 | zfs_oldace_t z_ace_data[ACE_SLOT_CNT]; /* 6 standard ACEs */
50 | } zfs_znode_acl_v0_t;
51 |
52 | #define ZFS_ACE_SPACE (sizeof (zfs_oldace_t) * ACE_SLOT_CNT)
53 |
54 | typedef struct zfs_znode_acl
55 | {
56 | grub_uint64_t z_acl_extern_obj; /* ext acl pieces */
57 | grub_uint32_t z_acl_size; /* Number of bytes in ACL */
58 | grub_uint16_t z_acl_version; /* acl version */
59 | grub_uint16_t z_acl_count; /* ace count */
60 | grub_uint8_t z_ace_data[ZFS_ACE_SPACE]; /* space for embedded ACEs */
61 | } zfs_znode_acl_t;
62 |
63 | #endif /* _SYS_FS_ZFS_ACL_H */
64 |
--------------------------------------------------------------------------------
/include/grub/zfs/zfs_znode.h:
--------------------------------------------------------------------------------
1 | /*
2 | * GRUB -- GRand Unified Bootloader
3 | * Copyright (C) 1999,2000,2001,2002,2003,2004 Free Software Foundation, Inc.
4 | *
5 | * GRUB is free software; you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation; either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * GRUB is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with GRUB. If not, see .
17 | */
18 | /*
19 | * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
20 | * Use is subject to license terms.
21 | */
22 |
23 | #ifndef _SYS_FS_ZFS_ZNODE_H
24 | #define _SYS_FS_ZFS_ZNODE_H
25 |
26 | #include
27 |
28 | #define MASTER_NODE_OBJ 1
29 | #define ZFS_ROOT_OBJ "ROOT"
30 | #define ZPL_VERSION_STR "VERSION"
31 | #define ZFS_SA_ATTRS "SA_ATTRS"
32 |
33 | #define ZPL_VERSION 5ULL
34 |
35 | #define ZFS_DIRENT_OBJ(de) BF64_GET(de, 0, 48)
36 |
37 | /*
38 | * This is the persistent portion of the znode. It is stored
39 | * in the "bonus buffer" of the file. Short symbolic links
40 | * are also stored in the bonus buffer.
41 | */
42 | typedef struct znode_phys
43 | {
44 | grub_uint64_t zp_atime[2]; /* 0 - last file access time */
45 | grub_uint64_t zp_mtime[2]; /* 16 - last file modification time */
46 | grub_uint64_t zp_ctime[2]; /* 32 - last file change time */
47 | grub_uint64_t zp_crtime[2]; /* 48 - creation time */
48 | grub_uint64_t zp_gen; /* 64 - generation (txg of creation) */
49 | grub_uint64_t zp_mode; /* 72 - file mode bits */
50 | grub_uint64_t zp_size; /* 80 - size of file */
51 | grub_uint64_t zp_parent; /* 88 - directory parent (`..') */
52 | grub_uint64_t zp_links; /* 96 - number of links to file */
53 | grub_uint64_t zp_xattr; /* 104 - DMU object for xattrs */
54 | grub_uint64_t zp_rdev; /* 112 - dev_t for VBLK & VCHR files */
55 | grub_uint64_t zp_flags; /* 120 - persistent flags */
56 | grub_uint64_t zp_uid; /* 128 - file owner */
57 | grub_uint64_t zp_gid; /* 136 - owning group */
58 | grub_uint64_t zp_pad[4]; /* 144 - future */
59 | zfs_znode_acl_t zp_acl; /* 176 - 263 ACL */
60 | /*
61 | * Data may pad out any remaining bytes in the znode buffer, eg:
62 | *
63 | * |<---------------------- dnode_phys (512) ------------------------>|
64 | * |<-- dnode (192) --->|<----------- "bonus" buffer (320) ---------->|
65 | * |<---- znode (264) ---->|<---- data (56) ---->|
66 | *
67 | * At present, we only use this space to store symbolic links.
68 | */
69 | } znode_phys_t;
70 |
71 | #endif /* _SYS_FS_ZFS_ZNODE_H */
72 |
--------------------------------------------------------------------------------
/include/grub/zfs/zil.h:
--------------------------------------------------------------------------------
1 | /*
2 | * GRUB -- GRand Unified Bootloader
3 | * Copyright (C) 1999,2000,2001,2002,2003,2004 Free Software Foundation, Inc.
4 | *
5 | * GRUB is free software; you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation; either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * GRUB is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with GRUB. If not, see .
17 | */
18 | /*
19 | * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
20 | * Use is subject to license terms.
21 | */
22 |
23 | #ifndef _SYS_ZIL_H
24 | #define _SYS_ZIL_H
25 |
26 | #include
27 |
28 | /*
29 | * Intent log format:
30 | *
31 | * Each objset has its own intent log. The log header (zil_header_t)
32 | * for objset N's intent log is kept in the Nth object of the SPA's
33 | * intent_log objset. The log header points to a chain of log blocks,
34 | * each of which contains log records (i.e., transactions) followed by
35 | * a log block trailer (zil_trailer_t). The format of a log record
36 | * depends on the record (or transaction) type, but all records begin
37 | * with a common structure that defines the type, length, and txg.
38 | */
39 |
40 | /*
41 | * Intent log header - this on disk structure holds fields to manage
42 | * the log. All fields are 64 bit to easily handle cross architectures.
43 | */
44 | typedef struct zil_header
45 | {
46 | grub_uint64_t zh_claim_txg; /* txg in which log blocks were claimed */
47 | grub_uint64_t zh_replay_seq; /* highest replayed sequence number */
48 | blkptr_t zh_log; /* log chain */
49 | grub_uint64_t zh_claim_seq; /* highest claimed sequence number */
50 | grub_uint64_t zh_flags; /* header flags */
51 | grub_uint64_t zh_pad[4];
52 | } zil_header_t;
53 |
54 | /*
55 | * zh_flags bit settings
56 | */
57 | #define ZIL_REPLAY_NEEDED 0x1 /* replay needed - internal only */
58 |
59 | #endif /* _SYS_ZIL_H */
60 |
--------------------------------------------------------------------------------
/include/grub/zfs/zio.h:
--------------------------------------------------------------------------------
1 | /*
2 | * GRUB -- GRand Unified Bootloader
3 | * Copyright (C) 1999,2000,2001,2002,2003,2004 Free Software Foundation, Inc.
4 | *
5 | * GRUB is free software; you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation; either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * GRUB is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with GRUB. If not, see .
17 | */
18 | /*
19 | * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
20 | * Use is subject to license terms.
21 | */
22 |
23 | #ifndef _ZIO_H
24 | #define _ZIO_H
25 |
26 | #include
27 |
28 | #define ZEC_MAGIC 0x210da7ab10c7a11ULL /* zio data bloc tail */
29 |
30 | GRUB_PACKED_START
31 | typedef struct zio_eck
32 | {
33 | grub_uint64_t zec_magic; /* for validation, endianness */
34 | zio_cksum_t zec_cksum; /* 256-bit checksum */
35 | } zio_eck_t;
36 | GRUB_PACKED_END
37 |
38 | /*
39 | * Gang block headers are self-checksumming and contain an array
40 | * of block pointers.
41 | */
42 | #define SPA_GANGBLOCKSIZE SPA_MINBLOCKSIZE
43 | #define SPA_GBH_NBLKPTRS ((SPA_GANGBLOCKSIZE - \
44 | sizeof (zio_eck_t)) / sizeof (blkptr_t))
45 | #define SPA_GBH_FILLER ((SPA_GANGBLOCKSIZE - \
46 | sizeof (zio_eck_t) - \
47 | (SPA_GBH_NBLKPTRS * sizeof (blkptr_t))) /\
48 | sizeof (grub_uint64_t))
49 |
50 | #define ZIO_GET_IOSIZE(zio) \
51 | (BP_IS_GANG((zio)->io_bp) ? \
52 | SPA_GANGBLOCKSIZE : BP_GET_PSIZE((zio)->io_bp))
53 |
54 | typedef struct zio_gbh
55 | {
56 | blkptr_t zg_blkptr[SPA_GBH_NBLKPTRS];
57 | grub_uint64_t zg_filler[SPA_GBH_FILLER];
58 | zio_eck_t zg_tail;
59 | } zio_gbh_phys_t;
60 |
61 | enum zio_checksum
62 | {
63 | ZIO_CHECKSUM_INHERIT = 0,
64 | ZIO_CHECKSUM_ON,
65 | ZIO_CHECKSUM_OFF,
66 | ZIO_CHECKSUM_LABEL,
67 | ZIO_CHECKSUM_GANG_HEADER,
68 | ZIO_CHECKSUM_ZILOG,
69 | ZIO_CHECKSUM_FLETCHER_2,
70 | ZIO_CHECKSUM_FLETCHER_4,
71 | ZIO_CHECKSUM_SHA256,
72 | ZIO_CHECKSUM_ZILOG2,
73 | ZIO_CHECKSUM_SHA256_MAC,
74 | ZIO_CHECKSUM_FUNCTIONS
75 | };
76 |
77 | #define ZIO_CHECKSUM_ON_VALUE ZIO_CHECKSUM_FLETCHER_2
78 | #define ZIO_CHECKSUM_DEFAULT ZIO_CHECKSUM_ON
79 |
80 | enum zio_compress
81 | {
82 | ZIO_COMPRESS_INHERIT = 0,
83 | ZIO_COMPRESS_ON,
84 | ZIO_COMPRESS_OFF,
85 | ZIO_COMPRESS_LZJB,
86 | ZIO_COMPRESS_EMPTY,
87 | ZIO_COMPRESS_GZIP1,
88 | ZIO_COMPRESS_GZIP2,
89 | ZIO_COMPRESS_GZIP3,
90 | ZIO_COMPRESS_GZIP4,
91 | ZIO_COMPRESS_GZIP5,
92 | ZIO_COMPRESS_GZIP6,
93 | ZIO_COMPRESS_GZIP7,
94 | ZIO_COMPRESS_GZIP8,
95 | ZIO_COMPRESS_GZIP9,
96 | ZIO_COMPRESS_ZLE,
97 | ZIO_COMPRESS_LZ4,
98 | ZIO_COMPRESS_ZSTD,
99 | ZIO_COMPRESS_FUNCTIONS
100 | };
101 |
102 | #endif /* _ZIO_H */
103 |
--------------------------------------------------------------------------------
/include/grub/zfs/zio_checksum.h:
--------------------------------------------------------------------------------
1 | /*
2 | * GRUB -- GRand Unified Bootloader
3 | * Copyright (C) 1999,2000,2001,2002,2003,2004 Free Software Foundation, Inc.
4 | *
5 | * GRUB is free software; you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation; either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * GRUB is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with GRUB. If not, see .
17 | */
18 | /*
19 | * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
20 | * Use is subject to license terms.
21 | */
22 |
23 | #ifndef _SYS_ZIO_CHECKSUM_H
24 | #define _SYS_ZIO_CHECKSUM_H
25 |
26 | #include
27 | #include
28 |
29 | extern void zio_checksum_SHA256 (const void *, grub_uint64_t,
30 | grub_zfs_endian_t endian, zio_cksum_t *);
31 | extern void fletcher_2 (const void *, grub_uint64_t, grub_zfs_endian_t endian,
32 | zio_cksum_t *);
33 | extern void fletcher_4 (const void *, grub_uint64_t, grub_zfs_endian_t endian,
34 | zio_cksum_t *);
35 |
36 | #endif /* _SYS_ZIO_CHECKSUM_H */
37 |
--------------------------------------------------------------------------------
/include/lang.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | enum
4 | {
5 | LANG_STR_UP = 0,
6 | LANG_STR_REFRESH_FILES,
7 | LANG_STR_EXTRACT_DIR,
8 | LANG_STR_ABOUT,
9 | LANG_STR_THIS_PC,
10 | LANG_STR_UMOUNT_DISK,
11 | LANG_STR_DISK_INFO,
12 | LANG_STR_VIEW_HEX,
13 | LANG_STR_CANCEL,
14 | LANG_STR_REFRESH_DISKS,
15 | LANG_STR_VIEW_IMAGE,
16 | LANG_STR_MOUNT_DISK,
17 | LANG_STR_GET_CHECKSUM,
18 | LANG_STR_EXTRACT_FILE,
19 | LANG_STR_NAME,
20 | LANG_STR_DRIVER,
21 | LANG_STR_SIZE,
22 | LANG_STR_PARENT,
23 | LANG_STR_FS,
24 | LANG_STR_VOL_LABEL,
25 | LANG_STR_FS_UUID,
26 | LANG_STR_UNKNOWN,
27 | LANG_STR_DIR,
28 | LANG_STR_CALC,
29 | LANG_STR_NO_DECOMP,
30 | LANG_STR_MOUNT,
31 |
32 | LANG_STRMAX
33 | };
34 |
35 | const char* GET_STR(int id);
36 |
37 | enum
38 | {
39 | LANG_WCS_INFO = 0,
40 | LANG_WCS_DONE,
41 | LANG_WCS_FAIL,
42 | LANG_WCS_SELECT_DIR,
43 | LANG_WCS_ERROR,
44 | LANG_WCS_CANNOT_OPEN_FILE,
45 | LANG_WCS_FILE_TOO_LARGE,
46 | LANG_WCS_OUT_OF_MEM,
47 |
48 | LANG_WCSMAX
49 | };
50 |
51 | const wchar_t* GET_WCS(int id);
52 |
--------------------------------------------------------------------------------
/include/loopback.h:
--------------------------------------------------------------------------------
1 | /*
2 | * NkArc
3 | * Copyright (C) 2023 A1ive
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #pragma once
20 |
21 | #include
22 |
23 | struct grub_file;
24 |
25 | struct grub_loopback
26 | {
27 | char* devname;
28 | struct grub_file* file;
29 | struct grub_loopback* next;
30 | unsigned long id;
31 | };
32 |
33 | grub_err_t
34 | grub_loopback_delete(const char* name);
35 |
36 | grub_err_t
37 | grub_loopback_add(const char* name, const char* path, int decompress);
38 |
--------------------------------------------------------------------------------
/include/resource.h:
--------------------------------------------------------------------------------
1 | //{{NO_DEPENDENCIES}}
2 | //
3 | #define IDI_MAIN_ICON 101
4 |
5 | #define IDD_PROG_DIALOG 105
6 |
7 | #define IDR_PNG_MIN 110
8 |
9 | #define IDR_PNG_ARC 110
10 | #define IDR_PNG_BIN 111
11 | #define IDR_PNG_CD 112
12 | #define IDR_PNG_COPY 113
13 | #define IDR_PNG_DIR 114
14 | #define IDR_PNG_DOC 115
15 | #define IDR_PNG_EMPTY 116
16 | #define IDR_PNG_ERROR 117
17 | #define IDR_PNG_FDD 118
18 | #define IDR_PNG_FILE 119
19 | #define IDR_PNG_FONT 120
20 | #define IDR_PNG_FW 121
21 | #define IDR_PNG_HDD 122
22 | #define IDR_PNG_IMAGE 123
23 | #define IDR_PNG_INFO 124
24 | #define IDR_PNG_ISO 125
25 | #define IDR_PNG_LINK 126
26 | #define IDR_PNG_LOCK 127
27 | #define IDR_PNG_MUSIC 128
28 | #define IDR_PNG_NET 129
29 | #define IDR_PNG_OK 130
30 | #define IDR_PNG_PC 131
31 | #define IDR_PNG_PDF 132
32 | #define IDR_PNG_REFRESH 133
33 | #define IDR_PNG_RM 134
34 | #define IDR_PNG_SERVER 135
35 | #define IDR_PNG_SETTINGS 136
36 | #define IDR_PNG_TXT 137
37 | #define IDR_PNG_UNKNOWN 138
38 | #define IDR_PNG_UNLOCK 139
39 | #define IDR_PNG_UP 140
40 | #define IDR_PNG_VIDEO 141
41 | #define IDR_PNG_WIN 142
42 |
43 | #define IDR_PNG_MAX 143
44 |
45 | #define IDC_PROG_TEXT 1001
46 |
--------------------------------------------------------------------------------
/include/version.h:
--------------------------------------------------------------------------------
1 | /*
2 | * NkArc
3 | * Copyright (C) 2023 A1ive
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #pragma once
20 |
21 | #define QUOTE_(x) #x
22 | #define QUOTE(x) QUOTE_(x)
23 |
24 | #define NKGUI_MAJOR_VERSION 0
25 | #define NKGUI_MINOR_VERSION 1
26 | #define NKGUI_MICRO_VERSION 0
27 | #define NKGUI_BUILD_VERSION 0
28 |
29 | #define NKGUI_VERSION NKGUI_MAJOR_VERSION,NKGUI_MINOR_VERSION,NKGUI_MICRO_VERSION,NKGUI_BUILD_VERSION
30 | #define NKGUI_VERSION_STR QUOTE(NKGUI_MAJOR_VERSION.NKGUI_MINOR_VERSION.NKGUI_MICRO_VERSION.NKGUI_BUILD_VERSION)
31 |
32 | #define NKGUI_COMPANY "A1ive"
33 | #define NKGUI_COPYRIGHT "Copyright (c) 2023 A1ive"
34 | #define NKGUI_FILEDESC "NkArc"
35 |
36 | #define NKGUI_NAME "NkArc"
37 |
--------------------------------------------------------------------------------
/lang.c:
--------------------------------------------------------------------------------
1 | /*
2 | * NkArc
3 | * Copyright (C) 2023 A1ive
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #include
20 | #include
21 |
22 | static const char* lang_en_us[LANG_STRMAX] =
23 | {
24 | u8"Up",
25 | u8"Refresh Files",
26 | u8"Extract Selected Files",
27 | u8"About",
28 | u8"[COMPUTER]",
29 | u8"Unmount Disk",
30 | u8"Disk Info",
31 | u8"View Hex",
32 | u8"Cancel",
33 | u8"Refresh Disks",
34 | u8"View Image",
35 | u8"Mount Disk",
36 | u8"Get Checksum",
37 | u8"Extract File",
38 | u8"Name",
39 | u8"Driver",
40 | u8"Size",
41 | u8"Parent",
42 | u8"Filesystem",
43 | u8"Label",
44 | u8"FS UUID",
45 | u8"UNKNOWN",
46 | u8"DIR",
47 | u8"CALC",
48 | u8"No decompress",
49 | u8"Mount",
50 | };
51 |
52 | static const wchar_t* langw_en_us[LANG_WCSMAX] =
53 | {
54 | L"INFO",
55 | L"DONE",
56 | L"FAIL",
57 | L"Select target folder",
58 | L"ERROR",
59 | L"CANNOT OPEN FILE",
60 | L"FILE TOO LARGE",
61 | L"OUT OF MEMORY",
62 | };
63 |
64 | static const char* lang_zh_cn[LANG_STRMAX] =
65 | {
66 | u8"向上",
67 | u8"刷新文件",
68 | u8"提取选中文件",
69 | u8"关于",
70 | u8"[计算机]",
71 | u8"卸载磁盘",
72 | u8"磁盘信息",
73 | u8"查看十六进制",
74 | u8"取消",
75 | u8"刷新磁盘",
76 | u8"查看图像",
77 | u8"挂载磁盘",
78 | u8"获取校验和",
79 | u8"提取文件",
80 | u8"名称",
81 | u8"驱动",
82 | u8"大小",
83 | u8"父级",
84 | u8"文件系统",
85 | u8"卷标",
86 | u8"文件系统 UUID",
87 | u8"未知",
88 | u8"文件夹",
89 | u8"计算",
90 | u8"不解压",
91 | u8"挂载",
92 | };
93 |
94 | static const wchar_t* langw_zh_cn[LANG_WCSMAX] =
95 | {
96 | L"信息",
97 | L"完成",
98 | L"失败",
99 | L"选择目标文件夹",
100 | L"错误",
101 | L"无法打开文件",
102 | L"文件过大",
103 | L"内存不足",
104 | };
105 |
106 | static const char* lang_zh_tw[LANG_STRMAX] =
107 | {
108 | u8"向上",
109 | u8"重新整理檔案",
110 | u8"提取選中檔案",
111 | u8"關於",
112 | u8"[計算機]",
113 | u8"解除安裝磁碟",
114 | u8"磁碟資訊",
115 | u8"查看十六進制",
116 | u8"取消",
117 | u8"重新整理磁碟",
118 | u8"檢視影象",
119 | u8"掛載磁碟",
120 | u8"獲取校驗和",
121 | u8"提取檔案",
122 | };
123 |
124 | static const wchar_t* langw_zh_tw[LANG_WCSMAX] =
125 | {
126 | L"信息",
127 | L"完成",
128 | L"失敗",
129 | L"選擇目標資料夾",
130 | };
131 |
132 | const char*
133 | GET_STR(int id)
134 | {
135 | const char* text = NULL;
136 | switch (nk.lang)
137 | {
138 | case 2052: text = lang_zh_cn[id]; break;
139 | case 1028: text = lang_zh_tw[id]; break;
140 | }
141 | if (text == NULL)
142 | text = lang_en_us[id];
143 | return text;
144 | }
145 |
146 | const wchar_t*
147 | GET_WCS(int id)
148 | {
149 | const wchar_t* text = NULL;
150 | switch (nk.lang)
151 | {
152 | case 2052: text = langw_zh_cn[id]; break;
153 | case 1028: text = langw_zh_tw[id]; break;
154 | }
155 | if (text == NULL)
156 | text = langw_en_us[id];
157 | return text;
158 | }
159 |
--------------------------------------------------------------------------------
/main.c:
--------------------------------------------------------------------------------
1 | /*
2 | * NkArc
3 | * Copyright (C) 2023 A1ive
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #include
20 |
21 | static DWORD
22 | obtain_privileges(LPWSTR privilege)
23 | {
24 | HANDLE hToken;
25 | TOKEN_PRIVILEGES tkp = { 0 };
26 | BOOL res;
27 | // Obtain required privileges
28 | if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
29 | return GetLastError();
30 | res = LookupPrivilegeValueW(NULL, privilege, &tkp.Privileges[0].Luid);
31 | if (!res)
32 | return GetLastError();
33 | tkp.PrivilegeCount = 1;
34 | tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
35 | AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, (PTOKEN_PRIVILEGES)NULL, 0);
36 | return GetLastError();
37 | }
38 |
39 | int APIENTRY
40 | wWinMain(_In_ HINSTANCE hInstance,
41 | _In_opt_ HINSTANCE hPrevInstance,
42 | _In_ LPWSTR lpCmdLine,
43 | _In_ int nCmdShow)
44 | {
45 | obtain_privileges(SE_SYSTEM_ENVIRONMENT_NAME);
46 | nkctx_init(hInstance,
47 | 100, 100, 900, 600,
48 | L"NkWindowClass", L"Demo",
49 | L"Courier New", 16);
50 | nkctx_loop();
51 | nkctx_fini(0);
52 | return 0;
53 | }
54 |
--------------------------------------------------------------------------------
/mount_file.c:
--------------------------------------------------------------------------------
1 | /*
2 | * NkArc
3 | * Copyright (C) 2023 A1ive
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #include
20 | #include
21 | #include
22 |
23 | #include
24 | #include
25 | #include
26 |
27 | #define MAX_LOOPBACK_NAME 16
28 |
29 | static struct
30 | {
31 | unsigned long id;
32 | char* path;
33 | int decompress;
34 | char name[MAX_LOOPBACK_NAME];
35 | } m_ctx;
36 |
37 | static void
38 | nkctx_mount_init(const char* path)
39 | {
40 | m_ctx.path = grub_strdup(path);
41 | m_ctx.decompress = 1;
42 | grub_snprintf(m_ctx.name, MAX_LOOPBACK_NAME, "ld%lu", m_ctx.id);
43 | }
44 |
45 | static void
46 | nkctx_mount_fini(void)
47 | {
48 | grub_free(m_ctx.path);
49 | m_ctx.path = NULL;
50 | }
51 |
52 | static nk_bool
53 | name_filter(const struct nk_text_edit* box, nk_rune unicode)
54 | {
55 | NK_UNUSED(box);
56 | // A - Z, a - z, 0 - 9
57 | if (unicode >= 'A' && unicode <= 'Z')
58 | return nk_true;
59 | if (unicode >= 'a' && unicode <= 'z')
60 | return nk_true;
61 | if (unicode >= '0' && unicode <= '9')
62 | return nk_true;
63 | return nk_false;
64 | }
65 |
66 | static void
67 | mount_file(void)
68 | {
69 | grub_loopback_add(m_ctx.name, m_ctx.path, m_ctx.decompress);
70 | m_ctx.id++;
71 | nkctx_free_disk();
72 | nkctx_enum_disk();
73 | for (struct nkctx_disk* info = nk.disks; info; info = info->next)
74 | {
75 | if (grub_strcmp(m_ctx.name, info->name) != 0)
76 | continue;
77 | nk.disk_index = info->index;
78 | nkctx_enum_file(info->path);
79 | break;
80 | }
81 | nkctx_mount_fini();
82 | }
83 |
84 | static void
85 | nkctx_mount_window(struct nk_context* ctx, float width, float height)
86 | {
87 | if (!m_ctx.path)
88 | return;
89 | if (!nk_begin(ctx, "Mount",
90 | nk_rect(width / 4.0f, height / 3.0f, width / 2.0f, height / 3.0f),
91 | NK_WINDOW_BORDER | NK_WINDOW_MOVABLE | NK_WINDOW_SCALABLE | NK_WINDOW_CLOSABLE))
92 | {
93 | nkctx_mount_fini();
94 | goto out;
95 | }
96 |
97 | nk_layout_row_dynamic(ctx, 0, 1);
98 | nk_label(ctx, m_ctx.path, NK_TEXT_LEFT);
99 |
100 | nk_checkbox_label(ctx, GET_STR(LANG_STR_NO_DECOMP), &m_ctx.decompress);
101 |
102 | nk_edit_string_zero_terminated(ctx, NK_EDIT_FIELD, m_ctx.name, MAX_LOOPBACK_NAME, name_filter);
103 |
104 | if (nk_button_label(ctx, GET_STR(LANG_STR_MOUNT)) && m_ctx.name[0])
105 | mount_file();
106 |
107 | out:
108 | nk_end(ctx);
109 | }
110 |
111 | struct nkctx_window nkctx_mount =
112 | {
113 | .init = nkctx_mount_init,
114 | .fini = nkctx_mount_fini,
115 | .window = nkctx_mount_window,
116 | };
117 |
--------------------------------------------------------------------------------
/nuklear.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/a1ive/NkArc/542297e75cfa4b0f53690decaa9b034922317ad6/nuklear.ico
--------------------------------------------------------------------------------
/nuklear.rc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/a1ive/NkArc/542297e75cfa4b0f53690decaa9b034922317ad6/nuklear.rc
--------------------------------------------------------------------------------
/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------