From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ot1-f68.google.com ([209.85.210.68]) by ewsd; Mon May 25 17:27:28 EDT 2020 Received: by mail-ot1-f68.google.com with SMTP id f18so14697144otq.11 for <9front@9front.org>; Mon, 25 May 2020 14:27:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=lfLs8ANvBas/Sosc0rU3JgfCo8nMFhgnq/m0xu2r3PE=; b=r1Amt0o1Y5QSe6JrVWWOroviw8NQyb8wItUV7aKRlhw5z+LegsSDFUi8KwnQM/nBp6 blVuZ2fz6iucy2Eeky/ZmmVHBYOwM/NULYwunWaEZEgDIbrR0Jbv53GXJnX46sEDBhiZ IFmkBp27iWJyzVPM96PCNOijswN9KesRjbl0ZkXB/mRr6bhUR9bJSZiTrBKh87Bfj9nq Y/I/mARWJfLqf7lJCkvYOsbNvlNklhoncJUiS9/NkBiNcJLWB7/TuDuSq8j+WjhCA8Uc ydPIW2oTPPAEyeBw+SErScYOQG8AbtTDF6TdOPfeMpL67aB+jOh+8/lncjxradAlzaJ0 t+2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=lfLs8ANvBas/Sosc0rU3JgfCo8nMFhgnq/m0xu2r3PE=; b=ORfxAY7A4r06RHj4rHSYzOKFgEJ98oMNDRtSXxap1an6XbsaMYov0lhkCxJtuckeaB viS20+sm0cFuYO/wJBP3Cf2Cwghwm0qGmvRMFPr2L1CxGyQnZCruggSX+EmBQ+r2elQu cbu9z05SanQo4+JHNJAbi62Jjb41K+akjFwHbErLioxm8bo6QmS3GKPY3VOaY9sy5CL/ +hlO9wiv4sUkK4dNMtqJh1FpvkOXl6pyQIESG81kx2Uy5H+EId6oEwO85VCUzoWUgMSq LYLArcqvUm3vFjhilRHEzaEhhWsyFHi95F/vgOTgWZ5OSZSoWHrnkQiIxRrF74WVDdaf v//A== X-Gm-Message-State: AOAM531ockPVd5jI//hVOtHQknzYVDh5JBZkUZYTschVC8kkFfss4zIx ulMMCDXfclacpLnpUv5hO1ZrI/6s3fJ6NDsgeAU9TDV1 X-Google-Smtp-Source: ABdhPJwOFJpTI+h/Wfrc5ksQaYb+gzEzRkxtcAVmzgNR/l/8Y/BqNeZ3oP5M+yvIaHk4RgSO39U5QDIhEMMiIuHT0Xw= X-Received: by 2002:a9d:75d0:: with SMTP id c16mr21699550otl.314.1590442044735; Mon, 25 May 2020 14:27:24 -0700 (PDT) MIME-Version: 1.0 From: Fazlul Shahriar Date: Mon, 25 May 2020 17:27:13 -0400 Message-ID: Subject: [PATCH] [drawterm] devfs-posix: add support for file truncation in wstat To: 9front@9front.org Content-Type: text/plain; charset="UTF-8" List-ID: <9front.9front.org> List-Help: X-Glyph: ➈ X-Bullshit: dependency YAML over SOAP rich-client-based CMS locator Hi, I copied these bits from u9fs to fix an issue when building a Go program within /mnt/term. See: https://github.com/golang/go/issues/39238 diff -r 8fd96772eb02 kern/devfs-posix.c --- a/kern/devfs-posix.c Mon Apr 27 14:19:37 2020 -0700 +++ b/kern/devfs-posix.c Mon May 25 17:22:48 2020 -0400 @@ -397,6 +397,13 @@ char strs[NAME_MAX*3]; Ufsinfo *uif; + /* + * wstat is supposed to be atomic. + * we check all the things we can before trying anything. + * still, if we are told to truncate a file and rename it and only + * one works, we're screwed. in such cases we leave things + * half broken and return an error. it's hardly perfect. + */ if(convM2D(buf, n, &d, strs) != n) error(Ebadstat); @@ -404,6 +411,13 @@ if(stat(uif->path, &stbuf) < 0) error(strerror(errno)); + /* + * try things in increasing order of harm to the file. + * mtime should come after truncate so that if you + * do both the mtime actually takes effect, but i'd rather + * leave truncate until last. + * (see above comment about atomicity). + */ if(~d.mode != 0 && (int)(d.mode&0777) != (int)(stbuf.st_mode&0777)) { if(chmod(uif->path, d.mode&0777) < 0) error(strerror(errno)); @@ -450,6 +464,10 @@ uif->gid = p->id; } */ + + if((uvlong)d.length != (uvlong)~0 && truncate(uif->path, d.length) < 0) + error(strerror(errno)); + return n; }