函数源码

Linux Kernel

v5.5.9

Brick Technologies Co., Ltd

Source File:block\partitions\atari.c Create Date:2022-07-27 19:01:30
首页 Copyright©Brick

33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
int atari_partition(struct parsed_partitions *state)
{
    Sector sect;
    struct rootsector *rs;
    struct partition_info *pi;
    u32 extensect;
    u32 hd_size;
    int slot;
#ifdef ICD_PARTS
    int part_fmt = 0; /* 0:unknown, 1:AHDI, 2:ICD/Supra */
#endif
 
    /*
     * ATARI partition scheme supports 512 lba only.  If this is not
     * the case, bail early to avoid miscalculating hd_size.
     */
    if (bdev_logical_block_size(state->bdev) != 512)
        return 0;
 
    rs = read_part_sector(state, 0, §);
    if (!rs)
        return -1;
 
    /* Verify this is an Atari rootsector: */
    hd_size = state->bdev->bd_inode->i_size >> 9;
    if (!VALID_PARTITION(&rs->part[0], hd_size) &&
        !VALID_PARTITION(&rs->part[1], hd_size) &&
        !VALID_PARTITION(&rs->part[2], hd_size) &&
        !VALID_PARTITION(&rs->part[3], hd_size)) {
        /*
         * if there's no valid primary partition, assume that no Atari
         * format partition table (there's no reliable magic or the like
             * :-()
         */
        put_dev_sector(sect);
        return 0;
    }
 
    pi = &rs->part[0];
    strlcat(state->pp_buf, " AHDI", PAGE_SIZE);
    for (slot = 1; pi < &rs->part[4] && slot < state->limit; slot++, pi++) {
        struct rootsector *xrs;
        Sector sect2;
        ulong partsect;
 
        if ( !(pi->flg & 1) )
            continue;
        /* active partition */
        if (memcmp (pi->id, "XGM", 3) != 0) {
            /* we don't care about other id's */
            put_partition (state, slot, be32_to_cpu(pi->st),
                    be32_to_cpu(pi->siz));
            continue;
        }
        /* extension partition */
#ifdef ICD_PARTS
        part_fmt = 1;
#endif
        strlcat(state->pp_buf, " XGM<", PAGE_SIZE);
        partsect = extensect = be32_to_cpu(pi->st);
        while (1) {
            xrs = read_part_sector(state, partsect, §2);
            if (!xrs) {
                printk (" block %ld read failed\n", partsect);
                put_dev_sector(sect);
                return -1;
            }
 
            /* ++roman: sanity check: bit 0 of flg field must be set */
            if (!(xrs->part[0].flg & 1)) {
                printk( "\nFirst sub-partition in extended partition is not valid!\n" );
                put_dev_sector(sect2);
                break;
            }
 
            put_partition(state, slot,
                   partsect + be32_to_cpu(xrs->part[0].st),
                   be32_to_cpu(xrs->part[0].siz));
 
            if (!(xrs->part[1].flg & 1)) {
                /* end of linked partition list */
                put_dev_sector(sect2);
                break;
            }
            if (memcmp( xrs->part[1].id, "XGM", 3 ) != 0) {
                printk("\nID of extended partition is not XGM!\n");
                put_dev_sector(sect2);
                break;
            }
 
            partsect = be32_to_cpu(xrs->part[1].st) + extensect;
            put_dev_sector(sect2);
            if (++slot == state->limit) {
                printk( "\nMaximum number of partitions reached!\n" );
                break;
            }
        }
        strlcat(state->pp_buf, " >", PAGE_SIZE);
    }
#ifdef ICD_PARTS
    if ( part_fmt!=1 ) { /* no extended partitions -> test ICD-format */
        pi = &rs->icdpart[0];
        /* sanity check: no ICD format if first partition invalid */
        if (OK_id(pi->id)) {
            strlcat(state->pp_buf, " ICD<", PAGE_SIZE);
            for (; pi < &rs->icdpart[8] && slot < state->limit; slot++, pi++) {
                /* accept only GEM,BGM,RAW,LNX,SWP partitions */
                if (!((pi->flg & 1) && OK_id(pi->id)))
                    continue;
                part_fmt = 2;
                put_partition (state, slot,
                        be32_to_cpu(pi->st),
                        be32_to_cpu(pi->siz));
            }
            strlcat(state->pp_buf, " >", PAGE_SIZE);
        }
    }
#endif
    put_dev_sector(sect);
 
    strlcat(state->pp_buf, "\n", PAGE_SIZE);
 
    return 1;
}