~ubuntu-branches/ubuntu/hoary/xfsprogs/hoary

« back to all changes in this revision

Viewing changes to libdisk/drivers.c

  • Committer: Bazaar Package Importer
  • Author(s): Nathan Scott
  • Date: 2004-07-28 21:11:38 UTC
  • Revision ID: james.westby@ubuntu.com-20040728211138-0v4pdnunnp7na5lm
Tags: 2.6.20-1
* New upstream release.
* Fix xfs_io segfault on non-XFS files.  (closes: #260470)
* Fix packaging botch, deleted files included.  (closes: #260491)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
3
 
 * 
 
2
 * Copyright (c) 2000-2004 Silicon Graphics, Inc.  All Rights Reserved.
 
3
 *
4
4
 * This program is free software; you can redistribute it and/or modify it
5
5
 * under the terms of version 2 of the GNU General Public License as
6
6
 * published by the Free Software Foundation.
7
 
 * 
 
7
 *
8
8
 * This program is distributed in the hope that it would be useful, but
9
9
 * WITHOUT ANY WARRANTY; without even the implied warranty of
10
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
 
 * 
 
11
 *
12
12
 * Further, this software is distributed without any warranty that it is
13
13
 * free of the rightful claim of any third person regarding infringement
14
14
 * or the like.  Any license provided herein, whether implied or
15
15
 * otherwise, applies only to this software file.  Patent licenses, if
16
16
 * any, provided herein do not apply to combinations of this program with
17
17
 * other software, or any other product whatsoever.
18
 
 * 
 
18
 *
19
19
 * You should have received a copy of the GNU General Public License along
20
20
 * with this program; if not, write the Free Software Foundation, Inc., 59
21
21
 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
22
 
 * 
 
22
 *
23
23
 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24
24
 * Mountain View, CA  94043, or:
25
 
 * 
26
 
 * http://www.sgi.com 
27
 
 * 
28
 
 * For further information regarding this notice, see: 
29
 
 * 
 
25
 *
 
26
 * http://www.sgi.com
 
27
 *
 
28
 * For further information regarding this notice, see:
 
29
 *
30
30
 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
31
31
 */
32
32
 
33
 
#include <stdio.h>
34
 
#include <errno.h>
35
 
#include <stdlib.h>
36
 
#include <string.h>
37
 
#include <sys/stat.h>
38
 
#include <volume.h>
39
 
 
40
 
extern int  md_get_subvol_stripe(char*, sv_type_t, int*, int*, struct stat64*);
41
 
extern int lvm_get_subvol_stripe(char*, sv_type_t, int*, int*, struct stat64*);
42
 
extern int xvm_get_subvol_stripe(char*, sv_type_t, int*, int*, struct stat64*);
 
33
#include "drivers.h"
43
34
 
44
35
void
45
36
get_subvol_stripe_wrapper(char *dev, sv_type_t type, int *sunit, int *swidth)
48
39
 
49
40
        if (dev == NULL)
50
41
                return;
51
 
                
 
42
 
52
43
        if (stat64(dev, &sb)) {
53
 
                fprintf(stderr, "Cannot stat %s: %s\n", dev, strerror(errno));
 
44
                fprintf(stderr, _("Cannot stat %s: %s\n"),
 
45
                        dev, strerror(errno));
54
46
                exit(1);
55
47
        }
56
48
 
57
 
        if ( md_get_subvol_stripe(dev, type, sunit, swidth, &sb))
58
 
                return;
59
 
        if (lvm_get_subvol_stripe(dev, type, sunit, swidth, &sb))
60
 
                return;
61
 
        if (xvm_get_subvol_stripe(dev, type, sunit, swidth, &sb))
62
 
                return;
 
49
        if (  dm_get_subvol_stripe(dev, type, sunit, swidth, &sb))
 
50
                return;
 
51
        if (  md_get_subvol_stripe(dev, type, sunit, swidth, &sb))
 
52
                return;
 
53
        if ( lvm_get_subvol_stripe(dev, type, sunit, swidth, &sb))
 
54
                return;
 
55
        if ( xvm_get_subvol_stripe(dev, type, sunit, swidth, &sb))
 
56
                return;
 
57
        if (evms_get_subvol_stripe(dev, type, sunit, swidth, &sb))
 
58
                return;
 
59
 
63
60
        /* ... add new device drivers here */
64
61
}
65
62
 
 
63
#define DEVICES "/proc/devices"
 
64
 
66
65
/*
67
66
 * General purpose routine which dredges through procfs trying to
68
67
 * match up device driver names with the associated major numbers
69
68
 * being used in the running kernel.
70
69
 */
71
70
int
72
 
get_driver_block_major(const char *driver)
 
71
get_driver_block_major(const char *driver, int major)
73
72
{
74
73
        FILE    *f;
75
74
        char    buf[64], puf[64];
76
 
        int     major = -1;
 
75
        int     dmajor, match = 0;
77
76
 
78
 
#define PROC_DEVICES    "/proc/devices"
79
 
        if ((f = fopen(PROC_DEVICES, "r")) == NULL)
80
 
                return major;
 
77
        if ((f = fopen(DEVICES, "r")) == NULL)
 
78
                return match;
81
79
        while (fgets(buf, sizeof(buf), f))      /* skip to block dev section */
82
 
                if (strcmp("Block devices:\n", buf) == 0)
 
80
                if (strncmp("Block devices:\n", buf, sizeof(buf)) == 0)
83
81
                        break;
84
82
        while (fgets(buf, sizeof(buf), f))
85
 
                if ((sscanf(buf, "%u %s\n", &major, puf) == 2) &&
86
 
                    (strcmp(puf, driver) == 0))
87
 
                        break;
 
83
                if ((sscanf(buf, "%u %s\n", &dmajor, puf) == 2) &&
 
84
                    (strncmp(puf, driver, sizeof(puf)) == 0) &&
 
85
                    (dmajor == major))
 
86
                        match = 1;
88
87
        fclose(f);
89
 
        return major;
 
88
        return match;
90
89
}