diskdefs.h
Go to the documentation of this file.
1 /****
2  * diskdefs.h - Low-level definitions
3  *
4  * Copyright 2022 mikee47 <mike@sillyhouse.net>
5  *
6  * This file is part of the DiskStorage Library
7  *
8  * This library is free software: you can redistribute it and/or modify it under the terms of the
9  * GNU General Public License as published by the Free Software Foundation, version 3 or later.
10  *
11  * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
12  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13  * See the GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along with this library.
16  * If not, see <https://www.gnu.org/licenses/>.
17  *
18  ****/
19 
20 #pragma once
21 
22 #include <cstdint>
23 #include <cstddef>
24 #include <sys/pgmspace.h>
25 #include <Data/Uuid.h>
26 
27 #define DISK_MIN_SECTOR_SIZE 512
28 
29 #define FSTYPE_FAT 0x2020202020544146ULL // "FAT " 46 41 54 20 20 20 20 20
30 #define FSTYPE_FAT32 0x2020203233544146ULL // "FAT32 " 46 41 54 33 32 20 20 20
31 #define FSTYPE_EXFAT 0x2020205441465845ULL // "EXFAT " 45 58 46 41 54 20 20 20
32 
33 #define N_SEC_TRACK 63 // Sectors per track for determination of drive CHS
34 #define GPT_ITEMS 128 // Number of GPT table size (>=128, sector aligned)
35 
36 #define OSTYPE_EXTENDED 0x05
37 
38 namespace Storage
39 {
40 namespace Disk
41 {
42 namespace FAT
43 {
44 #include "linux/msdos_fs.h"
45 }
46 
47 namespace EXFAT
48 {
49 #include "linux/exfat_raw.h"
50 }
51 
52 #include "linux/efi.h"
53 
54 template <typename T> T align_up(T value, uint32_t align)
55 {
56  return (value + align - 1) & ~(T(align) - 1);
57 }
58 
59 template <typename T> auto getBlockCount(T byteCount, uint32_t blockSize)
60 {
61  return (byteCount + blockSize - 1) / blockSize;
62 }
63 
64 uint32_t crc32_byte(uint32_t crc, uint8_t d);
65 uint32_t crc32(uint32_t bcc, const void* data, size_t length);
66 
67 inline uint32_t crc32(const void* data, size_t length)
68 {
69  return crc32(0, data, length);
70 }
71 
72 } // namespace Disk
73 } // namespace Storage
T align_up(T value, uint32_t align)
Definition: diskdefs.h:54
Definition: FileDevice.h:25
uint32_t crc32(uint32_t bcc, const void *data, size_t length)
auto getBlockCount(T byteCount, uint32_t blockSize)
Definition: diskdefs.h:59
uint32_t crc32_byte(uint32_t crc, uint8_t d)