hal/volume_id Makefile.am, 1.2, 1.3 logging.h, 1.1, 1.2 luks.c, NONE, 1.1 luks.h, NONE, 1.1 volume_id.h, 1.2, 1.3

David Zeuthen david at freedesktop.org
Wed Feb 16 14:25:23 PST 2005


Update of /cvs/hal/hal/volume_id
In directory gabe:/tmp/cvs-serv25568/volume_id

Modified Files:
	Makefile.am logging.h volume_id.h 
Added Files:
	luks.c luks.h 
Log Message:
2005-02-16  David Zeuthen  <davidz at redhat.com>

	* volume_id/luks.[ch]: New files (forgot to commit before) 

	* hald/linux2/probing/shared.h: Redefine logging a bit

	* hald/linux2/probing/probe-volume.c: Use new shared.h logging;
	implement volume_id_log and drive_id_log functions

	* hald/linux2/probing/probe-storage.c: Use new shared.h logging;
	implement volume_id_log and drive_id_log functions

	* hald/linux2/addons/addon-storage.c: Use new shared.h logging

	* drive_id/logging.h: Use drive_id_log function

	* drive_id/drive_id.h (drive_id_log): Add drive_id_log prototype



Index: Makefile.am
===================================================================
RCS file: /cvs/hal/hal/volume_id/Makefile.am,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- Makefile.am	16 Feb 2005 20:16:55 -0000	1.2
+++ Makefile.am	16 Feb 2005 22:25:20 -0000	1.3
@@ -1,6 +1,8 @@
 
 noinst_LTLIBRARIES = libvolume_id.la
 
+INCLUDES = -DDEBUG
+
 libvolume_id_la_SOURCES =				\
 	dasd.h			dasd.c			\
 	ext.h			ext.c			\

Index: logging.h
===================================================================
RCS file: /cvs/hal/hal/volume_id/logging.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- logging.h	7 Feb 2005 21:24:16 -0000	1.1
+++ logging.h	16 Feb 2005 22:25:20 -0000	1.2
@@ -16,9 +16,9 @@
 #endif
 
 #ifdef DEBUG
-#define dbg(format, arg...)						\
-	do {								\
-		printf("%s: " format "\n", __FUNCTION__ , ## arg);	\
+#define dbg(format, arg...)							\
+	do {									\
+		volume_id_log("%s: " format "\n", __FUNCTION__ , ## arg);	\
 	} while (0)
 #else
 #define dbg(format, arg...)	do {} while (0)

--- NEW FILE: luks.c ---
/*
 * volume_id - reads filesystem label and uuid
 *
 * Copyright (C) 2005 W. Michael Petullo <mike at flyn.org>
 *
 *	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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

#ifndef _GNU_SOURCE
#define _GNU_SOURCE 1
#endif

#ifdef HAVE_CONFIG_H
#  include <config.h>
#endif

#include <netinet/in.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <ctype.h>
#include <asm/types.h>

#include "volume_id.h"
#include "util.h"
#include "logging.h"
#include "luks.h"

/* FIXME: this contains a lot of copy and pasted code.  One alternative
 * would be to fork/exec cryptsetup isLuks and cryptsetup luksUUID.  Another
 * would be to write a LUKS library */

/* from cryptsetup-luks internal.h */
#define SECTOR_SHIFT            9
#define SECTOR_SIZE             (1 << SECTOR_SHIFT)

/* from cryptsetup-luks luks.h */
#define LUKS_CIPHERNAME_L 32
#define LUKS_CIPHERMODE_L 32
#define LUKS_HASHSPEC_L 32
#define LUKS_DIGESTSIZE 20 /* since SHA1 */
#define LUKS_SALTSIZE 32
#define LUKS_NUMKEYS 8

/* from cryptsetup-luks luks.h */
const unsigned char LUKS_MAGIC[] = {'L','U','K','S', 0xba, 0xbe};
#define LUKS_MAGIC_L 6

/* from cryptsetup-luks luks.h */
#define LUKS_PHDR_SIZE (sizeof(struct luks_phdr)/SECTOR_SIZE+1)

/* from cryptsetup-luks luks.h */
#define UUID_STRING_L 40

int volume_id_probe_luks(struct volume_id *id, __u64 off)
{
	int i;

	/* from cryptsetup-luks luks.h */
	struct luks_phdr {
		char            magic[LUKS_MAGIC_L];
		uint16_t        version;
		char            cipherName[LUKS_CIPHERNAME_L];
		char            cipherMode[LUKS_CIPHERMODE_L];
		char            hashSpec[LUKS_HASHSPEC_L];
		uint32_t        payloadOffset;
		uint32_t        keyBytes;
		char            mkDigest[LUKS_DIGESTSIZE];
		char            mkDigestSalt[LUKS_SALTSIZE];
		uint32_t        mkDigestIterations;
		char            uuid[UUID_STRING_L];

		struct {
			uint32_t active;

			/* parameters used for password processing */
			uint32_t passwordIterations;
			char     passwordSalt[LUKS_SALTSIZE];

			/* parameters used for AF store/load */
			uint32_t keyMaterialOffset;
			uint32_t stripes;
		} keyblock[LUKS_NUMKEYS];
	} *header;

	header = (struct luks_phdr*) volume_id_get_buffer(id, off, LUKS_PHDR_SIZE);

	if (header == NULL)
		return -1;

	if (memcmp(header->magic, LUKS_MAGIC, LUKS_MAGIC_L))
		return -1;

	volume_id_set_usage(id, VOLUME_ID_CRYPTO);
	volume_id_set_uuid(id, header->uuid, UUID_DCE);
	id->type = "crypto_LUKS";

	return 0;
}

--- NEW FILE: luks.h ---
/*
 * volume_id - reads filesystem label and uuid
 *
 * Copyright (C) 2004 Kay Sievers <kay.sievers at vrfy.org>
 *
 *	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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

#ifndef _VOLUME_ID_EXT_
#define _VOLUME_ID_EXT_

extern int volume_id_probe_luks(struct volume_id *id, __u64 off);

#endif

Index: volume_id.h
===================================================================
RCS file: /cvs/hal/hal/volume_id/volume_id.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- volume_id.h	16 Feb 2005 20:16:55 -0000	1.2
+++ volume_id.h	16 Feb 2005 22:25:20 -0000	1.3
@@ -79,4 +79,9 @@
 extern int volume_id_probe_all(struct volume_id *id, unsigned long long off, unsigned long long size);
 extern void volume_id_close(struct volume_id *id);
 
+/* User of this library is supposed to export the volume_id_log symbol
+ * if sources are built with -DDEBUG
+ */
+extern void volume_id_log (const char *format, ...);
+
 #endif




More information about the hal-commit mailing list