Changeset 2903
- Timestamp:
- Dec 25, 2006, 2:18:45 PM (19 years ago)
- Location:
- trunk/libc/src/kNIX
- Files:
-
- 1 added
- 1 deleted
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/libc/src/kNIX/Makefile.kmk
r2902 r2903 46 46 $(PATH_LIBC_SRC)/kNIX/b_processSetResourceLimit.c \ 47 47 $(PATH_LIBC_SRC)/kNIX/b_signalSendPid.c \ 48 $(PATH_LIBC_SRC)/kNIX/fs.c \ 49 $(PATH_LIBC_SRC)/kNIX/filehandles.c \ 48 50 $(PATH_LIBC_SRC)/kNIX/heap.c \ 49 51 $(PATH_LIBC_SRC)/kNIX/heapdata.c \ 50 52 51 # $(PATH_LIBC_SRC)/kNIX/fs.c \52 # $(PATH_LIBC_SRC)/kNIX/filehandles.c \53 53 # $(PATH_LIBC_SRC)/kNIX/b_ioDuplicate.c \ 54 54 … … 137 137 $(PATH_LIBC_SRC)/kNIX/os2/filesys.c \ 138 138 $(PATH_LIBC_SRC)/kNIX/os2/fhOS2File.c \ 139 $(PATH_LIBC_SRC)/kNIX/os2/fs .c \139 $(PATH_LIBC_SRC)/kNIX/os2/fs-os2.c \ 140 140 $(PATH_LIBC_SRC)/kNIX/os2/fsync.c \ 141 141 $(PATH_LIBC_SRC)/kNIX/os2/getppid.c \ -
trunk/libc/src/kNIX/b_fs.h
r2805 r2903 1 /* $Id$ */2 /** @file3 *4 * LIBC SYS Backend - file system stuff.5 *6 * Copyright (c) 2004 knut st. osmundsen <bird@innotek.de>7 *8 *9 * This file is part of InnoTek LIBC.10 *11 * InnoTek LIBC is free software; you can redistribute it and/or modify12 * it under the terms of the GNU Lesser General Public License as published13 * by the Free Software Foundation; either version 2 of the License, or14 * (at your option) any later version.15 *16 * InnoTek LIBC is distributed in the hope that it will be useful,17 * but WITHOUT ANY WARRANTY; without even the implied warranty of18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the19 * GNU Lesser General Public License for more details.20 *21 * You should have received a copy of the GNU Lesser General Public License22 * along with InnoTek LIBC; if not, write to the Free Software23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA24 *25 */26 27 #ifndef __fs_h__28 #define __fs_h__29 30 #include <sys/cdefs.h>31 #include <sys/syslimits.h>32 #include <sys/types.h>33 #include <emx/io.h>34 #include <InnoTekLIBC/sharedpm.h>35 #include "backend.h"36 37 struct stat;38 39 __BEGIN_DECLS40 41 /** Indicator whether or not we're in the unix tree. */42 extern int __libc_gfInUnixTree;43 /** Length of the unix root if the unix root is official. */44 extern int __libc_gcchUnixRoot;45 /** The current unix root. */46 extern char __libc_gszUnixRoot[PATH_MAX];47 /** The current umask of the process. */48 extern mode_t __libc_gfsUMask;49 50 51 /** @name Unix Attribute EA Names52 * @{ */53 /** Symlink EA name. */54 #define EA_SYMLINK "SYMLINK"55 /** File EA owner. */56 #define EA_UID "UID"57 /** File EA group. */58 #define EA_GID "GID"59 /** File EA mode. */60 #define EA_MODE "MODE"61 /** File EA i-node number. */62 #define EA_INO "INO"63 /** File EA rdev number. */64 #define EA_RDEV "RDEV"65 /** File EA gen number. */66 #define EA_GEN "GEN"67 /** File EA user flags. */68 #define EA_FLAGS "FLAGS"69 /** @} */70 71 /** The minimum EA size of a file for it to possibly contain any LIBC Unix EAs. */72 #define LIBC_UNIX_EA_MIN (1 + 1 + 2 + sizeof("???") + 2 + 2 + sizeof(uint32_t))73 74 #ifdef _OS2EMX_H75 76 /**77 * The prefilled FEA2LIST construct for creating all unix attributes except symlink.78 */79 #pragma pack(1)80 extern const struct __LIBC_FSUNIXATTRIBSCREATEFEA2LIST81 {82 ULONG cbList;83 84 ULONG offUID;85 BYTE fUIDEA;86 BYTE cbUIDName;87 USHORT cbUIDValue;88 CHAR szUIDName[sizeof(EA_UID)];89 USHORT usUIDType;90 USHORT cbUIDData;91 uint32_t u32UID;92 CHAR achUIDAlign[((sizeof(EA_UID) + 4) & ~3) - sizeof(EA_UID)];93 94 ULONG offGID;95 BYTE fGIDEA;96 BYTE cbGIDName;97 USHORT usGIDValue;98 CHAR szGIDName[sizeof(EA_GID)];99 USHORT usGIDType;100 USHORT cbGIDData;101 uint32_t u32GID;102 CHAR achGIDAlign[((sizeof(EA_GID) + 4) & ~3) - sizeof(EA_GID)];103 104 ULONG offMode;105 BYTE fModeEA;106 BYTE cbModeName;107 USHORT usModeValue;108 CHAR szModeName[sizeof(EA_MODE)];109 USHORT usModeType;110 USHORT cbModeData;111 uint32_t u32Mode;112 CHAR achModeAlign[((sizeof(EA_MODE) + 4) & ~3) - sizeof(EA_MODE)];113 114 ULONG offINO;115 BYTE fINOEA;116 BYTE cbINOName;117 USHORT usINOValue;118 CHAR szINOName[sizeof(EA_INO)];119 USHORT usINOType;120 USHORT cbINOData;121 uint64_t u64INO;122 CHAR achINOAlign[((sizeof(EA_INO) + 4) & ~3) - sizeof(EA_INO)];123 124 ULONG offRDev;125 BYTE fRDevEA;126 BYTE cbRDevName;127 USHORT usRDevValue;128 CHAR szRDevName[sizeof(EA_RDEV)];129 USHORT usRDevType;130 USHORT cbRDevData;131 uint32_t u32RDev;132 CHAR achGDAlign[((sizeof(EA_RDEV) + 4) & ~3) - sizeof(EA_RDEV)];133 134 ULONG offGen;135 BYTE fGenEA;136 BYTE cbGenName;137 USHORT usGenValue;138 CHAR szGenName[sizeof(EA_GEN)];139 USHORT usGenType;140 USHORT cbGenData;141 uint32_t u32Gen;142 CHAR achGenAlign[((sizeof(EA_GEN) + 4) & ~3) - sizeof(EA_GEN)];143 144 ULONG offFlags;145 BYTE fFlagsEA;146 BYTE cbFlagsName;147 USHORT usFlagsValue;148 CHAR szFlagsName[sizeof(EA_FLAGS)];149 USHORT usFlagsType;150 USHORT cbFlagsData;151 uint32_t u32Flags;152 CHAR achFlagsAlign[((sizeof(EA_FLAGS) + 4) & ~3) - sizeof(EA_FLAGS)];153 154 } __libc_gFsUnixAttribsCreateFEA2List;155 #pragma pack()156 157 158 /**159 * The prefilled GEA2LIST construct for querying all unix attributes.160 */161 #pragma pack(1)162 extern const struct __LIBC_BACK_FSUNIXATTRIBSGEA2LIST163 {164 ULONG cbList;165 166 ULONG offSymlink;167 BYTE cbSymlinkName;168 CHAR szSymlinkName[((sizeof(EA_SYMLINK) + 4) & ~3) - 1];169 170 ULONG offUID;171 BYTE cbUIDName;172 CHAR szUIDName[((sizeof(EA_UID) + 4) & ~3) - 1];173 174 ULONG offGID;175 BYTE cbGIDName;176 CHAR szGIDName[((sizeof(EA_GID) + 4) & ~3) - 1];177 178 ULONG offMode;179 BYTE cbModeName;180 CHAR szModeName[((sizeof(EA_MODE) + 4) & ~3) - 1];181 182 ULONG offINO;183 BYTE cbINOName;184 CHAR szINOName[((sizeof(EA_INO) + 4) & ~3) - 1];185 186 ULONG offRDev;187 BYTE cbRDevName;188 CHAR szRDevName[((sizeof(EA_RDEV) + 4) & ~3) - 1];189 190 ULONG offGen;191 BYTE cbGenName;192 CHAR szGenName[((sizeof(EA_GEN) + 4) & ~3) - 1];193 194 ULONG offFlags;195 BYTE cbFlagsName;196 CHAR szFlagsName[((sizeof(EA_FLAGS) + 4) & ~3) - 1];197 } __libc_gFsUnixAttribsGEA2List;198 #pragma pack()199 200 201 /**202 * The prefilled GEA2LIST construct for querying unix attributes for directory listing.203 */204 #pragma pack(1)205 extern const struct __LIBC_BACK_FSUNIXATTRIBSDIRGEA2LIST206 {207 ULONG cbList;208 209 ULONG offMode;210 BYTE cbModeName;211 CHAR szModeName[((sizeof(EA_MODE) + 4) & ~3) - 1];212 213 ULONG offINO;214 BYTE cbINOName;215 CHAR szINOName[((sizeof(EA_INO) + 4) & ~3) - 1];216 } __libc_gFsUnixAttribsDirGEA2List;217 #pragma pack()218 219 220 #endif /* _OS2EMX_H */221 222 /**223 * Init the file system stuff.224 *225 * @returns 0 on success.226 * @returns -1 on failure.227 */228 int __libc_back_fsInit(void);229 230 /**231 * Pack inherit data.232 * @returns 0 on success.233 * @returns -1 on failure.234 * @param ppFS Where to store the pointer to the inherit data, part 1.235 * @param pcbFS Where to store the size of the inherit data, part 1.236 * @param ppFS2 Where to store the pointer to the inherit data, part 2.237 * @param pcbFS2 Where to store the size of the inherit data, part 2.238 */239 int __libc_back_fsInheritPack(__LIBC_PSPMINHFS *ppFS, size_t *pcbFS, __LIBC_PSPMINHFS2 *ppFS2, size_t *pcbFS2);240 241 /**242 * Request the owner ship of the FS mutex.243 *244 * @returns 0 on success.245 * @returns -1 and errno on failure.246 */247 int __libc_back_fsMutexRequest(void);248 249 /**250 * Releases the owner ship of the FS mutex obtained by __libc_back_fsMutexRelease().251 */252 void __libc_back_fsMutexRelease(void);253 254 /**255 * Updates the global unix root stuff.256 * Assumes caller have locked the fs stuff.257 *258 * @param pszUnixRoot The new unix root. Fully resolved and existing.259 */260 void __libc_back_fsUpdateUnixRoot(const char *pszUnixRoot);261 262 /**263 * Resolves and verifies the user path to a native path.264 *265 * @returns 0 on success.266 * @returns Negative error code (errno.h) on failiure.267 * @param pszUserPath The user path.268 * @parm fFlags Flags controlling the operation of the function.269 * See the BACKFS_FLAGS_* defines.270 * @param pszNativePath Where to store the native path. This buffer is at271 * least PATH_MAX bytes big.272 * @param pfInUnixTree Where to store the result-in-unix-tree indicator. Optional.273 */274 int __libc_back_fsResolve(const char *pszUserPath, unsigned fFlags, char *pszNativePath, int *pfInUnixTree);275 276 /** __libc_back_fsResolve() flags.277 * @{ */278 /** Resolves the path up to but not including the last component. */279 #define BACKFS_FLAGS_RESOLVE_PARENT 0x00280 /** Resolves and verfies the entire path. */281 #define BACKFS_FLAGS_RESOLVE_FULL 0x01282 /** Resolves and verfies the entire path, but don't resolve any symlink in the last component. */283 #define BACKFS_FLAGS_RESOLVE_FULL_SYMLINK 0x02284 /** Internal, use BACKFS_FLAGS_RESOLVE_FULL_MAYBE. */285 #define BACKFS_FLAGS_RESOLVE_FULL_MAYBE_ 0x08286 /** Resolves and verfies the entire path but it's ok if the last component doesn't exist. */287 #define BACKFS_FLAGS_RESOLVE_FULL_MAYBE (BACKFS_FLAGS_RESOLVE_FULL_MAYBE_ | BACKFS_FLAGS_RESOLVE_FULL)288 /** Resolves and verfies the entire path but it's ok if the last component doesn't exist. */289 #define BACKFS_FLAGS_RESOLVE_FULL_SYMLINK_MAYBE (BACKFS_FLAGS_RESOLVE_FULL_MAYBE_ | BACKFS_FLAGS_RESOLVE_FULL_SYMLINK)290 /** The specified path is a directory. */291 #define BACKFS_FLAGS_RESOLVE_DIR 0x10292 /** Internal, use BACKFS_FLAGS_RESOLVE_DIR_MAYBE. */293 #define BACKFS_FLAGS_RESOLVE_DIR_MAYBE_ 0x80294 /** The specified path maybe a directory. */295 #define BACKFS_FLAGS_RESOLVE_DIR_MAYBE (BACKFS_FLAGS_RESOLVE_DIR_MAYBE_ | BACKFS_FLAGS_RESOLVE_DIR)296 /** @} */297 298 299 #ifdef _OS2EMX_H300 /**301 * Initializes a unix attribute structure before creating a new inode.302 * The call must have assigned default values to the the structure before doing this call!303 *304 * @returns Device number.305 * @param pFEas The attribute structure to fill with actual values.306 * @param pszNativePath The native path, used to calculate the inode number.307 * @param Mode The correct mode (the caller have fixed this!).308 */309 dev_t __libc_back_fsUnixAttribsInit(struct __LIBC_FSUNIXATTRIBSCREATEFEA2LIST *pFEas, char *pszNativePath, mode_t Mode);310 #endif /* _OS2EMX_H */311 312 /**313 * Reads the unix EAs for a file which is being stat'ed.314 *315 * @returns 0 on success.316 * @returns Negative errno on failure.317 * @param hFile File handle to the fs object. If no handle handy, set to -1.318 * @param pszNativePath Native path to the fs object. If handle is give this will be ignored.319 * @param pStat Pointer to the stat buffer.320 * The buffer is only updated if and with the EAs we find,321 * so the caller must fill the fields with defaults before322 * calling this function.323 */324 int __libc_back_fsUnixAttribsGet(int hFile, const char *pszNativePath, struct stat *pStat);325 326 /**327 * Reads the unix file mode EA.328 *329 * @returns 0 on success.330 * @returns -ENOTSUP if the file mode EA is not present or if Unix EAs isn't supported on the volume.331 * @returns Negative errno on failure.332 * @param hFile File handle to the fs object. If no handle handy, set to -1.333 * @param pszNativePath Native path to the fs object. If handle is give this will be ignored.334 * @param pMode Where to store the mode mask.335 */336 int __libc_back_fsUnixAttribsGetMode(int hFile, const char *pszNativePath, mode_t *pMode);337 338 /**339 * Creates a symbolic link.340 *341 * @returns 0 on success.342 * @returns Negative error code (errno.h) on failure.343 * @param pszTarget The target of the symlink link.344 * @param pszNativePath The path to the symbolic link to create.345 * This is not 'const' because the unix attribute init routine may have to346 * temporarily modify it to read the sticky bit from the parent directory.347 */348 int __libc_back_fsNativeSymlinkCreate(const char *pszTarget, char *pszNativePath);349 350 /**351 * Reads the content of a symbolic link.352 *353 * This is weird interface as it will return a truncated result if not354 * enough buffer space. It is also weird in that there is no string355 * terminator.356 *357 * @returns Number of bytes returned in pachBuf.358 * @returns -1 and errno on failure.359 * @param pszNativePath The path to the symlink to read.360 * @param pachBuf Where to store the symlink value.361 * @param cchBuf Size of buffer.362 */363 int __libc_back_fsNativeSymlinkRead(const char *pszNativePath, char *pachBuf, size_t cchBuf);364 365 /**366 * Stats a native file.367 *368 * @returns 0 on success.369 * @returns -1 and errno on failure.370 * @param pszNativePath Path to the file to stat. This path is resolved, no371 * processing required.372 * @param pStat Where to store the file stats.373 */374 int __libc_back_fsNativeFileStat(const char *pszNativePath, struct stat *pStat);375 376 /**377 * Sets the file access mode of a native file.378 *379 * @returns 0 on success.380 * @returns Negative error code (errno.h) on failure.381 * @param fh Handle to file.382 * @param Mode The filemode.383 */384 int __libc_back_fsNativeFileModeSet(const char *pszNativePath, mode_t Mode);385 386 /**387 * Sets the file times of a native file.388 *389 * @returns 0 on success.390 * @returns Negative error code (errno.h) on failure.391 * @param pszNativePath Path to the file to set the times of.392 * @param paTimes Two timevalue structures. If NULL the current time is used.393 */394 int __libc_back_fsNativeFileTimesSet(const char *pszNativePath, const struct timeval *paTimes);395 396 /**397 * Calc the Inode and Dev based on native path.398 *399 * @returns device number and *pInode.400 *401 * @param pszNativePath Pointer to native path.402 * @param pInode Where to store the inode number.403 * @remark This doesn't work right when in non-unix mode!404 */405 dev_t __libc_back_fsPathCalcInodeAndDev(const char *pszNativePath, ino_t *pInode);406 407 /**408 * Gets the fs info object for the specfied path.409 *410 * @returns Pointer to info object for the path, if it got one.411 * @param Dev The device we want the file system object for.412 */413 __LIBC_PFSINFO __libc_back_fsInfoObjByDev(dev_t Dev);414 415 /**416 * Gets the fs info object for the specfied path.417 *418 * @returns Pointer to info object for the path, if it got one.419 * @param pszNativePath The native path as returned by the resolver.420 */421 __LIBC_PFSINFO __libc_back_fsInfoObjByPath(const char *pszNativePath);422 423 /**424 * Gets the fs info object for the specfied path, with cache.425 *426 * @returns Pointer to info object for the path, if it got one.427 * @param pszNativePath The native path as returned by the resolver.428 * @param pCached An cached fs info object reference. Can be NULL.429 */430 __LIBC_PFSINFO __libc_back_fsInfoObjByPathCached(const char *pszNativePath, __LIBC_PFSINFO pCached);431 432 /**433 * Adds a reference to an existing FS info object.434 *435 * The caller is responsible for making sure that the object cannot436 * reach 0 references while inside this function.437 *438 * @returns pFsInfo.439 * @param pFsInfo Pointer to the fs info object to reference.440 */441 __LIBC_PFSINFO __libc_back_fsInfoObjAddRef(__LIBC_PFSINFO pFsInfo);442 443 /**444 * Releases the fs info object for the specfied path.445 *446 * @param pFsInfo Pointer to the fs info object to release a reference to.447 */448 void __libc_back_fsInfoObjRelease(__LIBC_PFSINFO pFsInfo);449 450 /**451 * Checks if the path supports Unix EAs or not.452 *453 * @returns true / false.454 * @param pszNativePath The native path to check.455 */456 int __libc_back_fsInfoSupportUnixEAs(const char *pszNativePath);457 458 __END_DECLS459 460 #endif -
trunk/libc/src/kNIX/fs.c
r2742 r2903 30 30 *******************************************************************************/ 31 31 #define __LIBC_LOG_GROUP __LIBC_LOG_GRP_BACK_FS 32 #define _GNU_SOURCE 32 33 #include "kNIX.h" 33 #define _GNU_SOURCE34 #include <stddef.h>35 #include <string.h>36 #include <errno.h>37 #include <sys/stat.h>38 #include <sys/fmutex.h>39 #include <sys/smutex.h>40 #include <emx/startup.h>41 #ifdef __OS2__42 # include <InnoTekLIBC/sharedpm.h> //???43 # include <InnoTekLIBC/pathrewrite.h>//??!44 #endif45 34 #include <klibc/backend.h> 46 35 #include <klibc/logstrict.h> … … 64 53 65 54 66 #ifdef __OS2__67 /**68 * The special /@unixroot rewrite rule.69 */70 static __LIBC_PATHREWRITE gaRewriteRule =71 {72 __LIBC_PRWF_CASE_SENSITIVE | __LIBC_PRWF_TYPE_DIR, "/@unixroot", 10, __libc_gszUnixRoot, 073 };74 #endif75 76 77 55 /******************************************************************************* 78 56 * Internal Functions * … … 110 88 LIBCLOG_RETURN_INT(-1); 111 89 112 #ifdef __OS2__ /** @todo move this! */ 113 /* 114 * Inherit File System Data from parent. 115 */ 116 __LIBC_PSPMINHERIT pInherit = __libc_spmInheritRequest(); 117 118 /* part 2, the umask. */ 119 __LIBC_PSPMINHFS2 pFS2; 120 if ( pInherit 121 && pInherit->cb > offsetof(__LIBC_SPMINHERIT, pFS2) 122 && (pFS2 = pInherit->pFS2) != NULL 123 && !(pFS2->fUMask & ~0777)) 124 { 125 LIBCLOG_MSG("Inherited fUMask=%04o\n", pFS2->fUMask); 126 __libc_gfsUMask = pFS2->fUMask & 0777; 127 } 128 129 /* part 1, the unixroot. */ 130 __LIBC_PSPMINHFS pFS; 131 if ( pInherit 132 && pInherit->cb > offsetof(__LIBC_SPMINHERIT, pFS) 133 && (pFS = pInherit->pFS) != NULL 134 && pFS->cchUnixRoot) 135 { 136 LIBCLOG_MSG("Inherited unixroot=%s fInUnixTree=%d cchUnixRoot=%d\n", pFS->szUnixRoot, pFS->fInUnixTree, pFS->cchUnixRoot); 137 __libc_gfNoUnix = 0; 138 __libc_gfInUnixTree = pFS->fInUnixTree; 139 __libc_gcchUnixRoot = pFS->cchUnixRoot; 140 memcpy(&__libc_gszUnixRoot[0], &pFS->szUnixRoot[0], pFS->cchUnixRoot + 1); 141 142 __libc_spmInheritRelease(); 143 144 /* Register rewrite rule. */ 145 gaRewriteRule.pszTo = "/"; 146 gaRewriteRule.cchTo = 1; 147 if (__libc_PathRewriteAdd(&gaRewriteRule, 1)) 148 LIBCLOG_RETURN_INT(-1); 149 } 150 else 151 { 152 /* 153 * Nothing to inherit. 154 */ 155 if (pInherit) 156 __libc_spmInheritRelease(); 157 if (!__libc_gfNoUnix) 158 { 159 /* 160 * Setup unofficial unixroot. 161 */ 162 const char *psz = getenv("UNIXROOT"); 163 if (psz) 164 { 165 LIBCLOG_MSG("Unofficial unixroot=%s\n", psz); 166 size_t cch = strlen(psz); 167 if (cch >= PATH_MAX - 32) 168 { 169 LIBC_ASSERTM_FAILED("The UNIXROOT environment variable is too long! cch=%d maxlength=%d\n", cch, PATH_MAX - 32); 170 LIBCLOG_RETURN_INT(-1); 171 } 172 memcpy(&__libc_gszUnixRoot[0], psz, cch + 1); 173 174 /* Register the rewrite rule. */ 175 gaRewriteRule.cchTo = cch; 176 if (__libc_PathRewriteAdd(&gaRewriteRule, 1)) 177 LIBCLOG_RETURN_INT(-1); 178 } 179 } 180 } 181 182 183 /* 184 * Try resolve large file APIs. 185 * 186 * First, get a handle to DOSCALLS/DOSCALL1 which is suitable 187 * for DosQueryProcAddr. 188 * Second, query the procedure addresses. 189 * Third, free DOSCALLS since there's no point messing up any 190 * reference counters for that module. 191 */ 192 HMODULE hmod = NULLHANDLE; 193 if (DosLoadModule(NULL, 0, (PCSZ)"DOSCALLS", &hmod)) 194 { 195 LIBC_ASSERTM_FAILED("DosLoadModule failed on doscalls!\n"); 196 abort(); 197 LIBCLOG_RETURN_INT(-1); 198 } 199 if ( DosQueryProcAddr(hmod, ORD_DOS32OPENL, NULL, (PFN*)(void *)&__libc_gpfnDosOpenL) 200 || DosQueryProcAddr(hmod, ORD_DOS32SETFILEPTRL, NULL, (PFN*)(void *)&__libc_gpfnDosSetFilePtrL) 201 || DosQueryProcAddr(hmod, ORD_DOS32SETFILESIZEL, NULL, (PFN*)(void *)&__libc_gpfnDosSetFileSizeL) 202 || DosQueryProcAddr(hmod, ORD_DOS32SETFILELOCKSL, NULL, (PFN*)(void *)&__libc_gpfnDosSetFileLocksL) 203 ) 204 { 205 __libc_gpfnDosOpenL = NULL; 206 __libc_gpfnDosSetFilePtrL = NULL; 207 __libc_gpfnDosSetFileSizeL = NULL; 208 __libc_gpfnDosSetFileLocksL = NULL; 209 } 210 DosFreeModule(hmod); 211 #endif /* __OS2__ */ 212 LIBCLOG_RETURN_INT(0); 213 } 214 215 #ifdef __OS2__ /** @todo move this! */ 216 /** 217 * Pack inherit data. 218 * @returns 0 on success. 219 * @returns -1 on failure. 220 * @param ppFS Where to store the pointer to the inherit data, part 1. 221 * @param pcbFS Where to store the size of the inherit data, part 1. 222 * @param ppFS2 Where to store the pointer to the inherit data, part 2. 223 * @param pcbFS2 Where to store the size of the inherit data, part 2. 224 */ 225 int __libc_back_fsInheritPack(__LIBC_PSPMINHFS *ppFS, size_t *pcbFS, __LIBC_PSPMINHFS2 *ppFS2, size_t *pcbFS2) 226 { 227 LIBCLOG_ENTER("ppFS=%p pcbFS=%p ppFS2=%p pcbFS2=%p\n", (void *)ppFS, (void *)pcbFS, (void *)ppFS2, (void *)pcbFS2); 228 229 *ppFS = NULL; 230 *pcbFS = 0; 231 *ppFS2 = NULL; 232 *pcbFS2 = 0; 233 234 if (__libc_back_fsMutexRequest()) 235 return -1; 236 237 int rc = 0; 238 if (__libc_gcchUnixRoot) 239 { 240 size_t cb = sizeof(__LIBC_SPMINHFS) + __libc_gcchUnixRoot; 241 __LIBC_PSPMINHFS pFS = (__LIBC_PSPMINHFS)malloc(cb); 242 if (pFS) 243 { 244 pFS->fInUnixTree = __libc_gfInUnixTree; 245 pFS->cchUnixRoot = __libc_gcchUnixRoot; 246 memcpy(pFS->szUnixRoot, __libc_gszUnixRoot, pFS->cchUnixRoot + 1); 247 LIBCLOG_MSG("unixroot=%s fInUnixTree=%d cchUnixRoot=%d\n", pFS->szUnixRoot, pFS->fInUnixTree, pFS->cchUnixRoot); 248 249 *pcbFS = cb; 250 *ppFS = pFS; 251 } 252 else 253 rc = -1; 254 } 255 256 if (!rc) 257 { 258 __LIBC_PSPMINHFS2 pFS2 = (__LIBC_PSPMINHFS2)malloc(sizeof(*pFS2)); 259 if (pFS2) 260 { 261 pFS2->cb = sizeof(*pFS2); 262 pFS2->fUMask = __libc_gfsUMask; 263 LIBCLOG_MSG("fUMask=%04o\n", pFS2->fUMask); 264 265 *pcbFS2 = sizeof(*pFS2); 266 *ppFS2 = pFS2; 267 } 268 else 269 rc = -1; 270 } 271 272 __libc_back_fsMutexRelease(); 273 LIBCLOG_RETURN_INT(rc); 274 } 275 #endif /*__OS2__ */ 276 90 /* 91 * OS specific init. 92 */ 93 rc = __libc_back_fsInitOS(); 94 LIBCLOG_MIX0_RETURN_INT(rc); 95 } 277 96 278 97 int __libc_back_fsMutexRequest(void) … … 302 121 void __libc_back_fsUpdateUnixRoot(const char *pszUnixRoot) 303 122 { 304 #ifdef __OS2__305 gaRewriteRule.pszTo = "/";306 gaRewriteRule.cchTo = 1;307 #endif308 309 123 int cch = strlen(pszUnixRoot); 310 124 memcpy(__libc_gszUnixRoot, pszUnixRoot, cch + 1); 311 125 __libc_gcchUnixRoot = cch; 126 127 __libc_back_fsUpdateUnixRootOS(pszUnixRoot); 312 128 } 313 129 … … 350 166 351 167 352 #ifdef __OS2__353 /**354 * Gets the fs info object for the specfied path.355 *356 * @returns Pointer to info object for the path, if it got one.357 * @param Dev The device we want the file system object for.358 */359 __LIBC_PFSINFO __libc_back_fsInfoObjByDev(dev_t Dev)360 {361 __LIBC_PFSINFO pFsInfo = NULL;362 char chDrv = minor(Dev);363 if ( major(Dev) == 'V'364 && chDrv >= 'A' && chDrv <= 'Z')365 {366 pFsInfo = &g_aFSInfoVolumes[(int)chDrv];367 _fmutex_request(&g_mtxFSInfoVolumes, 0);368 int cRefs = __atomic_increment_s32(&pFsInfo->cRefs);369 LIBC_ASSERT(cRefs > 0);370 if (cRefs <= 0)371 pFsInfo->cRefs = cRefs = 1;372 if (cRefs == 1)373 fsInfoObjUpdate(pFsInfo, Dev);374 _fmutex_release(&g_mtxFSInfoVolumes);375 }376 else377 {378 LIBC_ASSERTM(major(Dev) != 'V', "Dev=%#x major=%#x (%c) chDrv=%c\n", Dev, major(Dev), major(Dev), chDrv);379 LIBC_ASSERTM(major(Dev) != 'U' || minor(chDrv) == 0, "Dev=%#x major=%#x (%c)\n", Dev, major(Dev), major(Dev));380 }381 382 return pFsInfo;383 }384 385 386 /**387 * Gets the fs info object for the specfied path.388 *389 * @returns Pointer to info object for the path, if it got one.390 * @param pszNativePath The native path as returned by the resolver.391 */392 __LIBC_PFSINFO __libc_back_fsInfoObjByPath(const char *pszNativePath)393 {394 /*395 * Calc device.396 */397 dev_t Dev;398 char chDrv = *pszNativePath;399 if (chDrv == '/' || chDrv == '\\')400 Dev = makedev('U', 0); /* U as in UNC */401 else402 {403 LIBC_ASSERT(chDrv >= 'A' && chDrv <= 'Z');404 Dev = makedev('V', chDrv); /* V as in Volume */405 }406 return __libc_back_fsInfoObjByDev(Dev);407 }408 409 410 /**411 * Gets the fs info object for the specfied path, with cache.412 *413 * @returns Pointer to info object for the path, if it got one.414 * @param pszNativePath The native path as returned by the resolver.415 * @param pCached An cached fs info object reference. Can be NULL.416 */417 __LIBC_PFSINFO __libc_back_fsInfoObjByPathCached(const char *pszNativePath, __LIBC_PFSINFO pCached)418 {419 /*420 * Calc device.421 */422 dev_t Dev;423 char chDrv = *pszNativePath;424 if (chDrv == '/' || chDrv == '\\')425 Dev = makedev('U', 0); /* U as in UNC */426 else427 {428 LIBC_ASSERT(chDrv >= 'A' && chDrv <= 'Z');429 Dev = makedev('V', chDrv); /* V as in Volume */430 }431 if (!pCached)432 return __libc_back_fsInfoObjByDev(Dev);433 if (pCached->Dev == Dev)434 return pCached;435 __libc_back_fsInfoObjRelease(pCached);436 return __libc_back_fsInfoObjByDev(Dev);437 }438 #endif439 440 441 168 /** 442 169 * Adds a reference to an existing FS info object. … … 472 199 } 473 200 } 474 475 476 #ifdef __OS2__477 /**478 * Checks if the path supports Unix EAs or not.479 *480 * @returns true / false.481 * @param pszNativePath The native path to check.482 */483 int __libc_back_fsInfoSupportUnixEAs(const char *pszNativePath)484 {485 if (__libc_gfNoUnix)486 return 0;487 488 __LIBC_PFSINFO pFsInfo = __libc_back_fsInfoObjByPath(pszNativePath);489 const int fUnixEAs = pFsInfo && pFsInfo->fUnixEAs;490 __libc_back_fsInfoObjRelease(pFsInfo);491 return fUnixEAs;492 }493 #endif494 201 495 202 -
trunk/libc/src/kNIX/kNIX.h
r2819 r2903 104 104 /** @} */ 105 105 106 /** @name File System 107 * @{ 108 */ 109 /** Indicator whether or not we're in the unix tree. */ 110 extern int __libc_gfInUnixTree; 111 /** Length of the unix root if the unix root is official. */ 112 extern int __libc_gcchUnixRoot; 113 /** The current unix root. */ 114 extern char __libc_gszUnixRoot[PATH_MAX]; 115 /** The current umask of the process. */ 116 extern mode_t __libc_gfsUMask; 117 118 int __libc_back_fsInit(void); 119 int __libc_back_fsInitOS(void); 120 int __libc_back_fsMutexRequest(void); 121 void __libc_back_fsMutexRelease(void); 122 void __libc_back_fsUpdateUnixRoot(const char *pszUnixRoot); 123 void __libc_back_fsUpdateUnixRootOS(const char *pszUnixRoot); 124 int __libc_back_fsResolve(const char *pszUserPath, unsigned fFlags, char *pszNativePath, int *pfInUnixTree); 125 126 /** @name __libc_back_fsResolve() flags. 127 * @{ */ 128 /** Resolves the path up to but not including the last component. */ 129 #define BACKFS_FLAGS_RESOLVE_PARENT 0x00 130 /** Resolves and verfies the entire path. */ 131 #define BACKFS_FLAGS_RESOLVE_FULL 0x01 132 /** Resolves and verfies the entire path, but don't resolve any symlink in the last component. */ 133 #define BACKFS_FLAGS_RESOLVE_FULL_SYMLINK 0x02 134 /** Internal, use BACKFS_FLAGS_RESOLVE_FULL_MAYBE. */ 135 #define BACKFS_FLAGS_RESOLVE_FULL_MAYBE_ 0x08 136 /** Resolves and verfies the entire path but it's ok if the last component doesn't exist. */ 137 #define BACKFS_FLAGS_RESOLVE_FULL_MAYBE (BACKFS_FLAGS_RESOLVE_FULL_MAYBE_ | BACKFS_FLAGS_RESOLVE_FULL) 138 /** Resolves and verfies the entire path but it's ok if the last component doesn't exist. */ 139 #define BACKFS_FLAGS_RESOLVE_FULL_SYMLINK_MAYBE (BACKFS_FLAGS_RESOLVE_FULL_MAYBE_ | BACKFS_FLAGS_RESOLVE_FULL_SYMLINK) 140 /** The specified path is a directory. */ 141 #define BACKFS_FLAGS_RESOLVE_DIR 0x10 142 /** Internal, use BACKFS_FLAGS_RESOLVE_DIR_MAYBE. */ 143 #define BACKFS_FLAGS_RESOLVE_DIR_MAYBE_ 0x80 144 /** The specified path maybe a directory. */ 145 #define BACKFS_FLAGS_RESOLVE_DIR_MAYBE (BACKFS_FLAGS_RESOLVE_DIR_MAYBE_ | BACKFS_FLAGS_RESOLVE_DIR) 146 /** @} */ 147 148 int __libc_back_fsUnixAttribsGet(int hFile, const char *pszNativePath, struct stat *pStat); 149 int __libc_back_fsUnixAttribsGetMode(int hFile, const char *pszNativePath, mode_t *pMode); 150 int __libc_back_fsNativeSymlinkCreate(const char *pszTarget, char *pszNativePath); 151 int __libc_back_fsNativeSymlinkRead(const char *pszNativePath, char *pachBuf, size_t cchBuf); 152 int __libc_back_fsNativeFileStat(const char *pszNativePath, struct stat *pStat); 153 int __libc_back_fsNativeFileModeSet(const char *pszNativePath, mode_t Mode); 154 int __libc_back_fsNativeFileTimesSet(const char *pszNativePath, const struct timeval *paTimes); 155 dev_t __libc_back_fsPathCalcInodeAndDev(const char *pszNativePath, ino_t *pInode); 156 __LIBC_PFSINFO __libc_back_fsInfoObjByDev(dev_t Dev); 157 __LIBC_PFSINFO __libc_back_fsInfoObjByPath(const char *pszNativePath); 158 __LIBC_PFSINFO __libc_back_fsInfoObjByPathCached(const char *pszNativePath, __LIBC_PFSINFO pCached); 159 __LIBC_PFSINFO __libc_back_fsInfoObjAddRef(__LIBC_PFSINFO pFsInfo); 160 void __libc_back_fsInfoObjRelease(__LIBC_PFSINFO pFsInfo); 161 /** @} */ 106 162 107 163 /** @name ?? -
trunk/libc/src/kNIX/os2/kNIX-os2.h
r2805 r2903 29 29 30 30 #include "../backend.h" /** @todo remove backend.h! */ 31 31 #include <InnoTekLIBC/sharedpm.h> 32 33 __BEGIN_DECLS 32 34 33 35 #ifdef INCL_DOSFILEMGR 34 /** @ groupLarge File Support - API pointers.36 /** @name Large File Support - API pointers. 35 37 * Test if the function pointer is set before calling it. 36 38 * For APIs which take a structure level parameter, check __pfnDosOpenL. … … 43 45 #endif /* INCL_DOSFILEMGR */ 44 46 47 /** @name Unix Attribute EA Names 48 * @{ */ 49 /** Symlink EA name. */ 50 #define EA_SYMLINK "SYMLINK" 51 /** File EA owner. */ 52 #define EA_UID "UID" 53 /** File EA group. */ 54 #define EA_GID "GID" 55 /** File EA mode. */ 56 #define EA_MODE "MODE" 57 /** File EA i-node number. */ 58 #define EA_INO "INO" 59 /** File EA rdev number. */ 60 #define EA_RDEV "RDEV" 61 /** File EA gen number. */ 62 #define EA_GEN "GEN" 63 /** File EA user flags. */ 64 #define EA_FLAGS "FLAGS" 65 /** @} */ 66 67 /** The minimum EA size of a file for it to possibly contain any LIBC Unix EAs. */ 68 #define LIBC_UNIX_EA_MIN (1 + 1 + 2 + sizeof("???") + 2 + 2 + sizeof(uint32_t)) 69 70 #ifdef _OS2EMX_H 71 72 /** 73 * The prefilled FEA2LIST construct for creating all unix attributes except symlink. 74 */ 75 #pragma pack(1) 76 extern const struct __LIBC_FSUNIXATTRIBSCREATEFEA2LIST 77 { 78 ULONG cbList; 79 80 ULONG offUID; 81 BYTE fUIDEA; 82 BYTE cbUIDName; 83 USHORT cbUIDValue; 84 CHAR szUIDName[sizeof(EA_UID)]; 85 USHORT usUIDType; 86 USHORT cbUIDData; 87 uint32_t u32UID; 88 CHAR achUIDAlign[((sizeof(EA_UID) + 4) & ~3) - sizeof(EA_UID)]; 89 90 ULONG offGID; 91 BYTE fGIDEA; 92 BYTE cbGIDName; 93 USHORT usGIDValue; 94 CHAR szGIDName[sizeof(EA_GID)]; 95 USHORT usGIDType; 96 USHORT cbGIDData; 97 uint32_t u32GID; 98 CHAR achGIDAlign[((sizeof(EA_GID) + 4) & ~3) - sizeof(EA_GID)]; 99 100 ULONG offMode; 101 BYTE fModeEA; 102 BYTE cbModeName; 103 USHORT usModeValue; 104 CHAR szModeName[sizeof(EA_MODE)]; 105 USHORT usModeType; 106 USHORT cbModeData; 107 uint32_t u32Mode; 108 CHAR achModeAlign[((sizeof(EA_MODE) + 4) & ~3) - sizeof(EA_MODE)]; 109 110 ULONG offINO; 111 BYTE fINOEA; 112 BYTE cbINOName; 113 USHORT usINOValue; 114 CHAR szINOName[sizeof(EA_INO)]; 115 USHORT usINOType; 116 USHORT cbINOData; 117 uint64_t u64INO; 118 CHAR achINOAlign[((sizeof(EA_INO) + 4) & ~3) - sizeof(EA_INO)]; 119 120 ULONG offRDev; 121 BYTE fRDevEA; 122 BYTE cbRDevName; 123 USHORT usRDevValue; 124 CHAR szRDevName[sizeof(EA_RDEV)]; 125 USHORT usRDevType; 126 USHORT cbRDevData; 127 uint32_t u32RDev; 128 CHAR achGDAlign[((sizeof(EA_RDEV) + 4) & ~3) - sizeof(EA_RDEV)]; 129 130 ULONG offGen; 131 BYTE fGenEA; 132 BYTE cbGenName; 133 USHORT usGenValue; 134 CHAR szGenName[sizeof(EA_GEN)]; 135 USHORT usGenType; 136 USHORT cbGenData; 137 uint32_t u32Gen; 138 CHAR achGenAlign[((sizeof(EA_GEN) + 4) & ~3) - sizeof(EA_GEN)]; 139 140 ULONG offFlags; 141 BYTE fFlagsEA; 142 BYTE cbFlagsName; 143 USHORT usFlagsValue; 144 CHAR szFlagsName[sizeof(EA_FLAGS)]; 145 USHORT usFlagsType; 146 USHORT cbFlagsData; 147 uint32_t u32Flags; 148 CHAR achFlagsAlign[((sizeof(EA_FLAGS) + 4) & ~3) - sizeof(EA_FLAGS)]; 149 150 } __libc_gFsUnixAttribsCreateFEA2List; 151 #pragma pack() 152 153 154 /** 155 * The prefilled GEA2LIST construct for querying all unix attributes. 156 */ 157 #pragma pack(1) 158 extern const struct __LIBC_BACK_FSUNIXATTRIBSGEA2LIST 159 { 160 ULONG cbList; 161 162 ULONG offSymlink; 163 BYTE cbSymlinkName; 164 CHAR szSymlinkName[((sizeof(EA_SYMLINK) + 4) & ~3) - 1]; 165 166 ULONG offUID; 167 BYTE cbUIDName; 168 CHAR szUIDName[((sizeof(EA_UID) + 4) & ~3) - 1]; 169 170 ULONG offGID; 171 BYTE cbGIDName; 172 CHAR szGIDName[((sizeof(EA_GID) + 4) & ~3) - 1]; 173 174 ULONG offMode; 175 BYTE cbModeName; 176 CHAR szModeName[((sizeof(EA_MODE) + 4) & ~3) - 1]; 177 178 ULONG offINO; 179 BYTE cbINOName; 180 CHAR szINOName[((sizeof(EA_INO) + 4) & ~3) - 1]; 181 182 ULONG offRDev; 183 BYTE cbRDevName; 184 CHAR szRDevName[((sizeof(EA_RDEV) + 4) & ~3) - 1]; 185 186 ULONG offGen; 187 BYTE cbGenName; 188 CHAR szGenName[((sizeof(EA_GEN) + 4) & ~3) - 1]; 189 190 ULONG offFlags; 191 BYTE cbFlagsName; 192 CHAR szFlagsName[((sizeof(EA_FLAGS) + 4) & ~3) - 1]; 193 } __libc_gFsUnixAttribsGEA2List; 194 #pragma pack() 195 196 197 /** 198 * The prefilled GEA2LIST construct for querying unix attributes for directory listing. 199 */ 200 #pragma pack(1) 201 extern const struct __LIBC_BACK_FSUNIXATTRIBSDIRGEA2LIST 202 { 203 ULONG cbList; 204 205 ULONG offMode; 206 BYTE cbModeName; 207 CHAR szModeName[((sizeof(EA_MODE) + 4) & ~3) - 1]; 208 209 ULONG offINO; 210 BYTE cbINOName; 211 CHAR szINOName[((sizeof(EA_INO) + 4) & ~3) - 1]; 212 } __libc_gFsUnixAttribsDirGEA2List; 213 #pragma pack() 214 215 216 dev_t __libc_back_fsUnixAttribsInit(struct __LIBC_FSUNIXATTRIBSCREATEFEA2LIST *pFEas, char *pszNativePath, mode_t Mode); 217 #endif /* _OS2EMX_H */ 218 int __libc_back_fsInfoSupportUnixEAs(const char *pszNativePath); 219 int __libc_back_fsInheritPack(__LIBC_PSPMINHFS *ppFS, size_t *pcbFS, __LIBC_PSPMINHFS2 *ppFS2, size_t *pcbFS2); 220 221 __END_DECLS 45 222 46 223 #endif
Note:
See TracChangeset
for help on using the changeset viewer.