History

devfs-posix: apply u9fs truncate support (thanks Fazlul Shahriar)

This was copied fro u9fs, with the issue filed in: https://github.com/golang/go/issues/39238

cinap_lenrek committed 6 years ago

Commit e1964301 parent d4043e91 file · +18 −0Browse files

Unified · Split

kern/devfs-posix.c+18−0
@@ -397,6 +397,13 @@ fswstat(Chan *c, uchar *buf, int n) · 396 unmodified lines
397397 char strs[NAME_MAX*3];
398398 Ufsinfo *uif;
399399
400+ /*
401+ * wstat is supposed to be atomic.
402+ * we check all the things we can before trying anything.
403+ * still, if we are told to truncate a file and rename it and only
404+ * one works, we're screwed. in such cases we leave things
405+ * half broken and return an error. it's hardly perfect.
406+ */
400407 if(convM2D(buf, n, &d, strs) != n)
401408 error(Ebadstat);
402409
@@ -404,6 +411,13 @@ fswstat(Chan *c, uchar *buf, int n) · 1 unmodified line
404411 if(stat(uif->path, &stbuf) < 0)
405412 error(strerror(errno));
406413
414+ /*
415+ * try things in increasing order of harm to the file.
416+ * mtime should come after truncate so that if you
417+ * do both the mtime actually takes effect, but i'd rather
418+ * leave truncate until last.
419+ * (see above comment about atomicity).
420+ */
407421 if(~d.mode != 0 && (int)(d.mode&0777) != (int)(stbuf.st_mode&0777)) {
408422 if(chmod(uif->path, d.mode&0777) < 0)
409423 error(strerror(errno));
@@ -450,6 +464,10 @@ fswstat(Chan *c, uchar *buf, int n) · 40 unmodified lines
450464 uif->gid = p->id;
451465 }
452466 */
467+
468+ if((uvlong)d.length != (uvlong)~0 && truncate(uif->path, d.length) < 0)
469+ error(strerror(errno));
470+
453471 return n;
454472 }
455473

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t