提交 5717ee6a 编写于 作者: E Eric Blake

storage: use simpler 'char *'

'unsigned char *' makes sense if you are doing math on bytes and
don't want to worry about wraparound from a signed 'char'; but
since all we are doing is memcmp() or virReadBufInt*[LB]E(), which
are both safe on either type of char, and since read() prefers to
operate on 'char *', it's simpler to avoid casts by just typing
things as 'char *' from the get-go.  [Technically, read can
operate on an 'unsigned char *' thanks to the C rule that any
pointer can be implicitly converted to 'char *' for legacy K&R
compatibility; but where this patch saves us is if we try to use
virfile.h functions that take 'char **' in order to allocate the
buffer, where the compiler would barf on type mismatch.]

* src/util/virstoragefile.c (FileTypeInfo): Avoid unsigned char.
(cowGetBackingStore, qcow2GetBackingStoreFormat)
(qcowXGetBackingStore, qcow1GetBackingStore)
(qcow2GetBackingStore, vmdk4GetBackingStore, qedGetBackingStore)
(virStorageFileMatchesMagic, virStorageFileMatchesVersion)
(virStorageFileProbeFormatFromBuf, qcow2GetFeatures)
(virStorageFileGetMetadataInternal)
(virStorageFileProbeFormatFromFD): Simplify clients.
Signed-off-by: NEric Blake <eblake@redhat.com>
上级 3897975e
...@@ -102,23 +102,23 @@ struct FileTypeInfo { ...@@ -102,23 +102,23 @@ struct FileTypeInfo {
* where to find encryption mode, * where to find encryption mode,
* -1 if encryption is not used */ * -1 if encryption is not used */
int (*getBackingStore)(char **res, int *format, int (*getBackingStore)(char **res, int *format,
const unsigned char *buf, size_t buf_size); const char *buf, size_t buf_size);
int (*getFeatures)(virBitmapPtr *features, int format, int (*getFeatures)(virBitmapPtr *features, int format,
unsigned char *buf, ssize_t len); char *buf, ssize_t len);
}; };
static int cowGetBackingStore(char **, int *, static int cowGetBackingStore(char **, int *,
const unsigned char *, size_t); const char *, size_t);
static int qcow1GetBackingStore(char **, int *, static int qcow1GetBackingStore(char **, int *,
const unsigned char *, size_t); const char *, size_t);
static int qcow2GetBackingStore(char **, int *, static int qcow2GetBackingStore(char **, int *,
const unsigned char *, size_t); const char *, size_t);
static int qcow2GetFeatures(virBitmapPtr *features, int format, static int qcow2GetFeatures(virBitmapPtr *features, int format,
unsigned char *buf, ssize_t len); char *buf, ssize_t len);
static int vmdk4GetBackingStore(char **, int *, static int vmdk4GetBackingStore(char **, int *,
const unsigned char *, size_t); const char *, size_t);
static int static int
qedGetBackingStore(char **, int *, const unsigned char *, size_t); qedGetBackingStore(char **, int *, const char *, size_t);
#define QCOWX_HDR_VERSION (4) #define QCOWX_HDR_VERSION (4)
#define QCOWX_HDR_BACKING_FILE_OFFSET (QCOWX_HDR_VERSION+4) #define QCOWX_HDR_BACKING_FILE_OFFSET (QCOWX_HDR_VERSION+4)
...@@ -252,7 +252,7 @@ verify(ARRAY_CARDINALITY(qcow2CompatibleFeatureArray) == ...@@ -252,7 +252,7 @@ verify(ARRAY_CARDINALITY(qcow2CompatibleFeatureArray) ==
static int static int
cowGetBackingStore(char **res, cowGetBackingStore(char **res,
int *format, int *format,
const unsigned char *buf, const char *buf,
size_t buf_size) size_t buf_size)
{ {
#define COW_FILENAME_MAXLEN 1024 #define COW_FILENAME_MAXLEN 1024
...@@ -274,7 +274,7 @@ cowGetBackingStore(char **res, ...@@ -274,7 +274,7 @@ cowGetBackingStore(char **res,
static int static int
qcow2GetBackingStoreFormat(int *format, qcow2GetBackingStoreFormat(int *format,
const unsigned char *buf, const char *buf,
size_t buf_size, size_t buf_size,
size_t extension_start, size_t extension_start,
size_t extension_end) size_t extension_end)
...@@ -329,7 +329,7 @@ done: ...@@ -329,7 +329,7 @@ done:
static int static int
qcowXGetBackingStore(char **res, qcowXGetBackingStore(char **res,
int *format, int *format,
const unsigned char *buf, const char *buf,
size_t buf_size, size_t buf_size,
bool isQCow2) bool isQCow2)
{ {
...@@ -407,7 +407,7 @@ qcowXGetBackingStore(char **res, ...@@ -407,7 +407,7 @@ qcowXGetBackingStore(char **res,
static int static int
qcow1GetBackingStore(char **res, qcow1GetBackingStore(char **res,
int *format, int *format,
const unsigned char *buf, const char *buf,
size_t buf_size) size_t buf_size)
{ {
int ret; int ret;
...@@ -424,7 +424,7 @@ qcow1GetBackingStore(char **res, ...@@ -424,7 +424,7 @@ qcow1GetBackingStore(char **res,
static int static int
qcow2GetBackingStore(char **res, qcow2GetBackingStore(char **res,
int *format, int *format,
const unsigned char *buf, const char *buf,
size_t buf_size) size_t buf_size)
{ {
return qcowXGetBackingStore(res, format, buf, buf_size, true); return qcowXGetBackingStore(res, format, buf, buf_size, true);
...@@ -434,7 +434,7 @@ qcow2GetBackingStore(char **res, ...@@ -434,7 +434,7 @@ qcow2GetBackingStore(char **res,
static int static int
vmdk4GetBackingStore(char **res, vmdk4GetBackingStore(char **res,
int *format, int *format,
const unsigned char *buf, const char *buf,
size_t buf_size) size_t buf_size)
{ {
static const char prefix[] = "parentFileNameHint=\""; static const char prefix[] = "parentFileNameHint=\"";
...@@ -495,7 +495,7 @@ cleanup: ...@@ -495,7 +495,7 @@ cleanup:
static int static int
qedGetBackingStore(char **res, qedGetBackingStore(char **res,
int *format, int *format,
const unsigned char *buf, const char *buf,
size_t buf_size) size_t buf_size)
{ {
unsigned long long flags; unsigned long long flags;
...@@ -596,7 +596,7 @@ cleanup: ...@@ -596,7 +596,7 @@ cleanup:
static bool static bool
virStorageFileMatchesMagic(int format, virStorageFileMatchesMagic(int format,
unsigned char *buf, char *buf,
size_t buflen) size_t buflen)
{ {
int mlen; int mlen;
...@@ -634,7 +634,7 @@ virStorageFileMatchesExtension(int format, ...@@ -634,7 +634,7 @@ virStorageFileMatchesExtension(int format,
static bool static bool
virStorageFileMatchesVersion(int format, virStorageFileMatchesVersion(int format,
unsigned char *buf, char *buf,
size_t buflen) size_t buflen)
{ {
int version; int version;
...@@ -684,7 +684,7 @@ virBackingStoreIsFile(const char *backing) ...@@ -684,7 +684,7 @@ virBackingStoreIsFile(const char *backing)
static int static int
virStorageFileProbeFormatFromBuf(const char *path, virStorageFileProbeFormatFromBuf(const char *path,
unsigned char *buf, char *buf,
size_t buflen) size_t buflen)
{ {
int format = VIR_STORAGE_FILE_RAW; int format = VIR_STORAGE_FILE_RAW;
...@@ -726,7 +726,7 @@ cleanup: ...@@ -726,7 +726,7 @@ cleanup:
static int static int
qcow2GetFeatures(virBitmapPtr *features, qcow2GetFeatures(virBitmapPtr *features,
int format, int format,
unsigned char *buf, char *buf,
ssize_t len) ssize_t len)
{ {
int version = -1; int version = -1;
...@@ -767,7 +767,7 @@ virStorageFileGetMetadataInternal(const char *path, ...@@ -767,7 +767,7 @@ virStorageFileGetMetadataInternal(const char *path,
int format) int format)
{ {
virStorageFileMetadata *meta = NULL; virStorageFileMetadata *meta = NULL;
unsigned char *buf = NULL; char *buf = NULL;
ssize_t len = STORAGE_MAX_HEAD; ssize_t len = STORAGE_MAX_HEAD;
virStorageFileMetadata *ret = NULL; virStorageFileMetadata *ret = NULL;
struct stat sb; struct stat sb;
...@@ -922,7 +922,7 @@ cleanup: ...@@ -922,7 +922,7 @@ cleanup:
int int
virStorageFileProbeFormatFromFD(const char *path, int fd) virStorageFileProbeFormatFromFD(const char *path, int fd)
{ {
unsigned char *head; char *head = NULL;
ssize_t len = STORAGE_MAX_HEAD; ssize_t len = STORAGE_MAX_HEAD;
int ret = -1; int ret = -1;
struct stat sb; struct stat sb;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册