Merge commit 'dc97a43d4a70c8773a619f11b95b07a787f6f5b7' into merges
[unleashed.git] / share / man / man3volmgt / volmgt_acquire.3volmgt
blobe953ca1c7a6018c0f560f8a22ea56c5d140a950f
1 '\" te
2 .\"  Copyright (c) 1996, Sun Microsystems, Inc.  All Rights Reserved
3 .\" 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.
4 .\" 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.
5 .\" 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]
6 .TH VOLMGT_ACQUIRE 3VOLMGT "Mar 8, 2007"
7 .SH NAME
8 volmgt_acquire \- reserve removable media device
9 .SH SYNOPSIS
10 .LP
11 .nf
12 \fBcc\fR [ \fIflag\fR ... ] \fIfile\fR ... \fB-lvolmgt\fR [ \fIlibrary\fR ... ]
13 #include <sys/types.h>
15 #include <volmgt.h>
19 \fBint\fR \fBvolmgt_acquire\fR(\fBchar *\fR\fIdev\fR, \fBchar *\fR\fIid\fR, \fBint\fR \fIovr\fR, \fBchar **\fR\fIerr\fR, \fBpid_t *\fR\fIpidp\fR);
20 .fi
22 .SH DESCRIPTION
23 .sp
24 .LP
25 This function is obsolete. The management of removable media by the Volume
26 Management feature, including \fBvold\fR, has been replaced by software that
27 supports the Hardware Abstraction Layer (HAL). Programmatic support for HAL is
28 through the HAL APIs, which are documented on the HAL web site. See
29 \fBhal\fR(5). The return value of this function is undefined.
30 .sp
31 .LP
32 The  \fBvolmgt_acquire()\fR routine reserves the removable media device
33 specified as  \fIdev\fR. \fBvolmgt_acquire()\fR operates in two different
34 modes, depending on whether or not volume management is running.
35 .sp
36 .LP
37 If  volume management  \fIis\fR running, \fBvolmgt_acquire()\fR attempts to
38 reserve the removable media device specified as \fIdev\fR. Specify \fIdev\fR as
39 \fIeither\fR a symbolic device name (for example,  \fBfloppy0\fR) or a physical
40 device pathname (for example, \fB/dsk/unnamed_floppy\fR).
41 .sp
42 .LP
43 If  volume management  \fIis\fR \fInot\fR running, \fBvolmgt_acquire()\fR
44 requires callers to specify a physical device pathname for  \fIdev\fR.
45 Specifying  \fIdev\fR as a symbolic  device name is  \fInot\fR acceptable. In
46 this mode,  \fBvolmgt_acquire()\fR relies entirely on the major and minor
47 numbers of the device to determine whether or not the device is reserved.
48 .sp
49 .LP
50 If  \fIdev\fR is free,  \fBvolmgt_acquire()\fR updates the internal device
51 reservation database with the caller's process id  (\fIpid\fR) and the
52 specified \fBid\fR string.
53 .sp
54 .LP
55 If  \fIdev\fR is reserved  by another process, the reservation attempt fails
56 and  \fBvolmgt_acquire(\|):\fR
57 .RS +4
58 .TP
59 .ie t \(bu
60 .el o
61 sets \fBerrno\fR to \fBEBUSY\fR
62 .RE
63 .RS +4
64 .TP
65 .ie t \(bu
66 .el o
67 fills the caller's \fBid\fR value in the array pointed to by \fIerr\fR
68 .RE
69 .RS +4
70 .TP
71 .ie t \(bu
72 .el o
73 fills in the  \fIpid\fR to which the pointer  \fIpidp\fR points with the
74 \fIpid\fR of the process which holds the reservation,   if the supplied
75 \fIpidp\fR is non-zero
76 .RE
77 .sp
78 .LP
79 If the override  \fIovr\fR is non-zero, the call overrides the device
80 reservation.
81 .SH RETURN VALUES
82 .sp
83 .LP
84 The return from this function is undefined.
85 .SH ERRORS
86 .sp
87 .LP
88 The  \fBvolmgt_acquire()\fR routine fails if one or more of the following are
89 true:
90 .sp
91 .ne 2
92 .na
93 \fB\fBEINVAL\fR\fR
94 .ad
95 .RS 10n
96 One of the specified arguments is invalid or missing.
97 .RE
99 .sp
100 .ne 2
102 \fB\fBEBUSY\fR\fR
104 .RS 10n
105 \fIdev\fR is already reserved by another process (and \fIovr\fR was not set to
106 a non-zero value)
109 .SH EXAMPLES
111 \fBExample 1 \fRUsing \fBvolmgt_acquire()\fR
114 In the following example, volume management is running and the first floppy
115 drive is reserved, accessed and released.
118 .in +2
120 #include <volmgt.h>
121 char *errp;
122 if (!volmgt_acquire("floppy0", "FileMgr", 0, NULL,
123     &errp, NULL)) {
124         /* handle error case */
125         .\|.\|.
127 /* floppy acquired - now access it */
128 if (!volmgt_release("floppy0")) {
129         /* handle error case */
130         \|.\|.\|.
133 .in -2
136 \fBExample 2 \fRUsing  \fBvolmgt_acquire()\fR To Override A Lock On Another
137 Process
140 The following example shows how callers can override a  lock on another process
141 using  \fBvolmgt_acquire()\fR.
144 .in +2
146 char *errp, buf[20];
147 int override = 0;
148 pid_t pid;
149 if (!volmgt_acquire("floppy0", "FileMgr", 0, &errp,
150     &pid)) {
151       if (errno == EBUSY) {
152              (void) printf("override %s (pid=%ld)?\en",
153                 errp, pid); {
154              (void) fgets(buf, 20, stdin);
155              if (buf[0] == 'y') {
156                    override++;
157              }
158        } else {
159              /* handle other errors */
160              .\|.\|.
161        }
163 if (override) {
164       if (!volmgt_acquire("floppy0", "FileMgr", 1,
165           &errp, NULL)) {
166              /* really give up this time! */
167              \|.\|.\|.
168       }
171 .in -2
173 .SH ATTRIBUTES
176 See \fBattributes\fR(5) for descriptions of the following attributes:
181 box;
182 c | c
183 l | l .
184 ATTRIBUTE TYPE  ATTRIBUTE VALUE
186 MT-Level        MT-Safe
188 Interface Stability     Obsolete
191 .SH SEE ALSO
194 \fBfree\fR(3C), \fBmalloc\fR(3C), \fBvolmgt_release\fR(3VOLMGT),
195 \fBattributes\fR(5), \fBhal\fR(5)
196 .SH NOTES
199 When returning a string through  \fIerr\fR, \fBvolmgt_acquire()\fR allocates a
200 memory area using  \fBmalloc\fR(3C). Use \fBfree\fR(3C) to release the memory
201 area  when no longer needed.
204 The \fIovr\fR argument is intended to allow callers to override the current
205 device reservation. It is assumed that the calling application has determined
206 that the current reservation can safely be cleared. See  \fBEXAMPLES.\fR