Move the header part of struct lfs_direct to its own structure.
(lfs_dirheader) Take the opportunity to improve the directory generation code in make_lfs.c. (Everything else was unaffected by virtue of using accessor functions.)
This commit is contained in:
parent
5a97d9e5b6
commit
c2c4048b2d
|
@ -1,4 +1,4 @@
|
||||||
/* $NetBSD: make_lfs.c,v 1.50 2015/09/15 14:58:05 dholland Exp $ */
|
/* $NetBSD: make_lfs.c,v 1.51 2015/09/15 14:59:58 dholland Exp $ */
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* Copyright (c) 2003 The NetBSD Foundation, Inc.
|
* Copyright (c) 2003 The NetBSD Foundation, Inc.
|
||||||
|
@ -62,7 +62,7 @@
|
||||||
#if 0
|
#if 0
|
||||||
static char sccsid[] = "@(#)lfs.c 8.5 (Berkeley) 5/24/95";
|
static char sccsid[] = "@(#)lfs.c 8.5 (Berkeley) 5/24/95";
|
||||||
#else
|
#else
|
||||||
__RCSID("$NetBSD: make_lfs.c,v 1.50 2015/09/15 14:58:05 dholland Exp $");
|
__RCSID("$NetBSD: make_lfs.c,v 1.51 2015/09/15 14:59:58 dholland Exp $");
|
||||||
#endif
|
#endif
|
||||||
#endif /* not lint */
|
#endif /* not lint */
|
||||||
|
|
||||||
|
@ -242,63 +242,32 @@ static const struct lfs lfs_default;
|
||||||
|
|
||||||
#define UMASK 0755
|
#define UMASK 0755
|
||||||
|
|
||||||
struct lfs_direct lfs_root_dir[] = {
|
struct dirproto {
|
||||||
{
|
ino_t dp_ino;
|
||||||
.d_ino = ULFS_ROOTINO,
|
const char *dp_name;
|
||||||
.d_reclen = sizeof(struct lfs_direct),
|
unsigned dp_type;
|
||||||
.d_type = LFS_DT_DIR,
|
};
|
||||||
.d_namlen = 1,
|
|
||||||
.d_name = "."
|
static const struct dirproto lfs_root_dir[] = {
|
||||||
},
|
{ ULFS_ROOTINO, ".", LFS_DT_DIR },
|
||||||
{
|
{ ULFS_ROOTINO, "..", LFS_DT_DIR },
|
||||||
.d_ino = ULFS_ROOTINO,
|
/*{ LFS_IFILE_INUM, "ifile", LFS_DT_REG },*/
|
||||||
.d_reclen = sizeof(struct lfs_direct),
|
|
||||||
.d_type = LFS_DT_DIR,
|
|
||||||
.d_namlen = 2,
|
|
||||||
.d_name = ".."
|
|
||||||
},
|
|
||||||
/*
|
|
||||||
{
|
|
||||||
.d_ino = LFS_IFILE_INUM,
|
|
||||||
.d_reclen = sizeof(struct lfs_direct),
|
|
||||||
.d_type = LFS_DT_REG,
|
|
||||||
.d_namlen = 5,
|
|
||||||
.d_name = "ifile"
|
|
||||||
},
|
|
||||||
*/
|
|
||||||
#ifdef MAKE_LF_DIR
|
#ifdef MAKE_LF_DIR
|
||||||
{
|
{ LOSTFOUNDINO, "lost+found", LFS_DT_DIR },
|
||||||
.d_ino = LOSTFOUNDINO,
|
|
||||||
.d_reclen = sizeof(struct lfs_direct),
|
|
||||||
.d_type = LFS_DT_DIR,
|
|
||||||
.d_namlen = 10,
|
|
||||||
.d_name = "lost+found"
|
|
||||||
},
|
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef MAKE_LF_DIR
|
#ifdef MAKE_LF_DIR
|
||||||
struct lfs_direct lfs_lf_dir[] = {
|
static const struct dirproto lfs_lf_dir[] = {
|
||||||
{
|
{ LOSTFOUNDINO, ".", LFS_DT_DIR },
|
||||||
.d_ino = LOSTFOUNDINO,
|
{ ULFS_ROOTINO, "..", LFS_DT_DIR },
|
||||||
.d_reclen = sizeof(struct lfs_direct),
|
|
||||||
.d_type = LFS_DT_DIR,
|
|
||||||
.d_reclen = 1,
|
|
||||||
.d_name = "."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
.d_ino = ULFS_ROOTINO,
|
|
||||||
.d_reclen = sizeof(struct lfs_direct),
|
|
||||||
.d_type = LFS_DT_DIR,
|
|
||||||
.d_reclen = 2,
|
|
||||||
.d_name = ".."
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void pwarn(const char *, ...);
|
void pwarn(const char *, ...);
|
||||||
static void make_dinode(ino_t, union lfs_dinode *, int, struct lfs *);
|
static void make_dinode(ino_t, union lfs_dinode *, int, struct lfs *);
|
||||||
static void make_dir(struct lfs *, void *, struct lfs_direct *, int);
|
static void make_dir(struct lfs *, void *,
|
||||||
|
const struct dirproto *, unsigned);
|
||||||
static uint64_t maxfilesize(int);
|
static uint64_t maxfilesize(int);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -385,23 +354,42 @@ make_dinode(ino_t ino, union lfs_dinode *dip, int nfrags, struct lfs *fs)
|
||||||
* entries in protodir fit in the first DIRBLKSIZ.
|
* entries in protodir fit in the first DIRBLKSIZ.
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
make_dir(struct lfs *fs, void *bufp, struct lfs_direct *protodir, int entries)
|
make_dir(struct lfs *fs, void *bufp,
|
||||||
|
const struct dirproto *protodir, unsigned numentries)
|
||||||
{
|
{
|
||||||
char *cp;
|
struct lfs_direct *ep;
|
||||||
int i, spcleft;
|
unsigned spaceleft;
|
||||||
unsigned reclen;
|
unsigned namlen, reclen;
|
||||||
|
unsigned i;
|
||||||
|
char *pad;
|
||||||
|
|
||||||
spcleft = LFS_DIRBLKSIZ;
|
spaceleft = LFS_DIRBLKSIZ;
|
||||||
for (cp = bufp, i = 0; i < entries - 1; i++) {
|
ep = bufp;
|
||||||
reclen = LFS_DIRSIZ(fs, &protodir[i]);
|
for (i = 0; i < numentries; i++) {
|
||||||
lfs_dir_setreclen(fs, &protodir[i], reclen);
|
namlen = strlen(protodir[i].dp_name);
|
||||||
memmove(cp, &protodir[i], lfs_dir_getreclen(fs, &protodir[i]));
|
reclen = LFS_DIRECTSIZ(namlen);
|
||||||
cp += reclen;
|
if (spaceleft < reclen)
|
||||||
if ((spcleft -= reclen) < 0)
|
|
||||||
fatal("%s: %s", special, "directory too big");
|
fatal("%s: %s", special, "directory too big");
|
||||||
|
|
||||||
|
/* Last entry includes all the free space. */
|
||||||
|
if (i + 1 == numentries) {
|
||||||
|
reclen = spaceleft;
|
||||||
|
}
|
||||||
|
spaceleft -= reclen;
|
||||||
|
|
||||||
|
lfs_dir_setino(fs, ep, protodir[i].dp_ino);
|
||||||
|
lfs_dir_setreclen(fs, ep, reclen);
|
||||||
|
lfs_dir_settype(fs, ep, protodir[i].dp_type);
|
||||||
|
lfs_dir_setnamlen(fs, ep, namlen);
|
||||||
|
memcpy(ep->d_name, protodir[i].dp_name, namlen);
|
||||||
|
pad = ep->d_name + namlen;
|
||||||
|
ep = LFS_NEXTDIR(fs, ep);
|
||||||
|
|
||||||
|
while (pad < (char *)ep) {
|
||||||
|
*pad++ = '\0';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
lfs_dir_setreclen(fs, &protodir[i], spcleft);
|
assert(spaceleft == 0);
|
||||||
memmove(cp, &protodir[i], LFS_DIRSIZ(fs, &protodir[i]));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -838,8 +826,7 @@ make_lfs(int devfd, uint secsize, struct dkwedge_info *dkw, int minfree,
|
||||||
VTOI(vp)->i_lfs_fragsize[i - 1] =
|
VTOI(vp)->i_lfs_fragsize[i - 1] =
|
||||||
roundup(LFS_DIRBLKSIZ, lfs_sb_getfsize(fs));
|
roundup(LFS_DIRBLKSIZ, lfs_sb_getfsize(fs));
|
||||||
bread(vp, 0, lfs_sb_getfsize(fs), 0, &bp);
|
bread(vp, 0, lfs_sb_getfsize(fs), 0, &bp);
|
||||||
make_dir(fs, bp->b_data, lfs_root_dir,
|
make_dir(fs, bp->b_data, lfs_root_dir, __arraycount(lfs_root_dir));
|
||||||
sizeof(lfs_root_dir) / sizeof(struct lfs_direct));
|
|
||||||
VOP_BWRITE(bp);
|
VOP_BWRITE(bp);
|
||||||
|
|
||||||
#ifdef MAKE_LF_DIR
|
#ifdef MAKE_LF_DIR
|
||||||
|
@ -858,8 +845,7 @@ make_lfs(int devfd, uint secsize, struct dkwedge_info *dkw, int minfree,
|
||||||
VTOI(vp)->i_lfs_fragsize[i - 1] =
|
VTOI(vp)->i_lfs_fragsize[i - 1] =
|
||||||
roundup(DIRBLKSIZ,fs->lfs_fsize);
|
roundup(DIRBLKSIZ,fs->lfs_fsize);
|
||||||
bread(vp, 0, fs->lfs_fsize, 0, &bp);
|
bread(vp, 0, fs->lfs_fsize, 0, &bp);
|
||||||
make_dir(fs, bp->b_data, lfs_lf_dir,
|
make_dir(fs, bp->b_data, lfs_lf_dir, __arraycount(lfs_lf_dir));
|
||||||
sizeof(lfs_lf_dir) / sizeof(struct lfs_direct));
|
|
||||||
VOP_BWRITE(bp);
|
VOP_BWRITE(bp);
|
||||||
#endif /* MAKE_LF_DIR */
|
#endif /* MAKE_LF_DIR */
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* $NetBSD: lfs.h,v 1.186 2015/09/15 14:58:06 dholland Exp $ */
|
/* $NetBSD: lfs.h,v 1.187 2015/09/15 14:59:58 dholland Exp $ */
|
||||||
|
|
||||||
/* from NetBSD: dinode.h,v 1.22 2013/01/22 09:39:18 dholland Exp */
|
/* from NetBSD: dinode.h,v 1.22 2013/01/22 09:39:18 dholland Exp */
|
||||||
/* from NetBSD: dir.h,v 1.21 2009/07/22 04:49:19 dholland Exp */
|
/* from NetBSD: dir.h,v 1.21 2009/07/22 04:49:19 dholland Exp */
|
||||||
|
@ -365,11 +365,14 @@
|
||||||
/*
|
/*
|
||||||
* (See notes above)
|
* (See notes above)
|
||||||
*/
|
*/
|
||||||
|
struct lfs_dirheader {
|
||||||
|
u_int32_t dh_ino; /* inode number of entry */
|
||||||
|
u_int16_t dh_reclen; /* length of this record */
|
||||||
|
u_int8_t dh_type; /* file type, see below */
|
||||||
|
u_int8_t dh_namlen; /* length of string in d_name */
|
||||||
|
};
|
||||||
struct lfs_direct {
|
struct lfs_direct {
|
||||||
u_int32_t d_ino; /* inode number of entry */
|
struct lfs_dirheader d_header;
|
||||||
u_int16_t d_reclen; /* length of this record */
|
|
||||||
u_int8_t d_type; /* file type, see below */
|
|
||||||
u_int8_t d_namlen; /* length of string in d_name */
|
|
||||||
char d_name[LFS_MAXNAMLEN + 1];/* name with length <= LFS_MAXNAMLEN */
|
char d_name[LFS_MAXNAMLEN + 1];/* name with length <= LFS_MAXNAMLEN */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* $NetBSD: lfs_accessors.h,v 1.23 2015/09/15 14:58:06 dholland Exp $ */
|
/* $NetBSD: lfs_accessors.h,v 1.24 2015/09/15 14:59:58 dholland Exp $ */
|
||||||
|
|
||||||
/* from NetBSD: lfs.h,v 1.165 2015/07/24 06:59:32 dholland Exp */
|
/* from NetBSD: lfs.h,v 1.165 2015/07/24 06:59:32 dholland Exp */
|
||||||
/* from NetBSD: dinode.h,v 1.22 2013/01/22 09:39:18 dholland Exp */
|
/* from NetBSD: dinode.h,v 1.22 2013/01/22 09:39:18 dholland Exp */
|
||||||
|
@ -247,13 +247,13 @@
|
||||||
static __unused inline uint32_t
|
static __unused inline uint32_t
|
||||||
lfs_dir_getino(const STRUCT_LFS *fs, const struct lfs_direct *dp)
|
lfs_dir_getino(const STRUCT_LFS *fs, const struct lfs_direct *dp)
|
||||||
{
|
{
|
||||||
return LFS_SWAP_uint32_t(fs, dp->d_ino);
|
return LFS_SWAP_uint32_t(fs, dp->d_header.dh_ino);
|
||||||
}
|
}
|
||||||
|
|
||||||
static __unused inline uint16_t
|
static __unused inline uint16_t
|
||||||
lfs_dir_getreclen(const STRUCT_LFS *fs, const struct lfs_direct *dp)
|
lfs_dir_getreclen(const STRUCT_LFS *fs, const struct lfs_direct *dp)
|
||||||
{
|
{
|
||||||
return LFS_SWAP_uint16_t(fs, dp->d_reclen);
|
return LFS_SWAP_uint16_t(fs, dp->d_header.dh_reclen);
|
||||||
}
|
}
|
||||||
|
|
||||||
static __unused inline uint8_t
|
static __unused inline uint8_t
|
||||||
|
@ -262,7 +262,7 @@ lfs_dir_gettype(const STRUCT_LFS *fs, const struct lfs_direct *dp)
|
||||||
if (fs->lfs_hasolddirfmt) {
|
if (fs->lfs_hasolddirfmt) {
|
||||||
return LFS_DT_UNKNOWN;
|
return LFS_DT_UNKNOWN;
|
||||||
}
|
}
|
||||||
return dp->d_type;
|
return dp->d_header.dh_type;
|
||||||
}
|
}
|
||||||
|
|
||||||
static __unused inline uint8_t
|
static __unused inline uint8_t
|
||||||
|
@ -270,21 +270,21 @@ lfs_dir_getnamlen(const STRUCT_LFS *fs, const struct lfs_direct *dp)
|
||||||
{
|
{
|
||||||
if (fs->lfs_hasolddirfmt && LFS_LITTLE_ENDIAN_ONDISK(fs)) {
|
if (fs->lfs_hasolddirfmt && LFS_LITTLE_ENDIAN_ONDISK(fs)) {
|
||||||
/* low-order byte of old 16-bit namlen field */
|
/* low-order byte of old 16-bit namlen field */
|
||||||
return dp->d_type;
|
return dp->d_header.dh_type;
|
||||||
}
|
}
|
||||||
return dp->d_namlen;
|
return dp->d_header.dh_namlen;
|
||||||
}
|
}
|
||||||
|
|
||||||
static __unused inline void
|
static __unused inline void
|
||||||
lfs_dir_setino(STRUCT_LFS *fs, struct lfs_direct *dp, uint32_t ino)
|
lfs_dir_setino(STRUCT_LFS *fs, struct lfs_direct *dp, uint32_t ino)
|
||||||
{
|
{
|
||||||
dp->d_ino = LFS_SWAP_uint32_t(fs, ino);
|
dp->d_header.dh_ino = LFS_SWAP_uint32_t(fs, ino);
|
||||||
}
|
}
|
||||||
|
|
||||||
static __unused inline void
|
static __unused inline void
|
||||||
lfs_dir_setreclen(STRUCT_LFS *fs, struct lfs_direct *dp, uint16_t reclen)
|
lfs_dir_setreclen(STRUCT_LFS *fs, struct lfs_direct *dp, uint16_t reclen)
|
||||||
{
|
{
|
||||||
dp->d_reclen = LFS_SWAP_uint16_t(fs, reclen);
|
dp->d_header.dh_reclen = LFS_SWAP_uint16_t(fs, reclen);
|
||||||
}
|
}
|
||||||
|
|
||||||
static __unused inline void
|
static __unused inline void
|
||||||
|
@ -294,7 +294,7 @@ lfs_dir_settype(const STRUCT_LFS *fs, struct lfs_direct *dp, uint8_t type)
|
||||||
/* do nothing */
|
/* do nothing */
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
dp->d_type = type;
|
dp->d_header.dh_type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
static __unused inline void
|
static __unused inline void
|
||||||
|
@ -302,9 +302,9 @@ lfs_dir_setnamlen(const STRUCT_LFS *fs, struct lfs_direct *dp, uint8_t namlen)
|
||||||
{
|
{
|
||||||
if (fs->lfs_hasolddirfmt && LFS_LITTLE_ENDIAN_ONDISK(fs)) {
|
if (fs->lfs_hasolddirfmt && LFS_LITTLE_ENDIAN_ONDISK(fs)) {
|
||||||
/* low-order byte of old 16-bit namlen field */
|
/* low-order byte of old 16-bit namlen field */
|
||||||
dp->d_type = namlen;
|
dp->d_header.dh_type = namlen;
|
||||||
}
|
}
|
||||||
dp->d_namlen = namlen;
|
dp->d_header.dh_namlen = namlen;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Reference in New Issue