cregit-Linux how code gets into the kernel

Release 4.11 fs/quota/quota_v1.c

Directory: fs/quota
#include <linux/errno.h>
#include <linux/fs.h>
#include <linux/quota.h>
#include <linux/quotaops.h>
#include <linux/dqblk_v1.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/module.h>

#include <asm/byteorder.h>

#include "quotaio_v1.h"

MODULE_AUTHOR("Jan Kara");
MODULE_DESCRIPTION("Old quota format support");
MODULE_LICENSE("GPL");


#define QUOTABLOCK_BITS 10

#define QUOTABLOCK_SIZE (1 << QUOTABLOCK_BITS)


static inline qsize_t v1_stoqb(qsize_t space) { return (space + QUOTABLOCK_SIZE - 1) >> QUOTABLOCK_BITS; }

Contributors

PersonTokensPropCommitsCommitProp
Jan Kara21100.00%1100.00%
Total21100.00%1100.00%


static inline qsize_t v1_qbtos(qsize_t blocks) { return blocks << QUOTABLOCK_BITS; }

Contributors

PersonTokensPropCommitsCommitProp
Jan Kara15100.00%1100.00%
Total15100.00%1100.00%


static void v1_disk2mem_dqblk(struct mem_dqblk *m, struct v1_disk_dqblk *d) { m->dqb_ihardlimit = d->dqb_ihardlimit; m->dqb_isoftlimit = d->dqb_isoftlimit; m->dqb_curinodes = d->dqb_curinodes; m->dqb_bhardlimit = v1_qbtos(d->dqb_bhardlimit); m->dqb_bsoftlimit = v1_qbtos(d->dqb_bsoftlimit); m->dqb_curspace = v1_qbtos(d->dqb_curblocks); m->dqb_itime = d->dqb_itime; m->dqb_btime = d->dqb_btime; }

Contributors

PersonTokensPropCommitsCommitProp
Jan Kara89100.00%2100.00%
Total89100.00%2100.00%


static void v1_mem2disk_dqblk(struct v1_disk_dqblk *d, struct mem_dqblk *m) { d->dqb_ihardlimit = m->dqb_ihardlimit; d->dqb_isoftlimit = m->dqb_isoftlimit; d->dqb_curinodes = m->dqb_curinodes; d->dqb_bhardlimit = v1_stoqb(m->dqb_bhardlimit); d->dqb_bsoftlimit = v1_stoqb(m->dqb_bsoftlimit); d->dqb_curblocks = v1_stoqb(m->dqb_curspace); d->dqb_itime = m->dqb_itime; d->dqb_btime = m->dqb_btime; }

Contributors

PersonTokensPropCommitsCommitProp
Jan Kara89100.00%2100.00%
Total89100.00%2100.00%


