| OLD | NEW | 
|---|
| 1 /* Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 /* Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 
| 2  * Use of this source code is governed by a BSD-style license that can be | 2  * Use of this source code is governed by a BSD-style license that can be | 
| 3  * found in the LICENSE file. | 3  * found in the LICENSE file. | 
| 4  * | 4  * | 
| 5  * Header file for cgpt. | 5  * Header file for cgpt. | 
| 6  */ | 6  */ | 
| 7 #ifndef VBOOT_REFERENCE_UTILITY_CGPT_CGPT_H_ | 7 #ifndef VBOOT_REFERENCE_UTILITY_CGPT_CGPT_H_ | 
| 8 #define VBOOT_REFERENCE_UTILITY_CGPT_CGPT_H_ | 8 #define VBOOT_REFERENCE_UTILITY_CGPT_CGPT_H_ | 
| 9 | 9 | 
| 10 #include <getopt.h> | 10 #include <getopt.h> | 
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 44    * if invalid. */ | 44    * if invalid. */ | 
| 45   int (*validator)(const char *argument, void *valid_range, void *parsed); | 45   int (*validator)(const char *argument, void *valid_range, void *parsed); | 
| 46   void *valid_range;  /* The structure passed to validator. */ | 46   void *valid_range;  /* The structure passed to validator. */ | 
| 47   void *parsed;  /* The structure passed to validator. */ | 47   void *parsed;  /* The structure passed to validator. */ | 
| 48 }; | 48 }; | 
| 49 | 49 | 
| 50 /* This is a special 'validator'. It assists those options without an argument, | 50 /* This is a special 'validator'. It assists those options without an argument, | 
| 51  * i.e. help, to indicate the option is present. */ | 51  * i.e. help, to indicate the option is present. */ | 
| 52 int AssignTrue(const char *argument, void *pointer, void *integer); | 52 int AssignTrue(const char *argument, void *pointer, void *integer); | 
| 53 | 53 | 
|  | 54 /* Special validator. Copy string to 'parsed' with max 'valid_range' bytes. */ | 
|  | 55 int CopyString(const char *argument, void *max_len, void *dst); | 
|  | 56 | 
|  | 57 /* Validator function. Returns 1 if 'argument' is between 'max' and 'min' | 
|  | 58  * in 'valid_range'. */ | 
| 54 struct number_range { | 59 struct number_range { | 
| 55   int max; | 60   int max; | 
| 56   int min; | 61   int min; | 
| 57 }; | 62 }; | 
| 58 |  | 
| 59 /* Validator function. Returns 1 if 'argument' is between 'max' and 'min' |  | 
| 60  * in 'valid_range'. */ |  | 
| 61 int InNumberRange(const char *argument, void *valid_range, void *parsed); | 63 int InNumberRange(const char *argument, void *valid_range, void *parsed); | 
| 62 | 64 | 
| 63 void ShowOptions(const struct option *opts, | 65 void ShowOptions(const struct option *opts, | 
| 64                  const struct option_details *details, | 66                  const struct option_details *details, | 
| 65                  const int num); | 67                  const int num); | 
| 66 | 68 | 
| 67 /* Handles all options from given argc and argv. This function supports both | 69 /* Handles all options from given argc and argv. This function supports both | 
| 68  * short and long options. | 70  * short and long options. | 
| 69  * | 71  * | 
| 70  * Assumptions: | 72  * Assumptions: | 
| (...skipping 19 matching lines...) Expand all  Loading... | 
| 90                             struct drive *drive); | 92                             struct drive *drive); | 
| 91 | 93 | 
| 92 /* GUID conversion functions. Accepted format: | 94 /* GUID conversion functions. Accepted format: | 
| 93  * | 95  * | 
| 94  *   "C12A7328-F81F-11D2-BA4B-00A0C93EC93B" | 96  *   "C12A7328-F81F-11D2-BA4B-00A0C93EC93B" | 
| 95  * | 97  * | 
| 96  * At least GUID_STRLEN bytes should be reserved in 'str' (included the tailing | 98  * At least GUID_STRLEN bytes should be reserved in 'str' (included the tailing | 
| 97  * '\0'). | 99  * '\0'). | 
| 98  */ | 100  */ | 
| 99 #define GUID_STRLEN 37 | 101 #define GUID_STRLEN 37 | 
| 100 void StrToGuid(const char *str, Guid *guid); | 102 int StrToGuid(const char *str, Guid *guid); | 
| 101 void GuidToStr(const Guid *guid, char *str); | 103 void GuidToStr(const Guid *guid, char *str); | 
| 102 | 104 | 
| 103 /* Convert UTF16 string to UTF8. Rewritten from gpt utility. | 105 /* Convert UTF16 string to UTF8. Rewritten from gpt utility. | 
| 104  * Caller must prepare enough space for UTF8. The rough estimation is: | 106  * Caller must prepare enough space for UTF8. The rough estimation is: | 
| 105  * | 107  * | 
| 106  *   utf8 length = bytecount(utf16) * 1.5 | 108  *   utf8 length = bytecount(utf16) * 1.5 | 
| 107  */ | 109  */ | 
| 108 void UTF16ToUTF8(const uint16_t *utf16, uint8_t *utf8); | 110 void UTF16ToUTF8(const uint16_t *utf16, uint8_t *utf8); | 
| 109 /* Convert UTF8 string to UTF16. Rewritten from gpt utility. | 111 /* Convert UTF8 string to UTF16. Rewritten from gpt utility. | 
| 110  * Caller must prepare enough space for UTF16. The conservative estimation is: | 112  * Caller must prepare enough space for UTF16. The conservative estimation is: | 
| 111  * | 113  * | 
| 112  *   utf16 bytecount = bytecount(utf8) / 3 * 4 | 114  *   utf16 bytecount = bytecount(utf8) / 3 * 4 | 
| 113  */ | 115  */ | 
| 114 void UTF8ToUTF16(const uint8_t *utf8, uint16_t *utf16); | 116 void UTF8ToUTF16(const uint8_t *utf8, uint16_t *utf16); | 
| 115 | 117 | 
|  | 118 /* Helper functions for supported GPT types. */ | 
|  | 119 int ResolveType(const Guid *type, char *buf); | 
|  | 120 int SupportedType(const char *name, Guid *type); | 
|  | 121 void PrintTypes(void); | 
|  | 122 | 
| 116 /* Describes the drive storing the GPT. */ | 123 /* Describes the drive storing the GPT. */ | 
| 117 struct drive { | 124 struct drive { | 
| 118   int inited;       /* indicated if this structure is valid */ | 125   int inited;       /* indicated if this structure is valid */ | 
| 119   int fd;           /* file descriptor */ | 126   int fd;           /* file descriptor */ | 
| 120   uint64_t size;    /* total size (in bytes) */ | 127   uint64_t size;    /* total size (in bytes) */ | 
| 121   GptData gpt; | 128   GptData gpt; | 
| 122 }; | 129 }; | 
| 123 | 130 | 
| 124 extern const char* progname; | 131 extern const char* progname; | 
| 125 | 132 | 
| 126 /* Given a hard drive path, this function loads GPT sectors from that drive, | 133 /* Given a hard drive path, this function loads GPT sectors from that drive, | 
| 127  * and fills 'drive' structure. All memory allocated in drive_open() will be | 134  * and fills 'drive' structure. All memory allocated in drive_open() will be | 
| 128  * freed at drive_close(). | 135  * freed at drive_close(). | 
| 129  * | 136  * | 
| 130  * If 'drive_path' starts with '/', it is treated as absolute path. | 137  * If 'drive_path' starts with '/', it is treated as absolute path. | 
| 131  * If 'drive_path' starts with '.', it is treated as relative path. | 138  * If 'drive_path' starts with '.', it is treated as relative path. | 
| 132  * Otherwise, it will be prepended with '/dev/' to comply with gpt. | 139  * Otherwise, it will be prepended with '/dev/' to comply with gpt. | 
| 133  * | 140  * | 
| 134  * Returns CGPT_FAILED if any error happens. | 141  * Returns CGPT_FAILED if any error happens. | 
| 135  * Returns CGPT_OK if success and information are stored in 'drive'. | 142  * Returns CGPT_OK if success and information are stored in 'drive'. | 
| 136  */ | 143  */ | 
| 137 int DriveOpen(const char *drive_path, struct drive *drive); | 144 int DriveOpen(const char *drive_path, struct drive *drive); | 
| 138 int DriveClose(struct drive *drive); | 145 int DriveClose(struct drive *drive); | 
| 139 int CheckValid(const struct drive *drive); | 146 int CheckValid(const struct drive *drive); | 
| 140 | 147 | 
| 141 /* Function declarations for commands. | 148 /* Function declarations for commands. | 
| 142  * The return value of these functions is passed to main()'s exit value. */ | 149  * The return value of these functions is passed to main()'s exit value. */ | 
|  | 150 int CgptAdm(int argc, char *argv[]); | 
| 143 int CgptAttribute(int argc, char *argv[]); | 151 int CgptAttribute(int argc, char *argv[]); | 
|  | 152 int CgptDev(int argc, char *argv[]); | 
| 144 int CgptRepair(int argc, char *argv[]); | 153 int CgptRepair(int argc, char *argv[]); | 
| 145 int CgptShow(int argc, char *argv[]); | 154 int CgptShow(int argc, char *argv[]); | 
| 146 | 155 | 
| 147 #endif  /* VBOOT_REFERENCE_UTILITY_CGPT_CGPT_H_ */ | 156 #endif  /* VBOOT_REFERENCE_UTILITY_CGPT_CGPT_H_ */ | 
| OLD | NEW | 
|---|