From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=0.2 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED autolearn=no autolearn_force=no version=3.4.4 Received: (qmail 5066 invoked from network); 31 Dec 2021 01:27:53 -0000 Received: from 4ess.inri.net (216.126.196.42) by inbox.vuxu.org with ESMTPUTF8; 31 Dec 2021 01:27:53 -0000 Received: from wopr.sciops.net ([216.126.196.60]) by 4ess; Thu Dec 30 20:20:44 -0500 2021 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sciops.net; s=20210706; t=1640913639; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to; bh=5y+kiDr5IG0XoTsTUgLDPTm4em7YcZqM8y0M2AaHe8M=; b=JHijMkOw7ADxeYaioPWz+uVdN3O1hJ32mS+y/ncidDoFHkTGN4pHEod2JGkdvlhRaPgU+Y fFxQNVK8h8LzX3BSVa89DKtqJMtJnrJe4fDHyBpP2HmfIhx/7Xi1TCyB4PGyw4PCzknmMt 91/5ABFXce5XmA2JuzWQZ0Exa+sGSkk= Received: by wopr.sciops.net (OpenSMTPD) with ESMTPSA id a8002841 (TLSv1.2:ECDHE-RSA-CHACHA20-POLY1305:256:NO) for <9front@9front.org>; Thu, 30 Dec 2021 17:20:38 -0800 (PST) Message-ID: <5628D0A34F0089B1D3753D6886A1ECFF@wopr.sciops.net> Date: Fri, 31 Dec 2021 03:22:28 +0200 From: qwx@sciops.net To: 9front@9front.org In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit List-ID: <9front.9front.org> List-Help: X-Glyph: ➈ X-Bullshit: progressive pipelining CMS pipelining framework Subject: Re: [9front] delete in page(1) Reply-To: 9front@9front.org Precedence: bulk diff 855cf4326f5a07d7142c2d8918f5fa856d912b85 uncommitted --- a//sys/src/cmd/page.c +++ b//sys/src/cmd/page.c @@ -74,6 +74,7 @@ Czerox, Cwrite, Cext, + Cdel, Cdummy2, Cquit, }; @@ -98,6 +99,7 @@ [Czerox] "zerox", 'z', 0, 0, [Cwrite] "write", 'w', 0, 0, [Cext] "ext", 'x', 0, 0, + [Cdel] "del", 'd', 0, 0, [Cdummy2] "", 0, 0, 0, [Cquit] "quit", 'q', Kdel, Keof, }; @@ -134,6 +136,7 @@ void showpage(Page *); void drawpage(Page *); Point pagesize(Page *); +void drawlock(int); Page* addpage(Page *up, char *name, int (*popen)(Page *), void *pdata, int fd) @@ -986,6 +989,54 @@ } } +/* page entries are never freed, there's no point + * and would break everything */ +Page* +delpage(Page *p) +{ + Page *t, *q; + + if(p == nil) + return nil; + /* to remove(2) subpages in documents makes no sense, and just + * removing a subentry doesn't seem like a feature worth the bother */ + if(p->up != root) + return p; + if(p->fd >= 0) + close(p->fd); + p->fd = -1; + if(remove(p->name) < 0){ + fprint(2, "remove %s: %r", p->name); + return p; + } + qlock(&pagelock); + for(t = p->down; t != nil && t->up != root; t = q){ + qlock(t); + drawlock(0); + unloadpage(t); + drawlock(1); + free(t->name); + free(t->data); + t->name = t->data = nil; + q = nextpage(t); + qunlock(t); + } + drawlock(0); + unloadpage(p); + drawlock(1); + free(p->name); + free(p->data); + p->name = p->data = nil; + if(root->down != p){ + t = prevpage(p); + t->next = p->next; + }else + root->down = p->next; + qunlock(&pagelock); + qunlock(p); + return p->next != nil ? p->next : t; +} + /* * A draw operation that touches only the area contained in bot but not in top. * mp and sp get aligned with bot.min. @@ -1461,6 +1512,7 @@ char buf[NPATH], *s; Point o; int fd; + Page *p; switch(i){ case Corigsize: @@ -1545,6 +1597,19 @@ break; case Csnarf: writeaddr(current, "/dev/snarf"); + break; + case Cdel: + if(current == nil || !canqlock(current)) + break; + if((p = delpage(current)) == current){ + qunlock(current); + break; + } + current = p; + if(current == nil) + break; + forward = 1; + showpage(current); break; case Cnext: forward = 1;