3 Volume Boot Record creation code.
5 Copyright (C) 2009, 2010 Andrew Nayenko
7 This program is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
26 off_t vbr_alignment(void)
33 return 12 * SECTOR_SIZE(sb);
36 int vbr_write(off_t base, int fd)
39 le32_t* sector = malloc(SECTOR_SIZE(sb));
45 if (write(fd, &sb, sizeof(struct exfat_super_block)) == -1)
50 checksum = exfat_vbr_start_checksum(&sb, sizeof(struct exfat_super_block));
52 memset(sector, 0, SECTOR_SIZE(sb));
53 sector[SECTOR_SIZE(sb) / sizeof(sector[0]) - 1] = cpu_to_le32(0xaa550000);
54 for (i = 0; i < 8; i++)
56 if (write(fd, sector, SECTOR_SIZE(sb)) == -1)
61 checksum = exfat_vbr_add_checksum(sector, SECTOR_SIZE(sb), checksum);
64 memset(sector, 0, SECTOR_SIZE(sb));
65 if (write(fd, sector, SECTOR_SIZE(sb)) == -1)
70 checksum = exfat_vbr_add_checksum(sector, SECTOR_SIZE(sb), checksum);
71 if (write(fd, sector, SECTOR_SIZE(sb)) == -1)
76 checksum = exfat_vbr_add_checksum(sector, SECTOR_SIZE(sb), checksum);
78 for (i = 0; i < SECTOR_SIZE(sb) / sizeof(sector[0]); i++)
79 sector[i] = cpu_to_le32(checksum);
80 if (write(fd, sector, SECTOR_SIZE(sb)) == -1)