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

« back to all changes in this revision

Viewing changes to repair/agheader.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
 
46
46
 
47
47
        if (INT_GET(agf->agf_magicnum, ARCH_CONVERT) != XFS_AGF_MAGIC)  {
48
48
                retval = XR_AG_AGF;
49
 
                do_warn("bad magic # 0x%x for agf %d\n", INT_GET(agf->agf_magicnum, ARCH_CONVERT), i);
 
49
                do_warn(_("bad magic # 0x%x for agf %d\n"),
 
50
                        INT_GET(agf->agf_magicnum, ARCH_CONVERT), i);
50
51
 
51
52
                if (!no_modify)
52
53
                        INT_SET(agf->agf_magicnum, ARCH_CONVERT, XFS_AGF_MAGIC);
54
55
 
55
56
        if (!XFS_AGF_GOOD_VERSION(INT_GET(agf->agf_versionnum, ARCH_CONVERT)))  {
56
57
                retval = XR_AG_AGF;
57
 
                do_warn("bad version # %d for agf %d\n",
 
58
                do_warn(_("bad version # %d for agf %d\n"),
58
59
                        INT_GET(agf->agf_versionnum, ARCH_CONVERT), i);
59
60
 
60
61
                if (!no_modify)
61
 
                        INT_SET(agf->agf_versionnum, ARCH_CONVERT, XFS_AGF_VERSION);
 
62
                        INT_SET(agf->agf_versionnum, ARCH_CONVERT,
 
63
                                XFS_AGF_VERSION);
62
64
        }
63
65
 
64
66
        if (INT_GET(agf->agf_seqno, ARCH_CONVERT) != i)  {
65
67
                retval = XR_AG_AGF;
66
 
                do_warn("bad sequence # %d for agf %d\n", INT_GET(agf->agf_seqno, ARCH_CONVERT), i);
 
68
                do_warn(_("bad sequence # %d for agf %d\n"),
 
69
                        INT_GET(agf->agf_seqno, ARCH_CONVERT), i);
67
70
 
68
71
                if (!no_modify)
69
72
                        INT_SET(agf->agf_seqno, ARCH_CONVERT, i);
72
75
        if (INT_GET(agf->agf_length, ARCH_CONVERT) != mp->m_sb.sb_agblocks)  {
73
76
                if (i != mp->m_sb.sb_agcount - 1)  {
74
77
                        retval = XR_AG_AGF;
75
 
                        do_warn("bad length %d for agf %d, should be %d\n",
76
 
                                INT_GET(agf->agf_length, ARCH_CONVERT), i, mp->m_sb.sb_agblocks);
 
78
                        do_warn(_("bad length %d for agf %d, should be %d\n"),
 
79
                                INT_GET(agf->agf_length, ARCH_CONVERT), i,
 
80
                                mp->m_sb.sb_agblocks);
77
81
                        if (!no_modify)
78
 
                                INT_SET(agf->agf_length, ARCH_CONVERT, mp->m_sb.sb_agblocks);
 
82
                                INT_SET(agf->agf_length, ARCH_CONVERT,
 
83
                                        mp->m_sb.sb_agblocks);
79
84
                } else  {
80
85
                        agblocks = mp->m_sb.sb_dblocks -
81
86
                                (xfs_drfsbno_t) mp->m_sb.sb_agblocks * i;
83
88
                        if (INT_GET(agf->agf_length, ARCH_CONVERT) != agblocks)  {
84
89
                                retval = XR_AG_AGF;
85
90
                                do_warn(
86
 
                        "bad length %d for agf %d, should be %llu\n",
87
 
                                        INT_GET(agf->agf_length, ARCH_CONVERT), i, agblocks);
 
91
                        _("bad length %d for agf %d, should be %llu\n"),
 
92
                                        INT_GET(agf->agf_length, ARCH_CONVERT),
 
93
                                                i, agblocks);
88
94
                                if (!no_modify)
89
 
                                        INT_SET(agf->agf_length, ARCH_CONVERT, (xfs_agblock_t) agblocks);
 
95
                                        INT_SET(agf->agf_length, ARCH_CONVERT,
 
96
                                                (xfs_agblock_t) agblocks);
90
97
                        }
91
98
                }
92
99
        }
95
102
         * check first/last AGF fields.  if need be, lose the free
96
103
         * space in the AGFL, we'll reclaim it later.
97
104
         */
98
 
        if (INT_GET(agf->agf_flfirst, ARCH_CONVERT) >= XFS_AGFL_SIZE)  {
99
 
                do_warn("flfirst %d in agf %d too large (max = %d)\n",
100
 
                        INT_GET(agf->agf_flfirst, ARCH_CONVERT), i, XFS_AGFL_SIZE);
 
105
        if (INT_GET(agf->agf_flfirst, ARCH_CONVERT) >= XFS_AGFL_SIZE(mp))  {
 
106
                do_warn(_("flfirst %d in agf %d too large (max = %d)\n"),
 
107
                        INT_GET(agf->agf_flfirst, ARCH_CONVERT),
 
108
                        i, XFS_AGFL_SIZE(mp));
101
109
                if (!no_modify)
102
110
                        INT_ZERO(agf->agf_flfirst, ARCH_CONVERT);
103
111
        }
104
112
 
105
 
        if (INT_GET(agf->agf_fllast, ARCH_CONVERT) >= XFS_AGFL_SIZE)  {
106
 
                do_warn("fllast %d in agf %d too large (max = %d)\n",
107
 
                        INT_GET(agf->agf_fllast, ARCH_CONVERT), i, XFS_AGFL_SIZE);
 
113
        if (INT_GET(agf->agf_fllast, ARCH_CONVERT) >= XFS_AGFL_SIZE(mp))  {
 
114
                do_warn(_("fllast %d in agf %d too large (max = %d)\n"),
 
115
                        INT_GET(agf->agf_fllast, ARCH_CONVERT),
 
116
                        i, XFS_AGFL_SIZE(mp));
108
117
                if (!no_modify)
109
118
                        INT_ZERO(agf->agf_fllast, ARCH_CONVERT);
110
119
        }
124
133
 
125
134
        if (INT_GET(agi->agi_magicnum, ARCH_CONVERT) != XFS_AGI_MAGIC)  {
126
135
                retval = XR_AG_AGI;
127
 
                do_warn("bad magic # 0x%x for agi %d\n", INT_GET(agi->agi_magicnum, ARCH_CONVERT), i);
 
136
                do_warn(_("bad magic # 0x%x for agi %d\n"),
 
137
                        INT_GET(agi->agi_magicnum, ARCH_CONVERT), i);
128
138
 
129
139
                if (!no_modify)
130
140
                        INT_SET(agi->agi_magicnum, ARCH_CONVERT, XFS_AGI_MAGIC);
132
142
 
133
143
        if (!XFS_AGI_GOOD_VERSION(INT_GET(agi->agi_versionnum, ARCH_CONVERT)))  {
134
144
                retval = XR_AG_AGI;
135
 
                do_warn("bad version # %d for agi %d\n",
 
145
                do_warn(_("bad version # %d for agi %d\n"),
136
146
                        INT_GET(agi->agi_versionnum, ARCH_CONVERT), i);
137
147
 
138
148
                if (!no_modify)
139
 
                        INT_SET(agi->agi_versionnum, ARCH_CONVERT, XFS_AGI_VERSION);
 
149
                        INT_SET(agi->agi_versionnum, ARCH_CONVERT,
 
150
                                XFS_AGI_VERSION);
140
151
        }
141
152
 
142
153
        if (INT_GET(agi->agi_seqno, ARCH_CONVERT) != i)  {
143
154
                retval = XR_AG_AGI;
144
 
                do_warn("bad sequence # %d for agi %d\n", INT_GET(agi->agi_seqno, ARCH_CONVERT), i);
 
155
                do_warn(_("bad sequence # %d for agi %d\n"),
 
156
                        INT_GET(agi->agi_seqno, ARCH_CONVERT), i);
145
157
 
146
158
                if (!no_modify)
147
159
                        INT_SET(agi->agi_seqno, ARCH_CONVERT, i);
150
162
        if (INT_GET(agi->agi_length, ARCH_CONVERT) != mp->m_sb.sb_agblocks)  {
151
163
                if (i != mp->m_sb.sb_agcount - 1)  {
152
164
                        retval = XR_AG_AGI;
153
 
                        do_warn("bad length # %d for agi %d, should be %d\n",
154
 
                                INT_GET(agi->agi_length, ARCH_CONVERT), i, mp->m_sb.sb_agblocks);
 
165
                        do_warn(_("bad length # %d for agi %d, should be %d\n"),
 
166
                                INT_GET(agi->agi_length, ARCH_CONVERT), i,
 
167
                                        mp->m_sb.sb_agblocks);
155
168
                        if (!no_modify)
156
 
                                INT_SET(agi->agi_length, ARCH_CONVERT, mp->m_sb.sb_agblocks);
 
169
                                INT_SET(agi->agi_length, ARCH_CONVERT,
 
170
                                        mp->m_sb.sb_agblocks);
157
171
                } else  {
158
172
                        agblocks = mp->m_sb.sb_dblocks -
159
173
                                (xfs_drfsbno_t) mp->m_sb.sb_agblocks * i;
161
175
                        if (INT_GET(agi->agi_length, ARCH_CONVERT) != agblocks)  {
162
176
                                retval = XR_AG_AGI;
163
177
                                do_warn(
164
 
                        "bad length # %d for agi %d, should be %llu\n",
165
 
                                        INT_GET(agi->agi_length, ARCH_CONVERT), i, agblocks);
 
178
                        _("bad length # %d for agi %d, should be %llu\n"),
 
179
                                        INT_GET(agi->agi_length, ARCH_CONVERT),
 
180
                                                i, agblocks);
166
181
                                if (!no_modify)
167
 
                                        INT_SET(agi->agi_length, ARCH_CONVERT, (xfs_agblock_t) agblocks);
 
182
                                        INT_SET(agi->agi_length, ARCH_CONVERT,
 
183
                                                (xfs_agblock_t) agblocks);
168
184
                        }
169
185
                }
170
186
        }
209
225
 * zero and the shared version bit should be cleared for
210
226
 * current mkfs's.
211
227
 *
212
 
 * And everything else in the buffer beyond either sb_width
213
 
 * or sb_dirblklog (v2 dirs) should be zeroed.
 
228
 * And everything else in the buffer beyond either sb_width,
 
229
 * sb_dirblklog (v2 dirs), or sb_logsectsize can be zeroed.
 
230
 *
 
231
 * Note: contrary to the name, this routine is called for all
 
232
 * superblocks, not just the secondary superblocks.
214
233
 */
215
234
int
216
235
secondary_sb_wack(xfs_mount_t *mp, xfs_buf_t *sbuf, xfs_sb_t *sb,
235
254
            (sb->sb_versionnum & XR_GOOD_SECSB_VNMASK) == 0 ||
236
255
            sb->sb_versionnum < XFS_SB_VERSION_4)  {
237
256
                /*
238
 
                 * check for garbage beyond the last field set by the
239
 
                 * pre-6.5 mkfs's.  Don't blindly use sizeof(sb).
 
257
                 * Check for garbage beyond the last field.
240
258
                 * Use field addresses instead so this code will still
241
259
                 * work against older filesystems when the superblock
242
260
                 * gets rev'ed again with new fields appended.
243
261
                 */
244
 
                if (XFS_SB_VERSION_HASDIRV2(sb))
 
262
                if (XFS_SB_VERSION_HASLOGV2(sb))
 
263
                        size = (__psint_t)&sb->sb_logsunit
 
264
                                + sizeof(sb->sb_logsunit) - (__psint_t)sb;
 
265
                else if (XFS_SB_VERSION_HASSECTOR(sb))
 
266
                        size = (__psint_t)&sb->sb_logsectsize
 
267
                                + sizeof(sb->sb_logsectsize) - (__psint_t)sb;
 
268
                else if (XFS_SB_VERSION_HASDIRV2(sb))
245
269
                        size = (__psint_t)&sb->sb_dirblklog
246
270
                                + sizeof(sb->sb_dirblklog) - (__psint_t)sb;
247
271
                else
260
284
                        rval |= XR_AG_SB_SEC;
261
285
                        if (!no_modify)  {
262
286
                                do_warn(
263
 
                "zeroing unused portion of secondary superblock %d sector\n",
264
 
                                        i);
 
287
                _("zeroing unused portion of %s superblock (AG #%u)\n"),
 
288
                                        !i ? _("primary") : _("secondary"), i);
265
289
                                bzero((void *)((__psint_t)sb + size),
266
290
                                        mp->m_sb.sb_sectsize - size);
267
291
                        } else
268
292
                                do_warn(
269
 
                "would zero unused portion of secondary superblock %d sector\n",
270
 
                                        i);
 
293
                _("would zero unused portion of %s superblock (AG #%u)\n"),
 
294
                                        !i ? _("primary") : _("secondary"), i);
271
295
                }
272
296
        }
273
297
 
285
309
                        sb->sb_flags = 0;
286
310
                if (sb->sb_versionnum & XR_PART_SECSB_VNMASK || !do_bzero)  {
287
311
                        rval |= XR_AG_SB;
288
 
                        do_warn("bad flags field in superblock %d\n", i);
 
312
                        do_warn(_("bad flags field in superblock %d\n"), i);
289
313
                } else
290
314
                        rval |= XR_AG_SB_SEC;
291
315
        }
302
326
                if (sb->sb_versionnum & XR_PART_SECSB_VNMASK || !do_bzero)  {
303
327
                        rval |= XR_AG_SB;
304
328
                        do_warn(
305
 
                        "non-null user quota inode field in superblock %d\n",
 
329
                _("non-null user quota inode field in superblock %d\n"),
306
330
                                i);
 
331
 
307
332
                } else
308
333
                        rval |= XR_AG_SB_SEC;
309
334
        }
314
339
                if (sb->sb_versionnum & XR_PART_SECSB_VNMASK || !do_bzero)  {
315
340
                        rval |= XR_AG_SB;
316
341
                        do_warn(
317
 
                        "non-null group quota inode field in superblock %d\n",
 
342
                _("non-null group quota inode field in superblock %d\n"),
318
343
                                i);
 
344
 
319
345
                } else
320
346
                        rval |= XR_AG_SB_SEC;
321
347
        }
