Updated PCI IDs to latest snapshot.
[tangerine.git] / compiler / clib / getfsstat.c
blob88560009ac53540bb4605147a12ba37046641989
1 /*
2 Copyright © 2004, 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 "__errno.h"
15 #include "__upath.h"
17 short getnixfilesystemtype(LONG id_DiskType)
19 switch(id_DiskType)
21 case ID_DOS_DISK:
22 case ID_FASTDIR_DOS_DISK:
23 return MOUNT_ADOS_OFS;
24 case ID_INTER_DOS_DISK:
25 return MOUNT_ADOS_IOFS;
26 case ID_FFS_DISK:
27 case ID_FASTDIR_FFS_DISK:
28 return MOUNT_ADOS_FFS;
29 case ID_INTER_FFS_DISK:
30 return MOUNT_ADOS_IFFS;
31 default:
32 return MOUNT_NONE;
36 /*****************************************************************************
38 NAME */
39 #include <sys/mount.h>
41 int getfsstat(
43 /* SYNOPSIS */
44 struct statfs *buf,
45 long bufsize,
46 int flags)
48 /* FUNCTION
49 Gets information about mounted filesystems.
51 INPUTS
52 buf - pointer to statfs structures where information about filesystems
53 will be stored or NULL
54 bufsize - size of buf in bytes
55 flags - not used
57 RESULT
58 If buf is NULL number of mounted filesystems is returned. If buf is
59 not null, information about mounted filesystems is stored in statfs
60 structures up to bufsize bytes
62 NOTES
64 EXAMPLE
66 BUGS
67 f_flags, f_files, f_ffree and f_fsid.val are always set to 0
68 f_mntfromname is set to an empty string
70 SEE ALSO
72 INTERNALS
74 ******************************************************************************/
76 STRPTR name;
77 BPTR lock;
78 struct DosList *dlist;
79 struct InfoData data;
80 int fscount = 0; /* number of filesystems */
81 LONG ioerr = 0;
83 dlist = LockDosList(LDF_READ | LDF_VOLUMES);
84 while ((dlist = NextDosEntry(dlist, LDF_VOLUMES)) != NULL)
86 if(IsFileSystem(dlist->dol_Name) == FALSE)
87 continue;
88 fscount++;
90 /* If buf is NULL just count filesystems */
91 if(buf == NULL)
92 continue;
94 /* See if another structure can be stored */
95 bufsize -= sizeof(struct statfs);
96 if(bufsize < 0)
98 fscount--;
99 break;
102 /* Create a volume name */
103 if(!(name = (STRPTR) AllocVec(strlen(dlist->dol_Name) + 2,
104 MEMF_CLEAR | MEMF_ANY)))
106 ioerr = ERROR_NO_FREE_STORE;
107 break;
110 strcpy(name, dlist->dol_Name);
111 strcat(name, ":");
113 /* Get filesystem data from lock */
114 if((lock = Lock(name, SHARED_LOCK)))
116 if(Info(lock, &data))
118 /* Fill statfs structure */
119 buf[fscount - 1].f_type = getnixfilesystemtype(
120 data.id_DiskType);
121 buf[fscount - 1].f_flags = 0;
122 buf[fscount - 1].f_fsize = data.id_BytesPerBlock;
123 buf[fscount - 1].f_bsize = data.id_BytesPerBlock;
124 buf[fscount - 1].f_blocks = data.id_NumBlocks;
125 buf[fscount - 1].f_bfree = data.id_NumBlocks -
126 data.id_NumBlocksUsed;
127 buf[fscount - 1].f_bavail = data.id_NumBlocks -
128 data.id_NumBlocksUsed;
129 buf[fscount - 1].f_files = 0;
130 buf[fscount - 1].f_ffree = 0;
131 buf[fscount - 1].f_fsid.val[0] = 0;
132 buf[fscount - 1].f_fsid.val[1] = 0;
133 strncpy(buf[fscount - 1].f_mntonname, __path_a2u(name),
134 MNAMELEN);
135 buf[fscount - 1].f_mntfromname[0] = '\0';
137 else
139 ioerr = IoErr();
141 UnLock(lock);
143 else
145 ioerr = IoErr();
147 FreeVec(name);
148 if(ioerr)
149 break;
151 UnLockDosList(LDF_READ | LDF_VOLUMES);
153 if(ioerr) {
154 errno = IoErr2errno(ioerr);
155 return -1;
157 return fscount;