int SDL_SYS_CDInit(void) { /* checklist: Drive 'A' - 'Z' */ int i; char drive[4]; /* Fill in our driver capabilities */ SDL_CDcaps.Name = SDL_SYS_CDName; SDL_CDcaps.Open = SDL_SYS_CDOpen; SDL_CDcaps.GetTOC = SDL_SYS_CDGetTOC; SDL_CDcaps.Status = SDL_SYS_CDStatus; SDL_CDcaps.Play = SDL_SYS_CDPlay; SDL_CDcaps.Pause = SDL_SYS_CDPause; SDL_CDcaps.Resume = SDL_SYS_CDResume; SDL_CDcaps.Stop = SDL_SYS_CDStop; SDL_CDcaps.Eject = SDL_SYS_CDEject; SDL_CDcaps.Close = SDL_SYS_CDClose; /* Scan the system for CD-ROM drives */ for ( i='A'; i<='Z'; ++i ) { SDL_snprintf(drive, SDL_arraysize(drive), "%c:\\", i); if ( GetDriveType(drive) == DRIVE_CDROM ) { AddDrive(drive); } } SDL_memset(SDL_mciID, 0, sizeof(SDL_mciID)); return(0); }
int SDL_SYS_CDInit(void) { static char *checklist[] = { #if defined(__OPENBSD__) "?0 cd?c", "cdrom", NULL #elif defined(__NETBSD__) "?0 cd?d", "?0 cd?c", "cdrom", NULL #else "?0 cd?c", "?0 acd?c", "cdrom", NULL #endif }; char *SDLcdrom; int i, j, exists; char drive[32]; struct stat stbuf; /* Fill in our driver capabilities */ SDL_CDcaps.Name = SDL_SYS_CDName; SDL_CDcaps.Open = SDL_SYS_CDOpen; SDL_CDcaps.GetTOC = SDL_SYS_CDGetTOC; SDL_CDcaps.Status = SDL_SYS_CDStatus; SDL_CDcaps.Play = SDL_SYS_CDPlay; SDL_CDcaps.Pause = SDL_SYS_CDPause; SDL_CDcaps.Resume = SDL_SYS_CDResume; SDL_CDcaps.Stop = SDL_SYS_CDStop; SDL_CDcaps.Eject = SDL_SYS_CDEject; SDL_CDcaps.Close = SDL_SYS_CDClose; /* Look in the environment for our CD-ROM drive list */ SDLcdrom = SDL_getenv("SDL_CDROM"); /* ':' separated list of devices */ if ( SDLcdrom != NULL ) { char *cdpath, *delim; size_t len = SDL_strlen(SDLcdrom)+1; cdpath = SDL_stack_alloc(char, len); if ( cdpath != NULL ) { SDL_strlcpy(cdpath, SDLcdrom, len); SDLcdrom = cdpath; do { delim = SDL_strchr(SDLcdrom, ':'); if ( delim ) { *delim++ = '\0'; } if ( CheckDrive(SDLcdrom, &stbuf) > 0 ) { AddDrive(SDLcdrom, &stbuf); } if ( delim ) { SDLcdrom = delim; } else { SDLcdrom = NULL; } } while ( SDLcdrom ); SDL_stack_free(cdpath); } /* If we found our drives, there's nothing left to do */ if ( SDL_numcds > 0 ) { return(0); } }
int SDL_SYS_CDInit(void) { struct { char *dir; char *name; } checklist[] = { {"/dev/rdisk", "cdrom"}, {"/dev", "rrz"}, {NULL, NULL}}; char drive[32]; char *SDLcdrom; int i, j, exists; struct stat stbuf; SDL_CDcaps.Name = SDL_SYS_CDName; SDL_CDcaps.Open = SDL_SYS_CDOpen; SDL_CDcaps.GetTOC = SDL_SYS_CDGetTOC; SDL_CDcaps.Status = SDL_SYS_CDStatus; SDL_CDcaps.Play = SDL_SYS_CDPlay; SDL_CDcaps.Pause = SDL_SYS_CDPause; SDL_CDcaps.Resume = SDL_SYS_CDResume; SDL_CDcaps.Stop = SDL_SYS_CDStop; SDL_CDcaps.Eject = SDL_SYS_CDEject; SDL_CDcaps.Close = SDL_SYS_CDClose; SDLcdrom = SDL_getenv("SDL_CDROM"); if ( SDLcdrom != NULL ) { char *cdpath, *delim; size_t len = SDL_strlen(SDLcdrom)+1; cdpath = SDL_stack_alloc(char, len); if ( cdpath != NULL ) { SDL_strlcpy(cdpath, SDLcdrom, len); SDLcdrom = cdpath; do { delim = SDL_strchr(SDLcdrom, ':'); if ( delim ) { *delim++ = '\0'; } if ( CheckDrive(SDLcdrom, &stbuf) > 0 ) { AddDrive(SDLcdrom, &stbuf); } if ( delim ) { SDLcdrom = delim; } else { SDLcdrom = NULL; } } while ( SDLcdrom ); SDL_stack_free(cdpath); } if ( SDL_numcds > 0 ) { return(0); } }
int SDL_SYS_CDInit(void) { char *SDLcdrom; struct stat stbuf; /* Fill in our driver capabilities */ SDL_CDcaps.Name = SDL_SYS_CDName; SDL_CDcaps.Open = SDL_SYS_CDOpen; SDL_CDcaps.GetTOC = SDL_SYS_CDGetTOC; SDL_CDcaps.Status = SDL_SYS_CDStatus; SDL_CDcaps.Play = SDL_SYS_CDPlay; SDL_CDcaps.Pause = SDL_SYS_CDPause; SDL_CDcaps.Resume = SDL_SYS_CDResume; SDL_CDcaps.Stop = SDL_SYS_CDStop; SDL_CDcaps.Eject = SDL_SYS_CDEject; SDL_CDcaps.Close = SDL_SYS_CDClose; /* Look in the environment for our CD-ROM drive list */ SDLcdrom = getenv("SDL_CDROM"); /* ':' separated list of devices */ if ( SDLcdrom != NULL ) { char *cdpath, *delim; cdpath = malloc(strlen(SDLcdrom)+1); if ( cdpath != NULL ) { strcpy(cdpath, SDLcdrom); SDLcdrom = cdpath; do { delim = strchr(SDLcdrom, ':'); if ( delim ) { *delim++ = '\0'; } #ifdef DEBUG_CDROM fprintf(stderr, "Checking CD-ROM drive from SDL_CDROM: %s\n", SDLcdrom); #endif if ( CheckDrive(SDLcdrom, &stbuf) > 0 ) { AddDrive(SDLcdrom, &stbuf); } if ( delim ) { SDLcdrom = delim; } else { SDLcdrom = NULL; } } while ( SDLcdrom ); free(cdpath); } /* If we found our drives, there's nothing left to do */ if ( SDL_numcds > 0 ) { return(0); } } CheckMounts(); CheckNonmounts(); return 0; }
wxTreeItemId CLocalTreeView::GetNearestParent(wxString& localDir) { const wxString separator = wxFileName::GetPathSeparator(); #ifdef __WXMSW__ int pos = localDir.Find(separator); if (pos == -1) return wxTreeItemId(); wxString drive = localDir.Left(pos); localDir = localDir.Mid(pos + 1); wxTreeItemIdValue value; wxTreeItemId root = GetFirstChild(m_drives, value); while (root) { if (!GetItemText(root).Left(drive.Length()).CmpNoCase(drive)) break; root = GetNextSibling(root); } if (!root) { if (drive[1] == ':') return AddDrive(drive[0]); return wxTreeItemId(); } #else if (localDir[0] == '/') localDir = localDir.Mid(1); wxTreeItemId root = GetRootItem(); #endif while (localDir != _T("")) { wxString subDir; int pos = localDir.Find(separator); if (pos == -1) subDir = localDir; else subDir = localDir.Left(pos); wxTreeItemId child = GetSubdir(root, subDir); if (!child) return root; if (!pos) return child; root = child; localDir = localDir.Mid(pos + 1); } return root; }
void CLocalTreeView::OnDevicechange(WPARAM wParam, LPARAM lParam) { if (!m_drives) return; if (wParam == DBT_DEVICEARRIVAL || wParam == DBT_DEVICEREMOVECOMPLETE) { DEV_BROADCAST_HDR* pHdr = (DEV_BROADCAST_HDR*)lParam; if (pHdr->dbch_devicetype != DBT_DEVTYP_VOLUME) return; // Added or removed volume DEV_BROADCAST_VOLUME* pVolume = (DEV_BROADCAST_VOLUME*)lParam; wxChar drive = 'A'; int mask = 1; while (drive <= 'Z') { if (pVolume->dbcv_unitmask & mask) { if (wParam == DBT_DEVICEARRIVAL) AddDrive(drive); else { RemoveDrive(drive); if (pVolume->dbcv_flags & DBTF_MEDIA) { // E.g. disk removed from CD-ROM drive, need to keep the drive letter AddDrive(drive); } } } drive++; mask <<= 1; } if (GetSelection() == m_drives && m_pState) m_pState->RefreshLocal(); } }
static void CheckMounts(const char *mtab) { FILE *mntfp; struct mntent *mntent; struct stat stbuf; mntfp = setmntent(mtab, "r"); if ( mntfp != NULL ) { char *tmp, mnt_type[32], mnt_dev[1024]; while ( (mntent=getmntent(mntfp)) != NULL ) { /* Warning, possible buffer overflow.. */ strcpy(mnt_type, mntent->mnt_type); strcpy(mnt_dev, mntent->mnt_fsname); /* Handle "supermount" filesystem mounts */ if ( strcmp(mnt_type, MNTTYPE_SUPER) == 0 ) { tmp = strstr(mntent->mnt_opts, "fs="); if ( tmp ) { strcpy(mnt_type, tmp+strlen("fs=")); tmp = strchr(mnt_type, ','); if ( tmp ) { *tmp = '\0'; } } tmp = strstr(mntent->mnt_opts, "dev="); if ( tmp ) { strcpy(mnt_dev, tmp+strlen("dev=")); tmp = strchr(mnt_dev, ','); if ( tmp ) { *tmp = '\0'; } } } if ( strcmp(mnt_type, MNTTYPE_CDROM) == 0 ) { #ifdef DEBUG_CDROM fprintf(stderr, "Checking mount path from %s: %s mounted on %s of %s\n", mtab, mnt_dev, mntent->mnt_dir, mnt_type); #endif if (CheckDrive(mnt_dev, mnt_type, &stbuf) > 0) { AddDrive(mnt_dev, &stbuf); } } } endmntent(mntfp); } }
void CMyTreeView::AddItem(const TCHAR *szFullFileName) { TCHAR szDirectory[MAX_PATH]; HTREEITEM hParent; HTREEITEM hDeskParent; /* If the specified item is a drive, it will need to be handled differently, as it is a child of my computer (and as such is not a regular file). */ if(PathIsRoot(szFullFileName)) { AddDrive(szFullFileName); } else { StringCchCopy(szDirectory, SIZEOF_ARRAY(szDirectory), szFullFileName); PathRemoveFileSpec(szDirectory); // Check if it is a desktop (sub)child hDeskParent = LocateItemOnDesktopTree(szDirectory); hParent = LocateExistingItem(szDirectory); /* If this items' parent isn't currently shown on the treeview and the item is not on the desktop, exit without doing anything further. */ if(hParent == NULL && hDeskParent == NULL) return; AddItemInternal(hParent,szFullFileName); if(hDeskParent != NULL) { /* If the item is on the desktop, it is a special case. We need to update the treeview also starting from the root item. */ AddItemInternal(hDeskParent,szFullFileName); } } }
int SDL_SYS_CDInit(void) { /* checklist: /dev/cdrom, /dev/hd?, /dev/scd? /dev/sr? */ static char *checklist[] = { "cdrom", "?a hd?", "?0 scd?", "?0 sr?", NULL }; char *SDLcdrom; int i, j, exists; char drive[32]; struct stat stbuf; /* Fill in our driver capabilities */ SDL_CDcaps.Name = SDL_SYS_CDName; SDL_CDcaps.Open = SDL_SYS_CDOpen; SDL_CDcaps.GetTOC = SDL_SYS_CDGetTOC; SDL_CDcaps.Status = SDL_SYS_CDStatus; SDL_CDcaps.Play = SDL_SYS_CDPlay; SDL_CDcaps.Pause = SDL_SYS_CDPause; SDL_CDcaps.Resume = SDL_SYS_CDResume; SDL_CDcaps.Stop = SDL_SYS_CDStop; SDL_CDcaps.Eject = SDL_SYS_CDEject; SDL_CDcaps.Close = SDL_SYS_CDClose; /* Look in the environment for our CD-ROM drive list */ SDLcdrom = getenv("SDL_CDROM"); /* ':' separated list of devices */ if ( SDLcdrom != NULL ) { char *cdpath, *delim; cdpath = malloc(strlen(SDLcdrom)+1); if ( cdpath != NULL ) { strcpy(cdpath, SDLcdrom); SDLcdrom = cdpath; do { delim = strchr(SDLcdrom, ':'); if ( delim ) { *delim++ = '\0'; } #ifdef DEBUG_CDROM fprintf(stderr, "Checking CD-ROM drive from SDL_CDROM: %s\n", SDLcdrom); #endif if ( CheckDrive(SDLcdrom, NULL, &stbuf) > 0 ) { AddDrive(SDLcdrom, &stbuf); } if ( delim ) { SDLcdrom = delim; } else { SDLcdrom = NULL; } } while ( SDLcdrom ); free(cdpath); } /* If we found our drives, there's nothing left to do */ if ( SDL_numcds > 0 ) { return(0); } } #ifdef USE_MNTENT /* Check /dev/cdrom first :-) */ if (CheckDrive("/dev/cdrom", NULL, &stbuf) > 0) { AddDrive("/dev/cdrom", &stbuf); } /* Now check the currently mounted CD drives */ CheckMounts(_PATH_MOUNTED); /* Finally check possible mountable drives in /etc/fstab */ CheckMounts(_PATH_MNTTAB); /* If we found our drives, there's nothing left to do */ if ( SDL_numcds > 0 ) { return(0); } #endif /* USE_MNTENT */ /* Scan the system for CD-ROM drives. Not always 100% reliable, so use the USE_MNTENT code above first. */ for ( i=0; checklist[i]; ++i ) { if ( checklist[i][0] == '?' ) { char *insert; exists = 1; for ( j=checklist[i][1]; exists; ++j ) { sprintf(drive, "/dev/%s", &checklist[i][3]); insert = strchr(drive, '?'); if ( insert != NULL ) { *insert = j; } #ifdef DEBUG_CDROM fprintf(stderr, "Checking possible CD-ROM drive: %s\n", drive); #endif switch (CheckDrive(drive, NULL, &stbuf)) { /* Drive exists and is a CD-ROM */ case 1: AddDrive(drive, &stbuf); break; /* Drive exists, but isn't a CD-ROM */ case 0: break; /* Drive doesn't exist */ case -1: exists = 0; break; } } } else { sprintf(drive, "/dev/%s", checklist[i]); #ifdef DEBUG_CDROM fprintf(stderr, "Checking possible CD-ROM drive: %s\n", drive); #endif if ( CheckDrive(drive, NULL, &stbuf) > 0 ) { AddDrive(drive, &stbuf); } } } return(0); }
static int CheckNonmounts() { #ifdef _THREAD_SAFE AFILE_t fsFile = NULL; int passNo = 0; int ret; struct fstab entry; struct stat stbuf; ret = setfsent_r( &fsFile, &passNo ); if ( ret != 0 ) return -1; do { ret = getfsent_r ( &entry, &fsFile, &passNo ); if ( ret == 0 ) { char* l = strrchr(entry.fs_spec,'/'); if ( l != NULL ) { if ( !strncmp("cd",++l,2) ) { #ifdef DEBUG_CDROM fprintf(stderr, "Found unmounted CD ROM drive with device name %s\n", entry.fs_spec); #endif if ( CheckDrive( entry.fs_spec, &stbuf) > 0) { AddDrive( entry.fs_spec, &stbuf); } } } } } while ( ret == 0 ); ret = endfsent_r ( &fsFile ); if ( ret != 0 ) return -1; return 0; #else struct fstab* entry; struct stat stbuf; setfsent(); do { entry = getfsent(); if ( entry != NULL ) { char* l = strrchr(entry->fs_spec,'/'); if ( l != NULL ) { if ( !strncmp("cd",++l,2) ) { #ifdef DEBUG_CDROM fprintf(stderr,"Found unmounted CD ROM drive with device name %s", entry->fs_spec); #endif if ( CheckDrive( entry->fs_spec, &stbuf) > 0) { AddDrive( entry->fs_spec, &stbuf); } } } } } while ( entry != NULL ); endfsent(); #endif }
const char *CdromDriverLinux::DeviceName(int drive) { if (!drives_scanned) { /* checklist: /dev/cdrom, /dev/hd?, /dev/scd? /dev/sr? */ static const char *const checklist[] = { "cdrom", "?a hd?", "?0 scd?", "?0 sr?", NULL }; struct stat stbuf; #ifdef USE_MNTENT /* Check /dev/cdrom first :-) */ if (CheckDrive("/dev/cdrom", NULL, &stbuf) > 0) { AddDrive("/dev/cdrom", &stbuf); } /* Now check the currently mounted CD drives */ CheckMounts(_PATH_MOUNTED); /* Finally check possible mountable drives in /etc/fstab */ CheckMounts(_PATH_MNTTAB); /* If we found our drives, there's nothing left to do */ #endif /* USE_MNTENT */ if ( numcds == 0 ) { char drive[32]; int i, j, exists; /* Scan the system for CD-ROM drives. Not always 100% reliable, so use the USE_MNTENT code above first. */ for ( i=0; checklist[i]; ++i ) { if ( checklist[i][0] == '?' ) { char *insert; exists = 1; for ( j=checklist[i][1]; exists; ++j ) { sprintf(drive, "/dev/%s", &checklist[i][3]); insert = strchr(drive, '?'); if ( insert != NULL ) { *insert = j; } switch (CheckDrive(drive, NULL, &stbuf)) { /* Drive exists and is a CD-ROM */ case 1: AddDrive(drive, &stbuf); break; /* Drive exists, but isn't a CD-ROM */ case 0: break; /* Drive doesn't exist */ case -1: exists = 0; break; } } } else { sprintf(drive, "/dev/%s", checklist[i]); if ( CheckDrive(drive, NULL, &stbuf) > 0 ) { AddDrive(drive, &stbuf); } } } } drives_scanned = true; } return cddrives[drive].device; }
void CdromDriverLinux::CheckMounts(const char *mtab) { FILE *mntfp; struct mntent *mntent; struct stat stbuf; mntfp = setmntent(mtab, "r"); if ( mntfp != NULL ) { char *tmp; char *mnt_type; size_t mnt_type_len; char *mnt_dev; size_t mnt_dev_len; while ( (mntent=getmntent(mntfp)) != NULL ) { mnt_type_len = strlen(mntent->mnt_type) + 1; mnt_type = (char *)malloc(mnt_type_len); if (mnt_type == NULL) continue; /* maybe you'll get lucky next time. */ mnt_dev_len = strlen(mntent->mnt_fsname) + 1; mnt_dev = (char *)malloc(mnt_dev_len); if (mnt_dev == NULL) { free(mnt_type); continue; } strcpy(mnt_type, mntent->mnt_type); strcpy(mnt_dev, mntent->mnt_fsname); /* Handle "supermount" filesystem mounts */ if ( strcmp(mnt_type, MNTTYPE_SUPER) == 0 ) { tmp = strstr(mntent->mnt_opts, "fs="); if ( tmp ) { free(mnt_type); mnt_type = strdup(tmp + strlen("fs=")); if ( mnt_type ) { tmp = strchr(mnt_type, ','); if ( tmp ) { *tmp = '\0'; } } } tmp = strstr(mntent->mnt_opts, "dev="); if ( tmp ) { free(mnt_dev); mnt_dev = strdup(tmp + strlen("dev=")); if ( mnt_dev ) { tmp = strchr(mnt_dev, ','); if ( tmp ) { *tmp = '\0'; } } } } if ( strcmp(mnt_type, MNTTYPE_CDROM) == 0 ) { if (CheckDrive(mnt_dev, mnt_type, &stbuf) > 0) { AddDrive(mnt_dev, &stbuf); } } free(mnt_dev); free(mnt_type); } endmntent(mntfp); } }
int SDL_SYS_CDInit(void) { /* checklist: * * Tru64 5.X (/dev/rdisk/cdrom?c) * dir: /dev/rdisk, name: cdrom * * Digital UNIX 4.0X (/dev/rrz?c) * dir: /dev, name: rrz * */ struct { char *dir; char *name; } checklist[] = { { "/dev/rdisk", "cdrom"}, { "/dev", "rrz"}, { NULL, NULL}}; char drive[32]; char *SDLcdrom; int i, j, exists; struct stat stbuf; /* Fill in our driver capabilities */ SDL_CDcaps.Name = SDL_SYS_CDName; SDL_CDcaps.Open = SDL_SYS_CDOpen; SDL_CDcaps.GetTOC = SDL_SYS_CDGetTOC; SDL_CDcaps.Status = SDL_SYS_CDStatus; SDL_CDcaps.Play = SDL_SYS_CDPlay; SDL_CDcaps.Pause = SDL_SYS_CDPause; SDL_CDcaps.Resume = SDL_SYS_CDResume; SDL_CDcaps.Stop = SDL_SYS_CDStop; SDL_CDcaps.Eject = SDL_SYS_CDEject; SDL_CDcaps.Close = SDL_SYS_CDClose; /* Look in the environment for our CD-ROM drive list */ SDLcdrom = SDL_getenv("SDL_CDROM"); /* ':' separated list of devices */ if (SDLcdrom != NULL) { char *cdpath, *delim; size_t len = SDL_strlen(SDLcdrom) + 1; cdpath = SDL_stack_alloc(char, len); if (cdpath != NULL) { SDL_strlcpy(cdpath, SDLcdrom, len); SDLcdrom = cdpath; do { delim = SDL_strchr(SDLcdrom, ':'); if (delim) { *delim++ = '\0'; } if (CheckDrive(SDLcdrom, &stbuf) > 0) { AddDrive(SDLcdrom, &stbuf); } if (delim) { SDLcdrom = delim; } else { SDLcdrom = NULL; } } while (SDLcdrom); SDL_stack_free(cdpath); } /* If we found our drives, there's nothing left to do */ if (SDL_numcds > 0) { return (0); } }
int SDL_SYS_CDInit(void) { /* checklist: /dev/cdrom,/dev/cd?c /dev/acd?c * /dev/matcd?c /dev/mcd?c /dev/scd?c * */ static char *checklist[] = { "?0 rdisk/cdrom?",NULL}; char drive[32]; char *SDLcdrom; int i, j, exists; struct stat stbuf; /* Fill in our driver capabilities */ SDL_CDcaps.Name = SDL_SYS_CDName; SDL_CDcaps.Open = SDL_SYS_CDOpen; SDL_CDcaps.GetTOC = SDL_SYS_CDGetTOC; SDL_CDcaps.Status = SDL_SYS_CDStatus; SDL_CDcaps.Play = SDL_SYS_CDPlay; SDL_CDcaps.Pause = SDL_SYS_CDPause; SDL_CDcaps.Resume = SDL_SYS_CDResume; SDL_CDcaps.Stop = SDL_SYS_CDStop; SDL_CDcaps.Eject = SDL_SYS_CDEject; SDL_CDcaps.Close = SDL_SYS_CDClose; /* Look in the environment for our CD-ROM drive list */ SDLcdrom = getenv("SDL_CDROM"); /* ':' separated list of devices */ if ( SDLcdrom != NULL ) { char *cdpath, *delim; cdpath = malloc(strlen(SDLcdrom)+1); if ( cdpath != NULL ) { strcpy(cdpath, SDLcdrom); SDLcdrom = cdpath; do { delim = strchr(SDLcdrom, ':'); if ( delim ) { *delim++ = '\0'; } if ( CheckDrive(SDLcdrom, &stbuf) > 0 ) { AddDrive(SDLcdrom, &stbuf); } if ( delim ) { SDLcdrom = delim; } else { SDLcdrom = NULL; } } while ( SDLcdrom ); free(cdpath); } /* If we found our drives, there's nothing left to do */ if ( SDL_numcds > 0 ) { return(0); } } /* Scan the system for CD-ROM drives */ for ( i=0; checklist[i]; ++i ) { if ( checklist[i][0] == '?' ) { char *insert; exists = 1; for ( j=checklist[i][1]; exists; ++j ) { sprintf(drive, "/dev/%sc", &checklist[i][3]); insert = strchr(drive, '?'); if ( insert != NULL ) { *insert = j; } switch (CheckDrive(drive, &stbuf)) { /* Drive exists and is a CD-ROM */ case 1: AddDrive(drive, &stbuf); break; /* Drive exists, but isn't a CD-ROM */ case 0: break; /* Drive doesn't exist */ case -1: exists = 0; break; } } } else { sprintf(drive, "/dev/%s", checklist[i]); if ( CheckDrive(drive, &stbuf) > 0 ) { AddDrive(drive, &stbuf); } } } /* SDLcdrom=malloc(sizeof(char) * 32); strcpy(SDLcdrom,"/dev/rdisk/cdrom0c"); SDL_cdlist[0] = SDLcdrom; stat(SDLcdrom, &stbuf); SDL_cdmode[0] = stbuf.st_rdev; SDL_numcds = 1; */ return (0); }
int SDL_SYS_CDInit(void) { /* checklist: /dev/cdrom, /dev/cd?, /dev/scd? */ static char *checklist[]={"cdrom", "?0 cd?", "?1 cd?", "?0 scd?", NULL}; char *SDLcdrom; int i, j, exists; char drive[32]; struct stat stbuf; /* Fill in our driver capabilities */ SDL_CDcaps.Name = SDL_SYS_CDName; SDL_CDcaps.Open = SDL_SYS_CDOpen; SDL_CDcaps.GetTOC = SDL_SYS_CDGetTOC; SDL_CDcaps.Status = SDL_SYS_CDStatus; SDL_CDcaps.Play = SDL_SYS_CDPlay; SDL_CDcaps.Pause = SDL_SYS_CDPause; SDL_CDcaps.Resume = SDL_SYS_CDResume; SDL_CDcaps.Stop = SDL_SYS_CDStop; SDL_CDcaps.Eject = SDL_SYS_CDEject; SDL_CDcaps.Close = SDL_SYS_CDClose; /* clearing device open status */ for (i=0; i<MAX_DRIVES; i++) { SDL_cdopen[i]=0; } /* Look in the environment for our CD-ROM drive list */ SDLcdrom = SDL_getenv("SDL_CDROM"); /* ':' separated list of devices */ if ( SDLcdrom != NULL ) { char *cdpath, *delim; size_t len = SDL_strlen(SDLcdrom)+1; cdpath = SDL_stack_alloc(char, len); if (cdpath != NULL) { SDL_strlcpy(cdpath, SDLcdrom, len); SDLcdrom = cdpath; do { delim = SDL_strchr(SDLcdrom, ':'); if (delim) { *delim++ = '\0'; } if (CheckDrive(SDLcdrom, &stbuf) > 0) { AddDrive(SDLcdrom, &stbuf); } if (delim) { SDLcdrom = delim; } else { SDLcdrom = NULL; } } while (SDLcdrom); SDL_stack_free(cdpath); } /* If we found our drives, there's nothing left to do */ if (SDL_numcds > 0) { return(0); } }
static void CheckMounts(const char *mtab) { FILE *mntfp; struct mntent *mntent; struct stat stbuf; mntfp = setmntent(mtab, "r"); if ( mntfp != NULL ) { char *tmp; char *mnt_type; size_t mnt_type_len; char *mnt_dev; size_t mnt_dev_len; while ( (mntent=getmntent(mntfp)) != NULL ) { mnt_type_len = SDL_strlen(mntent->mnt_type) + 1; mnt_type = SDL_stack_alloc(char, mnt_type_len); if (mnt_type == NULL) continue; /* maybe you'll get lucky next time. */ mnt_dev_len = SDL_strlen(mntent->mnt_fsname) + 1; mnt_dev = SDL_stack_alloc(char, mnt_dev_len); if (mnt_dev == NULL) { SDL_stack_free(mnt_type); continue; } SDL_strlcpy(mnt_type, mntent->mnt_type, mnt_type_len); SDL_strlcpy(mnt_dev, mntent->mnt_fsname, mnt_dev_len); /* Handle "supermount" filesystem mounts */ if ( SDL_strcmp(mnt_type, MNTTYPE_SUPER) == 0 ) { tmp = SDL_strstr(mntent->mnt_opts, "fs="); if ( tmp ) { SDL_stack_free(mnt_type); mnt_type = SDL_strdup(tmp + SDL_strlen("fs=")); if ( mnt_type ) { tmp = SDL_strchr(mnt_type, ','); if ( tmp ) { *tmp = '\0'; } } } tmp = SDL_strstr(mntent->mnt_opts, "dev="); if ( tmp ) { SDL_stack_free(mnt_dev); mnt_dev = SDL_strdup(tmp + SDL_strlen("dev=")); if ( mnt_dev ) { tmp = SDL_strchr(mnt_dev, ','); if ( tmp ) { *tmp = '\0'; } } } } if ( SDL_strcmp(mnt_type, MNTTYPE_CDROM) == 0 ) { #ifdef DEBUG_CDROM fprintf(stderr, "Checking mount path from %s: %s mounted on %s of %s\n", mtab, mnt_dev, mntent->mnt_dir, mnt_type); #endif if (CheckDrive(mnt_dev, mnt_type, &stbuf) > 0) { AddDrive(mnt_dev, &stbuf); } } SDL_stack_free(mnt_dev); SDL_stack_free(mnt_type); } endmntent(mntfp); }
static void CheckMounts() { char* buffer; int bufsz; struct vmount* ptr; int ret; buffer = (char*)malloc(10); bufsz = 10; if ( buffer==NULL ) { fprintf(stderr, "Could not allocate 10 bytes in aix/SDL_syscdrom.c:CheckMounts\n" ); exit ( -10 ); } do { /* mntctrl() returns an array of all mounted filesystems */ ret = mntctl ( MCTL_QUERY, bufsz, buffer ); if ( ret == 0 ) { /* Buffer was too small, realloc. */ bufsz = *(int*)buffer; /* Required size is in first word. */ /* (whatever a word is in AIX 4.3.3) */ /* int seems to be OK in 32bit mode. */ free(buffer); buffer = (char*)malloc(bufsz); if ( buffer==NULL ) { fprintf(stderr, "Could not allocate %d bytes in aix/SDL_syscdrom.c:CheckMounts\n", bufsz ); exit ( -10 ); } } else if ( ret < 0 ) { #ifdef DEBUG_CDROM fprintf(stderr, "Error reading vmount structures\n"); #endif return; } } while ( ret == 0 ); #ifdef DEBUG_CDROM fprintf ( stderr, "Read %d vmount structures\n",ret ); #endif ptr = (struct vmount*)buffer; do { switch(ptr->vmt_gfstype) { case MNT_CDROM : { struct stat stbuf; char* text; text = (char*)ptr + ptr->vmt_data[VMT_OBJECT].vmt_off; #ifdef DEBUG_CDROM fprintf(stderr, "Checking mount path: %s mounted on %s\n", text, (char*)ptr + ptr->vmt_data[VMT_STUB].vmt_off ); #endif if ( CheckDrive( text, &stbuf) > 0) { AddDrive( text, &stbuf); } } break; default : break; } ptr = (struct vmount*)((char*)ptr + ptr->vmt_length); ret--; } while ( ret > 0 ); free ( buffer ); }