|
|
1.1 ! root 1: #define _DDI_DKI 1 ! 2: #define _SYSV4 1 ! 3: ! 4: /* ! 5: * This program performs some simple processing on a device master-file, ! 6: * mdevice (4) as specified in the "System File and Devices Reference ! 7: * Manual" for Unix System V, Release 4. ! 8: * ! 9: * The first part of the program inhales the 'mdevice' file. Other processing ! 10: * is dependent on the internal details of the character-device interface ! 11: * used by Coherent - our aim is to supply details for a mapping layer that ! 12: * converts the Coherent device system calling format. ! 13: */ ! 14: /* ! 15: *-IMPORTS: ! 16: * <sys/compat.h> ! 17: * CONST ! 18: * PROTO ! 19: * ARGS () ! 20: * LOCAL ! 21: * <stdlib.h> ! 22: * EXIT_SUCCESS ! 23: * EXIT_FAILURE ! 24: * NULL ! 25: * free () ! 26: * malloc () ! 27: * <unistd.h> ! 28: * STDERR_FILENO ! 29: * "mdev.h" ! 30: * read_mdev_file () ! 31: * "sdev.h" ! 32: * read_sdev_file () ! 33: * "symbol.h" ! 34: * symbol_init () ! 35: * "assign.h" ! 36: * assign_imajors () ! 37: * "mkconf.c" ! 38: * write_conf_c () ! 39: */ ! 40: ! 41: #include <sys/compat.h> ! 42: #include <stdlib.h> ! 43: #include <unistd.h> ! 44: #include <stdio.h> ! 45: #include <string.h> ! 46: #include <errno.h> ! 47: ! 48: #include "mdev.h" ! 49: #include "sdev.h" ! 50: #include "mtune.h" ! 51: #include "stune.h" ! 52: #include "symbol.h" ! 53: #include "assign.h" ! 54: #include "mkconf.h" ! 55: #include "ehand.h" ! 56: ! 57: /* ! 58: * Some ancient systems do not define EXIT_SUCCESS or EXIT_FAILURE. ! 59: */ ! 60: ! 61: #ifndef EXIT_SUCCESS ! 62: #define EXIT_SUCCESS 0 ! 63: #define EXIT_FAILURE 1 ! 64: #endif ! 65: ! 66: ! 67: LOCAL int _report_mode = 0; ! 68: ! 69: /* ! 70: * Test whether we are in report mode or not. ! 71: */ ! 72: ! 73: #if USE_PROTO ! 74: int (report_mode) (void) ! 75: #else ! 76: int ! 77: report_mode ARGS (()) ! 78: #endif ! 79: { ! 80: return _report_mode; ! 81: } ! 82: ! 83: ! 84: /* ! 85: * For some applications, we need to be able to report conflicts in a special ! 86: * way. By convention, "item1" is something new and "item2" is the old item ! 87: * that it conflicts with. ! 88: */ ! 89: ! 90: #if USE_PROTO ! 91: void (report_conflict) (CONST unsigned char * item1, ! 92: CONST unsigned char * item2, CONST char * msg) ! 93: #else ! 94: void ! 95: report_conflict ARGS ((item1, item2, msg)) ! 96: CONST unsigned char * item1; ! 97: CONST unsigned char * item2; ! 98: CONST char * msg; ! 99: #endif ! 100: { ! 101: if (_report_mode) ! 102: fprintf (stdout, "%s ", item2); ! 103: else ! 104: fprintf (stderr, "%s: %s with %s\n", item1, msg, item2); ! 105: } ! 106: ! 107: #if TRACE ! 108: /* ! 109: * If some modules have been compiled with debugging on, this enables that ! 110: * debugging output with -V ! 111: */ ! 112: ! 113: int do_debug; ! 114: #endif ! 115: ! 116: ! 117: #if USE_PROTO ! 118: void usage (void) ! 119: #else ! 120: void ! 121: usage () ! 122: #endif ! 123: { ! 124: static char usage_msg [] = { ! 125: "Usage:\t-d\t\tGenerate device configuration tables and makefiles\n" ! 126: "\t-t\t\tGenerate tunable parameter tables\n" ! 127: "\t-M mdevice\tSet a line in \"mdevice\" to the values in the argument\n" ! 128: "\t-S sdevice\tSet a line in \"sdevice\" to the values in the argument\n" ! 129: "\t-m mtune\tSet a line in \"mtune\" to the values in the argument\n" ! 130: "\t-s stune\tSet a line in \"stune\" to the values in the argument\n" ! 131: "\t-W\t\tWrite out changed files\n" ! 132: "\t-r\t\tReport conflicts caused by proposed changes\n" ! 133: "\t-I dir\t\tDirectory where files are located\n" ! 134: }; ! 135: ! 136: write (STDERR_FILENO, usage_msg, sizeof (usage_msg) - 1); ! 137: } ! 138: ! 139: ! 140: #if USE_PROTO ! 141: int main (int argc, char * argv []) ! 142: #else ! 143: int ! 144: main (argc, argv) ! 145: int argc; ! 146: char * argv []; ! 147: #endif ! 148: { ! 149: extinfo_t * extinfop; ! 150: int do_devices = 0; ! 151: int do_tune = 0; ! 152: int need_mdev = 0; ! 153: int need_sdev = 0; ! 154: int need_mtune = 0; ! 155: int need_stune = 0; ! 156: int write_changes = 0; ! 157: mdev_t * mdev_changes = NULL; ! 158: sdev_t * sdev_changes = NULL; ! 159: mtune_t * mtune_changes = NULL; ! 160: stune_t * stune_changes = NULL; ! 161: int i; ! 162: ! 163: symbol_init (); ! 164: ! 165: if (argc == 1) { ! 166: ! 167: usage (); ! 168: return EXIT_FAILURE; ! 169: } ! 170: ! 171: for (i = 1 ; i < argc ; i ++) { ! 172: int switches; ! 173: int j; ! 174: ! 175: if (argv [i][0] != '-') { ! 176: usage (); ! 177: return EXIT_FAILURE; ! 178: } ! 179: ! 180: switches = strlen (argv [i]); ! 181: ! 182: for (j = 1 ; j < switches ; j ++) { ! 183: char * string_arg; ! 184: int next_arg; ! 185: ! 186: if (argv [i][j + 1] == 0) ! 187: string_arg = argv [next_arg = i + 1]; ! 188: else ! 189: string_arg = & argv [next_arg = i][j + 1]; ! 190: ! 191: ! 192: switch (argv [i][j]) { ! 193: ! 194: case 'd': ! 195: do_devices ++; ! 196: need_mdev ++; ! 197: need_sdev ++; ! 198: break; ! 199: ! 200: case 't': ! 201: do_tune ++; ! 202: need_mtune ++; ! 203: need_stune ++; ! 204: break; ! 205: ! 206: #if TRACE ! 207: case 'V': ! 208: do_debug ++; ! 209: need_mdev ++; ! 210: need_sdev ++; ! 211: need_mtune ++; ! 212: need_stune ++; ! 213: break; ! 214: #endif ! 215: ! 216: case 'M': ! 217: read_mdev_string (string_arg, & mdev_changes); ! 218: need_mdev ++; ! 219: switches = 0; ! 220: break; ! 221: ! 222: case 'S': ! 223: read_sdev_string (string_arg, & sdev_changes); ! 224: need_mdev ++; ! 225: need_sdev ++; ! 226: switches = 0; ! 227: break; ! 228: ! 229: case 'm': ! 230: read_mtune_string (string_arg, ! 231: & mtune_changes); ! 232: need_mtune ++; ! 233: switches = 0; ! 234: break; ! 235: ! 236: case 's': ! 237: read_stune_string (string_arg, ! 238: & stune_changes); ! 239: need_mtune ++; ! 240: need_stune ++; ! 241: switches = 0; ! 242: break; ! 243: ! 244: case 'I': ! 245: if (chdir (string_arg) == 0) { ! 246: switches = 0; ! 247: break; ! 248: } ! 249: ! 250: throw_error ("Cannot change directory to %s, " ! 251: "OS says %s", string_arg, ! 252: strerror (errno)); ! 253: return EXIT_FAILURE; ! 254: ! 255: case 'W': ! 256: write_changes ++; ! 257: break; ! 258: ! 259: case 'r': ! 260: _report_mode ++; ! 261: break; ! 262: ! 263: default: ! 264: usage (); ! 265: return EXIT_FAILURE; ! 266: } ! 267: ! 268: if (switches == 0) { ! 269: i = next_arg; ! 270: break; ! 271: } ! 272: } ! 273: } ! 274: ! 275: if (need_mdev) { ! 276: need_mdev = mdev_changes != NULL && write_changes; ! 277: read_mdev_file ("mdevice", need_mdev ? "mdevice.new" : NULL, ! 278: & mdev_changes); ! 279: } ! 280: if (need_sdev) { ! 281: need_sdev = sdev_changes != NULL && write_changes; ! 282: read_sdev_file ("sdevice", need_sdev ? "sdevice.new" : NULL, ! 283: & sdev_changes); ! 284: } ! 285: if (need_mtune) { ! 286: need_mtune = mtune_changes != NULL && write_changes; ! 287: read_mtune_file ("mtune", need_mtune ? "mtune.new" : NULL, ! 288: & mtune_changes); ! 289: } ! 290: if (need_stune) { ! 291: need_stune = stune_changes != NULL && write_changes; ! 292: read_stune_file ("stune", need_stune ? "stune.new" : NULL, ! 293: & stune_changes); ! 294: } ! 295: ! 296: if (do_devices) { ! 297: if ((extinfop = assign_imajors ()) != NULL) { ! 298: ! 299: write_conf_c ("conf.c", extinfop); ! 300: free (extinfop); ! 301: } ! 302: ! 303: write_link ("drvbld.mak", "template.mak"); ! 304: } ! 305: ! 306: if (do_tune) ! 307: write_conf_h ("conf.h"); ! 308: ! 309: if (need_mdev) { ! 310: remove ("mdevice.old"); ! 311: if (rename ("mdevice", "mdevice.old") != 0 || ! 312: rename ("mdevice.new", "mdevice") != 0) ! 313: throw_error ("Unable to update 'mdevice' file with " ! 314: "new entries, OS says %s", ! 315: strerror (errno)); ! 316: } ! 317: if (need_sdev) { ! 318: remove ("sdevice.old"); ! 319: if (rename ("sdevice", "sdevice.old") != 0 || ! 320: rename ("sdevice.new", "sdevice") != 0) ! 321: throw_error ("Unable to update 'sdevice' file with " ! 322: "new entries, OS says %s", ! 323: strerror (errno)); ! 324: } ! 325: if (need_mtune) { ! 326: remove ("mtune.old"); ! 327: if (rename ("mtune", "mtune.old") != 0 || ! 328: rename ("mtune.new", "mtune") != 0) ! 329: throw_error ("Unable to update 'mtune' file with " ! 330: "new entries, OS says %s", ! 331: strerror (errno)); ! 332: } ! 333: if (need_stune) { ! 334: remove ("stune.old"); ! 335: if (rename ("stune", "stune.old") != 0 || ! 336: rename ("stune.new", "stune") != 0) ! 337: throw_error ("Unable to update 'stune' file with " ! 338: "new entries, OS says %s", ! 339: strerror (errno)); ! 340: } ! 341: return EXIT_SUCCESS; ! 342: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.