aboutsummaryrefslogtreecommitdiff
path: root/sys/fs/ext2fs/ext2_balloc.c
diff options
context:
space:
mode:
authorFedor Uporov <fsu@FreeBSD.org>2018-01-05 10:04:01 +0000
committerFedor Uporov <fsu@FreeBSD.org>2018-01-05 10:04:01 +0000
commit3acd9182a171ee292708e75d8f38a488e9937972 (patch)
tree73ef72fadcf1512437c714c72a39f73a4a5e3fbd /sys/fs/ext2fs/ext2_balloc.c
parente1c30f7a071584219c9504d80442e6540e2ef4c0 (diff)
downloadsrc-3acd9182a171ee292708e75d8f38a488e9937972.tar.gz
src-3acd9182a171ee292708e75d8f38a488e9937972.zip
Add 64bit feature support.
Reviewed by: kevlo, pfg (mentor) Approved by: pfg (mentor) MFC after: 6 months Differential Revision: https://reviews.freebsd.org/D11530
Notes
Notes: svn path=/head/; revision=327584
Diffstat (limited to 'sys/fs/ext2fs/ext2_balloc.c')
-rw-r--r--sys/fs/ext2fs/ext2_balloc.c39
1 files changed, 23 insertions, 16 deletions
diff --git a/sys/fs/ext2fs/ext2_balloc.c b/sys/fs/ext2fs/ext2_balloc.c
index a8552509122c..7d5cff6667ea 100644
--- a/sys/fs/ext2fs/ext2_balloc.c
+++ b/sys/fs/ext2fs/ext2_balloc.c
@@ -42,6 +42,7 @@
#include <sys/systm.h>
#include <sys/bio.h>
#include <sys/buf.h>
+#include <sys/limits.h>
#include <sys/lock.h>
#include <sys/mount.h>
#include <sys/vnode.h>
@@ -60,13 +61,13 @@ ext2_ext_balloc(struct inode *ip, uint32_t lbn, int size,
struct m_ext2fs *fs;
struct buf *bp = NULL;
struct vnode *vp = ITOV(ip);
- uint32_t nb;
+ daddr_t newblk;
int osize, nsize, blks, error, allocated;
fs = ip->i_e2fs;
blks = howmany(size, fs->e2fs_bsize);
- error = ext4_ext_get_blocks(ip, lbn, blks, cred, NULL, &allocated, &nb);
+ error = ext4_ext_get_blocks(ip, lbn, blks, cred, NULL, &allocated, &newblk);
if (error)
return (error);
@@ -80,7 +81,7 @@ ext2_ext_balloc(struct inode *ip, uint32_t lbn, int size,
if(!bp)
return (EIO);
- bp->b_blkno = fsbtodb(fs, nb);
+ bp->b_blkno = fsbtodb(fs, newblk);
if (flags & BA_CLRBUF)
vfs_bio_clrbuf(bp);
} else {
@@ -91,7 +92,7 @@ ext2_ext_balloc(struct inode *ip, uint32_t lbn, int size,
brelse(bp);
return (error);
}
- bp->b_blkno = fsbtodb(fs, nb);
+ bp->b_blkno = fsbtodb(fs, newblk);
*bpp = bp;
return (0);
}
@@ -101,21 +102,15 @@ ext2_ext_balloc(struct inode *ip, uint32_t lbn, int size,
*/
osize = fragroundup(fs, blkoff(fs, ip->i_size));
nsize = fragroundup(fs, size);
- if (nsize <= osize) {
+ if (nsize <= osize)
error = bread(vp, lbn, osize, NOCRED, &bp);
- if (error) {
- brelse(bp);
- return (error);
- }
- bp->b_blkno = fsbtodb(fs, nb);
- } else {
+ else
error = bread(vp, lbn, fs->e2fs_bsize, NOCRED, &bp);
- if (error) {
- brelse(bp);
- return (error);
- }
- bp->b_blkno = fsbtodb(fs, nb);
+ if (error) {
+ brelse(bp);
+ return (error);
}
+ bp->b_blkno = fsbtodb(fs, newblk);
}
*bpp = bp;
@@ -218,6 +213,12 @@ ext2_balloc(struct inode *ip, e2fs_lbn_t lbn, int size, struct ucred *cred,
nsize, cred, &newb);
if (error)
return (error);
+ /*
+ * If the newly allocated block exceeds 32-bit limit,
+ * we can not use it in file block maps.
+ */
+ if (newb > UINT_MAX)
+ return (EFBIG);
bp = getblk(vp, lbn, nsize, 0, 0, 0);
bp->b_blkno = fsbtodb(fs, newb);
if (flags & BA_CLRBUF)
@@ -250,6 +251,8 @@ ext2_balloc(struct inode *ip, e2fs_lbn_t lbn, int size, struct ucred *cred,
if ((error = ext2_alloc(ip, lbn, pref, fs->e2fs_bsize, cred,
&newb)))
return (error);
+ if (newb > UINT_MAX)
+ return (EFBIG);
nb = newb;
bp = getblk(vp, indirs[1].in_lbn, fs->e2fs_bsize, 0, 0, 0);
bp->b_blkno = fsbtodb(fs, newb);
@@ -293,6 +296,8 @@ ext2_balloc(struct inode *ip, e2fs_lbn_t lbn, int size, struct ucred *cred,
brelse(bp);
return (error);
}
+ if (newb > UINT_MAX)
+ return (EFBIG);
nb = newb;
nbp = getblk(vp, indirs[i].in_lbn, fs->e2fs_bsize, 0, 0, 0);
nbp->b_blkno = fsbtodb(fs, nb);
@@ -332,6 +337,8 @@ ext2_balloc(struct inode *ip, e2fs_lbn_t lbn, int size, struct ucred *cred,
brelse(bp);
return (error);
}
+ if (newb > UINT_MAX)
+ return (EFBIG);
nb = newb;
nbp = getblk(vp, lbn, fs->e2fs_bsize, 0, 0, 0);
nbp->b_blkno = fsbtodb(fs, nb);