summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2021-09-25 09:46:31 +0000
committermidipix <writeonce@midipix.org>2024-05-19 03:36:18 +0000
commit3179bb713afab5e24853313e36d5fde9b2295238 (patch)
tree485b1a4a5bb4b7a9b3abc5c1f7c18a3b0bb37f67 /src
parent0fedf72febdeecc6abd649f07a179811dcd22200 (diff)
downloadtpax-3179bb713afab5e24853313e36d5fde9b2295238.tar.bz2
tpax-3179bb713afab5e24853313e36d5fde9b2295238.tar.xz
item queue: implemented tpax_archive_append_queue_item().
Diffstat (limited to 'src')
-rw-r--r--src/logic/tpax_archive_append.c133
1 files changed, 78 insertions, 55 deletions
diff --git a/src/logic/tpax_archive_append.c b/src/logic/tpax_archive_append.c
index 76ac436..4bc3d2f 100644
--- a/src/logic/tpax_archive_append.c
+++ b/src/logic/tpax_archive_append.c
@@ -140,6 +140,77 @@ static int tpax_archive_append_ret(
return ret;
}
+static int tpax_archive_append_queue_item(
+ const struct tpax_driver_ctx * dctx,
+ const struct dirent * dirent,
+ const struct tpax_dirent * parent,
+ struct tpax_unit_ctx * unit,
+ int depth,
+ int fd,
+ bool * fkeep)
+
+{
+ struct tpax_dirent_buffer * dentbuf;
+ struct tpax_dirent * cdent;
+ const char * src;
+ char * dst;
+ char * cap;
+ size_t needed;
+
+ if (!(dentbuf = tpax_get_driver_dirents(dctx)))
+ if (!(dentbuf = tpax_dirent_buf_first_alloc(dctx)))
+ return tpax_archive_append_ret(
+ TPAX_SYSTEM_ERROR(dctx),
+ unit);
+
+ needed = dirent->d_reclen;
+ needed += offsetof(struct tpax_dirent,dirent);
+ needed += 0x7;
+ needed |= 0x7;
+ needed ^= 0x7;
+
+ for (; dentbuf->next && (dentbuf->nfree < needed); )
+ dentbuf = dentbuf->next;
+
+ if (dentbuf->nfree < needed)
+ if (!(dentbuf = tpax_dirent_buf_next_alloc(dentbuf)))
+ return tpax_archive_append_ret(
+ TPAX_SYSTEM_ERROR(dctx),
+ unit);
+
+ *fkeep = true;
+ cdent = dentbuf->cdent;
+
+ cdent->fdat = fd;
+ cdent->depth = depth;
+ cdent->nsize = needed;
+ cdent->parent = parent;
+
+ memset(&cdent->dirent,0,offsetof(struct dirent,d_name));
+
+ cdent->dirent.d_ino = dirent->d_ino;
+ cdent->dirent.d_type = dirent->d_type;
+ cdent->dirent.d_reclen = dirent->d_reclen;
+
+ src = dirent->d_name;
+ dst = cdent->dirent.d_name;
+
+ cap = dst - offsetof(struct dirent,d_name);
+ cap -= offsetof(struct tpax_dirent,dirent);
+ cap += needed;
+
+ for (; *src; )
+ *dst++ = *src++;
+
+ for (; dst<cap; )
+ *dst++ = 0;
+
+ dentbuf->cdent = (struct tpax_dirent *)cap;
+ dentbuf->nfree -= needed;
+
+ return 0;
+}
+
static int tpax_archive_append_one(
const struct tpax_driver_ctx * dctx,
const struct tpax_unit_ctx * uctx,
@@ -362,17 +433,11 @@ static int tpax_archive_append_dir(
int fd;
bool fkeep;
long nbytes;
- size_t needed;
struct dirent * dirent;
struct dirent * dirents;
- struct tpax_dirent_buffer * dentbuf;
- struct tpax_dirent * cdent;
struct tpax_unit_ctx * unit;
struct stat st;
uintptr_t addr;
- char * src;
- char * dst;
- char * cap;
/* fake uctx for recursion items */
unit = 0;
@@ -443,55 +508,13 @@ static int tpax_archive_append_dir(
}
if (dirent->d_type == DT_DIR) {
- if (!(dentbuf = tpax_get_driver_dirents(dctx)))
- if (!(dentbuf = tpax_dirent_buf_first_alloc(dctx)))
- return tpax_archive_append_ret(
- TPAX_SYSTEM_ERROR(dctx),
- unit);
-
- needed = dirent->d_reclen;
- needed += offsetof(struct tpax_dirent,dirent);
- needed += 0x7;
- needed |= 0x7;
- needed ^= 0x7;
-
- for (; dentbuf->next && (dentbuf->nfree < needed); )
- dentbuf = dentbuf->next;
-
- if (dentbuf->nfree < needed)
- if (!(dentbuf = tpax_dirent_buf_next_alloc(dentbuf)))
- return tpax_archive_append_ret(
- TPAX_SYSTEM_ERROR(dctx),
- unit);
-
- fkeep = true;
- cdent = dentbuf->cdent;
-
- cdent->fdat = fd;
- cdent->depth = depth;
- cdent->nsize = needed;
- cdent->parent = parent;
-
- memset(&cdent->dirent,0,offsetof(struct dirent,d_name));
-
- cdent->dirent.d_type = dirent->d_type;
- cdent->dirent.d_reclen = dirent->d_reclen;
-
- src = dirent->d_name;
- dst = cdent->dirent.d_name;
-
- cap = dst - offsetof(struct dirent,d_name);
- cap -= offsetof(struct tpax_dirent,dirent);
- cap += needed;
-
- for (; *src; )
- *dst++ = *src++;
-
- for (; dst<cap; )
- *dst++ = 0;
-
- dentbuf->cdent = (struct tpax_dirent *)cap;
- dentbuf->nfree -= needed;
+ if (tpax_archive_append_queue_item(
+ dctx,dirent,
+ parent,unit,depth,
+ fd,&fkeep) < 0)
+ return tpax_archive_append_ret(
+ TPAX_NESTED_ERROR(dctx),
+ unit);
} else {
if (tpax_archive_append_one(
dctx,0,dirent,fd,prefix,