~ubuntu-branches/ubuntu/utopic/xfsprogs/utopic-proposed

« back to all changes in this revision

Viewing changes to repair/sb.c

  • Committer: Bazaar Package Importer
  • Author(s): Nathan Scott
  • Date: 2009-05-06 11:29:18 UTC
  • mfrom: (8.1.1 jaunty)
  • Revision ID: james.westby@ubuntu.com-20090506112918-uzoyzcp90rtr8td7
Tags: 3.0.2
New bugfix release

Show diffs side-by-side

added added

removed removed

Lines of Context:
65
65
         * secondaries and cannot be changed at run time in
66
66
         * the primary superblock
67
67
         */
68
 
        if (XFS_SB_VERSION_HASDALIGN(source))
69
 
                XFS_SB_VERSION_ADDDALIGN(dest);
70
 
        if (XFS_SB_VERSION_HASEXTFLGBIT(source))
71
 
                XFS_SB_VERSION_ADDEXTFLGBIT(dest);
 
68
        if (xfs_sb_version_hasdalign(source))
 
69
                dest->sb_versionnum |= XFS_SB_VERSION_DALIGNBIT;
 
70
        if (xfs_sb_version_hasextflgbit(source))
 
71
                dest->sb_versionnum |= XFS_SB_VERSION_EXTFLGBIT;
72
72
 
73
73
        /*
74
74
         * these are all supposed to be zero or will get reset anyway
133
133
                 * we don't know how big the sectors really are.
134
134
                 */
