bhyve-fw: drop CSM
[oi-userland.git] / components / library / libdiscid / patches / 01-removable-devices-names.patch
blob3ff61b5b9c4731d605d1f3288c22fd46e4152a36
1 --- libdiscid-0.6.1/src/disc_solaris.c 2013-10-03 22:01:15.000000000 +0400
2 +++ disc_solaris.c 2016-02-01 12:27:13.037093987 +0300
3 @@ -33,16 +33,66 @@
4 #include <sys/stat.h>
5 #include <sys/ioctl.h>
6 #include <sys/cdio.h>
7 +#include <dirent.h>
8 +#include <errno.h>
9 +#include <limits.h>
10 +#include <sys/dkio.h>
13 #include "discid/discid.h"
14 #include "discid/discid_private.h"
15 #include "unix.h"
17 -#define NUM_CANDIDATES 2
18 +#define MAX_CANDIDATES 255
19 +#define REMOVABLE_MEDIA_DIR "/dev/removable-media/rdsk"
21 -static char *device_candidates[NUM_CANDIDATES] = {"/vol/dev/aliases/cdrom0",
22 - "/volumes/dev/aliases/cdrom0"};
23 +char *device_candidates[MAX_CANDIDATES] = {};
25 +int get_candidates_devices() {
26 + int devnum=0;
27 + DIR *devdir;
29 + devdir = opendir(REMOVABLE_MEDIA_DIR);
31 + if (devdir) {
32 + struct dirent *entry;
34 + while(entry = readdir(devdir)){
35 + int len;
37 + len=strlen(entry->d_name);
39 + /* We are looking for /dev/removable-media/rdsk/*p0 devices */
40 + if (len>2 && entry->d_name[len-1] == '0' && entry->d_name[len-2] == 'p') {
41 + char dev[PATH_MAX+1];
42 + int fl;
44 + snprintf(dev, PATH_MAX+1, "%s/%s", REMOVABLE_MEDIA_DIR, entry->d_name);
45 + fl=open(dev,O_RDONLY);
46 + if (fl != -1) {
47 + struct dk_cinfo dkci;
49 + if(ioctl(fl, DKIOCINFO, &dkci) != -1){
50 + if (dkci.dki_ctype & DKC_CDROM == DKC_CDROM) {
51 + if (devnum < MAX_CANDIDATES){
52 + devnum++;
53 + device_candidates[devnum-1]=strdup(dev);
54 + }
55 + }
56 + }
57 + }
58 + }
59 + }
60 + }
62 + /* If no devices were found, revert to old behavior */
63 + if (devnum==0) {
64 + device_candidates[0]=strdup("/vol/dev/aliases/cdrom0");
65 + device_candidates[1]=strdup("/volumes/dev/aliases/cdrom0");
66 + devnum=2;
67 + }
68 + return devnum;
71 int mb_disc_unix_read_toc_header(int fd, mb_disc_toc *toc) {
72 struct cdrom_tochdr th;
73 @@ -88,7 +138,15 @@
76 char *mb_disc_get_default_device_unportable(void) {
77 - return mb_disc_unix_find_device(device_candidates, NUM_CANDIDATES);
78 + int i,nc;
79 + char *ret;
81 + nc=get_candidates_devices();
82 + ret=mb_disc_unix_find_device(device_candidates, nc);
83 + for(i=0;i<nc;i++){
84 + free(device_candidates[i]);
85 + }
86 + return ret;
89 int mb_disc_has_feature_unportable(enum discid_feature feature) {