int close(int fd) { int cmd = PATH_CMD_CLOSE; unsigned int replyfd = getpid() + 3; int status = -1; char buf[4 + 4 + 4]; int pos = 0; path_write_data(buf, &cmd, 4, pos); path_write_data(buf, &replyfd, 4, pos); path_write_data(buf, &fd, 4, pos); write(PATHSERVER_FD, buf, pos); read(replyfd, &status, 4); return status; }
int open(const char *pathname, int flags) { int cmd = PATH_CMD_OPEN; unsigned int replyfd = getpid() + 3; size_t plen = strlen(pathname) + 1; unsigned int fd = -1; char buf[4 + 4 + 4 + PATH_MAX]; (void) flags; int pos = 0; path_write_data(buf, &cmd, 4, pos); path_write_data(buf, &replyfd, 4, pos); path_write_data(buf, &plen, 4, pos); path_write_data(buf, pathname, plen, pos); write(PATHSERVER_FD, buf, pos); read(replyfd, &fd, 4); return fd; }
int mkfile(const char *pathname, int mode, int dev) { int cmd = PATH_CMD_MKFILE; unsigned int replyfd = getpid() + 3; size_t plen = strlen(pathname)+1; char buf[4 + 4 + 4 + PATH_MAX + 4]; (void) mode; int pos = 0; int status = 0; path_write_data(buf, &cmd, 4, pos); path_write_data(buf, &replyfd, 4, pos); path_write_data(buf, &plen, 4, pos); path_write_data(buf, pathname, plen, pos); path_write_data(buf, &dev, 4, pos); write(PATHSERVER_FD, buf, pos); read(replyfd, &status, 4); return status; }