void SysAddCDROMPrefs(void) { // Don't scan for drives if nocdrom option given if (PrefsFindBool("nocdrom")) return; #if defined(__linux__) if (access("/dev/.devfsd", F_OK) < 0) PrefsAddString("cdrom", "/dev/cdrom"); else { DIR *cd_dir = opendir("/dev/cdroms"); if (cd_dir) { struct dirent *cdrom_dev; while ((cdrom_dev = readdir(cd_dir)) != NULL) { if (strcmp(cdrom_dev->d_name, ".") != 0 && strcmp(cdrom_dev->d_name, "..") != 0) { char cd_dev[20]; sprintf(cd_dev, "/dev/cdroms/%s", cdrom_dev->d_name); PrefsAddString("cdrom", cd_dev); } } closedir(cd_dir); } } #elif defined __MACOSX__ // There is no predefined path for CD-ROMs on MacOS X. Rather, we // define a single fake CD-ROM entry for the emulated MacOS. // XXX this means we handle only CD-ROM drive at a time, wherever // the disk is, the latest one is used. PrefsAddString("cdrom", "/dev/poll/cdrom"); #elif defined(__FreeBSD__) || defined(__NetBSD__) PrefsAddString("cdrom", "/dev/cd0c"); #endif }
void SysAddSerialPrefs(void) { #if defined(__linux__) if (access("/dev/.devfsd", F_OK) < 0) { PrefsAddString("seriala", "/dev/ttyS0"); PrefsAddString("serialb", "/dev/ttyS1"); } else { PrefsAddString("seriala", "/dev/tts/0"); PrefsAddString("serialb", "/dev/tts/1"); } #elif defined(__FreeBSD__) PrefsAddString("seriala", "/dev/cuaa0"); PrefsAddString("serialb", "/dev/cuaa1"); #elif defined(__NetBSD__) PrefsAddString("seriala", "/dev/tty00"); PrefsAddString("serialb", "/dev/tty01"); #elif defined(__APPLE__) && defined(__MACH__) #if defined(AQUA) || defined(HAVE_FRAMEWORK_COREFOUNDATION) extern void DarwinAddSerialPrefs(void); DarwinAddSerialPrefs(); #else // Until I can convince the other guys that my Darwin code is useful, // we just add something safe (non-existant devices): PrefsAddString("seriala", "/dev/null"); PrefsAddString("serialb", "/dev/null"); #endif #endif }
void SysAddDiskPrefs(void) { #ifdef __linux__ FILE *f = fopen("/etc/fstab", "r"); if (f) { char line[256]; while(fgets(line, 255, f)) { // Read line int len = strlen(line); if (len == 0 || line[0] == '#') continue; line[len-1] = 0; // Parse line char *dev, *mnt_point, *fstype; if (sscanf(line, "%as %as %as", &dev, &mnt_point, &fstype) == 3) { if (strcmp(fstype, "hfs") == 0) PrefsAddString("disk", dev); } free(dev); free(mnt_point); free(fstype); } fclose(f); } #endif }
void LoadPrefsFromStream(FILE *f) { char line[256]; while(fgets(line, 255, f)) { // Read line int len = strlen(line); if (len == 0) continue; line[len-1] = 0; // Comments begin with "#" or ";" if (line[0] == '#' || line[0] == ';') continue; // Terminate string after keyword char *p = line; while (!isspace(*p)) p++; *p++ = 0; // Skip whitespace until value while (isspace(*p)) p++; if (*p == 0) continue; char *keyword = line; char *value = p; int32 i = atol(value); // Look for keyword first in common item list, then in platform specific list const prefs_desc *desc = find_prefs_desc(keyword, common_prefs_items); if (desc == NULL) desc = find_prefs_desc(keyword, platform_prefs_items); if (desc == NULL) { //printf("WARNING: Unknown preferences keyword '%s'\n", keyword); continue; } // Add item to prefs switch (desc->type) { case TYPE_STRING: if (desc->multiple) PrefsAddString(keyword, value); else PrefsReplaceString(keyword, value); break; case TYPE_BOOLEAN: PrefsReplaceBool(keyword, !strcmp(value, "true")); break; case TYPE_INT16: PrefsReplaceInt16(keyword, i); break; case TYPE_INT32: PrefsReplaceInt32(keyword, i); break; default: break; } } }
// Scan directory for CD-ROM drives, add them to prefs static void scan_for_cdrom_drives(const char *directory) { // Set directory BDirectory dir; dir.SetTo(directory); if (dir.InitCheck() != B_NO_ERROR) return; dir.Rewind(); // Scan each entry BEntry entry; while (dir.GetNextEntry(&entry) >= 0) { // Get path and ref for entry BPath path; if (entry.GetPath(&path) != B_NO_ERROR) continue; const char *name = path.Path(); entry_ref e; if (entry.GetRef(&e) != B_NO_ERROR) continue; // Recursively enter subdirectories (except for floppy) if (entry.IsDirectory()) { if (!strcmp(e.name, "floppy")) continue; scan_for_cdrom_drives(name); } else { D(bug(" checking '%s'\n", name)); // Ignore partitions if (strcmp(e.name, "raw")) continue; // Open device int fd = open(name, O_RDONLY); if (fd < 0) continue; // Get geometry and device type device_geometry g; if (ioctl(fd, B_GET_GEOMETRY, &g, sizeof(g)) < 0) { close(fd); continue; } // Insert to list if it is a CD drive if (g.device_type == B_CD) PrefsAddString("cdrom", name); close(fd); } } }
void SysAddDiskPrefs(void) { // Let BeOS scan for HFS drives D(bug("Looking for Mac volumes...\n")); system("mountvolume -allhfs"); // Add all HFS volumes int32 i = 0; dev_t d; fs_info info; while ((d = next_dev(&i)) >= 0) { fs_stat_dev(d, &info); status_t err = -1; BPath mount; if (!strcmp(info.fsh_name, "hfs")) { BDirectory dir; BEntry entry; node_ref node; node.device = info.dev; node.node = info.root; err = dir.SetTo(&node); if (!err) err = dir.GetEntry(&entry); if (!err) err = entry.GetPath(&mount); } #warning TODO: unmount inuse disk! #if 0 if (!err) err = unmount(mount.Path()); #endif if (!err) { char dev_name[B_FILE_NAME_LENGTH]; if (info.flags & B_FS_IS_READONLY) { dev_name[0] = '*'; dev_name[1] = 0; } else dev_name[0] = 0; strcat(dev_name, info.device_name); PrefsAddString("disk", dev_name); } } }
void SysAddFloppyPrefs(void) { #if defined(__linux__) DIR *fd_dir = opendir("/dev/floppy"); if (fd_dir) { struct dirent *floppy_dev; while ((floppy_dev = readdir(fd_dir)) != NULL) { if (strstr(floppy_dev->d_name, "u1440") != NULL) { char fd_dev[20]; sprintf(fd_dev, "/dev/floppy/%s", floppy_dev->d_name); PrefsAddString("floppy", fd_dev); } } closedir(fd_dir); } else { PrefsAddString("floppy", "/dev/fd0"); PrefsAddString("floppy", "/dev/fd1"); } #elif defined(__NetBSD__) PrefsAddString("floppy", "/dev/fd0a"); PrefsAddString("floppy", "/dev/fd1a"); #elif defined(__APPLE__) && defined(__MACH__) #if defined(AQUA) || defined(HAVE_FRAMEWORK_COREFOUNDATION) extern void DarwinAddFloppyPrefs(void); DarwinAddFloppyPrefs(); #else // Until I can convince the other guys that my Darwin code is useful, // we just add something safe (a non-existant device): PrefsAddString("floppy", "/dev/null"); #endif #else PrefsAddString("floppy", "/dev/fd0"); PrefsAddString("floppy", "/dev/fd1"); #endif }
void SysAddSerialPrefs(void) { system_info info; get_system_info(&info); switch (info.platform_type) { case B_BEBOX_PLATFORM: case B_AT_CLONE_PLATFORM: PrefsAddString("seriala", "serial1"); PrefsAddString("serialb", "serial2"); break; case B_MAC_PLATFORM: PrefsAddString("seriala", "modem"); PrefsAddString("serialb", "printer"); break; default: PrefsAddString("seriala", "none"); PrefsAddString("serialb", "none"); break; } }
void SysAddFloppyPrefs(void) { // Only one floppy drive under BeOS PrefsAddString("floppy", "/dev/disk/floppy/raw"); }
void DarwinAddSerialPrefs(void) { mach_port_t masterPort; // The way to talk to the kernel io_iterator_t allModems; // List of modems on the system CFMutableDictionaryRef classesToMatch; io_object_t nextModem; if ( IOMasterPort(MACH_PORT_NULL, &masterPort) != KERN_SUCCESS ) bug("IOMasterPort failed. Won't be able to do anything with modems\n"); // Serial devices are instances of class IOSerialBSDClient classesToMatch = IOServiceMatching(kIOSerialBSDServiceValue); if ( classesToMatch ) { // Narrow the search a little further. Each serial device object has // a property with key kIOSerialBSDTypeKey and a value that is one of // kIOSerialBSDAllTypes, kIOSerialBSDModemType, or kIOSerialBSDRS232Type. CFDictionarySetValue(classesToMatch, CFSTR(kIOSerialBSDTypeKey), CFSTR(kIOSerialBSDModemType)); // This will find built-in and USB modems, but not serial modems. } if ( IOServiceGetMatchingServices(masterPort, classesToMatch, &allModems) != KERN_SUCCESS ) { D(bug("IOServiceGetMatchingServices failed. No modems found?\n")); return; } // Iterate through each modem while ( nextModem = IOIteratorNext(allModems)) { char bsdPath[MAXPATHLEN]; CFTypeRef bsdPathAsCFString = IORegistryEntryCreateCFProperty(nextModem, CFSTR(kIOCalloutDeviceKey), // kIODialinDeviceKey? kCFAllocatorDefault, 0); *bsdPath = '\0'; if ( bsdPathAsCFString ) { if ( CFStringGetCString((const __CFString *)bsdPathAsCFString, bsdPath, MAXPATHLEN, kCFStringEncodingASCII) ) { D(bug("Modem BSD path: %s\n", bsdPath)); // Note that if there are multiple modems, we only get the last PrefsAddString("seriala", bsdPath); } else D(bug("Could not get BSD device path for modem\n")); CFRelease(bsdPathAsCFString); } else D(puts("Cannot determine bsdPath for modem\n")); } IOObjectRelease(nextModem); IOObjectRelease(allModems); // Getting a printer device is a bit harder. Creating a fake device // that emulates a simple printer (e.g. a HP DeskJet) is one possibility, // but for now I will just create a fake, safe, device entry: PrefsAddString("serialb", "/dev/null"); }
void DarwinAddFloppyPrefs(void) { mach_port_t masterPort; // The way to talk to the kernel io_iterator_t allFloppies; // List of possible floppys CFMutableDictionaryRef classesToMatch; io_object_t nextFloppy; if ( IOMasterPort(MACH_PORT_NULL, &masterPort) != KERN_SUCCESS ) bug("IOMasterPort failed. Won't be able to do anything with floppy drives\n"); // This selects all partitions of all disks classesToMatch = IOServiceMatching(kIOMediaClass); if ( classesToMatch ) { // Skip drivers and partitions CFDictionarySetValue(classesToMatch, CFSTR(kIOMediaWholeKey), kCFBooleanTrue); // Skip fixed drives (hard disks?) CFDictionarySetValue(classesToMatch, CFSTR(kIOMediaEjectableKey), kCFBooleanTrue); } if ( IOServiceGetMatchingServices(masterPort, classesToMatch, &allFloppies) != KERN_SUCCESS ) { D(bug("IOServiceGetMatchingServices failed. No removable drives found?\n")); return; } // Iterate through each floppy while ( nextFloppy = IOIteratorNext(allFloppies)) { char bsdPath[MAXPATHLEN]; long size; CFTypeRef sizeAsCFNumber = IORegistryEntryCreateCFProperty(nextFloppy, CFSTR(kIOMediaSizeKey), kCFAllocatorDefault, 0); if ( CFNumberGetValue((CFNumberRef)sizeAsCFNumber, kCFNumberSInt32Type, &size) ) { D(bug("Got size of %ld\n", size)); if ( size < 800 * 1024 || size > 1440 * 1024 ) { D(puts("Device does not appear to be 800k or 1440k")); continue; } } else { D(puts("Couldn't get kIOMediaSizeKey of device")); continue; // if kIOMediaSizeKey is unavailable, we shouldn't use it anyway } if (get_device_path(nextFloppy, bsdPath, sizeof(bsdPath)) == KERN_SUCCESS) { PrefsAddString("floppy", bsdPath); } else { D(bug("Could not get BSD device path for floppy\n")); } } IOObjectRelease(nextFloppy); IOObjectRelease(allFloppies); }
void PrefsWindow::MessageReceived(BMessage *msg) { switch (msg->what) { case MSG_OK: { // "Start" button clicked read_volumes_prefs(); read_memory_prefs(); read_graphics_prefs(); SavePrefs(); send_quit_on_close = false; PostMessage(B_QUIT_REQUESTED); be_app->PostMessage(ok_message); break; } case MSG_CANCEL: // "Quit" button clicked send_quit_on_close = false; PostMessage(B_QUIT_REQUESTED); be_app->PostMessage(B_QUIT_REQUESTED); break; case B_ABOUT_REQUESTED: { // "About" menu item selected ShowAboutWindow(); break; } case MSG_ZAP_PRAM: // "Zap PRAM File" menu item selected ZapPRAM(); break; case MSG_VOLUME_INVOKED: { // Double-clicked on volume name, toggle read-only flag int selected = volume_list->CurrentSelection(); if (selected >= 0) { const char *str = PrefsFindString("disk", selected); BStringItem *item = (BStringItem *)volume_list->RemoveItem(selected); delete item; char newstr[256]; if (str[0] == '*') strcpy(newstr, str+1); else { strcpy(newstr, "*"); strcat(newstr, str); } PrefsReplaceString("disk", newstr, selected); volume_list->AddItem(new BStringItem(newstr), selected); volume_list->Select(selected); } break; } case MSG_ADD_VOLUME: add_volume_panel->Show(); break; case MSG_CREATE_VOLUME: create_volume_panel->Show(); break; case MSG_ADD_VOLUME_PANEL: { entry_ref ref; if (msg->FindRef("refs", &ref) == B_NO_ERROR) { BEntry entry(&ref, true); BPath path; entry.GetPath(&path); if (entry.IsFile()) { PrefsAddString("disk", path.Path()); volume_list->AddItem(new BStringItem(path.Path())); } else if (entry.IsDirectory()) { BVolume volume; if (path.Path()[0] == '/' && strchr(path.Path()+1, '/') == NULL && entry.GetVolume(&volume) == B_NO_ERROR) { int32 i = 0; dev_t d; fs_info info; while ((d = next_dev(&i)) >= 0) { fs_stat_dev(d, &info); if (volume.Device() == info.dev) { PrefsAddString("disk", info.device_name); volume_list->AddItem(new BStringItem(info.device_name)); } } } } } break; } case MSG_CREATE_VOLUME_PANEL: { entry_ref dir; if (msg->FindRef("directory", &dir) == B_NO_ERROR) { BEntry entry(&dir, true); BPath path; entry.GetPath(&path); path.Append(msg->FindString("name")); create_volume_panel->Window()->Lock(); BView *background = create_volume_panel->Window()->ChildAt(0); NumberControl *v = (NumberControl *)background->FindView("hardfile_size"); int size = v->Value(); char cmd[1024]; sprintf(cmd, "dd if=/dev/zero \"of=%s\" bs=1024k count=%d", path.Path(), size); int ret = system(cmd); if (ret == 0) { PrefsAddString("disk", path.Path()); volume_list->AddItem(new BStringItem(path.Path())); } else { sprintf(cmd, GetString(STR_CREATE_VOLUME_WARN), strerror(ret)); WarningAlert(cmd); } } break; } case MSG_REMOVE_VOLUME: { int selected = volume_list->CurrentSelection(); if (selected >= 0) { PrefsRemoveItem("disk", selected); BStringItem *item = (BStringItem *)volume_list->RemoveItem(selected); delete item; volume_list->Select(selected); } break; } case MSG_BOOT_ANY: PrefsReplaceInt32("bootdriver", 0); break; case MSG_BOOT_CDROM: PrefsReplaceInt32("bootdriver", CDROMRefNum); break; case MSG_NOCDROM: PrefsReplaceBool("nocdrom", nocdrom_checkbox->Value() == B_CONTROL_ON); break; case MSG_VIDEO_WINDOW: display_type = DISPLAY_WINDOW; hide_show_graphics_ctrls(); break; case MSG_VIDEO_SCREEN: display_type = DISPLAY_SCREEN; hide_show_graphics_ctrls(); break; case MSG_REF_5HZ: PrefsReplaceInt32("frameskip", 12); break; case MSG_REF_7_5HZ: PrefsReplaceInt32("frameskip", 8); break; case MSG_REF_10HZ: PrefsReplaceInt32("frameskip", 6); break; case MSG_REF_15HZ: PrefsReplaceInt32("frameskip", 4); break; case MSG_REF_30HZ: PrefsReplaceInt32("frameskip", 2); break; case MSG_NOSOUND: PrefsReplaceBool("nosound", nosound_checkbox->Value() == B_CONTROL_ON); break; case MSG_SER_A: { BMenuItem *source = NULL; msg->FindPointer("source", (void **)&source); if (source) PrefsReplaceString("seriala", source->Label()); break; } case MSG_SER_B: { BMenuItem *source = NULL; msg->FindPointer("source", (void **)&source); if (source) PrefsReplaceString("serialb", source->Label()); break; } case MSG_ETHER: if (ether_checkbox->Value() == B_CONTROL_ON) PrefsReplaceString("ether", "yes"); else PrefsRemoveItem("ether"); break; case MSG_UDPTUNNEL: PrefsReplaceBool("udptunnel", udptunnel_checkbox->Value() == B_CONTROL_ON); hide_show_serial_ctrls(); break; case MSG_RAMSIZE: PrefsReplaceInt32("ramsize", ramsize_slider->Value() * 1024 * 1024); break; case MSG_MODELID_5: PrefsReplaceInt32("modelid", 5); break; case MSG_MODELID_14: PrefsReplaceInt32("modelid", 14); break; case MSG_CPU_68020: PrefsReplaceInt32("cpu", 2); PrefsReplaceBool("fpu", false); break; case MSG_CPU_68020_FPU: PrefsReplaceInt32("cpu", 2); PrefsReplaceBool("fpu", true); break; case MSG_CPU_68030: PrefsReplaceInt32("cpu", 3); PrefsReplaceBool("fpu", false); break; case MSG_CPU_68030_FPU: PrefsReplaceInt32("cpu", 3); PrefsReplaceBool("fpu", true); break; case MSG_CPU_68040: PrefsReplaceInt32("cpu", 4); PrefsReplaceBool("fpu", true); break; default: { // Screen mode messages if ((msg->what & 0xffff0000) == MSG_SCREEN_MODE) { int m = msg->what & 0xffff; uint32 mask = scr_mode[m].mode_mask; for (int i=0; i<32; i++) if (mask & (1 << i)) scr_mode_bit = i; } else BWindow::MessageReceived(msg); } } }