Skip to contentSkip to conversation

erofs-utils: lib: support GNUTYPE_LONGNAME for tarerofs

PATCH In review Gao Xiang 2 participants 2 messages Jul 17, 2023 Library code

lore
Share & tools
lore

Gao Xiang

author
#0 lore raw

PATCH 1/1 erofs-utils: lib: support GNUTYPE_LONGNAME for tarerofs

The 'L' entry is present in a header for a series of 1 or more 512-byte tar blocks that hold just the filename for a file or directory with a name over 100 chars.

Following that series is another header block, in the traditional form:
A header with type '0' (regular file) or '5' (directory), followed by the appropriate number of data blocks with the entry data.

In the header for this series, the name will be truncated to the 1st 100 characters of the actual name.

---
 lib/tar.c | 8 ++++++++
 1 file changed, 8 insertions(+)
lib/tar.c +8 -0
index 8edfe75..b62e562 100644
@@ -570,6 +570,14 @@ restart:
 		if (ret)
 			goto out;
 		goto restart;
+	} else if (th.typeflag == 'L') {
+		free(eh.path);
+		eh.path = malloc(st.st_size + 1);
+		if (st.st_size != erofs_read_from_fd(tar->fd, eh.path,
+						     st.st_size))
+			goto invalid_tar;
+		eh.path[st.st_size] = '\0';
+		goto restart;
 	} else if (th.typeflag == 'K') {
 		free(eh.link);
 		eh.link = malloc(st.st_size + 1);
Signature · 1 line
2.24.4
Tested-by on v1 1/1
#1 lore raw
Quoted 26 lines · Gao Xiang

The 'L' entry is present in a header for a series of 1 or more 512-byte tar blocks that hold just the filename for a file or directory with a name over 100 chars.

Following that series is another header block, in the traditional form:
A header with type '0' (regular file) or '5' (directory), followed by the appropriate number of data blocks with the entry data.

In the header for this series, the name will be truncated to the 1st 100 characters of the actual name.

---
 lib/tar.c | 8 ++++++++
 1 file changed, 8 insertions(+)
lib/tar.c +1 -0
index 8edfe75..b62e562 100644
@@ -570,6 +570,14 @@ restart:
 		if (ret)
 			goto out;
 		goto restart;
+	} else if (th.typeflag == 'L') {

lib/tar.c restart: · line 583

Quoted 10 lines
lib/tar.c +7 -0
+		free(eh.path);
+		eh.path = malloc(st.st_size + 1);
+		if (st.st_size != erofs_read_from_fd(tar->fd, eh.path,
+						     st.st_size))
+			goto invalid_tar;
+		eh.path[st.st_size] = '\0';
+		goto restart;
 	} else if (th.typeflag == 'K') {
 		free(eh.link);
 		eh.link = malloc(st.st_size + 1);

LGTM.

Signature · 2 lines
Thanks,
Jingbo