diff options
| author | ngkaho1234 <ngkaho1234@gmail.com> | 2015-11-15 17:25:38 +0800 |
|---|---|---|
| committer | gkostka <kostka.grzegorz@gmail.com> | 2015-11-23 17:05:47 +0100 |
| commit | 2b928635d2a1258edcee77b315a2e66f41c6fd45 (patch) | |
| tree | cc253e53f48234f4680be0d7103ace2f371cf968 | |
| parent | 8f81cab8ae1a5d77fefb69698e92fa0a1dd1cdb4 (diff) | |
ext4_journal: two changes below
- Add JBD_SUPERBLOCK_SIZE macro
- Add jbd_sb_read & jbd_sb_write
| -rw-r--r-- | lwext4/ext4_journal.c | 35 | ||||
| -rw-r--r-- | lwext4/ext4_types.h | 2 |
2 files changed, 37 insertions, 0 deletions
diff --git a/lwext4/ext4_journal.c b/lwext4/ext4_journal.c index 14b741d..e10e210 100644 --- a/lwext4/ext4_journal.c +++ b/lwext4/ext4_journal.c @@ -6,6 +6,7 @@ #include "ext4_config.h" #include "ext4_types.h" #include "ext4_fs.h" +#include "ext4_super.h" #include "ext4_errno.h" #include "ext4_blockdev.h" #include "ext4_crc32c.h" @@ -13,6 +14,40 @@ #include <string.h> +int jbd_inode_bmap(struct jbd_fs *jbd_fs, + ext4_lblk_t iblock, + ext4_fsblk_t *fblock); + +int jbd_sb_write(struct jbd_fs *jbd_fs, struct jbd_sb *s) +{ + int rc; + struct ext4_fs *fs = jbd_fs->inode_ref.fs; + uint64_t offset; + ext4_fsblk_t fblock; + rc = jbd_inode_bmap(jbd_fs, 0, &fblock); + if (rc != EOK) + return rc; + + offset = fblock * ext4_sb_get_block_size(&fs->sb); + return ext4_block_writebytes(fs->bdev, offset, s, + EXT4_SUPERBLOCK_SIZE); +} + +int jbd_sb_read(struct jbd_fs *jbd_fs, struct ext4_sblock *s) +{ + int rc; + struct ext4_fs *fs = jbd_fs->inode_ref.fs; + uint64_t offset; + ext4_fsblk_t fblock; + rc = jbd_inode_bmap(jbd_fs, 0, &fblock); + if (rc != EOK) + return rc; + + offset = fblock * ext4_sb_get_block_size(&fs->sb); + return ext4_block_readbytes(fs->bdev, offset, s, + EXT4_SUPERBLOCK_SIZE); +} + int jbd_get_fs(struct ext4_fs *fs, struct jbd_fs *jbd_fs) { diff --git a/lwext4/ext4_types.h b/lwext4/ext4_types.h index 0663ddc..fc576db 100644 --- a/lwext4/ext4_types.h +++ b/lwext4/ext4_types.h @@ -1049,6 +1049,8 @@ struct jbd_sb { /* 0x0400 */ }; +#define JBD_SUPERBLOCK_SIZE sizeof(struct jbd_sb) + #define JBD_HAS_COMPAT_FEATURE(jsb,mask) \ ((jsb)->header.blocktype >= to_be32(2) && \ ((jsb)->feature_compat & to_be32((mask)))) |
