Beispiel #1
0
        /// <summary>Linux specific implementation of <see cref="IO.GetFilePermissionsForFilePath"/> </summary>
        internal static int GetFilePermissionsForFilePath(string path, bool followSymlink)
        {
            var stat      = new stat_buf();
            int errorCode = StatFile(AT_FDCWD, path, followSymlink, ref stat);

            return(errorCode == 0 ? (int)stat.st_mode : ERROR);
        }
Beispiel #2
0
        private static bool IsSymlink(string path)
        {
            var buf = new stat_buf();

            return
                (fstatat(__Ver, AT_FDCWD, path, ref buf, AT_SYMLINK_NOFOLLOW) == 0 &&
                 (buf.st_mode & (ushort)FilePermissions.S_IFLNK) != 0);
        }
Beispiel #3
0
        private static int StatFile(int fd, string path, bool followSymlink, ref StatBuffer statBuf)
        {
            // using 'fstatat' instead of the newer 'statx' because Ubuntu 18.04 doesn't have iit
            var buf    = new stat_buf();
            int result = StatFile(fd, path, followSymlink, ref buf);

            if (result != 0)
            {
                return(ERROR);
            }
            else
            {
                Translate(buf, ref statBuf);
                return(0);
            }
        }
Beispiel #4
0
        /// <summary>
        /// pathname, dirfd, and flags to identify the target file in one of the following ways:
        ///
        /// An absolute pathname
        ///    If pathname begins with a slash, then it is an absolute pathname that identifies the target file.  In this
        ///    case, dirfd is ignored.
        ///
        /// A relative pathname
        ///    If pathname is a string that begins with a character other than a slash and dirfd is AT_FDCWD, then
        ///    pathname is a relative pathname that is interpreted relative to the process's current working directory.
        ///
        /// A directory-relative pathname
        ///    If  pathname  is  a  string that begins with a character other than a slash and dirfd is a file descriptor
        ///    that refers to a directory, then pathname is a relative pathname that is interpreted relative to the
        ///    directory referred to by dirfd.
        /// </summary>
        private static int StatFile(int dirfd, string pathname, bool followSymlink, ref stat_buf buf)
        {
            Contract.Requires(pathname != null);

            int flags = 0
                        | (!followSymlink                 ? AT_SYMLINK_NOFOLLOW : 0)
                        | (string.IsNullOrEmpty(pathname) ? AT_EMPTY_PATH : 0);

            int result;

            while (
                (result = fstatat(__Ver, dirfd, pathname, ref buf, flags)) < 0 &&
                Marshal.GetLastWin32Error() == (int)Errno.EINTR)
            {
                ;
            }
            return(result);
        }