1884d179dSJan Kara /* 2884d179dSJan Kara * Quota code necessary even when VFS quota support is not compiled 3884d179dSJan Kara * into the kernel. The interesting stuff is over in dquot.c, here 4884d179dSJan Kara * we have symbols for initial quotactl(2) handling, the sysctl(2) 5884d179dSJan Kara * variables, etc - things needed even when quota support disabled. 6884d179dSJan Kara */ 7884d179dSJan Kara 8884d179dSJan Kara #include <linux/fs.h> 9884d179dSJan Kara #include <linux/namei.h> 10884d179dSJan Kara #include <linux/slab.h> 11884d179dSJan Kara #include <asm/current.h> 12f3da9310SJeff Liu #include <linux/uaccess.h> 13884d179dSJan Kara #include <linux/kernel.h> 14884d179dSJan Kara #include <linux/security.h> 15884d179dSJan Kara #include <linux/syscalls.h> 16884d179dSJan Kara #include <linux/capability.h> 17884d179dSJan Kara #include <linux/quotaops.h> 18884d179dSJan Kara #include <linux/types.h> 198c4e4acdSChristoph Hellwig #include <linux/writeback.h> 20884d179dSJan Kara 21c988afb5SChristoph Hellwig static int check_quotactl_permission(struct super_block *sb, int type, int cmd, 22268157baSJan Kara qid_t id) 23884d179dSJan Kara { 24c988afb5SChristoph Hellwig switch (cmd) { 25c988afb5SChristoph Hellwig /* these commands do not require any special privilegues */ 26c988afb5SChristoph Hellwig case Q_GETFMT: 27c988afb5SChristoph Hellwig case Q_SYNC: 28c988afb5SChristoph Hellwig case Q_GETINFO: 29c988afb5SChristoph Hellwig case Q_XGETQSTAT: 30af30cb44SChandra Seetharaman case Q_XGETQSTATV: 31c988afb5SChristoph Hellwig case Q_XQUOTASYNC: 32c988afb5SChristoph Hellwig break; 33c988afb5SChristoph Hellwig /* allow to query information for dquots we "own" */ 34c988afb5SChristoph Hellwig case Q_GETQUOTA: 35c988afb5SChristoph Hellwig case Q_XGETQUOTA: 3674a8a103SEric W. Biederman if ((type == USRQUOTA && uid_eq(current_euid(), make_kuid(current_user_ns(), id))) || 3774a8a103SEric W. Biederman (type == GRPQUOTA && in_egroup_p(make_kgid(current_user_ns(), id)))) 38c988afb5SChristoph Hellwig break; 39c988afb5SChristoph Hellwig /*FALLTHROUGH*/ 40c988afb5SChristoph Hellwig default: 41884d179dSJan Kara if (!capable(CAP_SYS_ADMIN)) 42884d179dSJan Kara return -EPERM; 43884d179dSJan Kara } 44884d179dSJan Kara 45c988afb5SChristoph Hellwig return security_quotactl(cmd, type, id, sb); 46884d179dSJan Kara } 47884d179dSJan Kara 4801a05b33SAl Viro static void quota_sync_one(struct super_block *sb, void *arg) 4901a05b33SAl Viro { 5001a05b33SAl Viro if (sb->s_qcop && sb->s_qcop->quota_sync) 51ceed1723SJan Kara sb->s_qcop->quota_sync(sb, *(int *)arg); 5201a05b33SAl Viro } 5301a05b33SAl Viro 546ae09575SChristoph Hellwig static int quota_sync_all(int type) 55884d179dSJan Kara { 566ae09575SChristoph Hellwig int ret; 576ae09575SChristoph Hellwig 586ae09575SChristoph Hellwig if (type >= MAXQUOTAS) 596ae09575SChristoph Hellwig return -EINVAL; 606ae09575SChristoph Hellwig ret = security_quotactl(Q_SYNC, type, 0, NULL); 6101a05b33SAl Viro if (!ret) 6201a05b33SAl Viro iterate_supers(quota_sync_one, &type); 636ae09575SChristoph Hellwig return ret; 64884d179dSJan Kara } 65884d179dSJan Kara 66c411e5f6SChristoph Hellwig static int quota_quotaon(struct super_block *sb, int type, int cmd, qid_t id, 67f00c9e44SJan Kara struct path *path) 68884d179dSJan Kara { 69f00c9e44SJan Kara if (!sb->s_qcop->quota_on && !sb->s_qcop->quota_on_meta) 70f00c9e44SJan Kara return -ENOSYS; 71f00c9e44SJan Kara if (sb->s_qcop->quota_on_meta) 72f00c9e44SJan Kara return sb->s_qcop->quota_on_meta(sb, type, id); 73f00c9e44SJan Kara if (IS_ERR(path)) 74f00c9e44SJan Kara return PTR_ERR(path); 75f00c9e44SJan Kara return sb->s_qcop->quota_on(sb, type, id, path); 76884d179dSJan Kara } 77884d179dSJan Kara 78c411e5f6SChristoph Hellwig static int quota_getfmt(struct super_block *sb, int type, void __user *addr) 79c411e5f6SChristoph Hellwig { 80884d179dSJan Kara __u32 fmt; 81884d179dSJan Kara 82884d179dSJan Kara down_read(&sb_dqopt(sb)->dqptr_sem); 83884d179dSJan Kara if (!sb_has_quota_active(sb, type)) { 84884d179dSJan Kara up_read(&sb_dqopt(sb)->dqptr_sem); 85884d179dSJan Kara return -ESRCH; 86884d179dSJan Kara } 87884d179dSJan Kara fmt = sb_dqopt(sb)->info[type].dqi_format->qf_fmt_id; 88884d179dSJan Kara up_read(&sb_dqopt(sb)->dqptr_sem); 89884d179dSJan Kara if (copy_to_user(addr, &fmt, sizeof(fmt))) 90884d179dSJan Kara return -EFAULT; 91884d179dSJan Kara return 0; 92884d179dSJan Kara } 93c411e5f6SChristoph Hellwig 94c411e5f6SChristoph Hellwig static int quota_getinfo(struct super_block *sb, int type, void __user *addr) 95c411e5f6SChristoph Hellwig { 96884d179dSJan Kara struct if_dqinfo info; 97c411e5f6SChristoph Hellwig int ret; 98884d179dSJan Kara 99f450d4feSChristoph Hellwig if (!sb->s_qcop->get_info) 100f450d4feSChristoph Hellwig return -ENOSYS; 101268157baSJan Kara ret = sb->s_qcop->get_info(sb, type, &info); 102c411e5f6SChristoph Hellwig if (!ret && copy_to_user(addr, &info, sizeof(info))) 103884d179dSJan Kara return -EFAULT; 104c411e5f6SChristoph Hellwig return ret; 105884d179dSJan Kara } 106c411e5f6SChristoph Hellwig 107c411e5f6SChristoph Hellwig static int quota_setinfo(struct super_block *sb, int type, void __user *addr) 108c411e5f6SChristoph Hellwig { 109884d179dSJan Kara struct if_dqinfo info; 110884d179dSJan Kara 111884d179dSJan Kara if (copy_from_user(&info, addr, sizeof(info))) 112884d179dSJan Kara return -EFAULT; 113f450d4feSChristoph Hellwig if (!sb->s_qcop->set_info) 114f450d4feSChristoph Hellwig return -ENOSYS; 115884d179dSJan Kara return sb->s_qcop->set_info(sb, type, &info); 116884d179dSJan Kara } 117c411e5f6SChristoph Hellwig 118b9b2dd36SChristoph Hellwig static void copy_to_if_dqblk(struct if_dqblk *dst, struct fs_disk_quota *src) 119b9b2dd36SChristoph Hellwig { 120*18da65e7SDan Carpenter memset(dst, 0, sizeof(*dst)); 121b9b2dd36SChristoph Hellwig dst->dqb_bhardlimit = src->d_blk_hardlimit; 122b9b2dd36SChristoph Hellwig dst->dqb_bsoftlimit = src->d_blk_softlimit; 123b9b2dd36SChristoph Hellwig dst->dqb_curspace = src->d_bcount; 124b9b2dd36SChristoph Hellwig dst->dqb_ihardlimit = src->d_ino_hardlimit; 125b9b2dd36SChristoph Hellwig dst->dqb_isoftlimit = src->d_ino_softlimit; 126b9b2dd36SChristoph Hellwig dst->dqb_curinodes = src->d_icount; 127b9b2dd36SChristoph Hellwig dst->dqb_btime = src->d_btimer; 128b9b2dd36SChristoph Hellwig dst->dqb_itime = src->d_itimer; 129b9b2dd36SChristoph Hellwig dst->dqb_valid = QIF_ALL; 130b9b2dd36SChristoph Hellwig } 131b9b2dd36SChristoph Hellwig 132c411e5f6SChristoph Hellwig static int quota_getquota(struct super_block *sb, int type, qid_t id, 133c411e5f6SChristoph Hellwig void __user *addr) 134c411e5f6SChristoph Hellwig { 13574a8a103SEric W. Biederman struct kqid qid; 136b9b2dd36SChristoph Hellwig struct fs_disk_quota fdq; 137884d179dSJan Kara struct if_dqblk idq; 138c411e5f6SChristoph Hellwig int ret; 139884d179dSJan Kara 140f450d4feSChristoph Hellwig if (!sb->s_qcop->get_dqblk) 141f450d4feSChristoph Hellwig return -ENOSYS; 14274a8a103SEric W. Biederman qid = make_kqid(current_user_ns(), type, id); 14374a8a103SEric W. Biederman if (!qid_valid(qid)) 14474a8a103SEric W. Biederman return -EINVAL; 14574a8a103SEric W. Biederman ret = sb->s_qcop->get_dqblk(sb, qid, &fdq); 146268157baSJan Kara if (ret) 147884d179dSJan Kara return ret; 148b9b2dd36SChristoph Hellwig copy_to_if_dqblk(&idq, &fdq); 149884d179dSJan Kara if (copy_to_user(addr, &idq, sizeof(idq))) 150884d179dSJan Kara return -EFAULT; 151884d179dSJan Kara return 0; 152884d179dSJan Kara } 153c411e5f6SChristoph Hellwig 154c472b432SChristoph Hellwig static void copy_from_if_dqblk(struct fs_disk_quota *dst, struct if_dqblk *src) 155c472b432SChristoph Hellwig { 156c472b432SChristoph Hellwig dst->d_blk_hardlimit = src->dqb_bhardlimit; 157c472b432SChristoph Hellwig dst->d_blk_softlimit = src->dqb_bsoftlimit; 158c472b432SChristoph Hellwig dst->d_bcount = src->dqb_curspace; 159c472b432SChristoph Hellwig dst->d_ino_hardlimit = src->dqb_ihardlimit; 160c472b432SChristoph Hellwig dst->d_ino_softlimit = src->dqb_isoftlimit; 161c472b432SChristoph Hellwig dst->d_icount = src->dqb_curinodes; 162c472b432SChristoph Hellwig dst->d_btimer = src->dqb_btime; 163c472b432SChristoph Hellwig dst->d_itimer = src->dqb_itime; 164c472b432SChristoph Hellwig 165c472b432SChristoph Hellwig dst->d_fieldmask = 0; 166c472b432SChristoph Hellwig if (src->dqb_valid & QIF_BLIMITS) 167c472b432SChristoph Hellwig dst->d_fieldmask |= FS_DQ_BSOFT | FS_DQ_BHARD; 168c472b432SChristoph Hellwig if (src->dqb_valid & QIF_SPACE) 169c472b432SChristoph Hellwig dst->d_fieldmask |= FS_DQ_BCOUNT; 170c472b432SChristoph Hellwig if (src->dqb_valid & QIF_ILIMITS) 171c472b432SChristoph Hellwig dst->d_fieldmask |= FS_DQ_ISOFT | FS_DQ_IHARD; 172c472b432SChristoph Hellwig if (src->dqb_valid & QIF_INODES) 173c472b432SChristoph Hellwig dst->d_fieldmask |= FS_DQ_ICOUNT; 174c472b432SChristoph Hellwig if (src->dqb_valid & QIF_BTIME) 175c472b432SChristoph Hellwig dst->d_fieldmask |= FS_DQ_BTIMER; 176c472b432SChristoph Hellwig if (src->dqb_valid & QIF_ITIME) 177c472b432SChristoph Hellwig dst->d_fieldmask |= FS_DQ_ITIMER; 178c472b432SChristoph Hellwig } 179c472b432SChristoph Hellwig 180c411e5f6SChristoph Hellwig static int quota_setquota(struct super_block *sb, int type, qid_t id, 181c411e5f6SChristoph Hellwig void __user *addr) 182c411e5f6SChristoph Hellwig { 183c472b432SChristoph Hellwig struct fs_disk_quota fdq; 184884d179dSJan Kara struct if_dqblk idq; 18574a8a103SEric W. Biederman struct kqid qid; 186884d179dSJan Kara 187884d179dSJan Kara if (copy_from_user(&idq, addr, sizeof(idq))) 188884d179dSJan Kara return -EFAULT; 189f450d4feSChristoph Hellwig if (!sb->s_qcop->set_dqblk) 190f450d4feSChristoph Hellwig return -ENOSYS; 19174a8a103SEric W. Biederman qid = make_kqid(current_user_ns(), type, id); 19274a8a103SEric W. Biederman if (!qid_valid(qid)) 19374a8a103SEric W. Biederman return -EINVAL; 194c472b432SChristoph Hellwig copy_from_if_dqblk(&fdq, &idq); 19574a8a103SEric W. Biederman return sb->s_qcop->set_dqblk(sb, qid, &fdq); 196884d179dSJan Kara } 197884d179dSJan Kara 198c411e5f6SChristoph Hellwig static int quota_setxstate(struct super_block *sb, int cmd, void __user *addr) 199c411e5f6SChristoph Hellwig { 200884d179dSJan Kara __u32 flags; 201884d179dSJan Kara 202884d179dSJan Kara if (copy_from_user(&flags, addr, sizeof(flags))) 203884d179dSJan Kara return -EFAULT; 204f450d4feSChristoph Hellwig if (!sb->s_qcop->set_xstate) 205f450d4feSChristoph Hellwig return -ENOSYS; 206884d179dSJan Kara return sb->s_qcop->set_xstate(sb, flags, cmd); 207884d179dSJan Kara } 208884d179dSJan Kara 209c411e5f6SChristoph Hellwig static int quota_getxstate(struct super_block *sb, void __user *addr) 210c411e5f6SChristoph Hellwig { 211c411e5f6SChristoph Hellwig struct fs_quota_stat fqs; 212c411e5f6SChristoph Hellwig int ret; 213c411e5f6SChristoph Hellwig 214f450d4feSChristoph Hellwig if (!sb->s_qcop->get_xstate) 215f450d4feSChristoph Hellwig return -ENOSYS; 216c411e5f6SChristoph Hellwig ret = sb->s_qcop->get_xstate(sb, &fqs); 217c411e5f6SChristoph Hellwig if (!ret && copy_to_user(addr, &fqs, sizeof(fqs))) 218884d179dSJan Kara return -EFAULT; 219c411e5f6SChristoph Hellwig return ret; 220884d179dSJan Kara } 221c411e5f6SChristoph Hellwig 222af30cb44SChandra Seetharaman static int quota_getxstatev(struct super_block *sb, void __user *addr) 223af30cb44SChandra Seetharaman { 224af30cb44SChandra Seetharaman struct fs_quota_statv fqs; 225af30cb44SChandra Seetharaman int ret; 226af30cb44SChandra Seetharaman 227af30cb44SChandra Seetharaman if (!sb->s_qcop->get_xstatev) 228af30cb44SChandra Seetharaman return -ENOSYS; 229af30cb44SChandra Seetharaman 230af30cb44SChandra Seetharaman memset(&fqs, 0, sizeof(fqs)); 231af30cb44SChandra Seetharaman if (copy_from_user(&fqs, addr, 1)) /* Just read qs_version */ 232af30cb44SChandra Seetharaman return -EFAULT; 233af30cb44SChandra Seetharaman 234af30cb44SChandra Seetharaman /* If this kernel doesn't support user specified version, fail */ 235af30cb44SChandra Seetharaman switch (fqs.qs_version) { 236af30cb44SChandra Seetharaman case FS_QSTATV_VERSION1: 237af30cb44SChandra Seetharaman break; 238af30cb44SChandra Seetharaman default: 239af30cb44SChandra Seetharaman return -EINVAL; 240af30cb44SChandra Seetharaman } 241af30cb44SChandra Seetharaman ret = sb->s_qcop->get_xstatev(sb, &fqs); 242af30cb44SChandra Seetharaman if (!ret && copy_to_user(addr, &fqs, sizeof(fqs))) 243af30cb44SChandra Seetharaman return -EFAULT; 244af30cb44SChandra Seetharaman return ret; 245af30cb44SChandra Seetharaman } 246af30cb44SChandra Seetharaman 247c411e5f6SChristoph Hellwig static int quota_setxquota(struct super_block *sb, int type, qid_t id, 248c411e5f6SChristoph Hellwig void __user *addr) 249c411e5f6SChristoph Hellwig { 250884d179dSJan Kara struct fs_disk_quota fdq; 25174a8a103SEric W. Biederman struct kqid qid; 252884d179dSJan Kara 253884d179dSJan Kara if (copy_from_user(&fdq, addr, sizeof(fdq))) 254884d179dSJan Kara return -EFAULT; 255c472b432SChristoph Hellwig if (!sb->s_qcop->set_dqblk) 256f450d4feSChristoph Hellwig return -ENOSYS; 25774a8a103SEric W. Biederman qid = make_kqid(current_user_ns(), type, id); 25874a8a103SEric W. Biederman if (!qid_valid(qid)) 25974a8a103SEric W. Biederman return -EINVAL; 26074a8a103SEric W. Biederman return sb->s_qcop->set_dqblk(sb, qid, &fdq); 261884d179dSJan Kara } 262c411e5f6SChristoph Hellwig 263c411e5f6SChristoph Hellwig static int quota_getxquota(struct super_block *sb, int type, qid_t id, 264c411e5f6SChristoph Hellwig void __user *addr) 265c411e5f6SChristoph Hellwig { 266884d179dSJan Kara struct fs_disk_quota fdq; 26774a8a103SEric W. Biederman struct kqid qid; 268c411e5f6SChristoph Hellwig int ret; 269884d179dSJan Kara 270b9b2dd36SChristoph Hellwig if (!sb->s_qcop->get_dqblk) 271f450d4feSChristoph Hellwig return -ENOSYS; 27274a8a103SEric W. Biederman qid = make_kqid(current_user_ns(), type, id); 27374a8a103SEric W. Biederman if (!qid_valid(qid)) 27474a8a103SEric W. Biederman return -EINVAL; 27574a8a103SEric W. Biederman ret = sb->s_qcop->get_dqblk(sb, qid, &fdq); 276c411e5f6SChristoph Hellwig if (!ret && copy_to_user(addr, &fdq, sizeof(fdq))) 277884d179dSJan Kara return -EFAULT; 278c411e5f6SChristoph Hellwig return ret; 279884d179dSJan Kara } 280c411e5f6SChristoph Hellwig 281c411e5f6SChristoph Hellwig /* Copy parameters and call proper function */ 282c411e5f6SChristoph Hellwig static int do_quotactl(struct super_block *sb, int type, int cmd, qid_t id, 283f00c9e44SJan Kara void __user *addr, struct path *path) 284c411e5f6SChristoph Hellwig { 285c988afb5SChristoph Hellwig int ret; 286c988afb5SChristoph Hellwig 287c988afb5SChristoph Hellwig if (type >= (XQM_COMMAND(cmd) ? XQM_MAXQUOTAS : MAXQUOTAS)) 288c988afb5SChristoph Hellwig return -EINVAL; 289c988afb5SChristoph Hellwig if (!sb->s_qcop) 290c988afb5SChristoph Hellwig return -ENOSYS; 291c988afb5SChristoph Hellwig 292c988afb5SChristoph Hellwig ret = check_quotactl_permission(sb, type, cmd, id); 293c988afb5SChristoph Hellwig if (ret < 0) 294c988afb5SChristoph Hellwig return ret; 295c988afb5SChristoph Hellwig 296c411e5f6SChristoph Hellwig switch (cmd) { 297c411e5f6SChristoph Hellwig case Q_QUOTAON: 298f00c9e44SJan Kara return quota_quotaon(sb, type, cmd, id, path); 299c411e5f6SChristoph Hellwig case Q_QUOTAOFF: 300f450d4feSChristoph Hellwig if (!sb->s_qcop->quota_off) 301f450d4feSChristoph Hellwig return -ENOSYS; 302307ae18aSChristoph Hellwig return sb->s_qcop->quota_off(sb, type); 303c411e5f6SChristoph Hellwig case Q_GETFMT: 304c411e5f6SChristoph Hellwig return quota_getfmt(sb, type, addr); 305c411e5f6SChristoph Hellwig case Q_GETINFO: 306c411e5f6SChristoph Hellwig return quota_getinfo(sb, type, addr); 307c411e5f6SChristoph Hellwig case Q_SETINFO: 308c411e5f6SChristoph Hellwig return quota_setinfo(sb, type, addr); 309c411e5f6SChristoph Hellwig case Q_GETQUOTA: 310c411e5f6SChristoph Hellwig return quota_getquota(sb, type, id, addr); 311c411e5f6SChristoph Hellwig case Q_SETQUOTA: 312c411e5f6SChristoph Hellwig return quota_setquota(sb, type, id, addr); 313c411e5f6SChristoph Hellwig case Q_SYNC: 314f450d4feSChristoph Hellwig if (!sb->s_qcop->quota_sync) 315f450d4feSChristoph Hellwig return -ENOSYS; 316ceed1723SJan Kara return sb->s_qcop->quota_sync(sb, type); 317c411e5f6SChristoph Hellwig case Q_XQUOTAON: 318c411e5f6SChristoph Hellwig case Q_XQUOTAOFF: 319c411e5f6SChristoph Hellwig case Q_XQUOTARM: 320c411e5f6SChristoph Hellwig return quota_setxstate(sb, cmd, addr); 321c411e5f6SChristoph Hellwig case Q_XGETQSTAT: 322c411e5f6SChristoph Hellwig return quota_getxstate(sb, addr); 323af30cb44SChandra Seetharaman case Q_XGETQSTATV: 324af30cb44SChandra Seetharaman return quota_getxstatev(sb, addr); 325c411e5f6SChristoph Hellwig case Q_XSETQLIM: 326c411e5f6SChristoph Hellwig return quota_setxquota(sb, type, id, addr); 327c411e5f6SChristoph Hellwig case Q_XGETQUOTA: 328c411e5f6SChristoph Hellwig return quota_getxquota(sb, type, id, addr); 329884d179dSJan Kara case Q_XQUOTASYNC: 3308c4e4acdSChristoph Hellwig if (sb->s_flags & MS_RDONLY) 3318c4e4acdSChristoph Hellwig return -EROFS; 3324b217ed9SChristoph Hellwig /* XFS quotas are fully coherent now, making this call a noop */ 3338c4e4acdSChristoph Hellwig return 0; 334884d179dSJan Kara default: 335f450d4feSChristoph Hellwig return -EINVAL; 336884d179dSJan Kara } 337884d179dSJan Kara } 338884d179dSJan Kara 33956df1278SLee Jones #ifdef CONFIG_BLOCK 34056df1278SLee Jones 341dcdbed85SJan Kara /* Return 1 if 'cmd' will block on frozen filesystem */ 342dcdbed85SJan Kara static int quotactl_cmd_write(int cmd) 343dcdbed85SJan Kara { 344dcdbed85SJan Kara switch (cmd) { 345dcdbed85SJan Kara case Q_GETFMT: 346dcdbed85SJan Kara case Q_GETINFO: 347dcdbed85SJan Kara case Q_SYNC: 348dcdbed85SJan Kara case Q_XGETQSTAT: 349af30cb44SChandra Seetharaman case Q_XGETQSTATV: 350dcdbed85SJan Kara case Q_XGETQUOTA: 351dcdbed85SJan Kara case Q_XQUOTASYNC: 352dcdbed85SJan Kara return 0; 353dcdbed85SJan Kara } 354dcdbed85SJan Kara return 1; 355dcdbed85SJan Kara } 356dcdbed85SJan Kara 35756df1278SLee Jones #endif /* CONFIG_BLOCK */ 35856df1278SLee Jones 359884d179dSJan Kara /* 360884d179dSJan Kara * look up a superblock on which quota ops will be performed 361884d179dSJan Kara * - use the name of a block device to find the superblock thereon 362884d179dSJan Kara */ 363dcdbed85SJan Kara static struct super_block *quotactl_block(const char __user *special, int cmd) 364884d179dSJan Kara { 365884d179dSJan Kara #ifdef CONFIG_BLOCK 366884d179dSJan Kara struct block_device *bdev; 367884d179dSJan Kara struct super_block *sb; 36891a27b2aSJeff Layton struct filename *tmp = getname(special); 369884d179dSJan Kara 370884d179dSJan Kara if (IS_ERR(tmp)) 371884d179dSJan Kara return ERR_CAST(tmp); 37291a27b2aSJeff Layton bdev = lookup_bdev(tmp->name); 373884d179dSJan Kara putname(tmp); 374884d179dSJan Kara if (IS_ERR(bdev)) 375884d179dSJan Kara return ERR_CAST(bdev); 376dcdbed85SJan Kara if (quotactl_cmd_write(cmd)) 377dcdbed85SJan Kara sb = get_super_thawed(bdev); 378dcdbed85SJan Kara else 379884d179dSJan Kara sb = get_super(bdev); 380884d179dSJan Kara bdput(bdev); 381884d179dSJan Kara if (!sb) 382884d179dSJan Kara return ERR_PTR(-ENODEV); 383884d179dSJan Kara 384884d179dSJan Kara return sb; 385884d179dSJan Kara #else 386884d179dSJan Kara return ERR_PTR(-ENODEV); 387884d179dSJan Kara #endif 388884d179dSJan Kara } 389884d179dSJan Kara 390884d179dSJan Kara /* 391884d179dSJan Kara * This is the system call interface. This communicates with 392884d179dSJan Kara * the user-level programs. Currently this only supports diskquota 393884d179dSJan Kara * calls. Maybe we need to add the process quotas etc. in the future, 394884d179dSJan Kara * but we probably should use rlimits for that. 395884d179dSJan Kara */ 396884d179dSJan Kara SYSCALL_DEFINE4(quotactl, unsigned int, cmd, const char __user *, special, 397884d179dSJan Kara qid_t, id, void __user *, addr) 398884d179dSJan Kara { 399884d179dSJan Kara uint cmds, type; 400884d179dSJan Kara struct super_block *sb = NULL; 401f00c9e44SJan Kara struct path path, *pathp = NULL; 402884d179dSJan Kara int ret; 403884d179dSJan Kara 404884d179dSJan Kara cmds = cmd >> SUBCMDSHIFT; 405884d179dSJan Kara type = cmd & SUBCMDMASK; 406884d179dSJan Kara 4076ae09575SChristoph Hellwig /* 4086ae09575SChristoph Hellwig * As a special case Q_SYNC can be called without a specific device. 4096ae09575SChristoph Hellwig * It will iterate all superblocks that have quota enabled and call 4106ae09575SChristoph Hellwig * the sync action on each of them. 4116ae09575SChristoph Hellwig */ 4126ae09575SChristoph Hellwig if (!special) { 4136ae09575SChristoph Hellwig if (cmds == Q_SYNC) 4146ae09575SChristoph Hellwig return quota_sync_all(type); 4156ae09575SChristoph Hellwig return -ENODEV; 4166ae09575SChristoph Hellwig } 4176ae09575SChristoph Hellwig 418f00c9e44SJan Kara /* 419f00c9e44SJan Kara * Path for quotaon has to be resolved before grabbing superblock 420f00c9e44SJan Kara * because that gets s_umount sem which is also possibly needed by path 421f00c9e44SJan Kara * resolution (think about autofs) and thus deadlocks could arise. 422f00c9e44SJan Kara */ 423f00c9e44SJan Kara if (cmds == Q_QUOTAON) { 424815d405cSTrond Myklebust ret = user_path_at(AT_FDCWD, addr, LOOKUP_FOLLOW|LOOKUP_AUTOMOUNT, &path); 425f00c9e44SJan Kara if (ret) 426f00c9e44SJan Kara pathp = ERR_PTR(ret); 427f00c9e44SJan Kara else 428f00c9e44SJan Kara pathp = &path; 429f00c9e44SJan Kara } 430f00c9e44SJan Kara 431dcdbed85SJan Kara sb = quotactl_block(special, cmds); 4320aaa6188SJan Kara if (IS_ERR(sb)) { 4330aaa6188SJan Kara ret = PTR_ERR(sb); 4340aaa6188SJan Kara goto out; 4350aaa6188SJan Kara } 436884d179dSJan Kara 437f00c9e44SJan Kara ret = do_quotactl(sb, type, cmds, id, addr, pathp); 438884d179dSJan Kara 4396ae09575SChristoph Hellwig drop_super(sb); 4400aaa6188SJan Kara out: 441f00c9e44SJan Kara if (pathp && !IS_ERR(pathp)) 442f00c9e44SJan Kara path_put(pathp); 443884d179dSJan Kara return ret; 444884d179dSJan Kara } 445