~psusi/ubuntu/precise/dmraid/fix-gpt

« back to all changes in this revision

Viewing changes to 1.0.0.rc15/lib/format/ddf/ddf1_lib.c

  • Committer: Bazaar Package Importer
  • Author(s): Giuseppe Iuculano, 6af052c
  • Date: 2009-03-25 22:34:59 UTC
  • mfrom: (2.1.9 sid)
  • mto: (2.4.1 squeeze)
  • mto: This revision was merged to the branch mainline in revision 39.
  • Revision ID: james.westby@ubuntu.com-20090325223459-y54f0rmxem7htn6r
Tags: 1.0.0.rc15-6
[6af052c] Remove 15_isw_incorrect_status_fix.patch, it causes a
segfault. (Closes: #521104)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * SNIA DDF1 v1.0 metadata format handler.
 
3
 *
 
4
 * Copyright (C) 2005-2006 IBM, All rights reserved.
 
5
 * Written by Darrick Wong <djwong@us.ibm.com>
 
6
 *
 
7
 * Copyright (C) 2006 Heinz Mauelshagen, Red Hat GmbH
 
8
 *                    All rights reserved.
 
9
 *
 
10
 * See file LICENSE at the top of this source tree for license information.
 
11
 */
 
12
 
 
13
#include "internal.h"
 
14
 
 
15
#define FORMAT_HANDLER
 
16
#include "ddf1.h"
 
17
#include "ddf1_lib.h"
 
18
 
 
19
#define DM_BYTEORDER_SWAB
 
20
#include <datastruct/byteorder.h>
 
21
 
 
22
/* Figure out what endian conversions we need */
 
23
int
 
24
ddf1_endianness(struct lib_context *lc, struct ddf1 *ddf1)
 
25
{
 
26
        uint8_t *ptr = (uint8_t *) & ddf1->anchor.signature;
 
27
 
 
28
        if (ptr[0] == 0xDE && ptr[1] == 0x11)
 
29
                return BIG_ENDIAN;
 
30
        else if (ptr[0] == 0x11 && ptr[1] == 0xDE)
 
31
                return LITTLE_ENDIAN;
 
32
        else
 
33
                LOG_ERR(lc, -EINVAL, "Can't figure out endianness!");
 
34
}
 
35
 
 
36
/* Find the beginning of all DDF metadata */
 
37
uint64_t
 
38
ddf1_beginning(struct ddf1 *ddf1)
 
39
{
 
40
        uint64_t start;
 
41
        struct ddf1_header *h = &ddf1->anchor;
 
42
 
 
43
        start = ddf1->anchor_offset;
 
44
        if (h->primary_table_lba < start)
 
45
                start = h->primary_table_lba;
 
46
        if (h->secondary_table_lba < start)
 
47
                start = h->secondary_table_lba;
 
48
#ifdef WORKSPACE_IS_PART_OF_DDF
 
49
        if (ddf1->primary->workspace_lba < start)
 
50
                start = ddf1->primary->workspace_lba;
 
51
#endif
 
52
 
 
53
        return start;
 
54
}
 
55
 
 
56
/* Helper for CR_OFF */
 
57
uint16_t
 
58
ddf1_cr_off_maxpds_helper(struct ddf1 * ddf1)
 
59
{
 
60
        struct ddf1_header *h = ddf1->primary;
 
61
 
 
62
        /* The 0xFFFF nonsense is a weird Adaptec quirk */
 
63
//      bz211016
 
64
//      return (h->max_primary_elements == 0xFFFF && ddf1->adaptec_mode) ?
 
65
        return (h->max_primary_elements == 0xFFFF) ?
 
66
                h->max_phys_drives : h->max_primary_elements;
 
67
}
 
68
 
 
69
/* Process DDF1 records depending on type */
 
70
int
 
71
ddf1_process_records(struct lib_context *lc, struct dev_info *di,
 
72
                     struct ddf1_record_handler *handler,
 
73
                     struct ddf1 *ddf1, int in_cpu_format)
 
74
{
 
75
        unsigned int i, cfgs = NUM_CONFIG_ENTRIES(ddf1);
 
76
        uint32_t x;
 
77
 
 
78
        for (i = 0; i < cfgs; i++) {
 
79
                x = *((uint32_t *) CR(ddf1, i));
 
80
                if (!in_cpu_format && BYTE_ORDER != ddf1->disk_format)
 
81
                        CVT32(x);
 
82
 
 
83
                switch (x) {
 
84
                case DDF1_VD_CONFIG_REC:
 
85
                        if (!handler->vd(lc, di, ddf1, i))
 
86
                                return 0;
 
87
 
 
88
                        break;
 
89
 
 
90
                case DDF1_SPARE_REC:
 
91
                        if (!handler->spare(lc, di, ddf1, i))
 
92
                                return 0;
 
93
 
 
94
                        break;
 
95
 
 
96
                case 0: /* Adaptec puts zero in this field??? */
 
97
                case DDF1_INVALID:
 
98
                        break;
 
99
 
 
100
                default:
 
101
                        log_warn(lc, "%s: Unknown config record %d.",
 
102
                                 di->path, x);
 
103
                }
 
104
        }
 
105
 
 
106
        return 1;
 
107
}