summaryrefslogtreecommitdiff
path: root/usr/src/man/man9f/ldi_open_by_dev.9f
blob: cc006ccba9ba1e0aca546a45bbfe2779718a49c5 (plain)
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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
'\" te
.\" Copyright (c) 2004, Sun Microsystems, Inc.,  All Rights Reserved
.\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License").  You may not use this file except in compliance with the License.
.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.  See the License for the specific language governing permissions and limitations under the License.
.\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE.  If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
.TH ldi_open_by_dev 9F "9 Aug 2004" "SunOS 5.11" "Kernel Functions for Drivers"
.SH NAME
ldi_open_by_dev, ldi_open_by_name, ldi_open_by_devid, ldi_close \- open and
close devices
.SH SYNOPSIS
.LP
.nf
#include <sys/sunldi.h> 

\fBint\fR \fBldi_open_by_dev\fR(\fBdev_t *\fR\fIdevp\fR, \fBint\fR \fIotyp\fR, \fBint\fR \fIflag\fR, \fBcred_t  *\fR\fIcr\fR, 
     \fBldi_handle_t *\fR\fIlhp\fR, \fBldi_ident_t\fR \fIli\fR);
.fi

.LP
.nf
\fBint\fR \fBldi_open_by_name\fR(\fBchar  *\fR\fIpathname\fR, \fBint\fR \fIflag\fR, \fBcred_t *\fR\fIcr\fR, 
     \fBldi_handle_t *\fR\fIlhp\fR, \fBldi_ident_t\fR \fIli\fR);
.fi

.LP
.nf
\fBint\fR \fBldi_open_by_devid\fR(\fBddi_devid_t\fR \fIdevid\fR, \fBchar  *\fR\fIminor_name\fR, \fBint\fR \fIflag\fR,
     \fBcred_t *\fR\fIcr\fR, \fBldi_handle_t *\fR\fIlhp\fR, \fBldi_ident_t\fR \fIli\fR);
.fi

.LP
.nf
\fBint\fR \fBldi_close\fR(\fBldi_handle_t\fR \fIlh\fR, \fBint\fR \fIflag\fR, \fBcred_ t *\fR\fIcr\fR);
.fi

.SH PARAMETERS
.sp
.ne 2
.mk
.na
\fB\fIlh\fR\fR
.ad
.RS 14n
.rt  
Layered handle
.RE

.sp
.ne 2
.mk
.na
\fB\fIlhp\fR\fR
.ad
.RS 14n
.rt  
Pointer to a layered handle that is returned upon a successful open.
.RE

.sp
.ne 2
.mk
.na
\fB\fIli\fR\fR
.ad
.RS 14n
.rt  
LDI identifier.
.RE

.sp
.ne 2
.mk
.na
\fB\fIcr\fR\fR
.ad
.RS 14n
.rt  
Pointer to the credential structure used to open a device.
.RE

.sp
.ne 2
.mk
.na
\fB\fIdevp\fR\fR
.ad
.RS 14n
.rt  
Pointer to a device number.
.RE

.sp
.ne 2
.mk
.na
\fB\fIpathname\fR\fR
.ad
.RS 14n
.rt  
Pathname to a device.
.RE

.sp
.ne 2
.mk
.na
\fB\fIdevid\fR\fR
.ad
.RS 14n
.rt  
Device ID.
.RE

.sp
.ne 2
.mk
.na
\fB\fIminor_name\fR\fR
.ad
.RS 14n
.rt  
Minor device node name.
.RE

.sp
.ne 2
.mk
.na
\fB\fIotyp\fR\fR
.ad
.RS 14n
.rt  
Flag passed to the driver indicating which interface is open. Valid settings
are:
.sp
.ne 2
.mk
.na
\fBOTYP_BLK\fR
.ad
.RS 12n
.rt  
Open the device block interface.
.RE

.sp
.ne 2
.mk
.na
\fBOTYP_CHR\fR
.ad
.RS 12n
.rt  
Open the device character interface.
.RE

Only one OTYP flag can be specified. To open streams devices, specify
\fBOTYP_CHR\fR.
.RE

.sp
.ne 2
.mk
.na
\fB\fIflag\fR\fR
.ad
.RS 14n
.rt  
Bit field that instructs the driver on how to open the device. Valid settings
are:
.sp
.ne 2
.mk
.na
\fBFEXCL\fR
.ad
.RS 11n
.rt  
Open the device with exclusive access; fail all other attempts to open the
device.
.RE

.sp
.ne 2
.mk
.na
\fBFNDELAY\fR
.ad
.RS 11n
.rt  
Open the device and return immediately.  Do not block the open even if
something is wrong.
.RE

.sp
.ne 2
.mk
.na
\fBFREAD\fR
.ad
.RS 11n
.rt  
Open the device with read-only permission. (If ORed with \fBFWRITE\fR, allow
both read and write access).
.RE

.sp
.ne 2
.mk
.na
\fBFWRITE\fR
.ad
.RS 11n
.rt  
Open a device with write-only permission (if ORed with \fBFREAD\fR, then allow
both read and write access).
.RE

.sp
.ne 2
.mk
.na
\fBFNOCTTY\fR
.ad
.RS 11n
.rt  
Open the device. If the device is a tty, do not attempt to open it as a
session-controlling tty.
.RE

