#define TAG_BTRFS_FILE 'FftB'
#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 {
ULONG DeviceId;
if (ret == 0)
slot++;
else if (slot == 0)
- return -1;
+ return INVALID_ADDRESS;
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,
chunk_map->map[slot - 1].physical + logical - chunk_map->map[slot - 1].logical);
}
path->slots[0] = slot;
- out:
+out:
if (path_current_disk_key(path)->objectid && !btrfs_comp_keys_type(key, path_current_disk_key(path)))
return 0;
else
} while (!next_slot(&key, &path));
- cleanup:
+cleanup:
free_path(&path);
return result;
}
if (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)
}
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,
if (offset > dlen)
{
ERR("Tried to read offset (%llu) beyond extent length (%lu)\n", offset, dlen);
- return -1ULL;
+ return READ_ERROR;
}
if (size > dlen - offset)
size = dlen - offset;
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);
- return -1ULL;
+ return READ_ERROR;
}
if (extent->compression == BTRFS_COMPRESS_NONE)
if (!disk_read(physical, temp_out, size + offset))
{
FrLdrTempFree(temp_out, TAG_BTRFS_FILE);
- return -1ULL;
+ return READ_ERROR;
}
memcpy(out, temp_out + offset, size);
} else
{
if (!disk_read(physical, out, size))
- return -1ULL;
+ return READ_ERROR;
}
return size;
}
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)
struct btrfs_disk_key key;
struct btrfs_file_extent_item *extent;
int res = 0;
- u64 rd, seek_pointer = (u64) -1ULL, offset_in_extent;
+ u64 rd, seek_pointer = READ_ERROR, offset_in_extent;
BOOLEAN find_res;
TRACE("btrfs_file_read inr=%llu offset=%llu size=%llu\n", inr, offset, size);
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");
- seek_pointer = (u64) -1ULL;
+ seek_pointer = READ_ERROR;
goto out;
}
if (res)
{
- seek_pointer = (u64) -1ULL;
+ seek_pointer = READ_ERROR;
goto out;
}
seek_pointer -= offset;
- out:
+out:
free_path(&path);
return seek_pointer;
}
{
struct btrfs_path path;
struct btrfs_inode_ref *ref;
- u64 ret = -1ULL;
+ u64 ret = INVALID_INODE;
init_path(&path);
if (BtrFsSearchTreeType(root, inr, BTRFS_INODE_REF_KEY, &path))
res = TRUE;
- out:
+out:
free_path(&path);
return res;
}
if (len > BTRFS_NAME_MAX)
{
ERR("%s: Name too long at \"%.*s\"\n", BTRFS_NAME_MAX, cur);
- return -1ULL;
+ return INVALID_INODE;
}
if (len == 1 && cur[0] == '.')
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);
return ENOENT;
Size = phandle->inode.size;
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);
return ENOENT;
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)
{
BtrFsInfo->DeviceId = DeviceId;