[FREELDR] Fix MSVC warnings C4146 (#863)

This commit is contained in:
Extravert-ir 2018-09-16 17:14:07 +03:00 committed by Hermès BÉLUSCA - MAÏTO
parent 6458e12ffe
commit d0e29db1cb

View file

@ -18,7 +18,9 @@ DBG_DEFAULT_CHANNEL(FILESYSTEM);
#define TAG_BTRFS_FILE 'FftB' #define TAG_BTRFS_FILE 'FftB'
#define TAG_BTRFS_LINK 'LftB' #define TAG_BTRFS_LINK 'LftB'
#define INVALID_INODE ((ULONGLONG)-1) #define INVALID_INODE _UI64_MAX
#define INVALID_ADDRESS _UI64_MAX
#define READ_ERROR _UI64_MAX
struct BTRFS_INFO { struct BTRFS_INFO {
ULONG DeviceId; ULONG DeviceId;
@ -239,9 +241,9 @@ static u64 logical_physical(u64 logical)
if (ret == 0) if (ret == 0)
slot++; slot++;
else if (slot == 0) else if (slot == 0)
return -1; return INVALID_ADDRESS;
if (logical >= chunk_map->map[slot - 1].logical + chunk_map->map[slot - 1].length) if (logical >= chunk_map->map[slot - 1].logical + chunk_map->map[slot - 1].length)
return -1; return INVALID_ADDRESS;
TRACE("Address translation: 0x%llx -> 0x%llx\n", logical, TRACE("Address translation: 0x%llx -> 0x%llx\n", logical,
chunk_map->map[slot - 1].physical + logical - chunk_map->map[slot - 1].logical); chunk_map->map[slot - 1].physical + logical - chunk_map->map[slot - 1].logical);
@ -652,7 +654,7 @@ static u64 btrfs_read_extent_inline(struct btrfs_path *path,
if (offset > dlen) if (offset > dlen)
{ {
ERR("Tried to read offset (%llu) beyond extent length (%lu)\n", offset, dlen); ERR("Tried to read offset (%llu) beyond extent length (%lu)\n", offset, dlen);
return INVALID_INODE; return READ_ERROR;
} }
if (size > dlen - offset) if (size > dlen - offset)
@ -666,7 +668,7 @@ static u64 btrfs_read_extent_inline(struct btrfs_path *path,
} }
ERR("No compression supported right now\n"); ERR("No compression supported right now\n");
return INVALID_INODE; return READ_ERROR;
} }
static u64 btrfs_read_extent_reg(struct btrfs_path *path, struct btrfs_file_extent_item *extent, static u64 btrfs_read_extent_reg(struct btrfs_path *path, struct btrfs_file_extent_item *extent,
@ -679,17 +681,17 @@ static u64 btrfs_read_extent_reg(struct btrfs_path *path, struct btrfs_file_exte
if (offset > dlen) if (offset > dlen)
{ {
ERR("Tried to read offset (%llu) beyond extent length (%lu)\n", offset, dlen); ERR("Tried to read offset (%llu) beyond extent length (%lu)\n", offset, dlen);
return -1ULL; return READ_ERROR;
} }
if (size > dlen - offset) if (size > dlen - offset)
size = dlen - offset; size = dlen - offset;
physical = logical_physical(extent->disk_bytenr); physical = logical_physical(extent->disk_bytenr);
if (physical == -1ULL) if (physical == INVALID_ADDRESS)
{ {
ERR("Unable to convert logical address to physical: %llu\n", extent->disk_bytenr); ERR("Unable to convert logical address to physical: %llu\n", extent->disk_bytenr);
return -1ULL; return READ_ERROR;
} }
if (extent->compression == BTRFS_COMPRESS_NONE) if (extent->compression == BTRFS_COMPRESS_NONE)
@ -704,7 +706,7 @@ static u64 btrfs_read_extent_reg(struct btrfs_path *path, struct btrfs_file_exte
if (!disk_read(physical, temp_out, size + offset)) if (!disk_read(physical, temp_out, size + offset))
{ {
FrLdrTempFree(temp_out, TAG_BTRFS_FILE); FrLdrTempFree(temp_out, TAG_BTRFS_FILE);
return -1ULL; return READ_ERROR;
} }
memcpy(out, temp_out + offset, size); memcpy(out, temp_out + offset, size);
@ -712,14 +714,14 @@ static u64 btrfs_read_extent_reg(struct btrfs_path *path, struct btrfs_file_exte
} else } else
{ {
if (!disk_read(physical, out, size)) if (!disk_read(physical, out, size))
return -1ULL; return READ_ERROR;
} }
return size; return size;
} }
ERR("No compression supported right now\n"); ERR("No compression supported right now\n");
return -1ULL; return READ_ERROR;
} }
static u64 btrfs_file_read(const struct btrfs_root_item *root, u64 inr, u64 offset, u64 size, char *buf) static u64 btrfs_file_read(const struct btrfs_root_item *root, u64 inr, u64 offset, u64 size, char *buf)
@ -728,7 +730,7 @@ static u64 btrfs_file_read(const struct btrfs_root_item *root, u64 inr, u64 offs
struct btrfs_disk_key key; struct btrfs_disk_key key;
struct btrfs_file_extent_item *extent; struct btrfs_file_extent_item *extent;
int res = 0; int res = 0;
u64 rd, seek_pointer = (u64) -1ULL, offset_in_extent; u64 rd, seek_pointer = READ_ERROR, offset_in_extent;
BOOLEAN find_res; BOOLEAN find_res;
TRACE("btrfs_file_read inr=%llu offset=%llu size=%llu\n", inr, offset, size); TRACE("btrfs_file_read inr=%llu offset=%llu size=%llu\n", inr, offset, size);
@ -776,10 +778,10 @@ static u64 btrfs_file_read(const struct btrfs_root_item *root, u64 inr, u64 offs
rd = btrfs_read_extent_reg(&path, extent, offset_in_extent, size, buf); rd = btrfs_read_extent_reg(&path, extent, offset_in_extent, size, buf);
} }
if (rd == -1ULL) if (rd == READ_ERROR)
{ {
ERR("Error while reading extent\n"); ERR("Error while reading extent\n");
seek_pointer = (u64) -1ULL; seek_pointer = READ_ERROR;
goto out; goto out;
} }
@ -794,7 +796,7 @@ static u64 btrfs_file_read(const struct btrfs_root_item *root, u64 inr, u64 offs
if (res) if (res)
{ {
seek_pointer = (u64) -1ULL; seek_pointer = READ_ERROR;
goto out; goto out;
} }
@ -814,7 +816,7 @@ static u64 btrfs_lookup_inode_ref(const struct btrfs_root_item *root, u64 inr,
{ {
struct btrfs_path path; struct btrfs_path path;
struct btrfs_inode_ref *ref; struct btrfs_inode_ref *ref;
u64 ret = -1ULL; u64 ret = INVALID_INODE;
init_path(&path); init_path(&path);
if (BtrFsSearchTreeType(root, inr, BTRFS_INODE_REF_KEY, &path)) if (BtrFsSearchTreeType(root, inr, BTRFS_INODE_REF_KEY, &path))
@ -1023,7 +1025,7 @@ static u64 btrfs_lookup_path(const struct btrfs_root_item *root, u64 inr, const
if (len > BTRFS_NAME_MAX) if (len > BTRFS_NAME_MAX)
{ {
ERR("%s: Name too long at \"%.*s\"\n", BTRFS_NAME_MAX, cur); ERR("%s: Name too long at \"%.*s\"\n", BTRFS_NAME_MAX, cur);
return -1ULL; return INVALID_INODE;
} }
if (len == 1 && cur[0] == '.') if (len == 1 && cur[0] == '.')
@ -1150,7 +1152,7 @@ ARC_STATUS BtrFsOpen(CHAR *Path, OPENMODE OpenMode, ULONG *FileId)
inr = btrfs_lookup_path(&BtrFsInfo->FsRoot, BtrFsInfo->FsRoot.root_dirid, Path, &type, &temp_file_info.inode, 40); inr = btrfs_lookup_path(&BtrFsInfo->FsRoot, BtrFsInfo->FsRoot.root_dirid, Path, &type, &temp_file_info.inode, 40);
if (inr == -1ULL) if (inr == INVALID_INODE)
{ {
TRACE("Cannot lookup file %s\n", Path); TRACE("Cannot lookup file %s\n", Path);
return ENOENT; return ENOENT;
@ -1191,7 +1193,7 @@ ARC_STATUS BtrFsRead(ULONG FileId, VOID *Buffer, ULONG Size, ULONG *BytesRead)
Size = phandle->inode.size; Size = phandle->inode.size;
rd = btrfs_file_read(&BtrFsInfo->FsRoot, phandle->inr, phandle->position, Size, Buffer); rd = btrfs_file_read(&BtrFsInfo->FsRoot, phandle->inr, phandle->position, Size, Buffer);
if (rd == -1ULL) if (rd == READ_ERROR)
{ {
TRACE("An error occured while reading file %lu\n", FileId); TRACE("An error occured while reading file %lu\n", FileId);
return ENOENT; return ENOENT;
@ -1245,7 +1247,7 @@ const DEVVTBL *BtrFsMount(ULONG DeviceId)
return NULL; return NULL;
} }
/* Check if SuperBlock is valid. If yes, return Ext2 function table */ /* Check if SuperBlock is valid. If yes, return BTRFS function table */
if (BtrFsInfo->SuperBlock.magic == BTRFS_MAGIC_N) if (BtrFsInfo->SuperBlock.magic == BTRFS_MAGIC_N)
{ {
BtrFsInfo->DeviceId = DeviceId; BtrFsInfo->DeviceId = DeviceId;