fix issues with string truncation and undersized buffers. (NicJA)
[AROS.git] / compiler / posixc / statfs.c
blob532b1c4125a74b8788a3f177fbe80696b99b6014
1 /*
2 Copyright © 2008-2019, 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/exec.h>
10 #include <proto/dos.h>
11 #include <dos/dos.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 CopyMem(__path_a2u(AROS_BSTR_ADDR(((struct DeviceList *)BADDR(data.id_VolumeNode))->dl_Name)), buf->f_mntonname, MNAMELEN);
88 buf->f_mntonname[MNAMELEN -1] = '\0';
89 buf->f_mntfromname[0] = '\0';
91 else
93 ioerr = IoErr();
95 UnLock(lock);
97 else
99 ioerr = IoErr();
102 if(ioerr != 0) {
103 errno = __stdc_ioerr2errno(ioerr);
104 return -1;
107 return 0;