]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - libdisk/xvm.c
remove rules to tidy up tmp libtool files - we use the installed version now.
[thirdparty/xfsprogs-dev.git] / libdisk / xvm.c
1 /*
2 * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 *
12 * Further, this software is distributed without any warranty that it is
13 * free of the rightful claim of any third person regarding infringement
14 * or the like. Any license provided herein, whether implied or
15 * otherwise, applies only to this software file. Patent licenses, if
16 * any, provided herein do not apply to combinations of this program with
17 * other software, or any other product whatsoever.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write the Free Software Foundation, Inc., 59
21 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
22 *
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
25 *
26 * http://www.sgi.com
27 *
28 * For further information regarding this notice, see:
29 *
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
31 */
32
33 #include <stdio.h>
34 #include <fcntl.h>
35 #include <unistd.h>
36 #include <sys/stat.h>
37 #include <sys/ioctl.h>
38 #include <volume.h>
39 #include "xvm.h"
40
41 int
42 mnt_is_xvm_subvol(dev_t dev)
43 {
44 if (major(dev) == get_driver_block_major("xvm"))
45 return 1;
46 return 0;
47 }
48
49 /*
50 * If the logical device is a xvm striped volume, then it returns the
51 * stripe unit and stripe width information.
52 * Input parameters: the logical volume
53 * the subvolume type - (SVTYPE_RT or
54 * SVTYPE_DATA)
55 * Output parameters: the stripe unit and width in 512 byte blocks
56 * true/false - was this device an XVM volume?
57 */
58 int
59 xvm_get_subvol_stripe(
60 char *dev,
61 sv_type_t type,
62 int *sunit,
63 int *swidth,
64 struct stat64 *sb)
65 {
66 int fd;
67 xvm_getdev_t getdev;
68 xvm_subvol_stripe_t subvol_stripe;
69
70 if (!mnt_is_xvm_subvol(sb->st_rdev))
71 return 0;
72
73 /*
74 * This will actually open the data subvolume.
75 */
76 if ((fd = open(dev, O_RDONLY)) < 0)
77 return 0;
78
79 /*
80 * Go and get the the information for the correct
81 * subvolume.
82 */
83 if (ioctl(fd, DIOCGETVOLDEV, &getdev) < 0) {
84 close(fd);
85 return 0;
86 }
87 if ( (type == SVTYPE_RT) && (getdev.rt_subvol_dev) )
88 subvol_stripe.dev = getdev.rt_subvol_dev;
89 else if ( (type == SVTYPE_DATA) && (getdev.data_subvol_dev) )
90 subvol_stripe.dev = getdev.data_subvol_dev;
91 else {
92 close(fd);
93 return 0;
94 }
95
96 if (ioctl(fd, DIOCGETVOLSTRIPE, &subvol_stripe) < 0) {
97 close(fd);
98 return 0;
99 }
100
101 *sunit = subvol_stripe.unit_size;
102 *swidth = *sunit * subvol_stripe.width_size;
103 close(fd);
104 return 1;
105 }