diff a70280308ae782ac422e78ccf19b221697116c1b uncommitted --- a/sys/src/cmd/ext4srv/common.h +++ b/sys/src/cmd/ext4srv/common.h @@ -5,9 +5,7 @@ char *group; int cachewb; int asroot; - int rdonly; - - int fstype; + int ream; int blksz; int inodesz; u32int ninode; --- a/sys/src/cmd/ext4srv/ext4srv.c +++ b/sys/src/cmd/ext4srv/ext4srv.c @@ -36,9 +36,8 @@ .group = nil, .cachewb = 0, .asroot = 0, - .rdonly = 0, - .fstype = -1, + .ream = 0, .blksz = 1024, .label = "", .inodesz = 256, @@ -46,7 +45,9 @@ }; static u32int Root; static u8int zero[65536]; -static char *srvname = "ext4"; +static char *srvname; +static char *device; +static Part *devpart; static int haveperm(Aux *a, int p, struct ext4_inode *inodeout) @@ -115,27 +116,31 @@ static void rattach(Req *r) { - char err[ERRMAX]; Aux *a; if((a = calloc(1, sizeof(*a))) == nil) respond(r, "memory"); - else if((a->p = openpart(r->ifcall.aname, &opts)) == nil){ - free(a); - rerrstr(err, sizeof(err)); - respond(r, err); - }else{ - if(opts.asroot || findgroup(&a->p->groups, r->ifcall.uname, &a->uid) == nil) - a->uid = Root; - - incref(a->p); - a->type = Adir; - a->path = estrdup9p(""); - r->ofcall.qid = a->p->qidmask; - r->fid->qid = a->p->qidmask; - r->fid->aux = a; - respond(r, nil); + if(r->ifcall.aname && *r->ifcall.aname){ + if((a->p = openpart(r->ifcall.aname, &opts)) == nil){ + free(a); + responderror(r); + return; + } + }else if((a->p = devpart) == nil){ + respond(r, "no file specified"); + return; } + + if(opts.asroot || findgroup(&a->p->groups, r->ifcall.uname, &a->uid) == nil) + a->uid = Root; + + incref(a->p); + a->type = Adir; + a->path = estrdup9p(""); + r->ofcall.qid = a->p->qidmask; + r->fid->qid = a->p->qidmask; + r->fid->aux = a; + respond(r, nil); } static u32int @@ -876,8 +881,8 @@ static void usage(void) { - fprint(2, "usage: %s [-Crs] [-g groupfile] [-R uid] [srvname]\n", argv0); - fprint(2, "mkfs: %s -M (2|3|4) [-L label] [-b blksize] [-N numinodes] [-I inodesize] device\n", argv0); + fprint(2, "usage: %s [-Cs] [-f file] [-g groupfile] [-n srvname] [-R uid]\n", argv0); + fprint(2, "mkfs: %s [-L label] [-b blksz] [-N ninodes] [-I inodesz] -f file -r (2|3|4)\n", argv0); threadexitsall("usage"); } @@ -891,20 +896,22 @@ rfork(RFNOTEG); stdio = 0; + device = nil; ARGBEGIN{ + case 'C': + opts.cachewb = 1; + break; case 'D': chatty9p++; -nomkfs: - if(opts.fstype > 0) - usage(); - opts.fstype = 0; break; case 'd': ext4_dmask_set(strtoul(EARGF(usage()), nil, 0)); break; - case 'C': - opts.cachewb = 1; - goto nomkfs; + case 'f': + if(device != nil) + usage(); + device = EARGF(usage()); + break; case 'g': gr = EARGF(usage()); if((f = open(gr, OREAD)) < 0) @@ -919,23 +926,20 @@ sysfatal("%s: read failed", gr); close(f); opts.group[sz] = 0; - goto nomkfs; + break; + case 'n': + if(stdio != 0) + usage(); + srvname = EARGF(usage()); + break; case 'R': opts.asroot = 1; Root = atoll(EARGF(usage())); - goto nomkfs; - case 'r': - opts.rdonly = 1; - goto nomkfs; + break; case 's': stdio = 1; - goto nomkfs; - case 'M': - if(!opts.fstype) + if(srvname != nil) usage(); - opts.fstype = atoi(EARGF(usage())); - if(opts.fstype < 2 || opts.fstype > 4) - usage(); break; case 'b': @@ -942,47 +946,48 @@ opts.blksz = atoi(EARGF(usage())); if(opts.blksz != 1024 && opts.blksz != 2048 && opts.blksz != 4096) usage(); -yesmkfs: - if(opts.fstype < 1) - usage(); break; - case 'L': - opts.label = EARGF(usage()); - goto yesmkfs; case 'I': opts.inodesz = atoi(EARGF(usage())); if(opts.inodesz < 128 || ((opts.inodesz-1) & opts.inodesz) != 0) usage(); - goto yesmkfs; + break; + case 'L': + opts.label = EARGF(usage()); + break; case 'N': opts.ninode = atoi(EARGF(usage())); if(opts.ninode < 1) usage(); - goto yesmkfs; + break; + case 'r': + if(opts.ream > 0) + usage(); + opts.ream = atoi(EARGF(usage())); + if(opts.ream < 2 || opts.ream > 4) + usage(); + break; default: usage(); }ARGEND - if(opts.fstype > 1){ - if(argc != 1) - usage(); - if(openpart(argv[0], &opts) == nil) - sysfatal("%r"); - closeallparts(); - threadexitsall(nil); - }else{ - if(!stdio && argc == 1) - srvname = *argv; - else if(argc != 0) - usage(); + if(argc != 0) + usage(); - if(stdio){ - fs.infd = 0; - fs.outfd = 1; - threadsrv(&fs); - }else - threadpostsrv(&fs, srvname); - threadexits(nil); + if(device == nil && opts.ream > 1) + usage(); + if(device != nil && (devpart = openpart(device, &opts)) == nil) + sysfatal("%r"); + + if(stdio){ + fs.infd = 0; + fs.outfd = 1; + threadsrv(&fs); + }else{ + if(srvname == nil) + srvname = "ext4"; + threadpostsrv(&fs, srvname); } + threadexits(nil); } --- a/sys/src/cmd/ext4srv/part.c +++ b/sys/src/cmd/ext4srv/part.c @@ -203,7 +203,7 @@ int r; mp = &p->mp; - if(ext4_mount(mp, &p->bdev, opts->rdonly) < 0){ + if(ext4_mount(mp, &p->bdev, 0) < 0){ werrstr("mount: %r"); goto error; } @@ -307,7 +307,7 @@ p->partdev = (char*)(p+1) + blksz; strcpy(p->partdev, dev); - if(opts->fstype > 1){ + if(opts->ream > 1){ memset(&fs, 0, sizeof(fs)); memset(&info, 0, sizeof(info)); info.block_size = opts->blksz; @@ -314,12 +314,12 @@ snprint(info.label, sizeof(info.label), opts->label); info.inode_size = opts->inodesz; info.inodes = opts->ninode; - info.journal = opts->fstype > 2; + info.journal = opts->ream > 2; for(i = 0; i < 16; i += 4){ rn = truerand(); memcpy(info.uuid+i, &rn, 4); } - if(ext4_mkfs(&fs, &p->bdev, &info, opts->fstype) < 0){ + if(ext4_mkfs(&fs, &p->bdev, &info, opts->ream) < 0){ werrstr("mkfs: %r"); goto error; }