visaljs 0.0.0-stage → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (520) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +45 -2
  3. package/cli.js +8084 -0
  4. package/node/include/js_node.h +46 -0
  5. package/node/prelude/async_hooks.js +88 -0
  6. package/node/prelude/buffer.js +31 -0
  7. package/node/prelude/crypto.js +114 -0
  8. package/node/prelude/events.js +227 -0
  9. package/node/prelude/fs.js +79 -0
  10. package/node/prelude/http.js +536 -0
  11. package/node/prelude/http2.js +30 -0
  12. package/node/prelude/internal/crypto/asym.js +333 -0
  13. package/node/prelude/internal/crypto/cipher.js +205 -0
  14. package/node/prelude/internal/crypto/hash.js +137 -0
  15. package/node/prelude/internal/crypto/kdf.js +182 -0
  16. package/node/prelude/internal/crypto/keys.js +603 -0
  17. package/node/prelude/internal/crypto/random.js +118 -0
  18. package/node/prelude/internal/crypto/util.js +76 -0
  19. package/node/prelude/internal/errors.js +88 -0
  20. package/node/prelude/internal/querystring.js +105 -0
  21. package/node/prelude/module.js +53 -0
  22. package/node/prelude/net.js +51 -0
  23. package/node/prelude/os.js +129 -0
  24. package/node/prelude/path.js +257 -0
  25. package/node/prelude/process.js +21 -0
  26. package/node/prelude/querystring.js +469 -0
  27. package/node/prelude/stream.js +1327 -0
  28. package/node/prelude/stream_promises.js +7 -0
  29. package/node/prelude/stream_web.js +6 -0
  30. package/node/prelude/string_decoder.js +236 -0
  31. package/node/prelude/tty.js +18 -0
  32. package/node/prelude/url.js +1156 -0
  33. package/node/prelude/util.js +64 -0
  34. package/node/prelude/zlib.js +81 -0
  35. package/node/src/host_fs.c +126 -0
  36. package/node/src/host_http.c +486 -0
  37. package/node/src/host_os.c +505 -0
  38. package/node/src/host_sys.c +78 -0
  39. package/node/third_party/libuv/LICENSE +19 -0
  40. package/node/third_party/libuv/include/uv/aix.h +32 -0
  41. package/node/third_party/libuv/include/uv/bsd.h +34 -0
  42. package/node/third_party/libuv/include/uv/darwin.h +61 -0
  43. package/node/third_party/libuv/include/uv/errno.h +483 -0
  44. package/node/third_party/libuv/include/uv/linux.h +34 -0
  45. package/node/third_party/libuv/include/uv/os390.h +33 -0
  46. package/node/third_party/libuv/include/uv/posix.h +31 -0
  47. package/node/third_party/libuv/include/uv/sunos.h +44 -0
  48. package/node/third_party/libuv/include/uv/threadpool.h +37 -0
  49. package/node/third_party/libuv/include/uv/tree.h +521 -0
  50. package/node/third_party/libuv/include/uv/unix.h +512 -0
  51. package/node/third_party/libuv/include/uv/version.h +43 -0
  52. package/node/third_party/libuv/include/uv/win.h +698 -0
  53. package/node/third_party/libuv/include/uv.h +1990 -0
  54. package/node/third_party/libuv/src/fs-poll.c +290 -0
  55. package/node/third_party/libuv/src/heap-inl.h +245 -0
  56. package/node/third_party/libuv/src/idna.c +560 -0
  57. package/node/third_party/libuv/src/idna.h +31 -0
  58. package/node/third_party/libuv/src/inet.c +298 -0
  59. package/node/third_party/libuv/src/queue.h +90 -0
  60. package/node/third_party/libuv/src/random.c +123 -0
  61. package/node/third_party/libuv/src/strscpy.c +38 -0
  62. package/node/third_party/libuv/src/strscpy.h +39 -0
  63. package/node/third_party/libuv/src/strtok.c +52 -0
  64. package/node/third_party/libuv/src/strtok.h +27 -0
  65. package/node/third_party/libuv/src/thread-common.c +175 -0
  66. package/node/third_party/libuv/src/threadpool.c +419 -0
  67. package/node/third_party/libuv/src/timer.c +200 -0
  68. package/node/third_party/libuv/src/unix/async.c +418 -0
  69. package/node/third_party/libuv/src/unix/bsd-ifaddrs.c +164 -0
  70. package/node/third_party/libuv/src/unix/core.c +2104 -0
  71. package/node/third_party/libuv/src/unix/darwin-proctitle.c +176 -0
  72. package/node/third_party/libuv/src/unix/darwin-stub.h +97 -0
  73. package/node/third_party/libuv/src/unix/darwin-syscalls.h +17 -0
  74. package/node/third_party/libuv/src/unix/darwin.c +237 -0
  75. package/node/third_party/libuv/src/unix/dl.c +80 -0
  76. package/node/third_party/libuv/src/unix/fs.c +2303 -0
  77. package/node/third_party/libuv/src/unix/fsevents.c +906 -0
  78. package/node/third_party/libuv/src/unix/getaddrinfo.c +252 -0
  79. package/node/third_party/libuv/src/unix/getnameinfo.c +121 -0
  80. package/node/third_party/libuv/src/unix/internal.h +530 -0
  81. package/node/third_party/libuv/src/unix/kqueue.c +667 -0
  82. package/node/third_party/libuv/src/unix/linux.c +2761 -0
  83. package/node/third_party/libuv/src/unix/loop-watcher.c +68 -0
  84. package/node/third_party/libuv/src/unix/loop.c +240 -0
  85. package/node/third_party/libuv/src/unix/pipe.c +555 -0
  86. package/node/third_party/libuv/src/unix/poll.c +159 -0
  87. package/node/third_party/libuv/src/unix/process.c +1123 -0
  88. package/node/third_party/libuv/src/unix/procfs-exepath.c +45 -0
  89. package/node/third_party/libuv/src/unix/proctitle.c +157 -0
  90. package/node/third_party/libuv/src/unix/random-devurandom.c +93 -0
  91. package/node/third_party/libuv/src/unix/random-getentropy.c +57 -0
  92. package/node/third_party/libuv/src/unix/random-getrandom.c +86 -0
  93. package/node/third_party/libuv/src/unix/random-sysctl-linux.c +99 -0
  94. package/node/third_party/libuv/src/unix/signal.c +581 -0
  95. package/node/third_party/libuv/src/unix/stream.c +1567 -0
  96. package/node/third_party/libuv/src/unix/tcp.c +673 -0
  97. package/node/third_party/libuv/src/unix/thread.c +975 -0
  98. package/node/third_party/libuv/src/unix/tty.c +510 -0
  99. package/node/third_party/libuv/src/unix/udp.c +1434 -0
  100. package/node/third_party/libuv/src/uv-common.c +1051 -0
  101. package/node/third_party/libuv/src/uv-common.h +474 -0
  102. package/node/third_party/libuv/src/uv-data-getter-setters.c +119 -0
  103. package/node/third_party/libuv/src/version.c +45 -0
  104. package/node/third_party/llhttp/LICENSE +22 -0
  105. package/node/third_party/llhttp/api.c +509 -0
  106. package/node/third_party/llhttp/http.c +170 -0
  107. package/node/third_party/llhttp/llhttp.c +10099 -0
  108. package/node/third_party/llhttp/llhttp.h +907 -0
  109. package/package.json +25 -4
  110. package/runtime/include/js_atoms.gen.h +68 -0
  111. package/runtime/include/js_atoms.h +54 -0
  112. package/runtime/include/js_bigint.h +93 -0
  113. package/runtime/include/js_buffer.h +79 -0
  114. package/runtime/include/js_builtins.h +168 -0
  115. package/runtime/include/js_console.h +58 -0
  116. package/runtime/include/js_convert.h +22 -0
  117. package/runtime/include/js_core.def +188 -0
  118. package/runtime/include/js_crypto.h +58 -0
  119. package/runtime/include/js_error.h +37 -0
  120. package/runtime/include/js_exception.h +65 -0
  121. package/runtime/include/js_function.h +167 -0
  122. package/runtime/include/js_gc.h +195 -0
  123. package/runtime/include/js_generator.h +96 -0
  124. package/runtime/include/js_host.h +19 -0
  125. package/runtime/include/js_jobs.h +84 -0
  126. package/runtime/include/js_module.h +16 -0
  127. package/runtime/include/js_object.h +384 -0
  128. package/runtime/include/js_ops.h +111 -0
  129. package/runtime/include/js_promise.h +45 -0
  130. package/runtime/include/js_regexp.h +25 -0
  131. package/runtime/include/js_runtime.h +30 -0
  132. package/runtime/include/js_symbol.h +62 -0
  133. package/runtime/include/js_web.h +110 -0
  134. package/runtime/include/jscell.h +48 -0
  135. package/runtime/include/jscontext.h +240 -0
  136. package/runtime/include/jsnum.h +42 -0
  137. package/runtime/include/jsstring.h +161 -0
  138. package/runtime/include/jsvalue.h +142 -0
  139. package/runtime/src/arguments.c +115 -0
  140. package/runtime/src/array.c +1145 -0
  141. package/runtime/src/arraybuffer.c +608 -0
  142. package/runtime/src/async_iter.c +479 -0
  143. package/runtime/src/atoms.c +157 -0
  144. package/runtime/src/base64.c +107 -0
  145. package/runtime/src/bigint.c +1189 -0
  146. package/runtime/src/blob.c +371 -0
  147. package/runtime/src/buffer.c +1357 -0
  148. package/runtime/src/builtin_table.c +100 -0
  149. package/runtime/src/builtins.c +987 -0
  150. package/runtime/src/builtins_util.h +53 -0
  151. package/runtime/src/collections.c +912 -0
  152. package/runtime/src/components.c +28 -0
  153. package/runtime/src/console.c +637 -0
  154. package/runtime/src/convert.c +82 -0
  155. package/runtime/src/core_all.c +21 -0
  156. package/runtime/src/crypto.c +116 -0
  157. package/runtime/src/crypto_asym.c +644 -0
  158. package/runtime/src/crypto_cipher.c +671 -0
  159. package/runtime/src/crypto_hash.c +260 -0
  160. package/runtime/src/crypto_host.c +414 -0
  161. package/runtime/src/crypto_internal.h +304 -0
  162. package/runtime/src/crypto_kdf.c +143 -0
  163. package/runtime/src/crypto_key.c +171 -0
  164. package/runtime/src/crypto_pkey.c +794 -0
  165. package/runtime/src/crypto_subtle.c +1675 -0
  166. package/runtime/src/date.c +940 -0
  167. package/runtime/src/domexception.c +169 -0
  168. package/runtime/src/elements.c +312 -0
  169. package/runtime/src/elements.h +45 -0
  170. package/runtime/src/encoding.c +485 -0
  171. package/runtime/src/error.c +297 -0
  172. package/runtime/src/events.c +793 -0
  173. package/runtime/src/exception.c +56 -0
  174. package/runtime/src/fetch.c +772 -0
  175. package/runtime/src/function.c +530 -0
  176. package/runtime/src/gc.c +803 -0
  177. package/runtime/src/generator.c +218 -0
  178. package/runtime/src/global.c +119 -0
  179. package/runtime/src/headers.c +557 -0
  180. package/runtime/src/inspect.c +1792 -0
  181. package/runtime/src/internal.h +80 -0
  182. package/runtime/src/iterate.c +94 -0
  183. package/runtime/src/iterator.c +409 -0
  184. package/runtime/src/jobs.c +337 -0
  185. package/runtime/src/jsnum.c +353 -0
  186. package/runtime/src/json.c +1028 -0
  187. package/runtime/src/math.c +243 -0
  188. package/runtime/src/module.c +336 -0
  189. package/runtime/src/number.c +176 -0
  190. package/runtime/src/object.c +1265 -0
  191. package/runtime/src/ops.c +322 -0
  192. package/runtime/src/os.c +196 -0
  193. package/runtime/src/os.h +29 -0
  194. package/runtime/src/process.c +432 -0
  195. package/runtime/src/promise.c +721 -0
  196. package/runtime/src/proxy.c +570 -0
  197. package/runtime/src/reflect.c +194 -0
  198. package/runtime/src/regexp.c +1141 -0
  199. package/runtime/src/regexp_anchor.h +34 -0
  200. package/runtime/src/regexp_message.h +32 -0
  201. package/runtime/src/shape.c +294 -0
  202. package/runtime/src/shape.h +46 -0
  203. package/runtime/src/streams.c +1046 -0
  204. package/runtime/src/streams.h +47 -0
  205. package/runtime/src/string.c +364 -0
  206. package/runtime/src/string_builtins.c +837 -0
  207. package/runtime/src/symbol.c +143 -0
  208. package/runtime/src/test_host.c +59 -0
  209. package/runtime/src/typedarray.c +1330 -0
  210. package/runtime/src/tznames.gen.h +712 -0
  211. package/runtime/src/uri.c +169 -0
  212. package/runtime/src/url.c +2116 -0
  213. package/runtime/src/weak.c +486 -0
  214. package/runtime/src/web.c +214 -0
  215. package/runtime/src/wrapper.c +59 -0
  216. package/runtime/src/writable.c +1486 -0
  217. package/runtime/third_party/ada-idna/LICENSE-MIT +18 -0
  218. package/runtime/third_party/ada-idna/README.md +27 -0
  219. package/runtime/third_party/ada-idna/convert.mjs +83 -0
  220. package/runtime/third_party/ada-idna/idna.c +416 -0
  221. package/runtime/third_party/ada-idna/idna.h +15 -0
  222. package/runtime/third_party/ada-idna/idna_tables.h +2657 -0
  223. package/runtime/third_party/bearssl/LICENSE.txt +21 -0
  224. package/runtime/third_party/bearssl/README.txt +136 -0
  225. package/runtime/third_party/bearssl/VERSION +1 -0
  226. package/runtime/third_party/bearssl/inc/bearssl.h +183 -0
  227. package/runtime/third_party/bearssl/inc/bearssl_aead.h +1059 -0
  228. package/runtime/third_party/bearssl/inc/bearssl_block.h +2618 -0
  229. package/runtime/third_party/bearssl/inc/bearssl_ec.h +967 -0
  230. package/runtime/third_party/bearssl/inc/bearssl_hash.h +1346 -0
  231. package/runtime/third_party/bearssl/inc/bearssl_hmac.h +241 -0
  232. package/runtime/third_party/bearssl/inc/bearssl_kdf.h +284 -0
  233. package/runtime/third_party/bearssl/inc/bearssl_pem.h +294 -0
  234. package/runtime/third_party/bearssl/inc/bearssl_prf.h +150 -0
  235. package/runtime/third_party/bearssl/inc/bearssl_rand.h +397 -0
  236. package/runtime/third_party/bearssl/inc/bearssl_rsa.h +1655 -0
  237. package/runtime/third_party/bearssl/inc/bearssl_ssl.h +4296 -0
  238. package/runtime/third_party/bearssl/inc/bearssl_x509.h +1474 -0
  239. package/runtime/third_party/bearssl/src/aead/ccm.c +346 -0
  240. package/runtime/third_party/bearssl/src/aead/eax.c +525 -0
  241. package/runtime/third_party/bearssl/src/aead/gcm.c +318 -0
  242. package/runtime/third_party/bearssl/src/codec/ccopy.c +44 -0
  243. package/runtime/third_party/bearssl/src/codec/dec16be.c +38 -0
  244. package/runtime/third_party/bearssl/src/codec/dec16le.c +38 -0
  245. package/runtime/third_party/bearssl/src/codec/dec32be.c +38 -0
  246. package/runtime/third_party/bearssl/src/codec/dec32le.c +38 -0
  247. package/runtime/third_party/bearssl/src/codec/dec64be.c +38 -0
  248. package/runtime/third_party/bearssl/src/codec/dec64le.c +38 -0
  249. package/runtime/third_party/bearssl/src/codec/enc16be.c +38 -0
  250. package/runtime/third_party/bearssl/src/codec/enc16le.c +38 -0
  251. package/runtime/third_party/bearssl/src/codec/enc32be.c +38 -0
  252. package/runtime/third_party/bearssl/src/codec/enc32le.c +38 -0
  253. package/runtime/third_party/bearssl/src/codec/enc64be.c +38 -0
  254. package/runtime/third_party/bearssl/src/codec/enc64le.c +38 -0
  255. package/runtime/third_party/bearssl/src/codec/pemdec.c +526 -0
  256. package/runtime/third_party/bearssl/src/codec/pemdec.t0 +314 -0
  257. package/runtime/third_party/bearssl/src/codec/pemenc.c +173 -0
  258. package/runtime/third_party/bearssl/src/config.h +247 -0
  259. package/runtime/third_party/bearssl/src/ec/ec_all_m15.c +121 -0
  260. package/runtime/third_party/bearssl/src/ec/ec_all_m31.c +171 -0
  261. package/runtime/third_party/bearssl/src/ec/ec_c25519_i15.c +398 -0
  262. package/runtime/third_party/bearssl/src/ec/ec_c25519_i31.c +390 -0
  263. package/runtime/third_party/bearssl/src/ec/ec_c25519_m15.c +1478 -0
  264. package/runtime/third_party/bearssl/src/ec/ec_c25519_m31.c +800 -0
  265. package/runtime/third_party/bearssl/src/ec/ec_c25519_m62.c +605 -0
  266. package/runtime/third_party/bearssl/src/ec/ec_c25519_m64.c +831 -0
  267. package/runtime/third_party/bearssl/src/ec/ec_curve25519.c +46 -0
  268. package/runtime/third_party/bearssl/src/ec/ec_default.c +36 -0
  269. package/runtime/third_party/bearssl/src/ec/ec_keygen.c +86 -0
  270. package/runtime/third_party/bearssl/src/ec/ec_p256_m15.c +2124 -0
  271. package/runtime/third_party/bearssl/src/ec/ec_p256_m31.c +1469 -0
  272. package/runtime/third_party/bearssl/src/ec/ec_p256_m62.c +1765 -0
  273. package/runtime/third_party/bearssl/src/ec/ec_p256_m64.c +1781 -0
  274. package/runtime/third_party/bearssl/src/ec/ec_prime_i15.c +824 -0
  275. package/runtime/third_party/bearssl/src/ec/ec_prime_i31.c +826 -0
  276. package/runtime/third_party/bearssl/src/ec/ec_pubkey.c +85 -0
  277. package/runtime/third_party/bearssl/src/ec/ec_secp256r1.c +51 -0
  278. package/runtime/third_party/bearssl/src/ec/ec_secp384r1.c +57 -0
  279. package/runtime/third_party/bearssl/src/ec/ec_secp521r1.c +64 -0
  280. package/runtime/third_party/bearssl/src/ec/ecdsa_atr.c +134 -0
  281. package/runtime/third_party/bearssl/src/ec/ecdsa_default_sign_asn1.c +36 -0
  282. package/runtime/third_party/bearssl/src/ec/ecdsa_default_sign_raw.c +36 -0
  283. package/runtime/third_party/bearssl/src/ec/ecdsa_default_vrfy_asn1.c +36 -0
  284. package/runtime/third_party/bearssl/src/ec/ecdsa_default_vrfy_raw.c +36 -0
  285. package/runtime/third_party/bearssl/src/ec/ecdsa_i15_bits.c +47 -0
  286. package/runtime/third_party/bearssl/src/ec/ecdsa_i15_sign_asn1.c +45 -0
  287. package/runtime/third_party/bearssl/src/ec/ecdsa_i15_sign_raw.c +174 -0
  288. package/runtime/third_party/bearssl/src/ec/ecdsa_i15_vrfy_asn1.c +48 -0
  289. package/runtime/third_party/bearssl/src/ec/ecdsa_i15_vrfy_raw.c +166 -0
  290. package/runtime/third_party/bearssl/src/ec/ecdsa_i31_bits.c +47 -0
  291. package/runtime/third_party/bearssl/src/ec/ecdsa_i31_sign_asn1.c +45 -0
  292. package/runtime/third_party/bearssl/src/ec/ecdsa_i31_sign_raw.c +173 -0
  293. package/runtime/third_party/bearssl/src/ec/ecdsa_i31_vrfy_asn1.c +48 -0
  294. package/runtime/third_party/bearssl/src/ec/ecdsa_i31_vrfy_raw.c +165 -0
  295. package/runtime/third_party/bearssl/src/ec/ecdsa_rta.c +121 -0
  296. package/runtime/third_party/bearssl/src/hash/dig_oid.c +84 -0
  297. package/runtime/third_party/bearssl/src/hash/dig_size.c +50 -0
  298. package/runtime/third_party/bearssl/src/hash/ghash_ctmul.c +345 -0
  299. package/runtime/third_party/bearssl/src/hash/ghash_ctmul32.c +251 -0
  300. package/runtime/third_party/bearssl/src/hash/ghash_ctmul64.c +154 -0
  301. package/runtime/third_party/bearssl/src/hash/ghash_pclmul.c +389 -0
  302. package/runtime/third_party/bearssl/src/hash/ghash_pwr8.c +411 -0
  303. package/runtime/third_party/bearssl/src/hash/md5.c +208 -0
  304. package/runtime/third_party/bearssl/src/hash/md5sha1.c +141 -0
  305. package/runtime/third_party/bearssl/src/hash/mgf1.c +56 -0
  306. package/runtime/third_party/bearssl/src/hash/multihash.c +166 -0
  307. package/runtime/third_party/bearssl/src/hash/sha1.c +191 -0
  308. package/runtime/third_party/bearssl/src/hash/sha2big.c +285 -0
  309. package/runtime/third_party/bearssl/src/hash/sha2small.c +341 -0
  310. package/runtime/third_party/bearssl/src/inner.h +2577 -0
  311. package/runtime/third_party/bearssl/src/int/i15_add.c +46 -0
  312. package/runtime/third_party/bearssl/src/int/i15_bitlen.c +44 -0
  313. package/runtime/third_party/bearssl/src/int/i15_decmod.c +124 -0
  314. package/runtime/third_party/bearssl/src/int/i15_decode.c +56 -0
  315. package/runtime/third_party/bearssl/src/int/i15_decred.c +100 -0
  316. package/runtime/third_party/bearssl/src/int/i15_encode.c +56 -0
  317. package/runtime/third_party/bearssl/src/int/i15_fmont.c +59 -0
  318. package/runtime/third_party/bearssl/src/int/i15_iszero.c +39 -0
  319. package/runtime/third_party/bearssl/src/int/i15_moddiv.c +465 -0
  320. package/runtime/third_party/bearssl/src/int/i15_modpow.c +50 -0
  321. package/runtime/third_party/bearssl/src/int/i15_modpow2.c +160 -0
  322. package/runtime/third_party/bearssl/src/int/i15_montmul.c +184 -0
  323. package/runtime/third_party/bearssl/src/int/i15_mulacc.c +61 -0
  324. package/runtime/third_party/bearssl/src/int/i15_muladd.c +173 -0
  325. package/runtime/third_party/bearssl/src/int/i15_ninv15.c +38 -0
  326. package/runtime/third_party/bearssl/src/int/i15_reduce.c +66 -0
  327. package/runtime/third_party/bearssl/src/int/i15_rshift.c +47 -0
  328. package/runtime/third_party/bearssl/src/int/i15_sub.c +46 -0
  329. package/runtime/third_party/bearssl/src/int/i15_tmont.c +36 -0
  330. package/runtime/third_party/bearssl/src/int/i31_add.c +46 -0
  331. package/runtime/third_party/bearssl/src/int/i31_bitlen.c +44 -0
  332. package/runtime/third_party/bearssl/src/int/i31_decmod.c +124 -0
  333. package/runtime/third_party/bearssl/src/int/i31_decode.c +57 -0
  334. package/runtime/third_party/bearssl/src/int/i31_decred.c +103 -0
  335. package/runtime/third_party/bearssl/src/int/i31_encode.c +79 -0
  336. package/runtime/third_party/bearssl/src/int/i31_fmont.c +60 -0
  337. package/runtime/third_party/bearssl/src/int/i31_iszero.c +39 -0
  338. package/runtime/third_party/bearssl/src/int/i31_moddiv.c +488 -0
  339. package/runtime/third_party/bearssl/src/int/i31_modpow.c +65 -0
  340. package/runtime/third_party/bearssl/src/int/i31_modpow2.c +160 -0
  341. package/runtime/third_party/bearssl/src/int/i31_montmul.c +127 -0
  342. package/runtime/third_party/bearssl/src/int/i31_mulacc.c +74 -0
  343. package/runtime/third_party/bearssl/src/int/i31_muladd.c +157 -0
  344. package/runtime/third_party/bearssl/src/int/i31_ninv31.c +39 -0
  345. package/runtime/third_party/bearssl/src/int/i31_reduce.c +66 -0
  346. package/runtime/third_party/bearssl/src/int/i31_rshift.c +47 -0
  347. package/runtime/third_party/bearssl/src/int/i31_sub.c +46 -0
  348. package/runtime/third_party/bearssl/src/int/i31_tmont.c +36 -0
  349. package/runtime/third_party/bearssl/src/int/i32_add.c +51 -0
  350. package/runtime/third_party/bearssl/src/int/i32_bitlen.c +44 -0
  351. package/runtime/third_party/bearssl/src/int/i32_decmod.c +77 -0
  352. package/runtime/third_party/bearssl/src/int/i32_decode.c +63 -0
  353. package/runtime/third_party/bearssl/src/int/i32_decred.c +107 -0
  354. package/runtime/third_party/bearssl/src/int/i32_div32.c +56 -0
  355. package/runtime/third_party/bearssl/src/int/i32_encode.c +72 -0
  356. package/runtime/third_party/bearssl/src/int/i32_fmont.c +60 -0
  357. package/runtime/third_party/bearssl/src/int/i32_iszero.c +39 -0
  358. package/runtime/third_party/bearssl/src/int/i32_modpow.c +65 -0
  359. package/runtime/third_party/bearssl/src/int/i32_montmul.c +69 -0
  360. package/runtime/third_party/bearssl/src/int/i32_mulacc.c +56 -0
  361. package/runtime/third_party/bearssl/src/int/i32_muladd.c +138 -0
  362. package/runtime/third_party/bearssl/src/int/i32_ninv32.c +39 -0
  363. package/runtime/third_party/bearssl/src/int/i32_reduce.c +66 -0
  364. package/runtime/third_party/bearssl/src/int/i32_sub.c +51 -0
  365. package/runtime/third_party/bearssl/src/int/i32_tmont.c +36 -0
  366. package/runtime/third_party/bearssl/src/int/i62_modpow2.c +493 -0
  367. package/runtime/third_party/bearssl/src/kdf/hkdf.c +107 -0
  368. package/runtime/third_party/bearssl/src/kdf/shake.c +590 -0
  369. package/runtime/third_party/bearssl/src/mac/hmac.c +122 -0
  370. package/runtime/third_party/bearssl/src/mac/hmac_ct.c +193 -0
  371. package/runtime/third_party/bearssl/src/rand/aesctr_drbg.c +206 -0
  372. package/runtime/third_party/bearssl/src/rand/hmac_drbg.c +157 -0
  373. package/runtime/third_party/bearssl/src/rand/sysrng.c +252 -0
  374. package/runtime/third_party/bearssl/src/rsa/rsa_default_keygen.c +38 -0
  375. package/runtime/third_party/bearssl/src/rsa/rsa_default_modulus.c +36 -0
  376. package/runtime/third_party/bearssl/src/rsa/rsa_default_oaep_decrypt.c +38 -0
  377. package/runtime/third_party/bearssl/src/rsa/rsa_default_oaep_encrypt.c +38 -0
  378. package/runtime/third_party/bearssl/src/rsa/rsa_default_pkcs1_sign.c +38 -0
  379. package/runtime/third_party/bearssl/src/rsa/rsa_default_pkcs1_vrfy.c +38 -0
  380. package/runtime/third_party/bearssl/src/rsa/rsa_default_priv.c +38 -0
  381. package/runtime/third_party/bearssl/src/rsa/rsa_default_privexp.c +36 -0
  382. package/runtime/third_party/bearssl/src/rsa/rsa_default_pss_sign.c +38 -0
  383. package/runtime/third_party/bearssl/src/rsa/rsa_default_pss_vrfy.c +38 -0
  384. package/runtime/third_party/bearssl/src/rsa/rsa_default_pub.c +38 -0
  385. package/runtime/third_party/bearssl/src/rsa/rsa_default_pubexp.c +36 -0
  386. package/runtime/third_party/bearssl/src/rsa/rsa_i15_keygen.c +583 -0
  387. package/runtime/third_party/bearssl/src/rsa/rsa_i15_modulus.c +99 -0
  388. package/runtime/third_party/bearssl/src/rsa/rsa_i15_oaep_decrypt.c +41 -0
  389. package/runtime/third_party/bearssl/src/rsa/rsa_i15_oaep_encrypt.c +44 -0
  390. package/runtime/third_party/bearssl/src/rsa/rsa_i15_pkcs1_sign.c +37 -0
  391. package/runtime/third_party/bearssl/src/rsa/rsa_i15_pkcs1_vrfy.c +43 -0
  392. package/runtime/third_party/bearssl/src/rsa/rsa_i15_priv.c +209 -0
  393. package/runtime/third_party/bearssl/src/rsa/rsa_i15_privexp.c +320 -0
  394. package/runtime/third_party/bearssl/src/rsa/rsa_i15_pss_sign.c +40 -0
  395. package/runtime/third_party/bearssl/src/rsa/rsa_i15_pss_vrfy.c +44 -0
  396. package/runtime/third_party/bearssl/src/rsa/rsa_i15_pub.c +113 -0
  397. package/runtime/third_party/bearssl/src/rsa/rsa_i15_pubexp.c +152 -0
  398. package/runtime/third_party/bearssl/src/rsa/rsa_i31_keygen.c +37 -0
  399. package/runtime/third_party/bearssl/src/rsa/rsa_i31_keygen_inner.c +608 -0
  400. package/runtime/third_party/bearssl/src/rsa/rsa_i31_modulus.c +99 -0
  401. package/runtime/third_party/bearssl/src/rsa/rsa_i31_oaep_decrypt.c +41 -0
  402. package/runtime/third_party/bearssl/src/rsa/rsa_i31_oaep_encrypt.c +44 -0
  403. package/runtime/third_party/bearssl/src/rsa/rsa_i31_pkcs1_sign.c +37 -0
  404. package/runtime/third_party/bearssl/src/rsa/rsa_i31_pkcs1_vrfy.c +43 -0
  405. package/runtime/third_party/bearssl/src/rsa/rsa_i31_priv.c +203 -0
  406. package/runtime/third_party/bearssl/src/rsa/rsa_i31_privexp.c +318 -0
  407. package/runtime/third_party/bearssl/src/rsa/rsa_i31_pss_sign.c +40 -0
  408. package/runtime/third_party/bearssl/src/rsa/rsa_i31_pss_vrfy.c +44 -0
  409. package/runtime/third_party/bearssl/src/rsa/rsa_i31_pub.c +106 -0
  410. package/runtime/third_party/bearssl/src/rsa/rsa_i31_pubexp.c +152 -0
  411. package/runtime/third_party/bearssl/src/rsa/rsa_i32_oaep_decrypt.c +41 -0
  412. package/runtime/third_party/bearssl/src/rsa/rsa_i32_oaep_encrypt.c +44 -0
  413. package/runtime/third_party/bearssl/src/rsa/rsa_i32_pkcs1_sign.c +37 -0
  414. package/runtime/third_party/bearssl/src/rsa/rsa_i32_pkcs1_vrfy.c +43 -0
  415. package/runtime/third_party/bearssl/src/rsa/rsa_i32_priv.c +160 -0
  416. package/runtime/third_party/bearssl/src/rsa/rsa_i32_pss_sign.c +40 -0
  417. package/runtime/third_party/bearssl/src/rsa/rsa_i32_pss_vrfy.c +44 -0
  418. package/runtime/third_party/bearssl/src/rsa/rsa_i32_pub.c +77 -0
  419. package/runtime/third_party/bearssl/src/rsa/rsa_i62_keygen.c +57 -0
  420. package/runtime/third_party/bearssl/src/rsa/rsa_i62_oaep_decrypt.c +61 -0
  421. package/runtime/third_party/bearssl/src/rsa/rsa_i62_oaep_encrypt.c +64 -0
  422. package/runtime/third_party/bearssl/src/rsa/rsa_i62_pkcs1_sign.c +57 -0
  423. package/runtime/third_party/bearssl/src/rsa/rsa_i62_pkcs1_vrfy.c +63 -0
  424. package/runtime/third_party/bearssl/src/rsa/rsa_i62_priv.c +223 -0
  425. package/runtime/third_party/bearssl/src/rsa/rsa_i62_pss_sign.c +60 -0
  426. package/runtime/third_party/bearssl/src/rsa/rsa_i62_pss_vrfy.c +64 -0
  427. package/runtime/third_party/bearssl/src/rsa/rsa_i62_pub.c +125 -0
  428. package/runtime/third_party/bearssl/src/rsa/rsa_oaep_pad.c +112 -0
  429. package/runtime/third_party/bearssl/src/rsa/rsa_oaep_unpad.c +145 -0
  430. package/runtime/third_party/bearssl/src/rsa/rsa_pkcs1_sig_pad.c +100 -0
  431. package/runtime/third_party/bearssl/src/rsa/rsa_pkcs1_sig_unpad.c +121 -0
  432. package/runtime/third_party/bearssl/src/rsa/rsa_pss_sig_pad.c +106 -0
  433. package/runtime/third_party/bearssl/src/rsa/rsa_pss_sig_unpad.c +121 -0
  434. package/runtime/third_party/bearssl/src/rsa/rsa_ssl_decrypt.c +52 -0
  435. package/runtime/third_party/bearssl/src/settings.c +306 -0
  436. package/runtime/third_party/bearssl/src/symcipher/aes_big_cbcdec.c +69 -0
  437. package/runtime/third_party/bearssl/src/symcipher/aes_big_cbcenc.c +67 -0
  438. package/runtime/third_party/bearssl/src/symcipher/aes_big_ctr.c +84 -0
  439. package/runtime/third_party/bearssl/src/symcipher/aes_big_ctrcbc.c +142 -0
  440. package/runtime/third_party/bearssl/src/symcipher/aes_big_dec.c +254 -0
  441. package/runtime/third_party/bearssl/src/symcipher/aes_big_enc.c +157 -0
  442. package/runtime/third_party/bearssl/src/symcipher/aes_common.c +112 -0
  443. package/runtime/third_party/bearssl/src/symcipher/aes_ct.c +328 -0
  444. package/runtime/third_party/bearssl/src/symcipher/aes_ct64.c +398 -0
  445. package/runtime/third_party/bearssl/src/symcipher/aes_ct64_cbcdec.c +104 -0
  446. package/runtime/third_party/bearssl/src/symcipher/aes_ct64_cbcenc.c +81 -0
  447. package/runtime/third_party/bearssl/src/symcipher/aes_ct64_ctr.c +114 -0
  448. package/runtime/third_party/bearssl/src/symcipher/aes_ct64_ctrcbc.c +433 -0
  449. package/runtime/third_party/bearssl/src/symcipher/aes_ct64_dec.c +159 -0
  450. package/runtime/third_party/bearssl/src/symcipher/aes_ct64_enc.c +115 -0
  451. package/runtime/third_party/bearssl/src/symcipher/aes_ct_cbcdec.c +111 -0
  452. package/runtime/third_party/bearssl/src/symcipher/aes_ct_cbcenc.c +91 -0
  453. package/runtime/third_party/bearssl/src/symcipher/aes_ct_ctr.c +116 -0
  454. package/runtime/third_party/bearssl/src/symcipher/aes_ct_ctrcbc.c +422 -0
  455. package/runtime/third_party/bearssl/src/symcipher/aes_ct_dec.c +170 -0
  456. package/runtime/third_party/bearssl/src/symcipher/aes_ct_enc.c +112 -0
  457. package/runtime/third_party/bearssl/src/symcipher/aes_pwr8.c +445 -0
  458. package/runtime/third_party/bearssl/src/symcipher/aes_pwr8_cbcdec.c +670 -0
  459. package/runtime/third_party/bearssl/src/symcipher/aes_pwr8_cbcenc.c +417 -0
  460. package/runtime/third_party/bearssl/src/symcipher/aes_pwr8_ctr.c +717 -0
  461. package/runtime/third_party/bearssl/src/symcipher/aes_pwr8_ctrcbc.c +946 -0
  462. package/runtime/third_party/bearssl/src/symcipher/aes_small_cbcdec.c +69 -0
  463. package/runtime/third_party/bearssl/src/symcipher/aes_small_cbcenc.c +67 -0
  464. package/runtime/third_party/bearssl/src/symcipher/aes_small_ctr.c +84 -0
  465. package/runtime/third_party/bearssl/src/symcipher/aes_small_ctrcbc.c +142 -0
  466. package/runtime/third_party/bearssl/src/symcipher/aes_small_dec.c +176 -0
  467. package/runtime/third_party/bearssl/src/symcipher/aes_small_enc.c +129 -0
  468. package/runtime/third_party/bearssl/src/symcipher/aes_x86ni.c +240 -0
  469. package/runtime/third_party/bearssl/src/symcipher/aes_x86ni_cbcdec.c +223 -0
  470. package/runtime/third_party/bearssl/src/symcipher/aes_x86ni_cbcenc.c +122 -0
  471. package/runtime/third_party/bearssl/src/symcipher/aes_x86ni_ctr.c +211 -0
  472. package/runtime/third_party/bearssl/src/symcipher/aes_x86ni_ctrcbc.c +596 -0
  473. package/runtime/third_party/bearssl/src/symcipher/chacha20_ct.c +106 -0
  474. package/runtime/third_party/bearssl/src/symcipher/chacha20_sse2.c +237 -0
  475. package/runtime/third_party/bearssl/src/symcipher/des_ct.c +411 -0
  476. package/runtime/third_party/bearssl/src/symcipher/des_ct_cbcdec.c +87 -0
  477. package/runtime/third_party/bearssl/src/symcipher/des_ct_cbcenc.c +69 -0
  478. package/runtime/third_party/bearssl/src/symcipher/des_support.c +166 -0
  479. package/runtime/third_party/bearssl/src/symcipher/des_tab.c +310 -0
  480. package/runtime/third_party/bearssl/src/symcipher/des_tab_cbcdec.c +85 -0
  481. package/runtime/third_party/bearssl/src/symcipher/des_tab_cbcenc.c +67 -0
  482. package/runtime/third_party/bearssl/src/symcipher/poly1305_ctmul.c +260 -0
  483. package/runtime/third_party/bearssl/src/symcipher/poly1305_ctmul32.c +297 -0
  484. package/runtime/third_party/bearssl/src/symcipher/poly1305_ctmulq.c +475 -0
  485. package/runtime/third_party/bearssl/src/symcipher/poly1305_i15.c +221 -0
  486. package/runtime/third_party/bearssl/src/x509/asn1.t0 +757 -0
  487. package/runtime/third_party/bearssl/src/x509/asn1enc.c +93 -0
  488. package/runtime/third_party/bearssl/src/x509/encode_ec_pk8der.c +110 -0
  489. package/runtime/third_party/bearssl/src/x509/encode_ec_rawder.c +161 -0
  490. package/runtime/third_party/bearssl/src/x509/encode_rsa_pk8der.c +97 -0
  491. package/runtime/third_party/bearssl/src/x509/encode_rsa_rawder.c +96 -0
  492. package/runtime/third_party/bearssl/src/x509/skey_decoder.c +653 -0
  493. package/runtime/third_party/bearssl/src/x509/skey_decoder.t0 +376 -0
  494. package/runtime/third_party/bearssl/src/x509/x509_decoder.c +776 -0
  495. package/runtime/third_party/bearssl/src/x509/x509_decoder.t0 +324 -0
  496. package/runtime/third_party/bearssl/src/x509/x509_knownkey.c +105 -0
  497. package/runtime/third_party/bearssl/src/x509/x509_minimal.c +1722 -0
  498. package/runtime/third_party/bearssl/src/x509/x509_minimal.t0 +1526 -0
  499. package/runtime/third_party/bearssl/src/x509/x509_minimal_full.c +59 -0
  500. package/runtime/third_party/quickjs-dtoa/LICENSE +22 -0
  501. package/runtime/third_party/quickjs-dtoa/README.md +23 -0
  502. package/runtime/third_party/quickjs-dtoa/dtoa.c +1640 -0
  503. package/runtime/third_party/quickjs-dtoa/dtoa.h +83 -0
  504. package/runtime/third_party/quickjs-dtoa/dtoa_compat.h +89 -0
  505. package/runtime/third_party/quickjs-regexp/LICENSE +22 -0
  506. package/runtime/third_party/quickjs-regexp/README.md +22 -0
  507. package/runtime/third_party/quickjs-regexp/cutils.c +641 -0
  508. package/runtime/third_party/quickjs-regexp/cutils.h +457 -0
  509. package/runtime/third_party/quickjs-regexp/libregexp-opcode.h +73 -0
  510. package/runtime/third_party/quickjs-regexp/libregexp.c +3448 -0
  511. package/runtime/third_party/quickjs-regexp/libregexp.h +65 -0
  512. package/runtime/third_party/quickjs-regexp/libunicode-table.h +5206 -0
  513. package/runtime/third_party/quickjs-regexp/libunicode.c +2124 -0
  514. package/runtime/third_party/quickjs-regexp/libunicode.h +196 -0
  515. package/runtime/third_party/v8-ieee754/LICENSE +61 -0
  516. package/runtime/third_party/v8-ieee754/README.md +22 -0
  517. package/runtime/third_party/v8-ieee754/convert.py +84 -0
  518. package/runtime/third_party/v8-ieee754/ieee754.c +3030 -0
  519. package/runtime/third_party/v8-ieee754/ieee754.h +27 -0
  520. package/runtime/tools/regexp_compile.c +90 -0
