diff options
Diffstat (limited to 'ports/darwin/guts')
-rw-r--r-- | ports/darwin/guts/COPYRIGHT | 17 | ||||
-rw-r--r-- | ports/darwin/guts/fcntl.c | 46 | ||||
-rw-r--r-- | ports/darwin/guts/fgetgrent_r.c | 13 | ||||
-rw-r--r-- | ports/darwin/guts/fgetpwent_r.c | 13 | ||||
-rw-r--r-- | ports/darwin/guts/fgetxattr.c | 13 | ||||
-rw-r--r-- | ports/darwin/guts/flistxattr.c | 13 | ||||
-rw-r--r-- | ports/darwin/guts/fsetxattr.c | 13 | ||||
-rw-r--r-- | ports/darwin/guts/fstat.c | 27 | ||||
-rw-r--r-- | ports/darwin/guts/getgrent_r.c | 13 | ||||
-rw-r--r-- | ports/darwin/guts/getgrouplist.c | 42 | ||||
-rw-r--r-- | ports/darwin/guts/getgroups.c | 22 | ||||
-rw-r--r-- | ports/darwin/guts/getpwent_r.c | 13 | ||||
-rw-r--r-- | ports/darwin/guts/getxattr.c | 13 | ||||
-rw-r--r-- | ports/darwin/guts/listxattr.c | 13 | ||||
-rw-r--r-- | ports/darwin/guts/lstat.c | 27 | ||||
-rw-r--r-- | ports/darwin/guts/open.c | 49 | ||||
-rw-r--r-- | ports/darwin/guts/scandir.c | 14 | ||||
-rw-r--r-- | ports/darwin/guts/setxattr.c | 13 | ||||
-rw-r--r-- | ports/darwin/guts/stat.c | 31 |
19 files changed, 405 insertions, 0 deletions
diff --git a/ports/darwin/guts/COPYRIGHT b/ports/darwin/guts/COPYRIGHT new file mode 100644 index 0000000..c96e1b1 --- /dev/null +++ b/ports/darwin/guts/COPYRIGHT @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2008-2010 Wind River Systems, Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the Lesser GNU General Public License version 2.1 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the Lesser GNU General Public License for more details. + * + * You should have received a copy of the Lesser GNU General Public License + * version 2.1 along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ diff --git a/ports/darwin/guts/fcntl.c b/ports/darwin/guts/fcntl.c new file mode 100644 index 0000000..ef42b33 --- /dev/null +++ b/ports/darwin/guts/fcntl.c @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2011 Wind River Systems; see + * guts/COPYRIGHT for information. + * + * int fcntl(int fd, int cmd, ... { struct flock *lock }) + * int rc = -1; + */ + int save_errno; + long long flag = 0; + void *ptr = 0; + off_t off = 0; + + va_start(ap, cmd); + flag = va_arg(ap, long long); + va_end(ap); + rc = real_fcntl(fd, cmd, flag); + + switch (cmd) { + case F_DUPFD: +#ifdef F_DUPFD_CLOEXEC + /* it doesn't exist now, but if I take this out they'll add it + * just to mess with me. + */ + case F_DUPFD_CLOEXEC: +#endif + /* actually do something */ + save_errno = errno; + if (rc != -1) { + pseudo_debug(2, "fcntl_dup: %d->%d\n", fd, rc); + pseudo_client_op(OP_DUP, 0, fd, rc, 0, 0); + } + errno = save_errno; + break; + default: + /* nothing to do, we hope */ + break; + } + + save_errno = errno; + pseudo_debug(3, "fcntl(fd %d, cmd %d, %llx) => %d (%s)\n", + fd, cmd, flag, rc, strerror(errno)); + errno = save_errno; + +/* return rc; + * } + */ diff --git a/ports/darwin/guts/fgetgrent_r.c b/ports/darwin/guts/fgetgrent_r.c new file mode 100644 index 0000000..e760cdd --- /dev/null +++ b/ports/darwin/guts/fgetgrent_r.c @@ -0,0 +1,13 @@ +/* + * Copyright (c) 2011 Wind River Systems; see + * guts/COPYRIGHT for information. + * + * int fgetgrent_r(FILE *fp, struct group*gbuf, char *buf, size_t buflen, struct group **gbufp) + * int rc = -1; + */ + + rc = real_fgetgrent_r(fp, gbuf, buf, buflen, gbufp); + +/* return rc; + * } + */ diff --git a/ports/darwin/guts/fgetpwent_r.c b/ports/darwin/guts/fgetpwent_r.c new file mode 100644 index 0000000..cfea5b8 --- /dev/null +++ b/ports/darwin/guts/fgetpwent_r.c @@ -0,0 +1,13 @@ +/* + * Copyright (c) 2011 Wind River Systems; see + * guts/COPYRIGHT for information. + * + * int fgetpwent_r(FILE *fp, struct passwd *pbuf, char *buf, size_t buflen, struct passwd **pbufp) + * int rc = -1; + */ + + rc = real_fgetpwent_r(fp, pbuf, buf, buflen, pbufp); + +/* return rc; + * } + */ diff --git a/ports/darwin/guts/fgetxattr.c b/ports/darwin/guts/fgetxattr.c new file mode 100644 index 0000000..1cd8904 --- /dev/null +++ b/ports/darwin/guts/fgetxattr.c @@ -0,0 +1,13 @@ +/* + * Copyright (c) 2011 Wind River Systems; see + * guts/COPYRIGHT for information. + * + * ssize_t fgetxattr(int filedes, const char *name, void *value, size_t size, u_int32_t position, int options) + * ssize_t rc = -1; + */ + + rc = real_fgetxattr(filedes, name, value, size, position, options); + +/* return rc; + * } + */ diff --git a/ports/darwin/guts/flistxattr.c b/ports/darwin/guts/flistxattr.c new file mode 100644 index 0000000..7575f28 --- /dev/null +++ b/ports/darwin/guts/flistxattr.c @@ -0,0 +1,13 @@ +/* + * Copyright (c) 2011 Wind River Systems; see + * guts/COPYRIGHT for information. + * + * ssize_t flistxattr(int filedes, char *list, size_t size, int options) + * ssize_t rc = -1; + */ + + rc = real_flistxattr(filedes, list, size, options); + +/* return rc; + * } + */ diff --git a/ports/darwin/guts/fsetxattr.c b/ports/darwin/guts/fsetxattr.c new file mode 100644 index 0000000..541569a --- /dev/null +++ b/ports/darwin/guts/fsetxattr.c @@ -0,0 +1,13 @@ +/* + * Copyright (c) 2011 Wind River Systems; see + * guts/COPYRIGHT for information. + * + * int fsetxattr(int filedes, const char *name, const void *value, size_t size, u_int32_t position, int options) + * int rc = -1; + */ + + rc = real_fsetxattr(filedes, name, value, size, position, options); + +/* return rc; + * } + */ diff --git a/ports/darwin/guts/fstat.c b/ports/darwin/guts/fstat.c new file mode 100644 index 0000000..7695147 --- /dev/null +++ b/ports/darwin/guts/fstat.c @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2011 Wind River Systems; see + * guts/COPYRIGHT for information. + * + * int fstat(int fd, struct stat *buf) + * int rc = -1; + */ + pseudo_msg_t *msg; + + rc = real_fstat(fd, buf); + + if (rc == -1) { + return rc; + } + + /* query database + * note that symlink canonicalizing is now automatic, so we + * don't need to check for a symlink on this end + */ + msg = pseudo_client_op(OP_FSTAT, 0, fd, -1, 0, buf); + if (msg && msg->result == RESULT_SUCCEED) { + pseudo_stat_msg(buf, msg); + } + +/* return rc; + * } + */ diff --git a/ports/darwin/guts/getgrent_r.c b/ports/darwin/guts/getgrent_r.c new file mode 100644 index 0000000..9d5db5a --- /dev/null +++ b/ports/darwin/guts/getgrent_r.c @@ -0,0 +1,13 @@ +/* + * Copyright (c) 2011 Wind River Systems; see + * guts/COPYRIGHT for information. + * + * int getgrent_r(struct group *gbuf, char *buf, size_t buflen, struct group **gbufp) + * int rc = -1; + */ + + rc = real_getgrent_r(gbuf, buf, buflen, gbufp); + +/* return rc; + * } + */ diff --git a/ports/darwin/guts/getgrouplist.c b/ports/darwin/guts/getgrouplist.c new file mode 100644 index 0000000..85fccc9 --- /dev/null +++ b/ports/darwin/guts/getgrouplist.c @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2010 Wind River Systems; see + * guts/COPYRIGHT for information. + * + * static int + * wrap_getgrouplist(const char *name, int basegid, int *groups, int *ngroups) { + * int rc = -1; + */ + + int found = 0; + int found_group = 0; + char buf[PSEUDO_PWD_MAX]; + struct group grp, *gbuf = &grp; + + setgrent(); + while ((rc = wrap_getgrent_r(gbuf, buf, PSEUDO_PWD_MAX, &gbuf)) == 0) { + int i = 0; + for (i = 0; gbuf->gr_mem[i]; ++i) { + if (!strcmp(gbuf->gr_mem[i], name)) { + if (found < *ngroups) + groups[found] = gbuf->gr_gid; + ++found; + if ((int) gbuf->gr_gid == basegid) + found_group = 1; + } + } + } + endgrent(); + if (!found_group) { + if (found < *ngroups) + groups[found] = basegid; + ++found; + } + if (found >= *ngroups) + rc = -1; + else + rc = found; + *ngroups = found; + +/* return rc; + * } + */ diff --git a/ports/darwin/guts/getgroups.c b/ports/darwin/guts/getgroups.c new file mode 100644 index 0000000..3cbeb76 --- /dev/null +++ b/ports/darwin/guts/getgroups.c @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2010 Wind River Systems; see + * guts/COPYRIGHT for information. + * + * static int + * wrap_getgroups(int size, gid_t *list) { + * int rc = -1; + */ + struct passwd *p = wrap_getpwuid(wrap_getuid()); + int oldsize = size; + + if (p) { + rc = wrap_getgrouplist(p->pw_name, wrap_getgid(), (int *) list, &size); + if (oldsize == 0 || size <= oldsize) + rc = size; + } else { + errno = ENOENT; + } + +/* return rc; + * } + */ diff --git a/ports/darwin/guts/getpwent_r.c b/ports/darwin/guts/getpwent_r.c new file mode 100644 index 0000000..3de41b9 --- /dev/null +++ b/ports/darwin/guts/getpwent_r.c @@ -0,0 +1,13 @@ +/* + * Copyright (c) 2011 Wind River Systems; see + * guts/COPYRIGHT for information. + * + * int getpwent_r(struct passwd *pwbuf, char *buf, size_t buflen, struct passwd **pwbufp) + * int rc = -1; + */ + + rc = real_getpwent_r(pwbuf, buf, buflen, pwbufp); + +/* return rc; + * } + */ diff --git a/ports/darwin/guts/getxattr.c b/ports/darwin/guts/getxattr.c new file mode 100644 index 0000000..16f0993 --- /dev/null +++ b/ports/darwin/guts/getxattr.c @@ -0,0 +1,13 @@ +/* + * Copyright (c) 2011 Wind River Systems; see + * guts/COPYRIGHT for information. + * + * ssize_t getxattr(const char *pathname, const char *name, void *value, size_t size, u_int32_t position, int options) + * ssize_t rc = -1; + */ + + rc = real_getxattr(pathname, name, value, size, position, options); + +/* return rc; + * } + */ diff --git a/ports/darwin/guts/listxattr.c b/ports/darwin/guts/listxattr.c new file mode 100644 index 0000000..0bba451 --- /dev/null +++ b/ports/darwin/guts/listxattr.c @@ -0,0 +1,13 @@ +/* + * Copyright (c) 2011 Wind River Systems; see + * guts/COPYRIGHT for information. + * + * ssize_t listxattr(const char *pathname, char *list, size_t size, int options) + * ssize_t rc = -1; + */ + + rc = real_listxattr(pathname, list, size, options); + +/* return rc; + * } + */ diff --git a/ports/darwin/guts/lstat.c b/ports/darwin/guts/lstat.c new file mode 100644 index 0000000..01e0f30 --- /dev/null +++ b/ports/darwin/guts/lstat.c @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2011 Wind River Systems; see + * guts/COPYRIGHT for information. + * + * int lstat(const char *path, struct stat *buf) + * int rc = -1; + */ + + pseudo_msg_t *msg; + + rc = real_lstat(path, buf); + if (rc == -1) { + return rc; + } + + /* query database + * note that symlink canonicalizing is now automatic, so we + * don't need to check for a symlink on this end + */ + msg = pseudo_client_op(OP_STAT, 0, -1, -1, path, buf); + if (msg && msg->result == RESULT_SUCCEED) { + pseudo_stat_msg(buf, msg); + } + +/* return rc; + * } + */ diff --git a/ports/darwin/guts/open.c b/ports/darwin/guts/open.c new file mode 100644 index 0000000..64cb6ad --- /dev/null +++ b/ports/darwin/guts/open.c @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2011 Wind River Systems; see + * guts/COPYRIGHT for information. + * + * int open(const char *path, int flags, ... { int mode }) + * int rc = -1; + */ + + struct stat buf; + int existed = 1; + int save_errno; + + /* if a creation has been requested, check whether file exists */ + if (flags & O_CREAT) { + save_errno = errno; + rc = real_stat(path, &buf); + existed = (rc != -1); + if (!existed) + pseudo_debug(2, "open_creat: %s -> 0%o\n", path, mode); + errno = save_errno; + } + + /* because we are not actually root, secretly mask in 0700 to the + * underlying mode + */ + rc = real_open(path, flags, PSEUDO_FS_MODE(mode)); + save_errno = errno; + + if (rc != -1) { + int stat_rc; + stat_rc = real_stat(path, &buf); + + if (stat_rc != -1) { + buf.st_mode = PSEUDO_DB_MODE(buf.st_mode, mode); + if (!existed) { + pseudo_client_op(OP_CREAT, 0, -1, -1, path, &buf); + } + pseudo_client_op(OP_OPEN, PSEUDO_ACCESS(flags), rc, -1, path, &buf); + } else { + pseudo_debug(1, "open (fd %d, path %s, flags %d) succeeded, but stat failed (%s).\n", + rc, path, flags, strerror(errno)); + pseudo_client_op(OP_OPEN, PSEUDO_ACCESS(flags), rc, -1, path, 0); + } + errno = save_errno; + } + +/* return rc; + * } + */ diff --git a/ports/darwin/guts/scandir.c b/ports/darwin/guts/scandir.c new file mode 100644 index 0000000..6492b1b --- /dev/null +++ b/ports/darwin/guts/scandir.c @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2010 Wind River Systems; see + * guts/COPYRIGHT for information. + * + * static int + * wrap_scandir(const char *path, struct dirent ***namelist, int (*filter)(struct dirent *), int (*compar)(const void *, const void *)) { + * int rc = -1; + */ + + rc = real_scandir(path, namelist, filter, compar); + +/* return rc; + * } + */ diff --git a/ports/darwin/guts/setxattr.c b/ports/darwin/guts/setxattr.c new file mode 100644 index 0000000..3c8fd3d --- /dev/null +++ b/ports/darwin/guts/setxattr.c @@ -0,0 +1,13 @@ +/* + * Copyright (c) 2011 Wind River Systems; see + * guts/COPYRIGHT for information. + * + * int setxattr(const char *pathname, const char *name, const void *value, size_t size, u_int32_t position, int options) + * int rc = -1; + */ + + rc = real_setxattr(pathname, name, value, size, position, options); + +/* return rc; + * } + */ diff --git a/ports/darwin/guts/stat.c b/ports/darwin/guts/stat.c new file mode 100644 index 0000000..1e1cf67 --- /dev/null +++ b/ports/darwin/guts/stat.c @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2011 Wind River Systems; see + * guts/COPYRIGHT for information. + * + * int stat(const char *path, struct stat *buf) + * int rc = -1; + */ + + pseudo_msg_t *msg; + int save_errno; + + rc = real_stat(path, buf); + if (rc == -1) { + return rc; + } + save_errno = errno; + + /* query database + * note that symlink canonicalizing is now automatic, so we + * don't need to check for a symlink on this end + */ + msg = pseudo_client_op(OP_STAT, 0, -1, AT_FDCWD, path, buf); + if (msg) { + pseudo_stat_msg(buf, msg); + } + + errno = save_errno; + +/* return rc; + * } + */ |