/* * Copyright (C) 2012 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 */ #include "file.h" static const char *LOGICALFILE_REQUIRED_NAMES[] = { "CSCreationClassName", "CSName", "CreationClassName", "FSCreationClassName", "FSName", "Name", NULL }; static const char *UNIXFILE_REQUIRED_NAMES[] = { "CSCreationClassName", "CSName", "LFCreationClassName", "FSCreationClassName", "FSName", "LFName", NULL }; CMPIStatus lmi_check_required( const CMPIBroker *b, const CMPIObjectPath *o, const enum RequiredNames rn) { const char **names; switch (rn) { case LOGICALFILE: names = LOGICALFILE_REQUIRED_NAMES; break; case UNIXFILE: names = UNIXFILE_REQUIRED_NAMES; break; default: /* not possible! */ assert(0); break; } for (int i = 0; names[i]; i++) { if (CMIsNullValue(CMGetKey(o, names[i], NULL))) { char errmsg[BUFLEN]; snprintf(errmsg, BUFLEN, "No '%s' specified", names[i]); CMReturnWithChars(b, CMPI_RC_ERR_FAILED, errmsg); } } CMReturn(CMPI_RC_OK); } void get_class_from_stat(const struct stat *sb, char *fileclass) { (S_ISREG(sb->st_mode)) ? strcpy(fileclass, "LMI_DataFile") : (S_ISDIR(sb->st_mode)) ? strcpy(fileclass, "LMI_UnixDirectory") : (S_ISCHR(sb->st_mode)) ? strcpy(fileclass, "LMI_UnixDeviceFile") : (S_ISBLK(sb->st_mode)) ? strcpy(fileclass, "LMI_UnixDeviceFile") : (S_ISLNK(sb->st_mode)) ? strcpy(fileclass, "LMI_SymbolicLink") : (S_ISFIFO(sb->st_mode)) ? strcpy(fileclass, "LMI_FIFOPipeFile") : (S_ISSOCK(sb->st_mode)) ? strcpy(fileclass, "LMI_UnixSocket") : strcpy(fileclass, "Unknown"); assert(strcmp(fileclass, "Unknown") != 0); } int get_class_from_path(const char *path, char *fileclass) { int rc = 0; struct stat sb; if (lstat(path, &sb) < 0) { rc = 1; } else { get_class_from_stat(&sb, fileclass); } return rc; } void _dump_objectpath(const CMPIObjectPath *o) { printf("OP: %s\n", CMGetCharsPtr(o->ft->toString(o, NULL), NULL)); } /* vi: set et: */