Changeset 2323
- Timestamp:
- Sep 25, 2005, 1:01:36 PM (20 years ago)
- Location:
- trunk/src/emx
- Files:
-
- 2 added
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/emx/ChangeLog.LIBC
-
Property cvs2svn:cvs-rev
changed from
1.135
to1.136
r2322 r2323 2 2 3 3 TODO: open replace on RAMFS fails with error 32! 4 5 2005-09-25: knut st. osmundsen <bird-gccos2-spam@anduin.net> 6 - libc: 7 o Implemented fchdir(). 8 o Implemented inheritance of open directory handles. Unfortunately, 9 I ran out of size bits for the bundle type, so the SPM bit is no 10 longer compatible with earlier versions. The consequences 11 of this are related to inheritance and signaling - so recompile! 4 12 5 13 2005-08-28: knut st. osmundsen <bird-gccos2-spam@anduin.net> -
Property cvs2svn:cvs-rev
changed from
-
trunk/src/emx/include/InnoTekLIBC/backend.h
-
Property cvs2svn:cvs-rev
changed from
1.34
to1.35
r2322 r2323 235 235 */ 236 236 int __libc_Back_fsDirCurrentSet(const char *pszPath, int fDrive); 237 238 /** 239 * Changes the current directory of the process. 240 * 241 * @returns 0 on success. 242 * @returns Negative error code (errno.h) on failure. 243 * @param fh The handle of an open directory. 244 * @param fDrive Force a change of the current drive too. 245 */ 246 int __libc_Back_fsDirCurrentSetFH(int fh, int fDrive); 237 247 238 248 /** -
Property cvs2svn:cvs-rev
changed from
-
trunk/src/emx/include/InnoTekLIBC/sharedpm.h
-
Property cvs2svn:cvs-rev
changed from
1.24
to1.25
r2322 r2323 37 37 38 38 /** The name of the shared semaphore protecting the memory. */ 39 #define SPM_MUTEX_NAME "\\SEM32\\INNOTEKLIBC-V1. 1"39 #define SPM_MUTEX_NAME "\\SEM32\\INNOTEKLIBC-V1.3" 40 40 41 41 /** The name of the shared memory. */ 42 #define SPM_MEMORY_NAME "\\SHAREMEM\\INNOTEKLIBC-V1. 1"42 #define SPM_MEMORY_NAME "\\SHAREMEM\\INNOTEKLIBC-V1.3" 43 43 44 44 /** The timeout for accessing the shared mem semaphore. */ … … 60 60 * The SPM version. 61 61 */ 62 #define SPM_VERSION 0x0001000 262 #define SPM_VERSION 0x00010003 63 63 64 64 … … 163 163 #define __LIBC_SPM_INH_FHB_TYPE_END (0) 164 164 /** Standard bundle. */ 165 #define __LIBC_SPM_INH_FHB_TYPE_STANDARD (0x 10 | (sizeof(unsigned) + sizeof(ino_t) + sizeof(dev_t)))166 /** The old standardbundle. */167 #define __LIBC_SPM_INH_FHB_TYPE_ STANDARD_OLD (0x10 | sizeof(unsigned))165 #define __LIBC_SPM_INH_FHB_TYPE_STANDARD (0xe0 | (sizeof(unsigned) + sizeof(ino_t) + sizeof(dev_t) + sizeof(unsigned))) 166 /** Directory bundle. */ 167 #define __LIBC_SPM_INH_FHB_TYPE_DIRECTORY (0xc0 | (sizeof(unsigned) + sizeof(ino_t) + sizeof(dev_t) + sizeof(unsigned) + sizeof(unsigned))) 168 168 /** Socket bundle, using the BSD 4.4 backend. */ 169 #define __LIBC_SPM_INH_FHB_TYPE_SOCKET_44 (0x 20 | (sizeof(unsigned) + sizeof(unsigned short)))169 #define __LIBC_SPM_INH_FHB_TYPE_SOCKET_44 (0xa0 | (sizeof(unsigned) + sizeof(unsigned short))) 170 170 /** Socket bundle, using the BSD 4.3 backend. */ 171 #define __LIBC_SPM_INH_FHB_TYPE_SOCKET_43 (0x30 | (sizeof(unsigned) + sizeof(unsigned short))) 171 #define __LIBC_SPM_INH_FHB_TYPE_SOCKET_43 (0x80 | (sizeof(unsigned) + sizeof(unsigned short))) 172 /*#define __LIBC_SPM_INH_FHB_TYPE_ (0x60 | (sizeof(unsigned) + ))*/ 173 /*#define __LIBC_SPM_INH_FHB_TYPE_ (0x40 | (sizeof(unsigned) + ))*/ 174 /*#define __LIBC_SPM_INH_FHB_TYPE_ (0x20 | (sizeof(unsigned) + ))*/ 175 /*#define __LIBC_SPM_INH_FHB_TYPE_ (0x00 | (sizeof(unsigned) + ))*/ 172 176 /** Get the per file handle size from the bundle type. */ 173 #define __LIBC_SPM_INH_FHB_SIZE(type) ((type) & 0x 0f)177 #define __LIBC_SPM_INH_FHB_SIZE(type) ((type) & 0x1f) 174 178 /** @} */ 175 179 … … 182 186 /** Bundle type. */ 183 187 unsigned char uchType; 184 /** Coun dof handles in this bundle. */188 /** Count of handles in this bundle. */ 185 189 unsigned char cHandles; 186 190 /** Start handle number. */ … … 204 208 struct 205 209 { 206 /** The flags */210 /** The flags. */ 207 211 unsigned fFlags; 208 212 /** The inode number. */ … … 210 214 /** The device number. */ 211 215 dev_t Dev; 216 /** String table offset of the native path. */ 217 unsigned offNativePath : 24; 218 unsigned u8Reserved : 8; 212 219 } aHandles[1]; 213 220 } __LIBC_SPMINHFHBSTD; … … 217 224 218 225 /** 219 * SPM standard filehandle inherit bundle 220 * This is used for OS/2 filehandles which only needs flags 221 * transfered. 226 * SPM directory filehandle inherit bundle. 222 227 */ 223 228 #pragma pack(1) 224 typedef struct __libc_SPMInhFH Old229 typedef struct __libc_SPMInhFHDir 225 230 { 226 231 /** The common bundle header. */ 227 232 __LIBC_SPMINHFHBHDR Hdr; 228 233 /** Array of flags of Hdr.cHandles entries. */ 229 unsigned afFlags[1]; 230 } __LIBC_SPMINHFHBSTDOLD; 234 struct 235 { 236 /** The flags. */ 237 unsigned fFlags; 238 /** The inode number. */ 239 ino_t Inode; 240 /** The device number. */ 241 dev_t Dev; 242 /** String table offset of the native path. */ 243 unsigned offNativePath : 24; 244 /** Set if this path is in the unix tree. */ 245 unsigned fInUnixTree : 1; 246 unsigned u7Reserved : 7; 247 /** The current position. */ 248 unsigned uCurEntry; 249 } aHandles[1]; 250 } __LIBC_SPMINHFHBDIR; 231 251 #pragma pack() 232 /** Pointer to SPM standardfilehandle inherit bundle. */233 typedef __LIBC_SPMINHFHB STDOLD *__LIBC_PSPMINHFHBSTDOLD;252 /** Pointer to SPM directory filehandle inherit bundle. */ 253 typedef __LIBC_SPMINHFHBDIR *__LIBC_PSPMINHFHBDIR; 234 254 235 255 /** … … 303 323 /** Pointer to the signal part. If NULL default values are assumed. */ 304 324 __LIBC_PSPMINHSIG pSig; 305 325 /** Pointer to strings (filenames++). 326 * All the strings are NULL terminated and referenced by offset. */ 327 char *pszStrings; 306 328 } __LIBC_SPMINHERIT; 307 329 /** Pointer to inherit data. */ -
Property cvs2svn:cvs-rev
changed from
-
trunk/src/emx/include/fts.h
-
Property cvs2svn:cvs-rev
changed from
1.3
to1.4
r2322 r2323 49 49 dev_t fts_dev; /* starting device # */ 50 50 char *fts_path; /* path for this descent */ 51 #ifdef __EMX__52 char *fts_rdir; /* path of root */53 #else54 51 int fts_rfd; /* fd for root */ 55 #endif56 52 int fts_pathlen; /* sizeof(path) */ 57 53 int fts_nitems; /* elements in the sort array */ … … 66 62 #define FTS_SEEDOT 0x020 /* return dot and dot-dot */ 67 63 #define FTS_XDEV 0x040 /* don't cross devices */ 68 #ifndef __EMX__69 64 #define FTS_WHITEOUT 0x080 /* return whiteout information */ 70 #endif71 65 #define FTS_OPTIONMASK 0x0ff /* valid user option mask */ 72 66 … … 86 80 char *fts_path; /* root path */ 87 81 int fts_errno; /* errno for this node */ 88 #ifndef __EMX__89 82 int fts_symfd; /* fd for symlink */ 90 #endif91 83 u_short fts_pathlen; /* strlen(fts_path) */ 92 84 u_short fts_namelen; /* strlen(fts_name) */ … … 113 105 #define FTS_SL 12 /* symbolic link */ 114 106 #define FTS_SLNONE 13 /* symbolic link without target */ 115 #ifndef __EMX__116 107 #define FTS_W 14 /* whiteout object */ 117 #endif118 108 u_short fts_info; /* user flags for FTSENT structure */ 119 109 120 110 #define FTS_DONTCHDIR 0x01 /* don't chdir .. to the parent */ 121 111 #define FTS_SYMFOLLOW 0x02 /* followed a symlink to get here */ 122 #ifndef __EMX__123 112 #define FTS_ISW 0x04 /* this is a whiteout object */ 124 #endif125 113 u_short fts_flags; /* private flags for FTSENT structure */ 126 114 -
Property cvs2svn:cvs-rev
changed from
-
trunk/src/emx/include/unistd.h
-
Property cvs2svn:cvs-rev
changed from
1.35
to1.36
r2322 r2323 441 441 /** @todo char *ctermid(char *); */ /* XXX ??? */ 442 442 void encrypt(char *, int); /* bird: SuS say it returns void, and so does our implementation */ 443 /** @todo int fchdir(int); */ 443 int fchdir(int); 444 444 /* tcpip: long gethostid(void); */ 445 445 pid_t getpgid(pid_t _pid); /* bird: SuS say pid_r return. */ -
Property cvs2svn:cvs-rev
changed from
-
trunk/src/emx/src/lib/bsd/gen/fts.c
-
Property cvs2svn:cvs-rev
changed from
1.3
to1.4
r2322 r2323 40 40 #endif 41 41 #ifndef __EMX__ 42 # define HAVE_FCHDIR43 42 # define IS_SLASH(ch) ( (ch) == '/' ) 44 43 #else … … 225 224 * descriptor we run anyway, just more slowly. 226 225 */ 227 #ifdef HAVE_FCHDIR228 226 if (!ISSET(FTS_NOCHDIR) && (sp->fts_rfd = _open(".", O_RDONLY, 0)) < 0) 229 #else 230 if (!ISSET(FTS_NOCHDIR) && (sp->fts_rdir = getcwd(NULL, 0)) != NULL) 231 #endif 232 SET(FTS_NOCHDIR); 227 SET(FTS_NOCHDIR); 233 228 234 229 return (sp); … … 319 314 /* Return to original directory, save errno if necessary. */ 320 315 if (!ISSET(FTS_NOCHDIR)) { 321 #ifdef HAVE_FCHDIR322 316 saved_errno = fchdir(sp->fts_rfd) ? errno : 0; 323 317 (void)_close(sp->fts_rfd); 324 #else325 saved_errno = chdir(sp->fts_rdir) ? errno : 0;326 free(sp->fts_rdir); sp->fts_rdir = NULL;327 #endif328 318 329 319 /* Set errno and return. */ … … 340 330 return (0); 341 331 } 342 343 332 344 333 /* … … 386 375 p->fts_info = fts_stat(sp, p, 1); 387 376 if (p->fts_info == FTS_D && !ISSET(FTS_NOCHDIR)) { 388 #ifdef HAVE_FCHDIR389 377 if ((p->fts_symfd = _open(".", O_RDONLY, 0)) < 0) { 390 378 p->fts_errno = errno; … … 392 380 } else 393 381 p->fts_flags |= FTS_SYMFOLLOW; 394 #endif395 382 } 396 383 return (p); … … 402 389 if (instr == FTS_SKIP || 403 390 (ISSET(FTS_XDEV) && p->fts_dev != sp->fts_dev)) { 404 #ifdef HAVE_FCHDIR405 391 if (p->fts_flags & FTS_SYMFOLLOW) 406 392 (void)_close(p->fts_symfd); 407 #endif408 393 if (sp->fts_child) { 409 394 fts_lfree(sp->fts_child); … … 462 447 */ 463 448 if (p->fts_level == FTS_ROOTLEVEL) { 464 #ifdef HAVE_FCHDIR465 449 if (FCHDIR(sp, sp->fts_rfd)) { 466 #else467 if (FCHDIR(sp, sp->fts_rdir)) {468 #endif469 450 SET(FTS_STOP); 470 451 return (NULL); … … 484 465 p->fts_info = fts_stat(sp, p, 1); 485 466 if (p->fts_info == FTS_D && !ISSET(FTS_NOCHDIR)) { 486 #ifdef HAVE_FCHDIR487 467 if ((p->fts_symfd = 488 468 _open(".", O_RDONLY, 0)) < 0) { … … 491 471 } else 492 472 p->fts_flags |= FTS_SYMFOLLOW; 493 #endif494 473 } 495 474 p->fts_instr = FTS_NOINSTR; … … 525 504 */ 526 505 if (p->fts_level == FTS_ROOTLEVEL) { 527 #ifdef HAVE_FCHDIR528 506 if (FCHDIR(sp, sp->fts_rfd)) { 529 #else530 if (FCHDIR(sp, sp->fts_rdir)) {531 #endif532 507 SET(FTS_STOP); 533 508 return (NULL); 534 509 } 535 #ifdef HAVE_FCHDIR536 510 } else if (p->fts_flags & FTS_SYMFOLLOW) { 537 511 if (FCHDIR(sp, p->fts_symfd)) { … … 543 517 } 544 518 (void)_close(p->fts_symfd); 545 #else546 (void)saved_errno;547 #endif548 519 } else if (!(p->fts_flags & FTS_DONTCHDIR) && 549 520 fts_safe_changedir(sp, p->fts_parent, -1, "..")) { … … 583 554 { 584 555 FTSENT *p; 585 #ifdef HAVE_FCHDIR586 556 int fd; 587 #else 588 char *pszRoot; 589 int rc; 590 #endif 557 591 558 if (instr != 0 && instr != FTS_NAMEONLY) { 592 559 errno = EINVAL; … … 640 607 return (sp->fts_child = fts_build(sp, instr)); 641 608 642 #ifdef HAVE_FCHDIR643 609 if ((fd = _open(".", O_RDONLY, 0)) < 0) 644 #else645 if ((pszRoot = getcwd(NULL, 0)) == NULL)646 #endif647 610 return (NULL); 648 611 sp->fts_child = fts_build(sp, instr); 649 #ifdef HAVE_FCHDIR650 612 if (fchdir(fd)) 651 613 return (NULL); 652 614 (void)_close(fd); 653 #else654 rc = chdir(pszRoot);655 free(pszRoot);656 if (rc)657 return NULL;658 #endif659 615 return (sp->fts_child); 660 616 } … … 725 681 * If being called from fts_read, set the fts_info field. 726 682 */ 727 #if def FTS_WHITEOUT683 #if defined(FTS_WHITEOUT) && !defined(__EMX__) 728 684 if (ISSET(FTS_WHITEOUT)) 729 685 oflag = DTF_NODUP | DTF_REWIND; … … 784 740 cderrno = 0; 785 741 if (nlinks || type == BREAD) { 786 #ifdef HAVE_FCHDIR787 742 if (fts_safe_changedir(sp, cur, dirfd(dirp), NULL)) { 788 #else789 if (fts_safe_changedir(sp, cur, dirfd(dirp), cur->fts_accpath)) {790 #endif791 743 if (nlinks && type == BREAD) 792 744 cur->fts_errno = errno; … … 953 905 if (descend && (type == BCHILD || !nitems) && 954 906 (cur->fts_level == FTS_ROOTLEVEL ? 955 #ifdef HAVE_FCHDIR956 907 FCHDIR(sp, sp->fts_rfd) : 957 #else958 FCHDIR(sp, sp->fts_rdir) :959 #endif960 908 fts_safe_changedir(sp, cur->fts_parent, -1, ".."))) { 961 909 cur->fts_info = FTS_ERR; … … 1259 1207 if (ISSET(FTS_NOCHDIR)) 1260 1208 return (0); 1261 #ifdef HAVE_FCHDIR1262 1209 if (fd < 0 && (newfd = _open(path, O_RDONLY, 0)) < 0) 1263 1210 return (-1); 1264 1211 if (_fstat(newfd, &sb)) { 1265 #else1266 (void)newfd;1267 if (_stat(path, &sb)) {1268 #endif1269 1212 ret = -1; 1270 1213 goto bail; … … 1275 1218 goto bail; 1276 1219 } 1277 #ifdef HAVE_FCHDIR1278 1220 ret = fchdir(newfd); 1279 #else1280 ret = chdir(path);1281 #endif1282 1221 bail: 1283 #ifdef HAVE_FCHDIR1284 1222 oerrno = errno; 1285 1223 if (fd < 0) 1286 1224 (void)_close(newfd); 1287 1225 errno = oerrno; 1288 #else1289 (void)oerrno;1290 #endif1291 1226 return (ret); 1292 1227 } -
Property cvs2svn:cvs-rev
changed from
-
trunk/src/emx/src/lib/libc.def
-
Property cvs2svn:cvs-rev
changed from
1.138
to1.139
r2322 r2323 1948 1948 "__hstrdup" @1946 1949 1949 "___libc_Back_dirOpenNative" @1947 1950 "___libc_Back_fsDirCurrentSetFH" @1948 1951 "__std_fchdir" @1949 -
Property cvs2svn:cvs-rev
changed from
-
trunk/src/emx/src/lib/sys/__spawnve.c
-
Property cvs2svn:cvs-rev
changed from
1.21
to1.22
r2322 r2323 42 42 LIBCLOG_ENTER("\n"); 43 43 __LIBC_PSPMINHERIT pRet = NULL; 44 size_t cbStrings = 0; 45 char *pszStrings = NULL; 44 46 45 47 /* … … 48 50 size_t cbFH; 49 51 __LIBC_PSPMINHFHBHDR pFH; 50 pFH = __libc_fhInheritPack(&cbFH );52 pFH = __libc_fhInheritPack(&cbFH, &pszStrings, &cbStrings); 51 53 if (pFH) 52 54 { … … 68 70 * Allocate shared memory. 69 71 */ 70 size_t cb = sizeof(__LIBC_SPMINHERIT) + ((cbFH + 3) & ~3) + ((cbFS + 3) & ~3) + ((cbSig + 3) & ~3); 72 #define ALIGNIT(cb) (((cb) + 3) & ~3) 73 size_t cb = sizeof(__LIBC_SPMINHERIT) + ALIGNIT(cbFH) + ALIGNIT(cbFS) + ALIGNIT(cbSig) + ALIGNIT(cbStrings); 71 74 pRet = __libc_spmAlloc(cb); 72 75 if (pRet) 73 76 { 77 pRet->cb = sizeof(*pRet); 78 char *p = (char *)(pRet + 1); 79 74 80 /* fh */ 75 pRet-> cb = sizeof(*pRet);76 p Ret->pFHBundles = (__LIBC_PSPMINHFHBHDR)(pRet + 1);81 pRet->pFHBundles = (__LIBC_PSPMINHFHBHDR)p; 82 p += ALIGNIT(cbFH); 77 83 memcpy(pRet->pFHBundles, pFH, cbFH); 78 84 free(pFH); … … 81 87 if (pFS) 82 88 { 83 pRet->pFS = (__LIBC_PSPMINHFS)((char *)pRet->pFHBundles + ((cbFH + 3) & ~3)); 89 pRet->pFS = (__LIBC_PSPMINHFS)p; 90 p += ALIGNIT(cbFS); 84 91 memcpy(pRet->pFS, pFS, cbFS); 85 92 free(pFS); … … 91 98 if (pSig) 92 99 { 93 pRet->pSig = (__LIBC_PSPMINHSIG)((char *)pRet->pFHBundles + ((cbFH + 3) & ~3) + ((cbFS + 3) & ~3)); 100 pRet->pSig = (__LIBC_PSPMINHSIG)p; 101 p += ALIGNIT(cbSig); 94 102 memcpy(pRet->pSig, pSig, cbSig); 95 103 free(pSig); 96 104 } 105 else 106 pRet->pSig = NULL; 107 108 /* strings */ 109 if (pszStrings) 110 { 111 pRet->pszStrings = p; 112 /*p += ALIGNIT(cbStrings);*/ 113 memcpy(pRet->pszStrings, pszStrings, cbStrings); 114 free(pszStrings); 115 } 116 else 117 pRet->pszStrings = NULL; 97 118 98 119 /* done! */ … … 108 129 free(pFH); 109 130 } 131 free(pszStrings); 110 132 111 133 LIBCLOG_RETURN_P(pRet); -
Property cvs2svn:cvs-rev
changed from
-
trunk/src/emx/src/lib/sys/b_dir.c
-
Property cvs2svn:cvs-rev
changed from
1.2
to1.3
r2322 r2323 39 39 #include <limits.h> 40 40 #include <sys/fcntl.h> 41 #include <sys/dirent.h> 41 42 #include <emx/umalloc.h> 42 43 #include <emx/io.h> … … 54 55 static int dirFileControl(__LIBC_PFH pFH, int fh, int iRequest, int iArg, int *prc); 55 56 static int dirIOControl(__LIBC_PFH pFH, int fh, int iIOControl, int iArg, int *prc); 57 static int dirSeek(__LIBC_PFH pFH, int fh, off_t off, int iMethod, off_t *poffNew); 56 58 static int dirSelect(int cFHs, struct fd_set *pRead, struct fd_set *pWrite, struct fd_set *pExcept, struct timeval *tv, int *prc); 57 59 static int dirForkChild(__LIBC_PFH pFH, int fh, __LIBC_PFORKHANDLE pForkHandle, __LIBC_FORKOP enmOperation); 60 static int dirOpen(const char *pszNativePath, unsigned fLibc, int *pfh, __LIBC_PFHDIR *ppFHDir); 58 61 59 62 … … 73 76 dirFileControl, 74 77 dirIOControl, 78 //dirSeek, 75 79 dirSelect, 76 80 NULL, … … 200 204 LIBCLOG_ENTER("pFH=%p fh=%d iIOControl=%d iArg=%d prc=%p\n", (void *)pFH, fh, iIOControl, iArg, (void *)prc); 201 205 LIBCLOG_ERROR_RETURN_INT(-EOPNOTSUPP); 206 } 207 208 209 /** Seek to a new position in the 'file'. 210 * 211 * @returns 0 on success. 212 * @returns OS/2 error code or negated errno on failure. 213 * @param pFH Pointer to the handle structure to operate on. 214 * @param fh It's associated filehandle. 215 * @param off The offset to seek. The meaning depends on SEEK_. 216 * @param iMethod The seek method, any of the SEEK_* macros. 217 * @param poffNew Where to store the new file offset. 218 */ 219 static int dirSeek(__LIBC_PFH pFH, int fh, off_t off, int iMethod, off_t *poffNew) 220 { 221 /** @todo Implement reading and seeking. */ 222 return -1; 202 223 } 203 224 … … 238 259 static int dirForkChild(__LIBC_PFH pFH, int fh, __LIBC_PFORKHANDLE pForkHandle, __LIBC_FORKOP enmOperation) 239 260 { 240 /** @todo reopen the handle, same as for duplicate! */ 261 switch (enmOperation) 262 { 263 case __LIBC_FORK_OP_FORK_CHILD: 264 { 265 __LIBC_PFHDIR pFHDir = (__LIBC_PFHDIR)pFH; 266 267 /* make pattern */ 268 char szNativePath[PATH_MAX + 5]; 269 size_t cch = strlen(pFH->pszNativePath); 270 memcpy(szNativePath, pFH->pszNativePath, cch); 271 szNativePath[cch] = '/'; 272 szNativePath[cch + 1] = '*'; 273 szNativePath[cch + 2] = '\0'; 274 275 pFHDir->hDir = HDIR_CREATE; 276 pFHDir->cFiles = pFHDir->cbBuf / 40; 277 #if OFF_MAX > LONG_MAX 278 if (pFHDir->fType == FIL_QUERYEASIZEL) /* the L version is buggy!! Make sure there is enough space. */ 279 pFHDir->cFiles = pFHDir->cbBuf / sizeof(FILEFINDBUF4L); 280 #endif 281 pFHDir->uCur.pv = pFHDir->uBuf.pv; 282 bzero(pFHDir->uBuf.pv, pFHDir->cbBuf); 283 284 int rc = DosFindFirst((PCSZ)szNativePath, 285 &pFHDir->hDir, 286 FILE_NORMAL | FILE_READONLY | FILE_HIDDEN | FILE_SYSTEM | FILE_DIRECTORY | FILE_ARCHIVED, 287 pFHDir->uBuf.pv, 288 pFHDir->cbBuf, 289 &pFHDir->cFiles, 290 pFHDir->fType); 291 if (rc) 292 { 293 pFHDir->hDir = HDIR_CREATE; 294 return rc; 295 } 296 if (pFHDir->uCurEntry) 297 { 298 unsigned uCurEntry = pFHDir->uCurEntry; 299 pFHDir->uCurEntry = 0; 300 dirSeek(&pFHDir->Core, fh, uCurEntry * sizeof(struct dirent), SEEK_SET, NULL); 301 } 302 break; 303 } 304 305 default: 306 break; 307 } 241 308 return 0; 242 309 } … … 248 315 249 316 /** 250 * Opens a directory specified by a path already made native. 251 * 252 * @returns File handle (>=0) on success. 253 * @returns negative error code (errno.h) on failure. 317 * Opens a directory. 318 * Internal worker used by the other open/inherit calls. 319 * 320 * @returns 0 on success. 321 * @returns Negated errno on failure. 254 322 * @param pszNativePath Pointer to the native path. The buffer must be on stack 255 323 * and must have space for 4 extra bytes! 256 * @param fInUnixTree Set if the native path is in the unix tree. 257 * @param fLibc The LIBC open() flags. 258 * @param pStat Pointer to the stat structure for the directory. 259 */ 260 int __libc_Back_dirOpenNative(char *pszNativePath, unsigned fInUnixTree, unsigned fLibc, struct stat *pStat) 261 { 262 LIBCLOG_ENTER("pszNativePath=%p:{%s} fInUnixTree=%d fLibc=%#x pStat=%p\n", (void *)pszNativePath, pszNativePath, fInUnixTree, fLibc, (void *)pStat); 263 264 /* 265 * Validate input. 266 */ 267 if (!S_ISDIR(pStat->st_mode)) 268 LIBCLOG_ERROR_RETURN_INT(-ENOTDIR); 269 if ((fLibc & O_ACCMODE) != O_RDONLY) 270 LIBCLOG_ERROR_RETURN_INT(-EISDIR); 271 if ((fLibc & (O_EXCL | O_CREAT)) == (O_EXCL | O_CREAT)) 272 LIBCLOG_ERROR_RETURN_INT(-EEXIST); 273 if (fLibc & (O_TRUNC | O_APPEND)) 274 LIBCLOG_ERROR_RETURN_INT(-EPERM); 275 if (fLibc & (O_TRUNC | O_APPEND | O_SIZE)) 276 LIBCLOG_ERROR_RETURN_INT(-EINVAL); 277 278 /* 279 * Directory handles are binary, period. 280 */ 281 fLibc &= ~O_TEXT; 282 fLibc |= O_BINARY; 324 * @param pfh On input the requested filehandle. -1 means any. 325 * On output (success only) the allocated file handle. 326 * @param ppFHDir Where to store the handle structure pointer on success. 327 */ 328 static int dirOpen(const char *pszNativePath, unsigned fLibc, int *pfh, __LIBC_PFHDIR *ppFHDir) 329 { 330 LIBC_ASSERT((fLibc & (O_BINARY | __LIBC_FH_TYPEMASK)) == (O_BINARY | F_DIR)); 283 331 284 332 /* … … 327 375 if (!rc) 328 376 { 329 int fh;330 377 __LIBC_PFH pFH; 331 rc = __libc_FHAllocate( -1, fLibc, sizeof(__LIBC_FHDIR), &gDirOps, &pFH, &fh);378 rc = __libc_FHAllocate(*pfh, fLibc, sizeof(__LIBC_FHDIR), &gDirOps, &pFH, pfh); 332 379 if (!rc) 333 380 { 334 pFH->Dev = __libc_back_fsPathCalcInodeAndDev(pszNativePath, &pFH->Inode);335 381 pFH->pFsInfo = __libc_back_fsInfoObjByDev(pFH->Dev); 336 382 pFH->pszNativePath = Tmp.Core.pszNativePath; … … 343 389 pFHDir->cFiles = Tmp.cFiles; 344 390 pFHDir->cbBuf = Tmp.cbBuf; 345 391 pFHDir->uCurEntry = 0; 392 393 *ppFHDir = pFHDir; 346 394 FS_RESTORE(); 347 LIBCLOG_MSG("pFHDir=%p:{.hDir=%#lx, .fType=%d, .cFiles=%ld, .cbBuf=%#x} fh=%d\n", 348 (void *)pFHDir, pFHDir->hDir, pFHDir->fType, pFHDir->cFiles, pFHDir->cbBuf, fh); 349 LIBCLOG_RETURN_INT(fh); 395 return 0; 350 396 } 351 397 … … 361 407 if (rc > 0) 362 408 rc = -__libc_native2errno(rc); 409 return rc; 410 } 411 412 413 /** 414 * Re-opens a directory we inherited from our parent process. 415 * 416 * @returns 0 on success. 417 * @returns Negated error code (errno.h) on failure. 418 * @param fh The file handle this directory shall have. 419 * @param pszNativePath Pointer to the native path. 420 * @param fInUnixTree Flag indicating whether the open() call was referencing a path in the unix tree or not. 421 * @param fFlags Filehandle flags. 422 * @param Inode The inode number of the directory. 423 * @param Dev The device number of the device with the directory. 424 * @param uCurEntry The current position. 425 */ 426 int __libc_back_dirInherit(int fh, const char *pszNativePath, unsigned fInUnixTree, unsigned fFlags, ino_t Inode, dev_t Dev, unsigned uCurEntry) 427 { 428 LIBCLOG_ENTER("fh=%d pszNativePath=%p:{%s} fInUnixTree=%d fFlags=%#x Inode=%#llx Dev=%#x uCurEntry=%d\n", 429 fh, (void *)pszNativePath, pszNativePath, fInUnixTree, fFlags, (unsigned long long)Inode, Dev, uCurEntry); 430 431 /* 432 * Open the directory. 433 */ 434 __LIBC_PFHDIR pFHDir; 435 char szNativePath[PATH_MAX + 5]; 436 strcpy(szNativePath, pszNativePath); 437 int rc = dirOpen(szNativePath, fFlags, &fh, &pFHDir); 438 if (!rc) 439 { 440 pFHDir->Core.Inode = Inode; 441 pFHDir->Core.Dev = Dev; 442 443 /* 444 * Seek to the current positions. 445 */ 446 if (uCurEntry) 447 dirSeek(&pFHDir->Core, fh, uCurEntry * sizeof(struct dirent), SEEK_SET, NULL); 448 449 LIBCLOG_MSG("pFHDir=%p:{.hDir=%#lx, .fType=%d, .cFiles=%ld, .cbBuf=%#x, .uCurEntry=%d} fh=%d\n", 450 (void *)pFHDir, pFHDir->hDir, pFHDir->fType, pFHDir->cFiles, pFHDir->cbBuf, pFHDir->uCurEntry, fh); 451 LIBCLOG_RETURN_INT(0); 452 } 363 453 LIBCLOG_ERROR_RETURN_INT(rc); 364 } 365 454 455 } 456 457 458 /** 459 * Opens a directory specified by a path already made native. 460 * 461 * @returns File handle (>=0) on success. 462 * @returns negative error code (errno.h) on failure. 463 * @param pszNativePath Pointer to the native path. The buffer must be on stack 464 * and must have space for 4 extra bytes! 465 * @param fInUnixTree Set if the native path is in the unix tree. 466 * @param fLibc The LIBC open() flags. 467 * @param pStat Pointer to the stat structure for the directory. 468 */ 469 int __libc_Back_dirOpenNative(char *pszNativePath, unsigned fInUnixTree, unsigned fLibc, struct stat *pStat) 470 { 471 LIBCLOG_ENTER("pszNativePath=%p:{%s} fInUnixTree=%d fLibc=%#x pStat=%p\n", (void *)pszNativePath, pszNativePath, fInUnixTree, fLibc, (void *)pStat); 472 473 /* 474 * Validate input. 475 */ 476 if (!S_ISDIR(pStat->st_mode)) 477 LIBCLOG_ERROR_RETURN_INT(-ENOTDIR); 478 if ((fLibc & O_ACCMODE) != O_RDONLY) 479 LIBCLOG_ERROR_RETURN_INT(-EISDIR); 480 if ((fLibc & (O_EXCL | O_CREAT)) == (O_EXCL | O_CREAT)) 481 LIBCLOG_ERROR_RETURN_INT(-EEXIST); 482 if (fLibc & (O_TRUNC | O_APPEND)) 483 LIBCLOG_ERROR_RETURN_INT(-EPERM); 484 if (fLibc & (O_TRUNC | O_APPEND | O_SIZE)) 485 LIBCLOG_ERROR_RETURN_INT(-EINVAL); 486 487 /* 488 * Directory handles are binary, period. 489 */ 490 fLibc &= ~(O_TEXT | __LIBC_FH_TYPEMASK | __LIBC_FH_FDFLAGS_MASK); 491 fLibc |= O_BINARY | F_DIR; 492 493 /* 494 * Open the directory. 495 */ 496 int fh = -1; 497 __LIBC_PFHDIR pFHDir; 498 int rc = dirOpen(pszNativePath, fLibc, &fh, &pFHDir); 499 if (!rc) 500 { 501 pFHDir->Core.Inode = pStat->st_ino; 502 pFHDir->Core.Dev = pStat->st_dev; 503 504 LIBCLOG_MSG("pFHDir=%p:{.hDir=%#lx, .fType=%d, .cFiles=%ld, .cbBuf=%#x} fh=%d\n", 505 (void *)pFHDir, pFHDir->hDir, pFHDir->fType, pFHDir->cFiles, pFHDir->cbBuf, fh); 506 LIBCLOG_RETURN_INT(fh); 507 } 508 LIBCLOG_ERROR_RETURN_INT(rc); 509 } 510 -
Property cvs2svn:cvs-rev
changed from
-
trunk/src/emx/src/lib/sys/b_dir.h
-
Property cvs2svn:cvs-rev
changed from
1.2
to1.3
r2322 r2323 65 65 /** The size of the find buffer. */ 66 66 unsigned cbBuf; 67 /** Current entry number (total, for seeking). */ 68 unsigned uCurEntry; 67 69 } __LIBC_FHDIR; 68 70 /** Pointer to the a directory handle. */ … … 71 73 72 74 int __libc_Back_dirOpenNative(char *pszNativePath, unsigned fInUnixTree, unsigned fLibc, struct stat *pStat); 75 int __libc_back_dirInherit(int fh, const char *pszNativePath, unsigned fInUnixTree, unsigned fFlags, 76 ino_t Inode, dev_t Dev, unsigned uCurEntry); 73 77 74 78 -
Property cvs2svn:cvs-rev
changed from
-
trunk/src/emx/src/lib/sys/b_fsDirCurrentSet.c
-
Property cvs2svn:cvs-rev
changed from
1.5
to1.6
r2322 r2323 49 49 { 50 50 LIBCLOG_ENTER("pszPath=%p:{%s} fDrive=%d\n", (void *)pszPath, pszPath, fDrive); 51 FS_VAR();52 51 53 52 /* … … 73 72 * when in the unix compartement or when fDrive is set. 74 73 */ 75 FS_ SAVE_LOAD();74 FS_VAR_SAVE_LOAD(); 76 75 int rc = DosSetCurrentDir((PCSZ)&szNativePath[0]); 77 FS_RESTORE();78 76 if (!rc) 79 77 { … … 84 82 ULONG ulDrive = szNativePath[0] - (szNativePath[0] >= 'A' && szNativePath[0] <= 'Z' ? 'A' - 1 : 'a' -1); 85 83 rc = DosSetDefaultDisk(ulDrive); 86 LIBC_ASSERTM(!rc, "DosSetDefaultDisk(%ld) -> %d. unixdrive is %c\n", ulDrive, rc, szNativePath[0]);84 LIBC_ASSERTM(!rc, "DosSetDefaultDisk(%ld) -> %d. drive is %c\n", ulDrive, rc, szNativePath[0]); 87 85 rc = 0; /* ignore this kind of errors. */ 88 86 __libc_gfInUnixTree = fInUnixTree; … … 92 90 else 93 91 rc = -__libc_native2errno(rc); 92 FS_RESTORE(); 94 93 } 95 94 -
Property cvs2svn:cvs-rev
changed from
-
trunk/src/emx/src/lib/sys/filehandles.c
-
Property cvs2svn:cvs-rev
changed from
1.25
to1.26
r2322 r2323 53 53 #include "syscalls.h" 54 54 #include "b_fs.h" 55 55 #include "b_dir.h" 56 57 #include <InnoTekLIBC/backend.h> 56 58 #define __LIBC_LOG_GROUP __LIBC_LOG_GRP_INITTERM 57 59 #include <InnoTekLIBC/logstrict.h> … … 170 172 __LIBC_PSPMINHFHBHDR pHdr; 171 173 __LIBC_PSPMINHFHBSTD pStds; 172 __LIBC_PSPMINHFHB STDOLD pStdsOld;174 __LIBC_PSPMINHFHBDIR pDirs; 173 175 __LIBC_PSPMINHFHBSOCK pSockets; 174 176 uintptr_t u; … … 189 191 if (fhAllocate(iFH, u.pStds->aHandles[i].fFlags, sizeof(__LIBC_FH), NULL, &pFH, NULL, 0)) 190 192 { 191 LIBC_ASSERTM_FAILED("Failed to allocated inherited file handle! iFH=%d\n", iFH);193 __libc_Back_panic(0, NULL, "Failed to allocated inherited file handle! iFH=%d\n", iFH); 192 194 __libc_spmInheritRelease(); 193 195 return -1; … … 196 198 pFH->Dev = u.pStds->aHandles[i].Dev; 197 199 pFH->pFsInfo = __libc_back_fsInfoObjByDev(pFH->Dev); 198 pFH->pszNativePath = NULL; 200 pFH->pszNativePath = u.pStds->aHandles[i].offNativePath 201 ? _hstrdup(pInherit->pszStrings + u.pStds->aHandles[i].offNativePath) : NULL; 199 202 } 200 203 u.pv = &u.pStds->aHandles[c]; 201 204 break; 202 205 203 case __LIBC_SPM_INH_FHB_TYPE_ STANDARD_OLD:206 case __LIBC_SPM_INH_FHB_TYPE_DIRECTORY: 204 207 for (i = 0; i < c; i++) 205 208 { 206 if (fhAllocate(iFH, u.pStdsOld->afFlags[i], sizeof(__LIBC_FH), NULL, NULL, NULL, 0)) 209 const char *pszPath = u.pDirs->aHandles[i].offNativePath ? pInherit->pszStrings + u.pDirs->aHandles[i].offNativePath : NULL; 210 int rc = __libc_back_dirInherit(iFH, pszPath, u.pDirs->aHandles[i].fInUnixTree, 211 u.pDirs->aHandles[i].fFlags, u.pDirs->aHandles[i].Inode, 212 u.pDirs->aHandles[i].Dev, u.pDirs->aHandles[i].uCurEntry); 213 if (rc) 207 214 { 208 LIBC_ASSERTM_FAILED("Failed to allocated inherited file handle! iFH=%d\n", iFH);215 __libc_Back_panic(0, NULL, "Failed to allocated inherited directory handle! rc=%d iFH=%d path=%s\n", rc, iFH, pszPath); 209 216 __libc_spmInheritRelease(); 210 217 return -1; 211 218 } 212 219 } 213 u.pv = &u.p StdsOld->afFlags[c];220 u.pv = &u.pDirs->aHandles[c]; 214 221 break; 215 222 … … 220 227 if (rc) 221 228 { 222 LIBC_ASSERTM_FAILED("Failed to allocated inherited socket (4.4) handle! rc=%d iFH=%d iSocket=%d\n",223 229 __libc_Back_panic(0, NULL, "Failed to allocated inherited socket (4.4) handle! rc=%d iFH=%d iSocket=%d\n", 230 rc, iFH, u.pSockets->aHandles[i].usSocket); 224 231 __libc_spmInheritRelease(); 225 232 return -1; … … 235 242 if (rc) 236 243 { 237 LIBC_ASSERTM_FAILED("Failed to allocated inherited socket (4.3) handle! rc=%d iFH=%d iSocket=%d\n",238 244 __libc_Back_panic(0, NULL, "Failed to allocated inherited socket (4.3) handle! rc=%d iFH=%d iSocket=%d\n", 245 rc, iFH, u.pSockets->aHandles[i].usSocket); 239 246 __libc_spmInheritRelease(); 240 247 return -1; … … 295 302 296 303 /** 304 * Adds a string to the string table. 305 */ 306 static inline unsigned fhAddString(const char *pszString, char **ppszStrings, size_t *pcbAlloc, size_t *pcb) 307 { 308 if (!pszString) 309 return 0; 310 311 size_t cb = strlen(pszString) + 1; 312 unsigned off = *pcb; 313 314 /* need more space? */ 315 if (cb + off > *pcbAlloc) 316 { 317 size_t cbAlloc = (cb + off + !off + 0xfff) & ~0xfff; 318 void *pv = _hrealloc(*ppszStrings, cbAlloc); 319 if (!pv) 320 return 0; 321 *ppszStrings = (char *)pv; 322 *pcbAlloc = cbAlloc; 323 if (!off) 324 { 325 *pcb = off = 1; 326 **ppszStrings = '\0'; 327 } 328 } 329 330 /* copy */ 331 memcpy(*ppszStrings + off, pszString, cb); 332 *pcb += cb; 333 return off; 334 } 335 336 337 /** 297 338 * Pack down file handles for exec. 298 339 * … … 303 344 * @param pcb Where to store the size of the returned data. 304 345 */ 305 __LIBC_PSPMINHFHBHDR __libc_fhInheritPack(size_t *pcb )346 __LIBC_PSPMINHFHBHDR __libc_fhInheritPack(size_t *pcb, char **ppszStrings, size_t *pcbStrings) 306 347 { 307 348 LIBCLOG_ENTER("pcb=%p\n", (void *)pcb); 308 size_t cb = 0x1000; 349 size_t cbStringAlloc = *pcbStrings; 350 size_t cb = 0x2000; 309 351 unsigned iFH; 310 352 unsigned cFHs; … … 314 356 { 315 357 __LIBC_PSPMINHFHBHDR pHdr; 358 __LIBC_PSPMINHFHBDIR pDirs; 316 359 __LIBC_PSPMINHFHBSTD pStds; 317 360 __LIBC_PSPMINHFHBSOCK pSockets; … … 321 364 322 365 /* 323 * Allocate buffer. 324 */ 366 * Allocate buffers. 367 */ 368 LIBC_ASSERT(cb > sizeof(u.pDirs->aHandles[0]) * 256 + sizeof(*u.pDirs)); 325 369 pRet = _hmalloc(cb); 326 370 if (!pRet) … … 361 405 */ 362 406 /* Ensure space for max sized bundle and termination record. */ 363 if ( ((uintptr_t)&u.p Sockets->aHandles[256] + sizeof(__LIBC_SPMINHFHBHDR) - (uintptr_t)pRet) > cb)364 { 365 void *pv = realloc(pRet, cb + 0x 1000);407 if ( ((uintptr_t)&u.pDirs->aHandles[256] + sizeof(__LIBC_SPMINHFHBHDR) - (uintptr_t)pRet) > cb ) 408 { 409 void *pv = realloc(pRet, cb + 0x2000); 366 410 if (!pv) 367 411 { … … 372 416 u.u += (uintptr_t)pv - (uintptr_t)pv; 373 417 pRet = pv; 374 cb += 0x 1000;418 cb += 0x2000; 375 419 } 376 420 /* init the bundle. */ … … 388 432 u.pStds->aHandles[i].Inode = gpapFHs[iFH]->Inode; 389 433 u.pStds->aHandles[i].Dev = gpapFHs[iFH]->Dev; 434 u.pStds->aHandles[i].offNativePath = fhAddString(gpapFHs[iFH]->pszNativePath, ppszStrings, &cbStringAlloc, pcbStrings); 390 435 /* next */ 391 436 i++; iFH++; … … 400 445 u.pStds->Hdr.cHandles = i; 401 446 u.pv = &u.pStds->aHandles[i]; 447 break; 448 } 449 450 case enmFH_Directory: 451 { 452 u.pDirs->Hdr.uchType = __LIBC_SPM_INH_FHB_TYPE_DIRECTORY; 453 u.pDirs->Hdr.StartFH = iFH; 454 /* walk file handles. */ 455 for (i = 0; ; ) 456 { 457 u.pDirs->aHandles[i].fFlags = gpapFHs[iFH]->fFlags; 458 u.pDirs->aHandles[i].Inode = gpapFHs[iFH]->Inode; 459 u.pDirs->aHandles[i].Dev = gpapFHs[iFH]->Dev; 460 LIBC_ASSERT(gpapFHs[iFH]->pszNativePath && *gpapFHs[iFH]->pszNativePath); 461 u.pDirs->aHandles[i].offNativePath = fhAddString(gpapFHs[iFH]->pszNativePath, ppszStrings, &cbStringAlloc, pcbStrings); 462 if (!u.pDirs->aHandles[i].offNativePath) 463 { 464 _fmutex_release(&gmtx); 465 free(pRet); 466 LIBCLOG_ERROR_RETURN_P(NULL); 467 } 468 u.pDirs->aHandles[i].fInUnixTree = !!((__LIBC_PFHDIR)gpapFHs[iFH])->fInUnixTree; 469 u.pDirs->aHandles[i].uCurEntry = ((__LIBC_PFHDIR)gpapFHs[iFH])->uCurEntry; 470 /* next */ 471 i++; iFH++; 472 if ( i >= 255 473 || iFH >= cFHs 474 || !gpapFHs[iFH] 475 || !gpapFHs[iFH]->pOps 476 || (gpapFHs[iFH]->pOps->enmType != enmType) 477 || (gpapFHs[iFH]->fFlags & ((FD_CLOEXEC << __LIBC_FH_FDFLAGS_SHIFT) | O_NOINHERIT)) ) 478 break; 479 } 480 /* commit the bundle. */ 481 u.pStds->Hdr.cHandles = i; 482 u.pv = &u.pDirs->aHandles[i]; 402 483 break; 403 484 } -
Property cvs2svn:cvs-rev
changed from
-
trunk/src/emx/src/lib/sys/syscalls.h
-
Property cvs2svn:cvs-rev
changed from
1.16
to1.17
r2322 r2323 126 126 /** @defgroup grp_sys_inherit Inherit Function 127 127 * @{ */ 128 __LIBC_PSPMINHFHBHDR __libc_fhInheritPack(size_t *pcb );128 __LIBC_PSPMINHFHBHDR __libc_fhInheritPack(size_t *pcb, char **ppszStrings, size_t *pcbStrings); 129 129 void __libc_fhInheritDone(void); 130 130 /** @} */ -
Property cvs2svn:cvs-rev
changed from
Note:
See TracChangeset
for help on using the changeset viewer.