muimaster.library: support Listview_List in List
[AROS.git] / compiler / posixc / getfsstat.c
bloba4c2959f19382307968b5cfc7f2049e30f163f07
1 /*
2 Copyright © 2004-2012, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <aros/debug.h>
8 #include <string.h>
9 #include <errno.h>
10 #include <sys/mount.h>
11 #include <proto/dos.h>
12 #include <dos/dos.h>
13 #include <proto/exec.h>
14 #include "__upath.h"
16 short getnixfilesystemtype(LONG id_DiskType)
18 switch(id_DiskType)
20 case ID_DOS_DISK:
21 case ID_FASTDIR_DOS_DISK:
22 return MOUNT_ADOS_OFS;
23 case ID_INTER_DOS_DISK:
24 return MOUNT_ADOS_IOFS;
25 case ID_FFS_DISK:
26 case ID_FASTDIR_FFS_DISK:
27 return MOUNT_ADOS_FFS;
28 case ID_INTER_FFS_DISK:
29 return MOUNT_ADOS_IFFS;
30 default:
31 return MOUNT_NONE;
35 /*****************************************************************************
37 NAME */
38 #include <sys/mount.h>
40 int getfsstat(
42 /* SYNOPSIS */
43 struct statfs *buf,
44 long bufsize,
45 int flags)
47 /* FUNCTION
48 Gets information about mounted filesystems.
50 INPUTS
51 buf - pointer to statfs structures where information about filesystems
52 will be stored or NULL
53 bufsize - size of buf in bytes
54 flags - not used
56 RESULT
57 If buf is NULL number of mounted filesystems is returned. If buf is
58 not null, information about mounted filesystems is stored in statfs
59 structures up to bufsize bytes
61 NOTES
63 EXAMPLE
65 BUGS
66 f_flags, f_files, f_ffree and f_fsid.val are always set to 0
67 f_mntfromname is set to an empty string
69 SEE ALSO
71 INTERNALS
73 ******************************************************************************/
75 STRPTR name;
76 BPTR lock;
77 struct DosList *dlist;
78 struct InfoData data;
79 int fscount = 0; /* number of filesystems */
80 LONG ioerr = 0;
82 dlist = LockDosList(LDF_READ | LDF_VOLUMES);
83 while ((dlist = NextDosEntry(dlist, LDF_VOLUMES)) != NULL)
85 if(IsFileSystem(AROS_BSTR_ADDR(dlist->dol_Name)) == FALSE)
86 continue;
87 fscount++;
89 /* If buf is NULL just count filesystems */
90 if(buf == NULL)
91 continue;
93 /* See if another structure can be stored */
94 bufsize -= sizeof(struct statfs);
95 if(bufsize < 0)
97 fscount--;
98 break;
101 /* Create a volume name */
102 if(!(name = (STRPTR) AllocVec(AROS_BSTR_strlen(dlist->dol_Name) + 2,
103 MEMF_CLEAR | MEMF_ANY)))
105 ioerr = ERROR_NO_FREE_STORE;
106 break;
109 strcpy(name, AROS_BSTR_ADDR(dlist->dol_Name));
110 strcat(name, ":");
112 /* Get filesystem data from lock */
113 if((lock = Lock(name, SHARED_LOCK)))
115 if(Info(lock, &data))
117 /* Fill statfs structure */
118 buf[fscount - 1].f_type = getnixfilesystemtype(
119 data.id_DiskType);
120 buf[fscount - 1].f_flags = 0;
121 buf[fscount - 1].f_fsize = data.id_BytesPerBlock;
122 buf[fscount - 1].f_bsize = data.id_BytesPerBlock;
123 buf[fscount - 1].f_blocks = data.id_NumBlocks;
124 buf[fscount - 1].f_bfree = data.id_NumBlocks -
125 data.id_NumBlocksUsed;
126 buf[fscount - 1].f_bavail = data.id_NumBlocks -
127 data.id_NumBlocksUsed;
128 buf[fscount - 1].f_files = 0;
129 buf[fscount - 1].f_ffree = 0;
130 buf[fscount - 1].f_fsid.val[0] = 0;
131 buf[fscount - 1].f_fsid.val[1] = 0;
132 strncpy(buf[fscount - 1].f_mntonname, __path_a2u(name),
133 MNAMELEN);
134 buf[fscount - 1].f_mntfromname[0] = '\0';
136 else
138 ioerr = IoErr();
140 UnLock(lock);
142 else
144 ioerr = IoErr();
146 FreeVec(name);
147 if(ioerr)
148 break;
150 UnLockDosList(LDF_READ | LDF_VOLUMES);
152 if(ioerr) {
153 errno = __stdc_ioerr2errno(ioerr);
154 return -1;
156 return fscount;