~daniel-mehrmann/e2fsprogs/master

« back to all changes in this revision

Viewing changes to lib/ext2fs/mmp.c

  • Committer: Package Import Robot
  • Author(s): Dmitrijs Ledkovs
  • Date: 2012-06-14 13:01:21 UTC
  • mfrom: (8.4.18 sid)
  • Revision ID: package-import@ubuntu.com-20120614130121-t2gct0d09jepx0y6
Tags: 1.42.4-3ubuntu1
* Merge from Debian unstable (LP: #978012), remainging changes:
  - debian/control.in: 
      Build-depend on gettext:any instead of on gettext for (cross-building)
      Drop build dependency on dc, which hasn't been needed for some time.
      Update maintainer field.
  - debian/rules:
      Block pkg-create-dbgsym from operating on this package.
      Build without dietlibc-dev, which is in universe 
  - debian/control:
      Regenerate with ./debian/rules debian/control

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
#include "ext2fs/ext2_fs.h"
28
28
#include "ext2fs/ext2fs.h"
29
29
 
30
 
static int mmp_pagesize(void)
31
 
{
32
 
#ifdef _SC_PAGESIZE
33
 
        int sysval = sysconf(_SC_PAGESIZE);
34
 
        if (sysval > 0)
35
 
                return sysval;
36
 
#endif /* _SC_PAGESIZE */
37
 
#ifdef HAVE_GETPAGESIZE
38
 
        return getpagesize();
39
 
#else
40
 
        return 4096;
41
 
#endif
42
 
}
43
 
 
44
30
#ifndef O_DIRECT
45
31
#define O_DIRECT 0
46
32
#endif
54
40
            (mmp_blk >= fs->super->s_blocks_count))
55
41
                return EXT2_ET_MMP_BAD_BLOCK;
56
42
 
57
 
        if (fs->mmp_cmp == NULL) {
58
 
                /* O_DIRECT in linux 2.4: page aligned
59
 
                 * O_DIRECT in linux 2.6: sector aligned
60
 
                 * A filesystem cannot be created with blocksize < sector size,
61
 
                 * or with blocksize > page_size. */
62
 
                int bufsize = fs->blocksize;
63
 
 
64
 
                if (bufsize < mmp_pagesize())
65
 
                        bufsize = mmp_pagesize();
66
 
                retval = ext2fs_get_memalign(bufsize, bufsize, &fs->mmp_cmp);
67
 
                if (retval)
68
 
                        return retval;
69
 
        }
70
 
 
71
43
        /* ext2fs_open() reserves fd0,1,2 to avoid stdio collision, so checking
72
44
         * mmp_fd <= 0 is OK to validate that the fd is valid.  This opens its
73
45
         * own fd to read the MMP block to ensure that it is using O_DIRECT,
81
53
                }
82
54
        }
83
55
 
 
56
        if (fs->mmp_cmp == NULL) {
 
57
                int align = ext2fs_get_dio_alignment(fs->mmp_fd);
 
58
 
 
59
                retval = ext2fs_get_memalign(fs->blocksize, align,
 
60
                                             &fs->mmp_cmp);
 
61
                if (retval)
 
62
                        return retval;
 
63
        }
 
64
 
84
65
        if (ext2fs_llseek(fs->mmp_fd, mmp_blk * fs->blocksize, SEEK_SET) !=
85
66
            mmp_blk * fs->blocksize) {
86
67
                retval = EXT2_ET_LLSEEK_FAILED;