From: <ba...@us...> - 2007-02-14 17:38:59
|
Revision: 440 http://svn.sourceforge.net/omc/?rev=440&view=rev Author: bartw Date: 2007-02-14 09:38:58 -0800 (Wed, 14 Feb 2007) Log Message: ----------- re-added fileTools Modified Paths: -------------- omccmpi/trunk/src/include/omc/Makefile.am omccmpi/trunk/src/lib/omc/Makefile.am Added Paths: ----------- omccmpi/trunk/src/include/omc/fileTools.h omccmpi/trunk/src/lib/omc/fileTools.c Removed Paths: ------------- omccmpi/trunk/src/include/omc/Makefile.in Modified: omccmpi/trunk/src/include/omc/Makefile.am =================================================================== --- omccmpi/trunk/src/include/omc/Makefile.am 2007-02-14 17:17:15 UTC (rev 439) +++ omccmpi/trunk/src/include/omc/Makefile.am 2007-02-14 17:38:58 UTC (rev 440) @@ -8,6 +8,7 @@ exec.h \ ioUtils.h \ modifyFile.h \ + fileTools.h \ string.h \ linuxProcUtils.h \ cmpiUtils.h \ Deleted: omccmpi/trunk/src/include/omc/Makefile.in =================================================================== --- omccmpi/trunk/src/include/omc/Makefile.in 2007-02-14 17:17:15 UTC (rev 439) +++ omccmpi/trunk/src/include/omc/Makefile.in 2007-02-14 17:38:58 UTC (rev 440) @@ -1,406 +0,0 @@ -# Makefile.in generated by automake 1.9.6 from Makefile.am. -# @configure_input@ - -# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, -# 2003, 2004, 2005 Free Software Foundation, Inc. -# This Makefile.in is free software; the Free Software Foundation -# gives unlimited permission to copy and/or distribute it, -# with or without modifications, as long as this notice is preserved. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY, to the extent permitted by law; without -# even the implied warranty of MERCHANTABILITY or FITNESS FOR A -# PARTICULAR PURPOSE. - -@SET_MAKE@ - -srcdir = @srcdir@ -top_srcdir = @top_srcdir@ -VPATH = @srcdir@ -pkgdatadir = $(datadir)/@PACKAGE@ -pkglibdir = $(libdir)/@PACKAGE@ -top_builddir = ../../.. -am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd -INSTALL = @INSTALL@ -install_sh_DATA = $(install_sh) -c -m 644 -install_sh_PROGRAM = $(install_sh) -c -install_sh_SCRIPT = $(install_sh) -c -INSTALL_HEADER = $(INSTALL_DATA) -transform = $(program_transform_name) -NORMAL_INSTALL = : -PRE_INSTALL = : -POST_INSTALL = : -NORMAL_UNINSTALL = : -PRE_UNINSTALL = : -POST_UNINSTALL = : -build_triplet = @build@ -host_triplet = @host@ -subdir = src/include/omc -DIST_COMMON = $(pkginclude_HEADERS) $(srcdir)/Makefile.am \ - $(srcdir)/Makefile.in -ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 -am__aclocal_m4_deps = $(top_srcdir)/configure.ac -am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ - $(ACLOCAL_M4) -mkinstalldirs = $(install_sh) -d -CONFIG_HEADER = $(top_builddir)/config.h -CONFIG_CLEAN_FILES = -SOURCES = -DIST_SOURCES = -am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; -am__vpath_adj = case $$p in \ - $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ - *) f=$$p;; \ - esac; -am__strip_dir = `echo $$p | sed -e 's|^.*/||'`; -am__installdirs = "$(DESTDIR)$(pkgincludedir)" -pkgincludeHEADERS_INSTALL = $(INSTALL_HEADER) -HEADERS = $(pkginclude_HEADERS) -ETAGS = etags -CTAGS = ctags -DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) -pkgincludedir = $(includedir)/omccmpi -ACLOCAL = @ACLOCAL@ -ALLOCA = @ALLOCA@ -AMDEP_FALSE = @AMDEP_FALSE@ -AMDEP_TRUE = @AMDEP_TRUE@ -AMTAR = @AMTAR@ -AR = @AR@ -AUTOCONF = @AUTOCONF@ -AUTOHEADER = @AUTOHEADER@ -AUTOMAKE = @AUTOMAKE@ -AWK = @AWK@ -CC = @CC@ -CCDEPMODE = @CCDEPMODE@ -CFLAGS = @CFLAGS@ -CP = @CP@ -CPP = @CPP@ -CPPFLAGS = @CPPFLAGS@ -CXX = @CXX@ -CXXCPP = @CXXCPP@ -CXXDEPMODE = @CXXDEPMODE@ -CXXFLAGS = @CXXFLAGS@ -CYGPATH_W = @CYGPATH_W@ -DEFS = @DEFS@ -DEPDIR = @DEPDIR@ -ECHO = @ECHO@ -ECHO_C = @ECHO_C@ -ECHO_N = @ECHO_N@ -ECHO_T = @ECHO_T@ -EGREP = @EGREP@ -EXEEXT = @EXEEXT@ -F77 = @F77@ -FFLAGS = @FFLAGS@ -INSTALL_DATA = @INSTALL_DATA@ -INSTALL_PROGRAM = @INSTALL_PROGRAM@ -INSTALL_SCRIPT = @INSTALL_SCRIPT@ -INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ -LDFLAGS = @LDFLAGS@ -LEX = @LEX@ -LEXLIB = @LEXLIB@ -LEX_OUTPUT_ROOT = @LEX_OUTPUT_ROOT@ -LIBOBJS = @LIBOBJS@ -LIBS = @LIBS@ -LIBTOOL = @LIBTOOL@ -LN_S = @LN_S@ -LTLIBOBJS = @LTLIBOBJS@ -MAKEINFO = @MAKEINFO@ -MV = @MV@ -OBJEXT = @OBJEXT@ -PACKAGE = @PACKAGE@ -PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ -PACKAGE_NAME = @PACKAGE_NAME@ -PACKAGE_STRING = @PACKAGE_STRING@ -PACKAGE_TARNAME = @PACKAGE_TARNAME@ -PACKAGE_VERSION = @PACKAGE_VERSION@ -PATH_SEPARATOR = @PATH_SEPARATOR@ -RANLIB = @RANLIB@ -RM = @RM@ -SET_MAKE = @SET_MAKE@ -SHELL = @SHELL@ -STRIP = @STRIP@ -VERSION = @VERSION@ -YACC = @YACC@ -ac_ct_AR = @ac_ct_AR@ -ac_ct_CC = @ac_ct_CC@ -ac_ct_CXX = @ac_ct_CXX@ -ac_ct_F77 = @ac_ct_F77@ -ac_ct_RANLIB = @ac_ct_RANLIB@ -ac_ct_STRIP = @ac_ct_STRIP@ -am__fastdepCC_FALSE = @am__fastdepCC_FALSE@ -am__fastdepCC_TRUE = @am__fastdepCC_TRUE@ -am__fastdepCXX_FALSE = @am__fastdepCXX_FALSE@ -am__fastdepCXX_TRUE = @am__fastdepCXX_TRUE@ -am__include = @am__include@ -am__leading_dot = @am__leading_dot@ -am__quote = @am__quote@ -am__tar = @am__tar@ -am__untar = @am__untar@ -bindir = @bindir@ -build = @build@ -build_alias = @build_alias@ -build_cpu = @build_cpu@ -build_os = @build_os@ -build_vendor = @build_vendor@ -datadir = @datadir@ -exec_prefix = @exec_prefix@ -host = @host@ -host_alias = @host_alias@ -host_cpu = @host_cpu@ -host_os = @host_os@ -host_vendor = @host_vendor@ -includedir = @includedir@ -infodir = @infodir@ -install_sh = @install_sh@ -libdir = @libdir@ -libexecdir = @libexecdir@ -localstatedir = @localstatedir@ -mandir = @mandir@ -mkdir_p = @mkdir_p@ -oldincludedir = @oldincludedir@ -prefix = @prefix@ -program_transform_name = @program_transform_name@ -sbindir = @sbindir@ -sharedstatedir = @sharedstatedir@ -sysconfdir = @sysconfdir@ -target_alias = @target_alias@ -pkginclude_HEADERS = \ - base.h \ - exec.h \ - ioUtils.h \ - modifyFile.h \ - string.h \ - linuxProcUtils.h \ - cmpiUtils.h \ - cmpiSimpleAssoc.h \ - cmpiTimeServiceUtils.h \ - ntpServer.h - -all: all-am - -.SUFFIXES: -$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) - @for dep in $?; do \ - case '$(am__configure_deps)' in \ - *$$dep*) \ - cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \ - && exit 0; \ - exit 1;; \ - esac; \ - done; \ - echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu src/include/omc/Makefile'; \ - cd $(top_srcdir) && \ - $(AUTOMAKE) --gnu src/include/omc/Makefile -.PRECIOUS: Makefile -Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status - @case '$?' in \ - *config.status*) \ - cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ - *) \ - echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ - cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ - esac; - -$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) - cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh - -$(top_srcdir)/configure: $(am__configure_deps) - cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh -$(ACLOCAL_M4): $(am__aclocal_m4_deps) - cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh - -mostlyclean-libtool: - -rm -f *.lo - -clean-libtool: - -rm -rf .libs _libs - -distclean-libtool: - -rm -f libtool -uninstall-info-am: -install-pkgincludeHEADERS: $(pkginclude_HEADERS) - @$(NORMAL_INSTALL) - test -z "$(pkgincludedir)" || $(mkdir_p) "$(DESTDIR)$(pkgincludedir)" - @list='$(pkginclude_HEADERS)'; for p in $$list; do \ - if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ - f=$(am__strip_dir) \ - echo " $(pkgincludeHEADERS_INSTALL) '$$d$$p' '$(DESTDIR)$(pkgincludedir)/$$f'"; \ - $(pkgincludeHEADERS_INSTALL) "$$d$$p" "$(DESTDIR)$(pkgincludedir)/$$f"; \ - done - -uninstall-pkgincludeHEADERS: - @$(NORMAL_UNINSTALL) - @list='$(pkginclude_HEADERS)'; for p in $$list; do \ - f=$(am__strip_dir) \ - echo " rm -f '$(DESTDIR)$(pkgincludedir)/$$f'"; \ - rm -f "$(DESTDIR)$(pkgincludedir)/$$f"; \ - done - -ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) - list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ - unique=`for i in $$list; do \ - if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ - done | \ - $(AWK) ' { files[$$0] = 1; } \ - END { for (i in files) print i; }'`; \ - mkid -fID $$unique -tags: TAGS - -TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ - $(TAGS_FILES) $(LISP) - tags=; \ - here=`pwd`; \ - list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ - unique=`for i in $$list; do \ - if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ - done | \ - $(AWK) ' { files[$$0] = 1; } \ - END { for (i in files) print i; }'`; \ - if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \ - test -n "$$unique" || unique=$$empty_fix; \ - $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ - $$tags $$unique; \ - fi -ctags: CTAGS -CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ - $(TAGS_FILES) $(LISP) - tags=; \ - here=`pwd`; \ - list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ - unique=`for i in $$list; do \ - if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ - done | \ - $(AWK) ' { files[$$0] = 1; } \ - END { for (i in files) print i; }'`; \ - test -z "$(CTAGS_ARGS)$$tags$$unique" \ - || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ - $$tags $$unique - -GTAGS: - here=`$(am__cd) $(top_builddir) && pwd` \ - && cd $(top_srcdir) \ - && gtags -i $(GTAGS_ARGS) $$here - -distclean-tags: - -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags - -distdir: $(DISTFILES) - @srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \ - topsrcdirstrip=`echo "$(top_srcdir)" | sed 's|.|.|g'`; \ - list='$(DISTFILES)'; for file in $$list; do \ - case $$file in \ - $(srcdir)/*) file=`echo "$$file" | sed "s|^$$srcdirstrip/||"`;; \ - $(top_srcdir)/*) file=`echo "$$file" | sed "s|^$$topsrcdirstrip/|$(top_builddir)/|"`;; \ - esac; \ - if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ - dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \ - if test "$$dir" != "$$file" && test "$$dir" != "."; then \ - dir="/$$dir"; \ - $(mkdir_p) "$(distdir)$$dir"; \ - else \ - dir=''; \ - fi; \ - if test -d $$d/$$file; then \ - if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ - cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \ - fi; \ - cp -pR $$d/$$file $(distdir)$$dir || exit 1; \ - else \ - test -f $(distdir)/$$file \ - || cp -p $$d/$$file $(distdir)/$$file \ - || exit 1; \ - fi; \ - done -check-am: all-am -check: check-am -all-am: Makefile $(HEADERS) -installdirs: - for dir in "$(DESTDIR)$(pkgincludedir)"; do \ - test -z "$$dir" || $(mkdir_p) "$$dir"; \ - done -install: install-am -install-exec: install-exec-am -install-data: install-data-am -uninstall: uninstall-am - -install-am: all-am - @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am - -installcheck: installcheck-am -install-strip: - $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ - install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ - `test -z '$(STRIP)' || \ - echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install -mostlyclean-generic: - -clean-generic: - -distclean-generic: - -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) - -maintainer-clean-generic: - @echo "This command is intended for maintainers to use" - @echo "it deletes files that may require special tools to rebuild." -clean: clean-am - -clean-am: clean-generic clean-libtool mostlyclean-am - -distclean: distclean-am - -rm -f Makefile -distclean-am: clean-am distclean-generic distclean-libtool \ - distclean-tags - -dvi: dvi-am - -dvi-am: - -html: html-am - -info: info-am - -info-am: - -install-data-am: install-pkgincludeHEADERS - -install-exec-am: - -install-info: install-info-am - -install-man: - -installcheck-am: - -maintainer-clean: maintainer-clean-am - -rm -f Makefile -maintainer-clean-am: distclean-am maintainer-clean-generic - -mostlyclean: mostlyclean-am - -mostlyclean-am: mostlyclean-generic mostlyclean-libtool - -pdf: pdf-am - -pdf-am: - -ps: ps-am - -ps-am: - -uninstall-am: uninstall-info-am uninstall-pkgincludeHEADERS - -.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \ - clean-libtool ctags distclean distclean-generic \ - distclean-libtool distclean-tags distdir dvi dvi-am html \ - html-am info info-am install install-am install-data \ - install-data-am install-exec install-exec-am install-info \ - install-info-am install-man install-pkgincludeHEADERS \ - install-strip installcheck installcheck-am installdirs \ - maintainer-clean maintainer-clean-generic mostlyclean \ - mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ - tags uninstall uninstall-am uninstall-info-am \ - uninstall-pkgincludeHEADERS - -# Tell versions [3.59,3.63) of GNU make to not export all variables. -# Otherwise a system limit (for SysV at least) may be exceeded. -.NOEXPORT: Added: omccmpi/trunk/src/include/omc/fileTools.h =================================================================== --- omccmpi/trunk/src/include/omc/fileTools.h (rev 0) +++ omccmpi/trunk/src/include/omc/fileTools.h 2007-02-14 17:38:58 UTC (rev 440) @@ -0,0 +1,104 @@ +/******************************************************************************* +* Copyright (C) 2005, 2006 Novell, Inc. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* +* - Redistributions of source code must retain the above copyright notice, +* this list of conditions and the following disclaimer. +* +* - Redistributions in binary form must reproduce the above copyright notice, +* this list of conditions and the following disclaimer in the documentation +* and/or other materials provided with the distribution. +* +* - Neither the name of Novell, Inc. nor the names of its +* contributors may be used to endorse or promote products derived from this +* software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' +* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +* ARE DISCLAIMED. IN NO EVENT SHALL Novell, Inc. OR THE CONTRIBUTORS +* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +* POSSIBILITY OF SUCH DAMAGE. +* +******************************************************************************/ + + +#ifndef OMCFILETOOLS_H_GUARD__ +#define OMCFILETOOLS_H_GUARD__ + +#ifdef __cplusplus +extern "C" { +#endif + +struct stat; + +/** + * Return the name of the directory containing the file (or + * directory) referenced by path. + * + * @param path The path + * + * @return The directory containing the file. The caller is + * responsible to free the buffer returned. + */ +char* omc_dirname(const char* path); + +/** + * Struct containing the six keys of CIM file classes. + * (CIM_LogicalFile and children) + */ +typedef struct omcFileKeys_ +{ + char * CSCreationClassName; + char * CSName; + char * CreationClassName; + char * FSCreationClassName; + char * FSName; + char * Name; +} omcFileKeys; + +/** + * Free a omcFileKeys structure and the pointers contained + * therein. + * + * @param fk pointer to the omcFileKeys structure to be freed. + */ +void omcFileKeys_free(omcFileKeys* fk); + +/** + * Determine the keys for the CIM instance representing a given + * file. + * @param path The full path to the file + * + * @return A pointer to an omcFileKeys structure. The caller is + * responsible to free this with a call to + * omcFileKeys_free(). + */ +omcFileKeys* omcGetKeysForFile(const char* path); + +/** + * Determine the keys for the CIM instance representing a given + * file. Use this version if you already have a stat for the + * file and wish to avoid an aditional stat. + * + * @param path The full path to the file + * @param st A stat structure for the file obtained from stat() + * + * @return A pointer to an omcFileKeys structure. The caller is + * responsible to free this with a call to + * omcFileKeys_free(). + */ +omcFileKeys* omcGetKeysForFileStat(const char* path, struct stat* st); + +#ifdef __cplusplus +} +#endif + +#endif Modified: omccmpi/trunk/src/lib/omc/Makefile.am =================================================================== --- omccmpi/trunk/src/lib/omc/Makefile.am 2007-02-14 17:17:15 UTC (rev 439) +++ omccmpi/trunk/src/lib/omc/Makefile.am 2007-02-14 17:38:58 UTC (rev 440) @@ -21,4 +21,5 @@ modifyFile.c \ string.c \ linuxProcUtils.c \ +fileTools.c \ ntpServer.c Added: omccmpi/trunk/src/lib/omc/fileTools.c =================================================================== --- omccmpi/trunk/src/lib/omc/fileTools.c (rev 0) +++ omccmpi/trunk/src/lib/omc/fileTools.c 2007-02-14 17:38:58 UTC (rev 440) @@ -0,0 +1,201 @@ +/******************************************************************************* +* Copyright (C) 2005, 2006 Novell, Inc. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* +* - Redistributions of source code must retain the above copyright notice, +* this list of conditions and the following disclaimer. +* +* - Redistributions in binary form must reproduce the above copyright notice, +* this list of conditions and the following disclaimer in the documentation +* and/or other materials provided with the distribution. +* +* - Neither the name of Novell, Inc. nor the names of its +* contributors may be used to endorse or promote products derived from this +* software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' +* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +* ARE DISCLAIMED. IN NO EVENT SHALL Novell, Inc. OR THE CONTRIBUTORS +* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +* POSSIBILITY OF SUCH DAMAGE. +* +******************************************************************************/ + + +#include "omc/fileTools.h" +//#include "omccmpi/string.h" +//#include "omccmpi/ioUtils.h" +//#include "string.h" +//#include "ioUtils.h" +#include <libgen.h> +#include "omc/string.h" +#include <sys/stat.h> +#include <sys/types.h> +#include <unistd.h> + +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif +#include <stdlib.h> +#include <stdio.h> + +char* omc_dirname(const char* path) +{ + char* tmp = strdup(path); + char* rv = dirname(tmp); + if (rv == NULL) + { + free(tmp); + } + return rv; +} + +void omcFileKeys_free(omcFileKeys* fk) +{ + if (fk == NULL) + { + return; + } + //free(fk->CSCreationClassName); // not malloc'd + free(fk->CSName); + //free(fk->CreationClassName); // not malloc'd + free(fk->FSCreationClassName); + free(fk->FSName); + free(fk->Name); + free(fk); +} + +omcFileKeys* omcGetKeysForFile(const char* path) +{ + struct stat st; + if (lstat(path, &st) != 0) + { + return NULL; + } + return omcGetKeysForFileStat(path, &st); +} + +omcFileKeys* omcGetKeysForFileStat(const char* path, struct stat* st) +{ + omcFileKeys* rv = (omcFileKeys*)malloc(sizeof(omcFileKeys)); + memset(rv, 0, sizeof(omcFileKeys)); + if (S_ISREG(st->st_mode)) + { + rv->CreationClassName = "OMC_LinuxDataFile"; + } else if (S_ISDIR(st->st_mode)) + { + rv->CreationClassName = "OMC_LinuxDirectory"; + } else if (S_ISCHR(st->st_mode) || S_ISBLK(st->st_mode)) + { + rv->CreationClassName = "OMC_LinuxDeviceFile"; + } else if (S_ISFIFO(st->st_mode)) + { + rv->CreationClassName = "OMC_LinuxFIFOPipeFile"; + } else if (S_ISLNK(st->st_mode)) + { + rv->CreationClassName = "OMC_LinuxSymbolicLink"; + } else + { + free(rv); + return NULL; + } + rv->Name = strdup(path); + rv->CSCreationClassName = "OMC_LinuxUnitaryComputerSystem"; + rv->CSName = (char*)malloc(256); + gethostname(rv->CSName, 256); + FILE* mounts = fopen("/proc/mounts", "r"); + if (mounts == NULL) + { + omcFileKeys_free(rv); + return NULL; + } + char* line = NULL; + char* p = NULL; + size_t bfrLen = 0; + for(p = omcReadLine(mounts, &line,&bfrLen); p; p = omcReadLine(mounts, &line,&bfrLen )) + { + int count = omcStrTokenCount(line, " \t\r\n"); + if (count != 6) + { + continue; + } + size_t numElems = 0; + char** strs = omcStrTokenize(line, " \t\r\n", &numElems); + if (strs == NULL) + { + continue; + } + if (strs[1][0] != '/') + { + free(strs); + continue; + } + if (strs[1][1] == 0 && strcmp(strs[0], "rootfs") == 0) + { + /* skip rootfs junk */ + free(strs); + continue; + } + struct stat dst; + if (stat(strs[1], &dst) != 0) + { + free(strs); + continue; + } + if (st->st_dev == dst.st_dev) + { + rv->FSName = strdup(strs[0]); + char* fstype = strs[2]; + if (strcmp(fstype, "ext2") == 0) + { + rv->FSCreationClassName = strdup("OMC_LinuxExt2FileSystem"); + } else if (strcmp(fstype, "ext3") == 0) + { + rv->FSCreationClassName = strdup("OMC_LinuxExt3FileSystem"); + } else if (strcmp(fstype, "reiserfs") == 0) + { + rv->FSCreationClassName = strdup("OMC_LinuxReiserFileSystem"); + } else if (strcmp(fstype, "nfs") == 0) + { + rv->FSCreationClassName = strdup("OMC_LinuxNFS"); + } else if (strcmp(fstype, "cifs") == 0) + { + rv->FSCreationClassName = strdup("OMC_LinuxCIFS"); /* TODO CIM class doesn't exist yet */ + } + else + { + int len = snprintf(NULL, 0, "Unknown:%s", fstype); + if (len > 0) + { + rv->FSCreationClassName = (char*)malloc(len + 1); + snprintf(rv->FSCreationClassName, len+1, "Unknown:%s", fstype); + } + else + { + rv->FSCreationClassName = strdup("Unknown"); + } + } + } + free(strs); + if (rv->FSName != NULL) + { + break; + } + } + if (line) + { + free(line); + } + fclose(mounts); + return rv; + +} + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |