aboutsummaryrefslogtreecommitdiffstats
path: root/sysutils/nautilus-cd-burner/files/patch-cd-drive.c
blob: c666b1c2923c5e0f37f590ae85075bd7f5ab4f5a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
--- cd-drive.c.orig Thu Feb 10 14:39:59 2005
+++ cd-drive.c  Tue Feb 15 03:34:40 2005
@@ -261,9 +261,21 @@
 {
    int fd;
    int mmc_profile;
+#ifdef __FreeBSD__
+   struct cam_device *cam;
+#endif
 
    g_return_val_if_fail (device != NULL, CD_MEDIA_TYPE_ERROR);
 
+#ifdef __FreeBSD__
+   cam = cam_open_device (device, O_RDWR);
+   if (cam == NULL) {
+       return CD_MEDIA_TYPE_ERROR;
+   }
+
+   fd = cam->fd;
+#else
+
    if ((fd = open (device, O_RDWR | O_EXCL | O_NONBLOCK)) < 0
        && (fd = open (device, O_RDONLY | O_EXCL | O_NONBLOCK)) < 0) {
        if (errno == EBUSY) {
@@ -271,6 +283,7 @@
        }
        return CD_MEDIA_TYPE_ERROR;
    }
+#endif
 
    mmc_profile = get_mmc_profile (fd);
 
@@ -298,7 +311,11 @@
        }
    }
 
+#ifdef __FreeBSD__
+   cam_close_device (cam);
+#else
    close (fd);
+#endif
 
    switch (mmc_profile) {
    case -1:
@@ -433,10 +450,21 @@
    int secs;
    int mmc_profile;
    gint64 size;
+#ifdef __FreeBSD__
+   struct cam_device *cam;
+#endif
 
    g_return_val_if_fail (device != NULL, CD_MEDIA_SIZE_UNKNOWN);
 
    secs = 0;
+#ifdef __FreeBSD__
+   cam = cam_open_device (device, O_RDWR);
+   if (cam == NULL) {
+       return CD_MEDIA_SIZE_UNKNOWN;
+   }
+
+   fd = cam->fd;
+#else
 
    if ((fd = open (device, O_RDWR | O_EXCL | O_NONBLOCK)) < 0
        && (fd = open (device, O_RDONLY | O_EXCL | O_NONBLOCK)) < 0) {
@@ -445,6 +473,7 @@
        }
        return CD_MEDIA_SIZE_UNKNOWN;
    }
+#endif
 
    mmc_profile = get_mmc_profile (fd);
 
@@ -467,7 +496,11 @@
        size = CD_MEDIA_SIZE_NA;
    }
 
+#ifdef __FreeBSD__
+   cam_close_device (cam);
+#else
    close (fd);
+#endif
 
    return size;
 }
@@ -586,9 +619,81 @@
 #endif /* USE_HAL */
 
 #if defined(__linux__) || defined(__FreeBSD__)
+static int
+get_device_max_write_speed (char *device)
+{
+   int fd;
+   int max_speed;
+   int read_speed, write_speed;
+#ifdef __FreeBSD__
+   struct cam_device *cam;
+#endif
+
+   max_speed = -1;
+#ifdef __FreeBSD__
+   cam = cam_open_device (device, O_RDWR);
+   if (cam == NULL) {
+       return -1;
+   }
+
+   fd = cam->fd;
+#else
+
+   fd = open (device, O_RDWR|O_EXCL|O_NONBLOCK);
+   if (fd < 0) {
+       return -1;
+   }
+#endif
 
+   get_read_write_speed (fd, &read_speed, &write_speed);
+#ifdef __FreeBSD__
+   cam_close_device (cam);
+#else
+   close (fd);
+#endif
+   max_speed = (int)floor  (write_speed) / CD_ROM_SPEED;
 
+   return max_speed;
+}
 
+#if !defined(__linux)
+static int
+get_device_max_read_speed (char *device)
+{
+   int fd;
+   int max_speed;
+   int read_speed, write_speed;
+#ifdef __FreeBSD__
+   struct cam_device *cam;
+#endif
+
+   max_speed = -1;
+#ifdef __FreeBSD__
+   cam = cam_open_device (device, O_RDWR);
+   if (cam == NULL) {
+       return -1;
+   }
+
+   fd = cam->fd;
+#else
+
+   fd = open (device, O_RDWR|O_EXCL|O_NONBLOCK);
+   if (fd < 0) {
+       return -1;
+   }
+#endif
+
+   get_read_write_speed (fd, &read_speed, &write_speed);
+#ifdef __FreeBSD__
+   cam_close_device (cam);
+#else
+   close (fd);
+#endif
+   max_speed = (int)floor  (read_speed) / CD_ROM_SPEED;
+
+   return max_speed;
+}
+#endif
 #endif /* __linux__ || __FreeBSD__ */
 
 #if defined (__linux__)
@@ -791,50 +896,6 @@
        }
    }
    return NULL;
-}
-
-#if !defined(__linux)
-static int
-get_device_max_read_speed (char *device)
-{
-   int fd;
-   int max_speed;
-   int read_speed, write_speed;
-
-   max_speed = -1;
-
-   if ((fd = open (device, O_RDWR | O_EXCL | O_NONBLOCK)) < 0
-       && (fd = open (device, O_RDONLY | O_EXCL | O_NONBLOCK)) < 0) {
-       return -1;
-   }
-
-   get_read_write_speed (fd, &read_speed, &write_speed);
-   close (fd);
-   max_speed = (int)floor  (read_speed) / CD_ROM_SPEED;
-
-   return max_speed;
-}
-#endif
-
-static int
-get_device_max_write_speed (char *device)
-{
-   int fd;
-   int max_speed;
-   int read_speed, write_speed;
-
-   max_speed = -1;
-
-   if ((fd = open (device, O_RDWR | O_EXCL | O_NONBLOCK)) < 0
-       && (fd = open (device, O_RDONLY | O_EXCL | O_NONBLOCK)) < 0) {
-       return -1;
-   }
-
-   get_read_write_speed (fd, &read_speed, &write_speed);
-   close (fd);
-   max_speed = (int)floor  (write_speed) / CD_ROM_SPEED;
-
-   return max_speed;
 }
 
 static char *