tools/toollib: remove from main Makefile.in
[AROS.git] / compiler / posixc / statfs.c
blob7c6874e2626d2590ddb1e7ebe6ae7ee0557f2a68
1 /*
2 Copyright © 2008-2012, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <string.h>
7 #include <errno.h>
8 #include <sys/mount.h>
9 #include <proto/dos.h>
10 #include <dos/dos.h>
11 #include "__upath.h"
13 short getnixfilesystemtype(LONG id_DiskType);
15 /*****************************************************************************
17 NAME */
18 #include <sys/mount.h>
20 int statfs(
22 /* SYNOPSIS */
23 const char *path,
24 struct statfs *buf)
26 /* FUNCTION
27 Gets information about mounted filesystem.
29 INPUTS
30 path - path to any file in the filesystem we want to know about
31 buf - pointer to statfs structures where information about filesystem
32 will be stored
34 RESULT
35 Information about filesystem is stored in statfs structure
37 NOTES
39 EXAMPLE
41 BUGS
42 f_flags, f_files, f_ffree and f_fsid.val are always set to 0
43 f_mntfromname is set to an empty string
45 SEE ALSO
47 INTERNALS
49 ******************************************************************************/
51 BPTR lock;
52 LONG ioerr = 0;
53 struct InfoData data;
54 const char *apath;
56 if (path == NULL)
58 errno = EINVAL;
59 return -1;
62 apath = __path_u2a(path);
63 if (!apath)
65 errno = EINVAL;
66 return -1;
69 /* Get filesystem data from lock */
70 if(((lock = Lock(apath, SHARED_LOCK))))
72 if(Info(lock, &data))
74 /* Fill statfs structure */
75 buf->f_type = getnixfilesystemtype(data.id_DiskType);
76 buf->f_flags = 0;
77 buf->f_fsize = data.id_BytesPerBlock;
78 buf->f_bsize = data.id_BytesPerBlock;
79 buf->f_blocks = data.id_NumBlocks;
80 buf->f_bfree = data.id_NumBlocks - data.id_NumBlocksUsed;
81 buf->f_bavail = data.id_NumBlocks - data.id_NumBlocksUsed;
82 buf->f_files = 0;
83 buf->f_ffree = 0;
84 buf->f_fsid.val[0] = 0;
85 buf->f_fsid.val[1] = 0;
86 strncpy(buf->f_mntonname, __path_a2u(AROS_BSTR_ADDR(((struct DeviceList *)BADDR(data.id_VolumeNode))->dl_Name)), MNAMELEN);
87 buf->f_mntfromname[0] = '\0';
89 else
91 ioerr = IoErr();
93 UnLock(lock);
95 else
97 ioerr = IoErr();
100 if(ioerr != 0) {
101 errno = __stdc_ioerr2errno(ioerr);
102 return -1;
105 return 0;