podman

Форк
0
159 строк · 4.2 Кб
1
#include "c_helpers.h"
2

3
GETFUNC(cpu)
4
GETFUNC(disk)
5
GETFUNC(diskadapter)
6
GETFUNC(diskpath)
7
GETFUNC(fcstat)
8
GETFUNC(logicalvolume)
9
GETFUNC(memory_page)
10
GETFUNC(netadapter)
11
GETFUNC(netbuffer)
12
GETFUNC(netinterface)
13
GETFUNC(pagingspace)
14
GETFUNC(process)
15
GETFUNC(thread)
16
GETFUNC(volumegroup)
17

18
double get_partition_mhz(perfstat_partition_config_t pinfo) {
19
	return pinfo.processorMHz;
20
}
21

22
char *get_ps_hostname(perfstat_pagingspace_t *ps) {
23
	return ps->u.nfs_paging.hostname;
24
}
25

26
char *get_ps_filename(perfstat_pagingspace_t *ps) {
27
	return ps->u.nfs_paging.filename;
28
}
29

30
char *get_ps_vgname(perfstat_pagingspace_t *ps) {
31
	return ps->u.lv_paging.vgname;
32
}
33

34
time_t boottime()
35
{
36
        register struct utmpx *utmp;
37

38
	setutxent();
39
        while ( (utmp = getutxent()) != NULL ) {
40
                if (utmp->ut_type == BOOT_TIME) {
41
                        return utmp->ut_tv.tv_sec;
42
                }
43
        }
44
	endutxent();
45
        return -1;
46
}
47

48
struct fsinfo *get_filesystem_stat(struct fsinfo *fs_all, int n) {
49
	if (!fs_all) return NULL;
50
	return &(fs_all[n]);
51
}
52

53
int get_mounts(struct vmount **vmountpp) {
54
        int size;
55
        struct vmount *vm;
56
        int nmounts;
57

58
        size = BUFSIZ;
59

60
        while (1) {
61
                if ((vm = (struct vmount *)malloc((size_t)size)) == NULL) {
62
                        perror("malloc failed");
63
                        exit(-1);
64
                }
65
                if ((nmounts = mntctl(MCTL_QUERY, size, (caddr_t)vm)) > 0) {
66
                        *vmountpp = vm;
67
                        return nmounts;
68
                } else if (nmounts == 0) {
69
                        size = *(int *)vm;
70
                        free((void *)vm);
71
                } else {
72
                        free((void *)vm);
73
                        return -1;
74
                }
75
        }
76
}
77

78
void fill_fsinfo(struct statfs statbuf, struct fsinfo *fs) {
79
        fsblkcnt_t freeblks, totblks, usedblks;
80
        fsblkcnt_t tinodes, ninodes, ifree;
81
        uint    cfactor;
82

83
        if (statbuf.f_blocks == -1) {
84
                fs->totalblks = 0;
85
                fs->freeblks = 0;
86
                fs->totalinodes = 0;
87
                fs->freeinodes = 0;
88
                return;
89
        }
90

91
        cfactor = statbuf.f_bsize / 512;
92
        fs->freeblks = statbuf.f_bavail * cfactor;
93
        fs->totalblks = statbuf.f_blocks * cfactor;
94

95
        fs->freeinodes = statbuf.f_ffree;
96
        fs->totalinodes = statbuf.f_files;
97

98
        if (fs->freeblks < 0)
99
                fs->freeblks = 0;
100
}
101

102
int getfsinfo(char *fsname, char *devname, char *host, char *options, int flags, int fstype, struct fsinfo *fs) {
103
        struct statfs statbuf;
104
	int devname_size = strlen(devname);
105
	int fsname_size = strlen(fsname);
106
        char buf[BUFSIZ];
107
        char *p;
108

109
        if (fs == NULL) {
110
                return 1;
111
        }
112

113
        for (p = strtok(options, ","); p != NULL; p = strtok(NULL, ","))
114
                if (strcmp(p, "ignore") == 0)
115
                        return 0;
116

117
        if (*host != 0 && strcmp(host, "-") != 0) {
118
                sprintf(buf, "%s:%s", host, devname);
119
                devname = buf;
120
        }
121
        fs->devname = (char *)calloc(devname_size+1, 1);
122
        fs->fsname = (char *)calloc(fsname_size+1, 1);
123
        strncpy(fs->devname, devname, devname_size);
124
        strncpy(fs->fsname, fsname, fsname_size);
125
	fs->flags = flags;
126
	fs->fstype = fstype;
127

128
        if (statfs(fsname,&statbuf) < 0) {
129
                return 1;
130
        }
131

132
        fill_fsinfo(statbuf, fs);
133
        return 0;
134
}
135

136
struct fsinfo *get_all_fs(int *rc) {
137
        struct vmount *mnt;
138
        struct fsinfo *fs_all;
139
        int nmounts;
140

141
        *rc = -1;
142
        if ((nmounts = get_mounts(&mnt)) <= 0) {
143
                perror("Can't get mount table info");
144
                return NULL;
145
        }
146

147
        fs_all = (struct fsinfo *)calloc(sizeof(struct fsinfo), nmounts);
148
        while ((*rc)++, nmounts--) {
149
                getfsinfo(vmt2dataptr(mnt, VMT_STUB),
150
                          vmt2dataptr(mnt, VMT_OBJECT),
151
                          vmt2dataptr(mnt, VMT_HOST),
152
                          vmt2dataptr(mnt, VMT_ARGS),
153
			  mnt->vmt_flags,
154
			  mnt->vmt_gfstype,
155
                          &fs_all[*rc]);
156
                mnt = (struct vmount *)((char *)mnt + mnt->vmt_length);
157
        }
158
        return fs_all;
159
}
160

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.