Enhance NetBSD hal support to at least be able to write files to optical media. No support for mounting yet.diff -r1.23 -r1.24 pkgsrc/sysutils/hal/Makefile
(reinoud)
@@ -1,99 +1,99 @@ | @@ -1,99 +1,99 @@ | |||
1 | # $NetBSD: Makefile,v 1.23 2008/12/19 23:13:24 jmcneill Exp $ | 1 | # $NetBSD: Makefile,v 1.24 2008/12/20 16:23:26 reinoud Exp $ | |
2 | # | 2 | # | |
3 | 3 | |||
4 | DISTNAME= hal-0.5.11 | 4 | DISTNAME= hal-0.5.11 | |
5 | PKGREVISION= 15 | 5 | PKGREVISION= 16 | |
6 | CATEGORIES= sysutils | 6 | CATEGORIES= sysutils | |
7 | MASTER_SITES= http://hal.freedesktop.org/releases/ | 7 | MASTER_SITES= http://hal.freedesktop.org/releases/ | |
8 | EXTRACT_SUFX= .tar.bz2 | 8 | EXTRACT_SUFX= .tar.bz2 | |
9 | 9 | |||
10 | MAINTAINER= jmcneill@NetBSD.org | 10 | MAINTAINER= jmcneill@NetBSD.org | |
11 | HOMEPAGE= http://hal.freedesktop.org/ | 11 | HOMEPAGE= http://hal.freedesktop.org/ | |
12 | COMMENT= FreeDesktop hardware abstraction layer | 12 | COMMENT= FreeDesktop hardware abstraction layer | |
13 | 13 | |||
14 | BUILD_DEFS+= VARBASE | 14 | BUILD_DEFS+= VARBASE | |
15 | PKG_DESTDIR_SUPPORT= user-destdir | 15 | PKG_DESTDIR_SUPPORT= user-destdir | |
16 | 16 | |||
17 | GNU_CONFIGURE= YES | 17 | GNU_CONFIGURE= YES | |
18 | USE_DIRS+= xdg-1.4 | 18 | USE_DIRS+= xdg-1.4 | |
19 | USE_PKGLOCALEDIR= YES | 19 | USE_PKGLOCALEDIR= YES | |
20 | USE_TOOLS+= gmake intltool msgfmt perl pkg-config | 20 | USE_TOOLS+= gmake intltool msgfmt perl pkg-config | |
21 | USE_TOOLS+= autoconf automake autoreconf | 21 | USE_TOOLS+= autoconf automake autoreconf | |
22 | USE_LIBTOOL= YES | 22 | USE_LIBTOOL= YES | |
23 | 23 | |||
24 | MAKE_DIRS= ${VARBASE}/cache/hald | 24 | MAKE_DIRS= ${VARBASE}/cache/hald | |
25 | SPECIAL_PERMS+= ${VARBASE}/cache/hald ${HAL_USER} ${HAL_GROUP} 0644 | 25 | SPECIAL_PERMS+= ${VARBASE}/cache/hald ${HAL_USER} ${HAL_GROUP} 0644 | |
26 | 26 | |||
27 | EGDIR= ${PREFIX}/share/examples/hal | 27 | EGDIR= ${PREFIX}/share/examples/hal | |
28 | 28 | |||
29 | CONF_FILES= ${EGDIR}/hal.conf ${PKG_SYSCONFBASE}/dbus-1/system.d/hal.conf | 29 | CONF_FILES= ${EGDIR}/hal.conf ${PKG_SYSCONFBASE}/dbus-1/system.d/hal.conf | |
30 | 30 | |||
31 | CONFIGURE_ARGS+= --localstatedir=${VARBASE} | 31 | CONFIGURE_ARGS+= --localstatedir=${VARBASE} | |
32 | CONFIGURE_ARGS+= --with-pci-ids=${PREFIX}/share/pciids | 32 | CONFIGURE_ARGS+= --with-pci-ids=${PREFIX}/share/pciids | |
33 | CONFIGURE_ARGS+= --with-usb-ids=${PREFIX}/share/usbids | 33 | CONFIGURE_ARGS+= --with-usb-ids=${PREFIX}/share/usbids | |
34 | 34 | |||
35 | .include "../../mk/bsd.prefs.mk" | 35 | .include "../../mk/bsd.prefs.mk" | |
36 | 36 | |||
37 | .if ${OPSYS} == "FreeBSD" || ${OPSYS} == "DragonFly" | 37 | .if ${OPSYS} == "FreeBSD" || ${OPSYS} == "DragonFly" | |
38 | .include "../../devel/libvolume_id/buildlink3.mk" | 38 | .include "../../devel/libvolume_id/buildlink3.mk" | |
39 | CONFIGURE_ARGS+= --with-eject=/usr/sbin/cdcontrol | 39 | CONFIGURE_ARGS+= --with-eject=/usr/sbin/cdcontrol | |
40 | CONFIGURE_ARGS+= --with-backend=freebsd | 40 | CONFIGURE_ARGS+= --with-backend=freebsd | |
41 | PLIST_SRC= PLIST.FreeBSD PLIST | 41 | PLIST_SRC= PLIST.FreeBSD PLIST | |
42 | .endif | 42 | .endif | |
43 | 43 | |||
44 | .if !empty(MACHINE_PLATFORM:MNetBSD-[5-9]*) | 44 | .if !empty(MACHINE_PLATFORM:MNetBSD-[5-9]*) | |
45 | .include "../../devel/libvolume_id/buildlink3.mk" | 45 | .include "../../devel/libvolume_id/buildlink3.mk" | |
46 | CONFIGURE_ARGS+= --with-backend=netbsd | 46 | CONFIGURE_ARGS+= --with-backend=netbsd | |
47 | HAL_GROUP= operator | 47 | HAL_GROUP= operator | |
48 | .elif ${OPSYS} == "NetBSD" | 48 | .elif ${OPSYS} == "NetBSD" | |
49 | # Pull in the dummy backend for older NetBSD | 49 | # Pull in the dummy backend for older NetBSD | |
50 | CONFIGURE_ARGS+= --with-backend=dummy | 50 | CONFIGURE_ARGS+= --with-backend=dummy | |
51 | PLIST_SRC= PLIST | 51 | PLIST_SRC= PLIST | |
52 | .endif | 52 | .endif | |
53 | 53 | |||
54 | .if ${OPSYS} == "Linux" | 54 | .if ${OPSYS} == "Linux" | |
55 | .include "../../devel/libusb/buildlink3.mk" | 55 | .include "../../devel/libusb/buildlink3.mk" | |
56 | .include "../../devel/libvolume_id/buildlink3.mk" | 56 | .include "../../devel/libvolume_id/buildlink3.mk" | |
57 | .include "../../sysutils/pciutils/buildlink3.mk" | 57 | .include "../../sysutils/pciutils/buildlink3.mk" | |
58 | CONFIGURE_ARGS+= --with-backend=linux | 58 | CONFIGURE_ARGS+= --with-backend=linux | |
59 | .endif | 59 | .endif | |
60 | 60 | |||
61 | REPLACE_INTERPRETER+= bash | 61 | REPLACE_INTERPRETER+= bash | |
62 | REPLACE.bash.old= /bin/bash | 62 | REPLACE.bash.old= /bin/bash | |
63 | REPLACE.bash.new= ${SH} | 63 | REPLACE.bash.new= ${SH} | |
64 | .for halscript in luks-remove luks-setup luks-teardown system-wol-enable system-wol-enabled system-wol-supported | 64 | .for halscript in luks-remove luks-setup luks-teardown system-wol-enable system-wol-enabled system-wol-supported | |
65 | REPLACE_FILES.bash+= tools/hal-${halscript} | 65 | REPLACE_FILES.bash+= tools/hal-${halscript} | |
66 | .endfor | 66 | .endfor | |
67 | 67 | |||
68 | HAL_USER?= haldaemon | 68 | HAL_USER?= haldaemon | |
69 | HAL_GROUP?= haldaemon | 69 | HAL_GROUP?= haldaemon | |
70 | CONFIGURE_ARGS+= --with-hal-user=${HAL_USER} | 70 | CONFIGURE_ARGS+= --with-hal-user=${HAL_USER} | |
71 | CONFIGURE_ARGS+= --with-hal-group=${HAL_GROUP} | 71 | CONFIGURE_ARGS+= --with-hal-group=${HAL_GROUP} | |
72 | 72 | |||
73 | RCD_SCRIPTS= hal | 73 | RCD_SCRIPTS= hal | |
74 | 74 | |||
75 | .if ${HAL_GROUP} != "operator" | 75 | .if ${HAL_GROUP} != "operator" | |
76 | PKG_GROUPS= ${HAL_GROUP} | 76 | PKG_GROUPS= ${HAL_GROUP} | |
77 | .endif | 77 | .endif | |
78 | PKG_USERS= ${HAL_USER}:${HAL_GROUP} | 78 | PKG_USERS= ${HAL_USER}:${HAL_GROUP} | |
79 | PKG_HOME.haldaemon= ${VARBASE}/run/hal | 79 | PKG_HOME.haldaemon= ${VARBASE}/run/hal | |
80 | 80 | |||
81 | FILES_SUBST+= HAL_USER=${HAL_USER} | 81 | FILES_SUBST+= HAL_USER=${HAL_USER} | |
82 | FILES_SUBST+= HAL_GROUP=${HAL_GROUP} | 82 | FILES_SUBST+= HAL_GROUP=${HAL_GROUP} | |
83 | 83 | |||
84 | post-extract: | 84 | post-extract: | |
85 | ${CP} -r ${FILESDIR}/hald-netbsd ${WRKSRC}/hald/netbsd | 85 | ${CP} -r ${FILESDIR}/hald-netbsd ${WRKSRC}/hald/netbsd | |
86 | ${CP} -r ${FILESDIR}/tools-netbsd ${WRKSRC}/tools/netbsd | 86 | ${CP} -r ${FILESDIR}/tools-netbsd ${WRKSRC}/tools/netbsd | |
87 | 87 | |||
88 | pre-configure: | 88 | pre-configure: | |
89 | cd ${WRKSRC} && autoreconf -vi | 89 | cd ${WRKSRC} && autoreconf -vi | |
90 | 90 | |||
91 | .include "../../devel/GConf/schemas.mk" | 91 | .include "../../devel/GConf/schemas.mk" | |
92 | .include "../../devel/glib2/buildlink3.mk" | 92 | .include "../../devel/glib2/buildlink3.mk" | |
93 | .include "../../misc/pciids/buildlink3.mk" | 93 | .include "../../misc/pciids/buildlink3.mk" | |
94 | .include "../../misc/usbids/buildlink3.mk" | 94 | .include "../../misc/usbids/buildlink3.mk" | |
95 | .include "../../security/policykit/buildlink3.mk" | 95 | .include "../../security/policykit/buildlink3.mk" | |
96 | .include "../../sysutils/dbus/buildlink3.mk" | 96 | .include "../../sysutils/dbus/buildlink3.mk" | |
97 | .include "../../sysutils/dbus-glib/buildlink3.mk" | 97 | .include "../../sysutils/dbus-glib/buildlink3.mk" | |
98 | .include "../../sysutils/hal-info/buildlink3.mk" | 98 | .include "../../sysutils/hal-info/buildlink3.mk" | |
99 | .include "../../mk/bsd.pkg.mk" | 99 | .include "../../mk/bsd.pkg.mk" |
@@ -1,411 +1,482 @@ | @@ -1,411 +1,482 @@ | |||
1 | /* | 1 | /* | |
2 | * Copyright (c) 2008 Reinoud Zandijk | 2 | * Copyright (c) 2008 Reinoud Zandijk | |
3 | * All rights reserved. | 3 | * All rights reserved. | |
4 | * | 4 | * | |
5 | * Redistribution and use in source and binary forms, with or without | 5 | * Redistribution and use in source and binary forms, with or without | |
6 | * modification, are permitted provided that the following conditions | 6 | * modification, are permitted provided that the following conditions | |
7 | * are met: | 7 | * are met: | |
8 | * 1. Redistributions of source code must retain the above copyright | 8 | * 1. Redistributions of source code must retain the above copyright | |
9 | * notice, this list of conditions and the following disclaimer. | 9 | * notice, this list of conditions and the following disclaimer. | |
10 | * 2. Redistributions in binary form must reproduce the above copyright | 10 | * 2. Redistributions in binary form must reproduce the above copyright | |
11 | * notice, this list of conditions and the following disclaimer in the | 11 | * notice, this list of conditions and the following disclaimer in the | |
12 | * documentation and/or other materials provided with the distribution. | 12 | * documentation and/or other materials provided with the distribution. | |
13 | * | 13 | * | |
14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | |
15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |
16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | |
17 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | 17 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | |
18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | 18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | |
19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | |
23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
24 | * | 24 | * | |
25 | */ | 25 | */ | |
26 | 26 | |||
27 | #ifdef HAVE_CONFIG_H | 27 | #ifdef HAVE_CONFIG_H | |
28 | # include <config.h> | 28 | # include <config.h> | |
29 | #endif | 29 | #endif | |
30 | 30 | |||
31 | #include <stdio.h> | 31 | #include <stdio.h> | |
32 | #include <sys/types.h> | 32 | #include <sys/types.h> | |
33 | #include <sys/scsiio.h> | 33 | #include <sys/scsiio.h> | |
34 | #include <sys/disklabel.h> | 34 | #include <sys/disklabel.h> | |
35 | #include <dev/scsipi/scsi_spc.h> | 35 | #include <dev/scsipi/scsi_spc.h> | |
36 | #include <dev/scsipi/scsipi_all.h> | 36 | #include <dev/scsipi/scsipi_all.h> | |
37 | #include <dev/scsipi/scsipi_cd.h> | 37 | #include <dev/scsipi/scsipi_cd.h> | |
38 | #include <string.h> | 38 | #include <string.h> | |
39 | #include <machine/disklabel.h> | 39 | #include <machine/disklabel.h> | |
40 | #include <sys/types.h> | 40 | #include <sys/types.h> | |
41 | #include <sys/stat.h> | 41 | #include <sys/stat.h> | |
42 | #include <ctype.h> | 42 | #include <ctype.h> | |
43 | #include <fcntl.h> | 43 | #include <fcntl.h> | |
44 | 44 | |||
45 | #include "../osspec.h" | 45 | #include "../osspec.h" | |
46 | #include "../logger.h" | 46 | #include "../logger.h" | |
47 | #include "../hald.h" | 47 | #include "../hald.h" | |
48 | #include "../hald_dbus.h" | 48 | #include "../hald_dbus.h" | |
49 | #include "../device_info.h" | 49 | #include "../device_info.h" | |
50 | #include "../util.h" | 50 | #include "../util.h" | |
51 | #include "devinfo_optical.h" | 51 | #include "devinfo_optical.h" | |
52 | 52 | |||
53 | #include "devinfo.h" | 53 | #include "devinfo.h" | |
54 | 54 | |||
55 | 55 | |||
56 | #define DEVINFO_PROBE_STORAGE_TIMEOUT 60000 | 56 | #define DEVINFO_PROBE_STORAGE_TIMEOUT 60000 | |
57 | static HalDevice *devinfo_optical_add(HalDevice *, const char *, char *,char *); | 57 | static HalDevice *devinfo_optical_add(HalDevice *, const char *, char *,char *); | |
58 | static HalDevice *devinfo_optical_volume_add(HalDevice *, const char *, char *, char *); | |||
58 | 59 | |||
59 | 60 | |||
60 | static const gchar * | 61 | static const gchar * | |
61 | devinfo_storage_get_prober (HalDevice *d, int *timeout) | 62 | devinfo_storage_get_prober (HalDevice *d, int *timeout) | |
62 | { | 63 | { | |
63 | *timeout = DEVINFO_PROBE_STORAGE_TIMEOUT; | 64 | *timeout = DEVINFO_PROBE_STORAGE_TIMEOUT; | |
64 | return "hald-probe-storage"; | 65 | return "hald-probe-storage"; | |
65 | } | 66 | } | |
66 | 67 | |||
67 | #if notyet | 68 | #if notyet | |
68 | const gchar * | 69 | const gchar * | |
69 | devinfo_volume_get_prober (HalDevice *d, int *timeout) | 70 | devinfo_volume_get_prober (HalDevice *d, int *timeout) | |
70 | { | 71 | { | |
71 | *timeout = DEVINFO_PROBE_VOLUME_TIMEOUT; | 72 | *timeout = DEVINFO_PROBE_VOLUME_TIMEOUT; | |
72 | return "hald-probe-volume"; | 73 | return "hald-probe-volume"; | |
73 | } | 74 | } | |
74 | #endif | 75 | #endif | |
75 | 76 | |||
76 | DevinfoDevHandler devinfo_optical_handler = { | 77 | DevinfoDevHandler devinfo_optical_handler = { | |
77 | devinfo_optical_add, | 78 | devinfo_optical_add, | |
78 | NULL, /* remove */ | 79 | NULL, /* remove */ | |
79 | NULL, /* hotplug_begin_add */ | 80 | NULL, /* hotplug_begin_add */ | |
80 | NULL, /* hotplug_begin_remove */ | 81 | NULL, /* hotplug_begin_remove */ | |
81 | NULL, /* probing_done */ | 82 | NULL, /* probing_done */ | |
82 | NULL /* devinfo_storage_get_prober */ /* get_prober */ | 83 | NULL /* devinfo_storage_get_prober */ /* get_prober */ | |
83 | }; | 84 | }; | |
84 | 85 | |||
85 | 86 | |||
87 | DevinfoDevHandler devinfo_optical_volume_handler = { | |||
88 | devinfo_optical_volume_add, | |||
89 | NULL, /* remove */ | |||
90 | NULL, /* hotplug_begin_add */ | |||
91 | NULL, /* hotplug_begin_remove */ | |||
92 | NULL, /* probing_done */ | |||
93 | NULL /* devinfo_storage_get_prober */ /* get_prober */ | |||
94 | }; | |||
95 | ||||
96 | ||||
86 | /* XXX i dont know how to link cdutils here XXX ! */ | 97 | /* XXX i dont know how to link cdutils here XXX ! */ | |
87 | bool | 98 | static bool | |
88 | scsi_command (int fd, void *cmd, size_t cmdlen, void *data, size_t datalen, | 99 | scsi_command (int fd, void *cmd, size_t cmdlen, void *data, size_t datalen, | |
89 | int timeout, int flags) | 100 | int timeout, int flags) | |
90 | { | 101 | { | |
91 | scsireq_t req; | 102 | scsireq_t req; | |
92 | 103 | |||
93 | memset(&req, 0, sizeof(req)); | 104 | memset(&req, 0, sizeof(req)); | |
94 | memcpy(req.cmd, cmd, cmdlen); | 105 | memcpy(req.cmd, cmd, cmdlen); | |
95 | req.cmdlen = cmdlen; | 106 | req.cmdlen = cmdlen; | |
96 | req.databuf = data; | 107 | req.databuf = data; | |
97 | req.datalen = datalen; | 108 | req.datalen = datalen; | |
98 | req.timeout = timeout; | 109 | req.timeout = timeout; | |
99 | req.flags = flags; | 110 | req.flags = flags; | |
100 | req.senselen = SENSEBUFLEN; | 111 | req.senselen = SENSEBUFLEN; | |
101 | 112 | |||
102 | if (ioctl(fd, SCIOCCOMMAND, &req) == -1) | 113 | if (ioctl(fd, SCIOCCOMMAND, &req) == -1) | |
103 | return false; | 114 | return false; | |
104 | if (req.retsts == SCCMD_OK) | 115 | if (req.retsts == SCCMD_OK) | |
105 | return true; | 116 | return true; | |
106 | return false; | 117 | return false; | |
107 | } | 118 | } | |
108 | 119 | |||
109 | 120 | |||
110 | static void | 121 | static void | |
111 | optical_get_str(char *str, unsigned char *buf, int len) | 122 | optical_get_str(char *str, unsigned char *buf, int len) | |
112 | { | 123 | { | |
113 | char *pos; | 124 | char *pos; | |
114 | int i; | 125 | int i; | |
115 | 126 | |||
116 | pos = str; | 127 | pos = str; | |
117 | for (i = 0; i < len; i++) { | 128 | for (i = 0; i < len; i++) { | |
118 | if (isprint(buf[i])) | 129 | if (isprint(buf[i])) | |
119 | *pos++ = buf[i]; | 130 | *pos++ = buf[i]; | |
120 | } | 131 | } | |
121 | *pos = (char) 0; | 132 | *pos = (char) 0; | |
122 | pos--; | 133 | pos--; | |
123 | while (*pos == ' ') | 134 | while (*pos == ' ') | |
124 | *pos-- = (char) 0; | 135 | *pos-- = (char) 0; | |
125 | } | 136 | } | |
126 | 137 | |||
127 | 138 | |||
128 | static void | 139 | static void | |
129 | devinfo_optical_identify_drive(HalDevice *d, char *devstr) | 140 | devinfo_optical_identify_drive(HalDevice *d, char *devstr) | |
130 | { | 141 | { | |
131 | uint8_t cmd[12], buf[100]; | 142 | uint8_t cmd[12], buf[100]; | |
132 | char str[100]; | 143 | char str[100]; | |
133 | int fd, ok; | 144 | int fd, ok; | |
134 | 145 | |||
135 | fd = open(devstr, O_RDONLY, 0); | 146 | fd = open(devstr, O_RDONLY, 0); | |
136 | if(!fd) | 147 | if(!fd) | |
137 | return; | 148 | return; | |
138 | 149 | |||
139 | HAL_INFO(("devinfo_optical_identify_drive: SCSI call")); | 150 | HAL_INFO(("devinfo_optical_identify_drive: SCSI call")); | |
140 | cmd[0] = 0x12; /* INQUIRY */ | 151 | cmd[0] = 0x12; /* INQUIRY */ | |
141 | cmd[1] = 0; /* basic inquiry */ | 152 | cmd[1] = 0; /* basic inquiry */ | |
142 | cmd[2] = 0; /* no page or operation code */ | 153 | cmd[2] = 0; /* no page or operation code */ | |
143 | cmd[3] = 0; /* reserved/MSB result */ | 154 | cmd[3] = 0; /* reserved/MSB result */ | |
144 | cmd[4] = 96; /* all but vendor specific */ | 155 | cmd[4] = 96; /* all but vendor specific */ | |
145 | cmd[5] = 0; /* control */ | 156 | cmd[5] = 0; /* control */ | |
146 | ok = scsi_command(fd, cmd, 6, buf, 96, 30000, SCCMD_READ); | 157 | ok = scsi_command(fd, cmd, 6, buf, 96, 30000, SCCMD_READ); | |
147 | close(fd); | 158 | close(fd); | |
148 | 159 | |||
149 | if (!ok) | 160 | if (!ok) | |
150 | return; | 161 | return; | |
151 | 162 | |||
152 | optical_get_str(str, buf+8, 8); | 163 | optical_get_str(str, buf+8, 8); | |
153 | hal_device_property_set_string (d, "storage.vendor", str); | 164 | hal_device_property_set_string (d, "storage.vendor", str); | |
154 | optical_get_str(str, buf+16, 16); | 165 | optical_get_str(str, buf+16, 16); | |
155 | hal_device_property_set_string (d, "storage.model", str); | 166 | hal_device_property_set_string (d, "storage.model", str); | |
156 | optical_get_str(str, buf+32, 4); | 167 | optical_get_str(str, buf+32, 4); | |
157 | hal_device_property_set_string (d, "storage.firmware_version", str); | 168 | hal_device_property_set_string (d, "storage.firmware_version", str); | |
158 | } | 169 | } | |
159 | 170 | |||
160 | 171 | |||
161 | static char const * | 172 | static char const * | |
162 | get_profile_name(HalDevice *d, int profile) | 173 | get_profile_name(HalDevice *d, int profile) | |
163 | { | 174 | { | |
164 | switch (profile) { | 175 | switch (profile) { | |
165 | case 0x00 : return NULL; // "Unknown[0] profile"; | 176 | case 0x00 : return NULL; // "Unknown[0] profile"; | |
166 | case 0x01 : return NULL; // "Non removeable disc"; | 177 | case 0x01 : return NULL; // "Non removeable disc"; | |
167 | case 0x02 : return NULL; // "Removable disc"; | 178 | case 0x02 : return NULL; // "Removable disc"; | |
168 | case 0x03 : return "mo"; // Magneto Optical with sector erase"; | 179 | case 0x03 : return "mo"; // Magneto Optical with sector erase"; | |
169 | case 0x04 : return "mo"; // "Magneto Optical write once"; | 180 | case 0x04 : return "mo"; // "Magneto Optical write once"; | |
170 | case 0x05 : return "mo"; // "Advance Storage Magneto Optical"; | 181 | case 0x05 : return "mo"; // "Advance Storage Magneto Optical"; | |
171 | case 0x08 : return "cd"; // "CD-ROM"; no writing | 182 | case 0x08 : return "cd"; // "CD-ROM"; no writing | |
172 | case 0x09 : return "cdr"; // "CD-R recordable"; | 183 | case 0x09 : return "cdr"; // "CD-R recordable"; | |
173 | case 0x0a : return "cdrw"; // "CD-RW rewritable"; | 184 | case 0x0a : return "cdrw"; // "CD-RW rewritable"; | |
174 | case 0x10 : return "dvd"; // "DVD-ROM"; no writing | 185 | case 0x10 : return "dvd"; // "DVD-ROM"; no writing | |
175 | case 0x11 : return "dvdr"; // "DVD-R sequential"; | 186 | case 0x11 : return "dvdr"; // "DVD-R sequential"; | |
176 | case 0x12 : return "dvdram"; // "DVD-RAM rewritable"; | 187 | case 0x12 : return "dvdram"; // "DVD-RAM rewritable"; | |
177 | case 0x13 : return "dvdrw"; // "DVD-RW restricted overwrite"; | 188 | case 0x13 : return "dvdrw"; // "DVD-RW restricted overwrite"; | |
178 | case 0x14 : return "dvdrw"; // "DVD-RW sequential"; | 189 | case 0x14 : return "dvdrw"; // "DVD-RW sequential"; | |
179 | case 0x15 : return "dvdr"; // "DVD-R dual layer sequential"; | 190 | case 0x15 : return "dvdr"; // "DVD-R dual layer sequential"; | |
180 | case 0x16 : return "dvdr"; // "DVD-R dual layer jump"; | 191 | case 0x16 : return "dvdr"; // "DVD-R dual layer jump"; | |
181 | case 0x17 : return "dvdrw"; // "DVD-RW dual layer"; | 192 | case 0x17 : return "dvdrw"; // "DVD-RW dual layer"; | |
182 | case 0x18 : return NULL; // "DVD-Download disc"; UNKNOWN | 193 | case 0x18 : return NULL; // "DVD-Download disc"; UNKNOWN | |
183 | case 0x1a : return "dvdplusrw"; // "DVD+RW rewritable"; | 194 | case 0x1a : return "dvdplusrw"; // "DVD+RW rewritable"; | |
184 | case 0x1b : return "dvdplusr"; // "DVD+R recordable"; | 195 | case 0x1b : return "dvdplusr"; // "DVD+R recordable"; | |
185 | case 0x20 : return "ddcd"; // "DDCD readonly (retracted)"; no writing | 196 | case 0x20 : return "ddcd"; // "DDCD readonly (retracted)"; no writing | |
186 | case 0x21 : return "ddcdr"; // "DDCD-R recordable (retracted)"; OK? | 197 | case 0x21 : return "ddcdr"; // "DDCD-R recordable (retracted)"; OK? | |
187 | case 0x22 : return "ddcdrw"; // "DDCD-RW rewritable (retracted)"; OK? | 198 | case 0x22 : return "ddcdrw"; // "DDCD-RW rewritable (retracted)"; OK? | |
188 | case 0x2a : return "dvdplusrwdl";//"DVD+RW double layer"; | 199 | case 0x2a : return "dvdplusrwdl";//"DVD+RW double layer"; | |
189 | case 0x2b : return "dvdplusrdl";// "DVD+R double layer"; | 200 | case 0x2b : return "dvdplusrdl";// "DVD+R double layer"; | |
190 | case 0x40 : return "bd"; // "BD-ROM"; | 201 | case 0x40 : return "bd"; // "BD-ROM"; | |
191 | case 0x41 : return "bdr"; // "BD-R Sequential Recording (SRM)"; | 202 | case 0x41 : return "bdr"; // "BD-R Sequential Recording (SRM)"; | |
192 | case 0x42 : return "bdr"; // "BD-R Random Recording (RRM)"; | 203 | case 0x42 : return "bdr"; // "BD-R Random Recording (RRM)"; | |
193 | case 0x43 : return "bdre"; // "BD-RE rewritable"; | 204 | case 0x43 : return "bdre"; // "BD-RE rewritable"; | |
194 | case 0x50 : return "hddvd"; // "HD DVD-ROM (retracted)"; | 205 | case 0x50 : return "hddvd"; // "HD DVD-ROM (retracted)"; | |
195 | case 0x51 : return "hddvdr"; // "HD DVD-R (retracted)"; | 206 | case 0x51 : return "hddvdr"; // "HD DVD-R (retracted)"; | |
196 | case 0x52 : return "hddvdram"; // "HD DVD-RAM (retracted)"; | 207 | case 0x52 : return "hddvdram"; // "HD DVD-RAM (retracted)"; | |
197 | case 0x53 : return "hddvdrw"; // "HD DVD-RW (retracted)"; | 208 | case 0x53 : return "hddvdrw"; // "HD DVD-RW (retracted)"; | |
198 | case 0x58 : return "hddvdrdl"; // "HD DVD-R dual layer (retracted)"; | 209 | case 0x58 : return "hddvdrdl"; // "HD DVD-R dual layer (retracted)"; | |
199 | case 0x5a : return "hddvdrwdl"; // "HD DVD-RW dual layer (retracted)"; | 210 | case 0x5a : return "hddvdrwdl"; // "HD DVD-RW dual layer (retracted)"; | |
200 | } | 211 | } | |
201 | /* reserved */ | 212 | /* reserved */ | |
202 | return NULL; | 213 | return NULL; | |
203 | } | 214 | } | |
204 | 215 | |||
205 | 216 | |||
206 | #define feat_tbl_len 300 | 217 | #define feat_tbl_len 300 | |
207 | #define max_profile 255 | 218 | #define max_profile 255 | |
208 | static void | 219 | static void | |
209 | devinfo_optical_disc_caps(int fd, HalDevice *d) | 220 | devinfo_optical_disc_caps(int fd, HalDevice *d) | |
210 | { | 221 | { | |
211 | uint8_t cmd[12], buf[feat_tbl_len], *fpos, *pos; | 222 | uint8_t cmd[12], buf[feat_tbl_len], *fpos, *pos; | |
212 | char str[100]; | 223 | char str[100]; | |
213 | uint8_t present[max_profile+1]; | 224 | uint8_t present[max_profile+1]; | |
214 | char const *name; | 225 | char const *name; | |
215 | int feature, feature_cur, feature_len, req_feature; | 226 | int feature, feature_cur, feature_len, req_feature; | |
216 | int cnt, profile; | 227 | int cnt, profile; | |
217 | int mrw, mrw_w, ok; | 228 | int mrw, mrw_w, ok; | |
218 | 229 | |||
219 | /* set defaults */ | 230 | /* set defaults */ | |
220 | for (profile = 0; profile <= max_profile; profile++) { | 231 | for (profile = 0; profile <= max_profile; profile++) { | |
221 | present[profile] = FALSE; | 232 | present[profile] = FALSE; | |
222 | } | 233 | } | |
223 | 234 | |||
224 | HAL_INFO(("devinfo_optical_disc_caps: get feature 0 SCSI call")); | 235 | HAL_INFO(("devinfo_optical_disc_caps: get feature 0 SCSI call")); | |
225 | req_feature = 0; | 236 | req_feature = 0; | |
226 | cmd[0] = 0x46; /* Get configuration */ | 237 | cmd[0] = 0x46; /* Get configuration */ | |
227 | cmd[1] = 0; /* RT=0 -> all independent of current setting */ | 238 | cmd[1] = 0; /* RT=0 -> all independent of current setting */ | |
228 | cmd[2] = (req_feature) >> 8; /* MSB feature number */ | 239 | cmd[2] = (req_feature) >> 8; /* MSB feature number */ | |
229 | cmd[3] = (req_feature) & 0xff; /* LSB feature number */ | 240 | cmd[3] = (req_feature) & 0xff; /* LSB feature number */ | |
230 | cmd[7] = (feat_tbl_len) >> 8; /* MSB buffersize */ | 241 | cmd[7] = (feat_tbl_len) >> 8; /* MSB buffersize */ | |
231 | cmd[8] = (feat_tbl_len) & 0xff; /* LSB buffersize */ | 242 | cmd[8] = (feat_tbl_len) & 0xff; /* LSB buffersize */ | |
232 | cmd[9] = 0; /* control */ | 243 | cmd[9] = 0; /* control */ | |
233 | ok = scsi_command(fd, cmd, 10, buf, feat_tbl_len, 30000, SCCMD_READ); | 244 | ok = scsi_command(fd, cmd, 10, buf, feat_tbl_len, 30000, SCCMD_READ); | |
234 | 245 | |||
235 | if (!ok) | 246 | if (!ok) | |
236 | return; | 247 | return; | |
237 | 248 | |||
238 | HAL_INFO(("devinfo_optical_disc_caps: processing profiles\n")); | 249 | HAL_INFO(("devinfo_optical_disc_caps: processing profiles\n")); | |
239 | fpos = buf + 8; | 250 | fpos = buf + 8; | |
240 | 251 | |||
241 | feature = fpos[1] | (fpos[0] << 8); | 252 | feature = fpos[1] | (fpos[0] << 8); | |
242 | feature_cur = (fpos[2] & 1); | 253 | feature_cur = (fpos[2] & 1); | |
243 | feature_len = fpos[3]; | 254 | feature_len = fpos[3]; | |
244 | if (feature != 0) { | 255 | if (feature != 0) { | |
245 | HAL_INFO(("cdrom drive on crack, its not returning feature 0\n")); | 256 | HAL_INFO(("cdrom drive on crack, its not returning feature 0\n")); | |
246 | return; | 257 | return; | |
247 | } | 258 | } | |
248 | 259 | |||
249 | if ((feature_len & 3) != 0) | 260 | if ((feature_len & 3) != 0) | |
250 | HAL_INFO(("*** drive returned bad feature length ***")); | 261 | HAL_INFO(("*** drive returned bad feature length ***")); | |
251 | 262 | |||
252 | /* process feature */ | 263 | /* process feature */ | |
253 | pos = &fpos[4]; | 264 | pos = &fpos[4]; | |
254 | for (cnt=0; cnt < feature_len; cnt += 4) { | 265 | for (cnt=0; cnt < feature_len; cnt += 4) { | |
255 | profile = pos[1] | (pos[0] << 8); | 266 | profile = pos[1] | (pos[0] << 8); | |
256 | if (profile <= max_profile) { | 267 | if (profile <= max_profile) { | |
257 | present[profile] = TRUE; | 268 | present[profile] = TRUE; | |
258 | } else { | 269 | } else { | |
259 | if (profile != 0xffff) | 270 | if (profile != 0xffff) | |
260 | HAL_INFO(("devinfo_optical_disc_caps: bump max_profile!, " | 271 | HAL_INFO(("devinfo_optical_disc_caps: bump max_profile!, " | |
261 | "found profile %d", profile)); | 272 | "found profile %d", profile)); | |
262 | } | 273 | } | |
263 | pos += 4; | 274 | pos += 4; | |
264 | } | 275 | } | |
265 | 276 | |||
266 | /* set hal properties */ | 277 | /* set hal properties */ | |
267 | for (profile = 0; profile <= max_profile; profile++) { | 278 | for (profile = 0; profile <= max_profile; profile++) { | |
268 | /* process profile */ | 279 | /* process profile */ | |
269 | name = get_profile_name(d, profile); | 280 | name = get_profile_name(d, profile); | |
270 | if (name) { | 281 | if (name) { | |
271 | strcpy(str, "storage.cdrom."); | 282 | strcpy(str, "storage.cdrom."); | |
272 | strcat(str, name); | 283 | strcat(str, name); | |
273 | HAL_INFO(("Profile %d : %s : %s", profile, str, | 284 | HAL_INFO(("Profile %d : %s : %s", profile, str, | |
274 | present[profile] ? "true":"false")); | 285 | present[profile] ? "true":"false")); | |
275 | hal_device_property_set_bool(d, str, present[profile]); | 286 | hal_device_property_set_bool(d, str, present[profile]); | |
276 | } | 287 | } | |
277 | } | 288 | } | |
278 | 289 | |||
279 | /* set MRW support; feature 0x28, version 0/1 */ | 290 | /* set MRW support; feature 0x28, version 0/1 */ | |
280 | HAL_INFO(("devinfo_optical_disc_caps: get feature 0x28 SCSI call")); | 291 | HAL_INFO(("devinfo_optical_disc_caps: get feature 0x28 SCSI call")); | |
281 | req_feature = 0x28; | 292 | req_feature = 0x28; | |
282 | cmd[0] = 0x46; /* Get configuration */ | 293 | cmd[0] = 0x46; /* Get configuration */ | |
283 | cmd[1] = 0; /* RT=0 -> all independent of current setting */ | 294 | cmd[1] = 0; /* RT=0 -> all independent of current setting */ | |
284 | cmd[2] = (req_feature) >> 8; /* MSB feature number */ | 295 | cmd[2] = (req_feature) >> 8; /* MSB feature number */ | |
285 | cmd[3] = (req_feature) & 0xff; /* LSB feature number */ | 296 | cmd[3] = (req_feature) & 0xff; /* LSB feature number */ | |
286 | cmd[7] = (feat_tbl_len) >> 8; /* MSB buffersize */ | 297 | cmd[7] = (feat_tbl_len) >> 8; /* MSB buffersize */ | |
287 | cmd[8] = (feat_tbl_len) & 0xff; /* LSB buffersize */ | 298 | cmd[8] = (feat_tbl_len) & 0xff; /* LSB buffersize */ | |
288 | cmd[9] = 0; /* control */ | 299 | cmd[9] = 0; /* control */ | |
289 | ok = scsi_command(fd, cmd, 10, buf, feat_tbl_len, 30000, SCCMD_READ); | 300 | ok = scsi_command(fd, cmd, 10, buf, feat_tbl_len, 30000, SCCMD_READ); | |
290 | 301 | |||
291 | if (!ok) | 302 | if (!ok) | |
292 | return; | 303 | return; | |
293 | 304 | |||
294 | feature = fpos[1] | (fpos[0] << 8); | 305 | feature = fpos[1] | (fpos[0] << 8); | |
295 | feature_cur = (fpos[2] & 1); | 306 | feature_cur = (fpos[2] & 1); | |
296 | feature_len = fpos[3]; | 307 | feature_len = fpos[3]; | |
297 | 308 | |||
298 | if ((feature_len & 3) != 0) | 309 | if ((feature_len & 3) != 0) | |
299 | HAL_INFO(("*** drive returned bad feature length ***")); | 310 | HAL_INFO(("*** drive returned bad feature length ***")); | |
300 | 311 | |||
301 | HAL_INFO(("devinfo_optical_disc_caps: processing MRW\n")); | 312 | HAL_INFO(("devinfo_optical_disc_caps: processing MRW\n")); | |
302 | /* process feature */ | 313 | /* process feature */ | |
303 | pos = &fpos[4]; | 314 | pos = &fpos[4]; | |
304 | mrw = FALSE; | 315 | mrw = FALSE; | |
305 | mrw_w = FALSE; | 316 | mrw_w = FALSE; | |
306 | if (feature == 0x28) { | 317 | if (feature == 0x28) { | |
307 | mrw = TRUE; | 318 | mrw = TRUE; | |
308 | if (pos[0] & 1) | 319 | if (pos[0] & 1) | |
309 | mrw_w = TRUE; | 320 | mrw_w = TRUE; | |
310 | } | 321 | } | |
311 | hal_device_property_set_bool(d, "storage.cdrom.mrw", mrw); | 322 | hal_device_property_set_bool(d, "storage.cdrom.mrw", mrw); | |
312 | hal_device_property_set_bool(d, "storage.cdrom.mrw_w", mrw_w); | 323 | hal_device_property_set_bool(d, "storage.cdrom.mrw_w", mrw_w); | |
313 | 324 | |||
314 | /* | 325 | /* | |
315 | * XXX very rare to now have multi-session support; could be detected | 326 | * XXX very rare to now have multi-session support; could be detected | |
316 | * in the change bits of page 5, but set to true for now | 327 | * in the change bits of page 5, but set to true for now | |
317 | */ | 328 | */ | |
318 | hal_device_property_set_bool(d,"storage.cdrom.support_multisession", TRUE); | 329 | hal_device_property_set_bool(d, "storage.cdrom.support_multisession", TRUE); | |
319 | 330 | |||
320 | /* XXX realy? */ | 331 | /* XXX realy? */ | |
321 | hal_device_property_set_bool(d,"storage.cdrom.support_media_changed", TRUE); | 332 | hal_device_property_set_bool(d, "storage.cdrom.support_media_changed", TRUE); | |
322 | 333 | |||
323 | /* media dependent; addon-storage will handle these */ | 334 | /* media dependent; addon-storage will handle these */ | |
324 | //hal_device_property_set_int(d,"storage.cdrom.read_speed", 0); | 335 | //hal_device_property_set_int(d,"storage.cdrom.read_speed", 0); | |
325 | //hal_device_property_set_int(d,"storage.cdrom.write_speed", 0); | 336 | //hal_device_property_set_int(d,"storage.cdrom.write_speed", 0); | |
326 | //hal_device_property_set_string(d, "storage.cdrom.write_speeds", FALSE); | 337 | //hal_device_property_set_string(d, "storage.cdrom.write_speeds", FALSE); | |
327 | 338 | |||
328 | } | 339 | } | |
329 | #undef max_profile | 340 | #undef max_profile | |
330 | #undef feat_tbl_len | 341 | #undef feat_tbl_len | |
331 | 342 | |||
332 | 343 | |||
333 | static HalDevice * | 344 | static HalDevice * | |
345 | devinfo_optical_volume_add(HalDevice *parent, const char *devnode, char *devfs_path, char *device_type) | |||
346 | { | |||
347 | HalDevice *d; | |||
348 | struct stat devstat; | |||
349 | char *devstr; | |||
350 | int error; | |||
351 | ||||
352 | HAL_INFO (("devinfo_optical_volume_add: parent=%p devnode=%s devfs_path=%s device_type=%s", | |||
353 | parent, devnode, devfs_path, device_type)); | |||
354 | ||||
355 | d = hal_device_new (); | |||
356 | ||||
357 | devstr = malloc(strlen(devnode) + 10); | |||
358 | ||||
359 | /* info */ | |||
360 | devinfo_set_default_properties (d, parent, devnode, devnode); | |||
361 | hal_device_add_capability (d, "block"); | |||
362 | hal_device_add_capability (d, "volume"); | |||
363 | hal_device_add_capability (d, "volume.disc"); | |||
364 | ||||
365 | /* block */ | |||
366 | sprintf(devstr, "/dev/%s", devnode); | |||
367 | hal_device_property_set_string (d, "block.device", devstr); | |||
368 | error = stat(devstr, &devstat); | |||
369 | if (!error) { | |||
370 | hal_device_property_set_int (d, "block.major", major(devstat.st_rdev)); | |||
371 | hal_device_property_set_int (d, "block.minor", minor(devstat.st_rdev)); | |||
372 | } | |||
373 | sprintf(devstr, "/dev/r%s", devnode); | |||
374 | hal_device_property_set_string (d, "block.netbsd.raw_device", devstr); | |||
375 | ||||
376 | hal_device_property_set_bool (d, "block.is_volume", TRUE); | |||
377 | hal_device_property_set_bool (d, "block.no_partitions", TRUE); | |||
378 | hal_device_property_set_bool (d, "block.have_scanned", TRUE); | |||
379 | ||||
380 | /* volume */ | |||
381 | hal_device_property_set_bool (d, "volume.ignore", FALSE); | |||
382 | hal_device_property_set_string(d, "volume.fsusage", "filesytem"); | |||
383 | hal_device_property_set_string(d, "volume.fstype", ""); | |||
384 | hal_device_property_set_string(d, "volume.label", ""); | |||
385 | hal_device_property_set_bool (d, "volume.is_disc", TRUE); | |||
386 | hal_device_property_set_bool (d, "volume.is_partition", FALSE); | |||
387 | /* rest by addon */ | |||
388 | ||||
389 | /* volume.disc */ | |||
390 | /* by addon */ | |||
391 | ||||
392 | devinfo_add_enqueue (d, devnode, &devinfo_optical_volume_handler); | |||
393 | ||||
394 | return d; | |||
395 | } | |||
396 | ||||
397 | ||||
398 | static HalDevice * | |||
334 | devinfo_optical_add(HalDevice *parent, const char *devnode, char *devfs_path, char *device_type) | 399 | devinfo_optical_add(HalDevice *parent, const char *devnode, char *devfs_path, char *device_type) | |
335 | { | 400 | { | |
336 | HalDevice *d; | 401 | HalDevice *d; | |
337 | struct stat devstat; | 402 | struct stat devstat; | |
338 | char *devstr; | 403 | char *devstr; | |
339 | char *parent_devnode; | 404 | char *parent_devnode; | |
340 | int fd, error; | 405 | int fd, error; | |
341 | 406 | |||
342 | if (strncmp(devnode, "cd", 2) != 0) { | 407 | if (strncmp(devnode, "cd", 2) != 0) { | |
343 | return (NULL); | 408 | return (NULL); | |
344 | } | 409 | } | |
345 | 410 | |||
346 | HAL_INFO (("devinfo_optical_add: parent=%p devnode=%s devfs_path=%s device_type=%s", | 411 | HAL_INFO (("devinfo_optical_add: parent=%p devnode=%s devfs_path=%s device_type=%s", | |
347 | parent, devnode, devfs_path, device_type)); | 412 | parent, devnode, devfs_path, device_type)); | |
348 | 413 | |||
349 | d = hal_device_new (); | 414 | d = hal_device_new (); | |
350 | 415 | |||
351 | devstr = malloc(strlen(devnode) + 10); | 416 | devstr = malloc(strlen(devnode) + 10); | |
352 | 417 | |||
353 | /* info */ | 418 | /* info */ | |
354 | devinfo_set_default_properties (d, parent, devnode, devnode); | 419 | devinfo_set_default_properties (d, parent, devnode, devnode); | |
355 | // hal_device_property_set_string (d, "netbsd.device", devfs_path); | 420 | // hal_device_property_set_string (d, "netbsd.device", devfs_path); | |
356 | 421 | |||
357 | hal_device_property_set_string (d, "info.subsystem", "block"); | 422 | hal_device_property_set_string (d, "info.subsystem", "block"); | |
358 | hal_device_add_capability (d, "block"); | 423 | hal_device_add_capability (d, "block"); | |
359 | hal_device_add_capability (d, "storage"); | 424 | hal_device_add_capability (d, "storage"); | |
360 | hal_device_add_capability (d, "storage.cdrom"); | 425 | hal_device_add_capability (d, "storage.cdrom"); | |
361 | 426 | |||
362 | /* block */ | 427 | /* block */ | |
363 | sprintf(devstr, "/dev/%s%c", devnode, 'a' + RAW_PART); | 428 | sprintf(devstr, "/dev/%s%c", devnode, 'a' + RAW_PART); | |
364 | hal_device_property_set_string (d, "block.device", devstr); | 429 | hal_device_property_set_string (d, "block.device", devstr); | |
365 | error = stat(devstr, &devstat); | 430 | error = stat(devstr, &devstat); | |
366 | if (!error) { | 431 | if (!error) { | |
367 | hal_device_property_set_int (d, "block.major", major(devstat.st_rdev)); | 432 | hal_device_property_set_int (d, "block.major", major(devstat.st_rdev)); | |
368 | hal_device_property_set_int (d, "block.minor", minor(devstat.st_rdev)); | 433 | hal_device_property_set_int (d, "block.minor", minor(devstat.st_rdev)); | |
369 | } | 434 | } | |
370 | sprintf(devstr, "/dev/r%s%c", devnode, 'a' + RAW_PART); | 435 | sprintf(devstr, "/dev/r%s%c", devnode, 'a' + RAW_PART); | |
371 | hal_device_property_set_string (d, "block.netbsd.raw_device", devstr); | 436 | hal_device_property_set_string (d, "block.netbsd.raw_device", devstr); | |
372 | 437 | |||
373 | hal_device_property_set_bool (d, "block.is_volume", FALSE); | 438 | hal_device_property_set_bool (d, "block.is_volume", FALSE); | |
374 | hal_device_property_set_bool (d, "block.no_partitions", TRUE); | 439 | hal_device_property_set_bool (d, "block.no_partitions", TRUE); | |
375 | hal_device_property_set_bool (d, "block.have_scanned", TRUE); | 440 | hal_device_property_set_bool (d, "block.have_scanned", TRUE); | |
376 | 441 | |||
377 | /* storage */ | 442 | /* storage */ | |
378 | parent_devnode = hal_device_property_get_string (parent, "netbsd.device"); | 443 | parent_devnode = hal_device_property_get_string (parent, "netbsd.device"); | |
379 | if (strstr (parent_devnode, "umass") == parent_devnode) | 444 | if (strstr (parent_devnode, "umass") == parent_devnode) | |
380 | hal_device_property_set_string (d, "storage.bus", "usb"); | 445 | hal_device_property_set_string (d, "storage.bus", "usb"); | |
381 | else if (strstr (parent_devnode, "atapi") == parent_devnode) | 446 | else if (strstr (parent_devnode, "atapi") == parent_devnode) | |
382 | hal_device_property_set_string (d, "storage.bus", "ide"); | 447 | hal_device_property_set_string (d, "storage.bus", "ide"); | |
383 | else | 448 | else | |
384 | hal_device_property_set_string (d, "storage.bus", "scsi"); | 449 | hal_device_property_set_string (d, "storage.bus", "scsi"); | |
385 | 450 | |||
386 | hal_device_property_set_string (d, "storage.drive_type", "cdrom"); | 451 | hal_device_property_set_string (d, "storage.drive_type", "cdrom"); | |
387 | hal_device_property_set_bool (d, "storage.removable", TRUE); | 452 | hal_device_property_set_bool (d, "storage.removable", TRUE); | |
388 | /* "storage.removable.media_available" set by addon-storage */ | 453 | /* "storage.removable.media_available" set by addon-storage */ | |
389 | /* "storage.removable.media_size" set by addon-storage */ | 454 | /* "storage.removable.media_size" set by addon-storage */ | |
455 | hal_device_property_set_bool (d, "storage.removable.support_async_notification", FALSE); | |||
390 | hal_device_property_set_bool (d, "storage.requires_eject", TRUE); | 456 | hal_device_property_set_bool (d, "storage.requires_eject", TRUE); | |
391 | hal_device_property_set_bool (d, "storage.hotpluggable", TRUE); | 457 | hal_device_property_set_bool (d, "storage.hotpluggable", TRUE); | |
392 | hal_device_property_set_bool (d, "storage.media_check_enabled", TRUE); /* XXX */ | 458 | hal_device_property_set_bool (d, "storage.media_check_enabled", TRUE); /* XXX */ | |
393 | hal_device_property_set_bool (d, "storage.automount_enabled_hint", FALSE); /* multiple choice */ | 459 | hal_device_property_set_bool (d, "storage.automount_enabled_hint", FALSE); /* multiple choice */ | |
394 | hal_device_property_set_bool (d, "storage.no_partitions_hint", TRUE); | 460 | hal_device_property_set_bool (d, "storage.no_partitions_hint", TRUE); | |
395 | hal_device_property_set_string (d, "storage.originating_device", ""); /* XXX */ | 461 | hal_device_property_set_string (d, "storage.originating_device", ""); /* XXX */ | |
396 | 462 | |||
397 | fd = open(devstr, O_RDONLY, 0); | 463 | fd = open(devstr, O_RDONLY, 0); | |
398 | if (fd) { | 464 | if (fd) { | |
399 | /* get drive's vendor and model name */ | 465 | /* get drive's vendor and model name */ | |
400 | devinfo_optical_identify_drive(d, devstr); | 466 | devinfo_optical_identify_drive(d, devstr); | |
401 | 467 | |||
402 | /* get CD specific `storage.cdrom' values */ | 468 | /* get CD specific `storage.cdrom' values */ | |
403 | devinfo_optical_disc_caps(fd, d); | 469 | devinfo_optical_disc_caps(fd, d); | |
404 | } | |||
405 | close(fd); | |||
406 | 470 | |||
471 | } | |||
407 | devinfo_add_enqueue (d, devnode, &devinfo_optical_handler); | 472 | devinfo_add_enqueue (d, devnode, &devinfo_optical_handler); | |
473 | if (fd) { | |||
474 | /* create CD volume node */ | |||
475 | sprintf(devstr, "%s%c", devnode, 'a' + RAW_PART); | |||
476 | devinfo_optical_volume_add(d, devstr, devfs_path, "volume"); | |||
477 | } | |||
478 | close(fd); | |||
408 | 479 | |||
409 | return (d); | 480 | return (d); | |
410 | } | 481 | } | |
411 | 482 |
@@ -1,332 +1,516 @@ | @@ -1,332 +1,516 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** | |
2 | * | 2 | * | |
3 | * addon-storage.c : watch removable media state changes | 3 | * addon-storage.c : watch removable media state changes | |
4 | * | 4 | * | |
5 | * Copyright 2006 Sun Microsystems, Inc. All rights reserved. | 5 | * Copyright 2006 Sun Microsystems, Inc. All rights reserved. | |
6 | * Use is subject to license terms. | 6 | * Use is subject to license terms. | |
7 | * | 7 | * | |
8 | * Licensed under the Academic Free License version 2.1 | 8 | * Licensed under the Academic Free License version 2.1 | |
9 | * | 9 | * | |
10 | **************************************************************************/ | 10 | **************************************************************************/ | |
11 | 11 | |||
12 | #ifdef HAVE_CONFIG_H | 12 | #ifdef HAVE_CONFIG_H | |
13 | # include <config.h> | 13 | # include <config.h> | |
14 | #endif | 14 | #endif | |
15 | 15 | |||
16 | #include <errno.h> | 16 | #include <errno.h> | |
17 | #include <string.h> | 17 | #include <string.h> | |
18 | #include <strings.h> | 18 | #include <strings.h> | |
19 | #include <stdlib.h> | 19 | #include <stdlib.h> | |
20 | #include <stdio.h> | 20 | #include <stdio.h> | |
21 | #include <syslog.h> | 21 | #include <syslog.h> | |
22 | #include <sys/ioctl.h> | 22 | #include <sys/ioctl.h> | |
23 | #include <sys/types.h> | 23 | #include <sys/types.h> | |
24 | #include <sys/stat.h> | 24 | #include <sys/stat.h> | |
25 | #include <sys/types.h> | 25 | #include <sys/types.h> | |
26 | #include <sys/wait.h> | 26 | #include <sys/wait.h> | |
27 | #include <fcntl.h> | 27 | #include <fcntl.h> | |
28 | #include <unistd.h> | 28 | #include <unistd.h> | |
29 | #include <sys/statvfs.h> | 29 | #include <sys/statvfs.h> | |
30 | #include <sys/dkio.h> | 30 | #include <sys/dkio.h> | |
31 | #include <dev/scsipi/scsi_spc.h> | 31 | #include <dev/scsipi/scsi_spc.h> | |
32 | #include <dev/scsipi/scsipi_all.h> | 32 | #include <dev/scsipi/scsipi_all.h> | |
33 | #include <dev/scsipi/scsipi_cd.h> | 33 | #include <dev/scsipi/scsipi_cd.h> | |
34 | #include <sys/scsiio.h> | 34 | #include <sys/scsiio.h> | |
35 | 35 | |||
36 | #include <libhal.h> | 36 | #include <libhal.h> | |
37 | 37 | |||
38 | #include <logger.h> | 38 | #include <logger.h> | |
39 | 39 | |||
40 | #define SLEEP_PERIOD 5 | 40 | #define SLEEP_PERIOD 5 | |
41 | 41 | |||
42 | #define _EXPOSE_MMC | |||
43 | #include <sys/cdio.h> | |||
44 | ||||
45 | ||||
42 | enum discstate { | 46 | enum discstate { | |
43 | DISC_INSERTED, | 47 | DISC_INSERTED, | |
44 | DISC_EJECTED, | 48 | DISC_EJECTED, | |
45 | DISC_NONE, | 49 | DISC_NONE, | |
46 | DISC_UNKNOWN | 50 | DISC_UNKNOWN | |
47 | }; | 51 | }; | |
48 | 52 | |||
49 | static enum discstate | 53 | static enum discstate | |
50 | scsi_test_unit_ready (int fd) | 54 | scsi_test_unit_ready (int fd) | |
51 | { | 55 | { | |
52 | struct scsi_test_unit_ready tur; | 56 | struct scsi_test_unit_ready tur; | |
53 | scsireq_t req; | 57 | scsireq_t req; | |
54 | 58 | |||
55 | memset(&tur, 0, sizeof(tur)); | 59 | memset(&tur, 0, sizeof(tur)); | |
56 | tur.opcode = SCSI_TEST_UNIT_READY; | 60 | tur.opcode = SCSI_TEST_UNIT_READY; | |
57 | 61 | |||
58 | memset(&req, 0, sizeof(req)); | 62 | memset(&req, 0, sizeof(req)); | |
59 | memcpy(req.cmd, &tur, sizeof(tur)); | 63 | memcpy(req.cmd, &tur, sizeof(tur)); | |
60 | req.cmdlen = sizeof(tur); | 64 | req.cmdlen = sizeof(tur); | |
61 | req.databuf = NULL; | 65 | req.databuf = NULL; | |
62 | req.datalen = 0; | 66 | req.datalen = 0; | |
63 | req.timeout = 10000; | 67 | req.timeout = 10000; | |
64 | req.flags = SCCMD_READ; | 68 | req.flags = SCCMD_READ; | |
65 | req.senselen = SENSEBUFLEN; | 69 | req.senselen = SENSEBUFLEN; | |
66 | 70 | |||
67 | if (ioctl(fd, SCIOCCOMMAND, &req) == -1) | 71 | if (ioctl(fd, SCIOCCOMMAND, &req) == -1) | |
68 | return DISC_UNKNOWN; | 72 | return DISC_UNKNOWN; | |
69 | if (req.retsts == SCCMD_OK) | 73 | if (req.retsts == SCCMD_OK) | |
70 | return DISC_INSERTED; | 74 | return DISC_INSERTED; | |
71 | return DISC_EJECTED; | 75 | return DISC_EJECTED; | |
72 | } | 76 | } | |
73 | 77 | |||
74 | static void | 78 | static void | |
75 | my_dbus_error_free(DBusError *error) | 79 | my_dbus_error_free(DBusError *error) | |
76 | { | 80 | { | |
77 | if (dbus_error_is_set(error)) { | 81 | if (dbus_error_is_set(error)) { | |
78 | dbus_error_free(error); | 82 | dbus_error_free(error); | |
79 | } | 83 | } | |
80 | } | 84 | } | |
81 | 85 | |||
82 | static void | 86 | static void | |
83 | force_unmount (LibHalContext *ctx, const char *udi) | 87 | force_unmount (LibHalContext *ctx, const char *udi) | |
84 | { | 88 | { | |
85 | DBusError error; | 89 | DBusError error; | |
86 | DBusMessage *msg = NULL; | 90 | DBusMessage *msg = NULL; | |
87 | DBusMessage *reply = NULL; | 91 | DBusMessage *reply = NULL; | |
88 | char **options = NULL; | 92 | char **options = NULL; | |
89 | unsigned int num_options = 0; | 93 | unsigned int num_options = 0; | |
90 | DBusConnection *dbus_connection; | 94 | DBusConnection *dbus_connection; | |
91 | char *device_file; | 95 | char *device_file; | |
92 | 96 | |||
93 | dbus_error_init (&error); | 97 | dbus_error_init (&error); | |
94 | 98 | |||
95 | dbus_connection = libhal_ctx_get_dbus_connection (ctx); | 99 | dbus_connection = libhal_ctx_get_dbus_connection (ctx); | |
96 | 100 | |||
97 | msg = dbus_message_new_method_call ("org.freedesktop.Hal", udi, | 101 | msg = dbus_message_new_method_call ("org.freedesktop.Hal", udi, | |
98 | "org.freedesktop.Hal.Device.Volume", | 102 | "org.freedesktop.Hal.Device.Volume", | |
99 | "Unmount"); | 103 | "Unmount"); | |
100 | if (msg == NULL) { | 104 | if (msg == NULL) { | |
101 | HAL_DEBUG (("Could not create dbus message for %s", udi)); | 105 | HAL_DEBUG (("Could not create dbus message for %s", udi)); | |
102 | goto out; | 106 | goto out; | |
103 | } | 107 | } | |
104 | 108 | |||
105 | 109 | |||
106 | options = calloc (1, sizeof (char *)); | 110 | options = calloc (1, sizeof (char *)); | |
107 | if (options == NULL) { | 111 | if (options == NULL) { | |
108 | HAL_DEBUG (("Could not allocate options array")); | 112 | HAL_DEBUG (("Could not allocate options array")); | |
109 | goto out; | 113 | goto out; | |
110 | } | 114 | } | |
111 | 115 | |||
112 | device_file = libhal_device_get_property_string (ctx, udi, "block.device", &error); | 116 | device_file = libhal_device_get_property_string (ctx, udi, "block.device", &error); | |
113 | if (device_file != NULL) { | 117 | if (device_file != NULL) { | |
114 | libhal_free_string (device_file); | 118 | libhal_free_string (device_file); | |
115 | } | 119 | } | |
116 | dbus_error_free (&error); | 120 | dbus_error_free (&error); | |
117 | 121 | |||
118 | if (!dbus_message_append_args (msg, | 122 | if (!dbus_message_append_args (msg, | |
119 | DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &options, num_options, | 123 | DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &options, num_options, | |
120 | DBUS_TYPE_INVALID)) { | 124 | DBUS_TYPE_INVALID)) { | |
121 | HAL_DEBUG (("Could not append args to dbus message for %s", udi)); | 125 | HAL_DEBUG (("Could not append args to dbus message for %s", udi)); | |
122 | goto out; | 126 | goto out; | |
123 | } | 127 | } | |
124 | 128 | |||
125 | if (!(reply = dbus_connection_send_with_reply_and_block (dbus_connection, msg, -1, &error))) { | 129 | if (!(reply = dbus_connection_send_with_reply_and_block (dbus_connection, msg, -1, &error))) { | |
126 | HAL_DEBUG (("Unmount failed for %s: %s : %s\n", udi, error.name, error.message)); | 130 | HAL_DEBUG (("Unmount failed for %s: %s : %s\n", udi, error.name, error.message)); | |
127 | goto out; | 131 | goto out; | |
128 | } | 132 | } | |
129 | 133 | |||
130 | if (dbus_error_is_set (&error)) { | 134 | if (dbus_error_is_set (&error)) { | |
131 | HAL_DEBUG (("Unmount failed for %s\n%s : %s\n", udi, error.name, error.message)); | 135 | HAL_DEBUG (("Unmount failed for %s\n%s : %s\n", udi, error.name, error.message)); | |
132 | goto out; | 136 | goto out; | |
133 | } | 137 | } | |
134 | 138 | |||
135 | HAL_DEBUG (("Succesfully unmounted udi '%s'", udi)); | 139 | HAL_DEBUG (("Succesfully unmounted udi '%s'", udi)); | |
136 | 140 | |||
137 | out: | 141 | out: | |
138 | dbus_error_free (&error); | 142 | dbus_error_free (&error); | |
139 | if (options != NULL) | 143 | if (options != NULL) | |
140 | free (options); | 144 | free (options); | |
141 | if (msg != NULL) | 145 | if (msg != NULL) | |
142 | dbus_message_unref (msg); | 146 | dbus_message_unref (msg); | |
143 | if (reply != NULL) | 147 | if (reply != NULL) | |
144 | dbus_message_unref (reply); | 148 | dbus_message_unref (reply); | |
145 | } | 149 | } | |
146 | 150 | |||
147 | static void | 151 | static void | |
148 | unmount_childs (LibHalContext *ctx, const char *udi) | 152 | unmount_childs (LibHalContext *ctx, const char *udi) | |
149 | { | 153 | { | |
150 | DBusError error; | 154 | DBusError error; | |
151 | int num_volumes; | 155 | int num_volumes; | |
152 | char **volumes; | 156 | char **volumes; | |
153 | 157 | |||
154 | dbus_error_init (&error); | 158 | dbus_error_init (&error); | |
155 | 159 | |||
156 | /* need to force unmount all partitions */ | 160 | /* need to force unmount all partitions */ | |
157 | if ((volumes = libhal_manager_find_device_string_match ( | 161 | if ((volumes = libhal_manager_find_device_string_match ( | |
158 | ctx, "block.storage_device", udi, &num_volumes, &error)) != NULL) { | 162 | ctx, "block.storage_device", udi, &num_volumes, &error)) != NULL) { | |
159 | dbus_error_free (&error); | 163 | dbus_error_free (&error); | |
160 | int i; | 164 | int i; | |
161 | 165 | |||
162 | for (i = 0; i < num_volumes; i++) { | 166 | for (i = 0; i < num_volumes; i++) { | |
163 | char *vol_udi; | 167 | char *vol_udi; | |
164 | 168 | |||
165 | vol_udi = volumes[i]; | 169 | vol_udi = volumes[i]; | |
166 | if (libhal_device_get_property_bool (ctx, vol_udi, "block.is_volume", &error)) { | 170 | if (libhal_device_get_property_bool (ctx, vol_udi, "block.is_volume", &error)) { | |
167 | dbus_error_free (&error); | 171 | dbus_error_free (&error); | |
168 | if (libhal_device_get_property_bool (ctx, vol_udi, "volume.is_mounted", &error)) { | 172 | if (libhal_device_get_property_bool (ctx, vol_udi, "volume.is_mounted", &error)) { | |
169 | dbus_error_free (&error); | 173 | dbus_error_free (&error); | |
170 | HAL_DEBUG (("Forcing unmount of child '%s'", vol_udi)); | 174 | HAL_DEBUG (("Forcing unmount of child '%s'", vol_udi)); | |
171 | force_unmount (ctx, vol_udi); | 175 | force_unmount (ctx, vol_udi); | |
172 | } | 176 | } | |
173 | } | 177 | } | |
174 | } | 178 | } | |
175 | libhal_free_string_array (volumes); | 179 | libhal_free_string_array (volumes); | |
176 | } | 180 | } | |
177 | my_dbus_error_free (&error); | 181 | my_dbus_error_free (&error); | |
178 | } | 182 | } | |
179 | 183 | |||
180 | /** Check if a filesystem on a special device file is mounted | 184 | /** Check if a filesystem on a special device file is mounted | |
181 | * | 185 | * | |
182 | * @param device_file Special device file, e.g. /dev/cdrom | 186 | * @param device_file Special device file, e.g. /dev/cdrom | |
183 | * @return TRUE iff there is a filesystem system mounted | 187 | * @return TRUE iff there is a filesystem system mounted | |
184 | * on the special device file | 188 | * on the special device file | |
185 | */ | 189 | */ | |
186 | static dbus_bool_t | 190 | static dbus_bool_t | |
187 | is_mounted (const char *device_file) | 191 | is_mounted (const char *device_file) | |
188 | { | 192 | { | |
189 | int count; | 193 | int count; | |
190 | struct statvfs *statvfs; | 194 | struct statvfs *statvfs; | |
191 | 195 | |||
192 | count = getmntinfo(&statvfs, ST_WAIT); | 196 | count = getmntinfo(&statvfs, ST_WAIT); | |
193 | while (count-- > 0) { | 197 | while (count-- > 0) { | |
194 | if (strcmp(statvfs->f_mntfromname, device_file) == 0) | 198 | if (strcmp(statvfs->f_mntfromname, device_file) == 0) | |
195 | return TRUE; | 199 | return TRUE; | |
196 | } | 200 | } | |
197 | 201 | |||
198 | return FALSE; | 202 | return FALSE; | |
199 | } | 203 | } | |
200 | 204 | |||
201 | static void | 205 | static void | |
202 | close_device (int *fd) | 206 | close_device (int *fd) | |
203 | { | 207 | { | |
204 | if (*fd > 0) { | 208 | if (*fd > 0) { | |
205 | close (*fd); | 209 | close (*fd); | |
206 | *fd = -1; | 210 | *fd = -1; | |
207 | } | 211 | } | |
208 | } | 212 | } | |
209 | 213 | |||
214 | ||||
215 | /* XXX why not share this further */ | |||
216 | static char const * | |||
217 | get_profile_typestring(int profile) | |||
218 | { | |||
219 | switch (profile) { | |||
220 | case 0x00 : return "unknown"; // "Unknown[0] profile"; | |||
221 | case 0x01 : return "unknown"; // "Non removeable disc"; | |||
222 | case 0x02 : return "unknown"; // "Removable disc"; | |||
223 | case 0x03 : return "mo"; // Magneto Optical with sector erase"; | |||
224 | case 0x04 : return "mo"; // "Magneto Optical write once"; | |||
225 | case 0x05 : return "mo"; // "Advance Storage Magneto Optical"; | |||
226 | case 0x08 : return "cd_rom"; // "CD-ROM"; no writing | |||
227 | case 0x09 : return "cd_r"; // "CD-R recordable"; | |||
228 | case 0x0a : return "cd_rw"; // "CD-RW rewritable"; | |||
229 | case 0x10 : return "dvd_rom"; // "DVD-ROM"; no writing | |||
230 | case 0x11 : return "dvd_r"; // "DVD-R sequential"; | |||
231 | case 0x12 : return "dvd_ram"; // "DVD-RAM rewritable"; | |||
232 | case 0x13 : return "dvd_rw"; // "DVD-RW restricted overwrite"; | |||
233 | case 0x14 : return "dvd_rw"; // "DVD-RW sequential"; | |||
234 | case 0x15 : return "dvd_r"; // "DVD-R dual layer sequential"; | |||
235 | case 0x16 : return "dvd_r"; // "DVD-R dual layer jump"; | |||
236 | case 0x17 : return "dvd_rw"; // "DVD-RW dual layer"; | |||
237 | case 0x18 : return "unknown"; // "DVD-Download disc"; UNKNOWN | |||
238 | case 0x1a : return "dvd_plus_rw"; // "DVD+RW rewritable"; | |||
239 | case 0x1b : return "dvd_plus_r"; // "DVD+R recordable"; | |||
240 | case 0x20 : return "ddcd_rom"; // "DDCD readonly (retracted)"; no writing | |||
241 | case 0x21 : return "ddcd_r"; // "DDCD-R recordable (retracted)"; OK? | |||
242 | case 0x22 : return "ddcd_rw"; // "DDCD-RW rewritable (retracted)"; OK? | |||
243 | case 0x2a : return "dvd_plus_rw_dl";//"DVD+RW double layer"; | |||
244 | case 0x2b : return "dvd_plus_r_dl";// "DVD+R double layer"; | |||
245 | case 0x40 : return "bd_rom"; // "BD-ROM"; | |||
246 | case 0x41 : return "bd_r"; // "BD-R Sequential Recording (SRM)"; | |||
247 | case 0x42 : return "bd_r"; // "BD-R Random Recording (RRM)"; | |||
248 | case 0x43 : return "bd_re"; // "BD-RE rewritable"; | |||
249 | case 0x50 : return "hddvd_rom"; // "HD DVD-ROM (retracted)"; | |||
250 | case 0x51 : return "hddvd_r"; // "HD DVD-R (retracted)"; | |||
251 | case 0x52 : return "hddvd_ram"; // "HD DVD-RAM (retracted)"; | |||
252 | case 0x53 : return "hddvd_rw"; // "HD DVD-RW (retracted)"; | |||
253 | case 0x58 : return "hddvd_r_dl"; // "HD DVD-R dual layer (retracted)"; | |||
254 | case 0x5a : return "hddvd_rw_dl"; // "HD DVD-RW dual layer (retracted)"; | |||
255 | } | |||
256 | /* reserved */ | |||
257 | return "unknown"; | |||
258 | } | |||
259 | ||||
260 | ||||
261 | static void | |||
262 | set_volume_properties(int fd, LibHalContext *ctx, char *udi, int state) | |||
263 | { | |||
264 | struct mmc_discinfo di; | |||
265 | struct mmc_trackinfo ti; | |||
266 | struct volume_id *vid; | |||
267 | DBusError error; | |||
268 | uint64_t capacity; | |||
269 | char const *disc_type; | |||
270 | char *disc_fstype, *disc_label; | |||
271 | int has_audio, has_data, is_vcd, is_svcd, is_videodvd, is_appendable, is_blank, is_rewritable; | |||
272 | int tracknr, err; | |||
273 | ||||
274 | disc_fstype = ""; | |||
275 | disc_label = ""; | |||
276 | disc_type = "unknown"; | |||
277 | has_audio = has_data = is_vcd = is_svcd = is_videodvd = is_appendable = is_blank = is_rewritable = 0; | |||
278 | capacity = 0; | |||
279 | ||||
280 | dbus_error_init (&error); | |||
281 | if (state == DISC_INSERTED) { | |||
282 | /* fetch new values */ | |||
283 | memset(&di, 0, sizeof(struct mmc_discinfo)); | |||
284 | err = ioctl(fd, MMCGETDISCINFO, &di); | |||
285 | if (!err) { | |||
286 | disc_type = get_profile_typestring(di.mmc_profile); | |||
287 | is_rewritable = di.mmc_cur & MMC_CAP_REWRITABLE; | |||
288 | is_blank = (di.disc_state == MMC_STATE_EMPTY); | |||
289 | is_appendable = (di.disc_state != MMC_STATE_FULL); | |||
290 | ||||
291 | /* can't check is_videodvd, is_svcd, is_vcd (yet); use volume lib */ | |||
292 | disc_fstype = "cd9660"; | |||
293 | disc_label = "label"; | |||
294 | vid = NULL; | |||
295 | #if 0 | |||
296 | vid = volume_id_open_fd (fd); | |||
297 | if (vid) { | |||
298 | if (volume_id_probe_all (vid, 0, psize) == 0) { | |||
299 | hal_device_property_set_string (d, "volume.label", vid->label); | |||
300 | hal_device_property_set_string (d, "volume.partition.label", vid->label); | |||
301 | hal_device_property_set_string (d, "volume.uuid", vid->uuid); | |||
302 | hal_device_property_set_string (d, "volume.partition.uuid", vid->uuid); | |||
303 | } | |||
304 | volume_id_close (vid); | |||
305 | } | |||
306 | #endif | |||
307 | for (tracknr = di.first_track; tracknr <= di.last_track_last_session; tracknr++) { | |||
308 | memset(&ti, 0, sizeof(struct mmc_trackinfo)); | |||
309 | ti.tracknr = tracknr; | |||
310 | err = ioctl(fd, MMCGETTRACKINFO, &ti); | |||
311 | if (err) | |||
312 | break; | |||
313 | if (!(ti.flags & MMC_TRACKINFO_BLANK)) { | |||
314 | if (ti.flags & MMC_TRACKINFO_DATA) | |||
315 | has_data = TRUE; | |||
316 | if (ti.flags & MMC_TRACKINFO_AUDIO) | |||
317 | has_audio = TRUE; | |||
318 | } | |||
319 | capacity += (ti.track_size + ti.free_blocks) * di.sector_size; | |||
320 | } | |||
321 | } | |||
322 | } | |||
323 | ||||
324 | /* add volume properties (ignoring dbus errors) */ | |||
325 | libhal_device_set_property_bool (ctx, udi, "volume.ignore", FALSE, &error); /* make visible */ | |||
326 | libhal_device_set_property_bool (ctx, udi, "volume.ismounted", FALSE, &error); /* XXX fixme XXX */ | |||
327 | libhal_device_set_property_bool (ctx, udi, "volume.ismounted_readonly", FALSE, &error); /* XXX fixme XXX */ | |||
328 | libhal_device_set_property_string (ctx, udi, "volume.fsusage", "filesystem", &error); | |||
329 | libhal_device_set_property_string (ctx, udi, "volume.fstype", disc_fstype, &error); | |||
330 | libhal_device_set_property_string (ctx, udi, "volume.label", disc_label, &error); | |||
331 | libhal_device_set_property_string (ctx, udi, "volume.uuid", "", &error); | |||
332 | libhal_device_set_property_uint64 (ctx, udi, "volume.size", capacity, &error); | |||
333 | ||||
334 | /* add volume.disc properties (ignoring dbus errors) */ | |||
335 | libhal_device_set_property_bool (ctx, udi, "volume.disc.has_audio", has_audio, &error); | |||
336 | libhal_device_set_property_bool (ctx, udi, "volume.disc.has_data", has_data, &error); | |||
337 | libhal_device_set_property_bool (ctx, udi, "volume.disc.is_vcd", is_vcd, &error); | |||
338 | libhal_device_set_property_bool (ctx, udi, "volume.disc.is_svcd", is_svcd, &error); | |||
339 | libhal_device_set_property_bool (ctx, udi, "volume.disc.is_videodvd", is_videodvd, &error); | |||
340 | libhal_device_set_property_bool (ctx, udi, "volume.disc.is_appendable", is_appendable, &error); | |||
341 | libhal_device_set_property_bool (ctx, udi, "volume.disc.is_blank", is_blank, &error); | |||
342 | libhal_device_set_property_bool (ctx, udi, "volume.disc.is_rewritable", is_rewritable, &error); | |||
343 | ||||
344 | libhal_device_set_property_string (ctx, udi, "volume.disc.type", disc_type, &error); | |||
345 | libhal_device_set_property_uint64 (ctx, udi, "volume.disc.capacity", capacity, &error); | |||
346 | ||||
347 | my_dbus_error_free (&error); | |||
348 | } | |||
349 | ||||
350 | ||||
351 | static void | |||
352 | update_disc_volume_properties(int fd, LibHalContext *ctx, const char *udi, int state) | |||
353 | { | |||
354 | DBusError error; | |||
355 | char **volumes; | |||
356 | char *vol_udi; | |||
357 | int num_volumes, i; | |||
358 | ||||
359 | dbus_error_init (&error); | |||
360 | ||||
361 | /* update volume children */ | |||
362 | if ((volumes = libhal_manager_find_device_string_match ( | |||
363 | ctx, "info.parent", udi, &num_volumes, &error)) != NULL) { | |||
364 | dbus_error_free (&error); | |||
365 | ||||
366 | for (i = 0; i < num_volumes; i++) { | |||
367 | vol_udi = volumes[i]; | |||
368 | if (libhal_device_get_property_bool (ctx, vol_udi, "block.is_volume", &error)) { | |||
369 | dbus_error_free (&error); | |||
370 | HAL_DEBUG(("Updating child %s of %s\n", udi, vol_udi)); | |||
371 | set_volume_properties(fd, ctx, vol_udi, state); | |||
372 | ||||
373 | #if 0 | |||
374 | if (libhal_device_get_property_bool (ctx, vol_udi, "volume.is_mounted", &error)) { | |||
375 | dbus_error_free (&error); | |||
376 | HAL_DEBUG (("Forcing unmount of child '%s'", vol_udi)); | |||
377 | force_unmount (ctx, vol_udi); | |||
378 | } | |||
379 | #endif | |||
380 | } | |||
381 | } | |||
382 | libhal_free_string_array (volumes); | |||
383 | } | |||
384 | my_dbus_error_free (&error); | |||
385 | } | |||
386 | ||||
387 | ||||
210 | int | 388 | int | |
211 | main (int argc, char *argv[]) | 389 | main (int argc, char *argv[]) | |
212 | { | 390 | { | |
213 | char *udi; | 391 | char *udi; | |
214 | char *device_file, *raw_device_file; | 392 | char *device_file, *raw_device_file; | |
215 | LibHalContext *ctx = NULL; | 393 | LibHalContext *ctx = NULL; | |
216 | DBusError error; | 394 | DBusError error; | |
217 | char *bus; | 395 | char *bus; | |
218 | char *drive_type; | 396 | char *drive_type; | |
219 | int state, last_state; | 397 | int state, last_state; | |
220 | char *support_media_changed_str; | 398 | char *support_media_changed_str; | |
221 | int support_media_changed; | 399 | int support_media_changed; | |
222 | int fd = -1; | 400 | int fd = -1; | |
223 | 401 | |||
224 | if ((udi = getenv ("UDI")) == NULL) | 402 | if ((udi = getenv ("UDI")) == NULL) | |
225 | goto out; | 403 | goto out; | |
226 | if ((device_file = getenv ("HAL_PROP_BLOCK_DEVICE")) == NULL) | 404 | if ((device_file = getenv ("HAL_PROP_BLOCK_DEVICE")) == NULL) | |
227 | goto out; | 405 | goto out; | |
228 | if ((raw_device_file = getenv ("HAL_PROP_BLOCK_NETBSD_RAW_DEVICE")) == NULL) | 406 | if ((raw_device_file = getenv ("HAL_PROP_BLOCK_NETBSD_RAW_DEVICE")) == NULL) | |
229 | goto out; | 407 | goto out; | |
230 | if ((bus = getenv ("HAL_PROP_STORAGE_BUS")) == NULL) | 408 | if ((bus = getenv ("HAL_PROP_STORAGE_BUS")) == NULL) | |
231 | goto out; | 409 | goto out; | |
232 | if ((drive_type = getenv ("HAL_PROP_STORAGE_DRIVE_TYPE")) == NULL) | 410 | if ((drive_type = getenv ("HAL_PROP_STORAGE_DRIVE_TYPE")) == NULL) | |
233 | goto out; | 411 | goto out; | |
234 | 412 | |||
235 | setup_logger (); | 413 | setup_logger (); | |
236 | 414 | |||
237 | support_media_changed_str = getenv ("HAL_PROP_STORAGE_CDROM_SUPPORT_MEDIA_CHANGED"); | 415 | support_media_changed_str = getenv ("HAL_PROP_STORAGE_CDROM_SUPPORT_MEDIA_CHANGED"); | |
238 | if (support_media_changed_str != NULL && strcmp (support_media_changed_str, "true") == 0) | 416 | if (support_media_changed_str != NULL && strcmp (support_media_changed_str, "true") == 0) | |
239 | support_media_changed = TRUE; | 417 | support_media_changed = TRUE; | |
240 | else | 418 | else | |
241 | support_media_changed = FALSE; | 419 | support_media_changed = FALSE; | |
242 | 420 | |||
243 | dbus_error_init (&error); | 421 | dbus_error_init (&error); | |
244 | 422 | |||
245 | if ((ctx = libhal_ctx_init_direct (&error)) == NULL) { | 423 | if ((ctx = libhal_ctx_init_direct (&error)) == NULL) { | |
246 | goto out; | 424 | goto out; | |
247 | } | 425 | } | |
248 | my_dbus_error_free (&error); | 426 | my_dbus_error_free (&error); | |
249 | 427 | |||
250 | if (!libhal_device_addon_is_ready (ctx, udi, &error)) { | 428 | if (!libhal_device_addon_is_ready (ctx, udi, &error)) { | |
251 | goto out; | 429 | goto out; | |
252 | } | 430 | } | |
253 | my_dbus_error_free (&error); | 431 | my_dbus_error_free (&error); | |
254 | 432 | |||
255 | printf ("Doing addon-storage for %s (bus %s) (drive_type %s) (udi %s)\n", device_file, bus, drive_type, udi); | 433 | printf ("Doing addon-storage for %s (bus %s) (drive_type %s) (udi %s)\n", device_file, bus, drive_type, udi); | |
256 | 434 | |||
257 | last_state = state = DISC_NONE; | 435 | last_state = state = DISC_NONE; | |
258 | 436 | |||
259 | /* Linux version of this addon attempts to re-open the device O_EXCL | 437 | /* Linux version of this addon attempts to re-open the device O_EXCL | |
260 | * every 2 seconds, trying to figure out if some other app, | 438 | * every 2 seconds, trying to figure out if some other app, | |
261 | * like a cd burner, is using the device. Aside from questionable | 439 | * like a cd burner, is using the device. Aside from questionable | |
262 | * value of this (apps should use HAL's locked property or/and | 440 | * value of this (apps should use HAL's locked property or/and | |
263 | * Solaris in_use facility), but also frequent opens/closes | 441 | * Solaris in_use facility), but also frequent opens/closes | |
264 | * keeps media constantly spun up. All this needs more thought. | 442 | * keeps media constantly spun up. All this needs more thought. | |
265 | */ | 443 | */ | |
266 | for (;;) { | 444 | for (;;) { | |
267 | sleep (SLEEP_PERIOD); | 445 | sleep (SLEEP_PERIOD); | |
268 | if (is_mounted (device_file)) { | 446 | if (is_mounted (device_file)) { | |
269 | close_device (&fd); | 447 | close_device (&fd); | |
270 | } else if ((fd < 0) && ((fd = open (raw_device_file, O_RDONLY | O_NONBLOCK)) < 0)) { | 448 | } else if ((fd < 0) && ((fd = open (raw_device_file, O_RDONLY | O_NONBLOCK)) < 0)) { | |
271 | HAL_DEBUG (("open failed for %s: %s", raw_device_file, strerror (errno))); | 449 | HAL_DEBUG (("open failed for %s: %s", raw_device_file, strerror (errno))); | |
272 | } else { | 450 | } else { | |
273 | /* Check if a disc is in the drive */ | 451 | /* Check if a disc is in the drive */ | |
274 | state = scsi_test_unit_ready (fd); | 452 | state = scsi_test_unit_ready (fd); | |
275 | 453 | |||
276 | if (state == last_state) { | 454 | if (state == last_state) { | |
277 | HAL_DEBUG (("state has not changed %d %s", state, device_file)); | 455 | HAL_DEBUG (("state has not changed %d %s", state, device_file)); | |
456 | /* TODO check if eject button was pressed */ | |||
457 | /* see linux addons/addon-storage.c */ | |||
278 | continue; | 458 | continue; | |
279 | } else { | 459 | } else { | |
280 | HAL_DEBUG (("new state %d %s", state, device_file)); | 460 | HAL_DEBUG (("new state %d %s", state, device_file)); | |
281 | } | 461 | } | |
282 | 462 | |||
283 | switch (state) { | 463 | switch (state) { | |
284 | case DISC_EJECTED: | 464 | case DISC_EJECTED: | |
285 | HAL_DEBUG (("Media removal detected on %s", device_file)); | 465 | HAL_DEBUG (("Media removal detected on %s", device_file)); | |
286 | last_state = state; | 466 | last_state = state; | |
287 | 467 | |||
288 | libhal_device_set_property_bool (ctx, udi, "storage.removable.media_available", FALSE, &error); | 468 | libhal_device_set_property_bool (ctx, udi, "storage.removable.media_available", FALSE, &error); | |
289 | my_dbus_error_free (&error); | 469 | my_dbus_error_free (&error); | |
290 | 470 | |||
291 | /* attempt to unmount all childs */ | 471 | /* attempt to unmount all childs */ | |
292 | unmount_childs (ctx, udi); | 472 | unmount_childs (ctx, udi); | |
293 | 473 | |||
474 | update_disc_volume_properties(fd, ctx, udi, state); | |||
475 | ||||
294 | /* could have a fs on the main block device; do a rescan to remove it */ | 476 | /* could have a fs on the main block device; do a rescan to remove it */ | |
295 | libhal_device_rescan (ctx, udi, &error); | 477 | libhal_device_rescan (ctx, udi, &error); | |
296 | my_dbus_error_free (&error); | 478 | my_dbus_error_free (&error); | |
297 | break; | 479 | break; | |
298 | 480 | |||
299 | case DISC_INSERTED: | 481 | case DISC_INSERTED: | |
300 | HAL_DEBUG (("Media insertion detected on %s", device_file)); | 482 | HAL_DEBUG (("Media insertion detected on %s", device_file)); | |
301 | last_state = state; | 483 | last_state = state; | |
302 | 484 | |||
303 | libhal_device_set_property_bool (ctx, udi, "storage.removable.media_available", TRUE, &error); | 485 | libhal_device_set_property_bool (ctx, udi, "storage.removable.media_available", TRUE, &error); | |
304 | my_dbus_error_free (&error); | 486 | my_dbus_error_free (&error); | |
305 | 487 | |||
488 | update_disc_volume_properties(fd, ctx, udi, state); | |||
489 | ||||
306 | /* could have a fs on the main block device; do a rescan to add it */ | 490 | /* could have a fs on the main block device; do a rescan to add it */ | |
307 | libhal_device_rescan (ctx, udi, &error); | 491 | libhal_device_rescan (ctx, udi, &error); | |
308 | my_dbus_error_free (&error); | 492 | my_dbus_error_free (&error); | |
309 | break; | 493 | break; | |
310 | 494 | |||
311 | case DISC_UNKNOWN: | 495 | case DISC_UNKNOWN: | |
312 | default: | 496 | default: | |
313 | HAL_DEBUG (("Device gone detected on %s", device_file)); | 497 | HAL_DEBUG (("Device gone detected on %s", device_file)); | |
314 | last_state = state; | 498 | last_state = state; | |
315 | 499 | |||
316 | unmount_childs (ctx, udi); | 500 | unmount_childs (ctx, udi); | |
317 | close_device (&fd); | 501 | close_device (&fd); | |
318 | goto out; | 502 | goto out; | |
319 | 503 | |||
320 | } | 504 | } | |
321 | } | 505 | } | |
322 | } | 506 | } | |
323 | 507 | |||
324 | out: | 508 | out: | |
325 | if (ctx != NULL) { | 509 | if (ctx != NULL) { | |
326 | my_dbus_error_free (&error); | 510 | my_dbus_error_free (&error); | |
327 | libhal_ctx_shutdown (ctx, &error); | 511 | libhal_ctx_shutdown (ctx, &error); | |
328 | libhal_ctx_free (ctx); | 512 | libhal_ctx_free (ctx); | |
329 | } | 513 | } | |
330 | 514 | |||
331 | return 0; | 515 | return 0; | |
332 | } | 516 | } |