135
135
                for (i = 0; !done && i < bsize; i += BBSIZE)  {
136
 
                        c_bufsb = (char *) sb + i;
137
 
                        libxfs_xlate_sb(c_bufsb, &bufsb, 1, XFS_SB_ALL_BITS);
 
136
                        c_bufsb = (char *)sb + i;
 
137
                        libxfs_sb_from_disk(&bufsb, (xfs_dsb_t *)c_bufsb);
138
138
 
139
139
                        if (verify_sb(&bufsb, 0) != XR_OK)
140
140
                                continue;
233
233
        if (sb->sb_magicnum != XFS_SB_MAGIC)
234
234
                return(XR_BAD_MAGIC);
235
235
 
236
 
        if (!XFS_SB_GOOD_VERSION(sb))
 
236
        if (!xfs_sb_good_version(sb))
237
237
                return(XR_BAD_VERSION);
238
238
 
239
239
        /* does sb think mkfs really finished ? */
298
298
        if (i != sb->sb_sectlog)
299
299
                return(XR_BAD_SECT_SIZE_DATA);
300
300
 
301
 
        if (XFS_SB_VERSION_HASSECTOR(sb))  {
 
301
        if (xfs_sb_version_hassector(sb))  {
302
302
 
303
303
                /* check to make sure log sector is legal 2^N, 9 <= N <= 15 */
304
304
 
361
361
        /*
362
362
         * verify correctness of inode alignment if it's there
363
363
         */
364
 
        if (XFS_SB_VERSION_HASALIGN(sb))  {
 
364
        if (xfs_sb_version_hasalign(sb))  {
365
365
                align = calc_ino_align(sb);
366
366
 
367
367
                if (align != sb->sb_inoalignmt)
377
377
        /*
378
378
         * verify stripe alignment fields if present
379
379
         */
380
 
        if (XFS_SB_VERSION_HASDALIGN(sb)) {
 
380
        if (xfs_sb_version_hasdalign(sb)) {
381
381
                if ((!sb->sb_unit && sb->sb_width) ||
382
382
                    (sb->sb_unit && sb->sb_agblocks % sb->sb_unit))
383
383
                        return(XR_BAD_SB_UNIT);
389
389
        /*
390
390
         * if shared bit is set, verify that the version number is sane
391
391
         */
392
 
        if (XFS_SB_VERSION_HASSHARED(sb))  {
 
392
        if (xfs_sb_version_hasshared(sb))  {
393
393
                if (sb->sb_shared_vn > XFS_SB_MAX_SHARED_VN)
394
394
                        return(XR_BAD_SVN);
395
395
        }
414
414
                         * shared version # and inode alignment fields
415
415
                         * should be valid
416
416
                         */
417
 
                        if (sb->sb_shared_vn && !XFS_SB_VERSION_HASSHARED(sb))
 
417
                        if (sb->sb_shared_vn && !xfs_sb_version_hasshared(sb))
418
418
                                return(XR_BAD_SVN);
419
 
                        if (sb->sb_inoalignmt && !XFS_SB_VERSION_HASALIGN(sb))
 
419
                        if (sb->sb_inoalignmt && !xfs_sb_version_hasalign(sb))
420
420
                                return(XR_BAD_INO_ALIGN);
421
421
                }
422
422
                if ((!pre_65_beta &&
426
426
                        /*
427
427
                         * stripe alignment values should be valid
428
428
                         */
429
 
                        if (sb->sb_unit && !XFS_SB_VERSION_HASDALIGN(sb))
 
429
                        if (sb->sb_unit && !xfs_sb_version_hasdalign(sb))
430
430
                                return(XR_BAD_SB_UNIT);
431
 
                        if (sb->sb_width && !XFS_SB_VERSION_HASDALIGN(sb))
 
431
                        if (sb->sb_width && !xfs_sb_version_hasdalign(sb))
432
432
                                return(XR_BAD_SB_WIDTH);
433
433
                }
434
434
 
447
447
void
448
448
write_primary_sb(xfs_sb_t *sbp, int size)
449
449
{
450
 
        void *buf;
 
450
        xfs_dsb_t       *buf;
451
451
 
452
452
        if (no_modify)
453
453
                return;
454
454
 
455
 
        if ((buf = memalign(libxfs_device_alignment(), size)) == NULL) {
 
455
        buf = memalign(libxfs_device_alignment(), size);
 
456
        if (buf == NULL) {
456
457
                do_error(_("failed to memalign superblock buffer\n"));
457
458
                return;
458
459
        }
463
464
                do_error(_("couldn't seek to offset 0 in filesystem\n"));
464
465
        }
465
466
 
466
 
        libxfs_xlate_sb(buf, sbp, -1, XFS_SB_ALL_BITS);
 
467
        
 
468
        libxfs_sb_to_disk(buf, sbp, XFS_SB_ALL_BITS);
467
469
 
468
470
        if (write(x.dfd, buf, size) != size) {
469
471
                free(buf);
480
482
get_sb(xfs_sb_t *sbp, xfs_off_t off, int size, xfs_agnumber_t agno)
481
483
{
482
484
        int error, rval;
483
 
        void *buf;
 
485
        xfs_dsb_t *buf;
484
486
 
485
 
        if ((buf = memalign(libxfs_device_alignment(), size)) == NULL) {
 
487
        buf = memalign(libxfs_device_alignment(), size);
 
488
        if (buf == NULL) {
486
489
                do_error(
487
490
        _("error reading superblock %u -- failed to memalign buffer\n"),
488
491
                        agno, off);
506
509
                        off, size, agno, rval);
507
510
                do_error("%s\n", strerror(error));
508
511
        }
509
 
        libxfs_xlate_sb(buf, sbp, 1, XFS_SB_ALL_BITS);
 
512
        libxfs_sb_from_disk(sbp, buf);
510
513
        free(buf);
511
514
 
512
515
        return (verify_sb(sbp, 0));
597
600
        geo->sb_sectsize = sbp->sb_sectsize;
598
601
        geo->sb_inodesize = sbp->sb_inodesize;
599
602
 
600
 
        if (XFS_SB_VERSION_HASALIGN(sbp))
 
603
        if (xfs_sb_version_hasalign(sbp))
601
604
                geo->sb_ialignbit = 1;
602
605
 
603
 
        if (XFS_SB_VERSION_HASSHARED(sbp) ||
 
606
        if (xfs_sb_version_hasshared(sbp) ||
604
607
            sbp->sb_versionnum & XR_PART_SECSB_VNMASK)
605
608
                geo->sb_sharedbit = 1;
606
609
 
607
 
        if (XFS_SB_VERSION_HASDALIGN(sbp))
 
610
        if (xfs_sb_version_hasdalign(sbp))
608
611
                geo->sb_salignbit = 1;
609
612
 
610
 
        if (XFS_SB_VERSION_HASEXTFLGBIT(sbp))
 
613
        if (xfs_sb_version_hasextflgbit(sbp))
611
614
                geo->sb_extflgbit = 1;
612
615
 
613
616
        /*
629
632
                geo->sb_inoalignmt = sbp->sb_inoalignmt;
630
633
 
631
634
        if ((!pre_65_beta && (sbp->sb_versionnum & XR_GOOD_SECSB_VNMASK)) ||
632
 
            (pre_65_beta && XFS_SB_VERSION_HASDALIGN(sbp))) {
 
635
            (pre_65_beta && xfs_sb_version_hasdalign(sbp))) {
633
636
                geo->sb_unit = sbp->sb_unit;
634
637
                geo->sb_width = sbp->sb_width;
635
638
        }
757
760
        switch (num_sbs)  {
758
761
        case 2:
759
762
                /*
760
 
                 * all them have to be right.  if not, report geometry
761
 
                 * and get out unless force option is in effect (-F)
 
763
                 * If we only have two allocation groups, and the superblock
 
764
                 * in the second allocation group differs from the primary
 
765
                 * superblock we can't verify the geometry information.
 
766
                 * Warn the user about this situation and get out unless
 
767
                 * explicitly overridden.
762
768
                 */
763
769
                if (current->refs != 2)  {
764
770
                        if (!force_geo)  {
765
771
                                do_warn(
766
 
        _("Only two AGs detected and they do not match - cannot proceed.\n"));
 
772
        _("Only two AGs detected and they do not match - "
 
773
          "cannot validate filesystem geometry.\n"
 
774
          "Use the -o force_geometry option to proceed.\n"));
767
775
                                exit(1);
768
776
                        }
769
777
                }
770
 
                break;
 
778
                goto out_free_list;
771
779
        case 1:
772
780
                /*
773
 
                 * just report the geometry info and get out.
774
 
                 * refuse to run further unless the force (-F)
775
 
                 * option is in effect.
 
781
                 * If we only have a single allocation group there is no
 
782
                 * secondary superblock that we can use to verify the geometry
 
783
                 * information.  Warn the user about this situation and get
 
784
                 * out unless explicitly overridden.
776
785
                 */
777
786
                if (!force_geo)  {
778
 
                        do_warn(_("Only one AG detected - cannot proceed.\n"));
 
787
                        do_warn(
 
788
        _("Only one AG detected - "
 
789
          "cannot validate filesystem geometry.\n"
 
790
          "Use the -o force_geometry option to proceed.\n"));
779
791
                        exit(1);
780
792
                }
 
793
                goto out_free_list;
781
794
        default:
782
795
                /*
783
796
                 * at least half of the probed superblocks have
817
830
                sb_width = sb->sb_width;
818
831
        }
819
832
 
 
833
out_free_list:
820
834
        free_geo(list);
821
835
out:
822
836
        free(sb);