]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blobdiff - quota/edit.c
libfrog: convert scrub.c functions to negative error codes
[thirdparty/xfsprogs-dev.git] / quota / edit.c
index 0170d51a69e5a3e785573b6d01e615ff28cd8208..f9938b8acbe0a3dc13f71b116bc71c88af073d19 100644 (file)
@@ -1,26 +1,14 @@
+// SPDX-License-Identifier: GPL-2.0
 /*
  * Copyright (c) 2005 Silicon Graphics, Inc.
  * All Rights Reserved.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write the Free Software Foundation,
- * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
 #include <pwd.h>
 #include <grp.h>
 #include <ctype.h>
-#include "xfs/input.h"
-#include "xfs/command.h"
+#include "input.h"
+#include "command.h"
 #include "init.h"
 #include "quota.h"
 
@@ -115,16 +103,16 @@ warn_help(void)
 
 static void
 set_limits(
-       __uint32_t      id,
+       uint32_t        id,
        uint            type,
        uint            mask,
        char            *dev,
-       __uint64_t      *bsoft,
-       __uint64_t      *bhard,
-       __uint64_t      *isoft,
-       __uint64_t      *ihard, 
-       __uint64_t      *rtbsoft,
-       __uint64_t      *rtbhard)
+       uint64_t        *bsoft,
+       uint64_t        *bhard,
+       uint64_t        *isoft,
+       uint64_t        *ihard,
+       uint64_t        *rtbsoft,
+       uint64_t        *rtbhard)
 {
        fs_disk_quota_t d;
 
@@ -152,12 +140,12 @@ set_user_limits(
        char            *name,
        uint            type,
        uint            mask,
-       __uint64_t      *bsoft,
-       __uint64_t      *bhard,
-       __uint64_t      *isoft,
-       __uint64_t      *ihard, 
-       __uint64_t      *rtbsoft,
-       __uint64_t      *rtbhard)
+       uint64_t        *bsoft,
+       uint64_t        *bhard,
+       uint64_t        *isoft,
+       uint64_t        *ihard,
+       uint64_t        *rtbsoft,
+       uint64_t        *rtbhard)
 {
        uid_t           uid = uid_from_string(name);
 
@@ -175,12 +163,12 @@ set_group_limits(
        char            *name,
        uint            type,
        uint            mask,
-       __uint64_t      *bsoft,
-       __uint64_t      *bhard,
-       __uint64_t      *isoft,
-       __uint64_t      *ihard, 
-       __uint64_t      *rtbsoft,
-       __uint64_t      *rtbhard)
+       uint64_t        *bsoft,
+       uint64_t        *bhard,
+       uint64_t        *isoft,
+       uint64_t        *ihard,
+       uint64_t        *rtbsoft,
+       uint64_t        *rtbhard)
 {
        gid_t           gid = gid_from_string(name);
 
@@ -198,12 +186,12 @@ set_project_limits(
        char            *name,
        uint            type,
        uint            mask,
-       __uint64_t      *bsoft,
-       __uint64_t      *bhard,
-       __uint64_t      *isoft,
-       __uint64_t      *ihard, 
-       __uint64_t      *rtbsoft,
-       __uint64_t      *rtbhard)
+       uint64_t        *bsoft,
+       uint64_t        *bhard,
+       uint64_t        *isoft,
+       uint64_t        *ihard,
+       uint64_t        *rtbsoft,
+       uint64_t        *rtbhard)
 {
        prid_t          prid = prid_from_string(name);
 
@@ -224,7 +212,7 @@ extractb(
        int             length,
        uint            blocksize,
        uint            sectorsize,
-       __uint64_t      *value)
+       uint64_t        *value)
 {
        long long       v;
        char            *s = string;
@@ -238,7 +226,7 @@ extractb(
                                progname, s);
                        return 0;
                }
-               *value = (__uint64_t)v >> 9;    /* syscalls use basic blocks */
+               *value = (uint64_t)v >> 9;      /* syscalls use basic blocks */
                if (v > 0 && *value == 0)
                        fprintf(stderr, _("%s: Warning: `%s' in quota blocks is 0 (unlimited).\n"), progname, s);
                return 1;