325
351
                        sb->sb_qflags = 0;
326
352
                if (sb->sb_versionnum & XR_PART_SECSB_VNMASK || !do_bzero)  {
327
353
                        rval |= XR_AG_SB;
328
 
                        do_warn("non-null quota flags in superblock %d\n", i);
 
354
                        do_warn(_("non-null quota flags in superblock %d\n"),
 
355
                                i);
329
356
                } else
330
357
                        rval |= XR_AG_SB_SEC;
331
358
        }
341
368
                        sb->sb_shared_vn = 0;
342
369
                if (sb->sb_versionnum & XR_PART_SECSB_VNMASK || !do_bzero)  {
343
370
                        rval |= XR_AG_SB;
344
 
                        do_warn("bad shared version number in superblock %d\n",
 
371
                        do_warn(
 
372
                _("bad shared version number in superblock %d\n"),
345
373
                                i);
346
374
                } else
347
375
                        rval |= XR_AG_SB_SEC;
352
380
                        sb->sb_inoalignmt = 0;
353
381
                if (sb->sb_versionnum & XR_PART_SECSB_VNMASK || !do_bzero)  {
354
382
                        rval |= XR_AG_SB;
355
 
                        do_warn("bad inode alignment field in superblock %d\n",
 
383
                        do_warn(
 
384
                _("bad inode alignment field in superblock %d\n"),
356
385
                                i);
357
386
                } else
358
387
                        rval |= XR_AG_SB_SEC;
365
394
                if (sb->sb_versionnum & XR_GOOD_SECSB_VNMASK || !do_bzero)  {
366
395
                        rval |= XR_AG_SB;
367
396
                        do_warn(
368
 
                        "bad stripe unit/width fields in superblock %d\n",
 
397
                _("bad stripe unit/width fields in superblock %d\n"),
 
398
                                i);
 
399
                } else
 
400
                        rval |= XR_AG_SB_SEC;
 
401
        }
 
402
 
 
403
        if (!XFS_SB_VERSION_HASSECTOR(sb) &&
 
404
            (sb->sb_sectsize != BBSIZE || sb->sb_sectlog != BBSHIFT ||
 
405
             sb->sb_logsectsize != 0 || sb->sb_logsectlog != 0))  {
 
406
                if (!no_modify)  {
 
407
                        sb->sb_sectsize = BBSIZE;
 
408
                        sb->sb_sectlog = BBSHIFT;
 
409
                        sb->sb_logsectsize = 0;
 
410
                        sb->sb_logsectlog = 0;
 
411
                }
 
412
                if (sb->sb_versionnum & XR_GOOD_SECSB_VNMASK || !do_bzero)  {
 
413
                        rval |= XR_AG_SB;
 
414
                        do_warn(
 
415
                _("bad log/data device sector size fields in superblock %d\n"),
369
416
                                i);
370
417
                } else
371
418
                        rval |= XR_AG_SB_SEC;
396
443
        status = verify_sb(sb, (i == 0));
397
444
 
398
445
        if (status != XR_OK)  {
399
 
                do_warn("bad on-disk superblock %d - %s\n",
 
446
                do_warn(_("bad on-disk superblock %d - %s\n"),
400
447
                        i, err_string(status));
401
448
        }
402
449
 
403
450
        status_sb = compare_sb(mp, sb);
404
451
 
405
452
        if (status_sb != XR_OK)  {
406
 
                do_warn("primary and secondary superblock %d conflict - %s\n",
 
453
                do_warn(_("primary/secondary superblock %d conflict - %s\n"),
407
454
                        i, err_string(status_sb));
408
455
        }
409
456