ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libeio/eio.c
(Generate patch)

Comparing libeio/eio.c (file contents):
Revision 1.142 by root, Sun May 1 17:15:45 2016 UTC vs.
Revision 1.144 by root, Tue Dec 27 09:58:44 2016 UTC

201 /* we could even stat and see if it exists */ 201 /* we could even stat and see if it exists */
202 static int 202 static int
203 symlink (const char *old, const char *neu) 203 symlink (const char *old, const char *neu)
204 { 204 {
205 #if WINVER >= 0x0600 205 #if WINVER >= 0x0600
206 int flags;
207
208 /* This tries out all combinations of SYMBOLIC_LINK_FLAG_DIRECTORY
209 * and SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE,
210 * with directory first.
211 */
212 for (flags = 3; flags >= 0; --flags)
206 if (CreateSymbolicLink (neu, old, 1)) 213 if (CreateSymbolicLink (neu, old, flags))
207 return 0; 214 return 0;
208
209 if (CreateSymbolicLink (neu, old, 0))
210 return 0;
211 #endif 215 #endif
212 216
213 return EIO_ERRNO (ENOENT, -1); 217 return EIO_ERRNO (ENOENT, -1);
214 } 218 }
215 219
312# define NAME_MAX 4096 316# define NAME_MAX 4096
313#endif 317#endif
314 318
315/* used for readlink etc. */ 319/* used for readlink etc. */
316#ifndef PATH_MAX 320#ifndef PATH_MAX
317# define PATH_MAX 4096 321# define PATH_MAX 0
318#endif 322#endif
323
324#ifndef EIO_PATH_MIN
325# define EIO_PATH_MIN 8160
326#endif
327
328#define EIO_PATH_MAX (PATH_MAX <= EIO_PATH_MIN ? EIO_PATH_MIN : PATH_MAX)
319 329
320/* buffer size for various temporary buffers */ 330/* buffer size for various temporary buffers */
321#define EIO_BUFSIZE 65536 331#define EIO_BUFSIZE 65536
322 332
323#define dBUF \ 333#define dBUF \
970 980
971 errno = ENOENT; 981 errno = ENOENT;
972 if (!*rel) 982 if (!*rel)
973 return -1; 983 return -1;
974 984
975 res = etp_tmpbuf_get (tmpbuf, PATH_MAX * 3); 985 res = etp_tmpbuf_get (tmpbuf, EIO_PATH_MAX * 3);
976#ifdef _WIN32 986#ifdef _WIN32
977 if (_access (rel, 4) != 0) 987 if (_access (rel, 4) != 0)
978 return -1; 988 return -1;
979 989
980 symlinks = GetFullPathName (rel, PATH_MAX * 3, res, 0); 990 symlinks = GetFullPathName (rel, EIO_PATH_MAX * 3, res, 0);
981 991
982 errno = ENAMETOOLONG; 992 errno = ENAMETOOLONG;
983 if (symlinks >= PATH_MAX * 3) 993 if (symlinks >= EIO_PATH_MAX * 3)
984 return -1; 994 return -1;
985 995
986 errno = EIO; 996 errno = EIO;
987 if (symlinks <= 0) 997 if (symlinks <= 0)
988 return -1; 998 return -1;
989 999
990 return symlinks; 1000 return symlinks;
991 1001
992#else 1002#else
993 tmp1 = res + PATH_MAX; 1003 tmp1 = res + EIO_PATH_MAX;
994 tmp2 = tmp1 + PATH_MAX; 1004 tmp2 = tmp1 + EIO_PATH_MAX;
995 1005
996#if 0 /* disabled, the musl way to do things is just too racy */ 1006#if 0 /* disabled, the musl way to do things is just too racy */
997#if __linux && defined(O_NONBLOCK) && defined(O_NOATIME) 1007#if __linux && defined(O_NONBLOCK) && defined(O_NOATIME)
998 /* on linux we may be able to ask the kernel */ 1008 /* on linux we may be able to ask the kernel */
999 { 1009 {
1000 int fd = open (rel, O_RDONLY | O_NONBLOCK | O_NOCTTY | O_NOATIME); 1010 int fd = open (rel, O_RDONLY | O_NONBLOCK | O_NOCTTY | O_NOATIME);
1001 1011
1002 if (fd >= 0) 1012 if (fd >= 0)
1003 { 1013 {
1004 sprintf (tmp1, "/proc/self/fd/%d", fd); 1014 sprintf (tmp1, "/proc/self/fd/%d", fd);
1005 req->result = readlink (tmp1, res, PATH_MAX); 1015 req->result = readlink (tmp1, res, EIO_PATH_MAX);
1006 /* here we should probably stat the open file and the disk file, to make sure they still match */ 1016 /* here we should probably stat the open file and the disk file, to make sure they still match */
1007 close (fd); 1017 close (fd);
1008 1018
1009 if (req->result > 0) 1019 if (req->result > 0)
1010 goto done; 1020 goto done;
1023 if (wd == EIO_INVALID_WD) 1033 if (wd == EIO_INVALID_WD)
1024 return -1; 1034 return -1;
1025 1035
1026 if (wd == EIO_CWD) 1036 if (wd == EIO_CWD)
1027 { 1037 {
1028 if (!getcwd (res, PATH_MAX)) 1038 if (!getcwd (res, EIO_PATH_MAX))
1029 return -1; 1039 return -1;
1030 1040
1031 len = strlen (res); 1041 len = strlen (res);
1032 } 1042 }
1033 else 1043 else
1080 1090
1081 /* zero-terminate, for readlink */ 1091 /* zero-terminate, for readlink */
1082 res [len + 1] = 0; 1092 res [len + 1] = 0;
1083 1093
1084 /* now check if it's a symlink */ 1094 /* now check if it's a symlink */
1085 linklen = readlink (tmpbuf->ptr, tmp1, PATH_MAX); 1095 linklen = readlink (tmpbuf->ptr, tmp1, EIO_PATH_MAX);
1086 1096
1087 if (linklen < 0) 1097 if (linklen < 0)
1088 { 1098 {
1089 if (errno != EINVAL) 1099 if (errno != EINVAL)
1090 return -1; 1100 return -1;
1096 { 1106 {
1097 /* yay, it was a symlink - build new path in tmp2 */ 1107 /* yay, it was a symlink - build new path in tmp2 */
1098 int rellen = strlen (rel); 1108 int rellen = strlen (rel);
1099 1109
1100 errno = ENAMETOOLONG; 1110 errno = ENAMETOOLONG;
1101 if (linklen + 1 + rellen >= PATH_MAX) 1111 if (linklen + 1 + rellen >= EIO_PATH_MAX) /* also catch linklen >= EIO_PATH_MAX */
1102 return -1; 1112 return -1;
1103 1113
1104 errno = ELOOP; 1114 errno = ELOOP;
1105 if (!--symlinks) 1115 if (!--symlinks)
1106 return -1; 1116 return -1;
1839 ? rename (req->wd->str, req->ptr2) 1849 ? rename (req->wd->str, req->ptr2)
1840 : renameat (dirfd, req->ptr1, WD2FD ((eio_wd)req->int3), req->ptr2); break; 1850 : renameat (dirfd, req->ptr1, WD2FD ((eio_wd)req->int3), req->ptr2); break;
1841 case EIO_LINK: req->result = linkat (dirfd, req->ptr1, WD2FD ((eio_wd)req->int3), req->ptr2, 0); break; 1851 case EIO_LINK: req->result = linkat (dirfd, req->ptr1, WD2FD ((eio_wd)req->int3), req->ptr2, 0); break;
1842 case EIO_SYMLINK: req->result = symlinkat (req->ptr1, dirfd, req->ptr2); break; 1852 case EIO_SYMLINK: req->result = symlinkat (req->ptr1, dirfd, req->ptr2); break;
1843 case EIO_MKNOD: req->result = mknodat (dirfd, req->ptr1, (mode_t)req->int2, (dev_t)req->offs); break; 1853 case EIO_MKNOD: req->result = mknodat (dirfd, req->ptr1, (mode_t)req->int2, (dev_t)req->offs); break;
1844 case EIO_READLINK: ALLOC (PATH_MAX);
1845 req->result = readlinkat (dirfd, req->ptr1, req->ptr2, PATH_MAX); break;
1846 case EIO_STATVFS: ALLOC (sizeof (EIO_STRUCT_STATVFS)); 1854 case EIO_STATVFS: ALLOC (sizeof (EIO_STRUCT_STATVFS));
1847 req->result = eio__statvfsat (dirfd, req->ptr1, (EIO_STRUCT_STATVFS *)req->ptr2); break; 1855 req->result = eio__statvfsat (dirfd, req->ptr1, (EIO_STRUCT_STATVFS *)req->ptr2); break;
1856 case EIO_READLINK: ALLOC (EIO_PATH_MAX);
1857 req->result = readlinkat (dirfd, req->ptr1, req->ptr2, EIO_PATH_MAX);
1858 if (req->result == EIO_PATH_MAX)
1859 {
1860 req->result = -1;
1861 errno = ENAMETOOLONG;
1862 }
1863 break;
1848 case EIO_UTIME: 1864 case EIO_UTIME:
1849 case EIO_FUTIME: 1865 case EIO_FUTIME:
1850 { 1866 {
1851 struct timespec ts[2]; 1867 struct timespec ts[2];
1852 struct timespec *times; 1868 struct timespec *times;
1885 case EIO_MKDIR: req->result = mkdir (path , (mode_t)req->int2); break; 1901 case EIO_MKDIR: req->result = mkdir (path , (mode_t)req->int2); break;
1886 case EIO_RENAME: req->result = rename (path , req->ptr2); break; 1902 case EIO_RENAME: req->result = rename (path , req->ptr2); break;
1887 case EIO_LINK: req->result = link (path , req->ptr2); break; 1903 case EIO_LINK: req->result = link (path , req->ptr2); break;
1888 case EIO_SYMLINK: req->result = symlink (path , req->ptr2); break; 1904 case EIO_SYMLINK: req->result = symlink (path , req->ptr2); break;
1889 case EIO_MKNOD: req->result = mknod (path , (mode_t)req->int2, (dev_t)req->offs); break; 1905 case EIO_MKNOD: req->result = mknod (path , (mode_t)req->int2, (dev_t)req->offs); break;
1890 case EIO_READLINK: ALLOC (PATH_MAX);
1891 req->result = readlink (path, req->ptr2, PATH_MAX); break;
1892 case EIO_STATVFS: ALLOC (sizeof (EIO_STRUCT_STATVFS)); 1906 case EIO_STATVFS: ALLOC (sizeof (EIO_STRUCT_STATVFS));
1893 req->result = statvfs (path , (EIO_STRUCT_STATVFS *)req->ptr2); break; 1907 req->result = statvfs (path , (EIO_STRUCT_STATVFS *)req->ptr2); break;
1908 case EIO_READLINK: ALLOC (EIO_PATH_MAX);
1909 req->result = readlink (path, req->ptr2, EIO_PATH_MAX);
1910 if (req->result == EIO_PATH_MAX)
1911 {
1912 req->result = -1;
1913 errno = ENAMETOOLONG;
1914 }
1915 break;
1894 1916
1895 case EIO_UTIME: 1917 case EIO_UTIME:
1896 case EIO_FUTIME: 1918 case EIO_FUTIME:
1897 { 1919 {
1898 struct timeval tv[2]; 1920 struct timeval tv[2];

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines