/* * Print an MBR disk signature for use in a Linux PARTUUID * * Copyright (C) 2020 Patrick McDermott * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include #include #include #include static int read_id(const char *dev) { FILE *fp; uint8_t id[4]; if ((fp = fopen(dev, "r")) == NULL) { perror("Failed to open device"); return 1; } if (fseek(fp, 440L, SEEK_SET) != 0) { perror("Failed to seek on device"); fclose(fp); return 1; } if (fread(id, sizeof(*id), sizeof(id) / sizeof(*id), fp) != 4) { perror("Failed to read from device"); fclose(fp); return 1; } printf("%02" PRIx8 "%02" PRIx8 "%02" PRIx8 "%02" PRIx8 "\n", id[3], id[2], id[1], id[0]); fclose(fp); return 0; } int main(int argc, char *argv[]) { int errors = 0; while (--argc) { errors += read_id(*++argv); } return (errors > 0) ? EXIT_FAILURE : EXIT_SUCCESS; }