]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blobdiff - io/parent.c
xfsprogs: convert to SPDX license tags
[thirdparty/xfsprogs-dev.git] / io / parent.c
index 6f429b7e49d801fb8c405dfa290ad516ad727692..53ac659f0ff8c6f804239b519771970678d1f952 100644 (file)
@@ -1,28 +1,15 @@
+// SPDX-License-Identifier: GPL-2.0
 /*
  * Copyright (c) 2005-2006 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 <xfs/xfs.h>
-#include <xfs/command.h>
-#include <xfs/input.h>
-#include <xfs/path.h>
-#include <xfs/parent.h>
-#include <xfs/handle.h>
-#include <xfs/jdm.h>
+#include "command.h"
+#include "input.h"
+#include "path.h"
+#include "parent.h"
+#include "handle.h"
+#include "jdm.h"
 #include "init.h"
 #include "io.h"
 
@@ -52,12 +39,12 @@ check_parent_entry(xfs_bstat_t *bstatp, parent_t *parent)
        if (sts != 0) {
                fprintf(stderr,
                        _("inode-path for inode: %llu is incorrect - path \"%s\" non-existent\n"),
-                       bstatp->bs_ino, fullpath);
+                       (unsigned long long) bstatp->bs_ino, fullpath);
                if (verbose_flag) {
                        fprintf(stderr,
                                _("path \"%s\" does not stat for inode: %llu; err = %s\n"),
                                fullpath,
-                               bstatp->bs_ino,
+                              (unsigned long long) bstatp->bs_ino,
                                strerror(errno));
                }
                err_status++;
@@ -71,7 +58,7 @@ check_parent_entry(xfs_bstat_t *bstatp, parent_t *parent)
        if (statbuf.st_ino != bstatp->bs_ino) {
                fprintf(stderr,
                        _("inode-path for inode: %llu is incorrect - wrong inode#\n"),
-                       bstatp->bs_ino);
+                      (unsigned long long) bstatp->bs_ino);
                if (verbose_flag) {
                        fprintf(stderr,
                                _("ino mismatch for path \"%s\" %llu vs %llu\n"),
@@ -101,7 +88,7 @@ check_parent_entry(xfs_bstat_t *bstatp, parent_t *parent)
                if (parent->p_ino != statbuf.st_ino) {
                        fprintf(stderr,
                                _("inode-path for inode: %llu is incorrect - wrong parent inode#\n"),
-                               bstatp->bs_ino);
+                              (unsigned long long) bstatp->bs_ino);
                        if (verbose_flag) {
                                fprintf(stderr,
                                        _("ino mismatch for path \"%s\" %llu vs %llu\n"),
@@ -113,7 +100,8 @@ check_parent_entry(xfs_bstat_t *bstatp, parent_t *parent)
                        return;
                } else {
                        if (verbose_flag > 1) {
-                               printf(_("parent ino match for %llu\n"), parent->p_ino);
+                              printf(_("parent ino match for %llu\n"),
+                                      (unsigned long long) parent->p_ino);
                        }
                }
        }
@@ -135,17 +123,18 @@ check_parents(parent_t *parentbuf, size_t *parentbuf_size,
                        parentbuf = (parent_t *)realloc(parentbuf, *parentbuf_size);
                } else if (error) {
                        fprintf(stderr, _("parentpaths failed for ino %llu: %s\n"),
-                               statp->bs_ino,
+                              (unsigned long long) statp->bs_ino,
                                strerror(errno));
                        err_status++;
                        break;
                }
        } while (error == ERANGE);
-       
+
 
        if (count == 0) {
                /* no links for inode - something wrong here */
-               fprintf(stderr, _("inode-path for inode: %llu is missing\n"), statp->bs_ino);
+              fprintf(stderr, _("inode-path for inode: %llu is missing\n"),
+                              (unsigned long long) statp->bs_ino);
                err_status++;
        }
 
