8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / lib / libdiskmgt / common / inuse_dump.c
blob7725f42a700807cc6d36aeb69db40026bdbd12e7
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
20 * CDDL HEADER END
23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
30 * Checks for a match with the the dump slice.
33 #include <stdlib.h>
34 #include <stdio.h>
35 #include <unistd.h>
36 #include <string.h>
37 #include <synch.h>
38 #include <sys/param.h>
39 #include <sys/types.h>
40 #include <sys/stat.h>
41 #include <fcntl.h>
42 #include <sys/dumpadm.h>
44 #include "libdiskmgt.h"
45 #include "disks_private.h"
47 /* Cached file descriptor for /dev/dump. */
48 static int dump_fd = -1;
50 static mutex_t dump_lock = DEFAULTMUTEX;
53 * Check the dump device against the input slice.
55 int
56 inuse_dump(char *slice, nvlist_t *attrs, int *errp)
58 int found = 0;
59 int fd;
60 char device[MAXPATHLEN];
62 *errp = 0;
63 if (slice == NULL) {
64 return (found);
68 * We only want to open /dev/dump once instead of for every
69 * slice so we cache the open file descriptor. The ioctl
70 * is cheap so we can do that for every slice.
72 (void) mutex_lock(&dump_lock);
74 if (dump_fd == -1) {
75 if ((dump_fd = open("/dev/dump", O_RDONLY)) >= 0)
76 (void) fcntl(dump_fd, F_SETFD, FD_CLOEXEC);
79 fd = dump_fd;
81 (void) mutex_unlock(&dump_lock);
83 if (fd != -1) {
84 if (ioctl(fd, DIOCGETDEV, device) != -1) {
85 if (strcmp(slice, device) == 0) {
86 libdiskmgt_add_str(attrs, DM_USED_BY,
87 DM_USE_DUMP, errp);
88 libdiskmgt_add_str(attrs, DM_USED_NAME,
89 DM_USE_DUMP, errp);
90 found = 1;
95 return (found);