@@ -252,7 +240,7 @@ extracti(
        char            *string,
        const char      *prefix,
        int             length,
-       __uint64_t      *value)
+       uint64_t        *value)
 {
        char            *sp, *s = string;
 
@@ -270,7 +258,7 @@ limit_f(
        char            **argv)
 {
        char            *name;
-       __uint64_t      bsoft, bhard, isoft, ihard, rtbsoft, rtbhard;
+       uint64_t        bsoft, bhard, isoft, ihard, rtbsoft, rtbhard;
        int             c, type = 0, mask = 0, flags = 0;
        uint            bsize, ssize, endoptions;
 
@@ -282,13 +270,13 @@ limit_f(
                        flags |= DEFAULTS_FLAG;
                        break;
                case 'g':
-                       type = XFS_GROUP_QUOTA;
+                       type |= XFS_GROUP_QUOTA;
                        break;
                case 'p':
-                       type = XFS_PROJ_QUOTA;
+                       type |= XFS_PROJ_QUOTA;
                        break;
                case 'u':
-                       type = XFS_USER_QUOTA;
+                       type |= XFS_USER_QUOTA;
                        break;
                default:
                        return command_usage(&limit_cmd);
@@ -343,8 +331,13 @@ limit_f(
 
        name = (flags & DEFAULTS_FLAG) ? "0" : argv[optind++];
 
-       if (!type)
+       if (!type) {
                type = XFS_USER_QUOTA;
+       } else if (type != XFS_GROUP_QUOTA &&
+                  type != XFS_PROJ_QUOTA &&
+                  type != XFS_USER_QUOTA) {
+               return command_usage(&limit_cmd);
+       }
 
        switch (type) {
        case XFS_USER_QUOTA:
@@ -375,16 +368,19 @@ restore_file(
        uint            type)
 {
        char            buffer[512];
-       char            devbuffer[512];
-       char            *dev = NULL;
+       char            dev[512];
        uint            mask;
        int             cnt;
-       __uint32_t      id;
-       __uint64_t      bsoft, bhard, isoft, ihard, rtbsoft, rtbhard;
+       uint32_t        id;
+       uint64_t        bsoft, bhard, isoft, ihard, rtbsoft, rtbhard;
 
        while (fgets(buffer, sizeof(buffer), fp) != NULL) {
                if (strncmp("fs = ", buffer, 5) == 0) {
-                       dev = strncpy(devbuffer, buffer+5, sizeof(devbuffer));
+                       /*
+                        * Copy the device name to dev, strip off the trailing
+                        * newline, and move on to the next line.
+                        */
+                       strncpy(dev, buffer + 5, sizeof(dev) - 1);
                        dev[strlen(dev) - 1] = '\0';
                        continue;
                }
@@ -422,13 +418,13 @@ restore_f(
                        fname = optarg;
                        break;
                case 'g':
-                       type = XFS_GROUP_QUOTA;
+                       type |= XFS_GROUP_QUOTA;
                        break;
                case 'p':
-                       type = XFS_PROJ_QUOTA;
+                       type |= XFS_PROJ_QUOTA;
                        break;
                case 'u':
-                       type = XFS_USER_QUOTA;
+                       type |= XFS_USER_QUOTA;
                        break;
                default:
                        return command_usage(&restore_cmd);
@@ -438,8 +434,13 @@ restore_f(
        if (argc < optind)
                return command_usage(&restore_cmd);
 
-       if (!type)
+       if (!type) {
                type = XFS_USER_QUOTA;
+       } else if (type != XFS_GROUP_QUOTA &&
+                  type != XFS_PROJ_QUOTA &&
+                  type != XFS_USER_QUOTA) {
+               return command_usage(&restore_cmd);
+       }
 
        if (fname) {
                if ((fp = fopen(fname, "r")) == NULL) {
@@ -501,13 +502,13 @@ timer_f(
                        mask |= FS_DQ_RTBTIMER;
                        break;
                case 'g':
-                       type = XFS_GROUP_QUOTA;
+                       type |= XFS_GROUP_QUOTA;
                        break;
                case 'p':
-                       type = XFS_PROJ_QUOTA;
+                       type |= XFS_PROJ_QUOTA;
                        break;
                case 'u':
-                       type = XFS_USER_QUOTA;
+                       type |= XFS_USER_QUOTA;
                        break;
                default:
                        return command_usage(&timer_cmd);
@@ -522,8 +523,13 @@ timer_f(
        if (!mask)
                mask = FS_DQ_TIMER_MASK;
 
-       if (!type)
+       if (!type) {
                type = XFS_USER_QUOTA;
+       } else if (type != XFS_GROUP_QUOTA &&
+                  type != XFS_PROJ_QUOTA &&
+                  type != XFS_USER_QUOTA) {
+               return command_usage(&timer_cmd);
+       }
 
        set_timer(type, mask, fs_path->fs_name, value);
        return 0;
@@ -531,7 +537,7 @@ timer_f(
 
 static void
 set_warnings(
-       __uint32_t      id,
+       uint32_t        id,
        uint            type,
        uint            mask,
        char            *dev,
@@ -630,13 +636,13 @@ warn_f(
                        mask |= FS_DQ_RTBWARNS;
                        break;
                case 'g':
-                       type = XFS_GROUP_QUOTA;
+                       type |= XFS_GROUP_QUOTA;
                        break;
                case 'p':
-                       type = XFS_PROJ_QUOTA;
+                       type |= XFS_PROJ_QUOTA;
                        break;
                case 'u':
-                       type = XFS_USER_QUOTA;
+                       type |= XFS_USER_QUOTA;
                        break;
                default:
                        return command_usage(&warn_cmd);
@@ -661,8 +667,13 @@ warn_f(
        if (!mask)
                mask = FS_DQ_WARNS_MASK;
 
-       if (!type)
+       if (!type) {
                type = XFS_USER_QUOTA;
+       } else if (type != XFS_GROUP_QUOTA &&
+                  type != XFS_PROJ_QUOTA &&
+                  type != XFS_USER_QUOTA) {
+               return command_usage(&warn_cmd);
+       }
 
        switch (type) {
        case XFS_USER_QUOTA:
@@ -686,30 +697,33 @@ edit_init(void)
        limit_cmd.argmin = 2;
        limit_cmd.argmax = -1;
        limit_cmd.args = \
-       _("[-gpu] bsoft|bhard|isoft|ihard|rtbsoft|rtbhard=N -d|id|name");
+       _("[-g|-p|-u] bsoft|bhard|isoft|ihard|rtbsoft|rtbhard=N -d|id|name");
        limit_cmd.oneline = _("modify quota limits");
        limit_cmd.help = limit_help;
+       limit_cmd.flags = CMD_FLAG_FOREIGN_OK;
 
        restore_cmd.name = "restore";
        restore_cmd.cfunc = restore_f;
        restore_cmd.argmin = 0;
        restore_cmd.argmax = -1;
-       restore_cmd.args = _("[-gpu] [-f file]");
+       restore_cmd.args = _("[-g|-p|-u] [-f file]");
        restore_cmd.oneline = _("restore quota limits from a backup file");
+       restore_cmd.flags = CMD_FLAG_FOREIGN_OK;
 
        timer_cmd.name = "timer";
        timer_cmd.cfunc = timer_f;
        timer_cmd.argmin = 2;
        timer_cmd.argmax = -1;
-       timer_cmd.args = _("[-bir] [-gpu] value -d|id|name");
-       timer_cmd.oneline = _("get/set quota enforcement timeouts");
+       timer_cmd.args = _("[-bir] [-g|-p|-u] value");
+       timer_cmd.oneline = _("set quota enforcement timeouts");
        timer_cmd.help = timer_help;
+       timer_cmd.flags = CMD_FLAG_FOREIGN_OK;
 
        warn_cmd.name = "warn";
        warn_cmd.cfunc = warn_f;
        warn_cmd.argmin = 2;
        warn_cmd.argmax = -1;
-       warn_cmd.args = _("[-bir] [-gpu] value -d|id|name");
+       warn_cmd.args = _("[-bir] [-g|-p|-u] value -d|id|name");
        warn_cmd.oneline = _("get/set enforcement warning counter");
        warn_cmd.help = warn_help;