Merge branch 'master' into 'master'
[brasero.git] / libbrasero-media / scsi-utils.h
blob5df35eb52502d539e7fce3f83c3e15f7ce9155f6
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
2 /*
3 * Libbrasero-media
4 * Copyright (C) Philippe Rouquier 2005-2009 <bonfire-app@wanadoo.fr>
6 * Libbrasero-media is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * The Libbrasero-media authors hereby grant permission for non-GPL compatible
12 * GStreamer plugins to be used and distributed together with GStreamer
13 * and Libbrasero-media. This permission is above and beyond the permissions granted
14 * by the GPL license by which Libbrasero-media is covered. If you modify this code
15 * you may extend this exception to your version of the code, but you are not
16 * obligated to do so. If you do not wish to do so, delete this exception
17 * statement from your version.
19 * Libbrasero-media is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Library General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to:
26 * The Free Software Foundation, Inc.,
27 * 51 Franklin Street, Fifth Floor
28 * Boston, MA 02110-1301, USA.
31 #include <errno.h>
32 #include <glib.h>
34 #include "brasero-media.h"
35 #include "scsi-base.h"
37 #ifndef _BURN_UTILS_H
38 #define _BURN_UTILS_H
40 G_BEGIN_DECLS
42 #define BRASERO_GET_BCD(data) ((((uchar)(data)&0xF0)>>4)*10+((uchar)(data)&0x0F))
43 #define BRASERO_GET_16(data) (((uchar)(data)[0]<<8)+(uchar)(data)[1])
44 #define BRASERO_GET_24(data) (((uchar)(data)[0]<<16)+((uchar)(data)[1]<<8)+((uchar)(data)[2]))
45 #define BRASERO_GET_32(data) (((uchar)(data)[0]<<24)+((uchar)(data)[1]<<16)+((uchar)(data)[2]<<8)+(uchar)(data)[3])
47 #define BRASERO_SET_BCD(data, num) (uchar)(data)=((((num)/10)<<4)&0xF0)|((num)-(((num)/10)*10))
48 #define BRASERO_SET_16(data, num) (data)[0]=(((num)>>8)&0xFF);(data)[1]=(uchar)((num)&0xFF)
49 #define BRASERO_SET_24(data, num) (data)[0]=(uchar)(((num)>>16)&0xFF);(data)[1]=(uchar)(((num)>>8)&0xFF);(data)[2]=(uchar)((num)&0xFF);
50 #define BRASERO_SET_32(data, num) (data)[0]=(uchar)(((num)>>24)&0xFF);(data)[1]=(uchar)(((num)>>16)&0xFF);(data)[2]=(uchar)(((num)>>8)&0xFF);(data)[3]=(uchar)((num)&0xFF)
52 #define BRASERO_MSF_TO_LBA(minute, second, frame) (((minute)*60+(second))*75+frame)
54 #define BRASERO_IS_BCD_VALID(number) ((((uchar)(number) & 0x0f) < 0x09) && (((uchar)(number) & 0xF0) <= 0x90))
56 /**
57 * Used to report errors and have some sort of debug output easily
60 #define BRASERO_SCSI_SET_ERRCODE(err, code) \
61 { \
62 if (code == BRASERO_SCSI_ERRNO) { \
63 int errsv = errno; \
64 BRASERO_MEDIA_LOG ("SCSI command error: %s", \
65 g_strerror (errsv)); \
66 } else { \
67 BRASERO_MEDIA_LOG ("SCSI command error: %s", \
68 brasero_scsi_strerror (code)); \
69 } \
70 if (err) \
71 *(err) = code; \
74 G_END_DECLS
76 #endif /* _BURN_UTILS_H */