]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blame - libdisk/xvm.c
Update copyright/license notices to match SGI legal prefered boilerplate.
[thirdparty/xfsprogs-dev.git] / libdisk / xvm.c
CommitLineData
f937adac 1/*
da23017d
NS
2 * Copyright (c) 2000-2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
dfc130f3 4 *
da23017d
NS
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
f937adac 7 * published by the Free Software Foundation.
dfc130f3 8 *
da23017d
NS
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.
dfc130f3 13 *
da23017d
NS
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
f937adac
NS
17 */
18
19#include <stdio.h>
20#include <fcntl.h>
a400ab25 21#include <stdlib.h>
f937adac
NS
22#include <unistd.h>
23#include <sys/stat.h>
24#include <sys/ioctl.h>
1d7e80ee 25#include <disk/volume.h>
f937adac
NS
26#include "xvm.h"
27
d5dca43b 28int
a400ab25
NS
29mnt_is_xvm_subvol(
30 dev_t dev)
f937adac 31{
a400ab25 32 return get_driver_block_major("xvm", major(dev));
f937adac
NS
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 */
44int
45xvm_get_subvol_stripe(
46 char *dev,
47 sv_type_t type,
48 int *sunit,
49 int *swidth,
c22b5fdf 50 int *sectalign,
f937adac
NS
51 struct stat64 *sb)
52{
d5dca43b
NS
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))
8e9bef16
NS
58 return 0;
59
d5dca43b
NS
60 /*
61 * This will actually open the data subvolume.
62 */
63 if ((fd = open(dev, O_RDONLY)) < 0)
64 return 0;
8e9bef16 65
d5dca43b
NS
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;
c22b5fdf 90 *sectalign = 0;
d5dca43b
NS
91 close(fd);
92 return 1;
f937adac 93}