1ldi_open_by_dev(9F)      Kernel Functions for Drivers      ldi_open_by_dev(9F)
2
3
4

NAME

6       ldi_open_by_dev,  ldi_open_by_name, ldi_open_by_devid, ldi_close - open
7       and close devices
8

SYNOPSIS

10       #include <sys/sunldi.h>
11
12       int ldi_open_by_dev(dev_t *devp, int otyp, int flag, cred_t  *cr,
13            ldi_handle_t *lhp, ldi_ident_t li);
14
15
16       int ldi_open_by_name(char  *pathname, int flag, cred_t *cr,
17            ldi_handle_t *lhp, ldi_ident_t li);
18
19
20       int ldi_open_by_devid(ddi_devid_t devid, char  *minor_name, int flag,
21            cred_t *cr, ldi_handle_t *lhp, ldi_ident_t li);
22
23
24       int ldi_close(ldi_handle_t lh, int flag, cred_ t *cr);
25
26

PARAMETERS

28       lh            Layered handle
29
30
31       lhp           Pointer to a layered handle that is returned upon a  suc‐
32                     cessful open.
33
34
35       li            LDI identifier.
36
37
38       cr            Pointer  to  the  credential  structure  used  to  open a
39                     device.
40
41
42       devp          Pointer to a device number.
43
44
45       pathname      Pathname to a device.
46
47
48       devid         Device ID.
49
50
51       minor_name    Minor device node name.
52
53
54       otyp          Flag passed to the driver indicating which  interface  is
55                     open. Valid settings are:
56
57                     OTYP_BLK    Open the device block interface.
58
59
60                     OTYP_CHR    Open the device character interface.
61
62                     Only  one  OTYP  flag  can  be specified. To open streams
63                     devices, specify OTYP_CHR.
64
65
66       flag          Bit field that instructs the driver on how  to  open  the
67                     device. Valid settings are:
68
69                     FEXCL      Open  the  device  with exclusive access; fail
70                                all other attempts to open the device.
71
72
73                     FNDELAY    Open the device and  return  immediately.   Do
74                                not block the open even if something is wrong.
75
76
77                     FREAD      Open the device with read-only permission. (If
78                                ORed with FWRITE, allow both  read  and  write
79                                access).
80
81
82                     FWRITE     Open  a  device with write-only permission (if
83                                ORed with FREAD,  then  allow  both  read  and
84                                write access).
85
86
87                     FNOCTTY    Open  the  device.  If the device is a tty, do
88                                not attempt to open it as  a  session-control‐
89                                ling tty.
90
91
92

DESCRIPTION

94       The ldi_open_by_dev(), ldi_open_by_name() and ldi_open_by_devid() func‐
95       tions allow a caller to open a block,  character,  or  streams  device.
96       Upon  a successful open, a layered handle to the device is returned via
97       the layered handle pointed to by lhp.  The  ldi  identifier  passed  to
98       these functions is previously allocated with ldi_ident_from_stream(9F),
99       ldi_ident_from_dev(9F), and ldi_ident_from_dip(9F).
100
101
102       The ldi_open_by_dev() function opens a device specified  by  the  dev_t
103       pointed  to by devp.  Upon successful open, the caller should check the
104       value of the dev_t to see if it  has  changed.  (Cloning  devices  will
105       change  this value during opens.)   When opening a streams device, otyp
106       must be OTYP_CHR.
107
108
109       The ldi_open_by_devid() function opens a device by  devid.  The  caller
110       must specify the minor node name to open.
111
112
113       The ldi_open_by_name() function opens a device by pathname. Pathname is
114       a null terminated string in the kernel address space. Pathname must  be
115       an  absolute  path,  meaning that it must begin with '/'. The format of
116       the pathname supplied to this function is either a /devices path or any
117       other  filesystem path to a device node. Opens utilizing /devices paths
118       are supported before root is mounted. Opens utilizing other  filesystem
119       paths to device nodes are supported only if root is already mounted.
120
121
122       The ldi_close() function closes a layered handle that was obtained with
123       either ldi_open_by_dev(), ldi_open_by_name(),  or  ldi_open_by_devid().
124       After  ldi_close()  returns  the layered handle, the lh that was previ‐
125       ously passed in is no longer valid.
126

RETURN VALUES

128       The ldi_close() function returns 0 for success. EINVAL is returned  for
129       invalid  input  parameters.  Otherwise,  any  other error number may be
130       returned by the device.
131
132
133       The ldi_open_by_dev() and ldi_open_by_devid() functions return  0  upon
134       success. If a failure occurs before the device is open, possible return
135       values are shown  below.  Otherwise  any  other  error  number  may  be
136       returned by the device.
137
138       EINVAL    Invalid input parameters.
139
140
141       ENODEV    Requested device does not exist.
142
143
144       ENXIO     Unsupported device operation or access mode.
145
146
147
148       The  ldi_open_by_name()  function  returns 0 upon success. If a failure
149       occurs before the device is open,  possible  return  values  are  shown
150       below. Otherwise any other error number may be returned by the device.
151
152       EINVAL    Invalid input parameters.
153
154
155       ENODEV    Requested device path does not exist.
156
157
158       EACCES    Search  permission  is denied on a component of the path pre‐
159                 fix, or the file exists and the permissions specified  by  cr
160                 are denied.
161
162
163       ENXIO     Unsupported device operation or access mode.
164
165

CONTEXT

167       These functions may be called from user or kernel context.
168
169
170       These functions should not be called from a device's attach, detach, or
171       power entry point. This could result in a system crash or deadlock.
172

SEE ALSO

174       scsi_vhci(7D),     ldi_ident_from_dev(9F),      ldi_ident_from_dip(9F),
175       ldi_ident_from_stream(9F)
176

NOTES

178       Use   only   OTYP_CHR   or   OTYP_BLK   options   when   you   use  the
179       ldi_open_by_dev() and ldi_open_by_devid() functions to open  a  device.
180       Other flags, including OTYP_LYR, have been deprecated and should not be
181       used with these interfaces.
182
183
184       The caller should be aware of cases when multiple  paths  to  a  single
185       device   may   exist.   (This  can  occur  for  scsi  disk  devices  if
186       scsi_vhci(7D)) is disabled or a disk  is  connected  to  multiple  con‐
187       trollers not supported by scsi_vhci(7D).
188
189
190       In these cases, ldi_open_by_devid() returns a device handle that corre‐
191       sponds to a  particular path to a target device. This path may  not  be
192       the  same across multiple calls to ldi_open_by_devid().  Device handles
193       associated  with the same device but different access paths should have
194       different filesystem device paths and dev_t values.
195
196
197       In  the  cases where multiple paths to a device exist and access to the
198       device has not been virtualized via MPXIO (as with  scsi  disk  devices
199       not  accessed  via  scsi_vhci(7D)),  the  LDI does not provide any path
200       fail-over capabilities. If the caller wishes to do their own path  man‐
201       agement  and  failover they should open all available paths to a device
202       via ldi_open_by_name().
203
204
205
206SunOS 5.11                        9 Aug 2004               ldi_open_by_dev(9F)
Impressum