@@ -0,0 +1,2303 @@
1
+ /* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
2
+ *
3
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ * of this software and associated documentation files (the "Software"), to
5
+ * deal in the Software without restriction, including without limitation the
6
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7
+ * sell copies of the Software, and to permit persons to whom the Software is
8
+ * furnished to do so, subject to the following conditions:
9
+ *
10
+ * The above copyright notice and this permission notice shall be included in
11
+ * all copies or substantial portions of the Software.
12
+ *
13
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19
+ * IN THE SOFTWARE.
20
+ */
21
+
22
+ /* Caveat emptor: this file deviates from the libuv convention of returning
23
+ * negated errno codes. Most uv_fs_*() functions map directly to the system
24
+ * call of the same name. For more complex wrappers, it's easier to just
25
+ * return -1 with errno set. The dispatcher in uv__fs_work() takes care of
26
+ * getting the errno to the right place (req->result or as the return value.)
27
+ */
28
+
29
+ #include "uv.h"
30
+ #include "internal.h"
31
+
32
+ #include <errno.h>
33
+ #include <dlfcn.h>
34
+ #include <stdatomic.h>
35
+ #include <stdio.h>
36
+ #include <stdlib.h>
37
+ #include <string.h>
38
+ #include <limits.h> /* PATH_MAX */
39
+
40
+ #include <sys/types.h>
41
+ #include <sys/socket.h>
42
+ #include <sys/stat.h>
43
+ #include <sys/time.h>
44
+ #include <sys/uio.h>
45
+ #include <unistd.h>
46
+ #include <fcntl.h>
47
+ #include <poll.h>
48
+
49
+ #if defined(__linux__)
50
+ # include <sys/sendfile.h>
51
+ #endif
52
+
53
+ #if defined(__sun)
54
+ # include <sys/sendfile.h>
55
+ # include <sys/sysmacros.h>
56
+ #endif
57
+
58
+ #if defined(__APPLE__)
59
+ # include <sys/sysctl.h>
60
+ #elif defined(__linux__) && !defined(FICLONE)
61
+ # include <sys/ioctl.h>
62
+ # define FICLONE _IOW(0x94, 9, int)
63
+ #endif
64
+
65
+ #if defined(_AIX) && !defined(_AIX71)
66
+ # include <utime.h>
67
+ #endif
68
+
69
+ #if defined(__APPLE__) || \
70
+ defined(__DragonFly__) || \
71
+ defined(__FreeBSD__) || \
72
+ defined(__OpenBSD__) || \
73
+ defined(__NetBSD__)
74
+ # include <sys/param.h>
75
+ # include <sys/mount.h>
76
+ #elif defined(__sun) || \
77
+ defined(__MVS__) || \
78
+ defined(__NetBSD__) || \
79
+ defined(__HAIKU__) || \
80
+ defined(__QNX__)
81
+ # include <sys/statvfs.h>
82
+ #else
83
+ # include <sys/statfs.h>
84
+ #endif
85
+
86
+ #if defined(_AIX) && _XOPEN_SOURCE <= 600
87
+ extern char *mkdtemp(char *template); /* See issue #740 on AIX < 7 */
88
+ #endif
89
+
90
+ #define INIT(subtype) \
91
+ do { \
92
+ if (req == NULL) \
93
+ return UV_EINVAL; \
94
+ UV_REQ_INIT(req, UV_FS); \
95
+ req->fs_type = UV_FS_ ## subtype; \
96
+ req->result = 0; \
97
+ req->ptr = NULL; \
98
+ req->loop = loop; \
99
+ req->path = NULL; \
100
+ req->new_path = NULL; \
101
+ req->bufs = NULL; \
102
+ req->cb = cb; \
103
+ } \
104
+ while (0)
105
+
106
+ #define PATH \
107
+ do { \
108
+ assert(path != NULL); \
109
+ if (cb == NULL) { \
110
+ req->path = path; \
111
+ } else { \
112
+ req->path = uv__strdup(path); \
113
+ if (req->path == NULL) \
114
+ return UV_ENOMEM; \
115
+ } \
116
+ } \
117
+ while (0)
118
+
119
+ #define PATH2 \
120
+ do { \
121
+ if (cb == NULL) { \
122
+ req->path = path; \
123
+ req->new_path = new_path; \
124
+ } else { \
125
+ size_t path_len; \
126
+ size_t new_path_len; \
127
+ path_len = strlen(path) + 1; \
128
+ new_path_len = strlen(new_path) + 1; \
129
+ req->path = uv__malloc(path_len + new_path_len); \
130
+ if (req->path == NULL) \
131
+ return UV_ENOMEM; \
132
+ req->new_path = req->path + path_len; \
133
+ memcpy((void*) req->path, path, path_len); \
134
+ memcpy((void*) req->new_path, new_path, new_path_len); \
135
+ } \
136
+ } \
137
+ while (0)
138
+
139
+ #define POST \
140
+ do { \
141
+ if (cb != NULL) { \
142
+ uv__req_register(loop); \
143
+ uv__work_submit(loop, \
144
+ &req->work_req, \
145
+ UV__WORK_FAST_IO, \
146
+ uv__fs_work, \
147
+ uv__fs_done); \
148
+ return 0; \
149
+ } \
150
+ else { \
151
+ uv__fs_work(&req->work_req); \
152
+ return req->result; \
153
+ } \
154
+ } \
155
+ while (0)
156
+
157
+
158
+ static int uv__fs_close(int fd) {
159
+ int rc;
160
+
161
+ rc = uv__close_nocancel(fd);
162
+ if (rc == -1)
163
+ if (errno == EINTR || errno == EINPROGRESS)
164
+ rc = 0; /* The close is in progress, not an error. */
165
+
166
+ return rc;
167
+ }
168
+
169
+
170
+ static ssize_t uv__fs_fsync(uv_fs_t* req) {
171
+ #if defined(__APPLE__)
172
+ /* Apple's fdatasync and fsync explicitly do NOT flush the drive write cache
173
+ * to the drive platters. This is in contrast to Linux's fdatasync and fsync
174
+ * which do, according to recent man pages. F_FULLFSYNC is Apple's equivalent
175
+ * for flushing buffered data to permanent storage. If F_FULLFSYNC is not
176
+ * supported by the file system we fall back to F_BARRIERFSYNC or fsync().
177
+ * This is the same approach taken by sqlite, except sqlite does not issue
178
+ * an F_BARRIERFSYNC call.
179
+ */
180
+ int r;
181
+
182
+ r = fcntl(req->file, F_FULLFSYNC);
183
+ if (r != 0)
184
+ r = fcntl(req->file, 85 /* F_BARRIERFSYNC */); /* fsync + barrier */
185
+ if (r != 0)
186
+ r = fsync(req->file);
187
+ return r;
188
+ #else
189
+ return fsync(req->file);
190
+ #endif
191
+ }
192
+
193
+
194
+ static ssize_t uv__fs_fdatasync(uv_fs_t* req) {
195
+ #if defined(__linux__) || defined(__sun) || defined(__NetBSD__)
196
+ return fdatasync(req->file);
197
+ #elif defined(__APPLE__)
198
+ /* See the comment in uv__fs_fsync. */
199
+ return uv__fs_fsync(req);
200
+ #else
201
+ return fsync(req->file);
202
+ #endif
203
+ }
204
+
205
+
206
+ #if defined(__APPLE__) \
207
+ || defined(_AIX71) \
208
+ || defined(__DragonFly__) \
209
+ || defined(__FreeBSD__) \
210
+ || defined(__HAIKU__) \
211
+ || defined(__NetBSD__) \
212
+ || defined(__OpenBSD__) \
213
+ || defined(__linux__) \
214
+ || defined(__sun)
215
+ static struct timespec uv__fs_to_timespec(double time) {
216
+ struct timespec ts;
217
+
218
+ if (uv__isinf(time))
219
+ return (struct timespec){UTIME_NOW, UTIME_NOW};
220
+ if (uv__isnan(time))
221
+ return (struct timespec){UTIME_OMIT, UTIME_OMIT};
222
+
223
+ ts.tv_sec = time;
224
+ ts.tv_nsec = (time - ts.tv_sec) * 1e9;
225
+
226
+ /* TODO(bnoordhuis) Remove this. utimesat() has nanosecond resolution but we
227
+ * stick to microsecond resolution for the sake of consistency with other
228
+ * platforms. I'm the original author of this compatibility hack but I'm
229
+ * less convinced it's useful nowadays.
230
+ */
231
+ ts.tv_nsec -= ts.tv_nsec % 1000;
232
+
233
+ if (ts.tv_nsec < 0) {
234
+ ts.tv_nsec += 1e9;
235
+ ts.tv_sec -= 1;
236
+ }
237
+ return ts;
238
+ }
239
+ #endif
240
+
241
+
242
+ static ssize_t uv__fs_futime(uv_fs_t* req) {
243
+ #if defined(__APPLE__) \
244
+ || defined(_AIX71) \
245
+ || defined(__DragonFly__) \
246
+ || defined(__FreeBSD__) \
247
+ || defined(__HAIKU__) \
248
+ || defined(__NetBSD__) \
249
+ || defined(__OpenBSD__) \
250
+ || defined(__linux__) \
251
+ || defined(__sun)
252
+ struct timespec ts[2];
253
+ ts[0] = uv__fs_to_timespec(req->atime);
254
+ ts[1] = uv__fs_to_timespec(req->mtime);
255
+ return futimens(req->file, ts);
256
+ #elif defined(__MVS__)
257
+ attrib_t atr;
258
+ memset(&atr, 0, sizeof(atr));
259
+ atr.att_mtimechg = 1;
260
+ atr.att_atimechg = 1;
261
+ atr.att_mtime = req->mtime;
262
+ atr.att_atime = req->atime;
263
+ return __fchattr(req->file, &atr, sizeof(atr));
264
+ #else
265
+ errno = ENOSYS;
266
+ return -1;
267
+ #endif
268
+ }
269
+
270
+
271
+ static ssize_t uv__fs_mkdtemp(uv_fs_t* req) {
272
+ return mkdtemp((char*) req->path) ? 0 : -1;
273
+ }
274
+
275
+
276
+ static int (*uv__mkostemp)(char*, int);
277
+
278
+
279
+ static void uv__mkostemp_initonce(void) {
280
+ /* z/os doesn't have RTLD_DEFAULT but that's okay
281
+ * because it doesn't have mkostemp(O_CLOEXEC) either.
282
+ */
283
+ #ifdef RTLD_DEFAULT
284
+ uv__mkostemp = (int (*)(char*, int)) dlsym(RTLD_DEFAULT, "mkostemp");
285
+
286
+ /* We don't care about errors, but we do want to clean them up.
287
+ * If there has been no error, then dlerror() will just return
288
+ * NULL.
289
+ */
290
+ dlerror();
291
+ #endif /* RTLD_DEFAULT */
292
+ }
293
+
294
+
295
+ static int uv__fs_mkstemp(uv_fs_t* req) {
296
+ static uv_once_t once = UV_ONCE_INIT;
297
+ int r;
298
+ #ifdef O_CLOEXEC
299
+ static _Atomic int no_cloexec_support;
300
+ #endif
301
+ static const char pattern[] = "XXXXXX";
302
+ static const size_t pattern_size = sizeof(pattern) - 1;
303
+ char* path;
304
+ size_t path_length;
305
+
306
+ path = (char*) req->path;
307
+ path_length = strlen(path);
308
+
309
+ /* EINVAL can be returned for 2 reasons:
310
+ 1. The template's last 6 characters were not XXXXXX
311
+ 2. open() didn't support O_CLOEXEC
312
+ We want to avoid going to the fallback path in case
313
+ of 1, so it's manually checked before. */
314
+ if (path_length < pattern_size ||
315
+ strcmp(path + path_length - pattern_size, pattern)) {
316
+ errno = EINVAL;
317
+ r = -1;
318
+ goto clobber;
319
+ }
320
+
321
+ uv_once(&once, uv__mkostemp_initonce);
322
+
323
+ #ifdef O_CLOEXEC
324
+ if (atomic_load_explicit(&no_cloexec_support, memory_order_relaxed) == 0 &&
325
+ uv__mkostemp != NULL) {
326
+ r = uv__mkostemp(path, O_CLOEXEC);
327
+
328
+ if (r >= 0)
329
+ return r;
330
+
331
+ /* If mkostemp() returns EINVAL, it means the kernel doesn't
332
+ support O_CLOEXEC, so we just fallback to mkstemp() below. */
333
+ if (errno != EINVAL)
334
+ goto clobber;
335
+
336
+ /* We set the static variable so that next calls don't even
337
+ try to use mkostemp. */
338
+ atomic_store_explicit(&no_cloexec_support, 1, memory_order_relaxed);
339
+ }
340
+ #endif /* O_CLOEXEC */
341
+
342
+ if (req->cb != NULL)
343
+ uv_rwlock_rdlock(&req->loop->cloexec_lock);
344
+
345
+ r = mkstemp(path);
346
+
347
+ /* In case of failure `uv__cloexec` will leave error in `errno`,
348
+ * so it is enough to just set `r` to `-1`.
349
+ */
350
+ if (r >= 0 && uv__cloexec(r, 1) != 0) {
351
+ r = uv__close(r);
352
+ if (r != 0)
353
+ abort();
354
+ r = -1;
355
+ }
356
+
357
+ if (req->cb != NULL)
358
+ uv_rwlock_rdunlock(&req->loop->cloexec_lock);
359
+
360
+ clobber:
361
+ if (r < 0)
362
+ path[0] = '\0';
363
+ return r;
364
+ }
365
+
366
+
367
+ static ssize_t uv__fs_open(uv_fs_t* req) {
368
+ #ifdef O_CLOEXEC
369
+ return open(req->path, req->flags | O_CLOEXEC, req->mode);
370
+ #else /* O_CLOEXEC */
371
+ int r;
372
+
373
+ if (req->cb != NULL)
374
+ uv_rwlock_rdlock(&req->loop->cloexec_lock);
375
+
376
+ r = open(req->path, req->flags, req->mode);
377
+
378
+ /* In case of failure `uv__cloexec` will leave error in `errno`,
379
+ * so it is enough to just set `r` to `-1`.
380
+ */
381
+ if (r >= 0 && uv__cloexec(r, 1) != 0) {
382
+ r = uv__close(r);
383
+ if (r != 0)
384
+ abort();
385
+ r = -1;
386
+ }
387
+
388
+ if (req->cb != NULL)
389
+ uv_rwlock_rdunlock(&req->loop->cloexec_lock);
390
+
391
+ return r;
392
+ #endif /* O_CLOEXEC */
393
+ }
394
+
395
+
396
+ static ssize_t uv__preadv_or_pwritev_emul(int fd,
397
+ const struct iovec* bufs,
398
+ size_t nbufs,
399
+ off_t off,
400
+ int is_pread) {
401
+ ssize_t total;
402
+ ssize_t r;
403
+ size_t i;
404
+ size_t n;
405
+ void* p;
406
+
407
+ total = 0;
408
+ for (i = 0; i < (size_t) nbufs; i++) {
409
+ p = bufs[i].iov_base;
410
+ n = bufs[i].iov_len;
411
+
412
+ do
413
+ if (is_pread)
414
+ r = pread(fd, p, n, off);
415
+ else
416
+ r = pwrite(fd, p, n, off);
417
+ while (r == -1 && errno == EINTR);
418
+
419
+ if (r == -1) {
420
+ if (total > 0)
421
+ return total;
422
+ return -1;
423
+ }
424
+
425
+ off += r;
426
+ total += r;
427
+
428
+ if ((size_t) r < n)
429
+ return total;
430
+ }
431
+
432
+ return total;
433
+ }
434
+
435
+
436
+ #ifdef __linux__
437
+ typedef int uv__iovcnt;
438
+ #else
439
+ typedef size_t uv__iovcnt;
440
+ #endif
441
+
442
+
443
+ static ssize_t uv__preadv_emul(int fd,
444
+ const struct iovec* bufs,
445
+ uv__iovcnt nbufs,
446
+ off_t off) {
447
+ return uv__preadv_or_pwritev_emul(fd, bufs, nbufs, off, /*is_pread*/1);
448
+ }
449
+
450
+
451
+ static ssize_t uv__pwritev_emul(int fd,
452
+ const struct iovec* bufs,
453
+ uv__iovcnt nbufs,
454
+ off_t off) {
455
+ return uv__preadv_or_pwritev_emul(fd, bufs, nbufs, off, /*is_pread*/0);
456
+ }
457
+
458
+
459
+ /* The function pointer cache is an uintptr_t because _Atomic void*
460
+ * doesn't work on macos/ios/etc...
461
+ */
462
+ static ssize_t uv__preadv_or_pwritev(int fd,
463
+ const struct iovec* bufs,
464
+ size_t nbufs,
465
+ off_t off,
466
+ _Atomic uintptr_t* cache,
467
+ int is_pread) {
468
+ ssize_t (*f)(int, const struct iovec*, uv__iovcnt, off_t);
469
+ void* p;
470
+
471
+ p = (void*) atomic_load_explicit(cache, memory_order_relaxed);
472
+ if (p == NULL) {
473
+ #ifdef RTLD_DEFAULT
474
+ /* Try _LARGEFILE_SOURCE version of preadv/pwritev first,
475
+ * then fall back to the plain version, for libcs like musl.
476
+ */
477
+ p = dlsym(RTLD_DEFAULT, is_pread ? "preadv64" : "pwritev64");
478
+ if (p == NULL)
479
+ p = dlsym(RTLD_DEFAULT, is_pread ? "preadv" : "pwritev");
480
+ dlerror(); /* Clear errors. */
481
+ #endif /* RTLD_DEFAULT */
482
+ if (p == NULL)
483
+ p = is_pread ? uv__preadv_emul : uv__pwritev_emul;
484
+ atomic_store_explicit(cache, (uintptr_t) p, memory_order_relaxed);
485
+ }
486
+
487
+ f = p;
488
+ return f(fd, bufs, nbufs, off);
489
+ }
490
+
491
+
492
+ static ssize_t uv__preadv(int fd,
493
+ const struct iovec* bufs,
494
+ size_t nbufs,
495
+ off_t off) {
496
+ static _Atomic uintptr_t cache;
497
+ return uv__preadv_or_pwritev(fd, bufs, nbufs, off, &cache, /*is_pread*/1);
498
+ }
499
+
500
+
501
+ static ssize_t uv__pwritev(int fd,
502
+ const struct iovec* bufs,
503
+ size_t nbufs,
504
+ off_t off) {
505
+ static _Atomic uintptr_t cache;
506
+ return uv__preadv_or_pwritev(fd, bufs, nbufs, off, &cache, /*is_pread*/0);
507
+ }
508
+
509
+
510
+ static ssize_t uv__fs_read(uv_fs_t* req) {
511
+ const struct iovec* bufs;
512
+ unsigned int iovmax;
513
+ size_t nbufs;
514
+ ssize_t r;
515
+ off_t off;
516
+ int fd;
517
+
518
+ fd = req->file;
519
+ off = req->off;
520
+ bufs = (const struct iovec*) req->bufs;
521
+ nbufs = req->nbufs;
522
+
523
+ iovmax = uv__getiovmax();
524
+ if (nbufs > iovmax)
525
+ nbufs = iovmax;
526
+
527
+ r = 0;
528
+ if (off < 0) {
529
+ if (nbufs == 1)
530
+ r = read(fd, bufs->iov_base, bufs->iov_len);
531
+ else if (nbufs > 1)
532
+ r = readv(fd, bufs, nbufs);
533
+ } else {
534
+ if (nbufs == 1)
535
+ r = pread(fd, bufs->iov_base, bufs->iov_len, off);
536
+ else if (nbufs > 1)
537
+ r = uv__preadv(fd, bufs, nbufs, off);
538
+ }
539
+
540
+ #ifdef __PASE__
541
+ /* PASE returns EOPNOTSUPP when reading a directory, convert to EISDIR */
542
+ if (r == -1 && errno == EOPNOTSUPP) {
543
+ struct stat buf;
544
+ ssize_t rc;
545
+ rc = uv__fstat(fd, &buf);
546
+ if (rc == 0 && S_ISDIR(buf.st_mode)) {
547
+ errno = EISDIR;
548
+ }
549
+ }
550
+ #endif
551
+
552
+ /* We don't own the buffer list in the synchronous case. */
553
+ if (req->cb != NULL)
554
+ if (req->bufs != req->bufsml)
555
+ uv__free(req->bufs);
556
+
557
+ req->bufs = NULL;
558
+ req->nbufs = 0;
559
+
560
+ return r;
561
+ }
562
+
563
+
564
+ static int uv__fs_scandir_filter(const uv__dirent_t* dent) {
565
+ return strcmp(dent->d_name, ".") != 0 && strcmp(dent->d_name, "..") != 0;
566
+ }
567
+
568
+
569
+ static int uv__fs_scandir_sort(const uv__dirent_t** a, const uv__dirent_t** b) {
570
+ return strcmp((*a)->d_name, (*b)->d_name);
571
+ }
572
+
573
+
574
+ static ssize_t uv__fs_scandir(uv_fs_t* req) {
575
+ uv__dirent_t** dents;
576
+ int n;
577
+
578
+ dents = NULL;
579
+ n = scandir(req->path, &dents, uv__fs_scandir_filter, uv__fs_scandir_sort);
580
+
581
+ /* NOTE: We will use nbufs as an index field */
582
+ req->nbufs = 0;
583
+
584
+ if (n == 0) {
585
+ /* OS X still needs to deallocate some memory.
586
+ * Memory was allocated using the system allocator, so use free() here.
587
+ */
588
+ free(dents);
589
+ dents = NULL;
590
+ } else if (n == -1) {
591
+ return n;
592
+ }
593
+
594
+ req->ptr = dents;
595
+
596
+ return n;
597
+ }
598
+
599
+ static int uv__fs_opendir(uv_fs_t* req) {
600
+ uv_dir_t* dir;
601
+
602
+ dir = uv__malloc(sizeof(*dir));
603
+ if (dir == NULL)
604
+ goto error;
605
+
606
+ dir->dir = opendir(req->path);
607
+ if (dir->dir == NULL)
608
+ goto error;
609
+
610
+ req->ptr = dir;
611
+ return 0;
612
+
613
+ error:
614
+ uv__free(dir);
615
+ req->ptr = NULL;
616
+ return -1;
617
+ }
618
+
619
+ static int uv__fs_readdir(uv_fs_t* req) {
620
+ uv_dir_t* dir;
621
+ uv_dirent_t* dirent;
622
+ struct dirent* res;
623
+ unsigned int dirent_idx;
624
+ unsigned int i;
625
+
626
+ dir = req->ptr;
627
+ dirent_idx = 0;
628
+
629
+ while (dirent_idx < dir->nentries) {
630
+ /* readdir() returns NULL on end of directory, as well as on error. errno
631
+ is used to differentiate between the two conditions. */
632
+ errno = 0;
633
+ res = readdir(dir->dir);
634
+
635
+ if (res == NULL) {
636
+ if (errno != 0)
637
+ goto error;
638
+ break;
639
+ }
640
+
641
+ if (strcmp(res->d_name, ".") == 0 || strcmp(res->d_name, "..") == 0)
642
+ continue;
643
+
644
+ dirent = &dir->dirents[dirent_idx];
645
+ dirent->name = uv__strdup(res->d_name);
646
+
647
+ if (dirent->name == NULL)
648
+ goto error;
649
+
650
+ dirent->type = uv__fs_get_dirent_type(res);
651
+ ++dirent_idx;
652
+ }
653
+
654
+ return dirent_idx;
655
+
656
+ error:
657
+ for (i = 0; i < dirent_idx; ++i) {
658
+ uv__free((char*) dir->dirents[i].name);
659
+ dir->dirents[i].name = NULL;
660
+ }
661
+
662
+ return -1;
663
+ }
664
+
665
+ static int uv__fs_closedir(uv_fs_t* req) {
666
+ uv_dir_t* dir;
667
+
668
+ dir = req->ptr;
669
+
670
+ if (dir->dir != NULL) {
671
+ closedir(dir->dir);
672
+ dir->dir = NULL;
673
+ }
674
+
675
+ uv__free(req->ptr);
676
+ req->ptr = NULL;
677
+ return 0;
678
+ }
679
+
680
+ static int uv__fs_statfs(uv_fs_t* req) {
681
+ uv_statfs_t* stat_fs;
682
+ #if defined(__sun) || \
683
+ defined(__MVS__) || \
684
+ defined(__NetBSD__) || \
685
+ defined(__HAIKU__) || \
686
+ defined(__QNX__)
687
+ struct statvfs buf;
688
+
689
+ if (0 != statvfs(req->path, &buf))
690
+ #else
691
+ struct statfs buf;
692
+
693
+ if (0 != statfs(req->path, &buf))
694
+ #endif /* defined(__sun) */
695
+ return -1;
696
+
697
+ stat_fs = uv__malloc(sizeof(*stat_fs));
698
+ if (stat_fs == NULL) {
699
+ errno = ENOMEM;
700
+ return -1;
701
+ }
702
+
703
+ #if defined(__sun) || \
704
+ defined(__MVS__) || \
705
+ defined(__OpenBSD__) || \
706
+ defined(__NetBSD__) || \
707
+ defined(__HAIKU__) || \
708
+ defined(__QNX__)
709
+ stat_fs->f_type = 0; /* f_type is not supported. */
710
+ #else
711
+ stat_fs->f_type = buf.f_type;
712
+ #endif
713
+ stat_fs->f_bsize = buf.f_bsize;
714
+ stat_fs->f_blocks = buf.f_blocks;
715
+ stat_fs->f_bfree = buf.f_bfree;
716
+ stat_fs->f_bavail = buf.f_bavail;
717
+ stat_fs->f_files = buf.f_files;
718
+ stat_fs->f_ffree = buf.f_ffree;
719
+ req->ptr = stat_fs;
720
+ return 0;
721
+ }
722
+
723
+ static ssize_t uv__fs_pathmax_size(const char* path) {
724
+ ssize_t pathmax;
725
+
726
+ pathmax = pathconf(path, _PC_PATH_MAX);
727
+
728
+ if (pathmax == -1)
729
+ pathmax = UV__PATH_MAX;
730
+
731
+ return pathmax;
732
+ }
733
+
734
+ static ssize_t uv__fs_readlink(uv_fs_t* req) {
735
+ ssize_t maxlen;
736
+ ssize_t len;
737
+ char* buf;
738
+
739
+ #if defined(_POSIX_PATH_MAX) || defined(PATH_MAX)
740
+ maxlen = uv__fs_pathmax_size(req->path);
741
+ #else
742
+ /* We may not have a real PATH_MAX. Read size of link. */
743
+ struct stat st;
744
+ int ret;
745
+ ret = uv__lstat(req->path, &st);
746
+ if (ret != 0)
747
+ return -1;
748
+ if (!S_ISLNK(st.st_mode)) {
749
+ errno = EINVAL;
750
+ return -1;
751
+ }
752
+
753
+ maxlen = st.st_size;
754
+
755
+ /* According to readlink(2) lstat can report st_size == 0
756
+ for some symlinks, such as those in /proc or /sys. */
757
+ if (maxlen == 0)
758
+ maxlen = uv__fs_pathmax_size(req->path);
759
+ #endif
760
+
761
+ buf = uv__malloc(maxlen);
762
+
763
+ if (buf == NULL) {
764
+ errno = ENOMEM;
765
+ return -1;
766
+ }
767
+
768
+ #if defined(__MVS__)
769
+ len = os390_readlink(req->path, buf, maxlen);
770
+ #else
771
+ len = readlink(req->path, buf, maxlen);
772
+ #endif
773
+
774
+ if (len == -1) {
775
+ uv__free(buf);
776
+ return -1;
777
+ }
778
+
779
+ /* Uncommon case: resize to make room for the trailing nul byte. */
780
+ if (len == maxlen) {
781
+ buf = uv__reallocf(buf, len + 1);
782
+
783
+ if (buf == NULL)
784
+ return -1;
785
+ }
786
+
787
+ buf[len] = '\0';
788
+ req->ptr = buf;
789
+
790
+ return 0;
791
+ }
792
+
793
+ static ssize_t uv__fs_realpath(uv_fs_t* req) {
794
+ char* buf;
795
+ char* tmp;
796
+
797
+ #if defined(_POSIX_VERSION) && _POSIX_VERSION >= 200809L
798
+ tmp = realpath(req->path, NULL);
799
+ if (tmp == NULL)
800
+ return -1;
801
+ buf = uv__strdup(tmp);
802
+ free(tmp); /* _Not_ uv__free. */
803
+ if (buf == NULL) {
804
+ errno = ENOMEM;
805
+ return -1;
806
+ }
807
+ #else
808
+ ssize_t len;
809
+
810
+ (void)tmp;
811
+
812
+ len = uv__fs_pathmax_size(req->path);
813
+ buf = uv__malloc(len + 1);
814
+
815
+ if (buf == NULL) {
816
+ errno = ENOMEM;
817
+ return -1;
818
+ }
819
+
820
+ if (realpath(req->path, buf) == NULL) {
821
+ uv__free(buf);
822
+ return -1;
823
+ }
824
+ #endif
825
+
826
+ req->ptr = buf;
827
+
828
+ return 0;
829
+ }
830
+
831
+ static ssize_t uv__fs_sendfile_emul(uv_fs_t* req) {
832
+ struct pollfd pfd;
833
+ int use_pread;
834
+ off_t offset;
835
+ ssize_t nsent;
836
+ ssize_t nread;
837
+ ssize_t nwritten;
838
+ size_t buflen;
839
+ size_t len;
840
+ ssize_t n;
841
+ int in_fd;
842
+ int out_fd;
843
+ char buf[8192];
844
+
845
+ len = req->bufsml[0].len;
846
+ in_fd = req->flags;
847
+ out_fd = req->file;
848
+ offset = req->off;
849
+ use_pread = 1;
850
+
851
+ /* Here are the rules regarding errors:
852
+ *
853
+ * 1. Read errors are reported only if nsent==0, otherwise we return nsent.
854
+ * The user needs to know that some data has already been sent, to stop
855
+ * them from sending it twice.
856
+ *
857
+ * 2. Write errors are always reported. Write errors are bad because they
858
+ * mean data loss: we've read data but now we can't write it out.
859
+ *
860
+ * We try to use pread() and fall back to regular read() if the source fd
861
+ * doesn't support positional reads, for example when it's a pipe fd.
862
+ *
863
+ * If we get EAGAIN when writing to the target fd, we poll() on it until
864
+ * it becomes writable again.
865
+ *
866
+ * FIXME: If we get a write error when use_pread==1, it should be safe to
867
+ * return the number of sent bytes instead of an error because pread()
868
+ * is, in theory, idempotent. However, special files in /dev or /proc
869
+ * may support pread() but not necessarily return the same data on
870
+ * successive reads.
871
+ *
872
+ * FIXME: There is no way now to signal that we managed to send *some* data
873
+ * before a write error.
874
+ */
875
+ for (nsent = 0; (size_t) nsent < len; ) {
876
+ buflen = len - nsent;
877
+
878
+ if (buflen > sizeof(buf))
879
+ buflen = sizeof(buf);
880
+
881
+ do
882
+ if (use_pread)
883
+ nread = pread(in_fd, buf, buflen, offset);
884
+ else
885
+ nread = read(in_fd, buf, buflen);
886
+ while (nread == -1 && errno == EINTR);
887
+
888
+ if (nread == 0)
889
+ goto out;
890
+
891
+ if (nread == -1) {
892
+ if (use_pread && nsent == 0 && (errno == EIO || errno == ESPIPE)) {
893
+ use_pread = 0;
894
+ continue;
895
+ }
896
+
897
+ if (nsent == 0)
898
+ nsent = -1;
899
+
900
+ goto out;
901
+ }
902
+
903
+ for (nwritten = 0; nwritten < nread; ) {
904
+ do
905
+ n = write(out_fd, buf + nwritten, nread - nwritten);
906
+ while (n == -1 && errno == EINTR);
907
+
908
+ if (n != -1) {
909
+ nwritten += n;
910
+ continue;
911
+ }
912
+
913
+ if (errno != EAGAIN && errno != EWOULDBLOCK) {
914
+ nsent = -1;
915
+ goto out;
916
+ }
917
+
918
+ pfd.fd = out_fd;
919
+ pfd.events = POLLOUT;
920
+ pfd.revents = 0;
921
+
922
+ do
923
+ n = poll(&pfd, 1, -1);
924
+ while (n == -1 && errno == EINTR);
925
+
926
+ if (n == -1 || (pfd.revents & ~POLLOUT) != 0) {
927
+ errno = EIO;
928
+ nsent = -1;
929
+ goto out;
930
+ }
931
+ }
932
+
933
+ offset += nread;
934
+ nsent += nread;
935
+ }
936
+
937
+ out:
938
+ if (nsent != -1)
939
+ req->off = offset;
940
+
941
+ return nsent;
942
+ }
943
+
944
+
945
+ #ifdef __linux__
946
+ /* Pre-4.20 kernels have a bug where CephFS uses the RADOS copy-from command
947
+ * in copy_file_range() when it shouldn't. There is no workaround except to
948
+ * fall back to a regular copy.
949
+ */
950
+ static int uv__is_buggy_cephfs(int fd) {
951
+ struct statfs s;
952
+
953
+ if (-1 == fstatfs(fd, &s))
954
+ return 0;
955
+
956
+ if (s.f_type != /* CephFS */ 0xC36400)
957
+ return 0;
958
+
959
+ return uv__kernel_version() < /* 4.20.0 */ 0x041400;
960
+ }
961
+
962
+
963
+ static int uv__is_cifs_or_smb(int fd) {
964
+ struct statfs s;
965
+
966
+ if (-1 == fstatfs(fd, &s))
967
+ return 0;
968
+
969
+ switch ((unsigned) s.f_type) {
970
+ case 0x0000517Bu: /* SMB */
971
+ case 0xFE534D42u: /* SMB2 */
972
+ case 0xFF534D42u: /* CIFS */
973
+ return 1;
974
+ }
975
+
976
+ return 0;
977
+ }
978
+
979
+
980
+ static ssize_t uv__fs_try_copy_file_range(int in_fd, off_t* off,
981
+ int out_fd, size_t len) {
982
+ static _Atomic int no_copy_file_range_support;
983
+ ssize_t r;
984
+
985
+ if (atomic_load_explicit(&no_copy_file_range_support, memory_order_relaxed)) {
986
+ errno = ENOSYS;
987
+ return -1;
988
+ }
989
+
990
+ r = uv__fs_copy_file_range(in_fd, off, out_fd, NULL, len, 0);
991
+
992
+ if (r != -1)
993
+ return r;
994
+
995
+ switch (errno) {
996
+ case EACCES:
997
+ /* Pre-4.20 kernels have a bug where CephFS uses the RADOS
998
+ * copy-from command when it shouldn't.
999
+ */
1000
+ if (uv__is_buggy_cephfs(in_fd))
1001
+ errno = ENOSYS; /* Use fallback. */
1002
+ break;
1003
+ case ENOSYS:
1004
+ atomic_store_explicit(&no_copy_file_range_support, 1, memory_order_relaxed);
1005
+ break;
1006
+ case EPERM:
1007
+ /* It's been reported that CIFS spuriously fails.
1008
+ * Consider it a transient error.
1009
+ */
1010
+ if (uv__is_cifs_or_smb(out_fd))
1011
+ errno = ENOSYS; /* Use fallback. */
1012
+ break;
1013
+ case ENOTSUP:
1014
+ case EXDEV:
1015
+ /* ENOTSUP - it could work on another file system type.
1016
+ * EXDEV - it will not work when in_fd and out_fd are not on the same
1017
+ * mounted filesystem (pre Linux 5.3)
1018
+ */
1019
+ errno = ENOSYS; /* Use fallback. */
1020
+ break;
1021
+ }
1022
+
1023
+ return -1;
1024
+ }
1025
+
1026
+ #endif /* __linux__ */
1027
+
1028
+
1029
+ static ssize_t uv__fs_sendfile(uv_fs_t* req) {
1030
+ int in_fd;
1031
+ int out_fd;
1032
+
1033
+ in_fd = req->flags;
1034
+ out_fd = req->file;
1035
+
1036
+ #if defined(__linux__) || defined(__sun)
1037
+ {
1038
+ off_t off;
1039
+ ssize_t r;
1040
+ size_t len;
1041
+ int try_sendfile;
1042
+
1043
+ off = req->off;
1044
+ len = req->bufsml[0].len;
1045
+ try_sendfile = 1;
1046
+
1047
+ #ifdef __linux__
1048
+ r = uv__fs_try_copy_file_range(in_fd, &off, out_fd, len);
1049
+ try_sendfile = (r == -1 && errno == ENOSYS);
1050
+ #endif
1051
+
1052
+ if (try_sendfile)
1053
+ r = sendfile(out_fd, in_fd, &off, len);
1054
+
1055
+ /* sendfile() on SunOS returns EINVAL if the target fd is not a socket but
1056
+ * it still writes out data. Fortunately, we can detect it by checking if
1057
+ * the offset has been updated.
1058
+ */
1059
+ if (r != -1 || off > req->off) {
1060
+ r = off - req->off;
1061
+ req->off = off;
1062
+ return r;
1063
+ }
1064
+
1065
+ if (errno == EINVAL ||
1066
+ errno == EIO ||
1067
+ errno == ENOTSOCK ||
1068
+ errno == EXDEV) {
1069
+ errno = 0;
1070
+ return uv__fs_sendfile_emul(req);
1071
+ }
1072
+
1073
+ return -1;
1074
+ }
1075
+ /* sendfile() on iOS(arm64) will throw SIGSYS signal cause crash. */
1076
+ #elif (defined(__APPLE__) && !TARGET_OS_IPHONE) \
1077
+ || defined(__DragonFly__) \
1078
+ || defined(__FreeBSD__)
1079
+ {
1080
+ off_t len;
1081
+ ssize_t r;
1082
+
1083
+ /* sendfile() on FreeBSD and Darwin returns EAGAIN if the target fd is in
1084
+ * non-blocking mode and not all data could be written. If a non-zero
1085
+ * number of bytes have been sent, we don't consider it an error.
1086
+ */
1087
+
1088
+ #if defined(__FreeBSD__) || defined(__DragonFly__)
1089
+ #if defined(__FreeBSD__)
1090
+ off_t off;
1091
+
1092
+ off = req->off;
1093
+ r = uv__fs_copy_file_range(in_fd, &off, out_fd, NULL, req->bufsml[0].len, 0);
1094
+ if (r >= 0) {
1095
+ r = off - req->off;
1096
+ req->off = off;
1097
+ return r;
1098
+ }
1099
+ #endif
1100
+ len = 0;
1101
+ r = sendfile(in_fd, out_fd, req->off, req->bufsml[0].len, NULL, &len, 0);
1102
+ #else
1103
+ /* The darwin sendfile takes len as an input for the length to send,
1104
+ * so make sure to initialize it with the caller's value. */
1105
+ len = req->bufsml[0].len;
1106
+ r = sendfile(in_fd, out_fd, req->off, &len, NULL, 0);
1107
+ #endif
1108
+
1109
+ /*
1110
+ * The man page for sendfile(2) on DragonFly states that `len` contains
1111
+ * a meaningful value ONLY in case of EAGAIN and EINTR.
1112
+ * Nothing is said about it's value in case of other errors, so better
1113
+ * not depend on the potential wrong assumption that is was not modified
1114
+ * by the syscall.
1115
+ */
1116
+ if (r == 0 || ((errno == EAGAIN || errno == EINTR) && len != 0)) {
1117
+ req->off += len;
1118
+ return (ssize_t) len;
1119
+ }
1120
+
1121
+ if (errno == EINVAL ||
1122
+ errno == EIO ||
1123
+ errno == ENOTSOCK ||
1124
+ errno == EXDEV) {
1125
+ errno = 0;
1126
+ return uv__fs_sendfile_emul(req);
1127
+ }
1128
+
1129
+ return -1;
1130
+ }
1131
+ #else
1132
+ /* Squelch compiler warnings. */
1133
+ (void) &in_fd;
1134
+ (void) &out_fd;
1135
+
1136
+ return uv__fs_sendfile_emul(req);
1137
+ #endif
1138
+ }
1139
+
1140
+
1141
+ static ssize_t uv__fs_utime(uv_fs_t* req) {
1142
+ #if defined(__APPLE__) \
1143
+ || defined(_AIX71) \
1144
+ || defined(__DragonFly__) \
1145
+ || defined(__FreeBSD__) \
1146
+ || defined(__HAIKU__) \
1147
+ || defined(__NetBSD__) \
1148
+ || defined(__OpenBSD__) \
1149
+ || defined(__linux__) \
1150
+ || defined(__sun)
1151
+ struct timespec ts[2];
1152
+ ts[0] = uv__fs_to_timespec(req->atime);
1153
+ ts[1] = uv__fs_to_timespec(req->mtime);
1154
+ return utimensat(AT_FDCWD, req->path, ts, 0);
1155
+ #elif defined(_AIX) && !defined(_AIX71)
1156
+ struct utimbuf buf;
1157
+ buf.actime = req->atime;
1158
+ buf.modtime = req->mtime;
1159
+ return utime(req->path, &buf);
1160
+ #elif defined(__MVS__)
1161
+ attrib_t atr;
1162
+ memset(&atr, 0, sizeof(atr));
1163
+ atr.att_mtimechg = 1;
1164
+ atr.att_atimechg = 1;
1165
+ atr.att_mtime = req->mtime;
1166
+ atr.att_atime = req->atime;
1167
+ return __lchattr((char*) req->path, &atr, sizeof(atr));
1168
+ #else
1169
+ errno = ENOSYS;
1170
+ return -1;
1171
+ #endif
1172
+ }
1173
+
1174
+
1175
+ static ssize_t uv__fs_lutime(uv_fs_t* req) {
1176
+ #if defined(__APPLE__) \
1177
+ || defined(_AIX71) \
1178
+ || defined(__DragonFly__) \
1179
+ || defined(__FreeBSD__) \
1180
+ || defined(__HAIKU__) \
1181
+ || defined(__NetBSD__) \
1182
+ || defined(__OpenBSD__) \
1183
+ || defined(__linux__) \
1184
+ || defined(__sun)
1185
+ struct timespec ts[2];
1186
+ ts[0] = uv__fs_to_timespec(req->atime);
1187
+ ts[1] = uv__fs_to_timespec(req->mtime);
1188
+ return utimensat(AT_FDCWD, req->path, ts, AT_SYMLINK_NOFOLLOW);
1189
+ #else
1190
+ errno = ENOSYS;
1191
+ return -1;
1192
+ #endif
1193
+ }
1194
+
1195
+
1196
+ static ssize_t uv__fs_write(uv_fs_t* req) {
1197
+ const struct iovec* bufs;
1198
+ size_t nbufs;
1199
+ ssize_t r;
1200
+ off_t off;
1201
+ int fd;
1202
+
1203
+ fd = req->file;
1204
+ off = req->off;
1205
+ bufs = (const struct iovec*) req->bufs;
1206
+ nbufs = req->nbufs;
1207
+
1208
+ r = 0;
1209
+ if (off < 0) {
1210
+ if (nbufs == 1)
1211
+ r = write(fd, bufs->iov_base, bufs->iov_len);
1212
+ else if (nbufs > 1)
1213
+ r = writev(fd, bufs, nbufs);
1214
+ } else {
1215
+ if (nbufs == 1)
1216
+ r = pwrite(fd, bufs->iov_base, bufs->iov_len, off);
1217
+ else if (nbufs > 1)
1218
+ r = uv__pwritev(fd, bufs, nbufs, off);
1219
+ }
1220
+
1221
+ return r;
1222
+ }
1223
+
1224
+
1225
+ static ssize_t uv__fs_copyfile(uv_fs_t* req) {
1226
+ uv_fs_t fs_req;
1227
+ uv_file srcfd;
1228
+ uv_file dstfd;
1229
+ struct stat src_statsbuf;
1230
+ struct stat dst_statsbuf;
1231
+ struct timespec times[2];
1232
+ int dst_flags;
1233
+ int result;
1234
+ int err;
1235
+ off_t bytes_to_send;
1236
+ off_t in_offset;
1237
+ off_t bytes_written;
1238
+ size_t bytes_chunk;
1239
+
1240
+ dstfd = -1;
1241
+ err = 0;
1242
+
1243
+ /* Open the source file. */
1244
+ srcfd = uv_fs_open(NULL, &fs_req, req->path, O_RDONLY, 0, NULL);
1245
+ uv_fs_req_cleanup(&fs_req);
1246
+
1247
+ if (srcfd < 0)
1248
+ return srcfd;
1249
+
1250
+ /* Get the source file's mode. */
1251
+ if (uv__fstat(srcfd, &src_statsbuf)) {
1252
+ err = UV__ERR(errno);
1253
+ goto out;
1254
+ }
1255
+
1256
+ dst_flags = O_WRONLY | O_CREAT;
1257
+
1258
+ if (req->flags & UV_FS_COPYFILE_EXCL)
1259
+ dst_flags |= O_EXCL;
1260
+
1261
+ /* Open the destination file. */
1262
+ dstfd = uv_fs_open(NULL,
1263
+ &fs_req,
1264
+ req->new_path,
1265
+ dst_flags,
1266
+ src_statsbuf.st_mode,
1267
+ NULL);
1268
+ uv_fs_req_cleanup(&fs_req);
1269
+
1270
+ if (dstfd < 0) {
1271
+ err = dstfd;
1272
+ goto out;
1273
+ }
1274
+
1275
+ /* If the file is not being opened exclusively, verify that the source and
1276
+ destination are not the same file. If they are the same, bail out early. */
1277
+ if ((req->flags & UV_FS_COPYFILE_EXCL) == 0) {
1278
+ /* Get the destination file's mode. */
1279
+ if (uv__fstat(dstfd, &dst_statsbuf)) {
1280
+ err = UV__ERR(errno);
1281
+ goto out;
1282
+ }
1283
+
1284
+ /* Check if srcfd and dstfd refer to the same file */
1285
+ if (src_statsbuf.st_dev == dst_statsbuf.st_dev &&
1286
+ src_statsbuf.st_ino == dst_statsbuf.st_ino) {
1287
+ goto out;
1288
+ }
1289
+
1290
+ /* Truncate the file in case the destination already existed. */
1291
+ if (ftruncate(dstfd, 0) != 0) {
1292
+ err = UV__ERR(errno);
1293
+
1294
+ /* ftruncate() on ceph-fuse fails with EACCES when the file is created
1295
+ * with read only permissions. Since ftruncate() on a newly created
1296
+ * file is a meaningless operation anyway, detect that condition
1297
+ * and squelch the error.
1298
+ */
1299
+ if (err != UV_EACCES)
1300
+ goto out;
1301
+
1302
+ if (dst_statsbuf.st_size > 0)
1303
+ goto out;
1304
+
1305
+ err = 0;
1306
+ }
1307
+ }
1308
+
1309
+ /**
1310
+ * Change the timestamps of the destination file to match the source file.
1311
+ */
1312
+ #if defined(__APPLE__)
1313
+ times[0] = src_statsbuf.st_atimespec;
1314
+ times[1] = src_statsbuf.st_mtimespec;
1315
+ #elif defined(_AIX)
1316
+ times[0].tv_sec = src_statsbuf.st_atime;
1317
+ times[0].tv_nsec = src_statsbuf.st_atime_n;
1318
+ times[1].tv_sec = src_statsbuf.st_mtime;
1319
+ times[1].tv_nsec = src_statsbuf.st_mtime_n;
1320
+ #else
1321
+ times[0] = src_statsbuf.st_atim;
1322
+ times[1] = src_statsbuf.st_mtim;
1323
+ #endif
1324
+
1325
+ if (futimens(dstfd, times) == -1) {
1326
+ err = UV__ERR(errno);
1327
+ goto out;
1328
+ }
1329
+
1330
+ /*
1331
+ * Change the ownership and permissions of the destination file to match the
1332
+ * source file.
1333
+ * `cp -p` does not care about errors here, so we don't either. Reuse the
1334
+ * `result` variable to silence a -Wunused-result warning.
1335
+ */
1336
+ result = fchown(dstfd, src_statsbuf.st_uid, src_statsbuf.st_gid);
1337
+
1338
+ if (fchmod(dstfd, src_statsbuf.st_mode) == -1) {
1339
+ err = UV__ERR(errno);
1340
+ #ifdef __linux__
1341
+ /* fchmod() on CIFS shares always fails with EPERM unless the share is
1342
+ * mounted with "noperm". As fchmod() is a meaningless operation on such
1343
+ * shares anyway, detect that condition and squelch the error.
1344
+ */
1345
+ if (err != UV_EPERM)
1346
+ goto out;
1347
+
1348
+ if (!uv__is_cifs_or_smb(dstfd))
1349
+ goto out;
1350
+
1351
+ err = 0;
1352
+ #else /* !__linux__ */
1353
+ goto out;
1354
+ #endif /* !__linux__ */
1355
+ }
1356
+
1357
+ #ifdef FICLONE
1358
+ if (req->flags & UV_FS_COPYFILE_FICLONE ||
1359
+ req->flags & UV_FS_COPYFILE_FICLONE_FORCE) {
1360
+ if (ioctl(dstfd, FICLONE, srcfd) == 0) {
1361
+ /* ioctl() with FICLONE succeeded. */
1362
+ goto out;
1363
+ }
1364
+ /* If an error occurred and force was set, return the error to the caller;
1365
+ * fall back to sendfile() when force was not set. */
1366
+ if (req->flags & UV_FS_COPYFILE_FICLONE_FORCE) {
1367
+ err = UV__ERR(errno);
1368
+ goto out;
1369
+ }
1370
+ }
1371
+ #else
1372
+ if (req->flags & UV_FS_COPYFILE_FICLONE_FORCE) {
1373
+ err = UV_ENOSYS;
1374
+ goto out;
1375
+ }
1376
+ #endif
1377
+
1378
+ bytes_to_send = src_statsbuf.st_size;
1379
+ in_offset = 0;
1380
+ while (bytes_to_send != 0) {
1381
+ bytes_chunk = SSIZE_MAX;
1382
+ if (bytes_to_send < (off_t) bytes_chunk)
1383
+ bytes_chunk = bytes_to_send;
1384
+ uv_fs_sendfile(NULL, &fs_req, dstfd, srcfd, in_offset, bytes_chunk, NULL);
1385
+ bytes_written = fs_req.result;
1386
+ uv_fs_req_cleanup(&fs_req);
1387
+
1388
+ if (bytes_written < 0) {
1389
+ err = bytes_written;
1390
+ break;
1391
+ }
1392
+
1393
+ bytes_to_send -= bytes_written;
1394
+ in_offset += bytes_written;
1395
+ }
1396
+
1397
+ out:
1398
+ if (err < 0)
1399
+ result = err;
1400
+ else
1401
+ result = 0;
1402
+
1403
+ /* Close the source file. */
1404
+ err = uv__close_nocheckstdio(srcfd);
1405
+
1406
+ /* Don't overwrite any existing errors. */
1407
+ if (err != 0 && result == 0)
1408
+ result = err;
1409
+
1410
+ /* Close the destination file if it is open. */
1411
+ if (dstfd >= 0) {
1412
+ err = uv__close_nocheckstdio(dstfd);
1413
+
1414
+ /* Don't overwrite any existing errors. */
1415
+ if (err != 0 && result == 0)
1416
+ result = err;
1417
+
1418
+ /* Remove the destination file if something went wrong. */
1419
+ if (result != 0) {
1420
+ uv_fs_unlink(NULL, &fs_req, req->new_path, NULL);
1421
+ /* Ignore the unlink return value, as an error already happened. */
1422
+ uv_fs_req_cleanup(&fs_req);
1423
+ }
1424
+ }
1425
+
1426
+ if (result == 0)
1427
+ return 0;
1428
+
1429
+ errno = UV__ERR(result);
1430
+ return -1;
1431
+ }
1432
+
1433
+ static void uv__to_stat(struct stat* src, uv_stat_t* dst) {
1434
+ dst->st_dev = src->st_dev;
1435
+ dst->st_mode = src->st_mode;
1436
+ dst->st_nlink = src->st_nlink;
1437
+ dst->st_uid = src->st_uid;
1438
+ dst->st_gid = src->st_gid;
1439
+ dst->st_rdev = src->st_rdev;
1440
+ dst->st_ino = src->st_ino;
1441
+ dst->st_size = src->st_size;
1442
+ dst->st_blksize = src->st_blksize;
1443
+ dst->st_blocks = src->st_blocks;
1444
+
1445
+ #if defined(__APPLE__)
1446
+ dst->st_atim.tv_sec = src->st_atimespec.tv_sec;
1447
+ dst->st_atim.tv_nsec = src->st_atimespec.tv_nsec;
1448
+ dst->st_mtim.tv_sec = src->st_mtimespec.tv_sec;
1449
+ dst->st_mtim.tv_nsec = src->st_mtimespec.tv_nsec;
1450
+ dst->st_ctim.tv_sec = src->st_ctimespec.tv_sec;
1451
+ dst->st_ctim.tv_nsec = src->st_ctimespec.tv_nsec;
1452
+ dst->st_birthtim.tv_sec = src->st_birthtimespec.tv_sec;
1453
+ dst->st_birthtim.tv_nsec = src->st_birthtimespec.tv_nsec;
1454
+ dst->st_flags = src->st_flags;
1455
+ dst->st_gen = src->st_gen;
1456
+ #elif defined(__ANDROID__)
1457
+ dst->st_atim.tv_sec = src->st_atime;
1458
+ dst->st_atim.tv_nsec = src->st_atimensec;
1459
+ dst->st_mtim.tv_sec = src->st_mtime;
1460
+ dst->st_mtim.tv_nsec = src->st_mtimensec;
1461
+ dst->st_ctim.tv_sec = src->st_ctime;
1462
+ dst->st_ctim.tv_nsec = src->st_ctimensec;
1463
+ dst->st_birthtim.tv_sec = src->st_ctime;
1464
+ dst->st_birthtim.tv_nsec = src->st_ctimensec;
1465
+ dst->st_flags = 0;
1466
+ dst->st_gen = 0;
1467
+ #elif !defined(_AIX) && \
1468
+ !defined(__MVS__) && ( \
1469
+ defined(__DragonFly__) || \
1470
+ defined(__FreeBSD__) || \
1471
+ defined(__OpenBSD__) || \
1472
+ defined(__NetBSD__) || \
1473
+ defined(_GNU_SOURCE) || \
1474
+ defined(_BSD_SOURCE) || \
1475
+ defined(_SVID_SOURCE) || \
1476
+ defined(_XOPEN_SOURCE) || \
1477
+ defined(_DEFAULT_SOURCE))
1478
+ dst->st_atim.tv_sec = src->st_atim.tv_sec;
1479
+ dst->st_atim.tv_nsec = src->st_atim.tv_nsec;
1480
+ dst->st_mtim.tv_sec = src->st_mtim.tv_sec;
1481
+ dst->st_mtim.tv_nsec = src->st_mtim.tv_nsec;
1482
+ dst->st_ctim.tv_sec = src->st_ctim.tv_sec;
1483
+ dst->st_ctim.tv_nsec = src->st_ctim.tv_nsec;
1484
+ # if defined(__FreeBSD__) || \
1485
+ defined(__NetBSD__)
1486
+ dst->st_birthtim.tv_sec = src->st_birthtim.tv_sec;
1487
+ dst->st_birthtim.tv_nsec = src->st_birthtim.tv_nsec;
1488
+ dst->st_flags = src->st_flags;
1489
+ dst->st_gen = src->st_gen;
1490
+ # else
1491
+ dst->st_birthtim.tv_sec = src->st_ctim.tv_sec;
1492
+ dst->st_birthtim.tv_nsec = src->st_ctim.tv_nsec;
1493
+ dst->st_flags = 0;
1494
+ dst->st_gen = 0;
1495
+ # endif
1496
+ #else
1497
+ dst->st_atim.tv_sec = src->st_atime;
1498
+ dst->st_atim.tv_nsec = 0;
1499
+ dst->st_mtim.tv_sec = src->st_mtime;
1500
+ dst->st_mtim.tv_nsec = 0;
1501
+ dst->st_ctim.tv_sec = src->st_ctime;
1502
+ dst->st_ctim.tv_nsec = 0;
1503
+ dst->st_birthtim.tv_sec = src->st_ctime;
1504
+ dst->st_birthtim.tv_nsec = 0;
1505
+ dst->st_flags = 0;
1506
+ dst->st_gen = 0;
1507
+ #endif
1508
+ }
1509
+
1510
+
1511
+ static int uv__fs_statx(int fd,
1512
+ const char* path,
1513
+ int is_fstat,
1514
+ int is_lstat,
1515
+ uv_stat_t* buf) {
1516
+ STATIC_ASSERT(UV_ENOSYS != -1);
1517
+ #ifdef __linux__
1518
+ static _Atomic int no_statx;
1519
+ struct uv__statx statxbuf;
1520
+ int dirfd;
1521
+ int flags;
1522
+ int mode;
1523
+ int rc;
1524
+
1525
+ if (atomic_load_explicit(&no_statx, memory_order_relaxed))
1526
+ return UV_ENOSYS;
1527
+
1528
+ dirfd = AT_FDCWD;
1529
+ flags = 0; /* AT_STATX_SYNC_AS_STAT */
1530
+ mode = 0xFFF; /* STATX_BASIC_STATS + STATX_BTIME */
1531
+
1532
+ if (is_fstat) {
1533
+ dirfd = fd;
1534
+ flags |= 0x1000; /* AT_EMPTY_PATH */
1535
+ }
1536
+
1537
+ if (is_lstat)
1538
+ flags |= AT_SYMLINK_NOFOLLOW;
1539
+
1540
+ rc = uv__statx(dirfd, path, flags, mode, &statxbuf);
1541
+
1542
+ switch (rc) {
1543
+ case 0:
1544
+ break;
1545
+ case -1:
1546
+ /* EPERM happens when a seccomp filter rejects the system call.
1547
+ * Has been observed with libseccomp < 2.3.3 and docker < 18.04.
1548
+ * EOPNOTSUPP is used on DVS exported filesystems
1549
+ */
1550
+ if (errno != EINVAL && errno != EPERM && errno != ENOSYS && errno != EOPNOTSUPP)
1551
+ return -1;
1552
+ /* Fall through. */
1553
+ default:
1554
+ /* Normally on success, zero is returned and On error, -1 is returned.
1555
+ * Observed on S390 RHEL running in a docker container with statx not
1556
+ * implemented, rc might return 1 with 0 set as the error code in which
1557
+ * case we return ENOSYS.
1558
+ */
1559
+ atomic_store_explicit(&no_statx, 1, memory_order_relaxed);
1560
+ return UV_ENOSYS;
1561
+ }
1562
+
1563
+ uv__statx_to_stat(&statxbuf, buf);
1564
+
1565
+ return 0;
1566
+ #else
1567
+ return UV_ENOSYS;
1568
+ #endif /* __linux__ */
1569
+ }
1570
+
1571
+
1572
+ static int uv__fs_stat(const char *path, uv_stat_t *buf) {
1573
+ struct stat pbuf;
1574
+ int ret;
1575
+
1576
+ ret = uv__fs_statx(-1, path, /* is_fstat */ 0, /* is_lstat */ 0, buf);
1577
+ if (ret != UV_ENOSYS)
1578
+ return ret;
1579
+
1580
+ ret = uv__stat(path, &pbuf);
1581
+ if (ret == 0)
1582
+ uv__to_stat(&pbuf, buf);
1583
+
1584
+ return ret;
1585
+ }
1586
+
1587
+
1588
+ static int uv__fs_lstat(const char *path, uv_stat_t *buf) {
1589
+ struct stat pbuf;
1590
+ int ret;
1591
+
1592
+ ret = uv__fs_statx(-1, path, /* is_fstat */ 0, /* is_lstat */ 1, buf);
1593
+ if (ret != UV_ENOSYS)
1594
+ return ret;
1595
+
1596
+ ret = uv__lstat(path, &pbuf);
1597
+ if (ret == 0)
1598
+ uv__to_stat(&pbuf, buf);
1599
+
1600
+ return ret;
1601
+ }
1602
+
1603
+
1604
+ static int uv__fs_fstat(int fd, uv_stat_t *buf) {
1605
+ struct stat pbuf;
1606
+ int ret;
1607
+
1608
+ ret = uv__fs_statx(fd, "", /* is_fstat */ 1, /* is_lstat */ 0, buf);
1609
+ if (ret != UV_ENOSYS)
1610
+ return ret;
1611
+
1612
+ ret = uv__fstat(fd, &pbuf);
1613
+ if (ret == 0)
1614
+ uv__to_stat(&pbuf, buf);
1615
+
1616
+ return ret;
1617
+ }
1618
+
1619
+ static size_t uv__fs_buf_offset(uv_buf_t* bufs, size_t size) {
1620
+ size_t offset;
1621
+ /* Figure out which bufs are done */
1622
+ for (offset = 0; size > 0 && bufs[offset].len <= size; ++offset)
1623
+ size -= bufs[offset].len;
1624
+
1625
+ /* Fix a partial read/write */
1626
+ if (size > 0) {
1627
+ bufs[offset].base += size;
1628
+ bufs[offset].len -= size;
1629
+ }
1630
+ return offset;
1631
+ }
1632
+
1633
+ static ssize_t uv__fs_write_all(uv_fs_t* req) {
1634
+ unsigned int iovmax;
1635
+ unsigned int nbufs;
1636
+ uv_buf_t* bufs;
1637
+ ssize_t total;
1638
+ ssize_t result;
1639
+
1640
+ iovmax = uv__getiovmax();
1641
+ nbufs = req->nbufs;
1642
+ bufs = req->bufs;
1643
+ total = 0;
1644
+
1645
+ while (nbufs > 0) {
1646
+ req->nbufs = nbufs;
1647
+ if (req->nbufs > iovmax)
1648
+ req->nbufs = iovmax;
1649
+
1650
+ do
1651
+ result = uv__fs_write(req);
1652
+ while (result < 0 && errno == EINTR);
1653
+
1654
+ if (result <= 0) {
1655
+ if (total == 0)
1656
+ total = result;
1657
+ break;
1658
+ }
1659
+
1660
+ if (req->off >= 0)
1661
+ req->off += result;
1662
+
1663
+ req->nbufs = uv__fs_buf_offset(req->bufs, result);
1664
+ req->bufs += req->nbufs;
1665
+ nbufs -= req->nbufs;
1666
+ total += result;
1667
+ }
1668
+
1669
+ if (bufs != req->bufsml)
1670
+ uv__free(bufs);
1671
+
1672
+ req->bufs = NULL;
1673
+ req->nbufs = 0;
1674
+
1675
+ return total;
1676
+ }
1677
+
1678
+
1679
+ static void uv__fs_work(struct uv__work* w) {
1680
+ int retry_on_eintr;
1681
+ uv_fs_t* req;
1682
+ ssize_t r;
1683
+
1684
+ req = container_of(w, uv_fs_t, work_req);
1685
+ retry_on_eintr = !(req->fs_type == UV_FS_CLOSE ||
1686
+ req->fs_type == UV_FS_READ);
1687
+
1688
+ do {
1689
+ errno = 0;
1690
+
1691
+ #define X(type, action) \
1692
+ case UV_FS_ ## type: \
1693
+ r = action; \
1694
+ break;
1695
+
1696
+ switch (req->fs_type) {
1697
+ X(ACCESS, access(req->path, req->flags));
1698
+ X(CHMOD, chmod(req->path, req->mode));
1699
+ X(CHOWN, chown(req->path, req->uid, req->gid));
1700
+ X(CLOSE, uv__fs_close(req->file));
1701
+ X(COPYFILE, uv__fs_copyfile(req));
1702
+ X(FCHMOD, fchmod(req->file, req->mode));
1703
+ X(FCHOWN, fchown(req->file, req->uid, req->gid));
1704
+ X(LCHOWN, lchown(req->path, req->uid, req->gid));
1705
+ X(FDATASYNC, uv__fs_fdatasync(req));
1706
+ X(FSTAT, uv__fs_fstat(req->file, &req->statbuf));
1707
+ X(FSYNC, uv__fs_fsync(req));
1708
+ X(FTRUNCATE, ftruncate(req->file, req->off));
1709
+ X(FUTIME, uv__fs_futime(req));
1710
+ X(LUTIME, uv__fs_lutime(req));
1711
+ X(LSTAT, uv__fs_lstat(req->path, &req->statbuf));
1712
+ X(LINK, link(req->path, req->new_path));
1713
+ X(MKDIR, mkdir(req->path, req->mode));
1714
+ X(MKDTEMP, uv__fs_mkdtemp(req));
1715
+ X(MKSTEMP, uv__fs_mkstemp(req));
1716
+ X(OPEN, uv__fs_open(req));
1717
+ X(READ, uv__fs_read(req));
1718
+ X(SCANDIR, uv__fs_scandir(req));
1719
+ X(OPENDIR, uv__fs_opendir(req));
1720
+ X(READDIR, uv__fs_readdir(req));
1721
+ X(CLOSEDIR, uv__fs_closedir(req));
1722
+ X(READLINK, uv__fs_readlink(req));
1723
+ X(REALPATH, uv__fs_realpath(req));
1724
+ X(RENAME, rename(req->path, req->new_path));
1725
+ X(RMDIR, rmdir(req->path));
1726
+ X(SENDFILE, uv__fs_sendfile(req));
1727
+ X(STAT, uv__fs_stat(req->path, &req->statbuf));
1728
+ X(STATFS, uv__fs_statfs(req));
1729
+ X(SYMLINK, symlink(req->path, req->new_path));
1730
+ X(UNLINK, unlink(req->path));
1731
+ X(UTIME, uv__fs_utime(req));
1732
+ X(WRITE, uv__fs_write_all(req));
1733
+ default: abort();
1734
+ }
1735
+ #undef X
1736
+ } while (r == -1 && errno == EINTR && retry_on_eintr);
1737
+
1738
+ if (r == -1)
1739
+ req->result = UV__ERR(errno);
1740
+ else
1741
+ req->result = r;
1742
+
1743
+ if (r == 0 && (req->fs_type == UV_FS_STAT ||
1744
+ req->fs_type == UV_FS_FSTAT ||
1745
+ req->fs_type == UV_FS_LSTAT)) {
1746
+ req->ptr = &req->statbuf;
1747
+ }
1748
+ }
1749
+
1750
+
1751
+ static void uv__fs_done(struct uv__work* w, int status) {
1752
+ uv_fs_t* req;
1753
+
1754
+ req = container_of(w, uv_fs_t, work_req);
1755
+ uv__req_unregister(req->loop);
1756
+
1757
+ if (status == UV_ECANCELED) {
1758
+ assert(req->result == 0);
1759
+ req->result = UV_ECANCELED;
1760
+ }
1761
+
1762
+ req->cb(req);
1763
+ }
1764
+
1765
+
1766
+ void uv__fs_post(uv_loop_t* loop, uv_fs_t* req) {
1767
+ uv__req_register(loop);
1768
+ uv__work_submit(loop,
1769
+ &req->work_req,
1770
+ UV__WORK_FAST_IO,
1771
+ uv__fs_work,
1772
+ uv__fs_done);
1773
+ }
1774
+
1775
+
1776
+ int uv_fs_access(uv_loop_t* loop,
1777
+ uv_fs_t* req,
1778
+ const char* path,
1779
+ int flags,
1780
+ uv_fs_cb cb) {
1781
+ INIT(ACCESS);
1782
+ PATH;
1783
+ req->flags = flags;
1784
+ POST;
1785
+ }
1786
+
1787
+
1788
+ int uv_fs_chmod(uv_loop_t* loop,
1789
+ uv_fs_t* req,
1790
+ const char* path,
1791
+ int mode,
1792
+ uv_fs_cb cb) {
1793
+ INIT(CHMOD);
1794
+ PATH;
1795
+ req->mode = mode;
1796
+ POST;
1797
+ }
1798
+
1799
+
1800
+ int uv_fs_chown(uv_loop_t* loop,
1801
+ uv_fs_t* req,
1802
+ const char* path,
1803
+ uv_uid_t uid,
1804
+ uv_gid_t gid,
1805
+ uv_fs_cb cb) {
1806
+ INIT(CHOWN);
1807
+ PATH;
1808
+ req->uid = uid;
1809
+ req->gid = gid;
1810
+ POST;
1811
+ }
1812
+
1813
+
1814
+ int uv_fs_close(uv_loop_t* loop, uv_fs_t* req, uv_file file, uv_fs_cb cb) {
1815
+ INIT(CLOSE);
1816
+ req->file = file;
1817
+ if (cb != NULL)
1818
+ if (uv__iou_fs_close(loop, req))
1819
+ return 0;
1820
+ POST;
1821
+ }
1822
+
1823
+
1824
+ int uv_fs_fchmod(uv_loop_t* loop,
1825
+ uv_fs_t* req,
1826
+ uv_file file,
1827
+ int mode,
1828
+ uv_fs_cb cb) {
1829
+ INIT(FCHMOD);
1830
+ req->file = file;
1831
+ req->mode = mode;
1832
+ POST;
1833
+ }
1834
+
1835
+
1836
+ int uv_fs_fchown(uv_loop_t* loop,
1837
+ uv_fs_t* req,
1838
+ uv_file file,
1839
+ uv_uid_t uid,
1840
+ uv_gid_t gid,
1841
+ uv_fs_cb cb) {
1842
+ INIT(FCHOWN);
1843
+ req->file = file;
1844
+ req->uid = uid;
1845
+ req->gid = gid;
1846
+ POST;
1847
+ }
1848
+
1849
+
1850
+ int uv_fs_lchown(uv_loop_t* loop,
1851
+ uv_fs_t* req,
1852
+ const char* path,
1853
+ uv_uid_t uid,
1854
+ uv_gid_t gid,
1855
+ uv_fs_cb cb) {
1856
+ INIT(LCHOWN);
1857
+ PATH;
1858
+ req->uid = uid;
1859
+ req->gid = gid;
1860
+ POST;
1861
+ }
1862
+
1863
+
1864
+ int uv_fs_fdatasync(uv_loop_t* loop, uv_fs_t* req, uv_file file, uv_fs_cb cb) {
1865
+ INIT(FDATASYNC);
1866
+ req->file = file;
1867
+ if (cb != NULL)
1868
+ if (uv__iou_fs_fsync_or_fdatasync(loop, req, /* IORING_FSYNC_DATASYNC */ 1))
1869
+ return 0;
1870
+ POST;
1871
+ }
1872
+
1873
+
1874
+ int uv_fs_fstat(uv_loop_t* loop, uv_fs_t* req, uv_file file, uv_fs_cb cb) {
1875
+ INIT(FSTAT);
1876
+ req->file = file;
1877
+ if (cb != NULL)
1878
+ if (uv__iou_fs_statx(loop, req, /* is_fstat */ 1, /* is_lstat */ 0))
1879
+ return 0;
1880
+ POST;
1881
+ }
1882
+
1883
+
1884
+ int uv_fs_fsync(uv_loop_t* loop, uv_fs_t* req, uv_file file, uv_fs_cb cb) {
1885
+ INIT(FSYNC);
1886
+ req->file = file;
1887
+ if (cb != NULL)
1888
+ if (uv__iou_fs_fsync_or_fdatasync(loop, req, /* no flags */ 0))
1889
+ return 0;
1890
+ POST;
1891
+ }
1892
+
1893
+
1894
+ int uv_fs_ftruncate(uv_loop_t* loop,
1895
+ uv_fs_t* req,
1896
+ uv_file file,
1897
+ int64_t off,
1898
+ uv_fs_cb cb) {
1899
+ INIT(FTRUNCATE);
1900
+ req->file = file;
1901
+ req->off = off;
1902
+ if (cb != NULL)
1903
+ if (uv__iou_fs_ftruncate(loop, req))
1904
+ return 0;
1905
+ POST;
1906
+ }
1907
+
1908
+
1909
+ int uv_fs_futime(uv_loop_t* loop,
1910
+ uv_fs_t* req,
1911
+ uv_file file,
1912
+ double atime,
1913
+ double mtime,
1914
+ uv_fs_cb cb) {
1915
+ INIT(FUTIME);
1916
+ req->file = file;
1917
+ req->atime = atime;
1918
+ req->mtime = mtime;
1919
+ POST;
1920
+ }
1921
+
1922
+ int uv_fs_lutime(uv_loop_t* loop,
1923
+ uv_fs_t* req,
1924
+ const char* path,
1925
+ double atime,
1926
+ double mtime,
1927
+ uv_fs_cb cb) {
1928
+ INIT(LUTIME);
1929
+ PATH;
1930
+ req->atime = atime;
1931
+ req->mtime = mtime;
1932
+ POST;
1933
+ }
1934
+
1935
+
1936
+ int uv_fs_lstat(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb) {
1937
+ INIT(LSTAT);
1938
+ PATH;
1939
+ if (cb != NULL)
1940
+ if (uv__iou_fs_statx(loop, req, /* is_fstat */ 0, /* is_lstat */ 1))
1941
+ return 0;
1942
+ POST;
1943
+ }
1944
+
1945
+
1946
+ int uv_fs_link(uv_loop_t* loop,
1947
+ uv_fs_t* req,
1948
+ const char* path,
1949
+ const char* new_path,
1950
+ uv_fs_cb cb) {
1951
+ INIT(LINK);
1952
+ PATH2;
1953
+ if (cb != NULL)
1954
+ if (uv__iou_fs_link(loop, req))
1955
+ return 0;
1956
+ POST;
1957
+ }
1958
+
1959
+
1960
+ int uv_fs_mkdir(uv_loop_t* loop,
1961
+ uv_fs_t* req,
1962
+ const char* path,
1963
+ int mode,
1964
+ uv_fs_cb cb) {
1965
+ INIT(MKDIR);
1966
+ PATH;
1967
+ req->mode = mode;
1968
+ if (cb != NULL)
1969
+ if (uv__iou_fs_mkdir(loop, req))
1970
+ return 0;
1971
+ POST;
1972
+ }
1973
+
1974
+
1975
+ int uv_fs_mkdtemp(uv_loop_t* loop,
1976
+ uv_fs_t* req,
1977
+ const char* tpl,
1978
+ uv_fs_cb cb) {
1979
+ INIT(MKDTEMP);
1980
+ req->path = uv__strdup(tpl);
1981
+ if (req->path == NULL)
1982
+ return UV_ENOMEM;
1983
+ POST;
1984
+ }
1985
+
1986
+
1987
+ int uv_fs_mkstemp(uv_loop_t* loop,
1988
+ uv_fs_t* req,
1989
+ const char* tpl,
1990
+ uv_fs_cb cb) {
1991
+ INIT(MKSTEMP);
1992
+ req->path = uv__strdup(tpl);
1993
+ if (req->path == NULL)
1994
+ return UV_ENOMEM;
1995
+ POST;
1996
+ }
1997
+
1998
+
1999
+ int uv_fs_open(uv_loop_t* loop,
2000
+ uv_fs_t* req,
2001
+ const char* path,
2002
+ int flags,
2003
+ int mode,
2004
+ uv_fs_cb cb) {
2005
+ INIT(OPEN);
2006
+ PATH;
2007
+ req->flags = flags;
2008
+ req->mode = mode;
2009
+ if (cb != NULL)
2010
+ if (uv__iou_fs_open(loop, req))
2011
+ return 0;
2012
+ POST;
2013
+ }
2014
+
2015
+
2016
+ int uv_fs_read(uv_loop_t* loop, uv_fs_t* req,
2017
+ uv_file file,
2018
+ const uv_buf_t bufs[],
2019
+ unsigned int nbufs,
2020
+ int64_t off,
2021
+ uv_fs_cb cb) {
2022
+ INIT(READ);
2023
+
2024
+ if (bufs == NULL || nbufs == 0)
2025
+ return UV_EINVAL;
2026
+
2027
+ req->off = off;
2028
+ req->file = file;
2029
+ req->bufs = (uv_buf_t*) bufs; /* Safe, doesn't mutate |bufs| */
2030
+ req->nbufs = nbufs;
2031
+
2032
+ if (cb == NULL)
2033
+ goto post;
2034
+
2035
+ req->bufs = req->bufsml;
2036
+ if (nbufs > ARRAY_SIZE(req->bufsml))
2037
+ req->bufs = uv__malloc(nbufs * sizeof(*bufs));
2038
+
2039
+ if (req->bufs == NULL)
2040
+ return UV_ENOMEM;
2041
+
2042
+ memcpy(req->bufs, bufs, nbufs * sizeof(*bufs));
2043
+
2044
+ if (uv__iou_fs_read_or_write(loop, req, /* is_read */ 1))
2045
+ return 0;
2046
+
2047
+ post:
2048
+ POST;
2049
+ }
2050
+
2051
+
2052
+ int uv_fs_scandir(uv_loop_t* loop,
2053
+ uv_fs_t* req,
2054
+ const char* path,
2055
+ int flags,
2056
+ uv_fs_cb cb) {
2057
+ INIT(SCANDIR);
2058
+ PATH;
2059
+ req->flags = flags;
2060
+ POST;
2061
+ }
2062
+
2063
+ int uv_fs_opendir(uv_loop_t* loop,
2064
+ uv_fs_t* req,
2065
+ const char* path,
2066
+ uv_fs_cb cb) {
2067
+ INIT(OPENDIR);
2068
+ PATH;
2069
+ POST;
2070
+ }
2071
+
2072
+ int uv_fs_readdir(uv_loop_t* loop,
2073
+ uv_fs_t* req,
2074
+ uv_dir_t* dir,
2075
+ uv_fs_cb cb) {
2076
+ INIT(READDIR);
2077
+
2078
+ if (dir == NULL || dir->dir == NULL || dir->dirents == NULL)
2079
+ return UV_EINVAL;
2080
+
2081
+ req->ptr = dir;
2082
+ POST;
2083
+ }
2084
+
2085
+ int uv_fs_closedir(uv_loop_t* loop,
2086
+ uv_fs_t* req,
2087
+ uv_dir_t* dir,
2088
+ uv_fs_cb cb) {
2089
+ INIT(CLOSEDIR);
2090
+
2091
+ if (dir == NULL)
2092
+ return UV_EINVAL;
2093
+
2094
+ req->ptr = dir;
2095
+ POST;
2096
+ }
2097
+
2098
+ int uv_fs_readlink(uv_loop_t* loop,
2099
+ uv_fs_t* req,
2100
+ const char* path,
2101
+ uv_fs_cb cb) {
2102
+ INIT(READLINK);
2103
+ PATH;
2104
+ POST;
2105
+ }
2106
+
2107
+
2108
+ int uv_fs_realpath(uv_loop_t* loop,
2109
+ uv_fs_t* req,
2110
+ const char * path,
2111
+ uv_fs_cb cb) {
2112
+ INIT(REALPATH);
2113
+ PATH;
2114
+ POST;
2115
+ }
2116
+
2117
+
2118
+ int uv_fs_rename(uv_loop_t* loop,
2119
+ uv_fs_t* req,
2120
+ const char* path,
2121
+ const char* new_path,
2122
+ uv_fs_cb cb) {
2123
+ INIT(RENAME);
2124
+ PATH2;
2125
+ if (cb != NULL)
2126
+ if (uv__iou_fs_rename(loop, req))
2127
+ return 0;
2128
+ POST;
2129
+ }
2130
+
2131
+
2132
+ int uv_fs_rmdir(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb) {
2133
+ INIT(RMDIR);
2134
+ PATH;
2135
+ POST;
2136
+ }
2137
+
2138
+
2139
+ int uv_fs_sendfile(uv_loop_t* loop,
2140
+ uv_fs_t* req,
2141
+ uv_file out_fd,
2142
+ uv_file in_fd,
2143
+ int64_t off,
2144
+ size_t len,
2145
+ uv_fs_cb cb) {
2146
+ INIT(SENDFILE);
2147
+ req->flags = in_fd; /* hack */
2148
+ req->file = out_fd;
2149
+ req->off = off;
2150
+ req->bufsml[0].len = len;
2151
+ POST;
2152
+ }
2153
+
2154
+
2155
+ int uv_fs_stat(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb) {
2156
+ INIT(STAT);
2157
+ PATH;
2158
+ if (cb != NULL)
2159
+ if (uv__iou_fs_statx(loop, req, /* is_fstat */ 0, /* is_lstat */ 0))
2160
+ return 0;
2161
+ POST;
2162
+ }
2163
+
2164
+
2165
+ int uv_fs_symlink(uv_loop_t* loop,
2166
+ uv_fs_t* req,
2167
+ const char* path,
2168
+ const char* new_path,
2169
+ int flags,
2170
+ uv_fs_cb cb) {
2171
+ INIT(SYMLINK);
2172
+ PATH2;
2173
+ req->flags = flags;
2174
+ if (cb != NULL)
2175
+ if (uv__iou_fs_symlink(loop, req))
2176
+ return 0;
2177
+ POST;
2178
+ }
2179
+
2180
+
2181
+ int uv_fs_unlink(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb) {
2182
+ INIT(UNLINK);
2183
+ PATH;
2184
+ if (cb != NULL)
2185
+ if (uv__iou_fs_unlink(loop, req))
2186
+ return 0;
2187
+ POST;
2188
+ }
2189
+
2190
+
2191
+ int uv_fs_utime(uv_loop_t* loop,
2192
+ uv_fs_t* req,
2193
+ const char* path,
2194
+ double atime,
2195
+ double mtime,
2196
+ uv_fs_cb cb) {
2197
+ INIT(UTIME);
2198
+ PATH;
2199
+ req->atime = atime;
2200
+ req->mtime = mtime;
2201
+ POST;
2202
+ }
2203
+
2204
+
2205
+ int uv_fs_write(uv_loop_t* loop,
2206
+ uv_fs_t* req,
2207
+ uv_file file,
2208
+ const uv_buf_t bufs[],
2209
+ unsigned int nbufs,
2210
+ int64_t off,
2211
+ uv_fs_cb cb) {
2212
+ INIT(WRITE);
2213
+
2214
+ if (bufs == NULL || nbufs == 0)
2215
+ return UV_EINVAL;
2216
+
2217
+ req->file = file;
2218
+
2219
+ req->nbufs = nbufs;
2220
+ req->bufs = req->bufsml;
2221
+ if (nbufs > ARRAY_SIZE(req->bufsml))
2222
+ req->bufs = uv__malloc(nbufs * sizeof(*bufs));
2223
+
2224
+ if (req->bufs == NULL)
2225
+ return UV_ENOMEM;
2226
+
2227
+ memcpy(req->bufs, bufs, nbufs * sizeof(*bufs));
2228
+
2229
+ req->off = off;
2230
+
2231
+ if (cb != NULL)
2232
+ if (uv__iou_fs_read_or_write(loop, req, /* is_read */ 0))
2233
+ return 0;
2234
+
2235
+ POST;
2236
+ }
2237
+
2238
+
2239
+ void uv_fs_req_cleanup(uv_fs_t* req) {
2240
+ if (req == NULL)
2241
+ return;
2242
+
2243
+ /* Only necessary for asynchronous requests, i.e., requests with a callback.
2244
+ * Synchronous ones don't copy their arguments and have req->path and
2245
+ * req->new_path pointing to user-owned memory. UV_FS_MKDTEMP and
2246
+ * UV_FS_MKSTEMP are the exception to the rule, they always allocate memory.
2247
+ */
2248
+ if (req->path != NULL &&
2249
+ (req->cb != NULL ||
2250
+ req->fs_type == UV_FS_MKDTEMP || req->fs_type == UV_FS_MKSTEMP))
2251
+ uv__free((void*) req->path); /* Memory is shared with req->new_path. */
2252
+
2253
+ req->path = NULL;
2254
+ req->new_path = NULL;
2255
+
2256
+ if (req->fs_type == UV_FS_READDIR && req->ptr != NULL)
2257
+ uv__fs_readdir_cleanup(req);
2258
+
2259
+ if (req->fs_type == UV_FS_SCANDIR && req->ptr != NULL)
2260
+ uv__fs_scandir_cleanup(req);
2261
+
2262
+ if (req->bufs != req->bufsml)
2263
+ uv__free(req->bufs);
2264
+ req->bufs = NULL;
2265
+
2266
+ if (req->fs_type != UV_FS_OPENDIR && req->ptr != &req->statbuf)
2267
+ uv__free(req->ptr);
2268
+ req->ptr = NULL;
2269
+ }
2270
+
2271
+
2272
+ int uv_fs_copyfile(uv_loop_t* loop,
2273
+ uv_fs_t* req,
2274
+ const char* path,
2275
+ const char* new_path,
2276
+ int flags,
2277
+ uv_fs_cb cb) {
2278
+ INIT(COPYFILE);
2279
+
2280
+ if (flags & ~(UV_FS_COPYFILE_EXCL |
2281
+ UV_FS_COPYFILE_FICLONE |
2282
+ UV_FS_COPYFILE_FICLONE_FORCE)) {
2283
+ return UV_EINVAL;
2284
+ }
2285
+
2286
+ PATH2;
2287
+ req->flags = flags;
2288
+ POST;
2289
+ }
2290
+
2291
+
2292
+ int uv_fs_statfs(uv_loop_t* loop,
2293
+ uv_fs_t* req,
2294
+ const char* path,
2295
+ uv_fs_cb cb) {
2296
+ INIT(STATFS);
2297
+ PATH;
2298
+ POST;
2299
+ }
2300
+
2301
+ int uv_fs_get_system_error(const uv_fs_t* req) {
2302
+ return -req->result;
2303
+ }