syscall_getiattr-fscompat.hc (2508B)
1 // $Id$ --*- c -*-- 2 3 // Copyright (C) 2004 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de> 4 // 5 // This program is free software; you can redistribute it and/or modify 6 // it under the terms of the GNU General Public License as published by 7 // the Free Software Foundation; version 2 of the License. 8 // 9 // This program is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with this program; if not, write to the Free Software 16 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 18 19 #ifdef HAVE_CONFIG_H 20 # include <config.h> 21 #endif 22 23 #include "ioctl-getext2flags.hc" 24 #include "ioctl-getfilecontext.hc" 25 #include "ioctl-getxflg.hc" 26 27 #include <fcntl.h> 28 #include <unistd.h> 29 #include <sys/stat.h> 30 31 static inline ALWAYSINLINE int 32 vc_get_iattr_fscompat(char const *filename, 33 xid_t * /*@null@*/ xid, 34 uint32_t * /*@null@*/ flags, 35 uint32_t * mask) 36 { 37 struct stat st; 38 int stat_rc; 39 int fd; 40 int old_mask = *mask; 41 42 *mask = 0; 43 44 if (lstat(filename, &st)==-1) return -1; 45 if (!S_ISREG(st.st_mode) && !S_ISDIR(st.st_mode)) return 0; 46 47 fd = open(filename, O_RDONLY|O_NONBLOCK); 48 if (fd==-1) return -1; 49 50 stat_rc = fstat(fd, &st); 51 if (stat_rc==-1) goto err; 52 53 if ( old_mask&VC_IATTR_XID ) { 54 *xid = vc_X_get_filecontext(fd); 55 if (*xid!=VC_NOCTX) *mask |= VC_IATTR_XID; 56 } 57 58 if ( old_mask&VC_IATTR_IUNLINK ) { 59 long tmp; 60 int rc = vc_X_get_ext2flags(fd, &tmp); 61 62 if (rc!=-1) { 63 *mask |= VC_IATTR_IUNLINK; 64 if (tmp & (VC_IMMUTABLE_FILE_FL|VC_IMMUTABLE_LINK_FL)) 65 *flags |= VC_IATTR_IUNLINK; 66 } 67 } 68 69 if ( (old_mask&VC_IATTR_BARRIER) && S_ISDIR(st.st_mode)) { 70 long ext2_flags; 71 72 *mask |= VC_IATTR_BARRIER; 73 if ((st.st_mode&0777)==0 && 74 vc_X_get_ext2flags(fd, &ext2_flags)!=-1 && 75 (ext2_flags & VC_IMMUTABLE_LINK_FL)) 76 *flags |= VC_IATTR_BARRIER; 77 } 78 79 if ( (old_mask&(VC_IATTR_WATCH|VC_IATTR_HIDE)) ){ 80 long tmp; 81 int rc = vc_X_get_xflg(fd, &tmp); 82 if (rc!=-1) { 83 *mask |= (VC_IATTR_WATCH|VC_IATTR_HIDE); 84 if (tmp&1) *flags |= VC_IATTR_HIDE; 85 if (tmp&2) *flags |= VC_IATTR_WATCH; 86 } 87 } 88 89 close(fd); 90 return 0; 91 err: 92 { 93 int old_errno = errno; 94 close(fd); 95 errno = old_errno; 96 return -1; 97 } 98 }