mirror of
https://github.com/AsahiLinux/u-boot
synced 2024-11-19 03:08:31 +00:00
83d290c56f
When U-Boot started using SPDX tags we were among the early adopters and there weren't a lot of other examples to borrow from. So we picked the area of the file that usually had a full license text and replaced it with an appropriate SPDX-License-Identifier: entry. Since then, the Linux Kernel has adopted SPDX tags and they place it as the very first line in a file (except where shebangs are used, then it's second line) and with slightly different comment styles than us. In part due to community overlap, in part due to better tag visibility and in part for other minor reasons, switch over to that style. This commit changes all instances where we have a single declared license in the tag as both the before and after are identical in tag contents. There's also a few places where I found we did not have a tag and have introduced one. Signed-off-by: Tom Rini <trini@konsulko.com>
119 lines
2.3 KiB
C
119 lines
2.3 KiB
C
// SPDX-License-Identifier: GPL-2.0+
|
|
/*
|
|
* BTRFS filesystem implementation for U-Boot
|
|
*
|
|
* 2017 Marek Behun, CZ.NIC, marek.behun@nic.cz
|
|
*/
|
|
|
|
#include "btrfs.h"
|
|
#include <malloc.h>
|
|
|
|
u64 btrfs_read_extent_inline(struct btrfs_path *path,
|
|
struct btrfs_file_extent_item *extent, u64 offset,
|
|
u64 size, char *out)
|
|
{
|
|
u32 clen, dlen, orig_size = size, res;
|
|
const char *cbuf;
|
|
char *dbuf;
|
|
const int data_off = offsetof(struct btrfs_file_extent_item,
|
|
disk_bytenr);
|
|
|
|
clen = btrfs_path_item_size(path) - data_off;
|
|
cbuf = (const char *) extent + data_off;
|
|
dlen = extent->ram_bytes;
|
|
|
|
if (offset > dlen)
|
|
return -1ULL;
|
|
|
|
if (size > dlen - offset)
|
|
size = dlen - offset;
|
|
|
|
if (extent->compression == BTRFS_COMPRESS_NONE) {
|
|
memcpy(out, cbuf + offset, size);
|
|
return size;
|
|
}
|
|
|
|
if (dlen > orig_size) {
|
|
dbuf = malloc(dlen);
|
|
if (!dbuf)
|
|
return -1ULL;
|
|
} else {
|
|
dbuf = out;
|
|
}
|
|
|
|
res = btrfs_decompress(extent->compression, cbuf, clen, dbuf, dlen);
|
|
if (res == -1 || res != dlen)
|
|
goto err;
|
|
|
|
if (dlen > orig_size) {
|
|
memcpy(out, dbuf + offset, size);
|
|
free(dbuf);
|
|
} else if (offset) {
|
|
memmove(out, dbuf + offset, size);
|
|
}
|
|
|
|
return size;
|
|
|
|
err:
|
|
if (dlen > orig_size)
|
|
free(dbuf);
|
|
return -1ULL;
|
|
}
|
|
|
|
u64 btrfs_read_extent_reg(struct btrfs_path *path,
|
|
struct btrfs_file_extent_item *extent, u64 offset,
|
|
u64 size, char *out)
|
|
{
|
|
u64 physical, clen, dlen, orig_size = size;
|
|
u32 res;
|
|
char *cbuf, *dbuf;
|
|
|
|
clen = extent->disk_num_bytes;
|
|
dlen = extent->num_bytes;
|
|
|
|
if (offset > dlen)
|
|
return -1ULL;
|
|
|
|
if (size > dlen - offset)
|
|
size = dlen - offset;
|
|
|
|
physical = btrfs_map_logical_to_physical(extent->disk_bytenr);
|
|
if (physical == -1ULL)
|
|
return -1ULL;
|
|
|
|
if (extent->compression == BTRFS_COMPRESS_NONE) {
|
|
physical += extent->offset + offset;
|
|
if (!btrfs_devread(physical, size, out))
|
|
return -1ULL;
|
|
|
|
return size;
|
|
}
|
|
|
|
cbuf = malloc(dlen > size ? clen + dlen : clen);
|
|
if (!cbuf)
|
|
return -1ULL;
|
|
|
|
if (dlen > orig_size)
|
|
dbuf = cbuf + clen;
|
|
else
|
|
dbuf = out;
|
|
|
|
if (!btrfs_devread(physical, clen, cbuf))
|
|
goto err;
|
|
|
|
res = btrfs_decompress(extent->compression, cbuf, clen, dbuf, dlen);
|
|
if (res == -1)
|
|
goto err;
|
|
|
|
if (dlen > orig_size)
|
|
memcpy(out, dbuf + offset, size);
|
|
else
|
|
memmove(out, dbuf + offset, size);
|
|
|
|
free(cbuf);
|
|
return res;
|
|
|
|
err:
|
|
free(cbuf);
|
|
return -1ULL;
|
|
}
|