Skip to content
This repository was archived by the owner on Sep 27, 2023. It is now read-only.

Commit

Permalink
Merge branch 'erofs:dev' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
affggh authored Aug 25, 2023
2 parents 4238346 + 88a43ec commit c0ba618
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 37 deletions.
2 changes: 1 addition & 1 deletion include/erofs/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ struct erofs_xattr_prefix_item {

struct erofs_sb_info {
struct erofs_device_info *devs;
const char *devname;
char *devname;

u64 total_blocks;
u64 primarydevice_blocks;
Expand Down
14 changes: 12 additions & 2 deletions lib/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include "erofs/io.h"
Expand Down Expand Up @@ -46,6 +47,7 @@ static int dev_get_blkdev_size(int fd, u64 *bytes)
void dev_close(struct erofs_sb_info *sbi)
{
close(sbi->devfd);
free(sbi->devname);
sbi->devname = NULL;
sbi->devfd = -1;
sbi->devsz = 0;
Expand Down Expand Up @@ -95,7 +97,11 @@ int dev_open(struct erofs_sb_info *sbi, const char *dev)
return -EINVAL;
}

sbi->devname = dev;
sbi->devname = strdup(dev);
if (!sbi->devname) {
close(fd);
return -ENOMEM;
}
sbi->devfd = fd;

erofs_info("successfully to open %s", dev);
Expand Down Expand Up @@ -136,8 +142,12 @@ int dev_open_ro(struct erofs_sb_info *sbi, const char *dev)
return -errno;
}

sbi->devname = strdup(dev);
if (!sbi->devname) {
close(fd);
return -ENOMEM;
}
sbi->devfd = fd;
sbi->devname = dev;
sbi->devsz = INT64_MAX;
return 0;
}
Expand Down
2 changes: 2 additions & 0 deletions lib/namei.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ int erofs_read_inode_from_disk(struct erofs_inode *vi)
die = (struct erofs_inode_extended *)buf;
vi->xattr_isize = erofs_xattr_ibody_size(die->i_xattr_icount);
vi->i_mode = le16_to_cpu(die->i_mode);
vi->i_ino[0] = le32_to_cpu(die->i_ino);

switch (vi->i_mode & S_IFMT) {
case S_IFREG:
Expand Down Expand Up @@ -95,6 +96,7 @@ int erofs_read_inode_from_disk(struct erofs_inode *vi)
vi->inode_isize = sizeof(struct erofs_inode_compact);
vi->xattr_isize = erofs_xattr_ibody_size(dic->i_xattr_icount);
vi->i_mode = le16_to_cpu(dic->i_mode);
vi->i_ino[0] = le32_to_cpu(dic->i_ino);

switch (vi->i_mode & S_IFMT) {
case S_IFREG:
Expand Down
9 changes: 7 additions & 2 deletions lib/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ static int erofs_init_devices(struct erofs_sb_info *sbi,
ret = dev_read(sbi, 0, &dis, pos, sizeof(dis));
if (ret < 0) {
free(sbi->devs);
sbi->devs = NULL;
return ret;
}

Expand Down Expand Up @@ -126,14 +127,18 @@ int erofs_read_superblock(struct erofs_sb_info *sbi)
return ret;

ret = erofs_xattr_prefixes_init(sbi);
if (ret)
if (ret && sbi->devs) {
free(sbi->devs);
sbi->devs = NULL;
}
return ret;
}

void erofs_put_super(struct erofs_sb_info *sbi)
{
if (sbi->devs)
if (sbi->devs) {
free(sbi->devs);
sbi->devs = NULL;
}
erofs_xattr_prefixes_cleanup(sbi);
}
77 changes: 45 additions & 32 deletions lib/tar.c
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,44 @@ void tarerofs_remove_inode(struct erofs_inode *inode)
--inode->i_parent->i_nlink;
}

static int tarerofs_write_file_data(struct erofs_inode *inode,
struct erofs_tarfile *tar)
{
unsigned int j, rem;
char buf[65536];

if (!inode->i_tmpfile) {
inode->i_tmpfile = tmpfile();
if (!inode->i_tmpfile)
return -ENOSPC;
}

for (j = inode->i_size; j; ) {
rem = min_t(unsigned int, sizeof(buf), j);

if (erofs_read_from_fd(tar->fd, buf, rem) != rem ||
fwrite(buf, rem, 1, inode->i_tmpfile) != 1)
return -EIO;
j -= rem;
}
fseek(inode->i_tmpfile, 0, SEEK_SET);
inode->with_tmpfile = true;
return 0;
}

static int tarerofs_write_file_index(struct erofs_inode *inode,
struct erofs_tarfile *tar, erofs_off_t data_offset)
{
int ret;

ret = tarerofs_write_chunkes(inode, data_offset);
if (ret)
return ret;
if (erofs_lskip(tar->fd, inode->i_size))
return -EIO;
return 0;
}

int tarerofs_parse_tar(struct erofs_inode *root, struct erofs_tarfile *tar)
{
char path[PATH_MAX];
Expand Down Expand Up @@ -672,41 +710,16 @@ int tarerofs_parse_tar(struct erofs_inode *root, struct erofs_tarfile *tar)
inode->i_size = strlen(eh.link);
inode->i_link = malloc(inode->i_size + 1);
memcpy(inode->i_link, eh.link, inode->i_size + 1);
} else if (tar->index_mode) {
ret = tarerofs_write_chunkes(inode, data_offset);
if (ret)
goto out;
if (erofs_lskip(tar->fd, inode->i_size)) {
} else if (inode->i_size) {
if (tar->index_mode)
ret = tarerofs_write_file_index(inode, tar,
data_offset);
else
ret = tarerofs_write_file_data(inode, tar);
if (ret) {
erofs_iput(inode);
ret = -EIO;
goto out;
}
} else {
char buf[65536];

if (!inode->i_tmpfile) {
inode->i_tmpfile = tmpfile();

if (!inode->i_tmpfile) {
erofs_iput(inode);
ret = -ENOSPC;
goto out;
}
}

for (j = inode->i_size; j; ) {
rem = min_t(int, sizeof(buf), j);

if (erofs_read_from_fd(tar->fd, buf, rem) != rem ||
fwrite(buf, rem, 1, inode->i_tmpfile) != 1) {
erofs_iput(inode);
ret = -EIO;
goto out;
}
j -= rem;
}
fseek(inode->i_tmpfile, 0, SEEK_SET);
inode->with_tmpfile = true;
}
inode->i_nlink++;
ret = 0;
Expand Down

0 comments on commit c0ba618

Please sign in to comment.