.RE

.SH DESCRIPTION
.sp
.LP
The \fBldi_open_by_dev()\fR, \fBldi_open_by_name()\fR and
\fBldi_open_by_devid()\fR functions allow a caller to open a block, character,
or streams device. Upon a successful open, a layered handle to the device is
returned via the layered handle pointed to by \fIlhp\fR. The ldi identifier
passed to these functions is previously allocated with
\fBldi_ident_from_stream\fR(9F), \fBldi_ident_from_dev\fR(9F), and
\fBldi_ident_from_dip\fR(9F).
.sp
.LP
The \fBldi_open_by_dev()\fR function opens a device specified by the dev_t
pointed to by devp.  Upon successful open, the caller should check the value of
the dev_t to see if it has changed. (Cloning devices will change this value
during opens.)   When opening a streams device, otyp must be OTYP_CHR.
.sp
.LP
The \fBldi_open_by_devid()\fR function opens a device by devid. The caller must
specify the minor node name to open.
.sp
.LP
The \fBldi_open_by_name()\fR function opens a device by pathname. Pathname is a
null terminated string in the kernel address space. Pathname must be an
absolute path, meaning that it must begin with '/'. The format of the pathname
supplied to this function is either a \fB/devices\fR path or any other
filesystem path to a device node. Opens utilizing \fB/devices\fR paths are
supported before root is mounted. Opens utilizing other filesystem paths to
device nodes are supported only if root is already mounted.
.sp
.LP
The \fBldi_close()\fR function closes a layered handle that was obtained with
either \fBldi_open_by_dev()\fR, \fBldi_open_by_name()\fR, or
\fBldi_open_by_devid()\fR. After \fBldi_close()\fR returns the layered handle,
the \fIlh\fR that was previously passed in is no longer valid.
.SH RETURN VALUES
.sp
.LP
The \fBldi_close()\fR function returns \fB0\fR for success. \fBEINVAL\fR is
returned for invalid input parameters. Otherwise, any other error number may be
returned by the device.
.sp
.LP
The \fBldi_open_by_dev()\fR and \fBldi_open_by_devid()\fR functions return
\fB0\fR upon success. If a failure occurs before the device is open, possible
return values are shown below. Otherwise any other error number may be returned
by the device.
.sp
.ne 2
.mk
.na
\fBEINVAL\fR
.ad
.RS 10n
.rt  
Invalid input parameters.
.RE

.sp
.ne 2
.mk
.na
\fBENODEV\fR
.ad
.RS 10n
.rt  
Requested device does not exist.
.RE

.sp
.ne 2
.mk
.na
\fBENXIO\fR
.ad
.RS 10n
.rt  
Unsupported device operation or access mode.
.RE

.sp
.LP
The \fBldi_open_by_name()\fR function returns \fB0\fR upon success. If a
failure occurs before the device is open, possible return values are shown
below. Otherwise any other error number may be returned by the device.
.sp
.ne 2
.mk
.na
\fBEINVAL\fR
.ad
.RS 10n
.rt  
Invalid input parameters.
.RE

.sp
.ne 2
.mk
.na
\fBENODEV\fR
.ad
.RS 10n
.rt  
Requested device path does not exist.
.RE

.sp
.ne 2
.mk
.na
\fBEACCES\fR
.ad
.RS 10n
.rt  
Search permission is denied on a component of the path prefix, or the file
exists and the permissions specified by \fIcr\fR are denied.
.RE

.sp
.ne 2
.mk
.na
\fBENXIO\fR
.ad
.RS 10n
.rt  
Unsupported device operation or access mode.
.RE

.SH CONTEXT
.sp
.LP
These functions may be called from user or kernel context.
.sp
.LP
These functions should not be called from a device's attach, detach, or power
entry point. This could result in a system crash or deadlock.
.SH SEE ALSO
.sp
.LP
\fBscsi_vhci\fR(7D), \fBldi_ident_from_dev\fR(9F),
\fBldi_ident_from_dip\fR(9F), \fBldi_ident_from_stream\fR(9F)
.SH NOTES
.sp
.LP
Use only OTYP_CHR or OTYP_BLK options when you use the \fBldi_open_by_dev()\fR
and \fBldi_open_by_devid()\fR functions to open a device. Other flags,
including OTYP_LYR, have been deprecated and should not be used with these
interfaces.
.sp
.LP
The caller should be aware of cases when multiple paths to a single device may
exist.  (This can occur for scsi disk devices if \fBscsi_vhci\fR(7D)) is
disabled or a disk is connected to multiple controllers not supported by
scsi_vhci(7D).
.sp
.LP
In these cases, \fBldi_open_by_devid()\fR returns a device handle that
corresponds to a  particular path to a target device. This path may not be the
same across multiple calls to \fBldi_open_by_devid()\fR.  Device handles
associated  with the same device but different access paths should have
different filesystem device paths and dev_t values.
.sp
.LP
In the cases where multiple paths to a device exist and access to the device
has not been virtualized via MPXIO (as with scsi disk devices not accessed via
\fBscsi_vhci\fR(7D)), the LDI does not provide any path fail-over capabilities.
If the caller wishes to do their own path management and failover they should
open all available paths to a device via \fBldi_open_by_name()\fR.