-/* $OpenBSD: dir.c,v 1.18 2014/05/24 02:27:31 krw Exp $ */
+/* $OpenBSD: dir.c,v 1.19 2014/07/13 16:08:53 pelikan Exp $ */
/* $NetBSD: dir.c,v 1.5 2000/01/28 16:01:46 bouyer Exp $ */
/*
}
idesc->id_loc = 0;
for (dp = fsck_readdir(idesc); dp != NULL; dp = fsck_readdir(idesc)) {
- dsize = fs2h16(dp->e2d_reclen);
+ dsize = letoh16(dp->e2d_reclen);
memcpy(dbuf, dp, (size_t)dsize);
idesc->id_dirp = (struct ext2fs_direct *)dbuf;
if ((n = (*idesc->id_func)(idesc)) & ALTERED) {
fix = dofix(idesc, "DIRECTORY CORRUPTED");
bp = getdirblk(idesc->id_blkno, blksiz);
dp = (struct ext2fs_direct *)(bp->b_un.b_buf + idesc->id_loc);
- dp->e2d_reclen = h2fs16(sblock.e2fs_bsize);
+ dp->e2d_reclen = htole16(sblock.e2fs_bsize);
dp->e2d_ino = 0;
dp->e2d_namlen = 0;
dp->e2d_type = 0;
return NULL;
dploc = idesc->id_loc;
dp = (struct ext2fs_direct *)(bp->b_un.b_buf + dploc);
- idesc->id_loc += fs2h16(dp->e2d_reclen);
- idesc->id_filesize -= fs2h16(dp->e2d_reclen);
+ idesc->id_loc += letoh16(dp->e2d_reclen);
+ idesc->id_filesize -= letoh16(dp->e2d_reclen);
if ((idesc->id_loc % sblock.e2fs_bsize) == 0)
return (dp);
ndp = (struct ext2fs_direct *)(bp->b_un.b_buf + idesc->id_loc);
fix = dofix(idesc, "DIRECTORY CORRUPTED");
bp = getdirblk(idesc->id_blkno, blksiz);
dp = (struct ext2fs_direct *)(bp->b_un.b_buf + dploc);
- dp->e2d_reclen = h2fs16(fs2h16(dp->e2d_reclen) + size);
+ dp->e2d_reclen = htole16(letoh16(dp->e2d_reclen) + size);
if (fix)
dirty(bp);
}
int size;
char *cp;
int spaceleft;
- u_int16_t reclen = fs2h16(dp->e2d_reclen);
+ u_int16_t reclen = letoh16(dp->e2d_reclen);
spaceleft = sblock.e2fs_bsize - (idesc->id_loc % sblock.e2fs_bsize);
- if (fs2h32(dp->e2d_ino) > maxino ||
+ if (letoh32(dp->e2d_ino) > maxino ||
reclen == 0 ||
reclen > spaceleft ||
(reclen & 0x3) != 0)
dp = ginode(ino);
if (ftypeok(dp))
pfatal("%s=%s\n",
- (fs2h16(dp->e2di_mode) & IFMT) == IFDIR ? "DIR" : "FILE", pathbuf);
+ (letoh16(dp->e2di_mode) & IFMT) == IFDIR ? "DIR" : "FILE", pathbuf);
else
pfatal("NAME=%s\n", pathbuf);
}
struct ext2fs_dinode *dp;
dp = ginode(idesc->id_number);
- if (fs2h16(dp->e2di_nlink) == lcnt) {
+ if (letoh16(dp->e2di_nlink) == lcnt) {
if (linkup(idesc->id_number, (ino_t)0) == 0)
clri(idesc, "UNREF", 0);
} else {
pwarn("LINK COUNT %s", (lfdir == idesc->id_number) ? lfname :
- ((fs2h16(dp->e2di_mode) & IFMT) == IFDIR ? "DIR" : "FILE"));
+ ((letoh16(dp->e2di_mode) & IFMT) == IFDIR ? "DIR" : "FILE"));
pinode(idesc->id_number);
printf(" COUNT %d SHOULD BE %d",
- fs2h16(dp->e2di_nlink), fs2h16(dp->e2di_nlink) - lcnt);
+ letoh16(dp->e2di_nlink), letoh16(dp->e2di_nlink) - lcnt);
if (preen) {
if (lcnt < 0) {
printf("\n");
printf(" (ADJUSTED)\n");
}
if (preen || reply("ADJUST") == 1) {
- dp->e2di_nlink = h2fs16(fs2h16(dp->e2di_nlink) - lcnt);
+ dp->e2di_nlink = htole16(letoh16(dp->e2di_nlink) - lcnt);
inodirty();
}
}
oldlen = EXT2FS_DIRSIZ(dirp->e2d_namlen);
else
oldlen = 0;
- if (fs2h16(dirp->e2d_reclen) - oldlen < newlen)
+ if (letoh16(dirp->e2d_reclen) - oldlen < newlen)
return (KEEPON);
- newent.e2d_reclen = h2fs16(fs2h16(dirp->e2d_reclen) - oldlen);
- dirp->e2d_reclen = h2fs16(oldlen);
+ newent.e2d_reclen = htole16(letoh16(dirp->e2d_reclen) - oldlen);
+ dirp->e2d_reclen = htole16(oldlen);
dirp = (struct ext2fs_direct *)(((char *)dirp) + oldlen);
- dirp->e2d_ino = h2fs32(idesc->id_parent); /* ino to be entered is in id_parent */
+ dirp->e2d_ino = htole32(idesc->id_parent); /* ino to be entered is in id_parent */
dirp->e2d_reclen = newent.e2d_reclen;
dirp->e2d_namlen = newent.e2d_namlen;
dirp->e2d_type = newent.e2d_type;
if (strlen(idesc->id_name) != namlen ||
strncmp(dirp->e2d_name, idesc->id_name, (int)namlen))
return (KEEPON);
- dirp->e2d_ino = h2fs32(idesc->id_parent);
+ dirp->e2d_ino = htole32(idesc->id_parent);
if (sblock.e2fs.e2fs_rev > E2FS_REV0 &&
(sblock.e2fs.e2fs_features_incompat & EXT2F_INCOMPAT_FTYPE))
dirp->e2d_type = inot2ext2dt(typemap[idesc->id_parent]);
memset(&idesc, 0, sizeof(struct inodesc));
dp = ginode(orphan);
- lostdir = (fs2h16(dp->e2di_mode) & IFMT) == IFDIR;
+ lostdir = (letoh16(dp->e2di_mode) & IFMT) == IFDIR;
pwarn("UNREF %s ", lostdir ? "DIR" : "FILE");
pinode(orphan);
if (preen && inosize(dp) == 0)
}
}
dp = ginode(lfdir);
- if ((fs2h16(dp->e2di_mode) & IFMT) != IFDIR) {
+ if ((letoh16(dp->e2di_mode) & IFMT) != IFDIR) {
pfatal("lost+found IS NOT A DIRECTORY");
if (reply("REALLOCATE") == 0)
return (0);
parentdir != (ino_t)-1)
(void)makeentry(orphan, lfdir, "..");
dp = ginode(lfdir);
- dp->e2di_nlink = h2fs16(fs2h16(dp->e2di_nlink) +1);
+ dp->e2di_nlink = htole16(letoh16(dp->e2di_nlink) +1);
inodirty();
lncntp[lfdir]++;
pwarn("DIR I=%llu CONNECTED. ", (unsigned long long)orphan);
char *firstblk;
lastbn = lblkno(&sblock, inosize(dp));
- if (lastbn >= NDADDR - 1 || fs2h32(dp->e2di_blocks[lastbn]) == 0 ||
+ if (lastbn >= NDADDR - 1 || letoh32(dp->e2di_blocks[lastbn]) == 0 ||
inosize(dp) == 0)
return (0);
if ((newblk = allocblk()) == 0)
return (0);
dp->e2di_blocks[lastbn + 1] = dp->e2di_blocks[lastbn];
- dp->e2di_blocks[lastbn] = h2fs32(newblk);
+ dp->e2di_blocks[lastbn] = htole32(newblk);
inossize(dp, inosize(dp) + sblock.e2fs_bsize);
- dp->e2di_nblock = h2fs32(fs2h32(dp->e2di_nblock) + 1);
- bp = getdirblk(fs2h32(dp->e2di_blocks[lastbn + 1]),
+ dp->e2di_nblock = htole32(letoh32(dp->e2di_nblock) + 1);
+ bp = getdirblk(letoh32(dp->e2di_blocks[lastbn + 1]),
sblock.e2fs_bsize);
if (bp->b_errs)
goto bad;
memcpy(bp->b_un.b_buf, firstblk, sblock.e2fs_bsize);
free(firstblk);
dirty(bp);
- bp = getdirblk(fs2h32(dp->e2di_blocks[lastbn + 1]),
+ bp = getdirblk(letoh32(dp->e2di_blocks[lastbn + 1]),
sblock.e2fs_bsize);
if (bp->b_errs)
goto bad;
- emptydir.dot_reclen = h2fs16(sblock.e2fs_bsize);
+ emptydir.dot_reclen = htole16(sblock.e2fs_bsize);
memcpy(bp->b_un.b_buf, &emptydir, sizeof emptydir);
pwarn("NO SPACE LEFT IN %s", name);
if (preen)
bad:
dp->e2di_blocks[lastbn] = dp->e2di_blocks[lastbn + 1];
dp->e2di_blocks[lastbn + 1] = 0;
- dp->e2di_size = h2fs32(fs2h32(dp->e2di_size) - sblock.e2fs_bsize);
+ dp->e2di_size = htole32(letoh32(dp->e2di_size) - sblock.e2fs_bsize);
inossize(dp, inosize(dp) - sblock.e2fs_bsize);
- dp->e2di_nblock = h2fs32(fs2h32(dp->e2di_nblock) - 1);
+ dp->e2di_nblock = htole32(letoh32(dp->e2di_nblock) - 1);
freeblk(newblk);
return (0);
}
struct ext2fs_dirtemplate *dirp;
ino = allocino(request, IFDIR|mode);
- dirhead.dot_reclen = h2fs16(12); /* XXX */
- dirhead.dotdot_reclen = h2fs16(sblock.e2fs_bsize - 12); /* XXX */
+ dirhead.dot_reclen = htole16(12); /* XXX */
+ dirhead.dotdot_reclen = htole16(sblock.e2fs_bsize - 12); /* XXX */
dirhead.dot_namlen = 1;
if (sblock.e2fs.e2fs_rev > E2FS_REV0 &&
(sblock.e2fs.e2fs_features_incompat & EXT2F_INCOMPAT_FTYPE))
else
dirhead.dotdot_type = 0;
dirp = &dirhead;
- dirp->dot_ino = h2fs32(ino);
- dirp->dotdot_ino = h2fs32(parent);
+ dirp->dot_ino = htole32(ino);
+ dirp->dotdot_ino = htole32(parent);
dp = ginode(ino);
- bp = getdirblk(fs2h32(dp->e2di_blocks[0]), sblock.e2fs_bsize);
+ bp = getdirblk(letoh32(dp->e2di_blocks[0]), sblock.e2fs_bsize);
if (bp->b_errs) {
freeino(ino);
return (0);
}
memcpy(bp->b_un.b_buf, dirp, sizeof(struct ext2fs_dirtemplate));
dirty(bp);
- dp->e2di_nlink = h2fs16(2);
+ dp->e2di_nlink = htole16(2);
inodirty();
if (ino == EXT2_ROOTINO) {
- lncntp[ino] = fs2h16(dp->e2di_nlink);
+ lncntp[ino] = letoh16(dp->e2di_nlink);
cacheino(dp, ino);
return(ino);
}
cacheino(dp, ino);
statemap[ino] = statemap[parent];
if (statemap[ino] == DSTATE) {
- lncntp[ino] = fs2h16(dp->e2di_nlink);
+ lncntp[ino] = letoh16(dp->e2di_nlink);
lncntp[parent]++;
}
dp = ginode(parent);
- dp->e2di_nlink = h2fs16(fs2h16(dp->e2di_nlink) + 1);
+ dp->e2di_nlink = htole16(letoh16(dp->e2di_nlink) + 1);
inodirty();
return (ino);
}
if (ino != parent) {
dp = ginode(parent);
- dp->e2di_nlink = h2fs16(fs2h16(dp->e2di_nlink) - 1);
+ dp->e2di_nlink = htole16(letoh16(dp->e2di_nlink) - 1);
inodirty();
}
freeino(ino);
-/* $OpenBSD: inode.c,v 1.21 2014/07/11 13:50:01 pelikan Exp $ */
+/* $OpenBSD: inode.c,v 1.22 2014/07/13 16:08:53 pelikan Exp $ */
/* $NetBSD: inode.c,v 1.8 2000/01/28 16:01:46 bouyer Exp $ */
/*
*/
#define fsck_ino_to_fsba(fs, x) \
- (fs2h32((fs)->e2fs_gd[ino_to_cg(fs, x)].ext2bgd_i_tables) + \
+ (letoh32((fs)->e2fs_gd[ino_to_cg(fs, x)].ext2bgd_i_tables) + \
(((x)-1) % (fs)->e2fs.e2fs_ipg)/(fs)->e2fs_ipb)
static ino_t startinum;
u_int64_t
inosize(struct ext2fs_dinode *dp)
{
- u_int64_t size = fs2h32(dp->e2di_size);
+ u_int64_t size = letoh32(dp->e2di_size);
- if ((fs2h16(dp->e2di_mode) & IFMT) == IFREG)
- size |= (u_int64_t)fs2h32(dp->e2di_size_hi) << 32;
+ if ((letoh16(dp->e2di_mode) & IFMT) == IFREG)
+ size |= (u_int64_t)letoh32(dp->e2di_size_hi) << 32;
if (size >= 0x80000000U)
(void)setlarge();
return size;
void
inossize(struct ext2fs_dinode *dp, u_int64_t size)
{
- if ((fs2h16(dp->e2di_mode) & IFMT) == IFREG) {
- dp->e2di_size_hi = h2fs32(size >> 32);
+ if ((letoh16(dp->e2di_mode) & IFMT) == IFREG) {
+ dp->e2di_size_hi = htole32(size >> 32);
if (size >= 0x80000000U)
if (!setlarge())
return;
} else if (size >= 0x80000000U) {
pfatal("TRYING TO SET FILESIZE TO %llu ON MODE %x FILE\n",
- (unsigned long long)size, fs2h16(dp->e2di_mode) & IFMT);
+ (unsigned long long)size, letoh16(dp->e2di_mode) & IFMT);
return;
}
- dp->e2di_size = h2fs32(size);
+ dp->e2di_size = htole32(size);
}
int
idesc->id_fix = DONTKNOW;
idesc->id_entryno = 0;
idesc->id_filesize = inosize(dp);
- mode = fs2h16(dp->e2di_mode) & IFMT;
+ mode = letoh16(dp->e2di_mode) & IFMT;
if (mode == IFBLK || mode == IFCHR || mode == IFIFO ||
(mode == IFLNK && (inosize(dp) < EXT2_MAXSYMLINKLEN)))
return (KEEPON);
}
continue;
}
- idesc->id_blkno = fs2h32(*ap);
+ idesc->id_blkno = letoh32(*ap);
if (idesc->id_type == ADDR)
ret = (*idesc->id_func)(idesc);
else
sizepb = sblock.e2fs_bsize;
for (ap = &dino.e2di_blocks[NDADDR], n = 1; n <= NIADDR; ap++, n++) {
if (*ap) {
- idesc->id_blkno = fs2h32(*ap);
+ idesc->id_blkno = letoh32(*ap);
ret = iblock(idesc, n, remsize);
if (ret & STOP)
return (ret);
aplim = &bp->b_un.b_indir[nif];
for (ap = bp->b_un.b_indir; ap < aplim; ap++) {
if (*ap) {
- idesc->id_blkno = fs2h32(*ap);
+ idesc->id_blkno = letoh32(*ap);
if (ilevel == 0)
n = (*func)(idesc);
else
struct ext2fs_direct *dirp = idesc->id_dirp;
u_int16_t namlen = dirp->e2d_namlen;
- if (fs2h32(dirp->e2d_ino) != idesc->id_parent)
+ if (letoh32(dirp->e2d_ino) != idesc->id_parent)
return (KEEPON);
memcpy(idesc->id_name, dirp->e2d_name, (size_t)namlen);
idesc->id_name[namlen] = '\0';
findino(struct inodesc *idesc)
{
struct ext2fs_direct *dirp = idesc->id_dirp;
- u_int32_t ino = fs2h32(dirp->e2d_ino);
+ u_int32_t ino = letoh32(dirp->e2d_ino);
if (ino == 0)
return (KEEPON);
return;
dp = ginode(ino);
printf(" OWNER=");
- uid = fs2h16(dp->e2di_uid_low) | (fs2h16(dp->e2di_uid_high) << 16);
+ uid = letoh16(dp->e2di_uid_low) | (letoh16(dp->e2di_uid_high) << 16);
#ifndef SMALL
if ((pw = getpwuid((int)uid)) != 0)
printf("%s ", pw->pw_name);
else
#endif
printf("%u ", (unsigned)uid);
- printf("MODE=%o\n", fs2h16(dp->e2di_mode));
+ printf("MODE=%o\n", letoh16(dp->e2di_mode));
if (preen)
printf("%s: ", cdevname());
printf("SIZE=%llu ", (long long)inosize(dp));
- t = (time_t)fs2h32(dp->e2di_mtime);
+ t = (time_t) letoh32(dp->e2di_mtime);
p = ctime(&t);
printf("MTIME=%12.12s %4.4s ", &p[4], &p[20]);
}
return (0);
}
dp = ginode(ino);
- dp->e2di_blocks[0] = h2fs32(allocblk());
+ dp->e2di_blocks[0] = htole32(allocblk());
if (dp->e2di_blocks[0] == 0) {
statemap[ino] = USTATE;
return (0);
}
- dp->e2di_mode = h2fs16(type);
+ dp->e2di_mode = htole16(type);
(void)time(&t);
- dp->e2di_atime = (u_int32_t)h2fs32(t);
+ dp->e2di_atime = (u_int32_t)htole32(t);
dp->e2di_mtime = dp->e2di_ctime = dp->e2di_atime;
dp->e2di_dtime = 0;
inossize(dp, sblock.e2fs_bsize);
- dp->e2di_nblock = h2fs32(btodb(sblock.e2fs_bsize));
+ dp->e2di_nblock = htole32(btodb(sblock.e2fs_bsize));
n_files++;
inodirty();
typemap[ino] = E2IFTODT(type);
-/* $OpenBSD: pass1.c,v 1.13 2013/04/24 13:46:27 deraadt Exp $ */
+/* $OpenBSD: pass1.c,v 1.14 2014/07/13 16:08:53 pelikan Exp $ */
/* $NetBSD: pass1.c,v 1.9 2000/01/31 11:40:12 bouyer Exp $ */
/*
dbase = c * sblock.e2fs.e2fs_bpg +
sblock.e2fs.e2fs_first_dblock;
/* Mark the blocks used for the inode table */
- if (fs2h32(sblock.e2fs_gd[c].ext2bgd_i_tables) >= dbase) {
+ if (letoh32(sblock.e2fs_gd[c].ext2bgd_i_tables) >= dbase) {
for (i = 0; i < sblock.e2fs_itpg; i++)
setbmap(
- fs2h32(sblock.e2fs_gd[c].ext2bgd_i_tables)
+ letoh32(sblock.e2fs_gd[c].ext2bgd_i_tables)
+ i);
}
/* Mark the blocks used for the block bitmap */
- if (fs2h32(sblock.e2fs_gd[c].ext2bgd_b_bitmap) >= dbase)
- setbmap(fs2h32(sblock.e2fs_gd[c].ext2bgd_b_bitmap));
+ if (letoh32(sblock.e2fs_gd[c].ext2bgd_b_bitmap) >= dbase)
+ setbmap(letoh32(sblock.e2fs_gd[c].ext2bgd_b_bitmap));
/* Mark the blocks used for the inode bitmap */
- if (fs2h32(sblock.e2fs_gd[c].ext2bgd_i_bitmap) >= dbase)
- setbmap(fs2h32(sblock.e2fs_gd[c].ext2bgd_i_bitmap));
+ if (letoh32(sblock.e2fs_gd[c].ext2bgd_i_bitmap) >= dbase)
+ setbmap(letoh32(sblock.e2fs_gd[c].ext2bgd_i_bitmap));
if (sblock.e2fs.e2fs_rev == E2FS_REV0 ||
(sblock.e2fs.e2fs_features_rocompat &
if (inumber < EXT2_FIRSTINO && inumber != EXT2_ROOTINO)
return;
- mode = fs2h16(dp->e2di_mode) & IFMT;
+ mode = letoh16(dp->e2di_mode) & IFMT;
if (mode == 0 || (dp->e2di_dtime != 0 && dp->e2di_nlink == 0)) {
if (mode == 0 && (
memcmp(dp->e2di_blocks, zino.e2di_blocks,
if (preen || reply("CORRECT")) {
time_t t;
time(&t);
- dp->e2di_dtime = h2fs32(t);
+ dp->e2di_dtime = htole32(t);
dp = ginode(inumber);
inodirty();
}
}
lastino = inumber;
if (dp->e2di_dtime != 0) {
- time_t t = fs2h32(dp->e2di_dtime);
+ time_t t = letoh32(dp->e2di_dtime);
char *p = ctime(&t);
pwarn("INODE I=%llu HAS DTIME=%12.12s %4.4s",
(unsigned long long)inumber, &p[4], &p[20]);
}
if (!preen && mode == IFMT && reply("HOLD BAD BLOCK") == 1) {
dp = ginode(inumber);
- dp->e2di_mode = h2fs16(IFREG|0600);
+ dp->e2di_mode = htole16(IFREG|0600);
inossize(dp, sblock.e2fs_bsize);
inodirty();
}
if (dp->e2di_blocks[j] != 0) {
if (debug)
printf("bad direct addr: %d\n",
- fs2h32(dp->e2di_blocks[j]));
+ letoh32(dp->e2di_blocks[j]));
goto unknown;
}
for (j = 0, ndb -= NDADDR; ndb > 0; j++)
if (dp->e2di_blocks[j+NDADDR] != 0) {
if (debug)
printf("bad indirect addr: %d\n",
- fs2h32(dp->e2di_blocks[j+NDADDR]));
+ letoh32(dp->e2di_blocks[j+NDADDR]));
goto unknown;
}
}
if (ftypeok(dp) == 0)
goto unknown;
n_files++;
- lncntp[inumber] = fs2h16(dp->e2di_nlink);
+ lncntp[inumber] = letoh16(dp->e2di_nlink);
if (dp->e2di_nlink == 0) {
zlnp = (struct zlncnt *)malloc(sizeof *zlnp);
if (zlnp == NULL) {
idesc->id_number = inumber;
(void)ckinode(dp, idesc);
idesc->id_entryno *= btodb(sblock.e2fs_bsize);
- if (fs2h32(dp->e2di_nblock) != idesc->id_entryno) {
+ if (letoh32(dp->e2di_nblock) != idesc->id_entryno) {
pwarn("INCORRECT BLOCK COUNT I=%llu (%d should be %d)",
(unsigned long long)inumber,
- fs2h32(dp->e2di_nblock), idesc->id_entryno);
+ letoh32(dp->e2di_nblock), idesc->id_entryno);
if (preen)
printf(" (CORRECTED)\n");
else if (reply("CORRECT") == 0)
return;
dp = ginode(inumber);
- dp->e2di_nblock = h2fs32(idesc->id_entryno);
+ dp->e2di_nblock = htole32(idesc->id_entryno);
inodirty();
}
return;
-/* $OpenBSD: pass2.c,v 1.12 2013/04/24 13:46:27 deraadt Exp $ */
+/* $OpenBSD: pass2.c,v 1.13 2014/07/13 16:08:53 pelikan Exp $ */
/* $NetBSD: pass2.c,v 1.6 2000/01/28 16:01:46 bouyer Exp $ */
/*
if (reply("FIX") == 0)
errexit("%s\n", "");
dp = ginode(EXT2_ROOTINO);
- dp->e2di_mode = h2fs16((fs2h16(dp->e2di_mode) & ~IFMT) | IFDIR);
+ dp->e2di_mode = htole16((letoh16(dp->e2di_mode) & ~IFMT) | IFDIR);
inodirty();
break;
}
}
memset(&dino, 0, sizeof(struct ext2fs_dinode));
- dino.e2di_mode = h2fs16(IFDIR);
+ dino.e2di_mode = htole16(IFDIR);
inossize(&dino, inp->i_isize);
memcpy(&dino.e2di_blocks[0], &inp->i_blks[0], (size_t)inp->i_numblks);
curino.id_number = inp->i_number;
*/
if (idesc->id_entryno != 0)
goto chk1;
- if (fs2h32(dirp->e2d_ino) != 0 && dirp->e2d_namlen == 1 &&
+ if (letoh32(dirp->e2d_ino) != 0 && dirp->e2d_namlen == 1 &&
dirp->e2d_name[0] == '.') {
- if (fs2h32(dirp->e2d_ino) != idesc->id_number) {
+ if (letoh32(dirp->e2d_ino) != idesc->id_number) {
direrror(idesc->id_number, "BAD INODE NUMBER FOR '.'");
- dirp->e2d_ino = h2fs32(idesc->id_number);
+ dirp->e2d_ino = htole32(idesc->id_number);
if (reply("FIX") == 1)
ret |= ALTERED;
}
goto chk1;
}
direrror(idesc->id_number, "MISSING '.'");
- proto.e2d_ino = h2fs32(idesc->id_number);
+ proto.e2d_ino = htole32(idesc->id_number);
proto.e2d_namlen = 1;
if (sblock.e2fs.e2fs_rev > E2FS_REV0 &&
(sblock.e2fs.e2fs_features_incompat & EXT2F_INCOMPAT_FTYPE))
proto.e2d_type = 0;
(void)strlcpy(proto.e2d_name, ".", sizeof proto.e2d_name);
entrysize = EXT2FS_DIRSIZ(proto.e2d_namlen);
- if (fs2h32(dirp->e2d_ino) != 0 && strcmp(dirp->e2d_name, "..") != 0) {
+ if (letoh32(dirp->e2d_ino) != 0 && strcmp(dirp->e2d_name, "..") != 0) {
pfatal("CANNOT FIX, FIRST ENTRY IN DIRECTORY CONTAINS %s\n",
dirp->e2d_name);
- } else if (fs2h16(dirp->e2d_reclen) < entrysize) {
+ } else if (letoh16(dirp->e2d_reclen) < entrysize) {
pfatal("CANNOT FIX, INSUFFICIENT SPACE TO ADD '.'\n");
- } else if (fs2h16(dirp->e2d_reclen) < 2 * entrysize) {
+ } else if (letoh16(dirp->e2d_reclen) < 2 * entrysize) {
proto.e2d_reclen = dirp->e2d_reclen;
memcpy(dirp, &proto, (size_t)entrysize);
if (reply("FIX") == 1)
ret |= ALTERED;
} else {
- n = fs2h16(dirp->e2d_reclen) - entrysize;
- proto.e2d_reclen = h2fs16(entrysize);
+ n = letoh16(dirp->e2d_reclen) - entrysize;
+ proto.e2d_reclen = htole16(entrysize);
memcpy(dirp, &proto, (size_t)entrysize);
idesc->id_entryno++;
- lncntp[fs2h32(dirp->e2d_ino)]--;
+ lncntp[letoh32(dirp->e2d_ino)]--;
dirp = (struct ext2fs_direct *)((char *)(dirp) + entrysize);
memset(dirp, 0, (size_t)n);
- dirp->e2d_reclen = h2fs16(n);
+ dirp->e2d_reclen = htole16(n);
if (reply("FIX") == 1)
ret |= ALTERED;
}
if (idesc->id_entryno > 1)
goto chk2;
inp = getinoinfo(idesc->id_number);
- proto.e2d_ino = h2fs32(inp->i_parent);
+ proto.e2d_ino = htole32(inp->i_parent);
proto.e2d_namlen = 2;
if (sblock.e2fs.e2fs_rev > E2FS_REV0 &&
(sblock.e2fs.e2fs_features_incompat & EXT2F_INCOMPAT_FTYPE))
entrysize = EXT2FS_DIRSIZ(2);
if (idesc->id_entryno == 0) {
n = EXT2FS_DIRSIZ(dirp->e2d_namlen);
- if (fs2h16(dirp->e2d_reclen) < n + entrysize)
+ if (letoh16(dirp->e2d_reclen) < n + entrysize)
goto chk2;
- proto.e2d_reclen = h2fs16(fs2h16(dirp->e2d_reclen) - n);
- dirp->e2d_reclen = h2fs16(n);
+ proto.e2d_reclen = htole16(letoh16(dirp->e2d_reclen) - n);
+ dirp->e2d_reclen = htole16(n);
idesc->id_entryno++;
- lncntp[fs2h32(dirp->e2d_ino)]--;
+ lncntp[letoh32(dirp->e2d_ino)]--;
dirp = (struct ext2fs_direct *)((char *)(dirp) + n);
- memset(dirp, 0, (size_t)fs2h16(proto.e2d_reclen));
+ memset(dirp, 0, (size_t)letoh16(proto.e2d_reclen));
dirp->e2d_reclen = proto.e2d_reclen;
}
- if (fs2h32(dirp->e2d_ino) != 0 &&
+ if (letoh32(dirp->e2d_ino) != 0 &&
dirp->e2d_namlen == 2 &&
strncmp(dirp->e2d_name, "..", 2) == 0) {
- inp->i_dotdot = fs2h32(dirp->e2d_ino);
+ inp->i_dotdot = letoh32(dirp->e2d_ino);
if (sblock.e2fs.e2fs_rev > E2FS_REV0 &&
(sblock.e2fs.e2fs_features_incompat & EXT2F_INCOMPAT_FTYPE)
&& dirp->e2d_type != EXT2_FT_DIR) {
}
goto chk2;
}
- if (fs2h32(dirp->e2d_ino) != 0 &&
+ if (letoh32(dirp->e2d_ino) != 0 &&
dirp->e2d_namlen == 1 &&
strncmp(dirp->e2d_name, ".", 1) != 0) {
fileerror(inp->i_parent, idesc->id_number, "MISSING '..'");
pfatal("CANNOT FIX, SECOND ENTRY IN DIRECTORY CONTAINS %s\n",
dirp->e2d_name);
inp->i_dotdot = (ino_t)-1;
- } else if (fs2h16(dirp->e2d_reclen) < entrysize) {
+ } else if (letoh16(dirp->e2d_reclen) < entrysize) {
fileerror(inp->i_parent, idesc->id_number, "MISSING '..'");
pfatal("CANNOT FIX, INSUFFICIENT SPACE TO ADD '..'\n");
inp->i_dotdot = (ino_t)-1;
ret |= ALTERED;
}
idesc->id_entryno++;
- if (fs2h32(dirp->e2d_ino) != 0)
- lncntp[fs2h32(dirp->e2d_ino)]--;
+ if (letoh32(dirp->e2d_ino) != 0)
+ lncntp[letoh32(dirp->e2d_ino)]--;
return (ret|KEEPON);
chk2:
- if (fs2h32(dirp->e2d_ino) == 0)
+ if (letoh32(dirp->e2d_ino) == 0)
return (ret|KEEPON);
if (dirp->e2d_namlen <= 2 &&
dirp->e2d_name[0] == '.' &&
}
idesc->id_entryno++;
n = 0;
- if (fs2h32(dirp->e2d_ino) > maxino ||
- (fs2h32(dirp->e2d_ino) < EXT2_FIRSTINO &&
- fs2h32(dirp->e2d_ino) != EXT2_ROOTINO)) {
- fileerror(idesc->id_number, fs2h32(dirp->e2d_ino), "I OUT OF RANGE");
+ if (letoh32(dirp->e2d_ino) > maxino ||
+ (letoh32(dirp->e2d_ino) < EXT2_FIRSTINO &&
+ letoh32(dirp->e2d_ino) != EXT2_ROOTINO)) {
+ fileerror(idesc->id_number, letoh32(dirp->e2d_ino), "I OUT OF RANGE");
n = reply("REMOVE");
} else {
again:
- switch (statemap[fs2h32(dirp->e2d_ino)]) {
+ switch (statemap[letoh32(dirp->e2d_ino)]) {
case USTATE:
if (idesc->id_entryno <= 2)
break;
- fileerror(idesc->id_number, fs2h32(dirp->e2d_ino), "UNALLOCATED");
+ fileerror(idesc->id_number, letoh32(dirp->e2d_ino), "UNALLOCATED");
n = reply("REMOVE");
break;
case FCLEAR:
if (idesc->id_entryno <= 2)
break;
- if (statemap[fs2h32(dirp->e2d_ino)] == FCLEAR)
+ if (statemap[letoh32(dirp->e2d_ino)] == FCLEAR)
errmsg = "DUP/BAD";
else if (!preen)
errmsg = "ZERO LENGTH DIRECTORY";
n = 1;
break;
}
- fileerror(idesc->id_number, fs2h32(dirp->e2d_ino), errmsg);
+ fileerror(idesc->id_number, letoh32(dirp->e2d_ino), errmsg);
if ((n = reply("REMOVE")) == 1)
break;
- dp = ginode(fs2h32(dirp->e2d_ino));
- statemap[fs2h32(dirp->e2d_ino)] =
- (fs2h16(dp->e2di_mode) & IFMT) == IFDIR ? DSTATE : FSTATE;
- lncntp[fs2h32(dirp->e2d_ino)] = fs2h16(dp->e2di_nlink);
+ dp = ginode(letoh32(dirp->e2d_ino));
+ statemap[letoh32(dirp->e2d_ino)] =
+ (letoh16(dp->e2di_mode) & IFMT) == IFDIR ? DSTATE : FSTATE;
+ lncntp[letoh32(dirp->e2d_ino)] = letoh16(dp->e2di_nlink);
goto again;
case DSTATE:
case DFOUND:
- inp = getinoinfo(fs2h32(dirp->e2d_ino));
+ inp = getinoinfo(letoh32(dirp->e2d_ino));
if (inp->i_parent != 0 && idesc->id_entryno > 2) {
getpathname(pathbuf, sizeof pathbuf,
idesc->id_number, idesc->id_number);
getpathname(namebuf, sizeof namebuf,
- fs2h32(dirp->e2d_ino), fs2h32(dirp->e2d_ino));
+ letoh32(dirp->e2d_ino), letoh32(dirp->e2d_ino));
pwarn("%s %s %s\n", pathbuf,
"IS AN EXTRANEOUS HARD LINK TO DIRECTORY",
namebuf);
(sblock.e2fs.e2fs_features_incompat &
EXT2F_INCOMPAT_FTYPE) &&
dirp->e2d_type !=
- inot2ext2dt(typemap[fs2h32(dirp->e2d_ino)])) {
+ inot2ext2dt(typemap[letoh32(dirp->e2d_ino)])) {
dirp->e2d_type =
- inot2ext2dt(typemap[fs2h32(dirp->e2d_ino)]);
+ inot2ext2dt(typemap[letoh32(dirp->e2d_ino)]);
fileerror(idesc->id_number,
- fs2h32(dirp->e2d_ino),
+ letoh32(dirp->e2d_ino),
"BAD TYPE VALUE");
if (reply("FIX") == 1)
ret |= ALTERED;
}
- lncntp[fs2h32(dirp->e2d_ino)]--;
+ lncntp[letoh32(dirp->e2d_ino)]--;
break;
default:
errexit("BAD STATE %d FOR INODE I=%llu\n",
- statemap[fs2h32(dirp->e2d_ino)],
- (unsigned long long)fs2h32(dirp->e2d_ino));
+ statemap[letoh32(dirp->e2d_ino)],
+ (unsigned long long)letoh32(dirp->e2d_ino));
}
}
if (n == 0)
-/* $OpenBSD: pass5.c,v 1.16 2013/04/24 13:46:27 deraadt Exp $ */
+/* $OpenBSD: pass5.c,v 1.17 2014/07/13 16:08:53 pelikan Exp $ */
/* $NetBSD: pass5.c,v 1.7 2000/01/28 16:01:46 bouyer Exp $ */
/*
ndirs = 0;
if (blk_bitmap == NULL) {
- blk_bitmap = getdatablk(fs2h32(fs->e2fs_gd[c].ext2bgd_b_bitmap),
+ blk_bitmap = getdatablk(letoh32(fs->e2fs_gd[c].ext2bgd_b_bitmap),
fs->e2fs_bsize);
} else {
- getblk(blk_bitmap, fs2h32(fs->e2fs_gd[c].ext2bgd_b_bitmap),
+ getblk(blk_bitmap, letoh32(fs->e2fs_gd[c].ext2bgd_b_bitmap),
fs->e2fs_bsize);
}
if (ino_bitmap == NULL) {
- ino_bitmap = getdatablk(fs2h32(fs->e2fs_gd[c].ext2bgd_i_bitmap),
+ ino_bitmap = getdatablk(letoh32(fs->e2fs_gd[c].ext2bgd_i_bitmap),
fs->e2fs_bsize);
} else {
- getblk(ino_bitmap, fs2h32(fs->e2fs_gd[c].ext2bgd_i_bitmap),
+ getblk(ino_bitmap, letoh32(fs->e2fs_gd[c].ext2bgd_i_bitmap),
fs->e2fs_bsize);
}
memset(bbmap, 0, fs->e2fs_bsize);
cs_nifree += nifree;
cs_ndir += ndirs;
- if (debug && (fs2h16(fs->e2fs_gd[c].ext2bgd_nbfree) != nbfree ||
- fs2h16(fs->e2fs_gd[c].ext2bgd_nifree) != nifree ||
- fs2h16(fs->e2fs_gd[c].ext2bgd_ndirs) != ndirs)) {
+ if (debug && (letoh16(fs->e2fs_gd[c].ext2bgd_nbfree) != nbfree ||
+ letoh16(fs->e2fs_gd[c].ext2bgd_nifree) != nifree ||
+ letoh16(fs->e2fs_gd[c].ext2bgd_ndirs) != ndirs)) {
printf("summary info for cg %d is %d, %d, %d,"
"should be %d, %d, %d\n", c,
- fs2h16(fs->e2fs_gd[c].ext2bgd_nbfree),
- fs2h16(fs->e2fs_gd[c].ext2bgd_nifree),
- fs2h16(fs->e2fs_gd[c].ext2bgd_ndirs),
+ letoh16(fs->e2fs_gd[c].ext2bgd_nbfree),
+ letoh16(fs->e2fs_gd[c].ext2bgd_nifree),
+ letoh16(fs->e2fs_gd[c].ext2bgd_ndirs),
nbfree,
nifree,
ndirs);
}
(void)snprintf(msg, sizeof(msg),
"SUMMARY INFORMATIONS WRONG FOR CG #%d", c);
- if ((fs2h16(fs->e2fs_gd[c].ext2bgd_nbfree) != nbfree ||
- fs2h16(fs->e2fs_gd[c].ext2bgd_nifree) != nifree ||
- fs2h16(fs->e2fs_gd[c].ext2bgd_ndirs) != ndirs) &&
+ if ((letoh16(fs->e2fs_gd[c].ext2bgd_nbfree) != nbfree ||
+ letoh16(fs->e2fs_gd[c].ext2bgd_nifree) != nifree ||
+ letoh16(fs->e2fs_gd[c].ext2bgd_ndirs) != ndirs) &&
dofix(&idesc[0], msg)) {
- fs->e2fs_gd[c].ext2bgd_nbfree = h2fs16(nbfree);
- fs->e2fs_gd[c].ext2bgd_nifree = h2fs16(nifree);
- fs->e2fs_gd[c].ext2bgd_ndirs = h2fs16(ndirs);
+ fs->e2fs_gd[c].ext2bgd_nbfree = htole16(nbfree);
+ fs->e2fs_gd[c].ext2bgd_nifree = htole16(nifree);
+ fs->e2fs_gd[c].ext2bgd_ndirs = htole16(ndirs);
sbdirty();
}
-/* $OpenBSD: setup.c,v 1.22 2014/07/13 13:50:00 pelikan Exp $ */
+/* $OpenBSD: setup.c,v 1.23 2014/07/13 16:08:53 pelikan Exp $ */
/* $NetBSD: setup.c,v 1.1 1997/06/11 11:22:01 bouyer Exp $ */
/*
goto badsblabel;
}
for (numdirs = 0, cg = 0; cg < sblock.e2fs_ncg; cg++) {
- numdirs += fs2h16(sblock.e2fs_gd[cg].ext2bgd_ndirs);
+ numdirs += letoh16(sblock.e2fs_gd[cg].ext2bgd_ndirs);
}
inplast = 0;
listmax = numdirs + 10;
continue;
printf("offset %ld, original %ld, alternate %ld\n",
(long)(olp - (u_int32_t *)sblk.b_un.b_fs),
- (long)fs2h32(*olp),
- (long)fs2h32(*nlp));
+ (long)letoh32(*olp),
+ (long)letoh32(*nlp));
}
}
badsb(listerr,
copyback_sb(struct bufarea *bp)
{
/* Copy the in-memory superblock back to buffer */
- bp->b_un.b_fs->e2fs_icount = fs2h32(sblock.e2fs.e2fs_icount);
- bp->b_un.b_fs->e2fs_bcount = fs2h32(sblock.e2fs.e2fs_bcount);
- bp->b_un.b_fs->e2fs_rbcount = fs2h32(sblock.e2fs.e2fs_rbcount);
- bp->b_un.b_fs->e2fs_fbcount = fs2h32(sblock.e2fs.e2fs_fbcount);
- bp->b_un.b_fs->e2fs_ficount = fs2h32(sblock.e2fs.e2fs_ficount);
+ bp->b_un.b_fs->e2fs_icount = letoh32(sblock.e2fs.e2fs_icount);
+ bp->b_un.b_fs->e2fs_bcount = letoh32(sblock.e2fs.e2fs_bcount);
+ bp->b_un.b_fs->e2fs_rbcount = letoh32(sblock.e2fs.e2fs_rbcount);
+ bp->b_un.b_fs->e2fs_fbcount = letoh32(sblock.e2fs.e2fs_fbcount);
+ bp->b_un.b_fs->e2fs_ficount = letoh32(sblock.e2fs.e2fs_ficount);
bp->b_un.b_fs->e2fs_first_dblock =
- fs2h32(sblock.e2fs.e2fs_first_dblock);
- bp->b_un.b_fs->e2fs_log_bsize = fs2h32(sblock.e2fs.e2fs_log_bsize);
- bp->b_un.b_fs->e2fs_log_fsize = fs2h32(sblock.e2fs.e2fs_log_fsize);
- bp->b_un.b_fs->e2fs_bpg = fs2h32(sblock.e2fs.e2fs_bpg);
- bp->b_un.b_fs->e2fs_fpg = fs2h32(sblock.e2fs.e2fs_fpg);
- bp->b_un.b_fs->e2fs_ipg = fs2h32(sblock.e2fs.e2fs_ipg);
- bp->b_un.b_fs->e2fs_mtime = fs2h32(sblock.e2fs.e2fs_mtime);
- bp->b_un.b_fs->e2fs_wtime = fs2h32(sblock.e2fs.e2fs_wtime);
- bp->b_un.b_fs->e2fs_lastfsck = fs2h32(sblock.e2fs.e2fs_lastfsck);
- bp->b_un.b_fs->e2fs_fsckintv = fs2h32(sblock.e2fs.e2fs_fsckintv);
- bp->b_un.b_fs->e2fs_creator = fs2h32(sblock.e2fs.e2fs_creator);
- bp->b_un.b_fs->e2fs_rev = fs2h32(sblock.e2fs.e2fs_rev);
- bp->b_un.b_fs->e2fs_mnt_count = fs2h16(sblock.e2fs.e2fs_mnt_count);
+ letoh32(sblock.e2fs.e2fs_first_dblock);
+ bp->b_un.b_fs->e2fs_log_bsize = letoh32(sblock.e2fs.e2fs_log_bsize);
+ bp->b_un.b_fs->e2fs_log_fsize = letoh32(sblock.e2fs.e2fs_log_fsize);
+ bp->b_un.b_fs->e2fs_bpg = letoh32(sblock.e2fs.e2fs_bpg);
+ bp->b_un.b_fs->e2fs_fpg = letoh32(sblock.e2fs.e2fs_fpg);
+ bp->b_un.b_fs->e2fs_ipg = letoh32(sblock.e2fs.e2fs_ipg);
+ bp->b_un.b_fs->e2fs_mtime = letoh32(sblock.e2fs.e2fs_mtime);
+ bp->b_un.b_fs->e2fs_wtime = letoh32(sblock.e2fs.e2fs_wtime);
+ bp->b_un.b_fs->e2fs_lastfsck = letoh32(sblock.e2fs.e2fs_lastfsck);
+ bp->b_un.b_fs->e2fs_fsckintv = letoh32(sblock.e2fs.e2fs_fsckintv);
+ bp->b_un.b_fs->e2fs_creator = letoh32(sblock.e2fs.e2fs_creator);
+ bp->b_un.b_fs->e2fs_rev = letoh32(sblock.e2fs.e2fs_rev);
+ bp->b_un.b_fs->e2fs_mnt_count = letoh16(sblock.e2fs.e2fs_mnt_count);
bp->b_un.b_fs->e2fs_max_mnt_count =
- fs2h16(sblock.e2fs.e2fs_max_mnt_count);
- bp->b_un.b_fs->e2fs_magic = fs2h16(sblock.e2fs.e2fs_magic);
- bp->b_un.b_fs->e2fs_state = fs2h16(sblock.e2fs.e2fs_state);
- bp->b_un.b_fs->e2fs_beh = fs2h16(sblock.e2fs.e2fs_beh);
- bp->b_un.b_fs->e2fs_ruid = fs2h16(sblock.e2fs.e2fs_ruid);
- bp->b_un.b_fs->e2fs_rgid = fs2h16(sblock.e2fs.e2fs_rgid);
+ letoh16(sblock.e2fs.e2fs_max_mnt_count);
+ bp->b_un.b_fs->e2fs_magic = letoh16(sblock.e2fs.e2fs_magic);
+ bp->b_un.b_fs->e2fs_state = letoh16(sblock.e2fs.e2fs_state);
+ bp->b_un.b_fs->e2fs_beh = letoh16(sblock.e2fs.e2fs_beh);
+ bp->b_un.b_fs->e2fs_ruid = letoh16(sblock.e2fs.e2fs_ruid);
+ bp->b_un.b_fs->e2fs_rgid = letoh16(sblock.e2fs.e2fs_rgid);
}
void
-/* $OpenBSD: utilities.c,v 1.22 2014/05/24 14:54:49 krw Exp $ */
+/* $OpenBSD: utilities.c,v 1.23 2014/07/13 16:08:53 pelikan Exp $ */
/* $NetBSD: utilities.c,v 1.6 2001/02/04 21:19:34 christos Exp $ */
/*
int
ftypeok(struct ext2fs_dinode *dp)
{
- switch (fs2h16(dp->e2di_mode) & IFMT) {
+ switch (letoh16(dp->e2di_mode) & IFMT) {
case IFDIR:
case IFREG:
default:
if (debug)
- printf("bad file type 0%o\n", fs2h16(dp->e2di_mode));
+ printf("bad file type 0%o\n", letoh16(dp->e2di_mode));
return (0);
}
}