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