Coccinelle release 0.2.5-rc3
[bpt/coccinelle.git] / tests / null_ver11.c
1 void udf_fill_spartable(struct super_block *sb, struct udf_sparing_data *sdata, int partlen)
2 {
3 Uint16 ident;
4 Uint32 spartable;
5 int i;
6 struct buffer_head *bh;
7 struct SparingTable *st;
8
9 for (i=0; i<4; i++)
10 {
11 if (!(spartable = sdata->s_spar_loc[i]))
12 continue;
13
14 bh = udf_read_tagged(sb, spartable, spartable, &ident);
15
16 if (!bh)
17 {
18 sdata->s_spar_loc[i] = 0;
19 continue;
20 }
21
22 if (ident == 0)
23 {
24 st = (struct SparingTable *)bh->b_data;
25 if (!strncmp(st->sparingIdent.ident, UDF_ID_SPARING, strlen(UDF_ID_SPARING)))
26 {
27 SparingEntry *se;
28 Uint16 rtl = le16_to_cpu(st->reallocationTableLen);
29 int index;
30
31 if (!sdata->s_spar_map)
32 {
33 int num = 1, mapsize;
34 sdata->s_spar_indexsize = 8;
35 while (rtl*sizeof(Uint32) >= (1 << sdata->s_spar_indexsize))
36 {
37 num ++;
38 sdata->s_spar_indexsize <<= 1;
39 }
40 mapsize = (rtl * sizeof(Uint32)) +
41 ((partlen/(1 << sdata->s_spar_pshift)) * sizeof(Uint8) * num);
42 sdata->s_spar_map = kmalloc(mapsize, GFP_KERNEL);
43 sdata->s_spar_remap.s_spar_remap32 = &sdata->s_spar_map[rtl];
44 memset(sdata->s_spar_map, 0xFF, mapsize);
45 }
46
47 index = sizeof(struct SparingTable);
48 for (i=0; i<rtl; i++)
49 {
50 if (index > sb->s_blocksize)
51 {
52 udf_release_data(bh);
53 bh = udf_tread(sb, ++spartable, sb->s_blocksize);
54 if (!bh)
55 {
56 sdata->s_spar_loc[i] = 0;
57 continue;
58 }
59 index = 0;
60 }
61 se = (SparingEntry *)&(bh->b_data[index]);
62 index += sizeof(SparingEntry);
63
64 if (sdata->s_spar_map[i] == 0xFFFFFFFF)
65 sdata->s_spar_map[i] = le32_to_cpu(se->mappedLocation);
66 else if (sdata->s_spar_map[i] != le32_to_cpu(se->mappedLocation))
67 {
68 udf_debug("Found conflicting Sparing Data (%d vs %d for entry %d)\n",
69 sdata->s_spar_map[i], le32_to_cpu(se->mappedLocation), i);
70 }
71
72 if (le32_to_cpu(se->origLocation) < 0xFFFFFFF0)
73 {
74 int packet = le32_to_cpu(se->origLocation) >> sdata->s_spar_pshift;
75 if (sdata->s_spar_indexsize == 8)
76 {
77 if (sdata->s_spar_remap.s_spar_remap8[packet] == 0xFF)
78 sdata->s_spar_remap.s_spar_remap8[packet] = i;
79 else if (sdata->s_spar_remap.s_spar_remap8[packet] != i)
80 {
81 udf_debug("Found conflicting Sparing Data (%d vs %d)\n",
82 sdata->s_spar_remap.s_spar_remap8[packet], i);
83 }
84 }
85 else if (sdata->s_spar_indexsize == 16)
86 {
87 if (sdata->s_spar_remap.s_spar_remap16[packet] == 0xFFFF)
88 sdata->s_spar_remap.s_spar_remap16[packet] = i;
89 else if (sdata->s_spar_remap.s_spar_remap16[packet] != i)
90 {
91 udf_debug("Found conflicting Sparing Data (%d vs %d)\n",
92 sdata->s_spar_remap.s_spar_remap16[packet], i);
93 }
94 }
95 else if (sdata->s_spar_indexsize == 32)
96 {
97 if (sdata->s_spar_remap.s_spar_remap32[packet] == 0xFFFFFFFF)
98 sdata->s_spar_remap.s_spar_remap32[packet] = i;
99 else if (sdata->s_spar_remap.s_spar_remap32[packet] != i)
100 {
101 udf_debug("Found conflicting Sparing Data (%d vs %d)\n",
102 sdata->s_spar_remap.s_spar_remap32[packet], i);
103 }
104 }
105 }
106 }
107 }
108 }
109 udf_release_data(bh);
110 }
111 }
112