static int v1_read_dqblk(struct dquot *dquot) { int type = dquot->dq_id.type; struct v1_disk_dqblk dqblk; if (!sb_dqopt(dquot->dq_sb)->files[type]) return -EINVAL; /* Set structure to 0s in case read fails/is after end of file */ memset(&dqblk, 0, sizeof(struct v1_disk_dqblk)); dquot->dq_sb->s_op->quota_read(dquot->dq_sb, type, (char *)&dqblk, sizeof(struct v1_disk_dqblk), v1_dqoff(from_kqid(&init_user_ns, dquot->dq_id))); v1_disk2mem_dqblk(&dquot->dq_dqb, &dqblk); if (dquot->dq_dqb.dqb_bhardlimit == 0 && dquot->dq_dqb.dqb_bsoftlimit == 0 && dquot->dq_dqb.dqb_ihardlimit == 0 && dquot->dq_dqb.dqb_isoftlimit == 0) set_bit(DQ_FAKE_B, &dquot->dq_flags); dqstats_inc(DQST_READS); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Jan Kara12879.01%233.33%
Andrew Morton2112.96%233.33%
Eric W. Biedermann95.56%116.67%
Dmitriy Monakhov42.47%116.67%
Total162100.00%6100.00%


static int v1_commit_dqblk(struct dquot *dquot) { short type = dquot->dq_id.type; ssize_t ret; struct v1_disk_dqblk dqblk; v1_mem2disk_dqblk(&dqblk, &dquot->dq_dqb); if (((type == USRQUOTA) && uid_eq(dquot->dq_id.uid, GLOBAL_ROOT_UID)) || ((type == GRPQUOTA) && gid_eq(dquot->dq_id.gid, GLOBAL_ROOT_GID))) { dqblk.dqb_btime = sb_dqopt(dquot->dq_sb)->info[type].dqi_bgrace; dqblk.dqb_itime = sb_dqopt(dquot->dq_sb)->info[type].dqi_igrace; } ret = 0; if (sb_dqopt(dquot->dq_sb)->files[type]) ret = dquot->dq_sb->s_op->quota_write(dquot->dq_sb, type, (char *)&dqblk, sizeof(struct v1_disk_dqblk), v1_dqoff(from_kqid(&init_user_ns, dquot->dq_id))); if (ret != sizeof(struct v1_disk_dqblk)) { quota_error(dquot->dq_sb, "dquota write failed"); if (ret >= 0) ret = -EIO; goto out; } ret = 0; out: dqstats_inc(DQST_WRITES); return ret; }

Contributors

PersonTokensPropCommitsCommitProp
Jan Kara17778.32%240.00%
Eric W. Biedermann4218.58%120.00%
Dmitriy Monakhov41.77%120.00%
Jiaying Zhang31.33%120.00%
Total226100.00%5100.00%

/* Magics of new quota format */ #define V2_INITQMAGICS {\ 0xd9c01f11, /* USRQUOTA */\ 0xd9c01927 /* GRPQUOTA */\ } /* Header of new quota format */ struct v2_disk_dqheader { __le32 dqh_magic; /* Magic number identifying file */ __le32 dqh_version; /* File version */ };
static int v1_check_quota_file(struct super_block *sb, int type) { struct inode *inode = sb_dqopt(sb)->files[type]; ulong blocks; size_t off; struct v2_disk_dqheader dqhead; ssize_t size; loff_t isize; static const uint quota_magics[] = V2_INITQMAGICS; isize = i_size_read(inode); if (!isize) return 0; blocks = isize >> BLOCK_SIZE_BITS; off = isize & (BLOCK_SIZE - 1); if ((blocks % sizeof(struct v1_disk_dqblk) * BLOCK_SIZE + off) % sizeof(struct v1_disk_dqblk)) return 0; /* Doublecheck whether we didn't get file with new format - with old * quotactl() this could happen */ size = sb->s_op->quota_read(sb, type, (char *)&dqhead, sizeof(struct v2_disk_dqheader), 0); if (size != sizeof(struct v2_disk_dqheader)) return 1; /* Probably not new format */ if (le32_to_cpu(dqhead.dqh_magic) != quota_magics[type]) return 1; /* Definitely not new format */ printk(KERN_INFO "VFS: %s: Refusing to turn on old quota format on given file." " It probably contains newer quota format.\n", sb->s_id); return 0; /* Seems like a new format file -> refuse it */ }

Contributors

PersonTokensPropCommitsCommitProp
Jan Kara17292.97%360.00%
Andrew Morton126.49%120.00%
Al Viro10.54%120.00%
Total185100.00%5100.00%


static int v1_read_file_info(struct super_block *sb, int type) { struct quota_info *dqopt = sb_dqopt(sb); struct v1_disk_dqblk dqblk; int ret; ret = sb->s_op->quota_read(sb, type, (char *)&dqblk, sizeof(struct v1_disk_dqblk), v1_dqoff(0)); if (ret != sizeof(struct v1_disk_dqblk)) { if (ret >= 0) ret = -EIO; goto out; } ret = 0; /* limits are stored as unsigned 32-bit data */ dqopt->info[type].dqi_max_spc_limit = 0xffffffffULL << QUOTABLOCK_BITS; dqopt->info[type].dqi_max_ino_limit = 0xffffffff; dqopt->info[type].dqi_igrace = dqblk.dqb_itime ? dqblk.dqb_itime : MAX_IQ_TIME; dqopt->info[type].dqi_bgrace = dqblk.dqb_btime ? dqblk.dqb_btime : MAX_DQ_TIME; out: return ret; }

Contributors

PersonTokensPropCommitsCommitProp
Jan Kara14087.50%480.00%
Andrew Perepechko2012.50%120.00%
Total160100.00%5100.00%


static int v1_write_file_info(struct super_block *sb, int type) { struct quota_info *dqopt = sb_dqopt(sb); struct v1_disk_dqblk dqblk; int ret; dqopt->info[type].dqi_flags &= ~DQF_INFO_DIRTY; ret = sb->s_op->quota_read(sb, type, (char *)&dqblk, sizeof(struct v1_disk_dqblk), v1_dqoff(0)); if (ret != sizeof(struct v1_disk_dqblk)) { if (ret >= 0) ret = -EIO; goto out; } dqblk.dqb_itime = dqopt->info[type].dqi_igrace; dqblk.dqb_btime = dqopt->info[type].dqi_bgrace; ret = sb->s_op->quota_write(sb, type, (char *)&dqblk, sizeof(struct v1_disk_dqblk), v1_dqoff(0)); if (ret == sizeof(struct v1_disk_dqblk)) ret = 0; else if (ret > 0) ret = -EIO; out: return ret; }

Contributors

PersonTokensPropCommitsCommitProp
Jan Kara188100.00%3100.00%
Total188100.00%3100.00%

static const struct quota_format_ops v1_format_ops = { .check_quota_file = v1_check_quota_file, .read_file_info = v1_read_file_info, .write_file_info = v1_write_file_info, .free_file_info = NULL, .read_dqblk = v1_read_dqblk, .commit_dqblk = v1_commit_dqblk, }; static struct quota_format_type v1_quota_format = { .qf_fmt_id = QFMT_VFS_OLD, .qf_ops = &v1_format_ops, .qf_owner = THIS_MODULE };
static int __init init_v1_quota_format(void) { return register_quota_format(&v1_quota_format); }

Contributors

PersonTokensPropCommitsCommitProp
Jan Kara16100.00%1100.00%
Total16100.00%1100.00%


static void __exit exit_v1_quota_format(void) { unregister_quota_format(&v1_quota_format); }

Contributors

PersonTokensPropCommitsCommitProp
Jan Kara15100.00%1100.00%
Total15100.00%1100.00%

module_init(init_v1_quota_format); module_exit(exit_v1_quota_format);

Overall Contributors

PersonTokensPropCommitsCommitProp
Jan Kara117689.57%842.11%
Eric W. Biedermann513.88%15.26%
Andrew Morton332.51%315.79%
Andrew Perepechko201.52%15.26%
Art Haas181.37%15.26%
Dmitriy Monakhov80.61%15.26%
Jiaying Zhang30.23%15.26%
Al Viro30.23%210.53%
Alexey Dobriyan10.08%15.26%
Total1313100.00%19100.00%
Directory: fs/quota
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.
Created with cregit.