Changeset 9016
- Timestamp:
- 08/19/11 13:24:28 (21 months ago)
- Location:
- branches/Orange-Branch/src/client/usrint
- Files:
-
- 13 modified
-
Makefile (modified) (1 diff)
-
iocommon.c (modified) (32 diffs)
-
iocommon.h (modified) (4 diffs)
-
openfile-util.c (modified) (25 diffs)
-
openfile-util.h (modified) (2 diffs)
-
posix-ops.h (modified) (3 diffs)
-
posix-pvfs.c (modified) (22 diffs)
-
posix-pvfs.h (modified) (2 diffs)
-
posix.c (modified) (63 diffs)
-
request.c (modified) (2 diffs)
-
socket.c (modified) (19 diffs)
-
stdio.c (modified) (72 diffs)
-
usrint.h (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/Orange-Branch/src/client/usrint/Makefile
r8957 r9016 4 4 LIBDIR= 5 5 6 CFLAGS=-g -O0 $(INCDIR) $(LIBDIR) 6 #CFLAGS=-g -O0 $(INCDIR) $(LIBDIR) -Wall -Wstrict-prototypes -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE 7 CFLAGS=-g -O0 $(INCDIR) $(LIBDIR) -Wall -Wstrict-prototypes -D_LARGEFILE64_SOURCE 7 8 8 OBJS=iocommon.o openfile-util.o posix-pvfs.o posix.o stdio.o request.o socket.o 9 OBJS=iocommon.o openfile-util.o posix-pvfs.o posix.o stdio.o request.o socket.o shim.o 9 10 10 INCS=usrint.h iocommon.h posix-pvfs.h openfile-util.h posix-ops.h 11 INCS=usrint.h iocommon.h posix-pvfs.h openfile-util.h posix-ops.h stdio-ops.h 11 12 12 13 all: $(OBJS) -
branches/Orange-Branch/src/client/usrint/iocommon.c
r8975 r9016 10 10 * PVFS2 user interface routines - low level calls to system interface 11 11 */ 12 #include <usrint.h>12 #include "usrint.h" 13 13 #include <linux/dirent.h> 14 #include <posix-ops.h>15 #include <openfile-util.h>16 #include <iocommon.h>14 #include "posix-ops.h" 15 #include "openfile-util.h" 16 #include "iocommon.h" 17 17 18 18 /* Functions in this file generally define a label errorout … … 89 89 90 90 pvfs_sys_init(); 91 if (!pd || pd->is_in_use != PVFS_FS) 92 { 93 errno = EBADF; 94 return -1; 95 } 91 96 iocommon_cred(&credentials); 92 97 rc = PVFS_sys_flush(pd->pvfs_ref, credentials, PVFS_HINT_NULL); … … 314 319 if (dist) 315 320 { 316 P INT_dist_free(dist);321 PVFS_sys_dist_free(dist); 317 322 } 318 323 return rc; … … 338 343 PVFS_object_ref file_ref; 339 344 PVFS_object_ref parent_ref; 340 int fs_id = 0;341 345 pvfs_descriptor *pd = NULL; /* invalid pd until file is opened */ 342 346 PVFS_sysresp_getattr attributes_resp; … … 416 420 rc = (*glibc_ops.open)(error_path, flags & 01777777, mode); 417 421 IOCOMMON_RETURN_ERR(rc); 418 pd = pvfs_alloc_descriptor(&pvfs_ops );422 pd = pvfs_alloc_descriptor(&pvfs_ops, -1); 419 423 pd->is_in_use = PVFS_FS; /* indicate fd is valid! */ 420 424 pd->true_fd = rc; … … 463 467 /* Set the file information */ 464 468 /* create fd object */ 465 pd = pvfs_alloc_descriptor(&pvfs_ops); 469 pd = pvfs_alloc_descriptor(&pvfs_ops, -1); 470 if (!pd) 471 { 472 rc = -1; 473 goto errorout; 474 } 466 475 pd->pvfs_ref = file_ref; 467 476 pd->flags = flags; /* open flags */ … … 565 574 int orig_errno = errno; 566 575 576 if (!pd || pd->is_in_use != PVFS_FS) 577 { 578 errno = EBADF; 579 return -1; 580 } 567 581 switch(whence) 568 582 { … … 838 852 PVFS_sysresp_io io_resp; 839 853 854 if (!pd || pd->is_in_use != PVFS_FS) 855 { 856 errno = EBADF; 857 return -1; 858 } 840 859 /* Initialize */ 841 860 memset(&io_resp, 0, sizeof(io_resp)); 842 861 843 if (!pd)844 {845 errno = EBADF;846 return -1;847 }848 849 862 //Ensure descriptor is used for the correct type of access 850 if ( which==PVFS_IO_READ && (O_WRONLY == (pd->flags & O_ACCMODE)) ||851 which==PVFS_IO_WRITE && (O_RDONLY == (pd->flags & O_ACCMODE)))863 if ((which==PVFS_IO_READ && (O_WRONLY == (pd->flags & O_ACCMODE))) || 864 (which==PVFS_IO_WRITE && (O_RDONLY == (pd->flags & O_ACCMODE)))) 852 865 { 853 866 errno = EBADF; … … 898 911 PVFS_size req_size; 899 912 913 if (!pd || pd->is_in_use != PVFS_FS) 914 { 915 errno = EBADF; 916 return -1; 917 } 900 918 //Ensure descriptor is used for the correct type of access 901 if ( which==PVFS_IO_READ && (O_WRONLY == (pd->flags & O_ACCMODE)) ||902 which==PVFS_IO_WRITE && (O_RDONLY == (pd->flags & O_ACCMODE)))919 if ((which==PVFS_IO_READ && (O_WRONLY == (pd->flags & O_ACCMODE))) || 920 (which==PVFS_IO_WRITE && (O_RDONLY == (pd->flags & O_ACCMODE)))) 903 921 { 904 922 errno = EBADF; … … 988 1006 PVFS_sys_attr attr; 989 1007 1008 if (!pd || pd->is_in_use != PVFS_FS) 1009 { 1010 errno = EBADF; 1011 return -1; 1012 } 990 1013 /* Initialize */ 991 1014 memset(&attr, 0, sizeof(attr)); … … 1032 1055 { 1033 1056 int rc = 0; 1034 int orig_errno = errno;1035 1057 PVFS_sys_attr attr; 1036 1058 1059 if (!pd || pd->is_in_use != PVFS_FS) 1060 { 1061 errno = EBADF; 1062 return -1; 1063 } 1037 1064 /* Initialize */ 1038 1065 memset(&attr, 0, sizeof(attr)); … … 1075 1102 { 1076 1103 int rc = 0; 1077 int orig_errno = errno;1078 1104 PVFS_sys_attr attr; 1079 1105 1106 if (!pd || pd->is_in_use != PVFS_FS) 1107 { 1108 errno = EBADF; 1109 return -1; 1110 } 1080 1111 /* Initialize */ 1081 1112 memset(&attr, 0, sizeof(attr)); … … 1099 1130 { 1100 1131 int rc = 0; 1101 int orig_errno = errno;1102 1132 PVFS_sys_attr attr; 1103 1133 1134 if (!pd || pd->is_in_use != PVFS_FS) 1135 { 1136 errno = EBADF; 1137 return -1; 1138 } 1104 1139 /* Initialize */ 1105 1140 memset(&attr, 0, sizeof(attr)); … … 1112 1147 } 1113 1148 1114 i ocommon_make_directory(const char *pvfs_path,1149 int iocommon_make_directory(const char *pvfs_path, 1115 1150 const int mode, 1116 1151 PVFS_object_ref *pdir) … … 1187 1222 int iocommon_readlink(pvfs_descriptor *pd, char *buf, int size) 1188 1223 { 1189 int rc = 0; 1190 int orig_errno = errno; 1191 PVFS_sys_attr attr; 1192 1224 int rc = 0; 1225 PVFS_sys_attr attr; 1226 1227 if (!pd || pd->is_in_use != PVFS_FS) 1228 { 1229 errno = EBADF; 1230 return -1; 1231 } 1193 1232 /* Initialize any variables */ 1194 1233 memset(&attr, 0, sizeof(attr)); … … 1299 1338 int bytes = 0, i = 0; 1300 1339 1340 if (!pd || pd->is_in_use != PVFS_FS) 1341 { 1342 errno = EBADF; 1343 return -1; 1344 } 1301 1345 if (pd->token == PVFS_READDIR_END) 1302 1346 { … … 1357 1401 int bytes = 0, i = 0; 1358 1402 1403 if (!pd || pd->is_in_use != PVFS_FS) 1404 { 1405 errno = EBADF; 1406 return -1; 1407 } 1359 1408 if (pd->token == PVFS_READDIR_END) 1360 1409 { … … 1563 1612 PVFS_sysresp_statfs statfs_resp; 1564 1613 1614 if (!pd || pd->is_in_use != PVFS_FS) 1615 { 1616 errno = EBADF; 1617 return -1; 1618 } 1565 1619 /* Initialize the system interface for this process */ 1566 1620 pvfs_sys_init(); … … 1598 1652 PVFS_sysresp_statfs statfs_resp; 1599 1653 1654 if (!pd || pd->is_in_use != PVFS_FS) 1655 { 1656 errno = EBADF; 1657 return -1; 1658 } 1600 1659 /* Initialize the system interface for this process */ 1601 1660 pvfs_sys_init(); … … 1626 1685 1627 1686 int iocommon_sendfile(int sockfd, pvfs_descriptor *pd, 1628 off64_t offset, size_t count) 1629 { 1630 int rc = 0, bytes_read; 1631 int orig_errno = errno; 1687 off64_t *offset, size_t count) 1688 { 1689 int rc = 0, bytes_read = 0; 1632 1690 PVFS_Request mem_req, file_req; 1633 PVFS_credentials *credentials;1634 1691 char *buffer; 1635 int buffer_size; 1636 1692 int buffer_size = (8*1024*1024); 1693 1694 if (!pd || pd->is_in_use != PVFS_FS) 1695 { 1696 errno = EBADF; 1697 return -1; 1698 } 1637 1699 buffer = (char *)malloc(buffer_size); 1638 1700 … … 1640 1702 file_req = PVFS_BYTE; 1641 1703 1642 rc = iocommon_readorwrite(PVFS_IO_READ, pd, offset + bytes_read,1704 rc = iocommon_readorwrite(PVFS_IO_READ, pd, *offset + bytes_read, 1643 1705 buffer, mem_req, file_req); 1644 1706 while(rc > 0) … … 1655 1717 break; 1656 1718 } 1657 rc = iocommon_readorwrite(PVFS_IO_READ, pd, offset + bytes_read,1719 rc = iocommon_readorwrite(PVFS_IO_READ, pd, *offset + bytes_read, 1658 1720 buffer, mem_req, file_req); 1659 1721 } … … 1666 1728 else 1667 1729 { 1730 *offset += bytes_read; 1668 1731 return bytes_read; 1669 1732 } … … 1677 1740 */ 1678 1741 int iocommon_geteattr(pvfs_descriptor *pd, 1679 c har *key_p,1742 const char *key_p, 1680 1743 void *val_p, 1681 1744 int size) … … 1686 1749 PVFS_ds_keyval key, val; 1687 1750 1751 if (!pd || pd->is_in_use != PVFS_FS) 1752 { 1753 errno = EBADF; 1754 return -1; 1755 } 1688 1756 /* Initialize */ 1689 1757 memset(&key, 0, sizeof(key)); … … 1693 1761 iocommon_cred(&credentials); 1694 1762 1695 key.buffer = key_p;1763 key.buffer = (char *)key_p; 1696 1764 key.buffer_sz = strlen(key_p) + 1; 1697 1765 val.buffer = val_p; … … 1721 1789 */ 1722 1790 int iocommon_seteattr(pvfs_descriptor *pd, 1723 c har *key_p,1724 void *val_p,1791 const char *key_p, 1792 const void *val_p, 1725 1793 int size, 1726 1794 int flag) … … 1732 1800 PVFS_ds_keyval key, val; 1733 1801 1802 if (!pd || pd->is_in_use != PVFS_FS) 1803 { 1804 errno = EBADF; 1805 return -1; 1806 } 1734 1807 /* Initialize */ 1735 1808 memset(&key, 0, sizeof(key)); … … 1739 1812 iocommon_cred(&credentials); 1740 1813 1741 key.buffer = key_p;1814 key.buffer = (char *)key_p; 1742 1815 key.buffer_sz = strlen(key_p) + 1; 1743 val.buffer = val_p;1816 val.buffer = (void *)val_p; 1744 1817 val.buffer_sz = size; 1745 1818 … … 1773 1846 */ 1774 1847 int iocommon_deleattr(pvfs_descriptor *pd, 1775 char *key_p) 1776 { 1777 int rc = 0; 1778 int pvfs_flag = 0; 1848 const char *key_p) 1849 { 1850 int rc = 0; 1779 1851 int orig_errno = errno; 1780 1852 PVFS_credentials *credentials; 1781 1853 PVFS_ds_keyval key; 1782 1854 1855 if (!pd || pd->is_in_use != PVFS_FS) 1856 { 1857 errno = EBADF; 1858 return -1; 1859 } 1783 1860 /* Initialize */ 1784 1861 memset(&key, 0, sizeof(key)); … … 1787 1864 iocommon_cred(&credentials); 1788 1865 1789 key.buffer = key_p;1866 key.buffer = (char *)key_p; 1790 1867 key.buffer_sz = strlen(key_p) + 1; 1791 1868 … … 1824 1901 PVFS_sysresp_listeattr listeattr_resp; 1825 1902 1903 if (!pd || pd->is_in_use != PVFS_FS) 1904 { 1905 errno = EBADF; 1906 return -1; 1907 } 1826 1908 /* Initialize */ 1827 1909 memset(&listeattr_resp, 0, sizeof(listeattr_resp)); -
branches/Orange-Branch/src/client/usrint/iocommon.h
r8975 r9016 38 38 39 39 /* Perform PVFS initialization if not already finished */ 40 void iocommon_ensure_init( );40 void iocommon_ensure_init(void); 41 41 42 42 void iocommon_cred(PVFS_credentials **credentials); … … 145 145 int iocommon_stat64(pvfs_descriptor *pd, struct stat64 *buf, uint32_t mask); 146 146 147 int iocommon_statfs(pvfs_descriptor *pd, struct statfs *buf); 148 149 int iocommon_statfs64(pvfs_descriptor *pd, struct statfs64 *buf); 150 151 int iocommon_seteattr(pvfs_descriptor *pd, const char *key, const void *val, int size, int flag); 152 153 int iocommon_geteattr(pvfs_descriptor *pd, const char *key, void *val, int size); 154 155 int iocommon_listeattr(pvfs_descriptor *pd, char *list, int size, int *numkeys); 156 157 int iocommon_deleattr(pvfs_descriptor *pd, const char * key); 158 147 159 int iocommon_chown(pvfs_descriptor *pd, uid_t owner, gid_t group); 148 160 … … 163 175 unsigned int count); 164 176 177 int iocommon_getdents64(pvfs_descriptor *pd, 178 struct dirent64 *dirp, 179 unsigned int count); 180 165 181 int iocommon_access(const char *pvfs_path, 166 182 int mode, … … 168 184 PVFS_object_ref *pdir); 169 185 186 int iocommon_sendfile(int sockfd, 187 pvfs_descriptor *pd, 188 off64_t *offset, 189 size_t count); 170 190 /* 171 191 * Local variables: -
branches/Orange-Branch/src/client/usrint/openfile-util.c
r8975 r9016 12 12 #include <usrint.h> 13 13 #include <linux/dirent.h> 14 #include <sys/syscall.h> 14 15 #include <posix-ops.h> 15 16 #include <openfile-util.h> 17 #include <posix-pvfs.h> 18 19 static struct glibc_redirect_s 20 { 21 int (*stat)(int ver, const char *path, struct stat *buf); 22 int (*stat64)(int ver, const char *path, struct stat64 *buf); 23 int (*fstat)(int ver, int fd, struct stat *buf); 24 int (*fstat64)(int ver, int fd, struct stat64 *buf); 25 int (*fstatat)(int ver, int fd, const char *path, struct stat *buf, int flag); 26 int (*fstatat64)(int ver, int fd, const char *path, struct stat64 *buf, int flag); 27 int (*lstat)(int ver, const char *path, struct stat *buf); 28 int (*lstat64)(int ver, const char *path, struct stat64 *buf); 29 int (*mknod)(int ver, const char *path, mode_t mode, dev_t dev); 30 int (*mknodat)(int ver, int dirfd, const char *path, mode_t mode, dev_t dev); 31 } glibc_redirect; 16 32 17 33 #define PREALLOC 3 34 static char logfilepath[25]; 35 static int logfile; 36 static int pvfs_initializing_flag = 0; 18 37 static int descriptor_table_count = 0; 19 38 static int descriptor_table_size = 0; 20 static int next_descriptor = 0;21 39 static pvfs_descriptor **descriptor_table; 22 40 static char rstate[256]; /* used for random number generation */ … … 68 86 .is_in_use = PVFS_FS 69 87 }; 88 89 static int my_glibc_stat(const char *path, struct stat *buf) 90 { 91 return glibc_redirect.stat(3, path, buf); 92 } 93 94 static int my_glibc_stat64(const char *path, struct stat64 *buf) 95 { 96 return glibc_redirect.stat64(3, path, buf); 97 } 98 99 static int my_glibc_fstat(int fd, struct stat *buf) 100 { 101 return glibc_redirect.fstat(3, fd, buf); 102 } 103 104 static int my_glibc_fstat64(int fd, struct stat64 *buf) 105 { 106 return glibc_redirect.fstat64(3, fd, buf); 107 } 108 109 static int my_glibc_fstatat(int fd, const char *path, struct stat *buf, int flag) 110 { 111 return glibc_redirect.fstatat(3, fd, path, buf, flag); 112 } 113 114 static int my_glibc_fstatat64(int fd, const char *path, struct stat64 *buf, int flag) 115 { 116 return glibc_redirect.fstatat64(3, fd, path, buf, flag); 117 } 118 119 static int my_glibc_lstat(const char *path, struct stat *buf) 120 { 121 return glibc_redirect.lstat(3, path, buf); 122 } 123 124 static int my_glibc_lstat64(const char *path, struct stat64 *buf) 125 { 126 return glibc_redirect.lstat64(3, path, buf); 127 } 128 129 static int my_glibc_mknod(const char *path, mode_t mode, dev_t dev) 130 { 131 return glibc_redirect.mknod(1, path, mode, dev); 132 } 133 134 static int my_glibc_mknodat(int dirfd, const char *path, mode_t mode, dev_t dev) 135 { 136 return glibc_redirect.mknodat(1, dirfd, path, mode, dev); 137 } 138 139 static int my_glibc_getdents(u_int fd, struct dirent *dirp, u_int count) 140 { 141 return syscall(SYS_getdents, fd, dirp, count); 142 } 143 144 static int my_glibc_getdents64(u_int fd, struct dirent64 *dirp, u_int count) 145 { 146 return syscall(SYS_getdents64, fd, dirp, count); 147 } 148 149 static int my_glibc_fadvise64(int fd, off64_t offset, off64_t len, int advice) 150 { 151 return syscall(SYS_fadvise64, fd, offset, len, advice); 152 } 153 154 static int my_glibc_fadvise(int fd, off_t offset, off_t len, int advice) 155 { 156 return my_glibc_fadvise64(fd, (off64_t)offset, (off64_t)len, advice); 157 } 158 159 static int my_glibc_flush(int fd) 160 { 161 errno = ENOSYS; 162 return -1; 163 } 164 165 static int my_glibc_readdir(u_int fd, struct dirent *dirp, u_int count) 166 { 167 return syscall(SYS_readdir, fd, dirp, count); 168 } 70 169 71 170 void load_glibc(void) … … 97 196 glibc_ops.fallocate = dlsym(RTLD_NEXT, "posix_fallocate"); 98 197 glibc_ops.close = dlsym(RTLD_NEXT, "close"); 99 glibc_ops.flush = dlsym(RTLD_NEXT, "flush"); 100 glibc_ops.stat = dlsym(RTLD_NEXT, "stat"); 101 glibc_ops.stat64 = dlsym(RTLD_NEXT, "stat64"); 102 glibc_ops.fstat = dlsym(RTLD_NEXT, "fstat"); 103 glibc_ops.fstat64 = dlsym(RTLD_NEXT, "fstat64"); 104 glibc_ops.fstatat = dlsym(RTLD_NEXT, "fstatat"); 105 glibc_ops.fstatat64 = dlsym(RTLD_NEXT, "fstatat64"); 106 glibc_ops.lstat = dlsym(RTLD_NEXT, "lstat"); 107 glibc_ops.lstat64 = dlsym(RTLD_NEXT, "lstat64"); 198 glibc_ops.flush = my_glibc_flush; 199 glibc_ops.stat = my_glibc_stat; 200 glibc_redirect.stat = dlsym(RTLD_NEXT, "__xstat"); 201 glibc_ops.stat64 = my_glibc_stat64; 202 glibc_redirect.stat64 = dlsym(RTLD_NEXT, "__xstat64"); 203 glibc_ops.fstat = my_glibc_fstat; 204 glibc_redirect.fstat = dlsym(RTLD_NEXT, "__fxstat"); 205 glibc_ops.fstat64 = my_glibc_fstat64; 206 glibc_redirect.fstat64 = dlsym(RTLD_NEXT, "__fxstat64"); 207 glibc_ops.fstatat = my_glibc_fstatat; 208 glibc_redirect.fstatat = dlsym(RTLD_NEXT, "__fxstatat"); 209 glibc_ops.fstatat64 = my_glibc_fstatat64; 210 glibc_redirect.fstatat64 = dlsym(RTLD_NEXT, "__fxstatat64"); 211 glibc_ops.lstat = my_glibc_lstat; 212 glibc_redirect.lstat = dlsym(RTLD_NEXT, "__lxstat"); 213 glibc_ops.lstat64 = my_glibc_lstat64; 214 glibc_redirect.lstat64 = dlsym(RTLD_NEXT, "__lxstat64"); 108 215 glibc_ops.dup = dlsym(RTLD_NEXT, "dup"); 109 216 glibc_ops.dup2 = dlsym(RTLD_NEXT, "dup2"); … … 124 231 glibc_ops.link = dlsym(RTLD_NEXT, "link"); 125 232 glibc_ops.linkat = dlsym(RTLD_NEXT, "linkat"); 126 glibc_ops.readdir = dlsym(RTLD_NEXT, "readdir");127 glibc_ops.getdents = dlsym(RTLD_NEXT, "getdents");128 glibc_ops.getdents64 = dlsym(RTLD_NEXT, "getdents64");233 glibc_ops.readdir = my_glibc_readdir; 234 glibc_ops.getdents = my_glibc_getdents; 235 glibc_ops.getdents64 = my_glibc_getdents64; 129 236 glibc_ops.access = dlsym(RTLD_NEXT, "access"); 130 237 glibc_ops.faccessat = dlsym(RTLD_NEXT, "faccessat"); … … 134 241 glibc_ops.fsync = dlsym(RTLD_NEXT, "fsync"); 135 242 glibc_ops.fdatasync = dlsym(RTLD_NEXT, "fdatasync"); 136 glibc_ops.fadvise = dlsym(RTLD_NEXT, "fadvise");137 glibc_ops.fadvise64 = dlsym(RTLD_NEXT, "fadvise64");243 glibc_ops.fadvise = my_glibc_fadvise; 244 glibc_ops.fadvise64 = my_glibc_fadvise64; 138 245 glibc_ops.statfs = dlsym(RTLD_NEXT, "statfs"); 139 246 glibc_ops.statfs64 = dlsym(RTLD_NEXT, "statfs64"); 140 247 glibc_ops.fstatfs = dlsym(RTLD_NEXT, "fstatfs"); 141 248 glibc_ops.fstatfs64 = dlsym(RTLD_NEXT, "fstatfs64"); 142 glibc_ops.mknod = dlsym(RTLD_NEXT, "mknod"); 143 glibc_ops.mknodat = dlsym(RTLD_NEXT, "mknodat"); 249 glibc_ops.mknod = my_glibc_mknod; 250 glibc_redirect.mknod = dlsym(RTLD_NEXT, "__xmknod"); 251 glibc_ops.mknodat = my_glibc_mknodat; 252 glibc_redirect.mknodat = dlsym(RTLD_NEXT, "__xmknodat"); 144 253 glibc_ops.sendfile = dlsym(RTLD_NEXT, "sendfile"); 145 254 glibc_ops.sendfile64 = dlsym(RTLD_NEXT, "sendfile64"); … … 181 290 glibc_ops.socketpair = dlsym(RTLD_NEXT, "socketpair"); 182 291 glibc_ops.pipe = dlsym(RTLD_NEXT, "pipe"); 292 glibc_ops.umask = dlsym(RTLD_NEXT, "umask"); 293 glibc_ops.getumask = dlsym(RTLD_NEXT, "getumask"); 294 glibc_ops.getdtablesize = dlsym(RTLD_NEXT, "getdtablesize"); 183 295 184 296 /* PVFS does not implement socket ops */ … … 208 320 pvfs_ops.socketpair = dlsym(RTLD_NEXT, "socketpair"); 209 321 pvfs_ops.pipe = dlsym(RTLD_NEXT, "pipe"); 210 glibc_ops.umask = dlsym(RTLD_NEXT, "umask"); 211 glibc_ops.getumask = dlsym(RTLD_NEXT, "getumask"); 212 glibc_ops.getdtablesize = dlsym(RTLD_NEXT, "getdtablesize"); 322 } 323 324 static void usrint_cleanup(void) 325 { 326 /* later check for an error that might want us */ 327 /* to keep this - for now it is empty */ 328 glibc_ops.unlink(logfilepath); 213 329 } 214 330 … … 227 343 } 228 344 pvfs_lib_init_flag = 1; /* should only run this once */ 345 pvfs_initializing_flag = 1; 229 346 230 347 /* this allows system calls to run */ 231 348 load_glibc(); 349 PINT_initrand(); 350 351 /* if this fails no much we can do about it */ 352 atexit(usrint_cleanup); 232 353 233 354 rc = getrlimit(RLIMIT_NOFILE, &rl); … … 245 366 descriptor_table[2] = &pvfs_stderr; 246 367 descriptor_table_count = PREALLOC; 247 next_descriptor = PREALLOC; 368 369 sprintf(logfilepath, "/tmp/pvfsuid-%05d.log", (int)(getuid())); 370 logfile = glibc_ops.open(logfilepath, O_RDWR|O_CREAT, 0600); 371 if (logfile < 0) 372 { 373 perror("failed in pvfs_sys_init"); 374 exit(-1); 375 } 248 376 249 377 /* initalize PVFS */ … … 255 383 256 384 /* call other initialization routines */ 257 PINT_initrand();258 385 //PVFS_perror_gossip_silent(); 386 pvfs_initializing_flag = 0; 259 387 } 260 388 … … 268 396 * initialize fsops to the given set 269 397 */ 270 pvfs_descriptor *pvfs_alloc_descriptor(posix_ops *fsops )398 pvfs_descriptor *pvfs_alloc_descriptor(posix_ops *fsops, int fd) 271 399 { 272 int i;400 int newfd, rc, flags; 273 401 if (fsops == NULL) 274 402 { … … 278 406 pvfs_sys_init(); 279 407 280 /* table should be initialized now - check for available slot */ 281 if (descriptor_table_count == (descriptor_table_size - PREALLOC)) 282 { 283 errno = ENOMEM; 284 return NULL; 285 } 286 287 /* find next empty slot in table */ 288 for (i = next_descriptor; descriptor_table[i]; 289 i = (i == descriptor_table_size - 1) ? PREALLOC : i + 1); 290 291 /* found a slot */ 292 descriptor_table[i] = malloc(sizeof(pvfs_descriptor)); 293 if (descriptor_table[i] == NULL) 294 { 295 return NULL; 296 } 297 next_descriptor = ((i == descriptor_table_size - 1) ? PREALLOC : i + 1); 408 if (fd == -1) 409 { 410 /* PVFS file allocate a real descriptor for it */ 411 newfd = glibc_ops.dup(logfile); 412 } 413 else 414 { 415 /* opened by glibc, make sure this is a valid fd */ 416 newfd = fd; 417 rc = fcntl(newfd, F_GETFL, flags); 418 if (rc < 0) 419 { 420 return NULL; 421 } 422 } 298 423 descriptor_table_count++; 424 descriptor_table[newfd] = 425 (pvfs_descriptor *)malloc(sizeof(pvfs_descriptor)); 426 if (!descriptor_table[newfd]) 427 { 428 return NULL; 429 } 299 430 300 431 /* fill in descriptor */ 301 descriptor_table[i]->fd = i; 302 descriptor_table[i]->dup_cnt = 1; 303 descriptor_table[i]->fsops = fsops; 304 descriptor_table[i]->true_fd = i; 305 descriptor_table[i]->pvfs_ref.fs_id = 0; 306 descriptor_table[i]->pvfs_ref.handle = 0; 307 descriptor_table[i]->flags = 0; 308 descriptor_table[i]->mode = 0; 309 descriptor_table[i]->file_pointer = 0; 310 descriptor_table[i]->token = 0; 311 descriptor_table[i]->dpath = NULL; 312 descriptor_table[i]->is_in_use = PVFS_FS; 313 314 return descriptor_table[i]; 432 /* add reference to chache objects here */ 433 descriptor_table[newfd]->fd = newfd; 434 descriptor_table[newfd]->dup_cnt = 1; 435 descriptor_table[newfd]->fsops = fsops; 436 descriptor_table[newfd]->true_fd = newfd; 437 descriptor_table[newfd]->pvfs_ref.fs_id = 0; 438 descriptor_table[newfd]->pvfs_ref.handle = 0; 439 descriptor_table[newfd]->flags = flags; 440 descriptor_table[newfd]->mode = 0; 441 descriptor_table[newfd]->file_pointer = 0; 442 descriptor_table[newfd]->token = 0; 443 descriptor_table[newfd]->dpath = NULL; 444 descriptor_table[newfd]->is_in_use = PVFS_FS; 445 446 return descriptor_table[newfd]; 315 447 } 316 448 317 449 /* 318 * Function for dupli ating a descriptor - used in dup and dup2 calls450 * Function for duplicating a descriptor - used in dup and dup2 calls 319 451 */ 320 452 int pvfs_dup_descriptor(int oldfd, int newfd) 321 453 { 454 int rc = 0; 322 455 if (oldfd < 0 || oldfd >= descriptor_table_size) 323 456 { … … 327 460 if (newfd == -1) 328 461 { 329 /* find next empty slot in table */ 330 for (newfd = next_descriptor; descriptor_table[newfd]; 331 newfd = (newfd == descriptor_table_size-1) ? PREALLOC : newfd++); 462 newfd = glibc_ops.dup(logfile); 463 if (newfd < 0) 464 { 465 return newfd; 466 } 332 467 } 333 468 else … … 336 471 { 337 472 /* close old file in new slot */ 338 pvfs_close(newfd); 339 } 473 rc = pvfs_free_descriptor(newfd); 474 if (rc < 0) 475 { 476 return rc; 477 } 478 } 479 } 480 rc = glibc_ops.dup2(oldfd, newfd); 481 if (rc < 0) 482 { 483 return rc; 340 484 } 341 485 descriptor_table[newfd] = descriptor_table[oldfd]; 342 486 descriptor_table[newfd]->dup_cnt++; 343 487 descriptor_table_count++; 488 return 0; 344 489 } 345 490 … … 351 496 pvfs_descriptor *pvfs_find_descriptor(int fd) 352 497 { 498 pvfs_descriptor *pd; 353 499 if (fd < 0 || fd >= descriptor_table_size) 354 500 { … … 356 502 return NULL; 357 503 } 358 return descriptor_table[fd]; 504 pd = descriptor_table[fd]; 505 if (!pd) 506 { 507 int rc, flags; 508 /* see if glibc opened this file without our knowing */ 509 rc = glibc_ops.fcntl(fd, F_GETFL, flags); 510 if (rc < 0) 511 { 512 errno = EBADF; 513 return NULL; 514 } 515 pd = (pvfs_descriptor *)malloc(sizeof(pvfs_descriptor)); 516 /* fill in descriptor */ 517 pd->fd = fd; 518 pd->dup_cnt = 1; 519 pd->fsops = &glibc_ops; 520 pd->true_fd = fd; 521 pd->pvfs_ref.fs_id = 0; 522 pd->pvfs_ref.handle = 0; 523 pd->flags = flags; 524 pd->mode = 0; 525 pd->file_pointer = 0; 526 pd->token = 0; 527 pd->dpath = NULL; 528 pd->is_in_use = PVFS_FS; 529 descriptor_table[fd] = pd; 530 } 531 else if (pd->is_in_use != PVFS_FS) 532 { 533 errno = EBADF; 534 return NULL; 535 } 536 return pd; 359 537 } 360 538 … … 362 540 { 363 541 pvfs_descriptor *pd; 364 365 if (fd < 0 || fd >= descriptor_table_size) 366 { 367 errno = EBADF; 542 debug("pvfs_free_descriptor called with %d\n", fd); 543 544 pd = pvfs_find_descriptor(fd); 545 if (pd == NULL) 546 { 368 547 return -1; 369 548 } 370 pd = descriptor_table[fd];371 549 372 550 /* clear out table entry */ 373 551 descriptor_table[fd] = NULL; 552 glibc_ops.close(fd); 374 553 375 554 /* keep up with used descriptors */ … … 383 562 free(pd->dpath); 384 563 } 564 /* release cache opbjects here */ 385 565 /* free descriptor - wipe memory first */ 386 566 memset(pd, 0, sizeof(pvfs_descriptor)); … … 388 568 } 389 569 570 debug("pvfs_free_descriptor returns %d\n", 0); 390 571 return 0; 391 572 } … … 401 582 int cdsz; 402 583 int psz; 403 char *curdir ;404 char *newpath ;584 char *curdir = NULL; 585 char *newpath = NULL; 405 586 406 587 if(path[0] != '/') … … 410 591 do 411 592 { 412 if (i > 1 )593 if (i > 1 && curdir) 413 594 { 414 595 free(curdir); … … 425 606 { 426 607 /* some other error, bail out */ 427 free(curdir); 608 if (curdir) 609 { 610 free(curdir); 611 } 428 612 return NULL; 429 613 } … … 450 634 */ 451 635 636 int is_pvfs_path(const char *path) 637 { 452 638 #ifdef PVFS_ASSUME_MOUNT 453 int is_pvfs_path(const char *path)454 {455 639 struct statfs file_system; 640 #endif 641 int rc = 0; 642 PVFS_fs_id fs_id; 643 char pvfs_path[256]; 456 644 char *newpath = NULL ; 457 645 646 if (pvfs_initializing_flag) 647 { 648 /* we cannot open a PVFS file while 649 * initializing PVFS 650 */ 651 return 0; 652 } 653 458 654 pvfs_sys_init(); 655 #ifdef PVFS_ASSUME_MOUNT 459 656 memset(&file_system, 0, sizeof(file_system)); 460 657 … … 484 681 return 0; /* not PVFS assume the kernel can handle it */ 485 682 } 486 } 683 /***************************************************************/ 487 684 #else 488 int is_pvfs_path(const char *path) 489 { 490 int rc = 0; 491 PVFS_fs_id fs_id; 492 char pvfs_path[256]; 493 char *newpath = NULL; 494 495 pvfs_sys_init(); 685 /***************************************************************/ 496 686 newpath = pvfs_qualify_path(path); 497 687 rc = PVFS_util_resolve(newpath, &fs_id, pvfs_path, 256); … … 510 700 } 511 701 return 1; /* a PVFS path */ 512 }513 702 #endif 514 515 void pvfs_debug(char *fmt, ...)516 {517 va_list ap;518 519 va_start(ap, fmt);520 vfprintf(stderr, fmt, ap);521 va_end(ap);522 703 } 523 704 -
branches/Orange-Branch/src/client/usrint/openfile-util.h
r8907 r9016 4 4 * See COPYING in top-level directory. 5 5 */ 6 7 #include "posix-ops.h" 6 8 7 9 /** \file … … 42 44 PVFS_object_ref *ref); 43 45 44 pvfs_descriptor *pvfs_alloc_descriptor(posix_ops *fsops );46 pvfs_descriptor *pvfs_alloc_descriptor(posix_ops *fsops, int fd); 45 47 46 48 pvfs_descriptor *pvfs_find_descriptor(int fd); 47 49 50 int pvfs_dup_descriptor(int oldfd, int newfd); 51 52 int pvfs_free_descriptor(int fd); 53 54 int pvfs_descriptor_table_size(void); 48 55 49 56 int pvfs_create_file(const char *filename, -
branches/Orange-Branch/src/client/usrint/posix-ops.h
r8975 r9016 51 51 int (*fstat)(int fd, struct stat *buf); 52 52 int (*fstat64)(int fd, struct stat64 *buf); 53 int (*fstatat)(int fd, c har *path, struct stat *buf, int flag);54 int (*fstatat64)(int fd, c har *path, struct stat64 *buf, int flag);53 int (*fstatat)(int fd, const char *path, struct stat *buf, int flag); 54 int (*fstatat64)(int fd, const char *path, struct stat64 *buf, int flag); 55 55 int (*lstat)(const char *path, struct stat *buf); 56 56 int (*lstat64)(const char *path, struct stat64 *buf); … … 74 74 int (*linkat)(int olddirfd, const char *oldpath, 75 75 int newdirfd, const char *newpath, int flags); 76 int (*readdir)(u nsigned int fd, struct dirent *dirp, unsignedint count);77 int (*getdents)(u nsigned int fd, struct dirent *dirp, unsignedint count);78 int (*getdents64)(u nsigned int fd, struct dirent64 *dirp, unsignedint count);76 int (*readdir)(u_int fd, struct dirent *dirp, u_int count); 77 int (*getdents)(u_int fd, struct dirent *dirp, u_int count); 78 int (*getdents64)(u_int fd, struct dirent64 *dirp, u_int count); 79 79 int (*access)(const char *path, int mode); 80 80 int (*faccessat)(int dirfd, const char *path, int mode, int flags); … … 92 92 int (*mknod)(const char *path, mode_t mode, dev_t dev); 93 93 int (*mknodat)(int dirfd, const char *path, mode_t mode, dev_t dev); 94 ssize_t (*sendfile)(int outfd, int infd, off_t offset, size_t count);95 ssize_t (*sendfile64)(int outfd, int infd, off64_t offset, size_t count);94 ssize_t (*sendfile)(int outfd, int infd, off_t *offset, size_t count); 95 ssize_t (*sendfile64)(int outfd, int infd, off64_t *offset, size_t count); 96 96 int (*setxattr)(const char *path, const char *name, 97 97 const void *value, size_t size, int flags); -
branches/Orange-Branch/src/client/usrint/posix-pvfs.c
r8975 r9016 43 43 char *newpath; 44 44 pvfs_descriptor *pd; 45 debug("pvfs_open: called with %s\n", path); 45 46 46 47 if (!path) … … 71 72 return -1; 72 73 } 74 debug("pvfs_open: returns %d\n", pd->fd); 73 75 return pd->fd; 74 76 } … … 122 124 if (!path) 123 125 { 124 errno -EINVAL;126 errno = EINVAL; 125 127 return -1; 126 128 } … … 176 178 int mode; 177 179 PVFS_hint hints; 178 pvfs_descriptor *pd;179 180 180 181 if (dirfd < 0) … … 228 229 int rc = 0; 229 230 char *newpath; 230 pvfs_descriptor *pd;231 231 232 232 newpath = pvfs_qualify_path(path); … … 264 264 return -1; 265 265 } 266 rc = iocommon_unlink(path, &pd->pvfs_ref); 266 if (flags & AT_REMOVEDIR) 267 { 268 rc = iocommon_rmdir(path, &pd->pvfs_ref); 269 } 270 else 271 { 272 rc = iocommon_unlink(path, &pd->pvfs_ref); 273 } 267 274 } 268 275 return rc; … … 620 627 } 621 628 /* if (file_size < offset + length) 622 /* {629 * { 623 630 */ 624 631 return pvfs_ftruncate64(fd, (off64_t)(offset) + (off64_t)(length)); … … 662 669 int pvfs_close(int fd) 663 670 { 671 int rc = 0; 664 672 pvfs_descriptor* pd; 673 debug("pvfs_close: called with %d\n", fd); 665 674 666 675 if (fd < 0) … … 677 686 678 687 /* flush buffers */ 679 pvfs_flush(fd); 688 if (S_ISREG(pd->mode)) 689 { 690 rc = iocommon_fsync(pd); 691 if (rc < 0) 692 { 693 return -1; 694 } 695 } 680 696 681 697 /* free descriptor */ 682 pvfs_free_descriptor(fd); 683 684 return PVFS_FD_SUCCESS; 698 rc = pvfs_free_descriptor(pd->fd); 699 if (rc < 0) 700 { 701 return -1; 702 } 703 704 debug("pvfs_close: returns %d\n", rc); 705 return rc; 685 706 } 686 707 … … 690 711 int pvfs_flush(int fd) 691 712 { 713 int rc = 0; 692 714 pvfs_descriptor* pd; 693 715 694 #ifdef DEBUG 695 pvfs_debug("in pvfs_flush(%ld)\n", fd); 696 #endif 716 debug("pvfs_flush: called with %d\n", fd); 697 717 698 718 if (fd < 0) … … 706 726 { 707 727 errno = EBADF; 708 return PVFS_FD_FAILURE;728 return -1; 709 729 } 710 730 711 731 /* tell the server to flush data to disk */ 712 return iocommon_fsync(pd); 732 rc = iocommon_fsync(pd); 733 debug("pvfs_flush: returns %d\n", rc); 734 return rc; 713 735 } 714 736 … … 809 831 * pvfs_fstatat 810 832 */ 811 int pvfs_fstatat(int fd, c har *path, struct stat *buf, int flag)833 int pvfs_fstatat(int fd, const char *path, struct stat *buf, int flag) 812 834 { 813 835 int rc; … … 852 874 * pvfs_fstatat64 853 875 */ 854 int pvfs_fstatat64(int fd, c har *path, struct stat64 *buf, int flag)876 int pvfs_fstatat64(int fd, const char *path, struct stat64 *buf, int flag) 855 877 { 856 878 int rc; … … 1154 1176 { 1155 1177 int rc; 1156 pvfs_descriptor *pd , *pd2;1178 pvfs_descriptor *pd; 1157 1179 1158 1180 if (path[0] == '/' || dirfd == AT_FDCWD) … … 1213 1235 free(newpath); 1214 1236 } 1237 debug("pvfs_readlink mode is %o\n", pd->mode); 1215 1238 /* this checks that it is a valid symlink and sets errno if not */ 1216 1239 rc = iocommon_readlink(pd, buf, bufsiz); … … 1257 1280 char *abspath; 1258 1281 abspath = pvfs_qualify_path(newpath); 1259 rc = iocommon_symlink(abspath, oldpath, NULL);1282 rc = iocommon_symlink(abspath, oldpath, NULL); 1260 1283 if (abspath != newpath) 1261 1284 { … … 1407 1430 int rc = 0; 1408 1431 va_list ap; 1409 long arg;1432 /* long arg; */ 1410 1433 struct flock *lock; 1411 1434 pvfs_descriptor *pd; … … 1415 1438 { 1416 1439 errno = EBADF; 1417 return -1; 1440 rc = -1; 1441 goto errorout; 1418 1442 } 1419 1443 va_start(ap, cmd); … … 1431 1455 break; 1432 1456 case F_SETFL : 1433 pd-> flags = va_arg(ap, int);1457 pd->flags = va_arg(ap, int); 1434 1458 break; 1435 1459 case F_GETLK : 1436 1460 case F_SETLK : 1437 1461 case F_SETLKW : 1462 lock = va_arg(ap, struct flock *); 1438 1463 case F_GETOWN : 1439 1464 case F_SETOWN : … … 1535 1560 free(newpath); 1536 1561 } 1537 rc = iocommon_statfs (pd, buf);1562 rc = iocommon_statfs64(pd, buf); 1538 1563 pvfs_close(pd->fd); 1539 1564 return rc; … … 1584 1609 { 1585 1610 int fd; 1586 int s_type = mode & S_IFMT;1611 /* int s_type = mode & S_IFMT; */ 1587 1612 1588 1613 switch (dev) … … 1607 1632 } 1608 1633 1609 ssize_t pvfs_sendfile(int outfd, int infd, off_t offset, size_t count)1610 { 1611 return pvfs_sendfile64(outfd, infd, (off64_t )offset, count);1634 ssize_t pvfs_sendfile(int outfd, int infd, off_t *offset, size_t count) 1635 { 1636 return pvfs_sendfile64(outfd, infd, (off64_t *)offset, count); 1612 1637 } 1613 1638 1614 ssize_t pvfs_sendfile64(int outfd, int infd, off64_t offset, size_t count)1639 ssize_t pvfs_sendfile64(int outfd, int infd, off64_t *offset, size_t count) 1615 1640 { 1616 1641 pvfs_descriptor *inpd, *outpd; -
branches/Orange-Branch/src/client/usrint/posix-pvfs.h
r8975 r9016 88 88 int pvfs_stat64(const char *path, struct stat64 *buf); 89 89 90 int pvfs_stat_mask(const char *path, struct stat *buf, uint32_t mask); 91 90 92 int pvfs_fstat(int fd, struct stat *buf); 91 93 92 94 int pvfs_fstat64(int fd, struct stat64 *buf); 93 95 94 int pvfs_fstatat(int fd, char *path, struct stat *buf, int flag); 95 96 int pvfs_fstatat64(int fd, char *path, struct stat64 *buf, int flag); 96 int pvfs_fstatat(int fd, const char *path, struct stat *buf, int flag); 97 98 int pvfs_fstatat64(int fd, const char *path, struct stat64 *buf, int flag); 99 100 int pvfs_fstat_mask(int fd, struct stat *buf, uint32_t mask); 97 101 98 102 int pvfs_lstat(const char *path, struct stat *buf); 99 103 100 104 int pvfs_lstat64(const char *path, struct stat64 *buf); 105 106 int pvfs_lstat_mask(const char *path, struct stat *buf, uint32_t mask); 101 107 102 108 int pvfs_dup(int oldfd); … … 180 186 int pvfs_mknodat(int dirfd, const char *path, mode_t mode, dev_t dev); 181 187 182 ssize_t pvfs_sendfile(int outfd, int infd, off_t offset, size_t count);183 184 ssize_t pvfs_sendfile64(int outfd, int infd, off64_t offset, size_t count);188 ssize_t pvfs_sendfile(int outfd, int infd, off_t *offset, size_t count); 189 190 ssize_t pvfs_sendfile64(int outfd, int infd, off64_t *offset, size_t count); 185 191 186 192 int pvfs_setxattr(const char *path, const char *name, -
branches/Orange-Branch/src/client/usrint/posix.c
r8975 r9016 10 10 * PVFS2 user interface routines - wrappers for posix system calls 11 11 */ 12 13 /* this prevents headers from using inlines for 64 bit calls */ 14 #ifdef _FILE_OFFSET_BITS 15 #undef _FILE_OFFSET_BITS 16 #endif 17 12 18 #include <usrint.h> 13 19 #include <linux/dirent.h> … … 56 62 int rc; 57 63 struct stat sbuf; 58 /* descrptor unknown to FS here so we must set it up*/59 rc = pd->fsops->open(path, flags & 01777777, mode);64 /* path unknown to FS so open with glibc */ 65 rc = glibc_ops.open(path, flags & 01777777, mode); 60 66 if (rc < 0) 61 67 { 62 68 return rc; 63 69 } 64 pd = pvfs_alloc_descriptor(&glibc_ops); 70 /* set up the descriptor manually */ 71 pd = pvfs_alloc_descriptor(&glibc_ops, rc); 72 if (!pd) 73 { 74 return -1; 75 } 65 76 pd->is_in_use = PVFS_FS; 66 pd->true_fd = rc;67 77 pd->flags = flags; 68 fstat(rc, &sbuf);78 glibc_ops.fstat(rc, &sbuf); 69 79 pd->mode = sbuf.st_mode; 70 80 return pd->fd; … … 78 88 { 79 89 int fd; 90 int mode = 0; 80 91 va_list ap; 81 92 va_start(ap, flags); 82 fd = open(path, flags|O_LARGEFILE, ap); 93 if (flags & O_CREAT) 94 { 95 mode = va_arg(ap, int); 96 } 97 fd = open(path, flags|O_LARGEFILE, mode); 83 98 va_end(ap); 84 99 return fd; … … 88 103 { 89 104 int fd; 105 int mode = 0; 90 106 pvfs_descriptor *pd; 91 107 va_list ap; … … 97 113 } 98 114 va_start(ap, flags); 115 if (flags & O_CREAT) 116 { 117 mode = va_arg(ap, int); 118 } 99 119 if (dirfd == AT_FDCWD || path[0] == '/') 100 120 { 101 fd = open(path, flags, ap);121 fd = open(path, flags, mode); 102 122 } 103 123 else … … 106 126 if (pd) 107 127 { 108 fd = pd->fsops->openat(pd->true_fd, path, flags, ap);128 fd = pd->fsops->openat(pd->true_fd, path, flags, mode); 109 129 } 110 130 else … … 121 141 { 122 142 int fd; 143 int mode; 123 144 va_list ap; 124 145 va_start(ap, flags); 125 fd = openat(dirfd, path, flags|O_LARGEFILE, ap); 146 if (flags & O_CREAT) 147 { 148 mode = va_arg(ap, int); 149 } 150 fd = openat(dirfd, path, flags|O_LARGEFILE, mode); 126 151 va_end(ap); 127 152 return fd; … … 154 179 return -1; 155 180 } 156 if (is_pvfs_path(path)) { 181 if (is_pvfs_path(path)) 182 { 157 183 return pvfs_ops.unlink(path); 158 184 } 159 else { 185 else 186 { 160 187 return glibc_ops.unlink(path); 161 188 } … … 164 191 int unlinkat(int dirfd, const char *path, int flag) 165 192 { 166 int rc ;193 int rc = 0; 167 194 pvfs_descriptor *pd; 168 195 … … 189 216 } 190 217 } 218 return rc; 191 219 } 192 220 … … 252 280 ssize_t read(int fd, void *buf, size_t count) 253 281 { 254 ssize_t rc ;282 ssize_t rc = 0; 255 283 pvfs_descriptor *pd; 256 284 … … 273 301 ssize_t pread(int fd, void *buf, size_t nbytes, off_t offset) 274 302 { 275 ssize_t rc ;303 ssize_t rc = 0; 276 304 pvfs_descriptor *pd; 277 305 … … 288 316 return rc; 289 317 } 290 291 /*292 * pread64 wrapper293 */294 ssize_t pread64(int fd, void *buf, size_t nbytes, off64_t offset)295 {296 ssize_t rc;297 pvfs_descriptor *pd;298 299 pd = pvfs_find_descriptor(fd);300 if (pd)301 {302 rc = pd->fsops->pread64(pd->true_fd, (void *)buf, nbytes, offset);303 }304 else305 {306 errno = EBADF;307 rc = -1;308 }309 return rc;310 }311 318 312 319 /* … … 315 322 ssize_t readv(int fd, const struct iovec *iov, int iovcnt) 316 323 { 317 ssize_t rc ;324 ssize_t rc = 0; 318 325 pvfs_descriptor *pd; 319 326 … … 322 329 { 323 330 rc = pd->fsops->readv(pd->true_fd, iov, iovcnt); 331 } 332 else 333 { 334 errno = EBADF; 335 rc = -1; 336 } 337 return rc; 338 } 339 340 /* 341 * pread64 wrapper 342 */ 343 ssize_t pread64(int fd, void *buf, size_t nbytes, off64_t offset) 344 { 345 ssize_t rc = 0; 346 pvfs_descriptor *pd; 347 348 pd = pvfs_find_descriptor(fd); 349 if (pd) 350 { 351 rc = pd->fsops->pread64(pd->true_fd, (void *)buf, nbytes, offset); 324 352 } 325 353 else … … 336 364 ssize_t write(int fd, const void *buf, size_t count) 337 365 { 338 ssize_t rc ;366 ssize_t rc = 0; 339 367 pvfs_descriptor *pd; 340 368 … … 357 385 ssize_t pwrite(int fd, const void *buf, size_t nbytes, off_t offset) 358 386 { 359 ssize_t rc ;387 ssize_t rc = 0; 360 388 pvfs_descriptor *pd; 361 389 … … 364 392 { 365 393 rc = pd->fsops->pwrite(pd->true_fd, buf, nbytes, offset); 366 }367 else368 {369 errno = EBADF;370 rc = -1;371 }372 return rc;373 }374 375 /*376 * pwrite64 wrapper377 */378 ssize_t pwrite64(int fd, const void *buf, size_t nbytes, off64_t offset)379 {380 ssize_t rc;381 pvfs_descriptor *pd;382 383 pd = pvfs_find_descriptor(fd);384 if (pd)385 {386 rc = pd->fsops->pwrite64(pd->true_fd, buf, nbytes, offset);387 394 } 388 395 else … … 399 406 ssize_t writev(int fd, const struct iovec *iov, int iovcnt) 400 407 { 401 ssize_t rc ;408 ssize_t rc = 0; 402 409 pvfs_descriptor *pd; 403 410 … … 408 415 if (rc > 0) 409 416 pd->file_pointer += rc; 417 } 418 else 419 { 420 errno = EBADF; 421 rc = -1; 422 } 423 return rc; 424 } 425 426 /* 427 * pwrite64 wrapper 428 */ 429 ssize_t pwrite64(int fd, const void *buf, size_t nbytes, off64_t offset) 430 { 431 ssize_t rc = 0; 432 pvfs_descriptor *pd; 433 434 pd = pvfs_find_descriptor(fd); 435 if (pd) 436 { 437 rc = pd->fsops->pwrite64(pd->true_fd, buf, nbytes, offset); 410 438 } 411 439 else … … 438 466 off64_t lseek64(int fd, off64_t offset, int whence) 439 467 { 440 off64_t rc ;468 off64_t rc = 0; 441 469 pvfs_descriptor *pd; 442 470 … … 490 518 int ftruncate(int fd, off_t length) 491 519 { 492 int rc ;520 int rc = 0; 493 521 pvfs_descriptor *pd; 494 522 … … 508 536 int ftruncate64(int fd, off64_t length) 509 537 { 510 int rc ;538 int rc = 0; 511 539 pvfs_descriptor *pd; 512 540 … … 527 555 int posix_fallocate(int fd, off_t offset, off_t length) 528 556 { 529 int rc ;557 int rc = 0; 530 558 pvfs_descriptor *pd; 531 559 … … 549 577 int close(int fd) 550 578 { 551 pvfs_descriptor *pd; 552 553 pd = pvfs_find_descriptor(fd); 554 if (pd) 555 { 556 pd->fsops->flush(pd->true_fd); 557 pd->fsops->close(pd->true_fd); 558 pvfs_free_descriptor(pd); 559 return 0; 560 } 561 else 562 { 563 errno = EBADF; 564 return -1; 565 } 579 int rc = 0; 580 581 rc = pvfs_free_descriptor(fd); 582 return rc; 566 583 } 567 584 568 585 int flush(int fd) 569 586 { 570 int rc ;587 int rc = 0; 571 588 pvfs_descriptor *pd; 572 589 … … 631 648 int fstat(int fd, struct stat *buf) 632 649 { 633 int rc ;650 int rc = 0; 634 651 pvfs_descriptor *pd; 635 652 … … 654 671 int fstat64(int fd, struct stat64 *buf) 655 672 { 656 int rc ;673 int rc = 0; 657 674 pvfs_descriptor *pd; 658 675 … … 675 692 } 676 693 694 int fstatat(int fd, const char *path, struct stat *buf, int flag) 695 { 696 int rc = 0; 697 pvfs_descriptor *pd; 698 699 if (fd == AT_FDCWD || path[0] == '/') 700 { 701 if (flag & AT_SYMLINK_NOFOLLOW) 702 { 703 lstat(path, buf); 704 } 705 else 706 { 707 stat(path, buf); 708 } 709 } 710 else 711 { 712 pd = pvfs_find_descriptor(fd); 713 if (pd) 714 { 715 rc = pd->fsops->fstatat(pd->true_fd, path, buf, flag); 716 } 717 else 718 { 719 errno = EBADF; 720 rc = -1; 721 } 722 } 723 return rc; 724 } 725 726 int __fxstatat(int ver, int fd, const char *path, struct stat *buf, int flag) 727 { 728 return fstatat(fd, path, buf, flag); 729 } 730 731 int fstatat64(int fd, const char *path, struct stat64 *buf, int flag) 732 { 733 int rc = 0; 734 pvfs_descriptor *pd; 735 736 if (fd == AT_FDCWD || path[0] == '/') 737 { 738 if (flag & AT_SYMLINK_NOFOLLOW) 739 { 740 lstat64(path, buf); 741 } 742 else 743 { 744 stat64(path, buf); 745 } 746 } 747 else 748 { 749 pd = pvfs_find_descriptor(fd); 750 if (pd) 751 { 752 rc = pd->fsops->fstatat64(pd->true_fd, path, buf, flag); 753 } 754 else 755 { 756 errno = EBADF; 757 rc = -1; 758 } 759 } 760 return rc; 761 } 762 763 int __fxstatat64(int ver, int fd, const char *path, struct stat64 *buf, int flag) 764 { 765 return fstatat64(fd, path, buf, flag); 766 } 767 677 768 int lstat(const char *path, struct stat *buf) 678 769 { … … 721 812 int dup(int oldfd) 722 813 { 723 int rc ;814 int rc = 0; 724 815 pvfs_descriptor *pd; 725 816 … … 739 830 int dup2(int oldfd, int newfd) 740 831 { 741 int rc ;832 int rc = 0; 742 833 pvfs_descriptor *pd; 743 834 … … 774 865 int fchown(int fd, uid_t owner, gid_t group) 775 866 { 776 int rc ;867 int rc = 0; 777 868 pvfs_descriptor *pd; 778 869 … … 792 883 int fchownat(int dirfd, const char *path, uid_t owner, gid_t group, int flag) 793 884 { 794 ssize_t rc;885 int rc = 0; 795 886 pvfs_descriptor *pd; 796 887 … … 812 903 } 813 904 } 905 return rc; 814 906 } 815 907 … … 850 942 int fchmod(int fd, mode_t mode) 851 943 { 852 int rc ;944 int rc = 0; 853 945 pvfs_descriptor *pd; 854 946 … … 868 960 int fchmodat(int dirfd, const char *path, mode_t mode, int flag) 869 961 { 870 ssize_t rc;962 int rc = 0; 871 963 pvfs_descriptor *pd; 872 964 … … 893 985 } 894 986 } 987 return rc; 895 988 } 896 989 … … 914 1007 int mkdirat(int dirfd, const char *path, mode_t mode) 915 1008 { 916 ssize_t rc;1009 int rc = 0; 917 1010 pvfs_descriptor *pd; 918 1011 … … 939 1032 } 940 1033 } 1034 return rc; 941 1035 } 942 1036 … … 977 1071 int readlinkat(int dirfd, const char *path, char *buf, size_t bufsiz) 978 1072 { 979 ssize_t rc;1073 int rc = 0; 980 1074 pvfs_descriptor *pd; 981 1075 … … 1002 1096 } 1003 1097 } 1098 return rc; 1004 1099 } 1005 1100 … … 1023 1118 int symlinkat(const char *oldpath, int newdirfd, const char *newpath) 1024 1119 { 1025 ssize_t rc;1120 int rc = 0; 1026 1121 pvfs_descriptor *pd; 1027 1122 … … 1048 1143 } 1049 1144 } 1145 return rc; 1050 1146 } 1051 1147 … … 1065 1161 return glibc_ops.link(oldpath, newpath); 1066 1162 } 1163 return -1; 1067 1164 } 1068 1165 … … 1095 1192 } 1096 1193 1097 int readdir(unsigned int fd, struct dirent *dirp, unsigned int count)1194 int posix_readdir(unsigned int fd, struct dirent *dirp, unsigned int count) 1098 1195 { 1099 1196 int rc; … … 1120 1217 int getdents(unsigned int fd, struct dirent *dirp, unsigned int count) 1121 1218 { 1122 int rc ;1219 int rc = 0; 1123 1220 pvfs_descriptor *pd; 1124 1221 … … 1143 1240 int getdents64(unsigned int fd, struct dirent64 *dirp, unsigned int count) 1144 1241 { 1145 int rc ;1242 int rc = 0; 1146 1243 pvfs_descriptor *pd; 1147 1244 … … 1188 1285 int faccessat(int dirfd, const char *path, int mode, int flags) 1189 1286 { 1190 ssize_t rc;1287 int rc = 0; 1191 1288 pvfs_descriptor *pd; 1192 1289 … … 1213 1310 } 1214 1311 } 1312 return rc; 1215 1313 } 1216 1314 1217 1315 int flock(int fd, int op) 1218 1316 { 1219 int rc ;1317 int rc = 0; 1220 1318 pvfs_descriptor *pd; 1221 1319 … … 1235 1333 int fcntl(int fd, int cmd, ...) 1236 1334 { 1237 int rc; 1335 int rc = 0; 1336 long arg; 1337 struct flock *lock; 1238 1338 pvfs_descriptor *pd; 1239 1339 va_list ap; … … 1243 1343 if (pd) 1244 1344 { 1245 rc = pd->fsops->fcntl(pd->true_fd, cmd, ap); 1345 switch (cmd) 1346 { 1347 case F_GETLK: 1348 case F_SETLK: 1349 case F_SETLKW: 1350 lock = va_arg(ap, struct flock *); 1351 rc = pd->fsops->fcntl(pd->true_fd, cmd, lock); 1352 break; 1353 default: 1354 arg = va_arg(ap, long); 1355 rc = pd->fsops->fcntl(pd->true_fd, cmd, arg); 1356 break; 1357 } 1246 1358 } 1247 1359 else … … 1262 1374 int fsync(int fd) 1263 1375 { 1264 int rc ;1376 int rc = 0; 1265 1377 pvfs_descriptor *pd; 1266 1378 … … 1280 1392 int fdatasync(int fd) 1281 1393 { 1282 int rc ;1394 int rc = 0; 1283 1395 pvfs_descriptor *pd; 1284 1396 … … 1298 1410 int posix_fadvise(int fd, off_t offset, off_t length, int advice) 1299 1411 { 1300 int rc ;1412 int rc = 0; 1301 1413 pvfs_descriptor *pd; 1302 1414 … … 1316 1428 int fadvise(int fd, off_t offset, off_t len, int advice) 1317 1429 { 1318 int rc ;1430 int rc = 0; 1319 1431 pvfs_descriptor *pd; 1320 1432 … … 1334 1446 int fadvise64(int fd, off64_t offset, off64_t len, int advice) 1335 1447 { 1336 int rc ;1448 int rc = 0; 1337 1449 pvfs_descriptor *pd; 1338 1450 … … 1386 1498 int fstatfs(int fd, struct statfs *buf) 1387 1499 { 1388 int rc ;1500 int rc = 0; 1389 1501 pvfs_descriptor *pd; 1390 1502 … … 1409 1521 int fstatfs64(int fd, struct statfs64 *buf) 1410 1522 { 1411 int rc ;1523 int rc = 0; 1412 1524 pvfs_descriptor *pd; 1413 1525 … … 1449 1561 int mknodat(int dirfd, const char *path, mode_t mode, dev_t dev) 1450 1562 { 1451 ssize_t rc;1563 int rc = 0; 1452 1564 pvfs_descriptor *pd; 1453 1565 … … 1474 1586 } 1475 1587 } 1476 } 1477 1478 ssize_t sendfile(int outfd, int infd, off_t offset, size_t count) 1479 { 1480 return sendfile64(outfd, infd, (off64_t)offset, count); 1481 } 1482 1483 ssize_t sendfile64(int outfd, int infd, off64_t offset, size_t count) 1484 { 1485 int rc; 1588 return rc; 1589 } 1590 1591 ssize_t sendfile(int outfd, int infd, off_t *offset, size_t count) 1592 { 1593 return sendfile64(outfd, infd, (off64_t *)offset, count); 1594 } 1595 1596 ssize_t sendfile64(int outfd, int infd, off64_t *offset, size_t count) 1597 { 1598 int rc = 0; 1486 1599 pvfs_descriptor *inpd, *outpd; 1487 1600 … … 1540 1653 const void *value, size_t size, int flags) 1541 1654 { 1542 int rc ;1655 int rc = 0; 1543 1656 pvfs_descriptor *pd; 1544 1657 … … 1595 1708 size_t size) 1596 1709 { 1597 int rc ;1710 int rc = 0; 1598 1711 pvfs_descriptor *pd; 1599 1712 … … 1647 1760 int flistxattr(int fd, char *list, size_t size) 1648 1761 { 1649 int rc ;1762 int rc = 0; 1650 1763 pvfs_descriptor *pd; 1651 1764 … … 1699 1812 int fremovexattr(int fd, const char *name) 1700 1813 { 1701 int rc ;1814 int rc = 0; 1702 1815 pvfs_descriptor *pd; 1703 1816 -
branches/Orange-Branch/src/client/usrint/request.c
r8890 r9016 11 11 */ 12 12 #include <usrint.h> 13 14 int pvfs_check_vector(const struct iovec *iov, 15 int count, 16 PVFS_Request *req, 17 void **buf); 13 18 14 19 /** … … 39 44 PVFS_Request *req_array; 40 45 int rblk; 41 PVFS_Request tmpreq;42 46 43 47 /* set up request arrays */ -
branches/Orange-Branch/src/client/usrint/socket.c
r8975 r9016 30 30 return sockfd; 31 31 } 32 pd = pvfs_alloc_descriptor(&glibc_ops); 33 pd->is_in_use = PVFS_FS; 34 pd->true_fd = sockfd; 32 pd = pvfs_alloc_descriptor(&glibc_ops, sockfd); 33 pd->mode |= S_IFSOCK; 35 34 return pd->fd; 36 35 } … … 38 37 int accept (int sockfd, struct sockaddr *addr, socklen_t *alen) 39 38 { 40 int rc = 0; 41 pvfs_descriptor *pd; 42 43 pd = pvfs_find_descriptor(sockfd); 44 if (pd) 45 { 46 rc = pd->fsops->accept(pd->true_fd, addr, alen); 47 } 48 else 49 { 50 rc = -1; 51 errno = EBADF; 52 } 39 int rc = 0, fd; 40 pvfs_descriptor *pd; 41 42 pd = pvfs_find_descriptor(sockfd); 43 if (!pd) 44 { 45 errno = EBADF; 46 rc = -1; 47 goto errorout; 48 } 49 if (!S_ISSOCK(pd->mode)) 50 { 51 errno = ENOTSOCK; 52 rc = -1; 53 goto errorout; 54 } 55 fd = pd->fsops->accept(pd->true_fd, addr, alen); 56 if (fd < 0) 57 { 58 rc = -1; 59 goto errorout; 60 } 61 pd = pvfs_alloc_descriptor(&glibc_ops, fd); 62 pd->mode |= S_IFSOCK; 63 rc = fd; 64 errorout: 53 65 return rc; 54 66 } … … 60 72 61 73 pd = pvfs_find_descriptor(sockfd); 62 if (pd) 63 { 64 rc = pd->fsops->bind(pd->true_fd, addr, alen); 65 } 66 else 67 { 68 rc = -1; 69 errno = EBADF; 70 } 74 if (!pd) 75 { 76 errno = EBADF; 77 rc = -1; 78 goto errorout; 79 } 80 if (!S_ISSOCK(pd->mode)) 81 { 82 errno = ENOTSOCK; 83 rc = -1; 84 goto errorout; 85 } 86 rc = pd->fsops->bind(pd->true_fd, addr, alen); 87 errorout: 71 88 return rc; 72 89 } … … 78 95 79 96 pd = pvfs_find_descriptor(sockfd); 80 if (pd) 81 { 82 rc = pd->fsops->connect(pd->true_fd, addr, alen); 83 } 84 else 85 { 86 rc = -1; 87 errno = EBADF; 88 } 97 if (!pd) 98 { 99 errno = EBADF; 100 rc = -1; 101 goto errorout; 102 } 103 if (!S_ISSOCK(pd->mode)) 104 { 105 errno = ENOTSOCK; 106 rc = -1; 107 goto errorout; 108 } 109 rc = pd->fsops->connect(pd->true_fd, addr, alen); 110 errorout: 89 111 return rc; 90 112 } … … 96 118 97 119 pd = pvfs_find_descriptor(sockfd); 98 if (pd) 99 { 100 rc = pd->fsops->getpeername(pd->true_fd, addr, alen); 101 } 102 else 103 { 104 rc = -1; 105 errno = EBADF; 106 } 120 if (!pd) 121 { 122 errno = EBADF; 123 rc = -1; 124 goto errorout; 125 } 126 if (!S_ISSOCK(pd->mode)) 127 { 128 errno = ENOTSOCK; 129 rc = -1; 130 goto errorout; 131 } 132 rc = pd->fsops->getpeername(pd->true_fd, addr, alen); 133 errorout: 107 134 return rc; 108 135 } … … 114 141 115 142 pd = pvfs_find_descriptor(sockfd); 116 if (pd) 117 { 118 rc = pd->fsops->getsockname(pd->true_fd, addr, alen); 119 } 120 else 121 { 122 rc = -1; 123 errno = EBADF; 124 } 143 if (!pd) 144 { 145 errno = EBADF; 146 rc = -1; 147 goto errorout; 148 } 149 if (!S_ISSOCK(pd->mode)) 150 { 151 errno = ENOTSOCK; 152 rc = -1; 153 goto errorout; 154 } 155 rc = pd->fsops->getsockname(pd->true_fd, addr, alen); 156 errorout: 125 157 return rc; 126 158 } … … 133 165 134 166 pd = pvfs_find_descriptor(sockfd); 135 if (pd) 136 { 137 rc = pd->fsops->getsockopt(pd->true_fd, lvl, oname, oval, olen); 138 } 139 else 140 { 141 rc = -1; 142 errno = EBADF; 143 } 167 if (!pd) 168 { 169 errno = EBADF; 170 rc = -1; 171 goto errorout; 172 } 173 if (!S_ISSOCK(pd->mode)) 174 { 175 errno = ENOTSOCK; 176 rc = -1; 177 goto errorout; 178 } 179 rc = pd->fsops->getsockopt(pd->true_fd, lvl, oname, oval, olen); 180 errorout: 144 181 return rc; 145 182 } … … 152 189 153 190 pd = pvfs_find_descriptor(sockfd); 154 if (pd) 155 { 156 rc = pd->fsops->setsockopt(pd->true_fd, lvl, oname, oval, olen); 157 } 158 else 159 { 160 rc = -1; 161 errno = EBADF; 162 } 191 if (!pd) 192 { 193 errno = EBADF; 194 rc = -1; 195 goto errorout; 196 } 197 if (!S_ISSOCK(pd->mode)) 198 { 199 errno = ENOTSOCK; 200 rc = -1; 201 goto errorout; 202 } 203 rc = pd->fsops->setsockopt(pd->true_fd, lvl, oname, oval, olen); 204 errorout: 163 205 return rc; 164 206 } … … 172 214 va_start(ap, request); 173 215 pd = pvfs_find_descriptor(fd); 174 if (pd) 175 { 176 rc = pd->fsops->ioctl(pd->true_fd, request, ap); 177 } 178 else 179 { 180 errno = EBADF; 181 rc = -1; 182 } 216 if (!pd) 217 { 218 errno = EBADF; 219 rc = -1; 220 goto errorout; 221 } 222 if (!S_ISSOCK(pd->mode)) 223 { 224 errno = ENOTSOCK; 225 rc = -1; 226 goto errorout; 227 } 228 rc = pd->fsops->ioctl(pd->true_fd, request, ap); 183 229 va_end(ap); 230 errorout: 184 231 return rc; 185 232 } … … 191 238 192 239 pd = pvfs_find_descriptor(sockfd); 193 if (pd) 194 { 195 rc = pd->fsops->listen(pd->true_fd, backlog); 196 } 197 else 198 { 199 rc = -1; 200 errno = EBADF; 201 } 240 if (!pd) 241 { 242 errno = EBADF; 243 rc = -1; 244 goto errorout; 245 } 246 if (!S_ISSOCK(pd->mode)) 247 { 248 errno = ENOTSOCK; 249 rc = -1; 250 goto errorout; 251 } 252 rc = pd->fsops->listen(pd->true_fd, backlog); 253 errorout: 202 254 return rc; 203 255 } … … 209 261 210 262 pd = pvfs_find_descriptor(sockfd); 211 if (pd) 212 { 213 rc = pd->fsops->recv(pd->true_fd, buf, len, flags); 214 } 215 else 216 { 217 rc = -1; 218 errno = EBADF; 219 } 263 if (!pd) 264 { 265 errno = EBADF; 266 rc = -1; 267 goto errorout; 268 } 269 if (!S_ISSOCK(pd->mode)) 270 { 271 errno = ENOTSOCK; 272 rc = -1; 273 goto errorout; 274 } 275 rc = pd->fsops->recv(pd->true_fd, buf, len, flags); 276 errorout: 220 277 return rc; 221 278 } … … 228 285 229 286 pd = pvfs_find_descriptor(sockfd); 230 if (pd) 231 { 232 rc = pd->fsops->recvfrom(pd->true_fd, buf, len, flags, addr, alen); 233 } 234 else 235 { 236 rc = -1; 237 errno = EBADF; 238 } 287 if (!pd) 288 { 289 errno = EBADF; 290 rc = -1; 291 goto errorout; 292 } 293 if (!S_ISSOCK(pd->mode)) 294 { 295 errno = ENOTSOCK; 296 rc = -1; 297 goto errorout; 298 } 299 rc = pd->fsops->recvfrom(pd->true_fd, buf, len, flags, addr, alen); 300 errorout: 239 301 return rc; 240 302 } … … 246 308 247 309 pd = pvfs_find_descriptor(sockfd); 248 if (pd) 249 { 250 rc = pd->fsops->recvmsg(pd->true_fd, msg, flags); 251 } 252 else 253 { 254 rc = -1; 255 errno = EBADF; 256 } 310 if (!pd) 311 { 312 errno = EBADF; 313 rc = -1; 314 goto errorout; 315 } 316 if (!S_ISSOCK(pd->mode)) 317 { 318 errno = ENOTSOCK; 319 rc = -1; 320 goto errorout; 321 } 322 rc = pd->fsops->recvmsg(pd->true_fd, msg, flags); 323 errorout: 257 324 return rc; 258 325 } … … 273 340 274 341 pd = pvfs_find_descriptor(sockfd); 275 if (pd) 276 { 277 rc = pd->fsops->send(pd->true_fd, buf, len, flags); 278 } 279 else 280 { 281 rc = -1; 282 errno = EBADF; 283 } 342 if (!pd) 343 { 344 errno = EBADF; 345 rc = -1; 346 goto errorout; 347 } 348 if (!S_ISSOCK(pd->mode)) 349 { 350 errno = ENOTSOCK; 351 rc = -1; 352 goto errorout; 353 } 354 rc = pd->fsops->send(pd->true_fd, buf, len, flags); 355 errorout: 284 356 return rc; 285 357 } … … 292 364 293 365 pd = pvfs_find_descriptor(sockfd); 294 if (pd) 295 { 296 rc = pd->fsops->sendto(pd->true_fd, buf, len, flags, addr, alen); 297 } 298 else 299 { 300 rc = -1; 301 errno = EBADF; 302 } 366 if (!pd) 367 { 368 errno = EBADF; 369 rc = -1; 370 goto errorout; 371 } 372 if (!S_ISSOCK(pd->mode)) 373 { 374 errno = ENOTSOCK; 375 rc = -1; 376 goto errorout; 377 } 378 rc = pd->fsops->sendto(pd->true_fd, buf, len, flags, addr, alen); 379 errorout: 303 380 return rc; 304 381 } … … 310 387 311 388 pd = pvfs_find_descriptor(sockfd); 312 if (pd) 313 { 314 rc = pd->fsops->sendmsg(pd->true_fd, msg, flags); 315 } 316 else 317 { 318 rc = -1; 319 errno = EBADF; 320 } 389 if (!pd) 390 { 391 errno = EBADF; 392 rc = -1; 393 goto errorout; 394 } 395 if (!S_ISSOCK(pd->mode)) 396 { 397 errno = ENOTSOCK; 398 rc = -1; 399 goto errorout; 400 } 401 rc = pd->fsops->sendmsg(pd->true_fd, msg, flags); 402 errorout: 321 403 return rc; 322 404 } … … 328 410 329 411 pd = pvfs_find_descriptor(sockfd); 330 if (pd) 331 { 332 rc = pd->fsops->shutdown(pd->true_fd, how); 333 } 334 else 335 { 336 rc = -1; 337 errno = EBADF; 338 } 412 if (!pd) 413 { 414 errno = EBADF; 415 rc = -1; 416 goto errorout; 417 } 418 if (!S_ISSOCK(pd->mode)) 419 { 420 errno = ENOTSOCK; 421 rc = -1; 422 goto errorout; 423 } 424 rc = pd->fsops->shutdown(pd->true_fd, how); 425 errorout: 339 426 return rc; 340 427 } … … 342 429 int socketpair (int d, int type, int protocol, int sv[2]) 343 430 { 344 int rc ;345 pvfs_descriptor *pd ;431 int rc = 0; 432 pvfs_descriptor *pd0, *pd1; 346 433 rc = glibc_ops.socketpair(d, type, protocol, sv); 347 434 if (rc < 0) 348 435 { 349 return rc; 350 } 351 pd = pvfs_alloc_descriptor(&glibc_ops); 352 pd->is_in_use = PVFS_FS; 353 pd->true_fd = sv[0]; 354 sv[0] = pd->fd; 355 pd = pvfs_alloc_descriptor(&glibc_ops); 356 pd->is_in_use = PVFS_FS; 357 pd->true_fd = sv[1]; 358 sv[1] = pd->fd; 436 goto errorout; 437 } 438 pd0 = pvfs_alloc_descriptor(&glibc_ops, sv[0]); 439 if (!pd0) 440 { 441 goto errorout; 442 } 443 pd1 = pvfs_alloc_descriptor(&glibc_ops, sv[1]); 444 if (!pd1) 445 { 446 pvfs_free_descriptor(pd0->fd); 447 errno = EMFILE; 448 rc = -1; 449 goto errorout; 450 } 451 pd0->mode |= S_IFSOCK; 452 pd1->mode |= S_IFSOCK; 453 sv[0] = pd0->true_fd; 454 sv[1] = pd1->true_fd; 455 errorout: 359 456 return rc; 360 457 } … … 376 473 goto errorout; 377 474 } 378 f0 = pvfs_alloc_descriptor(&glibc_ops );475 f0 = pvfs_alloc_descriptor(&glibc_ops, fa[0]); 379 476 if (!f0) 380 477 { 381 478 goto errorout; 382 479 } 383 f1 = pvfs_alloc_descriptor(&glibc_ops );480 f1 = pvfs_alloc_descriptor(&glibc_ops, fa[1]); 384 481 if (!f1) 385 482 { 386 pvfs_free_descriptor(f0 );483 pvfs_free_descriptor(f0->fd); 387 484 errno = EMFILE; 388 485 rc = -1; 389 486 goto errorout; 390 487 } 391 f0->true_fd = fa[0]; 392 filedes[0] = f0->fd; 393 f1->true_fd = fa[1]; 394 filedes[1] = f1->fd; 395 /* need to set mode and stuff appropriately */ 488 f0->mode |= S_IFSOCK; 489 f1->mode |= S_IFSOCK; 490 filedes[0] = f0->true_fd; 491 filedes[1] = f1->true_fd; 396 492 errorout: 397 493 return rc; -
branches/Orange-Branch/src/client/usrint/stdio.c
r8899 r9016 10 10 * PVFS2 user interface routines - implementation of stdio for pvfs 11 11 */ 12 /* this prevents headers from using inlines for 64 bit calls */ 13 #ifdef _FILE_OFFSET_BITS 14 #undef _FILE_OFFSET_BITS 15 #endif 16 12 17 #include <usrint.h> 13 18 #include <dirent.h> 14 15 #define ISFLAGSET(s,f) ((stream->_flags & (f)) == (f)) 19 #include <openfile-util.h> 20 #include <stdio-ops.h> 21 22 #define STDIO_DEBUG 0 23 24 static void init_stdio(void); 25 static struct stdio_ops_s stdio_ops; 26 27 #define _P_IO_MAGIC 0xF0BD0000 28 #define SETMAGIC(s,m) do{(s)->_flags = (m) & _IO_MAGIC_MASK;}while(0) 29 #define ISMAGICSET(s,m) (((s)->_flags & _IO_MAGIC_MASK) == (m)) 30 #define SETFLAG(s,f) do{(s)->_flags |= ((f) & ~_IO_MAGIC_MASK);}while(0) 31 #define CLEARFLAG(s,f) do{(s)->_flags &= ~((f) & ~_IO_MAGIC_MASK);}while(0) 32 #define ISFLAGSET(s,f) (((s)->_flags & (f)) == (f)) 16 33 17 34 /* STDIO implementation - this gives users something to link to … … 27 44 */ 28 45 struct __dirstream { 29 int flags; /**< general flags field */ 30 int fileno; /**< file dscriptor of open dir */ 31 char *buf_base; /**< pointer to beginning of buffer */ 32 char *buf_end; /**< pointer to end of buffer */ 33 char *buf_act; /**< pointer to end of active portion of buffer */ 34 char *buf_ptr; /**< pointer to current position in buffer */ 46 int _flags; /**< general flags field */ 47 int fileno; /**< file dscriptor of open dir */ 48 struct dirent de; /**< pointer to dirent read by readdir */ 49 char *buf_base; /**< pointer to beginning of buffer */ 50 char *buf_end; /**< pointer to end of buffer */ 51 char *buf_act; /**< pointer to end of active portion of buffer */ 52 char *buf_ptr; /**< pointer to current position in buffer */ 35 53 }; 36 54 37 #define DIRSTREAM_MAGIC 0x fd10000055 #define DIRSTREAM_MAGIC 0xFD100000 38 56 #define DIRBUFSIZE (512*1024) 39 57 #define ASIZE 256 40 58 #define MAXTRIES 16 /* arbitrary - how many tries to get a unique file name */ 41 59 60 /** These functions lock and unlock the stream structure 61 * 62 * These are only called within our library, so we assume that the 63 * stream is good, that it is our stream (and not glibc's) and we 64 * check for the flag to see if the lock is being used. 65 */ 66 67 static inline void lock_init_stream(FILE *stream) 68 { 69 #ifdef _IO_MTSAFE_IO 70 if (ISFLAGSET(stream, _IO_USER_LOCK)) 71 { 72 _IO_lock_init(stream->_lock); 73 } 74 #endif 75 } 76 77 static inline void lock_stream(FILE *stream) 78 { 79 #ifdef _IO_MTSAFE_IO 80 if (ISFLAGSET(stream, _IO_USER_LOCK)) 81 { 82 _IO_lock_lock(stream->_lock); 83 } 84 #endif 85 } 86 87 static inline int trylock_stream(FILE *stream) 88 { 89 #ifdef _IO_MTSAFE_IO 90 if (ISFLAGSET(stream, _IO_USER_LOCK)) 91 { 92 return _IO_lock_try(stream->_lock); 93 } 94 #else 95 return 0; 96 #endif 97 } 98 99 static inline void unlock_stream(FILE *stream) 100 { 101 #ifdef _IO_MTSAFE_IO 102 if (ISFLAGSET(stream, _IO_USER_LOCK)) 103 { 104 _IO_lock_unlock(stream->_lock); 105 } 106 #endif 107 } 108 109 static inline void lock_fini_stream(FILE *stream) 110 { 111 #ifdef _IO_MTSAFE_IO 112 if (ISFLAGSET(stream, _IO_USER_LOCK)) 113 { 114 _IO_lock_fini(stream->_lock); 115 } 116 #endif 117 } 118 119 /** POSIX interface for user level locking of streams *. 120 * 121 */ 122 void flockfile(FILE *stream) 123 { 124 lock_stream(stream); 125 } 126 127 int ftrylockfile(FILE *stream) 128 { 129 return trylock_stream(stream); 130 } 131 132 void funlockfile(FILE *stream) 133 { 134 unlock_stream(stream); 135 } 136 42 137 /** This function coverts from stream style mode to ssycall style flags 43 138 * … … 45 140 static int mode2flags(const char *mode) 46 141 { 47 int i ;48 int flags ;142 int i = 0; 143 int flags = 0; 49 144 int append = false, read = false, write = false, update = false; 50 145 int exclusive = false; … … 110 205 return -1; 111 206 } 112 if (read) 207 if (read && update) 208 { 209 flags = O_RDWR; 210 } 211 else if(read) 113 212 { 114 213 flags = O_RDONLY; 115 214 } 116 else if( read&& update)215 else if(write && update) 117 216 { 118 flags = O_RDWR ;119 } 217 flags = O_RDWR | O_CREAT | O_TRUNC; 218 } 120 219 else if(write) 121 220 { 122 221 flags = O_WRONLY | O_CREAT | O_TRUNC; 222 } 223 else if(append && update) 224 { 225 flags = O_RDWR | O_APPEND | O_CREAT; 123 226 } 124 else if(write && update) 125 { 126 flags = O_RDWR | O_CREAT | O_TRUNC; 127 } 128 else if(append) 227 else if (append) 129 228 { 130 229 flags = O_WRONLY | O_APPEND | O_CREAT; 131 }132 else if (append && update)133 {134 flags = O_RDWR | O_APPEND | O_CREAT;135 230 } 136 231 if (exclusive) /* check this regardless of the above */ … … 173 268 { 174 269 /* set up stream here */ 175 stream->_flags = _IO_MAGIC;270 SETMAGIC(stream, _P_IO_MAGIC); 176 271 if (!(flags & O_WRONLY)) 177 stream->_flags |= _IO_NO_READS;272 SETFLAG(stream, _IO_NO_READS); 178 273 if (!(flags & O_RDONLY)) 179 stream->_flags |= _IO_NO_WRITES;274 SETFLAG(stream, _IO_NO_WRITES); 180 275 /* set up default buffering here */ 181 276 stream->_IO_buf_base = (char *)malloc(bufsize); … … 215 310 memset(newfile, 0, sizeof(FILE)); 216 311 312 /* initize lock for this stream */ 313 SETFLAG(newfile, _IO_USER_LOCK); 314 lock_init_stream(newfile); 315 217 316 newfile->_fileno = fd; 218 317 rc = init_stream(newfile, flags, PVFS_BUFSIZE); … … 232 331 int fd = 0; 233 332 int flags = 0; 333 if (!stream || !ISMAGICSET(stream, _P_IO_MAGIC)) 334 { 335 if (stream && ISMAGICSET(stream, _IO_MAGIC)) 336 { 337 init_stdio(); 338 return stdio_ops.freopen(path, mode, stream); 339 } 340 errno = EINVAL; 341 return NULL; 342 } 343 lock_stream(stream); 234 344 /* see if stream is in use - if so close the file */ 235 345 if (stream->_fileno > -1) … … 239 349 if (rc == -1) 240 350 { 351 unlock_stream(stream); 241 352 return NULL; 242 353 } … … 250 361 if (fd == -1) 251 362 { 363 unlock_stream(stream); 252 364 return NULL; 253 365 } … … 259 371 init_stream(stream, flags, PVFS_BUFSIZE); 260 372 373 unlock_stream(stream); 261 374 return stream; 262 375 } … … 276 389 size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream) 277 390 { 391 int rc = 0; 392 393 if (!stream || !ISMAGICSET(stream, _P_IO_MAGIC)) 394 { 395 if (stream && ISMAGICSET(stream, _IO_MAGIC)) 396 { 397 init_stdio(); 398 return stdio_ops.fwrite(ptr, size, nmemb, stream); 399 } 400 errno = EINVAL; 401 return -1; 402 } 403 lock_stream(stream); 404 rc = fwrite_unlocked(ptr, size, nmemb, stream); 405 unlock_stream(stream); 406 return rc; 407 } 408 409 size_t fwrite_unlocked(const void *ptr, size_t size, size_t nmemb, FILE *stream) 410 { 278 411 off64_t rsz, rsz_buf, rsz_extra; 279 412 int rc; 280 413 281 if (!stream || !ISFLAGSET(stream, _IO_MAGIC) || 282 ISFLAGSET(stream, _IO_NO_WRITES) || 283 !ptr || size <= 0 || nmemb <= 0) 414 if (!stream || !ISMAGICSET(stream, _P_IO_MAGIC)) 415 { 416 if (stream && ISMAGICSET(stream, _IO_MAGIC)) 417 { 418 init_stdio(); 419 return stdio_ops.fwrite(ptr, size, nmemb, stream); 420 } 421 errno = EINVAL; 422 return -1; 423 } 424 if (!ptr || size <= 0 || nmemb <= 0) 284 425 { 285 426 errno = EINVAL; … … 290 431 if (!ISFLAGSET(stream, _IO_CURRENTLY_PUTTING)) 291 432 { 292 /* write buffer back */293 rc = write(stream->_fileno, stream->_IO_write_base,294 stream->_IO_write_ptr - stream->_IO_write_base);295 if (rc == -1)296 {297 stream->_flags |= _IO_ERR_SEEN;298 return -1;299 }300 433 /* reset read pointer */ 301 434 stream->_IO_read_ptr = stream->_IO_read_end; 302 435 /* set flag */ 303 stream->_flags |= _IO_CURRENTLY_PUTTING;436 SETFLAG(stream, _IO_CURRENTLY_PUTTING); 304 437 /* indicate read buffer empty */ 305 438 stream->_IO_read_end = stream->_IO_read_base; … … 324 457 { 325 458 /* buffer is full - write the current buffer */ 459 #if STDIO_DEBUG 460 fprintf(stderr,"fwrite writing %d bytes to offset %d\n", 461 (int)(stream->_IO_write_ptr - stream->_IO_write_base), 462 (int)lseek(stream->_fileno, 0, SEEK_CUR)); 463 #endif 326 464 rc = write(stream->_fileno, stream->_IO_write_base, 327 465 stream->_IO_write_ptr - stream->_IO_write_base); 328 466 if (rc == -1) 329 467 { 330 stream->_flags |= _IO_ERR_SEEN;468 SETFLAG(stream, _IO_ERR_SEEN); 331 469 return -1; 332 470 } … … 336 474 if(rsz_extra > stream->_IO_buf_end - stream->_IO_buf_base) 337 475 { 476 #if STDIO_DEBUG 477 fprintf(stderr,"fwrite writing %d bytes to offset %d\n", 478 (int)rsz_extra, 479 (int)lseek(stream->_fileno, 0, SEEK_CUR)); 480 #endif 338 481 /* write data directly */ 339 482 rc = write(stream->_fileno, ptr + rsz_buf, rsz_extra); 340 483 if (rc == -1) 341 484 { 342 stream->_flags |= _IO_ERR_SEEN;485 SETFLAG(stream, _IO_ERR_SEEN); 343 486 return -1; 344 487 } … … 359 502 size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream) 360 503 { 361 int fd; 504 int rc = 0; 505 506 if (!stream || !ISMAGICSET(stream, _P_IO_MAGIC)) 507 { 508 if (stream && ISMAGICSET(stream, _IO_MAGIC)) 509 { 510 init_stdio(); 511 return stdio_ops.fwrite(ptr, size, nmemb, stream); 512 } 513 errno = EINVAL; 514 return -1; 515 } 516 lock_stream(stream); 517 rc = fread_unlocked(ptr, size, nmemb, stream); 518 unlock_stream(stream); 519 return rc; 520 } 521 522 size_t fread_unlocked(void *ptr, size_t size, size_t nmemb, FILE *stream) 523 { 362 524 int rsz, rsz_buf, rsz_extra; 363 525 int bytes_read; 364 526 int rc; 365 527 366 if (!stream || !ISFLAGSET(stream, _IO_MAGIC) || 367 ISFLAGSET(stream, _IO_NO_READS) || 368 !ptr || size < 0 || nmemb < 0) 528 if (!stream || !ISMAGICSET(stream, _P_IO_MAGIC)) 529 { 530 if (stream && ISMAGICSET(stream, _IO_MAGIC)) 531 { 532 init_stdio(); 533 return stdio_ops.fread(ptr, size, nmemb, stream); 534 } 535 errno = EINVAL; 536 return -1; 537 } 538 if (!ptr || size < 0 || nmemb < 0) 369 539 { 370 540 errno = EINVAL; … … 376 546 { 377 547 /* write buffer back */ 548 #if STDIO_DEBUG 549 fprintf(stderr,"fread writing %d bytes to offset %d\n", 550 (int)(stream->_IO_write_ptr - stream->_IO_write_base), 551 (int)lseek(stream->_fileno, 0, SEEK_CUR)); 552 #endif 378 553 rc = write(stream->_fileno, stream->_IO_write_base, 379 554 stream->_IO_write_ptr - stream->_IO_write_base); 380 555 if (rc == -1) 381 556 { 382 stream->_flags |= _IO_ERR_SEEN;557 SETFLAG(stream, _IO_ERR_SEEN); 383 558 return -1; 384 559 } … … 386 561 stream->_IO_write_ptr = stream->_IO_write_base; 387 562 /* clear flag */ 388 stream->_flags &= ~_IO_CURRENTLY_PUTTING;563 CLEARFLAG(stream, _IO_CURRENTLY_PUTTING); 389 564 /* indicate read buffer empty */ 390 565 stream->_IO_read_end = stream->_IO_read_base; … … 401 576 if (bytes_read == -1) 402 577 { 403 stream->_flags |= _IO_ERR_SEEN;578 SETFLAG(stream, _IO_ERR_SEEN); 404 579 return -1; 405 580 } … … 440 615 if (bytes_read == -1) 441 616 { 442 stream->_flags |= _IO_ERR_SEEN;617 SETFLAG(stream, _IO_ERR_SEEN); 443 618 return -1; 444 619 } … … 450 625 if (bytes_read == -1) 451 626 { 452 stream->_flags |= _IO_ERR_SEEN;627 SETFLAG(stream, _IO_ERR_SEEN); 453 628 return -1; 454 629 } … … 458 633 } 459 634 /* have read to EOF */ 460 stream->_flags |= _IO_EOF_SEEN;635 SETFLAG(stream, _IO_EOF_SEEN); 461 636 return rsz_buf + bytes_read; 462 637 } … … 466 641 if (bytes_read == -1) 467 642 { 468 stream->_flags |= _IO_ERR_SEEN;643 SETFLAG(stream, _IO_ERR_SEEN); 469 644 return -1; 470 645 } … … 481 656 if (rsz_buf + rsz_extra < rsz) 482 657 { 483 stream->_flags |= _IO_EOF_SEEN;658 SETFLAG(stream, _IO_EOF_SEEN); 484 659 } 485 660 return rsz_buf + rsz_extra; … … 488 663 { 489 664 /* at EOF so return bytes read */ 490 stream->_flags |= _IO_EOF_SEEN;665 SETFLAG(stream, _IO_EOF_SEEN); 491 666 return rsz_buf; 492 667 } … … 501 676 int fclose(FILE *stream) 502 677 { 503 int rc; 504 if (!stream || !ISFLAGSET(stream, _IO_MAGIC)) 505 { 506 errno = EINVAL; 507 return -1; 508 } 678 int rc = 0; 679 if (!stream || !ISMAGICSET(stream, _P_IO_MAGIC)) 680 { 681 if (stream && ISMAGICSET(stream, _IO_MAGIC)) 682 { 683 init_stdio(); 684 return stdio_ops.fclose(stream); 685 } 686 errno = EINVAL; 687 return -1; 688 } 689 lock_stream(stream); 509 690 /* write any pending data */ 510 691 if (ISFLAGSET(stream, _IO_CURRENTLY_PUTTING)) … … 512 693 if (stream->_IO_write_ptr > stream->_IO_write_base) 513 694 { 514 rc = write(stream->_fileno, stream->_IO_write_ptr, 515 stream->_IO_write_ptr - stream->_IO_write_base); 695 #if STDIO_DEBUG 696 fprintf(stderr,"fclose writing %d bytes to offset %d\n", 697 (int)(stream->_IO_write_ptr - stream->_IO_write_base), 698 (int)lseek(stream->_fileno, 0, SEEK_CUR)); 699 #endif 700 rc = write(stream->_fileno, stream->_IO_write_base, 701 stream->_IO_write_ptr - stream->_IO_write_base); 516 702 if (rc == -1) 517 703 { 704 SETFLAG(stream, _IO_ERR_SEEN); 518 705 return -1; 519 706 } … … 527 714 if (!ISFLAGSET(stream, _IO_DELETE_DONT_CLOSE)) 528 715 { 529 return close(stream->_fileno); 530 } 716 rc = close(stream->_fileno); 717 } 718 stream->_flags = 0; 719 /* can stream be locked here */ 720 lock_fini_stream(stream); 531 721 free(stream); 532 return 0;722 return rc; 533 723 } 534 724 … … 551 741 { 552 742 int rc = 0; 553 if (!stream || !ISFLAGSET(stream, _IO_MAGIC)) 554 { 555 errno = EINVAL; 556 return -1; 557 } 558 /* if not just getting the position */ 743 if (!stream || !ISMAGICSET(stream, _P_IO_MAGIC)) 744 { 745 if (stream && ISMAGICSET(stream, _IO_MAGIC)) 746 { 747 init_stdio(); 748 return stdio_ops.fseek64(stream, offset, whence); 749 } 750 errno = EINVAL; 751 return -1; 752 } 753 lock_stream(stream); 754 /* if actually changing the position */ 559 755 if ((offset != 0L) || (whence != SEEK_CUR)) 560 756 { 561 757 int64_t filepos, fileend; 758 struct stat sbuf; 562 759 filepos = lseek64(stream->_fileno, 0, SEEK_CUR); 563 fileend = lseek64(stream->_fileno, 0, SEEK_END); 760 /* should fileend include stuff in write buffer ??? */ 761 rc = fstat(stream->_fileno, &sbuf); 762 if (rc < 0) 763 { 764 SETFLAG(stream, _IO_ERR_SEEN); 765 rc = -1; 766 goto exitout; 767 } 768 fileend = sbuf.st_size; 564 769 /* figure out if we are only seeking within the */ 565 770 /* bounds of the current buffer to minimize */ … … 570 775 { 571 776 stream->_IO_write_ptr += offset; 572 return 0; 777 /* should we zero out buffer if past eof ??? */ 778 rc = 0; 779 goto exitout; 573 780 } 574 781 if (whence == SEEK_CUR && !ISFLAGSET(stream, _IO_CURRENTLY_PUTTING) && … … 577 784 { 578 785 stream->_IO_read_ptr += offset; 579 return 0; 786 rc = 0; 787 goto exitout; 580 788 } 581 789 if (whence == SEEK_SET && ISFLAGSET(stream, _IO_CURRENTLY_PUTTING) && … … 584 792 { 585 793 stream->_IO_write_ptr += offset - filepos; 586 return 0; 794 /* should we zero out buffer if past eof ??? */ 795 rc = 0; 796 goto exitout; 587 797 } 588 798 if (whence == SEEK_SET && !ISFLAGSET(stream, _IO_CURRENTLY_PUTTING) && … … 591 801 { 592 802 stream->_IO_read_ptr += offset - filepos; 593 return 0; 803 rc = 0; 804 goto exitout; 594 805 } 595 806 if (whence == SEEK_END && ISFLAGSET(stream, _IO_CURRENTLY_PUTTING) && … … 599 810 { 600 811 stream->_IO_write_ptr += (fileend - offset) - filepos; 601 return 0; 812 /* should we zero out buffer if past eof ??? */ 813 rc = 0; 814 goto exitout; 602 815 } 603 816 if (whence == SEEK_END && !ISFLAGSET(stream, _IO_CURRENTLY_PUTTING) && … … 607 820 { 608 821 stream->_IO_read_ptr += (fileend - offset) - filepos; 609 return 0; 822 rc = 0; 823 goto exitout; 610 824 } 611 825 /* at this point the seek is beyond the current buffer */ … … 615 829 { 616 830 /* write buffer back */ 831 #if STDIO_DEBUG 832 fprintf(stderr,"fseek writing %d bytes to offset %d\n", 833 (int)(stream->_IO_write_ptr - stream->_IO_write_base), 834 (int)lseek(stream->_fileno, 0, SEEK_CUR)); 835 #endif 617 836 rc = write(stream->_fileno, stream->_IO_write_base, 618 837 stream->_IO_write_ptr - stream->_IO_write_base); 619 838 if (rc < 0) 620 839 { 621 return rc; 840 SETFLAG(stream, _IO_ERR_SEEN); 841 goto exitout; 622 842 } 623 843 /* reset write pointer */ … … 631 851 stream->_IO_read_ptr = stream->_IO_read_end; 632 852 } 633 lseek64(stream->_fileno, offset, whence); 634 } 635 /* seek to current position, no change */ 636 return 0; 853 rc = lseek64(stream->_fileno, offset, whence); 854 #if STDIO_DEBUG 855 fprintf(stderr,"fseek seeks to offset %d\n", 856 (int)lseek(stream->_fileno, 0, SEEK_CUR)); 857 #endif 858 if (rc < 0) 859 { 860 SETFLAG(stream, _IO_ERR_SEEN); 861 goto exitout; 862 } 863 } 864 exitout: 865 /* successful call */ 866 lock_stream(stream); 867 CLEARFLAG(stream, _IO_EOF_SEEN); 868 return rc; 637 869 } 638 870 … … 652 884 { 653 885 fseek64(stream, 0L, SEEK_SET); 886 CLEARFLAG(stream, _IO_ERR_SEEN); 654 887 } 655 888 … … 665 898 { 666 899 int64_t filepos; 667 if (!stream || !ISFLAGSET(stream, _IO_MAGIC)) 668 { 900 if (!stream || !ISMAGICSET(stream, _P_IO_MAGIC)) 901 { 902 if (stream && ISMAGICSET(stream, _IO_MAGIC)) 903 { 904 init_stdio(); 905 return stdio_ops.ftell64(stream); 906 } 669 907 errno = EINVAL; 670 908 return -1; … … 698 936 int fflush(FILE *stream) 699 937 { 938 int rc = 0; 939 940 if (!stream || !ISMAGICSET(stream, _P_IO_MAGIC)) 941 { 942 if (stream && ISMAGICSET(stream, _IO_MAGIC)) 943 { 944 init_stdio(); 945 return stdio_ops.fflush(stream); 946 } 947 errno = EINVAL; 948 return -1; 949 } 950 lock_stream(stream); 951 rc = fflush_unlocked(stream); 952 unlock_stream(stream); 953 return rc; 954 } 955 956 int fflush_unlocked(FILE *stream) 957 { 700 958 int rc; 701 if (!stream || !ISFLAGSET(stream, _IO_MAGIC)) 702 { 703 errno = EBADF; 959 if (!stream || !ISMAGICSET(stream, _P_IO_MAGIC)) 960 { 961 if (stream && ISMAGICSET(stream, _IO_MAGIC)) 962 { 963 init_stdio(); 964 return stdio_ops.fflush(stream); 965 } 966 errno = EINVAL; 704 967 return -1; 705 968 } … … 709 972 { 710 973 /* write buffer back */ 974 #if STDIO_DEBUG 975 fprintf(stderr,"fflush writing %d bytes to offset %d\n", 976 (int)(stream->_IO_write_ptr - stream->_IO_write_base), 977 (int)lseek(stream->_fileno, 0, SEEK_CUR)); 978 #endif 711 979 rc = write(stream->_fileno, stream->_IO_write_base, 712 980 stream->_IO_write_ptr - stream->_IO_write_base); 713 981 if (rc < 0) 714 982 { 715 stream->_flags |= _IO_ERR_SEEN;983 SETFLAG(stream, _IO_ERR_SEEN); 716 984 return rc; 717 985 } … … 727 995 int fputc(int c, FILE *stream) 728 996 { 997 int rc = 0; 998 999 if (!stream || !ISMAGICSET(stream, _P_IO_MAGIC)) 1000 { 1001 if (stream && ISMAGICSET(stream, _IO_MAGIC)) 1002 { 1003 init_stdio(); 1004 return stdio_ops.fputc(c, stream); 1005 } 1006 errno = EINVAL; 1007 return -1; 1008 } 1009 lock_stream(stream); 1010 rc = fputc_unlocked(c, stream); 1011 unlock_stream(stream); 1012 return rc; 1013 } 1014 1015 int fputc_unlocked(int c, FILE *stream) 1016 { 729 1017 int rc; 730 rc = fwrite (&c, 1, 1, stream);1018 rc = fwrite_unlocked(&c, 1, 1, stream); 731 1019 if (ferror(stream)) 732 1020 { … … 740 1028 */ 741 1029 int fputs(const char *s, FILE *stream) 1030 { 1031 int rc = 0; 1032 1033 if (!stream || !ISMAGICSET(stream, _P_IO_MAGIC)) 1034 { 1035 if (stream && ISMAGICSET(stream, _IO_MAGIC)) 1036 { 1037 init_stdio(); 1038 return stdio_ops.fputs(s, stream); 1039 } 1040 errno = EINVAL; 1041 return -1; 1042 } 1043 lock_stream(stream); 1044 rc = fputs_unlocked(s, stream); 1045 unlock_stream(stream); 1046 return rc; 1047 } 1048 1049 int fputs_unlocked(const char *s, FILE *stream) 742 1050 { 743 1051 size_t len; … … 749 1057 } 750 1058 len = strlen(s); 751 rc = fwrite (s, len, 1, stream);1059 rc = fwrite_unlocked(s, len, 1, stream); 752 1060 if (ferror(stream)) 753 1061 { … … 765 1073 } 766 1074 1075 int putc_unlocked(int c, FILE *stream) 1076 { 1077 return fputc_unlocked(c, stream); 1078 } 1079 767 1080 /** 768 1081 * putchar wrapper … … 771 1084 { 772 1085 return fputc(c, stdout); 1086 } 1087 1088 int putchar_unlocked(int c) 1089 { 1090 return fputc_unlocked(c, stdout); 773 1091 } 774 1092 … … 792 1110 char *fgets(char *s, int size, FILE *stream) 793 1111 { 1112 char *rc = NULL; 1113 1114 if (!stream || !ISMAGICSET(stream, _P_IO_MAGIC)) 1115 { 1116 if (stream && ISMAGICSET(stream, _IO_MAGIC)) 1117 { 1118 init_stdio(); 1119 return stdio_ops.fgets(s, size, stream); 1120 } 1121 errno = EINVAL; 1122 return NULL; 1123 } 1124 lock_stream(stream); 1125 rc = fgets_unlocked(s, size, stream); 1126 unlock_stream(stream); 1127 return rc; 1128 } 1129 1130 char *fgets_unlocked(char *s, int size, FILE *stream) 1131 { 794 1132 char c, *p; 795 1133 … … 807 1145 size--; 808 1146 do { 809 *p++ = c = fgetc(stream); 810 } while (--size && c != '\n' && !feof(stream) && !ferror(stream)); 811 if (ferror(stream)) 1147 *p++ = c = fgetc_unlocked(stream); 1148 } while (--size && c != '\n' && !feof_unlocked(stream) 1149 && !ferror_unlocked(stream)); 1150 if (ferror_unlocked(stream)) 812 1151 { 813 1152 return NULL; … … 832 1171 } 833 1172 1173 int fgetc_unlocked(FILE *stream) 1174 { 1175 int rc, ch; 1176 1177 rc = fread_unlocked(&ch, 1, 1, stream); 1178 if (ferror(stream)) 1179 { 1180 return EOF; 1181 } 1182 return ch; 1183 } 1184 834 1185 /** 835 1186 * getc wrapper … … 839 1190 return fgetc(stream); 840 1191 } 1192 int getc_unlocked(FILE *stream) 1193 { 1194 return fgetc_unlocked(stream); 1195 } 841 1196 842 1197 /** … … 846 1201 { 847 1202 return fgetc(stdin); 1203 } 1204 1205 int getchar_unlocked(void) 1206 { 1207 return fgetc_unlocked(stdin); 848 1208 } 849 1209 … … 964 1324 void clearerr (FILE *stream) 965 1325 { 966 if (!stream || !ISFLAGSET(stream, _IO_MAGIC)) 967 { 1326 if (!stream || !ISMAGICSET(stream, _P_IO_MAGIC)) 1327 { 1328 if (stream && ISMAGICSET(stream, _IO_MAGIC)) 1329 { 1330 init_stdio(); 1331 stdio_ops.clearerr(stream); 1332 return; 1333 } 968 1334 return; 969 1335 } 970 stream->_flags &= ~_IO_ERR_SEEN; 971 stream->_flags &= ~_IO_EOF_SEEN; 1336 lock_stream(stream); 1337 CLEARFLAG(stream, _IO_ERR_SEEN); 1338 CLEARFLAG(stream, _IO_EOF_SEEN); 1339 unlock_stream(stream); 1340 } 1341 1342 void clearerr_unlocked (FILE *stream) 1343 { 1344 if (!stream || !ISMAGICSET(stream, _P_IO_MAGIC)) 1345 { 1346 if (stream && ISMAGICSET(stream, _IO_MAGIC)) 1347 { 1348 init_stdio(); 1349 stdio_ops.clearerr(stream); 1350 return; 1351 } 1352 return; 1353 } 1354 CLEARFLAG(stream, _IO_ERR_SEEN); 1355 CLEARFLAG(stream, _IO_EOF_SEEN); 972 1356 } 973 1357 … … 977 1361 int feof (FILE *stream) 978 1362 { 979 if (!stream || !ISFLAGSET(stream, _IO_MAGIC)) 980 { 1363 int rc = 0; 1364 1365 if (!stream || !ISMAGICSET(stream, _P_IO_MAGIC)) 1366 { 1367 if (stream && ISMAGICSET(stream, _IO_MAGIC)) 1368 { 1369 init_stdio(); 1370 return stdio_ops.feof(stream); 1371 } 1372 errno = EINVAL; 1373 return -1; 1374 } 1375 lock_stream(stream); 1376 rc = ISFLAGSET(stream, _IO_EOF_SEEN); 1377 unlock_stream(stream); 1378 return rc; 1379 } 1380 1381 int feof_unlocked (FILE *stream) 1382 { 1383 if (!stream || !ISMAGICSET(stream, _P_IO_MAGIC)) 1384 { 1385 if (stream && ISMAGICSET(stream, _IO_MAGIC)) 1386 { 1387 init_stdio(); 1388 return stdio_ops.feof(stream); 1389 } 981 1390 errno = EBADF; 982 1391 return -1; 983 1392 } 984 return stream->_flags & _IO_EOF_SEEN;1393 return ISFLAGSET(stream, _IO_EOF_SEEN); 985 1394 } 986 1395 … … 990 1399 int ferror (FILE *stream) 991 1400 { 992 if (!stream || !ISFLAGSET(stream, _IO_MAGIC)) 993 { 1401 int rc = 0; 1402 1403 if (!stream || !ISMAGICSET(stream, _P_IO_MAGIC)) 1404 { 1405 if (stream && ISMAGICSET(stream, _IO_MAGIC)) 1406 { 1407 init_stdio(); 1408 return stdio_ops.ferror(stream); 1409 } 1410 errno = EINVAL; 1411 return -1; 1412 } 1413 lock_stream(stream); 1414 rc = ISFLAGSET(stream, _IO_ERR_SEEN); 1415 unlock_stream(stream); 1416 return rc; 1417 } 1418 1419 int ferror_unlocked (FILE *stream) 1420 { 1421 if (!stream || !ISMAGICSET(stream, _P_IO_MAGIC)) 1422 { 1423 if (stream && ISMAGICSET(stream, _IO_MAGIC)) 1424 { 1425 init_stdio(); 1426 return stdio_ops.ferror(stream); 1427 } 994 1428 errno = EBADF; 995 1429 return -1; 996 1430 } 997 return stream->_flags & _IO_ERR_SEEN;1431 return ISFLAGSET(stream, _IO_ERR_SEEN); 998 1432 } 999 1433 … … 1003 1437 int fileno (FILE *stream) 1004 1438 { 1005 if (!stream || !ISFLAGSET(stream, _IO_MAGIC)) 1006 { 1439 int rc = 0; 1440 1441 if (!stream || !ISMAGICSET(stream, _P_IO_MAGIC)) 1442 { 1443 if (stream && ISMAGICSET(stream, _IO_MAGIC)) 1444 { 1445 init_stdio(); 1446 return stdio_ops.fileno(stream); 1447 } 1448 errno = EINVAL; 1449 return -1; 1450 } 1451 lock_stream(stream); 1452 rc = stream->_fileno; 1453 unlock_stream(stream); 1454 return rc; 1455 } 1456 1457 int fileno_unlocked (FILE *stream) 1458 { 1459 if (!stream || !ISMAGICSET(stream, _P_IO_MAGIC)) 1460 { 1461 if (stream && ISMAGICSET(stream, _IO_MAGIC)) 1462 { 1463 init_stdio(); 1464 return stdio_ops.fileno(stream); 1465 } 1007 1466 errno = EBADF; 1008 1467 return -1; … … 1051 1510 /** 1052 1511 * 1053 * This should only be called on a stream that has be n opened1054 * but not used so we can assume any exitin fbuff is not dirty1512 * This should only be called on a stream that has been opened 1513 * but not used so we can assume any exiting buff is not dirty 1055 1514 */ 1056 1515 int setvbuf (FILE *stream, char *buf, int mode, size_t size) 1057 1516 { 1058 if (!stream || !ISFLAGSET(stream, _IO_MAGIC)) 1059 { 1060 errno = EBADF; 1517 if (!stream || !ISMAGICSET(stream, _P_IO_MAGIC)) 1518 { 1519 if (stream && ISMAGICSET(stream, _IO_MAGIC)) 1520 { 1521 init_stdio(); 1522 return stdio_ops.setvbuf(stream, buf, mode, size); 1523 } 1524 errno = EINVAL; 1061 1525 return -1; 1062 1526 } … … 1065 1529 { 1066 1530 /* fread or fwrite has been called */ 1067 errno - EINVAL; 1068 return -1; 1069 } 1531 errno = EINVAL; 1532 return -1; 1533 } 1534 lock_stream(stream); 1070 1535 switch (mode) 1071 1536 { … … 1074 1539 break; 1075 1540 case _IOLBF : /* line buffered */ 1076 stream->_flags |= _IO_LINE_BUF; /* TODO: This is not implemented */1541 SETFLAG(stream, _IO_LINE_BUF); /* TODO: This is not implemented */ 1077 1542 break; 1078 1543 case _IONBF : /* not buffered */ 1079 stream->_flags |= _IO_UNBUFFERED; /* TODO: This is not implemented */1544 SETFLAG(stream, _IO_UNBUFFERED); /* TODO: This is not implemented */ 1080 1545 break; 1081 1546 default : 1082 1547 errno = EINVAL; 1548 unlock_stream(stream); 1083 1549 return -1; 1084 1550 } 1085 1551 if (buf && size > 0) 1086 1552 { 1087 stream->_flags |= _IO_USER_BUF;1553 SETFLAG(stream, _IO_USER_BUF); 1088 1554 free(stream->_IO_buf_base); 1089 1555 stream->_IO_buf_base = buf; … … 1096 1562 stream->_IO_write_end = stream->_IO_buf_end; 1097 1563 } 1564 unlock_stream(stream); 1565 return 0; 1098 1566 } 1099 1567 … … 1201 1669 } 1202 1670 fd = open(name, O_RDONLY|O_DIRECTORY); 1203 if (fd == -1);1671 if (fd < 0) 1204 1672 { 1205 1673 return NULL; … … 1219 1687 return NULL; 1220 1688 } 1221 dstr->flags = DIRSTREAM_MAGIC;1689 SETMAGIC(dstr, DIRSTREAM_MAGIC); 1222 1690 dstr->fileno = fd; 1223 1691 dstr->buf_base = (char *)malloc(DIRBUFSIZE); … … 1225 1693 dstr->buf_act = dstr->buf_base; 1226 1694 dstr->buf_ptr = dstr->buf_base; 1695 return dstr; 1227 1696 } 1228 1697 … … 1232 1701 int dirfd (DIR *dir) 1233 1702 { 1234 if (!dir || ! (dir->flags ==DIRSTREAM_MAGIC))1703 if (!dir || !ISMAGICSET(dir, DIRSTREAM_MAGIC)) 1235 1704 { 1236 1705 errno = EBADF; … … 1246 1715 { 1247 1716 struct dirent64 *de64; 1248 /* this buffer is so we can return the smaller struct for1249 * single use as is the prerogative of the call. This1250 * approach sucks, not reentrant TODO: find a better way1251 */1252 static struct dirent *de = NULL;1253 1254 if (!de)1255 {1256 de = (struct dirent *)malloc(sizeof(struct dirent));1257 if (!de)1258 {1259 return NULL;1260 }1261 }1262 1717 1263 1718 de64 = readdir64(dir); … … 1266 1721 return NULL; 1267 1722 } 1268 memcpy(de->d_name, de64->d_name, 256); 1269 de->d_ino = de64->d_ino; 1270 /* these are Linux specific fields from the dirent */ 1271 #if 1 1272 de->d_off = de64->d_off; 1273 de->d_reclen = de64->d_reclen; 1274 de->d_type = de64->d_type; 1723 memcpy(dir->de.d_name, de64->d_name, 256); 1724 dir->de.d_ino = de64->d_ino; 1725 /* these are wsystem specific fields from the dirent */ 1726 #ifdef _DIRENT_HAVE_D_NAMELEN 1727 dir->de.d_namelen = strnlen(de64->d_name, 256); 1275 1728 #endif 1276 return de; 1729 #ifdef _DIRENT_HAVE_D_OFF 1730 dir->de.d_off = de64->d_off; 1731 #endif 1732 #ifdef _DIRENT_HAVE_D_RECLEN 1733 dir->de.d_reclen = de64->d_reclen; 1734 #endif 1735 #ifdef _DIRENT_HAVE_D_TYPE 1736 dir->de.d_type = de64->d_type; 1737 #endif 1738 return &dir->de; 1277 1739 } 1278 1740 1279 1741 /** 1280 1742 * reads a single dirent64 in buffered mode from a stream 1281 */ 1743 * 1744 * getdents is not defined in libc, though it is a linux 1745 * system call and we define it in the usr lib 1746 */ 1747 1748 int getdents(int fd, struct dirent *buf, size_t size); 1749 int getdents64(int fd, struct dirent64 *buf, size_t size); 1750 1282 1751 struct dirent64 *readdir64 (DIR *dir) 1283 1752 { 1284 1753 struct dirent64 *rval; 1285 if (!dir || ! (dir->flags ==DIRSTREAM_MAGIC))1754 if (!dir || !ISMAGICSET(dir, DIRSTREAM_MAGIC)) 1286 1755 { 1287 1756 errno = EBADF; … … 1291 1760 { 1292 1761 int bytes_read; 1293 /* read a block of dirent s into the buffer */1294 bytes_read = getdents (dir->fileno,dir->buf_base,1762 /* read a block of dirent64s into the buffer */ 1763 bytes_read = getdents64(dir->fileno, (struct dirent64 *)dir->buf_base, 1295 1764 (dir->buf_end - dir->buf_base)); 1296 1765 dir->buf_act = dir->buf_base + bytes_read; … … 1308 1777 { 1309 1778 off_t filepos; 1310 if (!dir || ! (dir->flags ==DIRSTREAM_MAGIC))1779 if (!dir || !ISMAGICSET(dir, DIRSTREAM_MAGIC)) 1311 1780 { 1312 1781 errno = EBADF; … … 1327 1796 1328 1797 /** 1329 * seeks in a direc otry stream1798 * seeks in a directory stream 1330 1799 */ 1331 1800 void seekdir (DIR *dir, off_t offset) 1332 1801 { 1333 1802 off_t filepos; 1334 if (!dir || ! (dir->flags ==DIRSTREAM_MAGIC))1803 if (!dir || !ISMAGICSET(dir, DIRSTREAM_MAGIC)) 1335 1804 { 1336 1805 errno = EBADF; … … 1357 1826 { 1358 1827 off_t filepos; 1359 if (!dir || ! (dir->flags ==DIRSTREAM_MAGIC))1828 if (!dir || !ISMAGICSET(dir, DIRSTREAM_MAGIC)) 1360 1829 { 1361 1830 errno = EBADF; … … 1375 1844 int closedir (DIR *dir) 1376 1845 { 1377 if (!dir || ! (dir->flags ==DIRSTREAM_MAGIC))1846 if (!dir || !ISMAGICSET(dir, DIRSTREAM_MAGIC)) 1378 1847 { 1379 1848 errno = EBADF; … … 1381 1850 } 1382 1851 free(dir->buf_base); 1383 dir-> flags = 0;1852 dir->_flags = 0; 1384 1853 free(dir); 1385 1854 return 0; … … 1452 1921 * pass in a flag to control the copy of the dirent into the array 1453 1922 */ 1454 int scandir64 (const char *dir, struct dirent64 ***namelist, 1455 int(*filter)(const struct dirent64 *), 1456 int(*compar)(const void *, const void *)) 1923 int scandir64 (const char *dir, 1924 struct dirent64 ***namelist, 1925 int(*filter)(const struct dirent64 *), 1926 int(*compar)(const void *, const void *)) 1457 1927 { 1458 1928 struct dirent64 *de; … … 1510 1980 } 1511 1981 1982 static void init_stdio(void) 1983 { 1984 static int init_flag = 0; 1985 if (init_flag) 1986 { 1987 return; 1988 } 1989 init_flag = 1; 1990 stdio_ops.fopen = dlsym(RTLD_NEXT, "fopen" ); 1991 stdio_ops.fdopen = dlsym(RTLD_NEXT, "fdopen" ); 1992 stdio_ops.freopen = dlsym(RTLD_NEXT, "freopen" ); 1993 stdio_ops.fwrite = dlsym(RTLD_NEXT, "fwrite" ); 1994 stdio_ops.fread = dlsym(RTLD_NEXT, "fread" ); 1995 stdio_ops.fclose = dlsym(RTLD_NEXT, "fclose" ); 1996 stdio_ops.fseek = dlsym(RTLD_NEXT, "fseek" ); 1997 stdio_ops.fseek64 = dlsym(RTLD_NEXT, "fseek64" ); 1998 stdio_ops.fsetpos = dlsym(RTLD_NEXT, "fsetpos" ); 1999 stdio_ops.rewind = dlsym(RTLD_NEXT, "rewind" ); 2000 stdio_ops.ftell = dlsym(RTLD_NEXT, "ftell" ); 2001 stdio_ops.ftell64 = dlsym(RTLD_NEXT, "ftell64" ); 2002 stdio_ops.fgetpos = dlsym(RTLD_NEXT, "fgetpos" ); 2003 stdio_ops.fflush = dlsym(RTLD_NEXT, "fflush" ); 2004 stdio_ops.fputc = dlsym(RTLD_NEXT, "fputc" ); 2005 stdio_ops.fputs = dlsym(RTLD_NEXT, "fputs" ); 2006 stdio_ops.putc = dlsym(RTLD_NEXT, "putc" ); 2007 stdio_ops.putchar = dlsym(RTLD_NEXT, "putchar" ); 2008 stdio_ops.puts = dlsym(RTLD_NEXT, "puts" ); 2009 stdio_ops.fgets = dlsym(RTLD_NEXT, "fgets" ); 2010 stdio_ops.fgetc = dlsym(RTLD_NEXT, "fgetc" ); 2011 stdio_ops.getc = dlsym(RTLD_NEXT, "getc" ); 2012 stdio_ops.getchar = dlsym(RTLD_NEXT, "getchar" ); 2013 stdio_ops.gets = dlsym(RTLD_NEXT, "gets" ); 2014 stdio_ops.ungetc = dlsym(RTLD_NEXT, "ungetc" ); 2015 stdio_ops.vfprintf = dlsym(RTLD_NEXT, "vfprintf" ); 2016 stdio_ops.vprintf = dlsym(RTLD_NEXT, "vprintf" ); 2017 stdio_ops.fprintf = dlsym(RTLD_NEXT, "fprintf" ); 2018 stdio_ops.printf = dlsym(RTLD_NEXT, "printf" ); 2019 stdio_ops.fscanf = dlsym(RTLD_NEXT, "fscanf" ); 2020 stdio_ops.scanf = dlsym(RTLD_NEXT, "scanf" ); 2021 stdio_ops.clearerr = dlsym(RTLD_NEXT, "clearerr" ); 2022 stdio_ops.feof = dlsym(RTLD_NEXT, "feof" ); 2023 stdio_ops.ferror = dlsym(RTLD_NEXT, "ferror" ); 2024 stdio_ops.fileno = dlsym(RTLD_NEXT, "fileno" ); 2025 stdio_ops.remove = dlsym(RTLD_NEXT, "remove" ); 2026 stdio_ops.setbuf = dlsym(RTLD_NEXT, "setbuf" ); 2027 stdio_ops.setbuffer = dlsym(RTLD_NEXT, "setbuffer" ); 2028 stdio_ops.setlinebuf = dlsym(RTLD_NEXT, "setlinebuf" ); 2029 stdio_ops.setvbuf = dlsym(RTLD_NEXT, "setvbuf" ); 2030 stdio_ops.mkdtemp = dlsym(RTLD_NEXT, "mkdtemp" ); 2031 stdio_ops.mkstemp = dlsym(RTLD_NEXT, "mkstemp" ); 2032 stdio_ops.tmpfile = dlsym(RTLD_NEXT, "tmpfile" ); 2033 stdio_ops.opendir = dlsym(RTLD_NEXT, "opendir" ); 2034 stdio_ops.fdopendir = dlsym(RTLD_NEXT, "fdopendir" ); 2035 stdio_ops.dirfd = dlsym(RTLD_NEXT, "dirfd" ); 2036 stdio_ops.readdir = dlsym(RTLD_NEXT, "readdir" ); 2037 stdio_ops.readdir64 = dlsym(RTLD_NEXT, "readdir64" ); 2038 stdio_ops.rewinddir = dlsym(RTLD_NEXT, "rewinddir" ); 2039 stdio_ops.seekdir = dlsym(RTLD_NEXT, "seekdir" ); 2040 stdio_ops.telldir = dlsym(RTLD_NEXT, "telldir" ); 2041 stdio_ops.closedir = dlsym(RTLD_NEXT, "closedir" ); 2042 stdio_ops.scandir = dlsym(RTLD_NEXT, "scandir" ); 2043 stdio_ops.scandir64 = dlsym(RTLD_NEXT, "scandir64" ); 2044 }; 2045 1512 2046 /* 1513 2047 * Local variables: -
branches/Orange-Branch/src/client/usrint/usrint.h
r8975 r9016 13 13 #define USRINT_H 1 14 14 15 #ifndef _LARGEFILE64_SOURCE 15 16 #define _LARGEFILE64_SOURCE 17 #endif 18 #ifndef _GNU_SOURCE 16 19 #define _GNU_SOURCE 20 #endif 17 21 #define __USE_MISC 1 18 22 #define __USE_ATFILE 1 … … 34 38 #include <sys/socket.h> 35 39 #include <sys/resource.h> 36 /* #include <sys/statvfs.h> /* struct statfs on OS X */ 40 #include <sys/sendfile.h> 41 /* #include <sys/statvfs.h> */ /* struct statfs on OS X */ 37 42 #include <sys/vfs.h> /* struct statfs on Linux */ 38 43 #include <sys/stat.h> … … 90 95 /* Macros */ 91 96 97 /* debugging */ 98 99 //#define USRINT_DEBUG 100 #ifdef USRINT_DEBUG 101 #define debug(s,v) fprintf(stderr,s,v) 102 #else 103 #define debug(s,v) 104 #endif 105 106 /* FD sets */ 107 92 108 #ifdef FD_SET 93 109 #undef FD_SET
