本文整理汇总了C++中NINDIR函数的典型用法代码示例。如果您正苦于以下问题:C++ NINDIR函数的具体用法?C++ NINDIR怎么用?C++ NINDIR使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NINDIR函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: virtualblocks
static int virtualblocks(struct fs *super, union dinode *dp)
{
off_t nblk, sz;
sz = DIP(super, dp, di_size);
#ifdef COMPAT
if (lblkno(super,sz) >= NDADDR) {
nblk = blkroundup(super,sz);
if (sz == nblk)
nblk += super->fs_bsize;
}
return sz / 1024;
#else /* COMPAT */
if (lblkno(super,sz) >= NDADDR) {
nblk = blkroundup(super,sz);
sz = lblkno(super,nblk);
sz = (sz - NDADDR + NINDIR(super) - 1) / NINDIR(super);
while (sz > 0) {
nblk += sz * super->fs_bsize;
/* sz - 1 rounded up */
sz = (sz - 1 + NINDIR(super) - 1) / NINDIR(super);
}
} else
nblk = fragroundup(super,sz);
return nblk / 512;
#endif /* COMPAT */
}
开发者ID:Alkzndr,项目名称:freebsd,代码行数:31,代码来源:quot.c
示例2: dmpindir
/*
* Read indirect blocks, and pass the data blocks to be dumped.
*/
static void
dmpindir(ino_t ino, daddr_t blk, int ind_level, off_t *size)
{
int i, cnt;
char idblk[MAXBSIZE];
if (blk != 0)
bread(fsbtodb(sblock, blk), idblk, (int) sblock->fs_bsize);
else
memset(idblk, 0, (int)sblock->fs_bsize);
if (ind_level <= 0) {
if (*size < NINDIR(sblock) * sblock->fs_bsize)
cnt = howmany(*size, sblock->fs_fsize);
else
cnt = NINDIR(sblock) * sblock->fs_frag;
*size -= NINDIR(sblock) * sblock->fs_bsize;
if (sblock->fs_magic == FS_UFS1_MAGIC)
ufs1_blksout((int32_t *)idblk, cnt, ino);
else
ufs2_blksout((int64_t *)idblk, cnt, ino);
return;
}
ind_level--;
for (i = 0; i < NINDIR(sblock); i++) {
if (sblock->fs_magic == FS_UFS1_MAGIC)
dmpindir(ino, ((int32_t *)idblk)[i], ind_level,
size);
else
dmpindir(ino, ((int64_t *)idblk)[i], ind_level,
size);
if (*size <= 0)
return;
}
}
开发者ID:darksoul42,项目名称:bitrig,代码行数:37,代码来源:traverse.c
示例3: dmpindir
/*
* Read indirect blocks, and pass the data blocks to be dumped.
*/
static void
dmpindir(ufs1_ino_t ino, daddr_t blk, int ind_level, fsizeT *size)
{
int i, cnt;
daddr_t idblk[MAXNINDIR];
if (blk != 0)
bread(fsbtodb(sblock, blk), (char *)idblk, (int) sblock->fs_bsize);
else
memset(idblk, 0, (int)sblock->fs_bsize);
if (ind_level <= 0) {
if (*size < NINDIR(sblock) * sblock->fs_bsize)
cnt = howmany(*size, sblock->fs_fsize);
else
cnt = NINDIR(sblock) * sblock->fs_frag;
*size -= NINDIR(sblock) * sblock->fs_bsize;
blksout(&idblk[0], cnt, ino);
return;
}
ind_level--;
for (i = 0; i < NINDIR(sblock); i++) {
dmpindir(ino, idblk[i], ind_level, size);
if (*size <= 0)
return;
}
}
开发者ID:juanfra684,项目名称:DragonFlyBSD,代码行数:29,代码来源:traverse.c
示例4: dirindir
/*
* Read indirect blocks, and pass the data blocks to be searched
* as directories. Quit as soon as any entry is found that will
* require the directory to be dumped.
*/
static int
dirindir(ino_t ino, daddr64_t blkno, int ind_level, off_t *filesize)
{
int ret = 0;
int i;
char idblk[MAXBSIZE];
bread(fsbtodb(sblock, blkno), idblk, (int)sblock->fs_bsize);
if (ind_level <= 0) {
for (i = 0; *filesize > 0 && i < NINDIR(sblock); i++) {
if (sblock->fs_magic == FS_UFS1_MAGIC)
blkno = ((int32_t *)idblk)[i];
else
blkno = ((int64_t *)idblk)[i];
if (blkno != 0)
ret |= searchdir(ino, blkno, sblock->fs_bsize,
*filesize);
if (ret & HASDUMPEDFILE)
*filesize = 0;
else
*filesize -= sblock->fs_bsize;
}
return (ret);
}
ind_level--;
for (i = 0; *filesize > 0 && i < NINDIR(sblock); i++) {
if (sblock->fs_magic == FS_UFS1_MAGIC)
blkno = ((int32_t *)idblk)[i];
else
blkno = ((int64_t *)idblk)[i];
if (blkno != 0)
ret |= dirindir(ino, blkno, ind_level, filesize);
}
return (ret);
}
开发者ID:repos-holder,项目名称:openbsd-patches,代码行数:40,代码来源:traverse.c
示例5: dirindir
/*
* Read indirect blocks, and pass the data blocks to be searched
* as directories. Quit as soon as any entry is found that will
* require the directory to be dumped.
*/
static int
dirindir(ufs1_ino_t ino, daddr_t blkno, int ind_level, long *filesize,
long *tape_size, int nodump)
{
int ret = 0;
int i;
daddr_t idblk[MAXNINDIR];
bread(fsbtodb(sblock, blkno), (char *)idblk, (int)sblock->fs_bsize);
if (ind_level <= 0) {
for (i = 0; *filesize > 0 && i < NINDIR(sblock); i++) {
blkno = idblk[i];
if (blkno != 0) {
ret |= searchdir(ino, blkno, sblock->fs_bsize,
*filesize, tape_size, nodump);
}
if (ret & HASDUMPEDFILE)
*filesize = 0;
else
*filesize -= sblock->fs_bsize;
}
return (ret);
}
ind_level--;
for (i = 0; *filesize > 0 && i < NINDIR(sblock); i++) {
blkno = idblk[i];
if (blkno != 0) {
ret |= dirindir(ino, blkno, ind_level, filesize,
tape_size, nodump);
}
}
return (ret);
}
开发者ID:juanfra684,项目名称:DragonFlyBSD,代码行数:38,代码来源:traverse.c
示例6: make_dinode
/*
* Create the root directory for this file system and the lost+found
* directory.
*/
static void
make_dinode(ino_t ino, struct ufs1_dinode *dip, int nfrags, struct lfs *fs)
{
int fsb_per_blk, i;
int nblocks, bb, base, factor, lvl;
nblocks = howmany(nfrags, fs->lfs_frag);
if(nblocks >= NDADDR)
nfrags = roundup(nfrags, fs->lfs_frag);
dip->di_nlink = 1;
dip->di_blocks = fragstofsb(fs, nfrags);
dip->di_size = (nfrags << fs->lfs_ffshift);
dip->di_atime = dip->di_mtime = dip->di_ctime = fs->lfs_tstamp;
dip->di_atimensec = dip->di_mtimensec = dip->di_ctimensec = 0;
dip->di_inumber = ino;
dip->di_gen = 1;
fsb_per_blk = fragstofsb(fs, blkstofrags(fs, 1));
if (NDADDR < nblocks) {
/* Count up how many indirect blocks we need, recursively */
/* XXX We are only called with nblocks > 1 for Ifile */
bb = nblocks - NDADDR;
while (bb > 0) {
bb = howmany(bb, NINDIR(fs));
ifibc += bb;
--bb;
}
dip->di_blocks += fragstofsb(fs, blkstofrags(fs, ifibc));
}
/* Assign the block addresses for the ifile */
for (i = 0; i < MIN(nblocks,NDADDR); i++) {
dip->di_db[i] = 0x0;
}
if(nblocks > NDADDR) {
dip->di_ib[0] = 0x0;
bb = howmany(nblocks - NDADDR, NINDIR(fs)) - 1;
factor = NINDIR(fs);
base = -NDADDR - factor;
lvl = 1;
while (bb > 0) {
dip->di_ib[lvl] = 0x0;
bb = howmany(bb, NINDIR(fs));
--bb;
factor *= NINDIR(fs);
base -= factor;
++lvl;
}
}
}
开发者ID:lacombar,项目名称:netbsd-alc,代码行数:57,代码来源:make_lfs.c
示例7: dirindir
/*
* Read indirect blocks, and pass the data blocks to be searched
* as directories. Quit as soon as any entry is found that will
* require the directory to be dumped.
*/
static int
dirindir(
ino_t ino,
ufs2_daddr_t blkno,
int ind_level,
long *filesize,
long *tapesize,
int nodump,
ino_t maxino)
{
union {
ufs1_daddr_t ufs1[MAXBSIZE / sizeof(ufs1_daddr_t)];
ufs2_daddr_t ufs2[MAXBSIZE / sizeof(ufs2_daddr_t)];
} idblk;
int ret = 0;
int i;
bread(fsbtodb(sblock, blkno), (char *)&idblk, (int)sblock->fs_bsize);
if (ind_level <= 0) {
for (i = 0; *filesize > 0 && i < NINDIR(sblock); i++) {
if (sblock->fs_magic == FS_UFS1_MAGIC)
blkno = idblk.ufs1[i];
else
blkno = idblk.ufs2[i];
if (blkno != 0)
ret |= searchdir(ino, blkno, sblock->fs_bsize,
*filesize, tapesize, nodump, maxino);
if (ret & HASDUMPEDFILE)
*filesize = 0;
else
*filesize -= sblock->fs_bsize;
}
return (ret);
}
ind_level--;
for (i = 0; *filesize > 0 && i < NINDIR(sblock); i++) {
if (sblock->fs_magic == FS_UFS1_MAGIC)
blkno = idblk.ufs1[i];
else
blkno = idblk.ufs2[i];
if (blkno != 0)
ret |= dirindir(ino, blkno, ind_level, filesize,
tapesize, nodump, maxino);
}
return (ret);
}
开发者ID:edgar-pek,项目名称:PerspicuOS,代码行数:51,代码来源:traverse.c
示例8: block_map
static grub_int64_t
block_map (int file_block)
{
int bnum, offset, bsize;
if (file_block < NDADDR)
return (INODE_UFS2->di_db[file_block]);
/* If the blockmap loaded does not include FILE_BLOCK,
load a new blockmap. */
if ((bnum = fsbtodb (SUPERBLOCK, INODE_UFS2->di_ib[0])) != mapblock
|| (mapblock_offset <= bnum && bnum <= mapblock_offset + mapblock_bsize))
{
if (MAPBUF_LEN < SUPERBLOCK->fs_bsize)
{
offset = ((file_block - NDADDR) % NINDIR (SUPERBLOCK));
bsize = MAPBUF_LEN;
if (offset + MAPBUF_LEN > SUPERBLOCK->fs_bsize)
offset = (SUPERBLOCK->fs_bsize - MAPBUF_LEN) / sizeof (int);
}
else
{
bsize = SUPERBLOCK->fs_bsize;
offset = 0;
}
if (! devread (bnum, offset * sizeof (int), bsize, (char *) MAPBUF, 0xedde0d90))
{
mapblock = -1;
mapblock_bsize = -1;
mapblock_offset = -1;
errnum = ERR_FSYS_CORRUPT;
return -1;
}
mapblock = bnum;
mapblock_bsize = bsize;
mapblock_offset = offset;
}
return (((grub_int64_t *) MAPBUF)[((file_block - NDADDR) % NINDIR (SUPERBLOCK))
- mapblock_offset]);
}
开发者ID:HappyBasher,项目名称:LINBOv3,代码行数:45,代码来源:fsys_ufs2.c
示例9: block_map
static int
block_map(int file_block)
{
int bnum;
if (file_block < NDADDR)
return(inode.i_db[file_block]);
if ((bnum=fsbtodb(fs, inode.i_ib[0])+boff) != mapblock) {
devread(mapbuf, bnum, fs->fs_bsize);
mapblock = bnum;
}
return (((int *)mapbuf)[(file_block - NDADDR) % NINDIR(fs)]);
}
开发者ID:UnitedMarsupials,项目名称:kame,代码行数:12,代码来源:sys.c
示例10: printindir
/*
* Recursively print a list of indirect blocks.
*/
static void
printindir(ufs2_daddr_t blk, int level, char *bufp)
{
struct bufarea buf, *bp;
char tempbuf[32]; /* enough to print an ufs2_daddr_t */
int i, j, cpl, charssofar;
ufs2_daddr_t blkno;
if (blk == 0)
return;
printf("%jd (%d) =>\n", (intmax_t)blk, level);
if (level == 0) {
/* for the final indirect level, don't use the cache */
bp = &buf;
bp->b_un.b_buf = bufp;
bp->b_prev = bp->b_next = bp;
initbarea(bp);
getblk(bp, blk, sblock.fs_bsize);
} else
bp = getdatablk(blk, sblock.fs_bsize);
cpl = charsperline();
for (i = charssofar = 0; i < NINDIR(&sblock); i++) {
if (sblock.fs_magic == FS_UFS1_MAGIC)
blkno = bp->b_un.b_indir1[i];
else
blkno = bp->b_un.b_indir2[i];
if (blkno == 0)
continue;
j = sprintf(tempbuf, "%jd", (intmax_t)blkno);
if (level == 0) {
charssofar += j;
if (charssofar >= cpl - 2) {
putchar('\n');
charssofar = j;
}
}
fputs(tempbuf, stdout);
if (level == 0) {
printf(", ");
charssofar += 2;
} else {
printf(" =>\n");
printindir(blkno, level - 1, bufp);
printf("\n");
charssofar = 0;
}
}
if (level == 0)
putchar('\n');
return;
}
开发者ID:AhmadTux,项目名称:freebsd,代码行数:56,代码来源:fsdbutil.c
示例11: dmpindir
/*
* Read indirect blocks, and pass the data blocks to be dumped.
*/
static void
dmpindir(union dinode *dp, ino_t ino, ufs2_daddr_t blk, int ind_level,
off_t *size)
{
union {
ufs1_daddr_t ufs1[MAXBSIZE / sizeof(ufs1_daddr_t)];
ufs2_daddr_t ufs2[MAXBSIZE / sizeof(ufs2_daddr_t)];
} idblk;
int i, cnt, last;
if (blk != 0)
bread(fsbtodb(sblock, blk), (char *)&idblk,
(int)sblock->fs_bsize);
else
memset(&idblk, 0, sblock->fs_bsize);
if (ind_level <= 0) {
if (*size > NINDIR(sblock) * sblock->fs_bsize) {
cnt = NINDIR(sblock) * sblock->fs_frag;
last = 0;
} else {
cnt = howmany(*size, sblock->fs_fsize);
last = 1;
}
*size -= NINDIR(sblock) * sblock->fs_bsize;
if (sblock->fs_magic == FS_UFS1_MAGIC)
ufs1_blksout(idblk.ufs1, cnt, ino);
else
ufs2_blksout(dp, idblk.ufs2, cnt, ino, last);
return;
}
ind_level--;
for (i = 0; i < NINDIR(sblock); i++) {
if (sblock->fs_magic == FS_UFS1_MAGIC)
dmpindir(dp, ino, idblk.ufs1[i], ind_level, size);
else
dmpindir(dp, ino, idblk.ufs2[i], ind_level, size);
if (*size <= 0)
return;
}
}
开发者ID:edgar-pek,项目名称:PerspicuOS,代码行数:43,代码来源:traverse.c
示例12: block_map
int
block_map(int file_block)
{
if (file_block < NDADDR)
return(inode.i_db[file_block]);
if ((bnum=fsbtodb(fs, inode.i_ib[0])+boff) != mapblock) {
cnt = fs->fs_bsize;
if (disk_read(bnum, cnt, (vm_offset_t)mapbuf))
return(-1);
mapblock = bnum;
}
return (((int *)mapbuf)[(file_block - NDADDR) % NINDIR(fs)]);
}
开发者ID:rohsaini,项目名称:mkunity,代码行数:13,代码来源:sys.c
示例13: printindir
/*
* Recursively print a list of indirect blocks.
*/
static int
printindir(ufs_daddr_t blk, int level, char *bufp)
{
struct bufarea buf, *bp;
char tempbuf[32]; /* enough to print an ufs_daddr_t */
int i, j, cpl, charssofar;
ufs_daddr_t blkno;
if (level == 0) {
/* for the final indirect level, don't use the cache */
bp = &buf;
bp->b_un.b_buf = bufp;
bp->b_prev = bp->b_next = bp;
initbarea(bp);
getblk(bp, blk, sblock.fs_bsize);
} else
bp = getdatablk(blk, sblock.fs_bsize);
cpl = charsperline();
for (i = charssofar = 0; i < NINDIR(&sblock); i++) {
blkno = bp->b_un.b_indir[i];
if (blkno == 0) {
if (level == 0)
putchar('\n');
return 0;
}
j = sprintf(tempbuf, "%d", blkno);
if (level == 0) {
charssofar += j;
if (charssofar >= cpl - 2) {
putchar('\n');
charssofar = j;
}
}
fputs(tempbuf, stdout);
if (level == 0) {
printf(", ");
charssofar += 2;
} else {
printf(" =>\n");
if (printindir(blkno, level - 1, bufp) == 0)
return 0;
}
}
if (level == 0)
putchar('\n');
return 1;
}
开发者ID:AhmadTux,项目名称:DragonFlyBSD,代码行数:52,代码来源:fsdbutil.c
示例14: bmap
diskaddr_t
bmap(diskaddr_t i)
{
daddr32_t ibuf[MAXNINDIR];
if (i < NDADDR)
return ((diskaddr_t)gip->di_db[i]);
i -= NDADDR;
if (i > NINDIR(&sblock)) {
(void) fprintf(stderr, "ff : %lu - huge directory\n", ino);
return ((diskaddr_t)0);
}
bread(fsbtodb(&sblock, gip->di_ib[0]), (char *)ibuf, sizeof (ibuf));
return ((diskaddr_t)ibuf[i]);
}
开发者ID:AlainODea,项目名称:illumos-gate,代码行数:15,代码来源:ff.c
示例15: collapse_dirhole
/*
* Truncate a directory to its first hole. If there are non-holes
* in the direct blocks after the problem block, move them down so
* that there's somewhat less lossage. Doing this for indirect blocks
* is left as an exercise for the reader.
*/
static void
collapse_dirhole(fsck_ino_t inumber, struct inodesc *idesc)
{
offset_t new_size;
int blocks;
if (idesc->id_firsthole < 0) {
return;
}
/*
* Since truncino() adjusts the size, we don't need to do that here,
* but we have to tell it what final size we want.
*
* We need to count from block zero up through the last block
* before the hole. If the hole is in the indirect blocks, chop at
* the start of the nearest level of indirection. Orphans will
* get reconnected, so we're not actually losing anything by doing
* it this way, and we're simplifying truncation significantly.
*/
new_size = idesc->id_firsthole * (offset_t)sblock.fs_bsize;
blocks = howmany(new_size, sblock.fs_bsize);
if (blocks > NDADDR) {
if (blocks < (NDADDR + NINDIR(&sblock)))
blocks = NDADDR;
else if (blocks < (NDADDR + NINDIR(&sblock) +
(NINDIR(&sblock) * NINDIR(&sblock))))
blocks = NDADDR + NINDIR(&sblock);
else
blocks = NDADDR + NINDIR(&sblock) +
(NINDIR(&sblock) * NINDIR(&sblock));
new_size = blocks * sblock.fs_bsize;
if (debug)
(void) printf("to %lld (blocks %d)\n",
(longlong_t)new_size, blocks);
}
truncino(inumber, new_size, TI_NOPARENT);
/*
* Technically, there are still the original number of fragments
* associated with the object. However, that number is not used
* to control anything, so we can do the in-memory truncation of
* it without bad things happening.
*/
idesc->id_entryno = btodb(new_size);
}
开发者ID:AlainODea,项目名称:illumos-gate,代码行数:52,代码来源:pass1.c
示例16: ffs_mkfs
//.........这里部分代码省略.........
sblock.fs_inopb = sblock.fs_bsize / sizeof(struct ufs1_dinode);
sblock.fs_maxsymlinklen = ((NDADDR + NIADDR) *
sizeof (ufs1_daddr_t));
sblock.fs_old_inodefmt = FS_44INODEFMT;
sblock.fs_old_cgoffset = 0;
sblock.fs_old_cgmask = 0xffffffff;
sblock.fs_old_size = sblock.fs_size;
sblock.fs_old_rotdelay = 0;
sblock.fs_old_rps = 60;
sblock.fs_old_nspf = sblock.fs_fsize / sectorsize;
sblock.fs_old_cpg = 1;
sblock.fs_old_interleave = 1;
sblock.fs_old_trackskew = 0;
sblock.fs_old_cpc = 0;
sblock.fs_old_postblformat = 1;
sblock.fs_old_nrpos = 1;
} else {
sblock.fs_magic = FS_UFS2_MAGIC;
sblock.fs_sblockloc = SBLOCK_UFS2;
sblock.fs_nindir = sblock.fs_bsize / sizeof(ufs2_daddr_t);
sblock.fs_inopb = sblock.fs_bsize / sizeof(struct ufs2_dinode);
sblock.fs_maxsymlinklen = ((NDADDR + NIADDR) *
sizeof (ufs2_daddr_t));
}
sblock.fs_sblkno =
roundup(howmany(sblock.fs_sblockloc + SBLOCKSIZE, sblock.fs_fsize),
sblock.fs_frag);
sblock.fs_cblkno = (daddr_t)(sblock.fs_sblkno +
roundup(howmany(SBLOCKSIZE, sblock.fs_fsize), sblock.fs_frag));
sblock.fs_iblkno = sblock.fs_cblkno + sblock.fs_frag;
sblock.fs_maxfilesize = sblock.fs_bsize * NDADDR - 1;
for (sizepb = sblock.fs_bsize, i = 0; i < NIADDR; i++) {
sizepb *= NINDIR(&sblock);
sblock.fs_maxfilesize += sizepb;
}
/*
* Calculate the number of blocks to put into each cylinder group.
*
* This algorithm selects the number of blocks per cylinder
* group. The first goal is to have at least enough data blocks
* in each cylinder group to meet the density requirement. Once
* this goal is achieved we try to expand to have at least
* 1 cylinder group. Once this goal is achieved, we pack as
* many blocks into each cylinder group map as will fit.
*
* We start by calculating the smallest number of blocks that we
* can put into each cylinder group. If this is too big, we reduce
* the density until it fits.
*/
origdensity = density;
for (;;) {
fragsperinode = MAX(numfrags(&sblock, density), 1);
minfpg = fragsperinode * INOPB(&sblock);
if (minfpg > sblock.fs_size)
minfpg = sblock.fs_size;
sblock.fs_ipg = INOPB(&sblock);
sblock.fs_fpg = roundup(sblock.fs_iblkno +
sblock.fs_ipg / INOPF(&sblock), sblock.fs_frag);
if (sblock.fs_fpg < minfpg)
sblock.fs_fpg = minfpg;
sblock.fs_ipg = roundup(howmany(sblock.fs_fpg, fragsperinode),
INOPB(&sblock));
sblock.fs_fpg = roundup(sblock.fs_iblkno +
sblock.fs_ipg / INOPF(&sblock), sblock.fs_frag);
开发者ID:lwhsu,项目名称:freebsd-makefs,代码行数:67,代码来源:mkfs.c
示例17: sbmap
static daddr_t
sbmap(struct iob *io, daddr_t bn)
{
register struct inode *ip;
int i, j, sh;
daddr_t nb, *bap;
ip = &io->i_ino;
if (ip->i_icflags & IC_FASTLINK)
{
error("fast symlinks unimplemented\n");
return ((daddr_t)0);
}
if (bn < 0) {
#if SYS_MESSAGES
error("bn negative\n");
#endif
return ((daddr_t)0);
}
/*
* blocks 0..NDADDR are direct blocks
*/
if(bn < NDADDR)
{
nb = ip->i_db[bn];
return (nb);
}
/*
* addresses NIADDR have single and double indirect blocks.
* the first step is to determine how many levels of indirection.
*/
sh = 1;
bn -= NDADDR;
for (j = NIADDR; j > 0; j--) {
sh *= NINDIR(io->i_fs);
if (bn < sh)
break;
bn -= sh;
}
if (j == 0) {
#if SYS_MESSAGES
error("bn ovf %d\n", bn);
#endif
return ((daddr_t)0);
}
/*
* fetch the first indirect block address from the inode
*/
nb = ip->i_ib[NIADDR - j];
if (nb == 0) {
#if SYS_MESSAGES
error("bn void %d\n",bn);
#endif
return ((daddr_t)0);
}
/*
* fetch through the indirect blocks
*/
for (; j <= NIADDR; j++) {
if (blknos[j] != nb) {
io->i_bn = fsbtodb(io->i_fs, nb) + io->i_boff;
if (b[j] == (char *)0)
b[j] = malloc(MAXBSIZE);
io->i_ma = b[j];
io->i_cc = io->i_fs->fs_bsize;
if (devread(io) != io->i_fs->fs_bsize) {
#if SYS_MESSAGES
error("bn %d: read error\n", io->i_bn);
#endif
return ((daddr_t)0);
}
blknos[j] = nb;
}
bap = (daddr_t *)b[j];
sh /= NINDIR(io->i_fs);
i = (bn / sh) % NINDIR(io->i_fs);
#if BIG_ENDIAN_FS
#if 1
// for now it is little endian FS for intel
nb = bap[i];
#else
nb = OSSwapBigToHostInt32(bap[i]);
#endif 1
#else BIG_ENDIAN_FS
nb = bap[i];
#endif BIG_ENDIAN_FS
if(nb == 0) {
#if SYS_MESSAGES
error("bn void %d\n",bn);
#endif
return ((daddr_t)0);
}
}
//.........这里部分代码省略.........
开发者ID:aosm,项目名称:boot,代码行数:101,代码来源:sys.c
示例18: ffs_indirtrunc
/*
* Release blocks associated with the inode ip and stored in the indirect
* block bn. Blocks are free'd in LIFO order up to (but not including)
* lastbn. If level is greater than SINGLE, the block is an indirect block
* and recursive calls to indirtrunc must be used to cleanse other indirect
* blocks.
*
* NB: triple indirect blocks are untested.
*/
static int
ffs_indirtrunc(struct inode *ip, ufs_daddr_t lbn, ufs_daddr_t dbn,
ufs_daddr_t lastbn, int level, long *countp)
{
int i;
struct buf *bp;
struct fs *fs = ip->i_fs;
ufs_daddr_t *bap;
struct vnode *vp;
ufs_daddr_t *copy = NULL, nb, nlbn, last;
long blkcount, factor;
int nblocks, blocksreleased = 0;
int error = 0, allerror = 0;
/*
* Calculate index in current block of last
* block to be kept. -1 indicates the entire
* block so we need not calculate the index.
*/
factor = 1;
for (i = SINGLE; i < level; i++)
factor *= NINDIR(fs);
last = lastbn;
if (lastbn > 0)
last /= factor;
nblocks = btodb(fs->fs_bsize);
/*
* Get buffer of block pointers, zero those entries corresponding
* to blocks to be free'd, and update on disk copy first. Since
* double(triple) indirect before single(double) indirect, calls
* to bmap on these blocks will fail. However, we already have
* the on disk address, so we have to set the bio_offset field
* explicitly instead of letting bread do everything for us.
*/
vp = ITOV(ip);
bp = getblk(vp, lblktodoff(fs, lbn), (int)fs->fs_bsize, 0, 0);
if ((bp->b_flags & B_CACHE) == 0) {
bp->b_flags &= ~(B_ERROR|B_INVAL);
bp->b_cmd = BUF_CMD_READ;
if (bp->b_bcount > bp->b_bufsize)
panic("ffs_indirtrunc: bad buffer size");
/*
* BIO is bio2 which chains back to bio1. We wait
* on bio1.
*/
bp->b_bio2.bio_offset = dbtodoff(fs, dbn);
bp->b_bio1.bio_done = biodone_sync;
bp->b_bio1.bio_flags |= BIO_SYNC;
vfs_busy_pages(vp, bp);
/*
* Access the block device layer using the device vnode
* and the translated block number (bio2) instead of the
* file vnode (vp) and logical block number (bio1).
*
* Even though we are bypassing the vnode layer, we still
* want the vnode state to indicate that an I/O on its behalf
* is in progress.
*/
bio_start_transaction(&bp->b_bio1, &vp->v_track_read);
vn_strategy(ip->i_devvp, &bp->b_bio2);
error = biowait(&bp->b_bio1, "biord");
}
if (error) {
brelse(bp);
*countp = 0;
return (error);
}
bap = (ufs_daddr_t *)bp->b_data;
if (lastbn != -1) {
copy = kmalloc(fs->fs_bsize, M_TEMP, M_WAITOK);
bcopy((caddr_t)bap, (caddr_t)copy, (uint)fs->fs_bsize);
bzero((caddr_t)&bap[last + 1],
(uint)(NINDIR(fs) - (last + 1)) * sizeof (ufs_daddr_t));
if (DOINGASYNC(vp)) {
bawrite(bp);
} else {
error = bwrite(bp);
if (error)
allerror = error;
}
bap = copy;
}
/*
* Recursively free totally unused blocks.
*/
for (i = NINDIR(fs) - 1, nlbn = lbn + 1 - i * factor; i > last;
i--, nlbn += factor) {
nb = bap[i];
if (nb == 0)
//.........这里部分代码省略.........
开发者ID:AhmadTux,项目名称:DragonFlyBSD,代码行数:101,代码来源:ffs_inode.c
示例19: ffs_truncate
//.........这里部分代码省略.........
fragroundup(fs, blkoff(fs, length)) < fs->fs_bsize) {
bundirty(bp);
error = VOP_FSYNC(ovp, MNT_WAIT, 0);
if (error) {
bdwrite(bp);
return (error);
}
}
oip->i_size = length;
size = blksize(fs, oip, lbn);
#if 0
/* remove - nvtruncbuf deals with this */
if (ovp->v_type != VDIR)
bzero((char *)bp->b_data + offset,
(uint)(size - offset));
#endif
/* Kirk's code has reallocbuf(bp, size, 1) here */
allocbuf(bp, size);
if (bp->b_bufsize == fs->fs_bsize)
bp->b_flags |= B_CLUSTEROK;
if (aflags & B_SYNC)
bwrite(bp);
else
bawrite(bp);
}
/*
* Calculate index into inode's block list of
* last direct and indirect blocks (if any)
* which we want to keep. Lastblock is -1 when
* the file is truncated to 0.
*/
lastblock = lblkno(fs, length + fs->fs_bsize - 1) - 1;
lastiblock[SINGLE] = lastblock - NDADDR;
lastiblock[DOUBLE] = lastiblock[SINGLE] - NINDIR(fs);
lastiblock[TRIPLE] = lastiblock[DOUBLE] - NINDIR(fs) * NINDIR(fs);
nblocks = btodb(fs->fs_bsize);
/*
* Update file and block pointers on disk before we start freeing
* blocks. If we crash before free'ing blocks below, the blocks
* will be returned to the free list. lastiblock values are also
* normalized to -1 for calls to ffs_indirtrunc below.
*/
bcopy((caddr_t)&oip->i_db[0], (caddr_t)oldblks, sizeof oldblks);
for (level = TRIPLE; level >= SINGLE; level--)
if (lastiblock[level] < 0) {
oip->i_ib[level] = 0;
lastiblock[level] = -1;
}
for (i = NDADDR - 1; i > lastblock; i--)
oip->i_db[i] = 0;
oip->i_flag |= IN_CHANGE | IN_UPDATE;
error = ffs_update(ovp, 1);
if (error && allerror == 0)
allerror = error;
/*
* Having written the new inode to disk, save its new configuration
* and put back the old block pointers long enough to process them.
* Note that we save the new block configuration so we can check it
* when we are done.
*/
bcopy((caddr_t)&oip->i_db[0], (caddr_t)newblks, sizeof newblks);
bcopy((caddr_t)oldblks, (caddr_t)&oip->i_db[0], sizeof oldblks);
oip->i_size = osize;
开发者ID:AhmadTux,项目名称:DragonFlyBSD,代码行数:66,代码来源:ffs_inode.c
示例20: mkfs
//.........这里部分代码省略.........
sblock.fs_bsize = bsize;
sblock.fs_fsize = fsize;
if (!POWEROF2(sblock.fs_bsize)) {
printf("block size must be a power of 2, not %d\n",
sblock.fs_bsize);
exit(16);
}
if (!POWEROF2(sblock.fs_fsize)) {
printf("fragment size must be a power of 2, not %d\n",
sblock.fs_fsize);
exit(17);
}
if (sblock.fs_fsize < sectorsize) {
printf("fragment size %d is too small, minimum is %d\n",
sblock.fs_fsize, sectorsize);
exit(18);
}
if (sblock.fs_bsize < MINBSIZE) {
printf("block size %d is too small, minimum is %d\n",
sblock.fs_bsize, MINBSIZE);
exit(19);
}
if (sblock.fs_bsize < sblock.fs_fsize) {
printf("block size (%d) cannot be smaller than fragment size (%d)\n",
sblock.fs_bsize, sblock.fs_fsize);
exit(20);
}
sblock.fs_bmask = ~(sblock.fs_bsize - 1);
sblock.fs_fmask = ~(sblock.fs_fsize - 1);
sblock.fs_qbmask = ~sblock.fs_bmask;
sblock.fs_qfmask = ~sblock.fs_fmask;
for (sblock.fs_bshift = 0, i = sblock.fs_bsize; i > 1; i >>= 1)
sblock.fs_bshift++;
for (sblock.fs_fshift = 0, i = sblock.fs_fsize; i > 1; i >>= 1)
sblock.fs_fshift++;
sblock.fs_frag = numfrags(&sblock, sblock.fs_bsize);
for (sblock.fs_fragshift = 0, i = sblock.fs_frag; i > 1; i >>= 1)
sblock.fs_fragshift++;
if (sblock.fs_frag > MAXFRAG) {
printf("fragment size %d is too small, minimum with block size %d is %d\n",
sblock.fs_fsize, sblock.fs_bsize,
sblock.fs_bsize / MAXFRAG);
exit(21);
}
sblock.fs_nrpos = nrpos;
sblock.fs_nindir = sblock.fs_bsize / sizeof(daddr_t);
sblock.fs_inopb = sblock.fs_bsize / sizeof(struct ufs1_dinode);
sblock.fs_nspf = sblock.fs_fsize / sectorsize;
for (sblock.fs_fsbtodb = 0, i = NSPF(&sblock); i > 1; i >>= 1)
sblock.fs_fsbtodb++;
sblock.fs_sblkno =
roundup(howmany(bbsize + sbsize, sblock.fs_fsize), sblock.fs_frag);
sblock.fs_cblkno = (daddr_t)(sblock.fs_sblkno +
roundup(howmany(sbsize, sblock.fs_fsize), sblock.fs_frag));
sblock.fs_iblkno = sblock.fs_cblkno + sblock.fs_frag;
sblock.fs_cgoffset = roundup(
howmany(sblock.fs_nsect, NSPF(&sblock)), sblock.fs_frag);
for (sblock.fs_cgmask = 0xffffffff, i = sblock.fs_ntrak; i > 1; i >>= 1)
sblock.fs_cgmask <<= 1;
if (!POWEROF2(sblock.fs_ntrak))
sblock.fs_cgmask <<= 1;
sblock.fs_maxfilesize = sblock.fs_bsize * NDADDR - 1;
for (sizepb = sblock.fs_bsize, i = 0; i < NIADDR; i++) {
sizepb *= NINDIR(&sblock);
sblock.fs_maxfilesize += sizepb;
}
/*
* Validate specified/determined secpercyl
* and calculate minimum cylinders per group.
*/
sblock.fs_spc = secpercyl;
for (sblock.fs_cpc = NSPB(&sblock), i = sblock.fs_spc;
sblock.fs_cpc > 1 && (i & 1) == 0;
sblock.fs_cpc >>= 1, i >>= 1)
/* void */;
mincpc = sblock.fs_cpc;
bpcg = sblock.fs_spc * sectorsize;
inospercg = roundup(bpcg / sizeof(struct ufs1_dinode), INOPB(&sblock));
if (inospercg > MAXIPG(&sblock))
inospercg = MAXIPG(&sblock);
used = (sblock.fs_iblkno + inospercg / INOPF(&sblock)) * NSPF(&sblock);
mincpgcnt = howmany(sblock.fs_cgoffset * (~sblock.fs_cgmask) + used,
sblock.fs_spc);
mincpg = roundup(mincpgcnt, mincpc);
/*
* Ensure that cylinder group with mincpg has enough space
* for block maps.
*/
sblock.fs_cpg = mincpg;
sblock.fs_ipg = inospercg;
if (maxcontig > 1)
sblock.fs_contigsumsize = MIN(maxcontig, FS_MAXCONTIG);
mapcramped = 0;
while (CGSIZE(&sblock) > (uint32_t)sblock.fs_bsize) {
mapcramped = 1;
if (sblock.fs_bsize < MAXBSIZE) {
sblock.fs_bsize <<= 1;
if ((i & 1) == 0) {
i >>= 1;
} else {
开发者ID:AhmadTux,项目名称:DragonFlyBSD,代码行数:101,代码来源:mkfs.c
注:本文中的NINDIR函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论