[inferno-npe] push by noah.ev...@gmail.com - The local filesystem provided by devfs now treats sockets as first cla... on 2011-03-22 08:31 GMT

2 views
Skip to first unread message

infer...@googlecode.com

unread,
Mar 22, 2011, 4:32:15 AM3/22/11
to inferno-n...@googlegroups.com
Revision: 39f6fb5aae70
Author: Noah Evans <noah....@gmail.com>
Date: Tue Mar 22 01:30:40 2011
Log: The local filesystem provided by devfs now treats sockets as
first class files. These changes were inspired by 9vx's devfs-posix.

It is now possible to mount plan9port services like `namespace`/factotum
into the inferno namespace.
http://code.google.com/p/inferno-npe/source/detail?r=39f6fb5aae70

Modified:
/emu/port/devfs-posix.c

=======================================
--- /emu/port/devfs-posix.c Sun Feb 21 06:23:46 2010
+++ /emu/port/devfs-posix.c Tue Mar 22 01:30:40 2011
@@ -13,6 +13,8 @@
#include <utime.h>
#include <dirent.h>
#include <stdio.h>
+#include <sys/socket.h>
+#include <sys/un.h>
#define __EXTENSIONS__
#undef getwd
#include <unistd.h>
@@ -34,10 +36,12 @@
char* spec;
Cname* name; /* Unix's name for file */
Qid rootqid; /* Plan 9's qid for Inferno's root */
+ int issocket;
};

#define FS(c) ((Fsinfo*)(c)->aux)

+
enum
{
IDSHIFT = 8,
@@ -239,6 +243,36 @@
qunlock(&idl);
return n;
}
+
+static int
+opensocket(Fsinfo *fi, char *path)
+{
+ int fd;
+ struct stat st;
+ struct sockaddr_un su;
+
+ if(stat(path, &st) < 0)
+ return -1;
+ if(!S_ISSOCK(st.st_mode))
+ return -1;
+ memset(&su, 0, sizeof su);
+ su.sun_family = AF_UNIX;
+ if(strlen(path)+1 > sizeof su.sun_path){
+ errno = ENAMETOOLONG;
+ return -1;
+ }
+ strcpy(su.sun_path, path);
+ if((fd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
+ return -1;
+ if(connect(fd, (struct sockaddr*)&su, sizeof su) < 0){
+ close(fd);
+ return -1;
+ }
+ fi->fd = fd;
+ fi->issocket = 1;
+ return 0;
+}
+

static Chan*
fsopen(Chan *c, int mode)
@@ -285,7 +319,7 @@
if(mode & OTRUNC)
m |= O_TRUNC;
FS(c)->fd = open(FS(c)->name->s, m, 0666);
- if(FS(c)->fd < 0)
+ if(FS(c)->fd < 0 && opensocket(FS(c), FS(c)->name->s) < 0)
oserror();
}

@@ -400,7 +434,10 @@
poperror();
qunlock(&FS(c)->oq);
}else{
- r = pread(FS(c)->fd, va, n, offset);
+ if(FS(c)->issocket)
+ r = read(FS(c)->fd, va, n);
+ else
+ r = pread(FS(c)->fd, va, n, offset);
if(r < 0){
if(errno == ESPIPE || errno == EPIPE){
r = read(FS(c)->fd, va, n);

Reply all
Reply to author
Forward
0 new messages