]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - libdisk/xvm.c
Update copyright/license notices to match SGI legal prefered boilerplate.
[thirdparty/xfsprogs-dev.git] / libdisk / xvm.c
1 /*
2 * Copyright (c) 2000-2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19 #include <stdio.h>
20 #include <fcntl.h>
21 #include <stdlib.h>
22 #include <unistd.h>
23 #include <sys/stat.h>
24 #include <sys/ioctl.h>
25 #include <disk/volume.h>
26 #include "xvm.h"
27
28 int
29 mnt_is_xvm_subvol(
30 dev_t dev)
31 {
32 return get_driver_block_major("xvm", major(dev));
33 }
34
35 /*
36 * If the logical device is a xvm striped volume, then it returns the
37 * stripe unit and stripe width information.
38 * Input parameters: the logical volume
39 * the subvolume type - (SVTYPE_RT or
40 * SVTYPE_DATA)
41 * Output parameters: the stripe unit and width in 512 byte blocks
42 * true/false - was this device an XVM volume?
43 */
44 int
45 xvm_get_subvol_stripe(
46 char *dev,
47 sv_type_t type,
48 int *sunit,
49 int *swidth,
50 int *sectalign,
51 struct stat64 *sb)
52 {
53 int fd;
54 xvm_getdev_t getdev;
55 xvm_subvol_stripe_t subvol_stripe;
56
57 if (!mnt_is_xvm_subvol(sb->st_rdev))
58 return 0;
59
60 /*
61 * This will actually open the data subvolume.
62 */
63 if ((fd = open(dev, O_RDONLY)) < 0)
64 return 0;
65
66 /*
67 * Go and get the the information for the correct
68 * subvolume.
69 */
70 if (ioctl(fd, DIOCGETVOLDEV, &getdev) < 0) {
71 close(fd);
72 return 0;
73 }
74 if ( (type == SVTYPE_RT) && (getdev.rt_subvol_dev) )
75 subvol_stripe.dev = getdev.rt_subvol_dev;
76 else if ( (type == SVTYPE_DATA) && (getdev.data_subvol_dev) )
77 subvol_stripe.dev = getdev.data_subvol_dev;
78 else {
79 close(fd);
80 return 0;
81 }
82
83 if (ioctl(fd, DIOCGETVOLSTRIPE, &subvol_stripe) < 0) {
84 close(fd);
85 return 0;
86 }
87
88 *sunit = subvol_stripe.unit_size;
89 *swidth = *sunit * subvol_stripe.width_size;
90 *sectalign = 0;
91 close(fd);
92 return 1;
93 }