9front - general discussion about 9front
 help / color / mirror / Atom feed
From: Fazlul Shahriar <fshahriar@gmail.com>
To: 9front@9front.org
Subject: [PATCH] [drawterm] devfs-posix: add support for file truncation in wstat
Date: Mon, 25 May 2020 17:27:13 -0400	[thread overview]
Message-ID: <CAA2CNPbV6kAZwH8=nV1P3Sv5C9LWE4HXQypP7Ms=joXQ1-6xnQ@mail.gmail.com> (raw)

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;
 }


             reply	other threads:[~2020-05-25 21:27 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-25 21:27 Fazlul Shahriar [this message]
2020-05-26 22:22 ` [9front] " cinap_lenrek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAA2CNPbV6kAZwH8=nV1P3Sv5C9LWE4HXQypP7Ms=joXQ1-6xnQ@mail.gmail.com' \
    --to=fshahriar@gmail.com \
    --cc=9front@9front.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).