~ubuntu-branches/ubuntu/edgy/xfsprogs/edgy

« back to all changes in this revision

Viewing changes to libdisk/pttype.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-2001 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
 
35
35
#include <unistd.h>
36
36
#include <sys/types.h>
37
37
#include <netinet/in.h>
38
 
#include <dvh.h>
 
38
#include <disk/dvh.h>
39
39
#include "pttype.h"
40
40
 
41
41
#define blksize 512
42
42
 
43
 
static __uint32_t
44
 
twos_complement_32bit_sum(__uint32_t *base, int size)
 
43
static u_int32_t
 
44
twos_complement_32bit_sum(u_int32_t *base, int size)
45
45
{
46
46
        int i;
47
 
        __uint32_t sum = 0;
 
47
        u_int32_t sum = 0;
48
48
 
49
 
        size = size / sizeof(__uint32_t);
 
49
        size = size / sizeof(u_int32_t);
50
50
        for (i = 0; i < size; i++)
51
51
                sum = sum - ntohl(base[i]);
52
52
        return sum;
55
55
static int
56
56
sgi_parttable(char *base)
57
57
{
58
 
        __uint32_t csum;
 
58
        u_int32_t csum;
59
59
        struct volume_header *vh = (struct volume_header *)base;
60
60
 
61
61
        if (ntohl(vh->vh_magic) != VHMAGIC)
62
62
                return 0;
63
 
        csum = twos_complement_32bit_sum((__uint32_t *)vh,
 
63
        csum = twos_complement_32bit_sum((u_int32_t *)vh,
64
64
                                         sizeof(struct volume_header));
65
65
        return !csum;
66
66
}
68
68
static int
69
69
dos_parttable(char *base)
70
70
{
71
 
        return (base[510] == 0x55 && base[511] == 0xaa);
 
71
        return (base[510] == 0x55 && base[511] == 0xaa);
72
72
}
73
73
 
74
74
static int
85
85
        int csum = 0;
86
86
 
87
87
        if (sunlabel(base)->magic != SUN_LABEL_MAGIC &&
88
 
            sunlabel(base)->magic != SUN_LABEL_MAGIC_SWAPPED)
 
88
            sunlabel(base)->magic != SUN_LABEL_MAGIC_SWAPPED)
89
89
                return csum;
90
90
        ush = ((unsigned short *) (sunlabel(base) + 1)) - 1;
91
91
        while (ush >= (unsigned short *)sunlabel(base))
93
93
        return !csum;
94
94
}
95
95
 
 
96
static int
 
97
mac_parttable(char *base)
 
98
{
 
99
        return (ntohs(maclabel(base)->magic) == MAC_LABEL_MAGIC ||
 
100
                ntohs(maclabel(base)->magic) == MAC_PARTITION_MAGIC ||
 
101
                ntohs(maclabel(base)->magic) == MAC_OLD_PARTITION_MAGIC);
 
102
}
 
103
 
96
104
 
97
105
char *
98
106
pttype(char *device)
114
122
                        type = "AIX";
115
123
                else if (dos_parttable(buf))
116
124
                        type = "DOS";
 
125
                else if (mac_parttable(buf))
 
126
                        type = "Mac";
117
127
        }
118
128
 
119
129
        if (fd >= 0)