本文整理汇总了C++中VFSTOEXT2函数的典型用法代码示例。如果您正苦于以下问题:C++ VFSTOEXT2函数的具体用法?C++ VFSTOEXT2怎么用?C++ VFSTOEXT2使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了VFSTOEXT2函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ext2_count_free_inodes
static unsigned long
ext2_count_free_inodes(struct mount *mp)
{
#ifdef EXT2FS_DEBUG
struct ext2_sb_info *sb = VFSTOEXT2(mp)->um_e2fs;
struct ext2_super_block *es;
unsigned long desc_count, bitmap_count, x;
int bitmap_nr;
struct ext2_group_desc *gdp;
int i;
lock_super (VFSTOEXT2(mp)->um_devvp);
es = sb->s_es;
desc_count = 0;
bitmap_count = 0;
gdp = NULL;
for (i = 0; i < sb->s_groups_count; i++) {
gdp = get_group_desc (mp, i, NULL);
desc_count += gdp->bg_free_inodes_count;
bitmap_nr = load_inode_bitmap (mp, i);
x = ext2_count_free (sb->s_inode_bitmap[bitmap_nr],
EXT2_INODES_PER_GROUP(sb) / 8);
ext2_debug ("group %d: stored = %d, counted = %lu\n",
i, gdp->bg_free_inodes_count, x);
bitmap_count += x;
}
ext2_debug("stored = %lu, computed = %lu, %lu\n",
es->s_free_inodes_count, desc_count, bitmap_count);
unlock_super (VFSTOEXT2(mp)->um_devvp);
return desc_count;
#else
return VFSTOEXT2(mp)->um_e2fsb->s_free_inodes_count;
#endif
}
示例2: get_group_desc
struct ext2_group_desc *
get_group_desc(struct mount *mp, unsigned int block_group,
struct buf **bh)
{
struct ext2_sb_info *sb = VFSTOEXT2(mp)->um_e2fs;
unsigned long group_desc;
unsigned long desc;
struct ext2_group_desc *gdp;
if (block_group >= sb->s_groups_count)
panic ("get_group_desc: "
"block_group >= groups_count - "
"block_group = %d, groups_count = %lu",
block_group, sb->s_groups_count);
group_desc = block_group / EXT2_DESC_PER_BLOCK(sb);
desc = block_group % EXT2_DESC_PER_BLOCK(sb);
if (!sb->s_group_desc[group_desc])
panic ( "get_group_desc:"
"Group descriptor not loaded - "
"block_group = %d, group_desc = %lu, desc = %lu",
block_group, group_desc, desc);
gdp = (struct ext2_group_desc *)
sb->s_group_desc[group_desc]->b_data;
if (bh)
*bh = sb->s_group_desc[group_desc];
return gdp + desc;
}
示例3: ext2_getinoquota
/*
* Set up the quotas for an inode.
*
* This routine completely defines the semantics of quotas.
* If other criterion want to be used to establish quotas, the
* MAXQUOTAS value in quotas.h should be increased, and the
* additional dquots set up here.
*/
int
ext2_getinoquota(struct inode *ip)
{
struct ext2mount *ump;
struct vnode *vp = ITOV(ip);
int error;
ump = VFSTOEXT2(vp->v_mount);
/*
* Set up the user quota based on file uid.
* EINVAL means that quotas are not enabled.
*/
if (ip->i_dquot[USRQUOTA] == NODQUOT &&
(error = ext2_dqget(vp, ip->i_uid, ump, USRQUOTA, &ip->i_dquot[USRQUOTA])) &&
error != EINVAL)
return (error);
/*
* Set up the group quota based on file gid.
* EINVAL means that quotas are not enabled.
*/
if (ip->i_dquot[GRPQUOTA] == NODQUOT &&
(error = ext2_dqget(vp, ip->i_gid, ump, GRPQUOTA, &ip->i_dquot[GRPQUOTA])) &&
error != EINVAL)
return (error);
return (0);
}
示例4: ext2_qsync
int
ext2_qsync(struct mount *mp)
{
struct ext2mount *ump = VFSTOEXT2(mp);
struct scaninfo scaninfo;
int i;
/*
* Check if the mount point has any quotas.
* If not, simply return.
*/
for (i = 0; i < MAXQUOTAS; i++)
if (ump->um_quotas[i] != NULLVP)
break;
if (i == MAXQUOTAS)
return (0);
/*
* Search vnodes associated with this mount point,
* synchronizing any modified ext2_dquot structures.
*/
scaninfo.rescan = 1;
while (scaninfo.rescan) {
scaninfo.rescan = 0;
vmntvnodescan(mp, VMSC_GETVP|VMSC_NOWAIT,
NULL, ext2_qsync_scan, &scaninfo);
}
return (0);
}
示例5: ext2_chkiq
/*
* Check the inode limit, applying corrective action.
*/
int
ext2_chkiq(struct inode *ip, long change, struct ucred *cred, int flags)
{
struct ext2_dquot *dq;
int i;
int ncurinodes, error;
#ifdef DIAGNOSTIC
if ((flags & CHOWN) == 0)
ext2_chkdquot(ip);
#endif
if (change == 0)
return (0);
if (change < 0) {
for (i = 0; i < MAXQUOTAS; i++) {
if ((dq = ip->i_dquot[i]) == NODQUOT)
continue;
while (dq->dq_flags & DQ_LOCK) {
dq->dq_flags |= DQ_WANT;
(void) tsleep((caddr_t)dq, 0, "chkiq1", 0);
}
ncurinodes = dq->dq_curinodes + change;
if (ncurinodes >= 0)
dq->dq_curinodes = ncurinodes;
else
dq->dq_curinodes = 0;
dq->dq_flags &= ~DQ_INODS;
dq->dq_flags |= DQ_MOD;
}
return (0);
}
if ((flags & FORCE) == 0 && cred->cr_uid != 0) {
for (i = 0; i < MAXQUOTAS; i++) {
if ((dq = ip->i_dquot[i]) == NODQUOT)
continue;
error = ext2_chkiqchg(ip, change, cred, i);
if (error)
return (error);
}
}
for (i = 0; i < MAXQUOTAS; i++) {
if ((dq = ip->i_dquot[i]) == NODQUOT)
continue;
while (dq->dq_flags & DQ_LOCK) {
dq->dq_flags |= DQ_WANT;
(void) tsleep((caddr_t)dq, 0, "chkiq2", 0);
}
/* Reset timer when crossing soft limit */
if (dq->dq_curinodes + change >= dq->dq_isoftlimit &&
dq->dq_curinodes < dq->dq_isoftlimit)
dq->dq_itime = time_second +
VFSTOEXT2(ITOV(ip)->v_mount)->um_itime[i];
dq->dq_curinodes += change;
dq->dq_flags |= DQ_MOD;
}
return (0);
}
示例6: read_inode_bitmap
static void
read_inode_bitmap(struct mount *mp, unsigned long block_group,
unsigned int bitmap_nr)
{
struct ext2_sb_info *sb = VFSTOEXT2(mp)->um_e2fs;
struct ext2_group_desc *gdp;
struct buf *bh;
int error;
gdp = get_group_desc (mp, block_group, NULL);
if ((error = bread (VFSTOEXT2(mp)->um_devvp,
fsbtodoff(sb, gdp->bg_inode_bitmap),
sb->s_blocksize, &bh)) != 0)
panic ( "read_inode_bitmap:"
"Cannot read inode bitmap - "
"block_group = %lu, inode_bitmap = %lu",
block_group, (unsigned long) gdp->bg_inode_bitmap);
sb->s_inode_bitmap_number[bitmap_nr] = block_group;
sb->s_inode_bitmap[bitmap_nr] = bh;
LCK_BUF(bh)
}
示例7: ext2_setquota
/*
* Q_SETQUOTA - assign an entire dqblk structure.
*/
int
ext2_setquota(struct mount *mp, u_long id, int type, caddr_t addr)
{
struct ext2_dquot *dq;
struct ext2_dquot *ndq;
struct ext2mount *ump = VFSTOEXT2(mp);
struct ext2_dqblk newlim;
int error;
error = copyin(addr, (caddr_t)&newlim, sizeof (struct ext2_dqblk));
if (error)
return (error);
error = ext2_dqget(NULLVP, id, ump, type, &ndq);
if (error)
return (error);
dq = ndq;
while (dq->dq_flags & DQ_LOCK) {
dq->dq_flags |= DQ_WANT;
(void) tsleep((caddr_t)dq, 0, "setqta", 0);
}
/*
* Copy all but the current values.
* Reset time limit if previously had no soft limit or were
* under it, but now have a soft limit and are over it.
*/
newlim.dqb_curblocks = dq->dq_curblocks;
newlim.dqb_curinodes = dq->dq_curinodes;
if (dq->dq_id != 0) {
newlim.dqb_btime = dq->dq_btime;
newlim.dqb_itime = dq->dq_itime;
}
if (newlim.dqb_bsoftlimit &&
dq->dq_curblocks >= newlim.dqb_bsoftlimit &&
(dq->dq_bsoftlimit == 0 || dq->dq_curblocks < dq->dq_bsoftlimit))
newlim.dqb_btime = time_second + ump->um_btime[type];
if (newlim.dqb_isoftlimit &&
dq->dq_curinodes >= newlim.dqb_isoftlimit &&
(dq->dq_isoftlimit == 0 || dq->dq_curinodes < dq->dq_isoftlimit))
newlim.dqb_itime = time_second + ump->um_itime[type];
dq->dq_dqb = newlim;
if (dq->dq_curblocks < dq->dq_bsoftlimit)
dq->dq_flags &= ~DQ_BLKS;
if (dq->dq_curinodes < dq->dq_isoftlimit)
dq->dq_flags &= ~DQ_INODS;
if (dq->dq_isoftlimit == 0 && dq->dq_bsoftlimit == 0 &&
dq->dq_ihardlimit == 0 && dq->dq_bhardlimit == 0)
dq->dq_flags |= DQ_FAKE;
else
dq->dq_flags &= ~DQ_FAKE;
dq->dq_flags |= DQ_MOD;
ext2_dqrele(NULLVP, dq);
return (0);
}
示例8: ext2_getquota
/*
* Q_GETQUOTA - return current values in a dqblk structure.
*/
int
ext2_getquota(struct mount *mp, u_long id, int type, caddr_t addr)
{
struct ext2_dquot *dq;
int error;
error = ext2_dqget(NULLVP, id, VFSTOEXT2(mp), type, &dq);
if (error)
return (error);
error = copyout((caddr_t)&dq->dq_dqb, addr, sizeof (struct ext2_dqblk));
ext2_dqrele(NULLVP, dq);
return (error);
}
示例9: ext2_chkdquot
/*
* On filesystems with quotas enabled, it is an error for a file to change
* size and not to have a dquot structure associated with it.
*/
static void
ext2_chkdquot(struct inode *ip)
{
struct ext2mount *ump = VFSTOEXT2(ITOV(ip)->v_mount);
int i;
for (i = 0; i < MAXQUOTAS; i++) {
if (ump->um_quotas[i] == NULLVP ||
(ump->um_qflags[i] & (QTF_OPENING|QTF_CLOSING)))
continue;
if (ip->i_dquot[i] == NODQUOT) {
vprint("chkdquot: missing dquot", ITOV(ip));
panic("chkdquot: missing dquot");
}
}
}
示例10: ext2_chkiqchg
/*
* Check for a valid change to a users allocation.
* Issue an error message if appropriate.
*/
static int
ext2_chkiqchg(struct inode *ip, long change, struct ucred *cred, int type)
{
struct ext2_dquot *dq = ip->i_dquot[type];
long ncurinodes = dq->dq_curinodes + change;
/*
* If user would exceed their hard limit, disallow inode allocation.
*/
if (ncurinodes >= dq->dq_ihardlimit && dq->dq_ihardlimit) {
if ((dq->dq_flags & DQ_INODS) == 0 &&
ip->i_uid == cred->cr_uid) {
uprintf("\n%s: write failed, %s inode limit reached\n",
ITOV(ip)->v_mount->mnt_stat.f_mntfromname,
quotatypes[type]);
dq->dq_flags |= DQ_INODS;
}
return (EDQUOT);
}
/*
* If user is over their soft limit for too long, disallow inode
* allocation. Reset time limit as they cross their soft limit.
*/
if (ncurinodes >= dq->dq_isoftlimit && dq->dq_isoftlimit) {
if (dq->dq_curinodes < dq->dq_isoftlimit) {
dq->dq_itime = time_second +
VFSTOEXT2(ITOV(ip)->v_mount)->um_itime[type];
if (ip->i_uid == cred->cr_uid)
uprintf("\n%s: warning, %s %s\n",
ITOV(ip)->v_mount->mnt_stat.f_mntfromname,
quotatypes[type], "inode quota exceeded");
return (0);
}
if (time_second > dq->dq_itime) {
if ((dq->dq_flags & DQ_INODS) == 0 &&
ip->i_uid == cred->cr_uid) {
uprintf("\n%s: write failed, %s %s\n",
ITOV(ip)->v_mount->mnt_stat.f_mntfromname,
quotatypes[type],
"inode quota exceeded for too long");
dq->dq_flags |= DQ_INODS;
}
return (EDQUOT);
}
}
return (0);
}
示例11: ext2_statfs
/*
* Get file system statistics.
*/
int
ext2_statfs(struct mount *mp, struct statfs *sbp, struct ucred *cred)
{
unsigned long overhead;
struct ext2_mount *ump;
struct ext2_sb_info *fs;
struct ext2_super_block *es;
int i, nsb;
ump = VFSTOEXT2(mp);
fs = ump->um_e2fs;
es = fs->s_es;
if (es->s_magic != EXT2_SUPER_MAGIC)
panic("ext2_statfs - magic number spoiled");
/*
* Compute the overhead (FS structures)
*/
if (es->s_feature_ro_compat & EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER) {
nsb = 0;
for (i = 0 ; i < fs->s_groups_count; i++)
if (ext2_group_sparse(i))
nsb++;
} else
nsb = fs->s_groups_count;
overhead = es->s_first_data_block +
/* Superblocks and block group descriptors: */
nsb * (1 + fs->s_db_per_group) +
/* Inode bitmap, block bitmap, and inode table: */
fs->s_groups_count * (1 + 1 + fs->s_itb_per_group);
sbp->f_bsize = EXT2_FRAG_SIZE(fs);
sbp->f_iosize = EXT2_BLOCK_SIZE(fs);
sbp->f_blocks = es->s_blocks_count - overhead;
sbp->f_bfree = es->s_free_blocks_count;
sbp->f_bavail = sbp->f_bfree - es->s_r_blocks_count;
sbp->f_files = es->s_inodes_count;
sbp->f_ffree = es->s_free_inodes_count;
if (sbp != &mp->mnt_stat) {
sbp->f_type = mp->mnt_vfc->vfc_typenum;
bcopy((caddr_t)mp->mnt_stat.f_mntfromname,
(caddr_t)&sbp->f_mntfromname[0], MNAMELEN);
}
return (0);
}
示例12: ext2_setuse
/*
* Q_SETUSE - set current inode and block usage.
*/
int
ext2_setuse(struct mount *mp, u_long id, int type, caddr_t addr)
{
struct ext2_dquot *dq;
struct ext2mount *ump = VFSTOEXT2(mp);
struct ext2_dquot *ndq;
struct ext2_dqblk usage;
int error;
error = copyin(addr, (caddr_t)&usage, sizeof (struct ext2_dqblk));
if (error)
return (error);
error = ext2_dqget(NULLVP, id, ump, type, &ndq);
if (error)
return (error);
dq = ndq;
while (dq->dq_flags & DQ_LOCK) {
dq->dq_flags |= DQ_WANT;
(void) tsleep((caddr_t)dq, 0, "setuse", 0);
}
/*
* Reset time limit if have a soft limit and were
* previously under it, but are now over it.
*/
if (dq->dq_bsoftlimit && dq->dq_curblocks < dq->dq_bsoftlimit &&
usage.dqb_curblocks >= dq->dq_bsoftlimit)
dq->dq_btime = time_second + ump->um_btime[type];
if (dq->dq_isoftlimit && dq->dq_curinodes < dq->dq_isoftlimit &&
usage.dqb_curinodes >= dq->dq_isoftlimit)
dq->dq_itime = time_second + ump->um_itime[type];
dq->dq_curblocks = usage.dqb_curblocks;
dq->dq_curinodes = usage.dqb_curinodes;
if (dq->dq_curblocks < dq->dq_bsoftlimit)
dq->dq_flags &= ~DQ_BLKS;
if (dq->dq_curinodes < dq->dq_isoftlimit)
dq->dq_flags &= ~DQ_INODS;
dq->dq_flags |= DQ_MOD;
ext2_dqrele(NULLVP, dq);
return (0);
}
示例13: ext2_quotaoff
int
ext2_quotaoff(struct mount *mp, int type)
{
struct vnode *qvp;
struct ext2mount *ump = VFSTOEXT2(mp);
int error;
struct scaninfo scaninfo;
if ((qvp = ump->um_quotas[type]) == NULLVP)
return (0);
ump->um_qflags[type] |= QTF_CLOSING;
/*
* Search vnodes associated with this mount point,
* deleting any references to quota file being closed.
*/
scaninfo.rescan = 1;
scaninfo.type = type;
while (scaninfo.rescan) {
scaninfo.rescan = 0;
vmntvnodescan(mp, VMSC_GETVP, NULL, ext2_quotaoff_scan, &scaninfo);
}
ext2_dqflush(qvp);
vclrflags(qvp, VSYSTEM);
error = vn_close(qvp, FREAD|FWRITE, NULL);
ump->um_quotas[type] = NULLVP;
crfree(ump->um_cred[type]);
ump->um_cred[type] = NOCRED;
ump->um_qflags[type] &= ~QTF_CLOSING;
for (type = 0; type < MAXQUOTAS; type++) {
if (ump->um_quotas[type] != NULLVP)
break;
}
if (type == MAXQUOTAS)
mp->mnt_flag &= ~MNT_QUOTA;
return (error);
}
示例14: ext2_getlbns
/*
* Create an array of logical block number/offset pairs which represent the
* path of indirect blocks required to access a data block. The first "pair"
* contains the logical block number of the appropriate single, double or
* triple indirect block and the offset into the inode indirect block array.
* Note, the logical block number of the inode single/double/triple indirect
* block appears twice in the array, once with the offset into the i_ib and
* once with the offset into the page itself.
*/
int
ext2_getlbns(struct vnode *vp, daddr_t bn, struct indir *ap, int *nump)
{
long blockcnt;
e2fs_lbn_t metalbn, realbn;
struct ext2mount *ump;
int i, numlevels, off;
int64_t qblockcnt;
ump = VFSTOEXT2(vp->v_mount);
if (nump)
*nump = 0;
numlevels = 0;
realbn = bn;
if ((long)bn < 0)
bn = -(long)bn;
/* The first NDADDR blocks are direct blocks. */
if (bn < NDADDR)
return (0);
/*
* Determine the number of levels of indirection. After this loop
* is done, blockcnt indicates the number of data blocks possible
* at the previous level of indirection, and NIADDR - i is the number
* of levels of indirection needed to locate the requested block.
*/
for (blockcnt = 1, i = NIADDR, bn -= NDADDR;; i--, bn -= blockcnt) {
if (i == 0)
return (EFBIG);
/*
* Use int64_t's here to avoid overflow for triple indirect
* blocks when longs have 32 bits and the block size is more
* than 4K.
*/
qblockcnt = (int64_t)blockcnt * MNINDIR(ump);
if (bn < qblockcnt)
break;
blockcnt = qblockcnt;
}
/* Calculate the address of the first meta-block. */
if (realbn >= 0)
metalbn = -(realbn - bn + NIADDR - i);
else
metalbn = -(-realbn - bn + NIADDR - i);
/*
* At each iteration, off is the offset into the bap array which is
* an array of disk addresses at the current level of indirection.
* The logical block number and the offset in that block are stored
* into the argument array.
*/
ap->in_lbn = metalbn;
ap->in_off = off = NIADDR - i;
ap++;
for (++numlevels; i <= NIADDR; i++) {
/* If searching for a meta-data block, quit when found. */
if (metalbn == realbn)
break;
off = (bn / blockcnt) % MNINDIR(ump);
++numlevels;
ap->in_lbn = metalbn;
ap->in_off = off;
++ap;
metalbn -= -1 + off * blockcnt;
blockcnt /= MNINDIR(ump);
}
if (nump)
*nump = numlevels;
return (0);
}
示例15: ext2_lookup
//.........这里部分代码省略.........
wantparent = flags & (CNP_LOCKPARENT|CNP_WANTPARENT);
/*
* We now have a segment name to search for, and a directory to search.
*/
/*
* Suppress search for slots unless creating
* file and at end of pathname, in which case
* we watch for a place to put the new file in
* case it doesn't already exist.
*/
slotstatus = FOUND;
slotfreespace = slotsize = slotneeded = 0;
if (nameiop == NAMEI_CREATE || nameiop == NAMEI_RENAME) {
slotstatus = NONE;
slotneeded = EXT2_DIR_REC_LEN(cnp->cn_namelen);
/* was
slotneeded = (sizeof(struct direct) - MAXNAMLEN +
cnp->cn_namelen + 3) &~ 3; */
}
/*
* If there is cached information on a previous search of
* this directory, pick up where we last left off.
* We cache only lookups as these are the most common
* and have the greatest payoff. Caching CREATE has little
* benefit as it usually must search the entire directory
* to determine that the entry does not exist. Caching the
* location of the last DELETE or RENAME has not reduced
* profiling time and hence has been removed in the interest
* of simplicity.
*/
bmask = VFSTOEXT2(vdp->v_mount)->um_mountp->mnt_stat.f_iosize - 1;
if (nameiop != NAMEI_LOOKUP || dp->i_diroff == 0 ||
dp->i_diroff > dp->i_size) {
entryoffsetinblock = 0;
dp->i_offset = 0;
numdirpasses = 1;
} else {
dp->i_offset = dp->i_diroff;
if ((entryoffsetinblock = dp->i_offset & bmask) &&
(error = EXT2_BLKATOFF(vdp, (off_t)dp->i_offset, NULL, &bp)))
return (error);
numdirpasses = 2;
}
prevoff = dp->i_offset;
endsearch = roundup(dp->i_size, DIRBLKSIZ);
enduseful = 0;
searchloop:
while (dp->i_offset < endsearch) {
/*
* If necessary, get the next directory block.
*/
if ((dp->i_offset & bmask) == 0) {
if (bp != NULL)
brelse(bp);
if ((error =
EXT2_BLKATOFF(vdp, (off_t)dp->i_offset, NULL, &bp)) != 0)
return (error);
entryoffsetinblock = 0;
}
/*
* If still looking for a slot, and at a DIRBLKSIZE
* boundary, have to start looking for free space again.