/* * Copyright (C), 2000-2003 by Contributors to the monit codebase. * All Rights Reserved. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software Foundation, * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /** * System dependent device methods. * * @author Jan-Henrik Haukeland, * @author Martin Pala, * * @version \$Id: sysdep_LINUX.c,v 1.1 2003/07/06 18:29:38 martinp Exp $ * * @file */ #include #include #ifdef HAVE_STRING_H #include #endif #ifdef HAVE_SYS_VFS_H # include #endif #ifdef HAVE_MNTENT_H #include #endif #include "monitor.h" #include "monit_device_sysdep.h" /** * Linux special block device mountpoint method. Filesystem must be mounted. * In the case of success, mountpoint is stored in device information * structure for later use. * * @param devinfo Information structure where resulting data will be stored * @param object Identifies block special device * @return NULL in the case of failure otherwise mountpoint */ char *DeviceInfo_MountPoint_sysdep(DeviceInfo_T devinfo, char *object) { struct mntent *mnt; FILE *mntfd; ASSERT(devinfo); ASSERT(object); if((mntfd= setmntent("/etc/mtab", "r")) == NULL) { log("%s: Cannot open /etc/mtab file", prog); return NULL; } /* First match is significant */ while((mnt= getmntent(mntfd)) != NULL) { if(IS(object, mnt->mnt_fsname)) { endmntent(mntfd); return strncpy(devinfo->mntpath, mnt->mnt_dir, sizeof(devinfo->mntpath)); } } endmntent(mntfd); return NULL; } /** * Linux filesystem usage statistics. In the case of success result is stored in * given information structure. * * @param devinfo Information structure where resulting data will be stored * @return TRUE if informations were succesfully read otherwise FALSE */ int DeviceInfo_Usage_sysdep(DeviceInfo_T devinfo) { struct statfs usage; ASSERT(devinfo); if(statfs(devinfo->mntpath, &usage) != 0) { log("%s: Error getting usage statistics for device '%s' -- %s\n", prog, devinfo->mntpath, STRERROR); return FALSE; } devinfo->f_bsize= usage.f_bsize; devinfo->f_blocks= usage.f_blocks; devinfo->f_blocksfree= usage.f_bavail; devinfo->f_blocksfreetotal= usage.f_bfree; devinfo->f_files= usage.f_files; devinfo->f_filesfree= usage.f_ffree; return TRUE; }