[Cluster-devel] conga ricci/modules/storage/ExtendedFS.cpp ric ...
kupcevic at sourceware.org
kupcevic at sourceware.org
Thu Sep 14 17:52:05 UTC 2006
CVSROOT: /cvs/cluster
Module name: conga
Changes by: kupcevic at sourceware.org 2006-09-14 17:52:04
Modified files:
ricci/modules/storage: ExtendedFS.cpp Makefile SwapFS.cpp
. : conga.spec.in.in
Added files:
ricci/modules/storage: FileMagic.h FileMagic.cpp
Log message:
storage module: use libmagic instead of executing "file" command
Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/modules/storage/FileMagic.h.diff?cvsroot=cluster&r1=NONE&r2=1.1
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/modules/storage/FileMagic.cpp.diff?cvsroot=cluster&r1=NONE&r2=1.1
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/modules/storage/ExtendedFS.cpp.diff?cvsroot=cluster&r1=1.3&r2=1.4
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/modules/storage/Makefile.diff?cvsroot=cluster&r1=1.10&r2=1.11
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/modules/storage/SwapFS.cpp.diff?cvsroot=cluster&r1=1.3&r2=1.4
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/conga.spec.in.in.diff?cvsroot=cluster&r1=1.40&r2=1.41
/cvs/cluster/conga/ricci/modules/storage/FileMagic.h,v --> standard output
revision 1.1
--- conga/ricci/modules/storage/FileMagic.h
+++ - 2006-09-14 17:52:05.102018000 +0000
@@ -0,0 +1,37 @@
+/*
+ Copyright Red Hat, Inc. 2006
+
+ 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, 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; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 675 Mass Ave, Cambridge,
+ MA 02139, USA.
+*/
+/*
+ * Author: Stanko Kupcevic <kupcevic at redhat.com>
+ */
+
+
+#ifndef FileMagic_h
+#define FileMagic_h
+
+#include "String.h"
+
+
+class FileMagic
+{
+ public:
+ static String get_description(const String& filename);
+};
+
+
+#endif // GlobalFS_h
/cvs/cluster/conga/ricci/modules/storage/FileMagic.cpp,v --> standard output
revision 1.1
--- conga/ricci/modules/storage/FileMagic.cpp
+++ - 2006-09-14 17:52:05.198820000 +0000
@@ -0,0 +1,75 @@
+/*
+ Copyright Red Hat, Inc. 2006
+
+ 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, 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; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 675 Mass Ave, Cambridge,
+ MA 02139, USA.
+*/
+/*
+ * Author: Stanko Kupcevic <kupcevic at redhat.com>
+ */
+
+
+#include "FileMagic.h"
+#include <magic.h>
+
+
+
+String
+__get_description(const String& filename,
+ const String& magic_filename = "")
+{
+ const char* buff = 0;
+ magic_t cookie = 0;
+
+ try {
+ cookie = magic_open(MAGIC_SYMLINK|MAGIC_DEVICES|MAGIC_ERROR);
+ if (!cookie)
+ throw String("initialization of libmagic failure");
+
+ if (magic_filename.empty()) {
+ if (magic_load(cookie, NULL))
+ throw String("initialization of libmagic failure: invalid default magic file");
+ } else
+ if (magic_load(cookie, magic_filename.c_str()))
+ throw String("initialization of libmagic failure: invalid magic file: ") + magic_filename;
+
+ String descr;
+ buff = magic_file(cookie, filename.c_str());
+ if (buff)
+ descr = buff;
+
+ if (descr.empty())
+ throw String("nothing detected");
+ if (descr == "data")
+ throw String("unknown data detected");
+
+ magic_close(cookie); cookie = 0;
+ free((char*) buff); buff = 0;
+
+ return descr;
+ } catch ( ... ) {
+ if (cookie)
+ magic_close(cookie);
+ if (buff)
+ free((char*) buff);
+ throw;
+ }
+}
+
+String
+FileMagic::get_description(const String& filename)
+{
+ return __get_description(filename);
+}
--- conga/ricci/modules/storage/ExtendedFS.cpp 2006/08/10 22:53:09 1.3
+++ conga/ricci/modules/storage/ExtendedFS.cpp 2006/09/14 17:52:04 1.4
@@ -26,6 +26,7 @@
#include "MountHandler.h"
#include "defines.h"
#include "UMountError.h"
+#include "FileMagic.h"
#include <iostream>
@@ -42,23 +43,15 @@
ContentFS("extended_fs", path),
_journaled(false)
{
- vector<String> args;
- args.push_back("-s");
- args.push_back("-L");
- args.push_back(path);
+ String magic(FileMagic::get_description(path));
+ if (magic.find("ext3") == magic.npos &&
+ magic.find("ext2") == magic.npos)
+ throw String(path + " not extended_fs");
+ // dumpe2fs
String out, err;
int status;
- if (utils::execute("/usr/bin/file", args, out, err, status))
- throw String("execute failed");
- if (status)
- throw String("file failed");
- if (out.find("ext3") == out.npos &&
- out.find("ext2") == out.npos)
- throw String("not extended_fs");
-
- // dumpe2fs
- args.clear();
+ vector<String> args;
args.push_back("-h");
args.push_back(path);
if (utils::execute("/sbin/dumpe2fs", args, out, err, status))
--- conga/ricci/modules/storage/Makefile 2006/08/16 06:34:20 1.10
+++ conga/ricci/modules/storage/Makefile 2006/09/14 17:52:04 1.11
@@ -17,6 +17,7 @@
TARGET = ricci-modstorage
OBJECTS = main.o \
+ FileMagic.o \
Props.o \
BD.o \
Content.o \
@@ -52,7 +53,7 @@
INCLUDE +=
CXXFLAGS +=
-LDFLAGS +=
+LDFLAGS += -lmagic
all: ${TARGET}
--- conga/ricci/modules/storage/SwapFS.cpp 2006/08/10 22:53:09 1.3
+++ conga/ricci/modules/storage/SwapFS.cpp 2006/09/14 17:52:04 1.4
@@ -25,6 +25,7 @@
#include "utils.h"
#include "MountHandler.h"
#include "UMountError.h"
+#include "FileMagic.h"
using namespace std;
@@ -33,20 +34,9 @@
SwapFS::SwapFS(const String& path) :
ContentFS("swap", path)
{
- vector<String> args;
- args.push_back("-s");
- args.push_back("-L");
- args.push_back(path);
-
- String out, err;
- int status;
- if (utils::execute("/usr/bin/file", args, out, err, status))
- throw String("execute failed");
- if (status)
- throw String("file failed");
-
- if (out.find("swap") == out.npos)
- throw String(path + "not swap");
+ String magic(FileMagic::get_description(path));
+ if (magic.find("swap") == magic.npos)
+ throw String(path + " not swap");
// swapon
MountHandler mh;
--- conga/conga.spec.in.in 2006/09/05 19:53:40 1.40
+++ conga/conga.spec.in.in 2006/09/14 17:52:04 1.41
@@ -40,7 +40,7 @@
BuildRequires: python-devel >= 2.4.1
%endif
BuildRequires: glibc-devel gcc-c++ libxml2-devel sed
-BuildRequires: openssl-devel dbus-devel pam-devel pkgconfig
+BuildRequires: openssl-devel dbus-devel pam-devel pkgconfig file
%description
Conga is a project developing management system for remote stations.
More information about the Cluster-devel
mailing list