-/* $OpenBSD: ext2fs.h,v 1.19 2014/07/13 13:28:26 pelikan Exp $ */
+/* $OpenBSD: ext2fs.h,v 1.20 2014/07/13 16:59:35 pelikan Exp $ */
/* $NetBSD: ext2fs.h,v 1.10 2000/01/28 16:00:23 bouyer Exp $ */
/*
}
/*
- * EXT2FS metadatas are stored in little-endian byte order. These macros
- * helps reading theses metadatas
+ * Ext2 metadata is stored in little-endian byte order.
+ * JBD2 journal used in ext3 and ext4 is big-endian!
*/
-
-#define h2fs16(x) htole16(x)
-#define h2fs32(x) htole32(x)
-#define fs2h16(x) letoh16(x)
-#define fs2h32(x) letoh32(x)
#if BYTE_ORDER == LITTLE_ENDIAN
#define e2fs_sbload(old, new) memcpy((new), (old), SBSIZE);
#define e2fs_cgload(old, new, size) memcpy((new), (old), (size));
-/* $OpenBSD: ext2fs_alloc.c,v 1.31 2014/05/27 14:31:24 krw Exp $ */
+/* $OpenBSD: ext2fs_alloc.c,v 1.32 2014/07/13 16:59:35 pelikan Exp $ */
/* $NetBSD: ext2fs_alloc.c,v 1.10 2001/07/05 08:38:27 toshii Exp $ */
/*
ip = VTOI(*vpp);
if (ip->i_e2fs_mode && ip->i_e2fs_nlink != 0) {
printf("mode = 0%o, nlinks %u, inum = %u, fs = %s\n",
- ip->i_e2fs_mode, ip->i_e2fs_nlink, ip->i_number, fs->e2fs_fsmnt);
+ ip->i_e2fs_mode, ip->i_e2fs_nlink, ip->i_number,
+ fs->e2fs_fsmnt);
panic("ext2fs_valloc: dup alloc");
}
if (bap) {
for (i = indx; i >= 0 ; i--) {
if (bap[i]) {
- return fs2h32(bap[i]) + 1;
+ return letoh32(bap[i]) + 1;
}
}
}
if (fs->e2fs_gd[cg].ext2bgd_nbfree == 0)
return (0);
error = bread(ip->i_devvp, fsbtodb(fs,
- fs->e2fs_gd[cg].ext2bgd_b_bitmap),
- (int)fs->e2fs_bsize, &bp);
+ fs->e2fs_gd[cg].ext2bgd_b_bitmap), (int)fs->e2fs_bsize, &bp);
if (error || fs->e2fs_gd[cg].ext2bgd_nbfree == 0) {
brelse(bp);
return (0);
if (fs->e2fs_gd[cg].ext2bgd_nifree == 0)
return (0);
error = bread(ip->i_devvp, fsbtodb(fs,
- fs->e2fs_gd[cg].ext2bgd_i_bitmap),
- (int)fs->e2fs_bsize, &bp);
+ fs->e2fs_gd[cg].ext2bgd_i_bitmap), (int)fs->e2fs_bsize, &bp);
if (error) {
brelse(bp);
return (0);
fs = pip->i_e2fs;
if ((u_int)ino > fs->e2fs.e2fs_icount || (u_int)ino < EXT2_FIRSTINO)
panic("ifree: range: dev = 0x%x, ino = %d, fs = %s",
- pip->i_dev, ino, fs->e2fs_fsmnt);
+ pip->i_dev, ino, fs->e2fs_fsmnt);
cg = ino_to_cg(fs, ino);
error = bread(pip->i_devvp,
- fsbtodb(fs, fs->e2fs_gd[cg].ext2bgd_i_bitmap),
- (int)fs->e2fs_bsize, &bp);
+ fsbtodb(fs, fs->e2fs_gd[cg].ext2bgd_i_bitmap),
+ (int)fs->e2fs_bsize, &bp);
if (error) {
brelse(bp);
return (0);
ino = (ino - 1) % fs->e2fs.e2fs_ipg;
if (isclr(ibp, ino)) {
printf("dev = 0x%x, ino = %d, fs = %s\n",
- pip->i_dev, ino, fs->e2fs_fsmnt);
+ pip->i_dev, ino, fs->e2fs_fsmnt);
if (fs->e2fs_ronly == 0)
panic("ifree: freeing free inode");
}
-/* $OpenBSD: ext2fs_balloc.c,v 1.21 2014/07/08 17:19:26 deraadt Exp $ */
+/* $OpenBSD: ext2fs_balloc.c,v 1.22 2014/07/13 16:59:35 pelikan Exp $ */
/* $NetBSD: ext2fs_balloc.c,v 1.10 2001/07/04 21:16:01 chs Exp $ */
/*
* The first NDADDR blocks are direct blocks
*/
if (bn < NDADDR) {
- nb = fs2h32(ip->i_e2fs_blocks[bn]);
+ nb = letoh32(ip->i_e2fs_blocks[bn]);
if (nb != 0) {
error = bread(vp, bn, fs->e2fs_bsize, &bp);
if (error) {
return (error);
ip->i_e2fs_last_lblk = lbn;
ip->i_e2fs_last_blk = newb;
- ip->i_e2fs_blocks[bn] = h2fs32(newb);
+ ip->i_e2fs_blocks[bn] = htole32(newb);
ip->i_flag |= IN_CHANGE | IN_UPDATE;
bp = getblk(vp, bn, fs->e2fs_bsize, 0, 0);
bp->b_blkno = fsbtodb(fs, newb);
* Fetch the first indirect block allocating if necessary.
*/
--num;
- nb = fs2h32(ip->i_e2fs_blocks[NDADDR + indirs[0].in_off]);
+ nb = letoh32(ip->i_e2fs_blocks[NDADDR + indirs[0].in_off]);
allocib = NULL;
allocblk = allociblk;
if (nb == 0) {
goto fail;
unwindidx = 0;
allocib = &ip->i_e2fs_blocks[NDADDR + indirs[0].in_off];
- *allocib = h2fs32(newb);
+ *allocib = htole32(newb);
ip->i_flag |= IN_CHANGE | IN_UPDATE;
}
/*
goto fail;
}
bap = (int32_t *)bp->b_data;
- nb = fs2h32(bap[indirs[i].in_off]);
+ nb = letoh32(bap[indirs[i].in_off]);
if (i == num)
break;
i++;
}
if (unwindidx < 0)
unwindidx = i - 1;
- bap[indirs[i - 1].in_off] = h2fs32(nb);
+ bap[indirs[i - 1].in_off] = htole32(nb);
/*
* If required, write synchronously, otherwise use
* delayed write.
*allocblk++ = nb;
ip->i_e2fs_last_lblk = lbn;
ip->i_e2fs_last_blk = newb;
- bap[indirs[num].in_off] = h2fs32(nb);
+ bap[indirs[num].in_off] = htole32(nb);
/*
* If required, write synchronously, otherwise use
* delayed write.
-/* $OpenBSD: ext2fs_bmap.c,v 1.23 2014/07/13 13:28:26 pelikan Exp $ */
+/* $OpenBSD: ext2fs_bmap.c,v 1.24 2014/07/13 16:59:35 pelikan Exp $ */
/* $NetBSD: ext2fs_bmap.c,v 1.5 2000/03/30 12:41:11 augustss Exp $ */
/*
num = *nump;
if (num == 0) {
- *bnp = blkptrtodb(ump, fs2h32(ip->i_e2fs_blocks[bn]));
+ *bnp = blkptrtodb(ump, letoh32(ip->i_e2fs_blocks[bn]));
if (*bnp == 0)
*bnp = -1;
else if (runp)
for (++bn; bn < NDADDR && *runp < maxrun &&
- is_sequential(ump, fs2h32(ip->i_e2fs_blocks[bn - 1]),
- fs2h32(ip->i_e2fs_blocks[bn]));
- ++bn, ++*runp);
+ is_sequential(ump,
+ letoh32(ip->i_e2fs_blocks[bn - 1]),
+ letoh32(ip->i_e2fs_blocks[bn]));
+ ++bn, ++*runp)
+ /* nothing */;
return (0);
}
/* Get disk address out of indirect block array */
- daddr = fs2h32(ip->i_e2fs_blocks[NDADDR + xap->in_off]);
+ daddr = letoh32(ip->i_e2fs_blocks[NDADDR + xap->in_off]);
devvp = VFSTOUFS(vp->v_mount)->um_devvp;
}
}
- daddr = fs2h32(((int32_t *)bp->b_data)[xap->in_off]);
+ daddr = letoh32(((int32_t *)bp->b_data)[xap->in_off]);
if (num == 1 && daddr && runp)
for (bn = xap->in_off + 1;
bn < MNINDIR(ump) && *runp < maxrun &&
-/* $OpenBSD: ext2fs_inode.c,v 1.53 2014/07/13 15:07:01 pelikan Exp $ */
+/* $OpenBSD: ext2fs_inode.c,v 1.54 2014/07/13 16:59:35 pelikan Exp $ */
/* $NetBSD: ext2fs_inode.c,v 1.24 2001/06/19 12:59:18 wiz Exp $ */
/*
indir_lbn[DOUBLE] = indir_lbn[SINGLE] - NINDIR(fs) -1;
indir_lbn[TRIPLE] = indir_lbn[DOUBLE] - NINDIR(fs) * NINDIR(fs) - 1;
for (level = TRIPLE; level >= SINGLE; level--) {
- bn = fs2h32(oip->i_e2fs_blocks[NDADDR + level]);
+ bn = letoh32(oip->i_e2fs_blocks[NDADDR + level]);
if (bn != 0) {
error = ext2fs_indirtrunc(oip, indir_lbn[level],
fsbtodb(fs, bn), lastiblock[level], level, &count);
* All whole direct blocks or frags.
*/
for (i = NDADDR - 1; i > lastblock; i--) {
- bn = fs2h32(oip->i_e2fs_blocks[i]);
+ bn = letoh32(oip->i_e2fs_blocks[i]);
if (bn == 0)
continue;
oip->i_e2fs_blocks[i] = 0;
for (i = NINDIR(fs) - 1,
nlbn = lbn + 1 - i * factor; i > last;
i--, nlbn += factor) {
- nb = fs2h32(bap[i]);
+ nb = letoh32(bap[i]);
if (nb == 0)
continue;
if (level > SINGLE) {
*/
if (level > SINGLE && lastbn >= 0) {
last = lastbn % factor;
- nb = fs2h32(bap[i]);
+ nb = letoh32(bap[i]);
if (nb != 0) {
error = ext2fs_indirtrunc(ip, nlbn, fsbtodb(fs, nb),
last, level - 1, &blkcount);
-/* $OpenBSD: ext2fs_lookup.c,v 1.36 2014/07/13 15:07:01 pelikan Exp $ */
+/* $OpenBSD: ext2fs_lookup.c,v 1.37 2014/07/13 16:59:35 pelikan Exp $ */
/* $NetBSD: ext2fs_lookup.c,v 1.16 2000/08/03 20:29:26 thorpej Exp $ */
/*
ext2fs_dirconv2ffs(struct ext2fs_direct *e2dir, struct dirent *ffsdir)
{
memset(ffsdir, 0, sizeof(struct dirent));
- ffsdir->d_fileno = fs2h32(e2dir->e2d_ino);
+ ffsdir->d_fileno = letoh32(e2dir->e2d_ino);
ffsdir->d_namlen = e2dir->e2d_namlen;
ffsdir->d_type = DT_UNKNOWN; /* don't know more here */
readcnt = e2fs_count - auio.uio_resid;
dp = (struct ext2fs_direct *) dirbuf;
while ((char *) dp < (char *) dirbuf + readcnt) {
- e2d_reclen = fs2h16(dp->e2d_reclen);
+ e2d_reclen = letoh16(dp->e2d_reclen);
if (e2d_reclen == 0) {
error = EIO;
break;
ep = (struct ext2fs_direct *)
((char *)bp->b_data + (entryoffsetinblock & bmask));
/* foundentry: */
- dp->i_ino = fs2h32(ep->e2d_ino);
- dp->i_reclen = fs2h16(ep->e2d_reclen);
+ dp->i_ino = letoh32(ep->e2d_ino);
+ dp->i_reclen = letoh16(ep->e2d_reclen);
goto found;
}
}
* compaction is viable.
*/
if (ssp->slotstatus != FOUND) {
- int size = fs2h16(ep->e2d_reclen);
+ int size = letoh16(ep->e2d_reclen);
if (ep->e2d_ino != 0)
size -= EXT2FS_DIRSIZ(ep->e2d_namlen);
if (size >= ssp->slotneeded) {
ssp->slotstatus = FOUND;
ssp->slotoffset = ip->i_offset;
- ssp->slotsize = fs2h16(ep->e2d_reclen);
+ ssp->slotsize = letoh16(ep->e2d_reclen);
} else if (ssp->slotstatus == NONE) {
ssp->slotfreespace += size;
if (ssp->slotoffset == -1)
if (ssp->slotfreespace >= ssp->slotneeded) {
ssp->slotstatus = COMPACT;
ssp->slotsize = ip->i_offset +
- fs2h16(ep->e2d_reclen) - ssp->slotoffset;
+ letoh16(ep->e2d_reclen) - ssp->slotoffset;
}
}
}
}
}
*prevoffp = ip->i_offset;
- ip->i_offset += fs2h16(ep->e2d_reclen);
- offset += fs2h16(ep->e2d_reclen);
+ ip->i_offset += letoh16(ep->e2d_reclen);
+ offset += letoh16(ep->e2d_reclen);
*entryoffsetinblockp = offset;
if (ep->e2d_ino)
*endusefulp = ip->i_offset;
ext2fs_dirbadentry(struct vnode *dp, struct ext2fs_direct *de,
int entryoffsetinblock)
{
- int dirblksize = VTOI(dp)->i_e2fs->e2fs_bsize;
+ int dirblksize = VTOI(dp)->i_e2fs->e2fs_bsize;
+ char *error_msg = NULL;
+ int reclen = letoh16(de->e2d_reclen);
+ int namlen = de->e2d_namlen;
- char * error_msg = NULL;
- int reclen = fs2h16(de->e2d_reclen);
- int namlen = de->e2d_namlen;
+ if (reclen < EXT2FS_DIRSIZ(1)) /* e2d_namlen = 1 */
+ error_msg = "rec_len is smaller than minimal";
+ else if (reclen % 4 != 0)
+ error_msg = "rec_len % 4 != 0";
+ else if (reclen < EXT2FS_DIRSIZ(namlen))
+ error_msg = "reclen is too small for name_len";
+ else if (entryoffsetinblock + reclen > dirblksize)
+ error_msg = "directory entry across blocks";
+ else if (letoh32(de->e2d_ino) > VTOI(dp)->i_e2fs->e2fs.e2fs_icount)
+ error_msg = "inode out of bounds";
- if (reclen < EXT2FS_DIRSIZ(1)) /* e2d_namlen = 1 */
- error_msg = "rec_len is smaller than minimal";
- else if (reclen % 4 != 0)
- error_msg = "rec_len % 4 != 0";
- else if (reclen < EXT2FS_DIRSIZ(namlen))
- error_msg = "reclen is too small for name_len";
- else if (entryoffsetinblock + reclen > dirblksize)
- error_msg = "directory entry across blocks";
- else if (fs2h32(de->e2d_ino) >
- VTOI(dp)->i_e2fs->e2fs.e2fs_icount)
- error_msg = "inode out of bounds";
-
- if (error_msg != NULL) {
- printf( "bad directory entry: %s\n"
- "offset=%d, inode=%lu, rec_len=%d, name_len=%d \n",
- error_msg, entryoffsetinblock,
- (unsigned long) fs2h32(de->e2d_ino),
- reclen, namlen);
- panic("ext2fs_dirbadentry");
- }
- return error_msg == NULL ? 0 : 1;
+ if (error_msg != NULL) {
+ printf("bad directory entry: %s\n"
+ "offset=%d, inode=%u, rec_len=%d, name_len=%d \n",
+ error_msg, entryoffsetinblock, letoh32(de->e2d_ino),
+ reclen, namlen);
+ panic(__func__);
+ }
+ return (0);
}
/*
panic("direnter: missing name");
#endif
dp = VTOI(dvp);
- newdir.e2d_ino = h2fs32(ip->i_number);
+ newdir.e2d_ino = htole32(ip->i_number);
newdir.e2d_namlen = cnp->cn_namelen;
if (ip->i_e2fs->e2fs.e2fs_rev > E2FS_REV0 &&
(ip->i_e2fs->e2fs.e2fs_features_incompat & EXT2F_INCOMPAT_FTYPE)) {
if (dp->i_offset & (dirblksize - 1))
panic("ext2fs_direnter: newblk");
auio.uio_offset = dp->i_offset;
- newdir.e2d_reclen = h2fs16(dirblksize);
+ newdir.e2d_reclen = htole16(dirblksize);
auio.uio_resid = newentrysize;
aiov.iov_len = newentrysize;
aiov.iov_base = (caddr_t)&newdir;
*/
ep = (struct ext2fs_direct *)dirbuf;
dsize = EXT2FS_DIRSIZ(ep->e2d_namlen);
- spacefree = fs2h16(ep->e2d_reclen) - dsize;
- for (loc = fs2h16(ep->e2d_reclen); loc < dp->i_count; ) {
+ spacefree = letoh16(ep->e2d_reclen) - dsize;
+ for (loc = letoh16(ep->e2d_reclen); loc < dp->i_count; ) {
nep = (struct ext2fs_direct *)(dirbuf + loc);
if (ep->e2d_ino) {
/* trim the existing slot */
- ep->e2d_reclen = h2fs16(dsize);
+ ep->e2d_reclen = htole16(dsize);
ep = (struct ext2fs_direct *)((char *)ep + dsize);
} else {
/* overwrite; nothing there; header is ours */
spacefree += dsize;
}
dsize = EXT2FS_DIRSIZ(nep->e2d_namlen);
- spacefree += fs2h16(nep->e2d_reclen) - dsize;
- loc += fs2h16(nep->e2d_reclen);
+ spacefree += letoh16(nep->e2d_reclen) - dsize;
+ loc += letoh16(nep->e2d_reclen);
memcpy(ep, nep, dsize);
}
/*
if (spacefree + dsize < newentrysize)
panic("ext2fs_direnter: compact1");
#endif
- newdir.e2d_reclen = h2fs16(spacefree + dsize);
+ newdir.e2d_reclen = htole16(spacefree + dsize);
} else {
#ifdef DIAGNOSTIC
if (spacefree < newentrysize) {
panic("ext2fs_direnter: compact2");
}
#endif
- newdir.e2d_reclen = h2fs16(spacefree);
- ep->e2d_reclen = h2fs16(dsize);
+ newdir.e2d_reclen = htole16(spacefree);
+ ep->e2d_reclen = htole16(dsize);
ep = (struct ext2fs_direct *)((char *)ep + dsize);
}
memcpy(ep, &newdir, newentrysize);
(char **)&ep, &bp);
if (error != 0)
return (error);
- ep->e2d_reclen = h2fs16(fs2h16(ep->e2d_reclen) + dp->i_reclen);
+ ep->e2d_reclen = htole16(letoh16(ep->e2d_reclen) + dp->i_reclen);
error = VOP_BWRITE(bp);
dp->i_flag |= IN_CHANGE | IN_UPDATE;
return (error);
error = ext2fs_bufatoff(dp, (off_t)dp->i_offset, (char **)&ep, &bp);
if (error != 0)
return (error);
- ep->e2d_ino = h2fs32(ip->i_number);
+ ep->e2d_ino = htole32(ip->i_number);
if (ip->i_e2fs->e2fs.e2fs_rev > E2FS_REV0 &&
(ip->i_e2fs->e2fs.e2fs_features_incompat & EXT2F_INCOMPAT_FTYPE)) {
ep->e2d_type = inot2ext2dt(IFTODT(ip->i_e2fs_mode));
#define MINDIRSIZ (sizeof (struct ext2fs_dirtemplate) / 2)
- for (off = 0; off < ext2fs_size(ip); off += fs2h16(dp->e2d_reclen)) {
+ for (off = 0; off < ext2fs_size(ip); off += letoh16(dp->e2d_reclen)) {
error = vn_rdwr(UIO_READ, ITOV(ip), (caddr_t)dp, MINDIRSIZ, off,
UIO_SYSSPACE, IO_NODELOCKED, cred, &count, curproc);
/*
*/
if (namlen == 1)
continue;
- if (dp->e2d_name[1] == '.' && fs2h32(dp->e2d_ino) == parentino)
+ if (dp->e2d_name[1] == '.' && letoh32(dp->e2d_ino) == parentino)
continue;
return (0);
}
error = ENOTDIR;
break;
}
- ino = fs2h32(dirbuf.dotdot_ino);
+ ino = letoh32(dirbuf.dotdot_ino);
if (ino == source->i_number) {
error = EINVAL;
break;
-/* $OpenBSD: ext2fs_subr.c,v 1.31 2014/07/13 13:28:26 pelikan Exp $ */
+/* $OpenBSD: ext2fs_subr.c,v 1.32 2014/07/13 16:59:35 pelikan Exp $ */
/* $NetBSD: ext2fs_subr.c,v 1.1 1997/06/11 09:34:03 bouyer Exp $ */
/*
case VBLK:
vp->v_op = specops;
- nvp = checkalias(vp, fs2h32(ip->i_e2din->e2di_rdev), mp);
+ nvp = checkalias(vp, letoh32(ip->i_e2din->e2di_rdev), mp);
if (nvp != NULL) {
/*
* Discard unneeded vnode, but save its inode. Note
-/* $OpenBSD: ext2fs_vnops.c,v 1.66 2014/07/08 17:19:26 deraadt Exp $ */
+/* $OpenBSD: ext2fs_vnops.c,v 1.67 2014/07/13 16:59:35 pelikan Exp $ */
/* $NetBSD: ext2fs_vnops.c,v 1.1 1997/06/11 09:34:09 bouyer Exp $ */
/*
* Want to be able to use this to make badblock
* inodes, so don't truncate the dev number.
*/
- ip->i_e2din->e2di_rdev = h2fs32(vap->va_rdev);
+ ip->i_e2din->e2di_rdev = htole32(vap->va_rdev);
}
/*
* Remove inode so that it will be reloaded by VFS_VGET and
vap->va_nlink = ip->i_e2fs_nlink;
vap->va_uid = ip->i_e2fs_uid;
vap->va_gid = ip->i_e2fs_gid;
- vap->va_rdev = (dev_t)fs2h32(ip->i_e2din->e2di_rdev);
+ vap->va_rdev = (dev_t) letoh32(ip->i_e2din->e2di_rdev);
vap->va_size = ext2fs_size(ip);
vap->va_atime.tv_sec = ip->i_e2fs_atime;
vap->va_atime.tv_nsec = 0;
ufs_dirbad(xp, (doff_t)12,
"ext2fs_rename: mangled dir");
} else {
- dirbuf.dotdot_ino = h2fs32(newparent);
+ dirbuf.dotdot_ino = htole32(newparent);
(void) vn_rdwr(UIO_WRITE, fvp,
(caddr_t)&dirbuf,
sizeof (struct dirtemplate),
/* Initialize directory with "." and ".." from static template. */
memset(&dirtemplate, 0, sizeof(dirtemplate));
- dirtemplate.dot_ino = h2fs32(ip->i_number);
- dirtemplate.dot_reclen = h2fs16(12);
+ dirtemplate.dot_ino = htole32(ip->i_number);
+ dirtemplate.dot_reclen = htole16(12);
dirtemplate.dot_namlen = 1;
if (ip->i_e2fs->e2fs.e2fs_rev > E2FS_REV0 &&
(ip->i_e2fs->e2fs.e2fs_features_incompat & EXT2F_INCOMPAT_FTYPE)) {
dirtemplate.dot_type = EXT2_FT_DIR;
}
dirtemplate.dot_name[0] = '.';
- dirtemplate.dotdot_ino = h2fs32(dp->i_number);
- dirtemplate.dotdot_reclen = h2fs16(VTOI(dvp)->i_e2fs->e2fs_bsize - 12);
+ dirtemplate.dotdot_ino = htole32(dp->i_number);
+ dirtemplate.dotdot_reclen = htole16(VTOI(dvp)->i_e2fs->e2fs_bsize - 12);
dirtemplate.dotdot_namlen = 2;
if (ip->i_e2fs->e2fs.e2fs_rev > E2FS_REV0 &&
(ip->i_e2fs->e2fs.e2fs_features_incompat & EXT2F_INCOMPAT_FTYPE)) {