@@ -190,13 +179,13 @@ do_bulkstat(parent_t *parentbuf, size_t *parentbuf_size, xfs_bstat_t *bstatbuf,
                                if (xfsctl(mntpt, fsfd, XFS_IOC_FSBULKSTAT_SINGLE, &bulkreq) < 0) {
                                    fprintf(stderr,
                                          _("failed to get bulkstat information for inode %llu\n"),
-                                         p->bs_ino );
+                                        (unsigned long long) p->bs_ino);
                                    continue;
                                }
                                if (!p->bs_nlink || !p->bs_mode || !p->bs_ino) {
                                    fprintf(stderr,
                                          _("failed to get valid bulkstat information for inode %llu\n"),
-                                         p->bs_ino );
+                                        (unsigned long long) p->bs_ino);
                                    continue;
                                }
                        }
@@ -207,7 +196,8 @@ do_bulkstat(parent_t *parentbuf, size_t *parentbuf_size, xfs_bstat_t *bstatbuf,
                        }
 
                        if (verbose_flag > 1) {
-                               printf(_("checking inode %llu\n"), p->bs_ino);
+                              printf(_("checking inode %llu\n"),
+                                      (unsigned long long) p->bs_ino);
                        }
 
                        /* print dotted progress */
@@ -242,7 +232,7 @@ parent_check(void)
         fsfd = file->fd;
 
        fshandlep = jdm_getfshandle(mntpt);
-       if (fshandlep == 0) {
+       if (fshandlep == NULL) {
                fprintf(stderr, _("unable to open \"%s\" for jdm: %s\n"),
                      mntpt,
                      strerror(errno));
@@ -255,7 +245,8 @@ parent_check(void)
        if (!bstatbuf || !parentbuf) {
                fprintf(stderr, _("unable to allocate buffers: %s\n"),
                        strerror(errno));
-               return 1;
+               err_status = 1;
+               goto out;
        }
 
        if (do_bulkstat(parentbuf, &parentbuf_size, bstatbuf, fsfd, fshandlep) != 0)
@@ -264,17 +255,20 @@ parent_check(void)
        if (err_status > 0)
                fprintf(stderr, _("num errors: %d\n"), err_status);
        else
-               printf(_("succeeded checking %llu inodes\n"), inodes_checked);
+               printf(_("succeeded checking %llu inodes\n"),
+                       (unsigned long long) inodes_checked);
 
+out:
        free(bstatbuf);
        free(parentbuf);
+       free(fshandlep);
        return err_status;
 }
 
 static void
 print_parent_entry(parent_t *parent, int fullpath)
 {
-       printf(_("p_ino    = %llu\n"),  parent->p_ino);
+       printf(_("p_ino    = %llu\n"),  (unsigned long long) parent->p_ino);
        printf(_("p_gen    = %u\n"),    parent->p_gen);
        printf(_("p_reclen = %u\n"),    parent->p_reclen);
        if (fullpath)
@@ -286,7 +280,7 @@ print_parent_entry(parent_t *parent, int fullpath)
 static int
 parent_list(int fullpath)
 {
-       void *handlep;
+       void *handlep = NULL;
        size_t handlen;
        int error, i;
        int retval = 1;
@@ -306,6 +300,7 @@ parent_list(int fullpath)
                                progname, path, strerror(errno));
                        goto error;
                }
+               free_handle(fshandle, fshlen);
        }
 
        if (path_to_handle(path, &handlep, &handlen) != 0) {
@@ -318,7 +313,7 @@ parent_list(int fullpath)
                if (!parentbuf) {
                        fprintf(stderr, _("%s: unable to allocate parent buffer: %s\n"),
                                progname, strerror(errno));
-                       return 1;
+                       goto error;
                }
 
                if (fullpath) {
@@ -358,6 +353,7 @@ parent_list(int fullpath)
 
        retval = 0;
 error:
+       free(handlep);
        free(parentbuf);
        return retval;
 }
@@ -373,7 +369,7 @@ parent_f(int argc, char **argv)
 
        if (!tab_init) {
                tab_init = 1;
-               fs_table_initialise();
+               fs_table_initialise(0, NULL, 0, NULL);
        }
        fs = fs_table_lookup(file->name, FS_MOUNT_POINT);
        if (!fs) {
@@ -429,7 +425,7 @@ parent_help(void)
 void
 parent_init(void)
 {
-       parent_cmd.name = _("parent");
+       parent_cmd.name = "parent";
        parent_cmd.cfunc = parent_f;
        parent_cmd.argmin = 0;
        parent_cmd.argmax = -1;