9front - general discussion about 9front
 help / color / mirror / Atom feed
* [PATCH] [drawterm] devfs-posix: add support for file truncation in wstat
@ 2020-05-25 21:27 Fazlul Shahriar
  2020-05-26 22:22 ` [9front] " cinap_lenrek
  0 siblings, 1 reply; 2+ messages in thread
From: Fazlul Shahriar @ 2020-05-25 21:27 UTC (permalink / raw)
  To: 9front

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [9front] [PATCH] [drawterm] devfs-posix: add support for file truncation in wstat
  2020-05-25 21:27 [PATCH] [drawterm] devfs-posix: add support for file truncation in wstat Fazlul Shahriar
@ 2020-05-26 22:22 ` cinap_lenrek
  0 siblings, 0 replies; 2+ messages in thread
From: cinap_lenrek @ 2020-05-26 22:22 UTC (permalink / raw)
  To: 9front

applied.

muchas gracias!

--
cinap


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-05-26 22:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-25 21:27 [PATCH] [drawterm] devfs-posix: add support for file truncation in wstat Fazlul Shahriar
2020-05-26 22:22 ` [9front] " cinap_lenrek

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).