summaryrefslogtreecommitdiff
path: root/sys/src/ape/lib/ap/plan9/dirtostat.c
diff options
context:
space:
mode:
authorTaru Karttunen <taruti@taruti.net>2011-03-30 15:46:40 +0300
committerTaru Karttunen <taruti@taruti.net>2011-03-30 15:46:40 +0300
commite5888a1ffdae813d7575f5fb02275c6bb07e5199 (patch)
treed8d51eac403f07814b9e936eed0c9a79195e2450 /sys/src/ape/lib/ap/plan9/dirtostat.c
Import sources from 2011-03-30 iso image
Diffstat (limited to 'sys/src/ape/lib/ap/plan9/dirtostat.c')
-rwxr-xr-xsys/src/ape/lib/ap/plan9/dirtostat.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/sys/src/ape/lib/ap/plan9/dirtostat.c b/sys/src/ape/lib/ap/plan9/dirtostat.c
new file mode 100755
index 000000000..6abc6dfa7
--- /dev/null
+++ b/sys/src/ape/lib/ap/plan9/dirtostat.c
@@ -0,0 +1,52 @@
+#include "lib.h"
+#include <sys/stat.h>
+#include <errno.h>
+#include "sys9.h"
+#include "dir.h"
+
+/* fi is non-null if there is an fd associated with s */
+void
+_dirtostat(struct stat *s, Dir *d, Fdinfo *fi)
+{
+ int num;
+ char *nam;
+
+ s->st_dev = (d->type<<8)|(d->dev&0xFF);
+ s->st_ino = d->qid.path;
+ s->st_mode = d->mode&0777;
+ if(fi && (fi->flags&FD_ISTTY))
+ s->st_mode |= S_IFCHR;
+ else if(d->mode & 0x80000000)
+ s->st_mode |= S_IFDIR;
+ else if(d->type == '|' || d->type == 's')
+ s->st_mode |= S_IFIFO;
+ else if(d->type != 'M')
+ s->st_mode |= S_IFCHR;
+ else
+ s->st_mode |= S_IFREG;
+ s->st_nlink = 1;
+ s->st_uid = 1;
+ s->st_gid = 1;
+ if(fi && (fi->flags&FD_BUFFERED))
+ s->st_size = fi->buf->n;
+ else
+ s->st_size = d->length;
+ s->st_atime = d->atime;
+ s->st_mtime = d->mtime;
+ s->st_ctime = d->mtime;
+ if(fi && fi->uid != -2){
+ s->st_uid = fi->uid;
+ s->st_gid = fi->gid;
+ } else {
+ nam = d->uid;
+ if(_getpw(&num, &nam, 0))
+ s->st_uid = num;
+ nam = d->gid;
+ if(_getpw(&num, &nam, 0))
+ s->st_gid = num;
+ if(fi){
+ fi->uid = s->st_uid;
+ fi->gid = s->st_gid;
+ }
+ }
+}