use same location as .configured, etc, to store .files-touched
[AROS.git] / compiler / clib / statfs.c
blob6e5e3a3c282a08d9dfefc9576d2fbf42a47b8abb
1 /*
2 Copyright © 2008, 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 "__errno.h"
12 #include "__upath.h"
14 short getnixfilesystemtype(LONG id_DiskType);
16 /*****************************************************************************
18 NAME */
19 #include <sys/mount.h>
21 int statfs(
23 /* SYNOPSIS */
24 const char *path,
25 struct statfs *buf)
27 /* FUNCTION
28 Gets information about mounted filesystem.
30 INPUTS
31 path - path to any file in the filesystem we want to know about
32 buf - pointer to statfs structures where information about filesystem
33 will be stored
35 RESULT
36 Information about filesystem is stored in statfs structure
38 NOTES
40 EXAMPLE
42 BUGS
43 f_flags, f_files, f_ffree and f_fsid.val are always set to 0
44 f_mntfromname is set to an empty string
46 SEE ALSO
48 INTERNALS
50 ******************************************************************************/
52 BPTR lock;
53 LONG ioerr = 0;
54 struct InfoData data;
55 const char *apath;
57 if (path == NULL)
59 errno = EINVAL;
60 return -1;
63 apath = __path_u2a(path);
64 if (!apath)
66 errno = EINVAL;
67 return -1;
70 /* Get filesystem data from lock */
71 if(((lock = Lock(apath, SHARED_LOCK))))
73 if(Info(lock, &data))
75 /* Fill statfs structure */
76 buf->f_type = getnixfilesystemtype(data.id_DiskType);
77 buf->f_flags = 0;
78 buf->f_fsize = data.id_BytesPerBlock;
79 buf->f_bsize = data.id_BytesPerBlock;
80 buf->f_blocks = data.id_NumBlocks;
81 buf->f_bfree = data.id_NumBlocks - data.id_NumBlocksUsed;
82 buf->f_bavail = data.id_NumBlocks - data.id_NumBlocksUsed;
83 buf->f_files = 0;
84 buf->f_ffree = 0;
85 buf->f_fsid.val[0] = 0;
86 buf->f_fsid.val[1] = 0;
87 strncpy(buf->f_mntonname, __path_a2u(AROS_BSTR_ADDR(((struct DeviceList *)BADDR(data.id_VolumeNode))->dl_Name)), MNAMELEN);
88 buf->f_mntfromname[0] = '\0';
90 else
92 ioerr = IoErr();
94 UnLock(lock);
96 else
98 ioerr = IoErr();
101 if(ioerr != 0) {
102 errno = IoErr2errno(ioerr);
103 return -1;
106 return 0;