ref: 0d4b5b8a8a6e38faf3a07774f97dbf66797f8dea
parent: f8ce6a33af132b68ba48a2da7c04138052eaa49e
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Wed Aug 16 09:15:15 EDT 2023
bzfs: use IOUNIT for buffer size
--- a/sys/src/cmd/bzfs/mkext.c
+++ b/sys/src/cmd/bzfs/mkext.c
@@ -27,7 +27,6 @@
#include "bzfs.h"
enum{
- LEN = 8*1024,
NFLDS = 6, /* filename, modes, uid, gid, mtime, bytes */
};
@@ -39,8 +38,7 @@
void warn(char*, ...);
void usage(void);
char *mtpt;
-Biobufhdr bin;
-uchar binbuf[2*LEN];
+Biobuf bin;
void
usage(void)
@@ -89,15 +87,12 @@
return -1;
}
-enum { NAMELEN = 28 };
-
void
main(int argc, char **argv)
{
char *rargv[10];
int rargc;
- char *fields[NFLDS], name[2*LEN], *p, *namep;
- char uid[NAMELEN], gid[NAMELEN];
+ char *fields[NFLDS], *p;
ulong mode, bytes, mtime;
char *file;
int i, n, stdin, fd, chatty;
@@ -116,7 +111,6 @@
rfork(RFNOTEG);
stdin = 0;
file = nil;
- namep = name;
mtpt = "/root";
chatty = 0;
ARGBEGIN{
@@ -174,33 +168,29 @@
fd = unbflz(unbzip(blockread(fd, blk+13, sizeof(blk)-13)));
- Binits(&bin, fd, OREAD, binbuf, sizeof binbuf);
- while(p = Brdline(&bin, '\n')){
- p[Blinelen(&bin)-1] = '\0';
+ Binit(&bin, fd, OREAD);
+ while((p = Brdstr(&bin, '\n', 1)) != nil){
if(chatty) fprint(2, "%s\n", p);
- if(strcmp(p, "end of archive") == 0){
+ if(strcmp(p, "end of archive") == 0)
_exits(0);
- }
if(getfields(p, fields, NFLDS, 0, " \t") != NFLDS){
warn("too few fields in file header");
continue;
}
- strcpy(namep, fields[0]);
mode = strtoul(fields[1], 0, 8);
mtime = strtoul(fields[4], 0, 10);
bytes = strtoul(fields[5], 0, 10);
- strncpy(uid, fields[2], NAMELEN);
- strncpy(gid, fields[3], NAMELEN);
if(mode & DMDIR)
- mkdir(name, mode, mtime, uid, gid);
+ mkdir(fields[0], mode, mtime, fields[2], fields[3]);
else
- extract(name, mode, mtime, uid, gid, bytes);
+ extract(fields[0], mode, mtime, fields[2], fields[3], bytes);
+ free(p);
}
fprint(2, "premature end of archive\n");
exits("premature end of archive");
}
-char buf[8192];
+char buf[IOUNIT];
int
ffcreate(char *name, ulong mode, char *uid, char *gid, ulong mtime, int length)
@@ -208,7 +198,7 @@
int fd, om;
Dir nd;
- sprint(buf, "%s/%s", mtpt, name);
+ snprint(buf, sizeof buf, "%s/%s", mtpt, name);
om = ORDWR;
if(mode&DMDIR)
om = OREAD;
--- a/sys/src/cmd/bzfs/oramfs.c
+++ b/sys/src/cmd/bzfs/oramfs.c
@@ -16,7 +16,7 @@
OPERM = 0x3, /* mask of all permission types in open mode */
Nram = 512,
Maxsize = 512*1024*1024,
- Maxfdata = 8192,
+ Maxfdata= IOUNIT,
};
typedef struct Fid Fid;
--- a/sys/src/cmd/bzfs/unbzip.c
+++ b/sys/src/cmd/bzfs/unbzip.c
@@ -68,8 +68,8 @@
bunzip(int ofd, char *ofile, Biobuf *bin)
{
int e, n, done, onemore;
- char buf[8192];
- char obuf[8192];
+ char buf[IOUNIT];
+ char obuf[IOUNIT];
Biobuf bout;
bz_stream strm;