home *** CD-ROM | disk | FTP | other *** search
- /*
- * statfs() emulation for MiNT/TOS
- *
- * Written by Adrian Ashley (adrian@secret.uucp)
- * and placed in the public domain.
- */
-
- #include <errno.h>
- #include <stat.h>
- #include <osbind.h>
- #include <sys/statfs.h>
-
- int statfs(char *path, struct statfs *buf)
- {
- int r;
- struct {
- unsigned long free_blocks, total_blocks, sector_size, sec_per_block;
- } free;
- struct stat statbuf;
-
- if (!buf || !path)
- {
- errno = EFAULT;
- return -1;
- }
-
- r = stat(path, &statbuf);
-
- if (r == -1)
- return -1;
-
- (void) Dfree(&free, statbuf.st_dev + 1);
-
- buf->f_type = 0;
- buf->f_bsize = free.sector_size * free.sec_per_block;
- buf->f_blocks = free.total_blocks;
- buf->f_bfree = buf->f_bavail = free.free_blocks;
- buf->f_files = buf->f_ffree = buf->f_fsid.val[0] = buf->f_fsid.val[1] = -1L;
-
- return 0;
- }
-
- #ifdef TEST
-
- #include <stdio.h>
-
- main(int argc, char **argv)
- {
- int i = 0, r;
- register char *p;
- struct statfs stbuf;
-
- while (--argc)
- {
- p = argv[++i];
-
- r = statfs(p, &stbuf);
- if (r == -1)
- perror(p);
- else
- printf("statfs(`%s'): %ld free bytes\n", p,
- (long)(stbuf.f_bfree * stbuf.f_bsize));
- }
- return 0;
- }
-
- #endif
-