Lines Matching refs:drive
54 int CheckValid(const struct drive *drive) { in CheckValid() argument
55 if ((drive->gpt.valid_headers != MASK_BOTH) || in CheckValid()
56 (drive->gpt.valid_entries != MASK_BOTH)) { in CheckValid()
63 int Load(struct drive *drive, uint8_t **buf, in Load() argument
86 if (-1 == lseek(drive->fd, sector * sector_bytes, SEEK_SET)) { in Load()
91 nread = read(drive->fd, *buf, count); in Load()
106 int ReadPMBR(struct drive *drive) { in ReadPMBR() argument
107 if (-1 == lseek(drive->fd, 0, SEEK_SET)) in ReadPMBR()
110 int nread = read(drive->fd, &drive->pmbr, sizeof(struct pmbr)); in ReadPMBR()
117 int WritePMBR(struct drive *drive) { in WritePMBR() argument
118 if (-1 == lseek(drive->fd, 0, SEEK_SET)) in WritePMBR()
121 int nwrote = write(drive->fd, &drive->pmbr, sizeof(struct pmbr)); in WritePMBR()
128 int Save(struct drive *drive, const uint8_t *buf, in Save() argument
138 if (-1 == lseek(drive->fd, sector * sector_bytes, SEEK_SET)) in Save()
141 nwrote = write(drive->fd, buf, count); in Save()
148 static int GptLoad(struct drive *drive, uint32_t sector_bytes) { in GptLoad() argument
149 drive->gpt.sector_bytes = sector_bytes; in GptLoad()
150 if (drive->size % drive->gpt.sector_bytes) { in GptLoad()
152 (long long unsigned int)drive->size, drive->gpt.sector_bytes); in GptLoad()
155 drive->gpt.streaming_drive_sectors = drive->size / drive->gpt.sector_bytes; in GptLoad()
158 if (!(drive->gpt.flags & GPT_FLAG_EXTERNAL)) { in GptLoad()
159 drive->gpt.gpt_drive_sectors = drive->gpt.streaming_drive_sectors; in GptLoad()
163 if (CGPT_OK != Load(drive, &drive->gpt.primary_header, in GptLoad()
165 drive->gpt.sector_bytes, GPT_HEADER_SECTORS)) { in GptLoad()
169 if (CGPT_OK != Load(drive, &drive->gpt.secondary_header, in GptLoad()
170 drive->gpt.gpt_drive_sectors - GPT_PMBR_SECTORS, in GptLoad()
171 drive->gpt.sector_bytes, GPT_HEADER_SECTORS)) { in GptLoad()
175 GptHeader* primary_header = (GptHeader*)drive->gpt.primary_header; in GptLoad()
176 if (CheckHeader(primary_header, 0, drive->gpt.streaming_drive_sectors, in GptLoad()
177 drive->gpt.gpt_drive_sectors, in GptLoad()
178 drive->gpt.flags) == 0) { in GptLoad()
179 if (CGPT_OK != Load(drive, &drive->gpt.primary_entries, in GptLoad()
181 drive->gpt.sector_bytes, in GptLoad()
189 GptHeader* secondary_header = (GptHeader*)drive->gpt.secondary_header; in GptLoad()
190 if (CheckHeader(secondary_header, 1, drive->gpt.streaming_drive_sectors, in GptLoad()
191 drive->gpt.gpt_drive_sectors, in GptLoad()
192 drive->gpt.flags) == 0) { in GptLoad()
193 if (CGPT_OK != Load(drive, &drive->gpt.secondary_entries, in GptLoad()
195 drive->gpt.sector_bytes, in GptLoad()
206 static int GptSave(struct drive *drive) { in GptSave() argument
208 if (drive->gpt.modified & GPT_MODIFIED_HEADER1) { in GptSave()
209 if (CGPT_OK != Save(drive, drive->gpt.primary_header, in GptSave()
211 drive->gpt.sector_bytes, GPT_HEADER_SECTORS)) { in GptSave()
217 if (drive->gpt.modified & GPT_MODIFIED_HEADER2) { in GptSave()
218 if(CGPT_OK != Save(drive, drive->gpt.secondary_header, in GptSave()
219 drive->gpt.gpt_drive_sectors - GPT_PMBR_SECTORS, in GptSave()
220 drive->gpt.sector_bytes, GPT_HEADER_SECTORS)) { in GptSave()
225 GptHeader* primary_header = (GptHeader*)drive->gpt.primary_header; in GptSave()
226 if (drive->gpt.modified & GPT_MODIFIED_ENTRIES1) { in GptSave()
227 if (CGPT_OK != Save(drive, drive->gpt.primary_entries, in GptSave()
229 drive->gpt.sector_bytes, in GptSave()
235 GptHeader* secondary_header = (GptHeader*)drive->gpt.secondary_header; in GptSave()
236 if (drive->gpt.modified & GPT_MODIFIED_ENTRIES2) { in GptSave()
237 if (CGPT_OK != Save(drive, drive->gpt.secondary_entries, in GptSave()
239 drive->gpt.sector_bytes, in GptSave()
246 if (drive->gpt.primary_header) in GptSave()
247 free(drive->gpt.primary_header); in GptSave()
248 drive->gpt.primary_header = 0; in GptSave()
249 if (drive->gpt.primary_entries) in GptSave()
250 free(drive->gpt.primary_entries); in GptSave()
251 drive->gpt.primary_entries = 0; in GptSave()
252 if (drive->gpt.secondary_header) in GptSave()
253 free(drive->gpt.secondary_header); in GptSave()
254 drive->gpt.secondary_header = 0; in GptSave()
255 if (drive->gpt.secondary_entries) in GptSave()
256 free(drive->gpt.secondary_entries); in GptSave()
257 drive->gpt.secondary_entries = 0; in GptSave()
289 int DriveOpen(const char *drive_path, struct drive *drive, int mode, in DriveOpen() argument
294 require(drive); in DriveOpen()
297 memset(drive, 0, sizeof(struct drive)); in DriveOpen()
299 drive->fd = open(drive_path, mode | in DriveOpen()
304 if (drive->fd == -1) { in DriveOpen()
311 if (ObtainDriveSize(drive->fd, &gpt_drive_size, §or_bytes) != 0) { in DriveOpen()
317 drive->gpt.gpt_drive_sectors = gpt_drive_size / sector_bytes; in DriveOpen()
319 drive->size = gpt_drive_size; in DriveOpen()
320 drive->gpt.flags = 0; in DriveOpen()
322 drive->size = drive_size; in DriveOpen()
323 drive->gpt.flags = GPT_FLAG_EXTERNAL; in DriveOpen()
327 if (GptLoad(drive, sector_bytes)) { in DriveOpen()
335 (void) DriveClose(drive, 0); in DriveOpen()
340 int DriveClose(struct drive *drive, int update_as_needed) { in DriveClose() argument
344 if (GptSave(drive)) { in DriveClose()
352 fsync(drive->fd); in DriveClose()
354 close(drive->fd); in DriveClose()
697 uint32_t GetNumberOfEntries(const struct drive *drive) { in GetNumberOfEntries() argument
698 GptHeader *header = GetGptHeader(&drive->gpt); in GetNumberOfEntries()
729 void SetPriority(struct drive *drive, int secondary, uint32_t entry_index, in SetPriority() argument
733 entry = GetEntry(&drive->gpt, secondary, entry_index); in SetPriority()
737 int GetPriority(struct drive *drive, int secondary, uint32_t entry_index) { in GetPriority() argument
739 entry = GetEntry(&drive->gpt, secondary, entry_index); in GetPriority()
743 void SetTries(struct drive *drive, int secondary, uint32_t entry_index, in SetTries() argument
747 entry = GetEntry(&drive->gpt, secondary, entry_index); in SetTries()
751 int GetTries(struct drive *drive, int secondary, uint32_t entry_index) { in GetTries() argument
753 entry = GetEntry(&drive->gpt, secondary, entry_index); in GetTries()
757 void SetSuccessful(struct drive *drive, int secondary, uint32_t entry_index, in SetSuccessful() argument
761 entry = GetEntry(&drive->gpt, secondary, entry_index); in SetSuccessful()
765 int GetSuccessful(struct drive *drive, int secondary, uint32_t entry_index) { in GetSuccessful() argument
767 entry = GetEntry(&drive->gpt, secondary, entry_index); in GetSuccessful()
771 void SetRaw(struct drive *drive, int secondary, uint32_t entry_index, in SetRaw() argument
774 entry = GetEntry(&drive->gpt, secondary, entry_index); in SetRaw()
778 void UpdateAllEntries(struct drive *drive) { in UpdateAllEntries() argument
779 RepairEntries(&drive->gpt, MASK_PRIMARY); in UpdateAllEntries()
780 RepairHeader(&drive->gpt, MASK_PRIMARY); in UpdateAllEntries()
782 drive->gpt.modified |= (GPT_MODIFIED_HEADER1 | GPT_MODIFIED_ENTRIES1 | in UpdateAllEntries()
784 UpdateCrc(&drive->gpt); in UpdateAllEntries()
787 int IsUnused(struct drive *drive, int secondary, uint32_t index) { in IsUnused() argument
789 entry = GetEntry(&drive->gpt, secondary, index); in IsUnused()
793 int IsKernel(struct drive *drive, int secondary, uint32_t index) { in IsKernel() argument
795 entry = GetEntry(&drive->gpt, secondary, index); in IsKernel()
968 struct drive drive; in CgptGetNumNonEmptyPartitions() local
975 if (CGPT_OK != DriveOpen(params->drive_name, &drive, O_RDONLY, in CgptGetNumNonEmptyPartitions()
979 if (GPT_SUCCESS != (gpt_retval = GptSanityCheck(&drive.gpt))) { in CgptGetNumNonEmptyPartitions()
987 int numEntries = GetNumberOfEntries(&drive); in CgptGetNumNonEmptyPartitions()
990 GptEntry *entry = GetEntry(&drive.gpt, ANY_VALID, i); in CgptGetNumNonEmptyPartitions()
1000 DriveClose(&drive, 0); in CgptGetNumNonEmptyPartitions()