From 46789e47c8ea3de00dea50813cc0c05b7873831c Mon Sep 17 00:00:00 2001 From: Enrico Scholz Date: Thu, 22 Jan 2004 13:29:48 +0000 Subject: [PATCH] * added additional 'mode' parameter to avoid an additional 'lstat' * operate on regular files and directories only git-svn-id: http://svn.linux-vserver.org/svn/util-vserver/trunk@679 94cd875c-1c1d-0410-91d2-eb244daf1a30 --- util-vserver/lib/fscompat_getiattr-fscompat.hc | 16 ++++++++++++---- util-vserver/lib/fscompat_setiattr-fscompat.hc | 11 ++++++++--- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/util-vserver/lib/fscompat_getiattr-fscompat.hc b/util-vserver/lib/fscompat_getiattr-fscompat.hc index 24417a7..24d026f 100644 --- a/util-vserver/lib/fscompat_getiattr-fscompat.hc +++ b/util-vserver/lib/fscompat_getiattr-fscompat.hc @@ -29,16 +29,24 @@ vc_get_iattr_compat_fscompat(char const *filename, dev_t dev, ino_t ino, xid_t * /*@null@*/ xid, uint32_t * /*@null@*/ flags, - uint32_t * mask) + uint32_t * mask, + mode_t const *mode) { - int fd = open(filename, O_RDONLY); struct stat st; int stat_rc; + int fd; int old_mask = *mask; - - if (fd==-1) return -1; + *mask = 0; + if (mode!=0) st.st_mode = *mode; + else if (lstat(filename, &st)==-1) return -1; + + if (!S_ISREG(st.st_mode) && !S_ISDIR(st.st_mode)) return 0; + + fd = open(filename, O_RDONLY); + if (fd==-1) return -1; + stat_rc = fstat(fd, &st); if (stat_rc==-1) goto err; diff --git a/util-vserver/lib/fscompat_setiattr-fscompat.hc b/util-vserver/lib/fscompat_setiattr-fscompat.hc index 7ffcb66..7772074 100644 --- a/util-vserver/lib/fscompat_setiattr-fscompat.hc +++ b/util-vserver/lib/fscompat_setiattr-fscompat.hc @@ -28,12 +28,17 @@ static inline ALWAYSINLINE int vc_set_iattr_compat_fscompat(char const *filename, dev_t dev, ino_t ino, xid_t xid, - uint32_t flags, uint32_t mask) + uint32_t flags, uint32_t mask, + mode_t const *mode) { - int fd = open(filename, O_RDONLY); + int fd; struct stat st; int stat_rc; - + + if (mode!=0) st.st_mode = *mode; + if (!S_ISREG(st.st_mode) && !S_ISDIR(st.st_mode)) return 0; + + fd = open(filename, O_RDONLY); if (fd==-1) return -1; stat_rc = fstat(fd, &st); -- 1.8.1.5