123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508 |
- #include <linux/fs.h>
- #include <linux/buffer_head.h>
- #include "jfs_incore.h"
- #include "jfs_filsys.h"
- #include "jfs_superblock.h"
- #include "jfs_dmap.h"
- #include "jfs_imap.h"
- #include "jfs_metapage.h"
- #include "jfs_debug.h"
- static int chkSuper(struct super_block *);
- static int logMOUNT(struct super_block *sb);
- int jfs_mount(struct super_block *sb)
- {
- int rc = 0;
- struct jfs_sb_info *sbi = JFS_SBI(sb);
- struct inode *ipaimap = NULL;
- struct inode *ipaimap2 = NULL;
- struct inode *ipimap = NULL;
- struct inode *ipbmap = NULL;
-
- if ((rc = chkSuper(sb))) {
- goto errout20;
- }
- ipaimap = diReadSpecial(sb, AGGREGATE_I, 0);
- if (ipaimap == NULL) {
- jfs_err("jfs_mount: Failed to read AGGREGATE_I");
- rc = -EIO;
- goto errout20;
- }
- sbi->ipaimap = ipaimap;
- jfs_info("jfs_mount: ipaimap:0x%p", ipaimap);
-
- if ((rc = diMount(ipaimap))) {
- jfs_err("jfs_mount: diMount(ipaimap) failed w/rc = %d", rc);
- goto errout21;
- }
-
- ipbmap = diReadSpecial(sb, BMAP_I, 0);
- if (ipbmap == NULL) {
- rc = -EIO;
- goto errout22;
- }
- jfs_info("jfs_mount: ipbmap:0x%p", ipbmap);
- sbi->ipbmap = ipbmap;
-
- if ((rc = dbMount(ipbmap))) {
- jfs_err("jfs_mount: dbMount failed w/rc = %d", rc);
- goto errout22;
- }
-
- if ((sbi->mntflag & JFS_BAD_SAIT) == 0) {
- ipaimap2 = diReadSpecial(sb, AGGREGATE_I, 1);
- if (!ipaimap2) {
- jfs_err("jfs_mount: Failed to read AGGREGATE_I");
- rc = -EIO;
- goto errout35;
- }
- sbi->ipaimap2 = ipaimap2;
- jfs_info("jfs_mount: ipaimap2:0x%p", ipaimap2);
-
- if ((rc = diMount(ipaimap2))) {
- jfs_err("jfs_mount: diMount(ipaimap2) failed, rc = %d",
- rc);
- goto errout35;
- }
- } else
-
- sbi->ipaimap2 = NULL;
-
-
- ipimap = diReadSpecial(sb, FILESYSTEM_I, 0);
- if (ipimap == NULL) {
- jfs_err("jfs_mount: Failed to read FILESYSTEM_I");
-
- rc = -EIO;
- goto errout40;
- }
- jfs_info("jfs_mount: ipimap:0x%p", ipimap);
-
- sbi->ipimap = ipimap;
-
- if ((rc = diMount(ipimap))) {
- jfs_err("jfs_mount: diMount failed w/rc = %d", rc);
- goto errout41;
- }
- goto out;
-
- errout41:
- diFreeSpecial(ipimap);
- errout40:
-
- if (ipaimap2) {
- diUnmount(ipaimap2, 1);
- diFreeSpecial(ipaimap2);
- }
- errout35:
-
- dbUnmount(ipbmap, 1);
- diFreeSpecial(ipbmap);
- errout22:
- diUnmount(ipaimap, 1);
- errout21:
- diFreeSpecial(ipaimap);
- errout20:
- out:
- if (rc)
- jfs_err("Mount JFS Failure: %d", rc);
- return rc;
- }
- int jfs_mount_rw(struct super_block *sb, int remount)
- {
- struct jfs_sb_info *sbi = JFS_SBI(sb);
- int rc;
-
- if (remount) {
- if (chkSuper(sb) || (sbi->state != FM_CLEAN))
- return -EINVAL;
- truncate_inode_pages(sbi->ipimap->i_mapping, 0);
- truncate_inode_pages(sbi->ipbmap->i_mapping, 0);
- diUnmount(sbi->ipimap, 1);
- if ((rc = diMount(sbi->ipimap))) {
- jfs_err("jfs_mount_rw: diMount failed!");
- return rc;
- }
- dbUnmount(sbi->ipbmap, 1);
- if ((rc = dbMount(sbi->ipbmap))) {
- jfs_err("jfs_mount_rw: dbMount failed!");
- return rc;
- }
- }
-
- if ((rc = lmLogOpen(sb)))
- return rc;
-
- if ((rc = updateSuper(sb, FM_MOUNT))) {
- jfs_err("jfs_mount: updateSuper failed w/rc = %d", rc);
- lmLogClose(sb);
- return rc;
- }
-
- logMOUNT(sb);
- return rc;
- }
- static int chkSuper(struct super_block *sb)
- {
- int rc = 0;
- struct jfs_sb_info *sbi = JFS_SBI(sb);
- struct jfs_superblock *j_sb;
- struct buffer_head *bh;
- int AIM_bytesize, AIT_bytesize;
- int expected_AIM_bytesize, expected_AIT_bytesize;
- s64 AIM_byte_addr, AIT_byte_addr, fsckwsp_addr;
- s64 byte_addr_diff0, byte_addr_diff1;
- s32 bsize;
- if ((rc = readSuper(sb, &bh)))
- return rc;
- j_sb = (struct jfs_superblock *)bh->b_data;
-
-
- if (strncmp(j_sb->s_magic, JFS_MAGIC, 4) ||
- le32_to_cpu(j_sb->s_version) > JFS_VERSION) {
- rc = -EINVAL;
- goto out;
- }
- bsize = le32_to_cpu(j_sb->s_bsize);
- #ifdef _JFS_4K
- if (bsize != PSIZE) {
- jfs_err("Currently only 4K block size supported!");
- rc = -EINVAL;
- goto out;
- }
- #endif
- jfs_info("superblock: flag:0x%08x state:0x%08x size:0x%Lx",
- le32_to_cpu(j_sb->s_flag), le32_to_cpu(j_sb->s_state),
- (unsigned long long) le64_to_cpu(j_sb->s_size));
-
- if ((j_sb->s_flag & cpu_to_le32(JFS_BAD_SAIT)) !=
- cpu_to_le32(JFS_BAD_SAIT)) {
- expected_AIM_bytesize = 2 * PSIZE;
- AIM_bytesize = lengthPXD(&(j_sb->s_aim2)) * bsize;
- expected_AIT_bytesize = 4 * PSIZE;
- AIT_bytesize = lengthPXD(&(j_sb->s_ait2)) * bsize;
- AIM_byte_addr = addressPXD(&(j_sb->s_aim2)) * bsize;
- AIT_byte_addr = addressPXD(&(j_sb->s_ait2)) * bsize;
- byte_addr_diff0 = AIT_byte_addr - AIM_byte_addr;
- fsckwsp_addr = addressPXD(&(j_sb->s_fsckpxd)) * bsize;
- byte_addr_diff1 = fsckwsp_addr - AIT_byte_addr;
- if ((AIM_bytesize != expected_AIM_bytesize) ||
- (AIT_bytesize != expected_AIT_bytesize) ||
- (byte_addr_diff0 != AIM_bytesize) ||
- (byte_addr_diff1 <= AIT_bytesize))
- j_sb->s_flag |= cpu_to_le32(JFS_BAD_SAIT);
- }
- if ((j_sb->s_flag & cpu_to_le32(JFS_GROUPCOMMIT)) !=
- cpu_to_le32(JFS_GROUPCOMMIT))
- j_sb->s_flag |= cpu_to_le32(JFS_GROUPCOMMIT);
-
- if (j_sb->s_state != cpu_to_le32(FM_CLEAN) &&
- !(sb->s_flags & MS_RDONLY)) {
- jfs_err("jfs_mount: Mount Failure: File System Dirty.");
- rc = -EINVAL;
- goto out;
- }
- sbi->state = le32_to_cpu(j_sb->s_state);
- sbi->mntflag = le32_to_cpu(j_sb->s_flag);
-
- sbi->bsize = bsize;
- sbi->l2bsize = le16_to_cpu(j_sb->s_l2bsize);
-
- sbi->nbperpage = PSIZE >> sbi->l2bsize;
- sbi->l2nbperpage = L2PSIZE - sbi->l2bsize;
- sbi->l2niperblk = sbi->l2bsize - L2DISIZE;
- if (sbi->mntflag & JFS_INLINELOG)
- sbi->logpxd = j_sb->s_logpxd;
- else {
- sbi->logdev = new_decode_dev(le32_to_cpu(j_sb->s_logdev));
- memcpy(sbi->uuid, j_sb->s_uuid, sizeof(sbi->uuid));
- memcpy(sbi->loguuid, j_sb->s_loguuid, sizeof(sbi->uuid));
- }
- sbi->fsckpxd = j_sb->s_fsckpxd;
- sbi->ait2 = j_sb->s_ait2;
- out:
- brelse(bh);
- return rc;
- }
- int updateSuper(struct super_block *sb, uint state)
- {
- struct jfs_superblock *j_sb;
- struct jfs_sb_info *sbi = JFS_SBI(sb);
- struct buffer_head *bh;
- int rc;
- if (sbi->flag & JFS_NOINTEGRITY) {
- if (state == FM_DIRTY) {
- sbi->p_state = state;
- return 0;
- } else if (state == FM_MOUNT) {
- sbi->p_state = sbi->state;
- state = FM_DIRTY;
- } else if (state == FM_CLEAN) {
- state = sbi->p_state;
- } else
- jfs_err("updateSuper: bad state");
- } else if (sbi->state == FM_DIRTY)
- return 0;
- if ((rc = readSuper(sb, &bh)))
- return rc;
- j_sb = (struct jfs_superblock *)bh->b_data;
- j_sb->s_state = cpu_to_le32(state);
- sbi->state = state;
- if (state == FM_MOUNT) {
-
- j_sb->s_logdev = cpu_to_le32(new_encode_dev(sbi->log->bdev->bd_dev));
- j_sb->s_logserial = cpu_to_le32(sbi->log->serial);
- } else if (state == FM_CLEAN) {
-
- if (j_sb->s_flag & cpu_to_le32(JFS_DASD_ENABLED))
- j_sb->s_flag |= cpu_to_le32(JFS_DASD_PRIME);
- }
- mark_buffer_dirty(bh);
- sync_dirty_buffer(bh);
- brelse(bh);
- return 0;
- }
- int readSuper(struct super_block *sb, struct buffer_head **bpp)
- {
-
- *bpp = sb_bread(sb, SUPER1_OFF >> sb->s_blocksize_bits);
- if (*bpp)
- return 0;
-
- *bpp = sb_bread(sb, SUPER2_OFF >> sb->s_blocksize_bits);
- if (*bpp)
- return 0;
- return -EIO;
- }
- static int logMOUNT(struct super_block *sb)
- {
- struct jfs_log *log = JFS_SBI(sb)->log;
- struct lrd lrd;
- lrd.logtid = 0;
- lrd.backchain = 0;
- lrd.type = cpu_to_le16(LOG_MOUNT);
- lrd.length = 0;
- lrd.aggregate = cpu_to_le32(new_encode_dev(sb->s_bdev->bd_dev));
- lmLog(log, NULL, &lrd, NULL);
- return 0;
- }
|