summaryrefslogtreecommitdiffstats
path: root/src/logicalfile/file.h
diff options
context:
space:
mode:
authorJan Synacek <jsynacek@redhat.com>2013-09-18 08:33:03 +0200
committerJan Synacek <jsynacek@redhat.com>2013-09-18 15:19:30 +0200
commitcd13c983a49ce3685a3813e66001bd3ea8f796c8 (patch)
treec79386678dbfdbfbdbbccb48d690f7cd3f475c50 /src/logicalfile/file.h
parent2746832524f5e5d022b13ffa0890f895ab82355c (diff)
downloadopenlmi-providers-cd13c983a49ce3685a3813e66001bd3ea8f796c8.tar.gz
openlmi-providers-cd13c983a49ce3685a3813e66001bd3ea8f796c8.tar.xz
openlmi-providers-cd13c983a49ce3685a3813e66001bd3ea8f796c8.zip
logicalfile: code cleanup and rewrite
GetInstance() calls were rewritten using cleaner code. Also, the macros that were used before were either rewritten to functions, or cleaned up so they wouldn't return or do anything unexpected. Helper functions now use CMPIStatus more consistently. Some memory leaks were fixed.
Diffstat (limited to 'src/logicalfile/file.h')
-rw-r--r--src/logicalfile/file.h95
1 files changed, 43 insertions, 52 deletions
diff --git a/src/logicalfile/file.h b/src/logicalfile/file.h
index 938673c..b84dc34 100644
--- a/src/logicalfile/file.h
+++ b/src/logicalfile/file.h
@@ -30,6 +30,12 @@
#include <konkret/konkret.h>
#include <assert.h>
#include <libudev.h>
+#include "LMI_DataFile.h"
+#include "LMI_UnixDeviceFile.h"
+#include "LMI_SymbolicLink.h"
+#include "LMI_UnixDirectory.h"
+#include "LMI_UnixSocket.h"
+#include "LMI_FIFOPipeFile.h"
#include "globals.h"
#ifndef BUFLEN
@@ -45,6 +51,9 @@
#define SAME_ELEMENT "SameElement"
#define SYSTEM_ELEMENT "SystemElement"
+/* CMPI_RC_ERR_<error> values end at 200. 0xFF should be safe. */
+#define RC_ERR_CLASS_CHECK_FAILED 0xFF
+
#define sb_permmask(sb) ((sb).st_mode & (S_IRWXU | S_IRWXG | S_IRWXO))
#define sb_isreadable(sb) ( \
(sb_permmask(sb) & S_IRUSR) || \
@@ -71,69 +80,51 @@
type##_Set_FSName((obj), (fsname)); \
type##_Set_CreationClassName((obj), (creation_class));
-#define fill_basic(cmpitype, path, stattype, error) \
- struct stat sb; \
- char errmsg[BUFLEN]; \
- char aux[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); \
- } \
- \
- get_class_from_stat(&sb, aux); \
- LMI_##cmpitype##_Set_CreationClassName(&lmi_file, aux); \
- LMI_##cmpitype##_Set_FSCreationClassName(&lmi_file, FSCREATIONCLASSNAME); \
- char *fsname; \
- if (get_fsname_from_stat(&sb, &fsname) < 0) { \
- CMReturnWithChars(_cb, CMPI_RC_ERR_FAILED, "Can't get filesystem name"); \
- } else { \
- LMI_##cmpitype##_Set_FSName(&lmi_file, fsname); \
- free(fsname); \
- } \
- 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 fill_basic(b, cmpitype, lmi_file, creation_class_name, fsname, sb) \
+ LMI_##cmpitype##_Set_CreationClassName(lmi_file, creation_class_name); \
+ LMI_##cmpitype##_Set_FSCreationClassName(lmi_file, FSCREATIONCLASSNAME); \
+ LMI_##cmpitype##_Set_FSName(lmi_file, fsname); \
+ 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(b, stoms(sb.st_atime), 0, NULL)); \
+ LMI_##cmpitype##_Set_LastModified(lmi_file, CMNewDateTimeFromBinary(b, 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); \
+#define check_status(st) \
if (st.rc != CMPI_RC_OK) { \
return st; \
- } \
- fill_basic(cmpitype, KChars(lmi_file.Name.value), stattype, error) \
- KReturnInstance(cr, lmi_file);
+ }
-#define check_assoc_class(b, ns, assoc_class, cls) \
-{ \
- CMPIObjectPath *o; \
- CMPIStatus st; \
- \
- o = CMNewObjectPath(b, ns, cls, &st); \
- if (!o || st.rc) { \
- CMRelease(o); \
- return st; \
- } \
- if (assoc_class && !CMClassPathIsA(b, o, assoc_class, &st)) { \
- CMRelease(o); \
+#define check_class_check_status(st) \
+ if (st.rc == RC_ERR_CLASS_CHECK_FAILED) { \
CMReturn(CMPI_RC_OK); \
} \
- CMRelease(o); \
-}
+ check_status(st);
+
+#define return_with_status(b, st, code, msg) \
+ KSetStatus2(b, st, code, msg); \
+ return *(st);
+
+typedef struct {
+ union {
+ LMI_DataFile datafile;
+ LMI_UnixDeviceFile unixdevicefile;
+ LMI_UnixDirectory unixdirectory;
+ LMI_FIFOPipeFile fifopipefile;
+ LMI_UnixSocket unixsocket;
+ LMI_SymbolicLink symboliclink;
+ } lf;
+} logicalfile_t;
CMPIStatus lmi_check_required(const CMPIBroker *, const CMPIObjectPath *);
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 **);
+CMPIStatus get_fsname_from_stat(const CMPIBroker *, const struct stat *, char **);
+CMPIStatus get_fsname_from_path(const CMPIBroker *, const char *, char **);
const char *get_string_property_from_op(const CMPIObjectPath *, const char *);
-
+CMPIStatus check_assoc_class(const CMPIBroker *, const char *, const char *, const char *);
+CMPIStatus stat_logicalfile_and_fill(const CMPIBroker *, logicalfile_t *, mode_t, const char *);
void _dump_objectpath(const CMPIObjectPath *);
#endif /* _FILE_H */