Repository navigation
Expand file tree
/
Copy pathstatvfs.c
More file actions
52 lines (44 loc) · 1.83 KB
/
Copy pathstatvfs.c
File metadata and controls
52 lines (44 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string.h>
#include <errno.h>
#include <sys/statvfs.h>
/* Lo scopo del programma e' di ottenere informazioni su un file system montato.
Il device relativo al file siystem viene fornito in input. */
int main(int argc, char *argv[]) {
char *pathname = NULL;
size_t len = 0;
int my_err = 0;
errno = 0;
struct statvfs device;
if (argc != 2) {
fprintf(stdout, "Usage: %s 'pathname'\n", argv[0]);
exit(EXIT_FAILURE);
}
len = strlen(argv[1]) + 1;
pathname = malloc(len * sizeof(char));
strncpy(pathname, argv[1], len);
if (statvfs(pathname, &device) == -1) {
my_err = errno;
fprintf(stdout, "Err.%d statvfs(); %s\n", my_err, strerror(errno));
exit(EXIT_FAILURE);
}
printf("%31s: %s\n", "file system", pathname);
printf("%31s: %lu (byte)\n", "fs block size", device.f_bsize);
printf("%31s: %lu (byte)\n", "fundamental fs block size", device.f_frsize);
printf("%31s: %lu\n", "total number of blocks", device.f_blocks);
printf("%31s: %lu\n", "total number of free blocks", device.f_bfree);
printf("%31s: %lu\n", "number of free blocks available", device.f_bavail);
printf("%31s: %lu\n", "total number of i-nodes", device.f_files);
printf("%31s: %lu\n", "total number of free i-nodes", device.f_ffree);
printf("%31s: %lu\n", "number of i-nodes available", device.f_favail);
printf("%31s: %lu\n", "File System ID", device.f_fsid);
printf("%31s: %lu\n", "Maximum length of filenames", device.f_namemax);
printf("%31s: %s\n", "flags (Read only)",
(device.f_flag & ST_RDONLY) == ST_RDONLY ? "yes" : "no");
printf("%31s: %s\n", "flags (No Suid)",
(device.f_flag & ST_NOSUID) == ST_NOSUID ? "yes" : "no");
free(pathname);
return(EXIT_SUCCESS);
}