Thread: [Libsysio-commit] HEAD: libsysio/src chdir.c
Brought to you by:
lward
From: Lee W. <lw...@us...> - 2003-10-15 19:25:28
|
Update of /cvsroot/libsysio/libsysio/src In directory sc8-pr-cvs1:/tmp/cvs-serv24739/src Modified Files: chdir.c Log Message: Grrr... Here again! The recent changes to the mount interconnection exposed the name of the covering path-node. The name of this node was being delivered by _sysio_p_path inappropriately. Instead, the _sysio_p_path routine must dive down to the bottom-most, covered, path node for the component name. Index: chdir.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/chdir.c,v retrieving revision 1.7 retrieving revision 1.8 diff -u -w -b -B -p -r1.7 -r1.8 --- chdir.c 6 Oct 2003 21:19:31 -0000 1.7 +++ chdir.c 15 Oct 2003 19:21:37 -0000 1.8 @@ -164,6 +164,14 @@ _sysio_p_path(struct pnode *pno, char ** n = 0; do { /* + * If this is a covering path-node then the name should be + * the *covered* nodes name, not this one unless we are at + * the root of the name-space. + */ + while (pno == pno->p_mount->mnt_root && pno != pno->p_parent ) + pno = pno->p_mount->mnt_covers; + + /* * Add length of this component to running sum and * account for this vertex. */ @@ -196,6 +204,14 @@ _sysio_p_path(struct pnode *pno, char ** cp = *buf + len + n; *cp = '\0'; /* NUL terminate */ do { + /* + * If this is a covering path-node then the name should be + * the *covered* nodes name, not this one unless we are at + * the root of the name-space. + */ + while (pno == pno->p_mount->mnt_root && pno != pno->p_parent ) + pno = pno->p_mount->mnt_covers; + /* * Add component and separator. */ |
From: Lee W. <lw...@us...> - 2003-10-24 18:00:46
|
Update of /cvsroot/libsysio/libsysio/src In directory sc8-pr-cvs1:/tmp/cvs-serv27145 Modified Files: chdir.c Log Message: It's a bad idea to return -EFAULT from a function that returns pointers. Now set errno to EFAULT and return NULL in getwd(). Index: chdir.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/chdir.c,v retrieving revision 1.8 retrieving revision 1.9 diff -u -w -b -B -p -r1.8 -r1.9 --- chdir.c 15 Oct 2003 19:21:37 -0000 1.8 +++ chdir.c 24 Oct 2003 17:59:18 -0000 1.9 @@ -248,8 +248,10 @@ char * getwd(char *buf) { - if (!buf) - return -EFAULT; + if (!buf) { + errno = EFAULT; + return NULL; + } return getcwd(buf, PATH_MAX); } |
From: jaschut <ja...@us...> - 2003-10-27 23:43:12
|
Update of /cvsroot/libsysio/libsysio/src In directory sc8-pr-cvs1:/tmp/cvs-serv19199 Modified Files: chdir.c Log Message: Remove the inop_getattr() call, which is redundant since _sysio_p_validate() should be checking the inode mode bits, and we can use them to test if the node is a directory. Index: chdir.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/chdir.c,v retrieving revision 1.9 retrieving revision 1.10 diff -u -w -b -B -p -r1.9 -r1.10 --- chdir.c 24 Oct 2003 17:59:18 -0000 1.9 +++ chdir.c 27 Oct 2003 23:42:29 -0000 1.10 @@ -89,28 +89,17 @@ int _sysio_p_chdir(struct pnode *pno) { int err; - struct intnl_stat stbuf; /* - * Revalidate + * Revalidate the pnode, and ensure it's a directory */ err = _sysio_p_validate(pno, NULL, NULL); if (err) return err; - if (!pno->p_base->pb_ino) - return -ENOTDIR; - /* - * Stat the node and ensure it's a directory. - */ - err = - pno->p_base->pb_ino->i_ops.inop_getattr(pno, - NULL, - &stbuf); - if (err) - return err; - if (!S_ISDIR(stbuf.st_mode)) - return -ENOTDIR; + if (!(pno->p_base->pb_ino && + S_ISDIR(pno->p_base->pb_ino->i_mode))) + return -ENOTDIR; /* * Release old if set. */ |
From: Lee W. <lw...@us...> - 2004-02-08 21:40:33
|
Update of /cvsroot/libsysio/libsysio/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19216 Modified Files: chdir.c Log Message: The chdir() function was not setting errno when errors occurred. Fixed. Index: chdir.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/chdir.c,v retrieving revision 1.12 retrieving revision 1.13 diff -u -w -b -B -p -r1.12 -r1.13 --- chdir.c 26 Jan 2004 16:34:54 -0000 1.12 +++ chdir.c 8 Feb 2004 21:37:26 -0000 1.13 @@ -128,8 +128,14 @@ chdir(const char *path) } err = _sysio_p_chdir(pno); + if (err) + P_RELE(pno); SYSIO_LEAVE; + if (err) { + errno = -err; + err = -1; + } return err; } |
From: Lee W. <lw...@us...> - 2004-08-26 09:02:37
|
Update of /cvsroot/libsysio/libsysio/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20538 Modified Files: chdir.c Log Message: Fixed error return for zero length buffer specification. Now returns EINVAL as it should. Index: chdir.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/chdir.c,v retrieving revision 1.19 retrieving revision 1.20 diff -u -w -b -B -p -r1.19 -r1.20 --- chdir.c 27 Jul 2004 15:00:43 -0000 1.19 +++ chdir.c 26 Aug 2004 09:02:28 -0000 1.20 @@ -154,6 +154,9 @@ _sysio_p_path(struct pnode *pno, char ** cur = pno; + if (!size) + return -EINVAL; + /* * Walk up the tree to the root, summing the component name * lengths and counting the vertices. |
From: Lee W. <lw...@us...> - 2004-09-16 14:41:41
|
Update of /cvsroot/libsysio/libsysio/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13425/src Modified Files: chdir.c Log Message: Henry Pierce noticed that the Linux-ish support for getcwd with a zero buffer size was gone. This had been done to make it POSIX compatible. However, we went overboard. It only must be applied when the passed buffer is non-null. The feature returns with this deposit. Index: chdir.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/chdir.c,v retrieving revision 1.20 retrieving revision 1.21 diff -u -w -b -B -p -r1.20 -r1.21 --- chdir.c 26 Aug 2004 09:02:28 -0000 1.20 +++ chdir.c 16 Sep 2004 14:41:32 -0000 1.21 @@ -154,7 +154,7 @@ _sysio_p_path(struct pnode *pno, char ** cur = pno; - if (!size) + if (!size && buf && *buf) return -EINVAL; /* |
From: Lee W. <lw...@us...> - 2007-03-23 23:50:45
|
Update of /cvsroot/libsysio/libsysio/src In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv9103/src Modified Files: chdir.c Log Message: BUG: The last component of the path argument to chdir() was not being checked. Fixed now. Index: chdir.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/chdir.c,v retrieving revision 1.25 retrieving revision 1.26 diff -u -w -b -B -p -r1.25 -r1.26 --- chdir.c 3 May 2006 22:34:46 -0000 1.25 +++ chdir.c 23 Mar 2007 23:50:37 -0000 1.26 @@ -102,6 +102,8 @@ _sysio_p_chdir(struct pnode *pno) if (!(pno->p_base->pb_ino && S_ISDIR(pno->p_base->pb_ino->i_stbuf.st_mode))) return -ENOTDIR; + if (!_sysio_permitted(pno, X_OK)) + return -EACCES; /* * Release old if set. |
From: Ruth K. <rk...@us...> - 2007-03-26 18:35:53
|
Update of /cvsroot/libsysio/libsysio/src In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv32194 Modified Files: chdir.c Log Message: correct return code check and pass up to higher levels Index: chdir.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/chdir.c,v retrieving revision 1.26 retrieving revision 1.27 diff -u -w -b -B -p -r1.26 -r1.27 --- chdir.c 23 Mar 2007 23:50:37 -0000 1.26 +++ chdir.c 26 Mar 2007 18:35:50 -0000 1.27 @@ -102,8 +102,8 @@ _sysio_p_chdir(struct pnode *pno) if (!(pno->p_base->pb_ino && S_ISDIR(pno->p_base->pb_ino->i_stbuf.st_mode))) return -ENOTDIR; - if (!_sysio_permitted(pno, X_OK)) - return -EACCES; + if ((err = _sysio_permitted(pno, X_OK)) != 0) + return err; /* * Release old if set. |
From: Lee W. <lw...@us...> - 2008-04-14 23:22:51
|
Update of /cvsroot/libsysio/libsysio/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32572 Modified Files: chdir.c Log Message: The routine _sysio_p_path has moved to inode.c for general use by others. Index: chdir.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/chdir.c,v retrieving revision 1.31 retrieving revision 1.32 diff -u -w -b -B -p -r1.31 -r1.32 --- chdir.c 21 Sep 2007 19:41:37 -0000 1.31 +++ chdir.c 14 Apr 2008 23:22:47 -0000 1.32 @@ -143,100 +143,6 @@ sysio_sym_weak_alias(SYSIO_INTERFACE_NAM PREPEND(__, SYSIO_INTERFACE_NAME(chdir))) #endif -/* - * Return path tracked by the path ancestor chain. - * - * If the buf pointer is NULL, a buffer large enough to hold the path - * is allocated from the heap. - */ - -static int -_sysio_p_path(struct pnode *pno, char **buf, size_t size) -{ - struct pnode *cur; - size_t len; - size_t n; - char *cp; - - cur = pno; - - if (!size && buf && *buf) - return -EINVAL; - - /* - * Walk up the tree to the root, summing the component name - * lengths and counting the vertices. - */ - len = 0; - n = 0; - do { - /* - * If this is a covering path-node then the name should be - * the *covered* nodes name, not this one unless we are at - * the root of the name-space. - */ - while (pno == pno->p_mount->mnt_root && - pno != pno->p_parent) - pno = pno->p_mount->mnt_covers; - - /* - * Add length of this component to running sum and - * account for this vertex. - */ - assert((len >= pno->p_base->pb_key.pbk_name.len && - (size_t )~0 - pno->p_base->pb_key.pbk_name.len > len) || - (size_t )~0 - len > pno->p_base->pb_key.pbk_name.len); - len += pno->p_base->pb_key.pbk_name.len; - n++; - assert(n); - pno = pno->p_parent; - } while (pno && pno != pno->p_parent); - if (!pno) - return -ENOENT; - - if (!*buf) - size = len + n + 1; - if (len >= size || n >= size - len) - return -ERANGE; - if (!*buf) { - /* - * Allocate path buffer from the heap. - */ - *buf = malloc(size * sizeof(char)); - if (!*buf) - return -ENOMEM; - } - - /* - * Fill in the path buffer. - */ - pno = cur; - cp = *buf + len + n; - *cp = '\0'; /* NUL terminate */ - do { - /* - * If this is a covering path-node then the name should be - * the *covered* nodes name, not this one unless we are at - * the root of the name-space. - */ - while (pno == pno->p_mount->mnt_root && - pno != pno->p_parent ) - pno = pno->p_mount->mnt_covers; - - /* - * Add component and separator. - */ - cp -= pno->p_base->pb_key.pbk_name.len; - (void )memcpy(cp, pno->p_base->pb_key.pbk_name.name, - pno->p_base->pb_key.pbk_name.len); - - *--cp = PATH_SEPARATOR; - pno = pno->p_parent; - } while (pno != pno->p_parent); - - return 0; -} - char * SYSIO_INTERFACE_NAME(getcwd)(char *buf, size_t size) { |