L4Re/departure

Annotated fsaccess/op_stat_objects.c

360:92c5f6aa8c36
2022-06-12 Paul Boddie Reintroduced PagerObject code generation required to initiate servers. mmap-region-flags
paul@295 1
/*
paul@295 2
 * Obtain object statistics from a filesystem.
paul@295 3
 *
paul@295 4
 * Copyright (C) 2019, 2022 Paul Boddie <paul@boddie.org.uk>
paul@295 5
 *
paul@295 6
 * This program is free software; you can redistribute it and/or
paul@295 7
 * modify it under the terms of the GNU General Public License as
paul@295 8
 * published by the Free Software Foundation; either version 2 of
paul@295 9
 * the License, or (at your option) any later version.
paul@295 10
 *
paul@295 11
 * This program is distributed in the hope that it will be useful,
paul@295 12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
paul@295 13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
paul@295 14
 * GNU General Public License for more details.
paul@295 15
 *
paul@295 16
 * You should have received a copy of the GNU General Public License
paul@295 17
 * along with this program; if not, write to the Free Software
paul@295 18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
paul@295 19
 * Boston, MA  02110-1301, USA
paul@295 20
 */
paul@295 21
paul@295 22
#include <stdio.h>
paul@295 23
paul@295 24
#include <sys/stat.h>
paul@295 25
#include <sys/sysmacros.h>  /* major, minor */
paul@295 26
#include <sys/types.h>
paul@295 27
paul@295 28
#include <fsclient/client.h>
paul@295 29
paul@295 30
#include "ops.h"
paul@295 31
paul@295 32
paul@295 33
paul@295 34
/* Show statistics for files and directories. */
paul@295 35
paul@295 36
int stat_objects(int argc, char *argv[])
paul@295 37
{
paul@295 38
    int i;
paul@295 39
    const char *path;
paul@295 40
    struct stat st;
paul@295 41
paul@295 42
    for (i = 0; i < argc; i++)
paul@295 43
    {
paul@295 44
        path = argv[i];
paul@295 45
paul@295 46
        /* Detect missing objects. */
paul@295 47
paul@295 48
        if (client_stat(path, &st))
paul@295 49
        {
paul@295 50
            fprintf(stderr, "Cannot stat object: %s\n", path);
paul@295 51
            return 1;
paul@295 52
        }
paul@295 53
paul@295 54
        /* Terse stat output:
paul@295 55
           %n %s %b %f %u %g %D %i %h %t %T %X %Y %Z %W %o %C */
paul@295 56
paul@295 57
        printf("%s %ld %ld %x %d %d ",
paul@295 58
            path, st.st_size, st.st_blocks, st.st_mode, st.st_uid, st.st_gid);
paul@295 59
paul@295 60
        printf("%ld %ld %ld %x %x ",
paul@295 61
            st.st_dev, st.st_ino, st.st_nlink,
paul@295 62
            major(st.st_rdev), minor(st.st_rdev));
paul@295 63
paul@295 64
        printf("%ld %ld %ld ",
paul@295 65
            st.st_atim.tv_sec, st.st_mtim.tv_sec, st.st_ctim.tv_sec);
paul@295 66
paul@295 67
        /* NOTE: Arbitrary values:
paul@295 68
           %W (creation time) given as 0
paul@295 69
           %o (I/O transfer size hint) given as 0
paul@295 70
           %C (SELinux security context) given as empty string */
paul@295 71
paul@295 72
        printf("%d %d %s\n",
paul@295 73
            0, 0, "");
paul@295 74
    }
paul@295 75
paul@295 76
    return 0;
paul@295 77
}
paul@295 78
paul@295 79
/* vim: tabstop=4 expandtab shiftwidth=4
paul@295 80
*/