/* * Copyright (C) 2012-2013 Red Hat, Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * Authors: Jan Synacek */ #ifndef _FILE_H #define _FILE_H #include #include #include #include #include #include #include #include #include #include #include "globals.h" #ifndef BUFLEN #define BUFLEN 512 #endif #ifndef PATH_MAX #define PATH_MAX 4096 #endif #define FSCREATIONCLASSNAME "LMI_LocalFileSystem" #define sb_permmask(sb) ((sb).st_mode & (S_IRWXU | S_IRWXG | S_IRWXO)) #define sb_isreadable(sb) ( \ (sb_permmask(sb) & S_IRUSR) || \ (sb_permmask(sb) & S_IRGRP) || \ (sb_permmask(sb) & S_IROTH) \ ) #define sb_iswriteable(sb) ( \ (sb_permmask(sb) & S_IWUSR) || \ (sb_permmask(sb) & S_IWGRP) || \ (sb_permmask(sb) & S_IWOTH) \ ) #define sb_isexecutable(sb) ( \ (sb_permmask(sb) & S_IXUSR) || \ (sb_permmask(sb) & S_IXGRP) || \ (sb_permmask(sb) & S_IXOTH) \ ) #define stoms(t) ((t)*1000000) #define fill_logicalfile(type, obj, name, fsname, creation_class) \ type##_Set_Name((obj), (name)); \ type##_Set_CSCreationClassName((obj), get_system_creation_class_name()); \ type##_Set_CSName((obj), get_system_name()); \ type##_Set_FSCreationClassName((obj), FSCREATIONCLASSNAME); \ type##_Set_FSName((obj), (fsname)); \ type##_Set_CreationClassName((obj), (creation_class)); #define fill_basic(cmpitype, path, stattype, error) \ struct stat sb; \ char errmsg[BUFLEN]; \ \ if (lstat((path), &sb) < 0 || !(sb.st_mode & S_IFMT & (stattype))) { \ snprintf(errmsg, BUFLEN, error, (path)); \ CMReturnWithChars(_cb, CMPI_RC_ERR_NOT_FOUND, errmsg); \ } \ \ LMI_##cmpitype##_Set_Readable(&lmi_file, sb_isreadable(sb)); \ LMI_##cmpitype##_Set_Writeable(&lmi_file, sb_iswriteable(sb)); \ LMI_##cmpitype##_Set_Executable(&lmi_file, sb_isexecutable(sb)); \ LMI_##cmpitype##_Set_FileSize(&lmi_file, sb.st_size); \ LMI_##cmpitype##_Set_LastAccessed(&lmi_file, CMNewDateTimeFromBinary(_cb, stoms(sb.st_atime), 0, NULL)); \ LMI_##cmpitype##_Set_LastModified(&lmi_file, CMNewDateTimeFromBinary(_cb, stoms(sb.st_mtime), 0, NULL)); #define get_instance(cmpitype, stattype, error) \ LMI_##cmpitype lmi_file; \ CMPIStatus st; \ \ LMI_##cmpitype##_InitFromObjectPath(&lmi_file, _cb, cop); \ st = lmi_check_required(_cb, cop, LOGICALFILE); \ if (st.rc != CMPI_RC_OK) { \ return st; \ } \ fill_basic(cmpitype, KChars(lmi_file.Name.value), stattype, error) \ KReturnInstance(cr, lmi_file); enum RequiredNames { LOGICALFILE, UNIXFILE, }; CMPIStatus lmi_check_required(const CMPIBroker *, const CMPIObjectPath *, const enum RequiredNames); void get_class_from_stat(const struct stat *, char *); int get_class_from_path(const char *, char *); int get_fsname_from_stat(const struct stat *, char **); int get_fsname_from_path(const char *, char **); const char *get_string_property_from_op(const CMPIObjectPath *, const char *); void _dump_objectpath(const CMPIObjectPath *); #endif /* _FILE_H */ /* vi: set et: */