| 1 | /* -*- c-basic-offset: 2 -*- */cxx . . $ `<file>/storage/mroonga/vendor/groonga/lib/io.c`/ |
| 2 | /* |
| 3 | Copyright(C) 2009-2017 Brazil |
| 4 | |
| 5 | This library is free software; you can redistribute it and/or |
| 6 | modify it under the terms of the GNU Lesser General Public |
| 7 | License version 2.1 as published by the Free Software Foundation. |
| 8 | |
| 9 | This library is distributed in the hope that it will be useful, |
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 | Lesser General Public License for more details. |
| 13 | |
| 14 | You should have received a copy of the GNU Lesser General Public |
| 15 | License along with this library; if not, write to the Free Software |
| 16 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA |
| 17 | */ |
| 18 | |
| 19 | #include "grn.h"cxx . . $ `<file>/storage/mroonga/vendor/groonga/lib/grn.h`/ |
| 20 | |
| 21 | #include <stdlib.h> |
| 22 | #include <stdio.h> |
| 23 | #include <fcntl.h> |
| 24 | #include <string.h> |
| 25 | #include <sys/stat.h> |
| 26 | |
| 27 | #include "grn_ctx.h"cxx . . $ `<file>/storage/mroonga/vendor/groonga/lib/grn_ctx.h`/ |
| 28 | #include "grn_io.h"cxx . . $ `<file>/storage/mroonga/vendor/groonga/lib/grn_io.h`/ |
| 29 | #include "grn_plugin.h"cxx . . $ `<file>/storage/mroonga/vendor/groonga/lib/grn_plugin.h`/ |
| 30 | #include "grn_hash.h"cxx . . $ `<file>/storage/mroonga/vendor/groonga/lib/grn_hash.h`/ |
| 31 | #include "grn_ctx_impl.h"cxx . . $ `<file>/storage/mroonga/vendor/groonga/lib/grn_ctx_impl.h`/ |
| 32 | #include "grn_util.h"cxx . . $ `<file>/storage/mroonga/vendor/groonga/lib/grn_util.h`/ |
| 33 | |
| 34 | #ifdef WIN32 |
| 35 | # include <io.h> |
| 36 | # include <share.h> |
| 37 | #endif /* WIN32 */ |
| 38 | |
| 39 | #define GRN_IO_IDSTRcxx . . $ `storage/mroonga/vendor/groonga/lib/io.c:39:9`! "GROONGA:IO:00001" |
| 40 | #define GRN_IO_IDSTR_LENcxx . . $ `storage/mroonga/vendor/groonga/lib/io.c:40:9`! (sizeof(GRN_IO_IDSTRcxx . . $ `storage/mroonga/vendor/groonga/lib/io.c:39:9`!) - 1) |
| 41 | |
| 42 | #define GRN_IO_VERSION_DEFAULTcxx . . $ `storage/mroonga/vendor/groonga/lib/io.c:42:9`! 1 |
| 43 | |
| 44 | #define GRN_IO_FILE_SIZE_V1cxx . . $ `storage/mroonga/vendor/groonga/lib/io.c:44:9`! 1073741824UL |
| 45 | |
| 46 | #ifdef WIN32 |
| 47 | # define GRN_IO_FILE_SIZE_V0 134217728L |
| 48 | #else /* WIN32 */ |
| 49 | # define GRN_IO_FILE_SIZE_V0cxx . . $ `storage/mroonga/vendor/groonga/lib/io.c:49:10`! GRN_IO_FILE_SIZE_V1cxx . . $ `storage/mroonga/vendor/groonga/lib/io.c:44:9`! |
| 50 | #endif /* WIN32 */ |
| 51 | |
| 52 | typedef struct _grn_io_fileinfocxx . . $ _grn_io_fileinfo# { |
| 53 | #ifdef WIN32 |
| 54 | HANDLE fh; |
| 55 | HANDLE fmo; |
| 56 | grn_critical_section cs; |
| 57 | #else /* WIN32 */ |
| 58 | int fdcxx . . $ _grn_io_fileinfo#fd.; |
| 59 | dev_tcxx . . $ dev_t# devcxx . . $ _grn_io_fileinfo#dev.; |
| 60 | ino_tcxx . . $ ino_t# inodecxx . . $ _grn_io_fileinfo#inode.; |
| 61 | #endif /* WIN32 */ |
| 62 | } fileinfocxx . . $ fileinfo#; |
| 63 | |
| 64 | #define IO_HEADER_SIZEcxx . . $ `storage/mroonga/vendor/groonga/lib/io.c:64:9`! 64 |
| 65 | |
| 66 | static uint32_tcxx . . $ uint32_t# grn_io_version_defaultcxx . . $ grn_io_version_default. = GRN_IO_VERSION_DEFAULTcxx . . $ `storage/mroonga/vendor/groonga/lib/io.c:42:9`!; |
| 67 | static grn_boolcxx . . $ grn_bool# grn_io_use_sparsecxx . . $ grn_io_use_sparse. = GRN_FALSEcxx . . $ `storage/mroonga/vendor/groonga/include/groonga/groonga.h:45:9`!; |
| 68 | |
| 69 | inline static grn_rccxx . . $ grn_rc# grn_fileinfo_opencxx . . $ grn_fileinfo_open(ac8f5bf2db69e073).(grn_ctxcxx . . $ grn_ctx# *ctx, fileinfocxx . . $ fileinfo# *fi, |
| 70 | const char *path, int flags); |
| 71 | inline static void grn_fileinfo_initcxx . . $ grn_fileinfo_init(f06d8a745bb74b52).(fileinfocxx . . $ fileinfo# *fis, int nfis); |
| 72 | inline static int grn_fileinfo_openedcxx . . $ grn_fileinfo_opened(600504bf85ebe923).(fileinfocxx . . $ fileinfo# *fi); |
| 73 | inline static grn_rccxx . . $ grn_rc# grn_fileinfo_closecxx . . $ grn_fileinfo_close(91b895c7c0cdf7c3).(grn_ctxcxx . . $ grn_ctx# *ctx, fileinfocxx . . $ fileinfo# *fi); |
| 74 | #ifdef WIN32 |
| 75 | inline static void * grn_mmap(grn_ctx *ctx, grn_ctx *owner_ctx, |
| 76 | grn_io *io, HANDLE *fmo, fileinfo *fi, |
| 77 | off_t offset, size_t length); |
| 78 | inline static int grn_munmap(grn_ctx *ctx, grn_ctx *owner_ctx, |
| 79 | grn_io *io, HANDLE *fmo, fileinfo *fi, |
| 80 | void *start, size_t length); |
| 81 | inline static int grn_msync(grn_ctx *ctx, HANDLE fh, |
| 82 | void *start, size_t length); |
| 83 | # define GRN_MMAP(ctx,owner_ctx,io,fmo,fi,offset,length)\ |
| 84 | (grn_mmap((ctx), (owner_ctx), (io), (fmo), (fi), (offset), (length))) |
| 85 | # define GRN_MUNMAP(ctx,owner_ctx,io,fmo,fi,start,length)\ |
| 86 | (grn_munmap((ctx), (owner_ctx), (io), (fmo), (fi), (start), (length))) |
| 87 | # define GRN_MSYNC(ctx,fh,start,length) \ |
| 88 | (grn_msync((ctx), (fh), (start), (length))) |
| 89 | #else /* WIN32 */ |
| 90 | inline static void * grn_mmapcxx . . $ grn_mmap(eae34eb82c337900).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_ctxcxx . . $ grn_ctx# *owner_ctx, |
| 91 | grn_iocxx . . $ grn_io# *io, fileinfocxx . . $ fileinfo# *fi, |
| 92 | off_tcxx . . $ off_t# offset, size_t length); |
| 93 | inline static int grn_munmapcxx . . $ grn_munmap(d6c6eff378d3be7).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_ctxcxx . . $ grn_ctx# *owner_ctx, |
| 94 | grn_iocxx . . $ grn_io# *io, fileinfocxx . . $ fileinfo# *fi, |
| 95 | void *start, size_t length); |
| 96 | inline static int grn_msynccxx . . $ grn_msync(7850c81bf663d613).(grn_ctxcxx . . $ grn_ctx# *ctx, void *start, size_t length); |
| 97 | # define GRN_MUNMAPcxx . . $ `storage/mroonga/vendor/groonga/lib/io.c:97:10`!(ctx,owner_ctx,io,fmo,fi,start,length) \ |
| 98 | (grn_munmap((ctx), (owner_ctx), (io), (fi), (start), (length))) |
| 99 | # define GRN_MSYNCcxx . . $ `storage/mroonga/vendor/groonga/lib/io.c:99:10`!(ctx,fh,start,length) \ |
| 100 | (grn_msync((ctx), (start), (length))) |
| 101 | # ifdef USE_FAIL_MALLOC |
| 102 | inline static void * grn_fail_mmap(grn_ctx *ctx, grn_ctx *owner_ctx, |
| 103 | grn_io *io, fileinfo *fi, |
| 104 | off_t offset, size_t length, |
| 105 | const char* file, int line, const char *func); |
| 106 | # define GRN_MMAP(ctx,owner_ctx,io,fmo,fi,offset,length)\ |
| 107 | (grn_fail_mmap((ctx), (owner_ctx), (io), (fi), (offset), (length),\ |
| 108 | __FILE__, __LINE__, __FUNCTION__)) |
| 109 | # else /* USE_FAIL_MALLOC */ |
| 110 | # define GRN_MMAPcxx . . $ `storage/mroonga/vendor/groonga/lib/io.c:110:11`!(ctx,owner_ctx,io,fmo,fi,offset,length)\ |
| 111 | (grn_mmap((ctx), (owner_ctx), (io), (fi), (offset), (length))) |
| 112 | # endif /* USE_FAIL_MALLOC */ |
| 113 | #endif /* WIN32 */ |
| 114 | inline static grn_rccxx . . $ grn_rc# grn_preadcxx . . $ grn_pread(4577714838bf4b55).(grn_ctxcxx . . $ grn_ctx# *ctx, fileinfocxx . . $ fileinfo# *fi, void *buf, |
| 115 | size_t count, off_tcxx . . $ off_t# offset); |
| 116 | inline static grn_rccxx . . $ grn_rc# grn_pwritecxx . . $ grn_pwrite(4577714838bf4b55).(grn_ctxcxx . . $ grn_ctx# *ctx, fileinfocxx . . $ fileinfo# *fi, void *buf, |
| 117 | size_t count, off_tcxx . . $ off_t# offset); |
| 118 | |
| 119 | void |
| 120 | grn_io_init_from_envcxx . . $ grn_io_init_from_env(49f6e7a06ebc5aa8).(void) |
| 121 | { |
| 122 | { |
| 123 | char version_env[GRN_ENV_BUFFER_SIZEcxx . . $ `storage/mroonga/vendor/groonga/include/groonga/portability.h:41:9`!]; |
| 124 | |
| 125 | grn_getenvcxx . . $ `storage/mroonga/vendor/groonga/include/groonga/portability.h:56:10`!("GRN_IO_VERSION", |
| 126 | version_env, |
| 127 | GRN_ENV_BUFFER_SIZEcxx . . $ `storage/mroonga/vendor/groonga/include/groonga/portability.h:41:9`!); |
| 128 | if (version_env[0]) { |
| 129 | grn_io_version_defaultcxx . . $ grn_io_version_default. = atoicxx . . $ atoi(5c4306d8553b3696).(version_env); |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | { |
| 134 | char use_sparse_env[GRN_ENV_BUFFER_SIZEcxx . . $ `storage/mroonga/vendor/groonga/include/groonga/portability.h:41:9`!]; |
| 135 | |
| 136 | grn_getenvcxx . . $ `storage/mroonga/vendor/groonga/include/groonga/portability.h:56:10`!("GRN_IO_USE_SPARSE", |
| 137 | use_sparse_env, |
| 138 | GRN_ENV_BUFFER_SIZEcxx . . $ `storage/mroonga/vendor/groonga/include/groonga/portability.h:41:9`!); |
| 139 | if (use_sparse_env[0] && strcmpcxx . . $ strcmp(5ae29d726ae57f88).(use_sparse_env, "yes") == 0) { |
| 140 | grn_io_use_sparsecxx . . $ grn_io_use_sparse. = GRN_TRUEcxx . . $ `storage/mroonga/vendor/groonga/include/groonga/groonga.h:44:9`!; |
| 141 | } |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | static inline uint32_tcxx . . $ uint32_t# |
| 146 | grn_io_compute_basecxx . . $ grn_io_compute_base(2141b656ce2cc063).(uint32_tcxx . . $ uint32_t# header_size) |
| 147 | { |
| 148 | uint32_tcxx . . $ uint32_t# total_header_size; |
| 149 | total_header_size = IO_HEADER_SIZEcxx . . $ `storage/mroonga/vendor/groonga/lib/io.c:64:9`! + header_size; |
| 150 | return (total_header_size + grn_pagesizecxx . . $ grn_pagesize. - 1) & ~(grn_pagesizecxx . . $ grn_pagesize. - 1); |
| 151 | } |
| 152 | |
| 153 | static inline uint32_tcxx . . $ uint32_t# |
| 154 | grn_io_compute_base_segmentcxx . . $ grn_io_compute_base_segment(83f10ac8959d5577).(uint32_tcxx . . $ uint32_t# base, uint32_tcxx . . $ uint32_t# segment_size) |
| 155 | { |
| 156 | return (base + segment_size - 1) / segment_size; |
| 157 | } |
| 158 | |
| 159 | static uint32_tcxx . . $ uint32_t# |
| 160 | grn_io_compute_max_n_filescxx . . $ grn_io_compute_max_n_files(6b98de4443a54ff8).(uint32_tcxx . . $ uint32_t# segment_size, uint32_tcxx . . $ uint32_t# max_segment, |
| 161 | unsigned int base_segument, unsigned long file_size) |
| 162 | { |
| 163 | uint64_tcxx . . $ uint64_t# last_segment_end; |
| 164 | last_segment_end = ((uint64_tcxx . . $ uint64_t#)segment_size) * (max_segment + base_segument); |
| 165 | return (uint32_tcxx . . $ uint32_t#)((last_segment_end + file_size - 1) / file_size); |
| 166 | } |
| 167 | |
| 168 | static inline unsigned long |
| 169 | grn_io_compute_file_sizecxx . . $ grn_io_compute_file_size(1892545c1754497d).(uint32_tcxx . . $ uint32_t# version) |
| 170 | { |
| 171 | if (version == 0) { |
| 172 | return GRN_IO_FILE_SIZE_V0cxx . . $ `storage/mroonga/vendor/groonga/lib/io.c:49:10`!; |
| 173 | } else { |
| 174 | return GRN_IO_FILE_SIZE_V1cxx . . $ `storage/mroonga/vendor/groonga/lib/io.c:44:9`!; |
| 175 | } |
| 176 | } |
| 177 | |
| 178 | static inline uint32_tcxx . . $ uint32_t# |
| 179 | grn_io_max_segmentcxx . . $ grn_io_max_segment(ee95b3f473df551b).(grn_iocxx . . $ grn_io# *io) |
| 180 | { |
| 181 | if (io->headercxx . . $ _grn_io#header.->segment_tailcxx . . $ _grn_io_header#segment_tail.) { |
| 182 | return io->headercxx . . $ _grn_io#header.->segment_tailcxx . . $ _grn_io_header#segment_tail.; |
| 183 | } else { |
| 184 | return io->headercxx . . $ _grn_io#header.->max_segmentcxx . . $ _grn_io_header#max_segment.; |
| 185 | } |
| 186 | } |
| 187 | |
| 188 | static uint32_tcxx . . $ uint32_t# |
| 189 | grn_io_max_n_filescxx . . $ grn_io_max_n_files(ee95b3f473df551b).(grn_iocxx . . $ grn_io# *io) |
| 190 | { |
| 191 | unsigned long file_size; |
| 192 | |
| 193 | file_size = grn_io_compute_file_sizecxx . . $ grn_io_compute_file_size(1892545c1754497d).(io->headercxx . . $ _grn_io#header.->versioncxx . . $ _grn_io_header#version.); |
| 194 | return grn_io_compute_max_n_filescxx . . $ grn_io_compute_max_n_files(6b98de4443a54ff8).(io->headercxx . . $ _grn_io#header.->segment_sizecxx . . $ _grn_io_header#segment_size., |
| 195 | grn_io_max_segmentcxx . . $ grn_io_max_segment(ee95b3f473df551b).(io), |
| 196 | io->base_segcxx . . $ _grn_io#base_seg., |
| 197 | file_size); |
| 198 | } |
| 199 | |
| 200 | static inline uint32_tcxx . . $ uint32_t# |
| 201 | grn_io_compute_nth_file_infocxx . . $ grn_io_compute_nth_file_info(edffd242529b3d8b).(grn_iocxx . . $ grn_io# *io, uint32_tcxx . . $ uint32_t# nth_segment) |
| 202 | { |
| 203 | uint32_tcxx . . $ uint32_t# segment_size; |
| 204 | unsigned long file_size; |
| 205 | uint32_tcxx . . $ uint32_t# segments_per_file; |
| 206 | uint32_tcxx . . $ uint32_t# resolved_nth_segment; |
| 207 | |
| 208 | segment_size = io->headercxx . . $ _grn_io#header.->segment_sizecxx . . $ _grn_io_header#segment_size.; |
| 209 | file_size = grn_io_compute_file_sizecxx . . $ grn_io_compute_file_size(1892545c1754497d).(io->headercxx . . $ _grn_io#header.->versioncxx . . $ _grn_io_header#version.); |
| 210 | segments_per_file = file_size / segment_size; |
| 211 | resolved_nth_segment = nth_segment + io->base_segcxx . . $ _grn_io#base_seg.; |
| 212 | return resolved_nth_segment / segments_per_file; |
| 213 | } |
| 214 | |
| 215 | static grn_iocxx . . $ grn_io# * |
| 216 | grn_io_create_tmpcxx . . $ grn_io_create_tmp(c3a908de4c247567).(grn_ctxcxx . . $ grn_ctx# *ctx, uint32_tcxx . . $ uint32_t# header_size, uint32_tcxx . . $ uint32_t# segment_size, |
| 217 | uint32_tcxx . . $ uint32_t# max_segment, grn_io_modecxx . . $ grn_io_mode# mode, uint32_tcxx . . $ uint32_t# flags) |
| 218 | { |
| 219 | grn_iocxx . . $ grn_io# *io; |
| 220 | uint32_tcxx . . $ uint32_t# b; |
| 221 | struct _grn_io_headercxx . . $ _grn_io_header# *header; |
| 222 | b = grn_io_compute_basecxx . . $ grn_io_compute_base(2141b656ce2cc063).(header_size); |
| 223 | header = (struct _grn_io_headercxx . . $ _grn_io_header# *)GRN_MMAPcxx . . $ `storage/mroonga/vendor/groonga/lib/io.c:110:11`!(ctx, &grn_gctx, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, NULL, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, |
| 224 | 0, b); |
| 225 | if (header) { |
| 226 | header->versioncxx . . $ _grn_io_header#version. = grn_io_version_defaultcxx . . $ grn_io_version_default.; |
| 227 | header->header_sizecxx . . $ _grn_io_header#header_size. = header_size; |
| 228 | header->segment_sizecxx . . $ _grn_io_header#segment_size. = segment_size; |
| 229 | header->max_segmentcxx . . $ _grn_io_header#max_segment. = max_segment; |
| 230 | header->n_arrayscxx . . $ _grn_io_header#n_arrays. = 0; |
| 231 | header->flagscxx . . $ _grn_io_header#flags. = flags; |
| 232 | header->lockcxx . . $ _grn_io_header#lock. = 0; |
| 233 | grn_memcpycxx . . $ `storage/mroonga/vendor/groonga/include/groonga/portability.h:31:11`!(header->idstr, GRN_IO_IDSTRcxx . . $ `storage/mroonga/vendor/groonga/lib/io.c:39:9`!, 16); |
| 234 | if ((io = GRN_MALLOCNcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_alloc.h:47:9`!(grn_io, 1))) { |
| 235 | grn_io_mapinfocxx . . $ grn_io_mapinfo# *maps = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 236 | if ((maps = GRN_CALLOCcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_alloc.h:39:9`!(sizeof(grn_io_mapinfo) * max_segment))) { |
| 237 | io->headercxx . . $ _grn_io#header. = header; |
| 238 | io->user_headercxx . . $ _grn_io#user_header. = (((bytecxx . . $ byte# *) header) + IO_HEADER_SIZEcxx . . $ `storage/mroonga/vendor/groonga/lib/io.c:64:9`!); |
| 239 | io->mapscxx . . $ _grn_io#maps. = maps; |
| 240 | io->basecxx . . $ _grn_io#base. = b; |
| 241 | io->base_segcxx . . $ _grn_io#base_seg. = 0; |
| 242 | io->modecxx . . $ _grn_io#mode. = mode; |
| 243 | io->headercxx . . $ _grn_io#header.->curr_sizecxx . . $ _grn_io_header#curr_size. = b; |
| 244 | io->fiscxx . . $ _grn_io#fis. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 245 | io->ainfocxx . . $ _grn_io#ainfo. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 246 | io->max_map_segcxx . . $ _grn_io#max_map_seg. = 0; |
| 247 | io->nmapscxx . . $ _grn_io#nmaps. = 0; |
| 248 | io->countcxx . . $ _grn_io#count. = 0; |
| 249 | io->flagscxx . . $ _grn_io#flags. = GRN_IO_TEMPORARYcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_io.h:160:9`!; |
| 250 | io->lockcxx . . $ _grn_io#lock. = &header->lockcxx . . $ _grn_io_header#lock.; |
| 251 | io->pathcxx . . $ _grn_io#path.[0] = '\0'; |
| 252 | return io; |
| 253 | } |
| 254 | GRN_FREEcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_alloc.h:46:9`!(io); |
| 255 | } |
| 256 | GRN_MUNMAPcxx . . $ `storage/mroonga/vendor/groonga/lib/io.c:97:10`!(ctx, &grn_gctx, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, NULL, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, header, b); |
| 257 | } |
| 258 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 259 | } |
| 260 | |
| 261 | static void |
| 262 | grn_io_registercxx . . $ grn_io_register(341fd28fcb683921).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_iocxx . . $ grn_io# *io) |
| 263 | { |
| 264 | if (io->fiscxx . . $ _grn_io#fis. && (io->flagscxx . . $ _grn_io#flags. & (GRN_IO_EXPIRE_GTICKcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_io.h:158:9`!|GRN_IO_EXPIRE_SEGMENTcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_io.h:159:9`!))) { |
| 265 | grn_boolcxx . . $ grn_bool# succeeded = GRN_FALSEcxx . . $ `storage/mroonga/vendor/groonga/include/groonga/groonga.h:45:9`!; |
| 266 | CRITICAL_SECTION_ENTERcxx . . $ `storage/mroonga/vendor/groonga/lib/grn.h:235:10`!(grn_glock); |
| 267 | if (grn_gctxcxx . . $ grn_gctx..implcxx . . $ _grn_ctx#impl. && grn_gctxcxx . . $ grn_gctx..implcxx . . $ _grn_ctx#impl.->ioscxx . . $ _grn_ctx_impl#ios. && |
| 268 | grn_hash_addcxx . . $ grn_hash_add(251a256fc515235e).(&grn_gctxcxx . . $ grn_gctx., grn_gctxcxx . . $ grn_gctx..implcxx . . $ _grn_ctx#impl.->ioscxx . . $ _grn_ctx_impl#ios., io->pathcxx . . $ _grn_io#path., strlencxx . . $ strlen(751346f8406fd082).(io->pathcxx . . $ _grn_io#path.), |
| 269 | (void **)&io, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)) { |
| 270 | succeeded = GRN_TRUEcxx . . $ `storage/mroonga/vendor/groonga/include/groonga/groonga.h:44:9`!; |
| 271 | } |
| 272 | CRITICAL_SECTION_LEAVEcxx . . $ `storage/mroonga/vendor/groonga/lib/grn.h:236:10`!(grn_glock); |
| 273 | if (!succeeded) { |
| 274 | GRN_LOGcxx . . $ `storage/mroonga/vendor/groonga/include/groonga/groonga.h:1112:9`!(ctx, GRN_LOG_WARNING, |
| 275 | "grn_io_register(%s) failed", io->path); |
| 276 | } |
| 277 | } |
| 278 | } |
| 279 | |
| 280 | static void |
| 281 | grn_io_unregistercxx . . $ grn_io_unregister(341fd28fcb683921).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_iocxx . . $ grn_io# *io) |
| 282 | { |
| 283 | if (io->fiscxx . . $ _grn_io#fis. && (io->flagscxx . . $ _grn_io#flags. & (GRN_IO_EXPIRE_GTICKcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_io.h:158:9`!|GRN_IO_EXPIRE_SEGMENTcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_io.h:159:9`!))) { |
| 284 | grn_boolcxx . . $ grn_bool# succeeded = GRN_FALSEcxx . . $ `storage/mroonga/vendor/groonga/include/groonga/groonga.h:45:9`!; |
| 285 | CRITICAL_SECTION_ENTERcxx . . $ `storage/mroonga/vendor/groonga/lib/grn.h:235:10`!(grn_glock); |
| 286 | if (grn_gctxcxx . . $ grn_gctx..implcxx . . $ _grn_ctx#impl. && grn_gctxcxx . . $ grn_gctx..implcxx . . $ _grn_ctx#impl.->ioscxx . . $ _grn_ctx_impl#ios.) { |
| 287 | grn_hash_deletecxx . . $ grn_hash_delete(c1719313595c9549).(&grn_gctxcxx . . $ grn_gctx., grn_gctxcxx . . $ grn_gctx..implcxx . . $ _grn_ctx#impl.->ioscxx . . $ _grn_ctx_impl#ios., |
| 288 | io->pathcxx . . $ _grn_io#path., strlencxx . . $ strlen(751346f8406fd082).(io->pathcxx . . $ _grn_io#path.), NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 289 | succeeded = GRN_TRUEcxx . . $ `storage/mroonga/vendor/groonga/include/groonga/groonga.h:44:9`!; |
| 290 | } |
| 291 | CRITICAL_SECTION_LEAVEcxx . . $ `storage/mroonga/vendor/groonga/lib/grn.h:236:10`!(grn_glock); |
| 292 | if (!succeeded) { |
| 293 | GRN_LOGcxx . . $ `storage/mroonga/vendor/groonga/include/groonga/groonga.h:1112:9`!(ctx, GRN_LOG_WARNING, |
| 294 | "grn_io_unregister(%s) failed", io->path); |
| 295 | } |
| 296 | } |
| 297 | } |
| 298 | |
| 299 | grn_iocxx . . $ grn_io# * |
| 300 | grn_io_createcxx . . $ grn_io_create(d9bf0f53c110ad98).(grn_ctxcxx . . $ grn_ctx# *ctx, const char *path, uint32_tcxx . . $ uint32_t# header_size, |
| 301 | uint32_tcxx . . $ uint32_t# segment_size, uint32_tcxx . . $ uint32_t# max_segment, grn_io_modecxx . . $ grn_io_mode# mode, |
| 302 | uint32_tcxx . . $ uint32_t# flags) |
| 303 | { |
| 304 | grn_iocxx . . $ grn_io# *io; |
| 305 | fileinfocxx . . $ fileinfo# *fis; |
| 306 | uint32_tcxx . . $ uint32_t# b, max_nfiles; |
| 307 | uint32_tcxx . . $ uint32_t# bs; |
| 308 | struct _grn_io_headercxx . . $ _grn_io_header# *header; |
| 309 | uint32_tcxx . . $ uint32_t# version = grn_io_version_defaultcxx . . $ grn_io_version_default.; |
| 310 | unsigned long file_size; |
| 311 | |
| 312 | if (!path) { |
| 313 | return grn_io_create_tmpcxx . . $ grn_io_create_tmp(c3a908de4c247567).(ctx, header_size, segment_size, max_segment, |
| 314 | mode, flags); |
| 315 | } |
| 316 | if (!*path || (strlencxx . . $ strlen(751346f8406fd082).(path) > PATH_MAXcxx . . $ `<external>/6347054901304145714/limits.h:13:9`! - 4)) { return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; } |
| 317 | b = grn_io_compute_basecxx . . $ grn_io_compute_base(2141b656ce2cc063).(header_size); |
| 318 | bs = grn_io_compute_base_segmentcxx . . $ grn_io_compute_base_segment(83f10ac8959d5577).(b, segment_size); |
| 319 | file_size = grn_io_compute_file_sizecxx . . $ grn_io_compute_file_size(1892545c1754497d).(version); |
| 320 | max_nfiles = grn_io_compute_max_n_filescxx . . $ grn_io_compute_max_n_files(6b98de4443a54ff8).(segment_size, max_segment, |
| 321 | bs, file_size); |
| 322 | if ((fis = GRN_MALLOCNcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_alloc.h:47:9`!(fileinfo, max_nfiles))) { |
| 323 | grn_fileinfo_initcxx . . $ grn_fileinfo_init(f06d8a745bb74b52).(fis, max_nfiles); |
| 324 | if (!grn_fileinfo_opencxx . . $ grn_fileinfo_open(ac8f5bf2db69e073).(ctx, fis, path, O_RDWRcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:45:9`!|O_CREATcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:47:10`!|O_EXCLcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:50:10`!)) { |
| 325 | header = (struct _grn_io_headercxx . . $ _grn_io_header# *)GRN_MMAPcxx . . $ `storage/mroonga/vendor/groonga/lib/io.c:110:11`!(ctx, &grn_gctx, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, |
| 326 | &fis->fmo, fis, 0, b); |
| 327 | if (header) { |
| 328 | header->versioncxx . . $ _grn_io_header#version. = version; |
| 329 | header->header_sizecxx . . $ _grn_io_header#header_size. = header_size; |
| 330 | header->segment_sizecxx . . $ _grn_io_header#segment_size. = segment_size; |
| 331 | header->max_segmentcxx . . $ _grn_io_header#max_segment. = max_segment; |
| 332 | header->n_arrayscxx . . $ _grn_io_header#n_arrays. = 0; |
| 333 | header->flagscxx . . $ _grn_io_header#flags. = flags; |
| 334 | header->lockcxx . . $ _grn_io_header#lock. = 0; |
| 335 | grn_memcpycxx . . $ `storage/mroonga/vendor/groonga/include/groonga/portability.h:31:11`!(header->idstr, GRN_IO_IDSTRcxx . . $ `storage/mroonga/vendor/groonga/lib/io.c:39:9`!, 16); |
| 336 | GRN_MSYNCcxx . . $ `storage/mroonga/vendor/groonga/lib/io.c:99:10`!(ctx, fis[0].fh, header, b); |
| 337 | if ((io = GRN_MALLOCNcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_alloc.h:47:9`!(grn_io, 1))) { |
| 338 | grn_io_mapinfocxx . . $ grn_io_mapinfo# *maps = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 339 | if ((maps = GRN_CALLOCcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_alloc.h:39:9`!(sizeof(grn_io_mapinfo) * max_segment))) { |
| 340 | grn_strncpycxx . . $ `storage/mroonga/vendor/groonga/include/groonga/portability.h:108:10`!(io->path, PATH_MAX-1, path, PATH_MAXcxx . . $ `<external>/6347054901304145714/limits.h:13:9`!-1); |
| 341 | io->headercxx . . $ _grn_io#header. = header; |
| 342 | io->user_headercxx . . $ _grn_io#user_header. = (((bytecxx . . $ byte# *) header) + IO_HEADER_SIZEcxx . . $ `storage/mroonga/vendor/groonga/lib/io.c:64:9`!); |
| 343 | io->mapscxx . . $ _grn_io#maps. = maps; |
| 344 | io->basecxx . . $ _grn_io#base. = b; |
| 345 | io->base_segcxx . . $ _grn_io#base_seg. = bs; |
| 346 | io->modecxx . . $ _grn_io#mode. = mode; |
| 347 | io->headercxx . . $ _grn_io#header.->curr_sizecxx . . $ _grn_io_header#curr_size. = b; |
| 348 | io->fiscxx . . $ _grn_io#fis. = fis; |
| 349 | io->ainfocxx . . $ _grn_io#ainfo. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 350 | io->max_map_segcxx . . $ _grn_io#max_map_seg. = 0; |
| 351 | io->nmapscxx . . $ _grn_io#nmaps. = 0; |
| 352 | io->countcxx . . $ _grn_io#count. = 0; |
| 353 | io->flagscxx . . $ _grn_io#flags. = flags; |
| 354 | io->lockcxx . . $ _grn_io#lock. = &header->lockcxx . . $ _grn_io_header#lock.; |
| 355 | grn_io_registercxx . . $ grn_io_register(341fd28fcb683921).(ctx, io); |
| 356 | return io; |
| 357 | } |
| 358 | GRN_FREEcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_alloc.h:46:9`!(io); |
| 359 | } |
| 360 | GRN_MUNMAPcxx . . $ `storage/mroonga/vendor/groonga/lib/io.c:97:10`!(ctx, &grn_gctx, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, &fis->fmo, fis, header, b); |
| 361 | } |
| 362 | grn_fileinfo_closecxx . . $ grn_fileinfo_close(91b895c7c0cdf7c3).(ctx, fis); |
| 363 | if (grn_unlinkcxx . . $ `storage/mroonga/vendor/groonga/include/groonga/portability.h:85:10`!(path) == 0) { |
| 364 | GRN_LOGcxx . . $ `storage/mroonga/vendor/groonga/include/groonga/groonga.h:1112:9`!(ctx, GRN_LOG_INFO, |
| 365 | "[io][create][error] removed path: <%s>", path); |
| 366 | } else { |
| 367 | ERRNO_ERRcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_ctx.h:403:9`!("[io][create][error] failed to remove path: <%s>", path); |
| 368 | } |
| 369 | } |
| 370 | GRN_FREEcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_alloc.h:46:9`!(fis); |
| 371 | } |
| 372 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 373 | } |
| 374 | |
| 375 | static grn_rccxx . . $ grn_rc# |
| 376 | array_init_cxx . . $ array_init_(22efe90f3085c19).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_iocxx . . $ grn_io# *io, int n_arrays, size_t hsize, size_t msize) |
| 377 | { |
| 378 | int i; |
| 379 | uint32_tcxx . . $ uint32_t# ws; |
| 380 | bytecxx . . $ byte# *hp, *mp; |
| 381 | grn_io_array_speccxx . . $ grn_io_array_spec# *array_specs = (grn_io_array_speccxx . . $ grn_io_array_spec# *)io->user_headercxx . . $ _grn_io#user_header.; |
| 382 | hp = io->user_headercxx . . $ _grn_io#user_header.; |
| 383 | if (!(mp = GRN_CALLOCcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_alloc.h:39:9`!(msize))) { |
| 384 | return GRN_NO_MEMORY_AVAILABLEcxx . . $ GRN_NO_MEMORY_AVAILABLE.; |
| 385 | } |
| 386 | io->ainfocxx . . $ _grn_io#ainfo. = (grn_io_array_infocxx . . $ grn_io_array_info# *)mp; |
| 387 | hp += sizeof(grn_io_array_speccxx . . $ grn_io_array_spec#) * n_arrays; |
| 388 | mp += sizeof(grn_io_array_infocxx . . $ grn_io_array_info#) * n_arrays; |
| 389 | for (ws = 0; (1 << ws) < io->headercxx . . $ _grn_io#header.->segment_sizecxx . . $ _grn_io_header#segment_size.; ws++); |
| 390 | for (i = 0; i < n_arrays; i++) { |
| 391 | uint32_tcxx . . $ uint32_t# we = ws - array_specs[i].w_of_elementcxx . . $ _grn_io_array_spec#w_of_element.; |
| 392 | io->ainfocxx . . $ _grn_io#ainfo.[i].w_of_elm_in_a_segmentcxx . . $ _grn_io_array_info#w_of_elm_in_a_segment. = we; |
| 393 | io->ainfocxx . . $ _grn_io#ainfo.[i].elm_mask_in_a_segmentcxx . . $ _grn_io_array_info#elm_mask_in_a_segment. = (1 << we) - 1; |
| 394 | io->ainfocxx . . $ _grn_io#ainfo.[i].max_n_segmentscxx . . $ _grn_io_array_info#max_n_segments. = array_specs[i].max_n_segmentscxx . . $ _grn_io_array_spec#max_n_segments.; |
| 395 | io->ainfocxx . . $ _grn_io#ainfo.[i].element_sizecxx . . $ _grn_io_array_info#element_size. = 1 << array_specs[i].w_of_elementcxx . . $ _grn_io_array_spec#w_of_element.; |
| 396 | io->ainfocxx . . $ _grn_io#ainfo.[i].segmentscxx . . $ _grn_io_array_info#segments. = (uint32_tcxx . . $ uint32_t# *)hp; |
| 397 | io->ainfocxx . . $ _grn_io#ainfo.[i].addrscxx . . $ _grn_io_array_info#addrs. = (void **)mp; |
| 398 | hp += sizeof(uint32_tcxx . . $ uint32_t#) * array_specs[i].max_n_segmentscxx . . $ _grn_io_array_spec#max_n_segments.; |
| 399 | mp += sizeof(void *) * array_specs[i].max_n_segmentscxx . . $ _grn_io_array_spec#max_n_segments.; |
| 400 | } |
| 401 | io->user_headercxx . . $ _grn_io#user_header. += hsize; |
| 402 | return GRN_SUCCESScxx . . $ GRN_SUCCESS.; |
| 403 | } |
| 404 | |
| 405 | static grn_rccxx . . $ grn_rc# |
| 406 | array_initcxx . . $ array_init(2c16bfdb6acf067b).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_iocxx . . $ grn_io# *io, int n_arrays) |
| 407 | { |
| 408 | if (n_arrays) { |
| 409 | int i; |
| 410 | grn_io_array_speccxx . . $ grn_io_array_spec# *array_specs = (grn_io_array_speccxx . . $ grn_io_array_spec# *)io->user_headercxx . . $ _grn_io#user_header.; |
| 411 | size_t hsize = sizeof(grn_io_array_speccxx . . $ grn_io_array_spec#) * n_arrays; |
| 412 | size_t msize = sizeof(grn_io_array_infocxx . . $ grn_io_array_info#) * n_arrays; |
| 413 | for (i = 0; i < n_arrays; i++) { |
| 414 | hsize += sizeof(uint32_tcxx . . $ uint32_t#) * array_specs[i].max_n_segmentscxx . . $ _grn_io_array_spec#max_n_segments.; |
| 415 | msize += sizeof(void *) * array_specs[i].max_n_segmentscxx . . $ _grn_io_array_spec#max_n_segments.; |
| 416 | } |
| 417 | return array_init_cxx . . $ array_init_(22efe90f3085c19).(ctx, io, n_arrays, hsize, msize); |
| 418 | } |
| 419 | return GRN_SUCCESScxx . . $ GRN_SUCCESS.; |
| 420 | } |
| 421 | |
| 422 | grn_iocxx . . $ grn_io# * |
| 423 | grn_io_create_with_arraycxx . . $ grn_io_create_with_array(878445e8291bbc58).(grn_ctxcxx . . $ grn_ctx# *ctx, const char *path, |
| 424 | uint32_tcxx . . $ uint32_t# header_size, uint32_tcxx . . $ uint32_t# segment_size, |
| 425 | grn_io_modecxx . . $ grn_io_mode# mode, int n_arrays, |
| 426 | grn_io_array_speccxx . . $ grn_io_array_spec# *array_specs) |
| 427 | { |
| 428 | if (n_arrays) { |
| 429 | int i; |
| 430 | grn_iocxx . . $ grn_io# *io; |
| 431 | bytecxx . . $ byte# *hp; |
| 432 | uint32_tcxx . . $ uint32_t# nsegs = 0; |
| 433 | size_t hsize = sizeof(grn_io_array_speccxx . . $ grn_io_array_spec#) * n_arrays; |
| 434 | size_t msize = sizeof(grn_io_array_infocxx . . $ grn_io_array_info#) * n_arrays; |
| 435 | for (i = 0; i < n_arrays; i++) { |
| 436 | nsegs += array_specs[i].max_n_segmentscxx . . $ _grn_io_array_spec#max_n_segments.; |
| 437 | hsize += sizeof(uint32_tcxx . . $ uint32_t#) * array_specs[i].max_n_segmentscxx . . $ _grn_io_array_spec#max_n_segments.; |
| 438 | msize += sizeof(void *) * array_specs[i].max_n_segmentscxx . . $ _grn_io_array_spec#max_n_segments.; |
| 439 | } |
| 440 | if ((io = grn_io_createcxx . . $ grn_io_create(d9bf0f53c110ad98).(ctx, path, header_size + hsize, |
| 441 | segment_size, nsegs, mode, GRN_IO_EXPIRE_GTICKcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_io.h:158:9`!))) { |
| 442 | grn_rccxx . . $ grn_rc# rc; |
| 443 | hp = io->user_headercxx . . $ _grn_io#user_header.; |
| 444 | grn_memcpycxx . . $ `storage/mroonga/vendor/groonga/include/groonga/portability.h:31:11`!(hp, array_specs, sizeof(grn_io_array_spec) * n_arrays); |
| 445 | io->headercxx . . $ _grn_io#header.->n_arrayscxx . . $ _grn_io_header#n_arrays. = n_arrays; |
| 446 | io->headercxx . . $ _grn_io#header.->segment_tailcxx . . $ _grn_io_header#segment_tail. = 1; |
| 447 | rc = array_init_cxx . . $ array_init_(22efe90f3085c19).(ctx, io, n_arrays, hsize, msize); |
| 448 | if (rc == GRN_SUCCESScxx . . $ GRN_SUCCESS.) { |
| 449 | return io; |
| 450 | } |
| 451 | ERRcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_ctx.h:143:9`!(GRN_NO_MEMORY_AVAILABLE, "grn_io_create_with_array failed"); |
| 452 | grn_io_closecxx . . $ grn_io_close(117c07c672382ce3).(ctx, io); |
| 453 | } |
| 454 | } |
| 455 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 456 | } |
| 457 | |
| 458 | inline static uint32_tcxx . . $ uint32_t# |
| 459 | segment_alloccxx . . $ segment_alloc(7752bae3ff5e951e).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_iocxx . . $ grn_io# *io) |
| 460 | { |
| 461 | uint32_tcxx . . $ uint32_t# n, s; |
| 462 | grn_io_array_infocxx . . $ grn_io_array_info# *ai; |
| 463 | if (io->headercxx . . $ _grn_io#header.->segment_tailcxx . . $ _grn_io_header#segment_tail.) { |
| 464 | if (io->headercxx . . $ _grn_io#header.->segment_tailcxx . . $ _grn_io_header#segment_tail. > io->headercxx . . $ _grn_io#header.->max_segmentcxx . . $ _grn_io_header#max_segment.) { |
| 465 | s = 0; |
| 466 | } else { |
| 467 | s = io->headercxx . . $ _grn_io#header.->segment_tailcxx . . $ _grn_io_header#segment_tail.++; |
| 468 | } |
| 469 | } else { |
| 470 | char *used = GRN_CALLOCcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_alloc.h:39:9`!(io->header->max_segment + 1); |
| 471 | if (!used) { return 0; } |
| 472 | for (n = io->headercxx . . $ _grn_io#header.->n_arrayscxx . . $ _grn_io_header#n_arrays., ai = io->ainfocxx . . $ _grn_io#ainfo.; n; n--, ai++) { |
| 473 | for (s = 0; s < ai->max_n_segmentscxx . . $ _grn_io_array_info#max_n_segments.; s++) { |
| 474 | used[ai->segmentscxx . . $ _grn_io_array_info#segments.[s]] = 1; |
| 475 | } |
| 476 | } |
| 477 | for (s = 1; ; s++) { |
| 478 | if (s > io->headercxx . . $ _grn_io#header.->max_segmentcxx . . $ _grn_io_header#max_segment.) { |
| 479 | io->headercxx . . $ _grn_io#header.->segment_tailcxx . . $ _grn_io_header#segment_tail. = s; |
| 480 | s = 0; |
| 481 | break; |
| 482 | } |
| 483 | if (!used[s]) { |
| 484 | io->headercxx . . $ _grn_io#header.->segment_tailcxx . . $ _grn_io_header#segment_tail. = s + 1; |
| 485 | break; |
| 486 | } |
| 487 | } |
| 488 | GRN_FREEcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_alloc.h:46:9`!(used); |
| 489 | } |
| 490 | return s; |
| 491 | } |
| 492 | |
| 493 | void |
| 494 | grn_io_segment_alloccxx . . $ grn_io_segment_alloc(334338f53ffa5aeb).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_iocxx . . $ grn_io# *io, grn_io_array_infocxx . . $ grn_io_array_info# *ai, |
| 495 | uint32_tcxx . . $ uint32_t# lseg, int *flags, void **p) |
| 496 | { |
| 497 | uint32_tcxx . . $ uint32_t# *sp = &ai->segmentscxx . . $ _grn_io_array_info#segments.[lseg]; |
| 498 | if (!*sp) { |
| 499 | if ((*flags & GRN_TABLE_ADDcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_io.h:152:9`!)) { |
| 500 | if ((*sp = segment_alloccxx . . $ segment_alloc(7752bae3ff5e951e).(ctx, io))) { |
| 501 | *flags |= GRN_TABLE_ADDEDcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_io.h:153:9`!; |
| 502 | } |
| 503 | } |
| 504 | } |
| 505 | if (*sp) { |
| 506 | uint32_tcxx . . $ uint32_t# pseg = *sp - 1; |
| 507 | GRN_IO_SEG_REFcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_io.h:169:9`!(io, pseg, *p); |
| 508 | if (*p) { GRN_IO_SEG_UNREFcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_io.h:276:9`!(io, pseg); }; |
| 509 | } |
| 510 | } |
| 511 | |
| 512 | void * |
| 513 | grn_io_array_atcxx . . $ grn_io_array_at(f5c59b3d5bdcec2b).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_iocxx . . $ grn_io# *io, uint32_tcxx . . $ uint32_t# array, off_tcxx . . $ off_t# offset, int *flags) |
| 514 | { |
| 515 | void *res; |
| 516 | GRN_IO_ARRAY_ATcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_io.h:319:9`!(io,array,offset,flags,res); |
| 517 | return res; |
| 518 | } |
| 519 | |
| 520 | uint32_tcxx . . $ uint32_t# |
| 521 | grn_io_detect_typecxx . . $ grn_io_detect_type(1be90328514dd2c4).(grn_ctxcxx . . $ grn_ctx# *ctx, const char *path) |
| 522 | { |
| 523 | struct _grn_io_headercxx . . $ _grn_io_header# h; |
| 524 | uint32_tcxx . . $ uint32_t# res = 0; |
| 525 | int fd; |
| 526 | grn_opencxx . . $ `storage/mroonga/vendor/groonga/include/groonga/portability.h:175:10`!(fd, path, O_RDONLYcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:43:9`! | GRN_OPEN_FLAG_BINARYcxx . . $ `storage/mroonga/vendor/groonga/include/groonga/portability.h:174:10`!); |
| 527 | if (fd != -1) { |
| 528 | struct statcxx . . $ stat# s; |
| 529 | if (fstatcxx . . $ fstat(a43660ce2f600cb5).(fd, &s) != -1 && (size_t) s.st_sizecxx . . $ stat#st_size. >= sizeof(struct _grn_io_headercxx . . $ _grn_io_header#)) { |
| 530 | if (grn_readcxx . . $ `storage/mroonga/vendor/groonga/include/groonga/portability.h:164:10`!(fd, &h, sizeof(struct _grn_io_header)) == |
| 531 | sizeof(struct _grn_io_headercxx . . $ _grn_io_header#)) { |
| 532 | if (!memcmpcxx . . $ memcmp(36f949851efa3055).(h.idstrcxx . . $ _grn_io_header#idstr., GRN_IO_IDSTRcxx . . $ `storage/mroonga/vendor/groonga/lib/io.c:39:9`!, GRN_IO_IDSTR_LENcxx . . $ `storage/mroonga/vendor/groonga/lib/io.c:40:9`!)) { |
| 533 | res = h.typecxx . . $ _grn_io_header#type.; |
| 534 | } else { |
| 535 | ERRcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_ctx.h:143:9`!(GRN_INCOMPATIBLE_FILE_FORMAT, |
| 536 | "failed to detect type: format ID is different: <%s>: <%.*s>", |
| 537 | path, |
| 538 | (int)GRN_IO_IDSTR_LENcxx . . $ `storage/mroonga/vendor/groonga/lib/io.c:40:9`!, GRN_IO_IDSTRcxx . . $ `storage/mroonga/vendor/groonga/lib/io.c:39:9`!); |
| 539 | } |
| 540 | } else { |
| 541 | SERRcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_ctx.h:332:9`!("failed to read enough data for detecting type: <%s>", |
| 542 | path); |
| 543 | } |
| 544 | } else { |
| 545 | ERRcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_ctx.h:143:9`!(GRN_INVALID_FORMAT, "grn_io_detect_type failed"); |
| 546 | } |
| 547 | grn_closecxx . . $ `storage/mroonga/vendor/groonga/include/groonga/portability.h:182:10`!(fd); |
| 548 | } else { |
| 549 | ERRNO_ERRcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_ctx.h:403:9`!("failed to open path for detecting type: <%s>", |
| 550 | path); |
| 551 | } |
| 552 | return res; |
| 553 | } |
| 554 | |
| 555 | grn_iocxx . . $ grn_io# * |
| 556 | grn_io_opencxx . . $ grn_io_open(f25995ba89d9e599).(grn_ctxcxx . . $ grn_ctx# *ctx, const char *path, grn_io_modecxx . . $ grn_io_mode# mode) |
| 557 | { |
| 558 | size_t max_path_len = PATH_MAXcxx . . $ `<external>/6347054901304145714/limits.h:13:9`! - 4; |
| 559 | grn_iocxx . . $ grn_io# *io; |
| 560 | struct statcxx . . $ stat# s; |
| 561 | fileinfocxx . . $ fileinfo# fi; |
| 562 | uint32_tcxx . . $ uint32_t# b; |
| 563 | uint32_tcxx . . $ uint32_t# header_size = 0, segment_size = 0, max_segment = 0, bs; |
| 564 | if (!path || !*path) { |
| 565 | ERRcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_ctx.h:143:9`!(GRN_INVALID_ARGUMENT, "[io][open] path is missing"); |
| 566 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 567 | } |
| 568 | if ((strlencxx . . $ strlen(751346f8406fd082).(path) > max_path_len)) { |
| 569 | int truncate_length = 10; |
| 570 | ERRcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_ctx.h:143:9`!(GRN_INVALID_ARGUMENT, |
| 571 | "[io][open] path is too long: " |
| 572 | "<%" GRN_FMT_SIZEcxx . . $ `storage/mroonga/vendor/groonga/lib/grn.h:473:10`! ">(max: %" GRN_FMT_SIZEcxx . . $ `storage/mroonga/vendor/groonga/lib/grn.h:473:10`! "): <%.*s...>", |
| 573 | strlen(path), |
| 574 | max_path_len, |
| 575 | truncate_length, |
| 576 | path); |
| 577 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 578 | } |
| 579 | { |
| 580 | struct _grn_io_headercxx . . $ _grn_io_header# h; |
| 581 | int fd; |
| 582 | ssize_tcxx . . $ ssize_t# read_bytes; |
| 583 | grn_opencxx . . $ `storage/mroonga/vendor/groonga/include/groonga/portability.h:175:10`!(fd, path, O_RDWRcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:45:9`! | GRN_OPEN_FLAG_BINARYcxx . . $ `storage/mroonga/vendor/groonga/include/groonga/portability.h:174:10`!); |
| 584 | if (fd == -1) { |
| 585 | ERRNO_ERRcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_ctx.h:403:9`!("failed to open path: <%s>", |
| 586 | path); |
| 587 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 588 | } |
| 589 | if (fstatcxx . . $ fstat(a43660ce2f600cb5).(fd, &s) == -1) { |
| 590 | ERRNO_ERRcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_ctx.h:403:9`!("[io][open] failed to file status: <%s>", |
| 591 | path); |
| 592 | grn_closecxx . . $ `storage/mroonga/vendor/groonga/include/groonga/portability.h:182:10`!(fd); |
| 593 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 594 | } |
| 595 | if ((size_t) s.st_sizecxx . . $ stat#st_size. < sizeof(struct _grn_io_headercxx . . $ _grn_io_header#)) { |
| 596 | ERRcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_ctx.h:143:9`!(GRN_INCOMPATIBLE_FILE_FORMAT, |
| 597 | "[io][open] file size is too small: " |
| 598 | "<%" GRN_FMT_INT64Dcxx . . $ `storage/mroonga/vendor/groonga/lib/grn.h:436:10`! ">(required: >= %" GRN_FMT_SIZEcxx . . $ `storage/mroonga/vendor/groonga/lib/grn.h:473:10`! "): <%s>", |
| 599 | (int64_t)(s.st_size), |
| 600 | sizeof(struct _grn_io_header), |
| 601 | path); |
| 602 | grn_closecxx . . $ `storage/mroonga/vendor/groonga/include/groonga/portability.h:182:10`!(fd); |
| 603 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 604 | } |
| 605 | read_bytes = grn_readcxx . . $ `storage/mroonga/vendor/groonga/include/groonga/portability.h:164:10`!(fd, &h, sizeof(struct _grn_io_header)); |
| 606 | if (read_bytes != sizeof(struct _grn_io_headercxx . . $ _grn_io_header#)) { |
| 607 | ERRNO_ERRcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_ctx.h:403:9`!("[io][open] failed to read header data: " |
| 608 | "<%" GRN_FMT_SSIZEcxx . . $ `storage/mroonga/vendor/groonga/lib/grn.h:474:10`! ">(expected: %" GRN_FMT_SSIZEcxx . . $ `storage/mroonga/vendor/groonga/lib/grn.h:474:10`! "): <%s>", |
| 609 | read_bytes, |
| 610 | sizeof(struct _grn_io_header), |
| 611 | path); |
| 612 | grn_closecxx . . $ `storage/mroonga/vendor/groonga/include/groonga/portability.h:182:10`!(fd); |
| 613 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 614 | } |
| 615 | if (memcmpcxx . . $ memcmp(36f949851efa3055).(h.idstrcxx . . $ _grn_io_header#idstr., GRN_IO_IDSTRcxx . . $ `storage/mroonga/vendor/groonga/lib/io.c:39:9`!, GRN_IO_IDSTR_LENcxx . . $ `storage/mroonga/vendor/groonga/lib/io.c:40:9`!) != 0) { |
| 616 | ERRcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_ctx.h:143:9`!(GRN_INCOMPATIBLE_FILE_FORMAT, |
| 617 | "failed to open: format ID is different: <%s>: <%.*s>", |
| 618 | path, |
| 619 | (int)GRN_IO_IDSTR_LENcxx . . $ `storage/mroonga/vendor/groonga/lib/io.c:40:9`!, GRN_IO_IDSTRcxx . . $ `storage/mroonga/vendor/groonga/lib/io.c:39:9`!); |
| 620 | grn_closecxx . . $ `storage/mroonga/vendor/groonga/include/groonga/portability.h:182:10`!(fd); |
| 621 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 622 | } |
| 623 | header_size = h.header_sizecxx . . $ _grn_io_header#header_size.; |
| 624 | segment_size = h.segment_sizecxx . . $ _grn_io_header#segment_size.; |
| 625 | max_segment = h.max_segmentcxx . . $ _grn_io_header#max_segment.; |
| 626 | grn_closecxx . . $ `storage/mroonga/vendor/groonga/include/groonga/portability.h:182:10`!(fd); |
| 627 | if (segment_size == 0) { |
| 628 | ERRcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_ctx.h:143:9`!(GRN_INCOMPATIBLE_FILE_FORMAT, "failed to open: segment size is 0"); |
| 629 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 630 | } |
| 631 | } |
| 632 | b = grn_io_compute_basecxx . . $ grn_io_compute_base(2141b656ce2cc063).(header_size); |
| 633 | bs = grn_io_compute_base_segmentcxx . . $ grn_io_compute_base_segment(83f10ac8959d5577).(b, segment_size); |
| 634 | grn_fileinfo_initcxx . . $ grn_fileinfo_init(f06d8a745bb74b52).(&fi, 1); |
| 635 | if (!grn_fileinfo_opencxx . . $ grn_fileinfo_open(ac8f5bf2db69e073).(ctx, &fi, path, O_RDWRcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:45:9`!)) { |
| 636 | struct _grn_io_headercxx . . $ _grn_io_header# *header; |
| 637 | header = GRN_MMAPcxx . . $ `storage/mroonga/vendor/groonga/lib/io.c:110:11`!(ctx, &grn_gctx, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, &(fi.fmo), &fi, 0, b); |
| 638 | if (header) { |
| 639 | unsigned long file_size; |
| 640 | unsigned int max_nfiles; |
| 641 | fileinfocxx . . $ fileinfo# *fis; |
| 642 | |
| 643 | file_size = grn_io_compute_file_sizecxx . . $ grn_io_compute_file_size(1892545c1754497d).(header->versioncxx . . $ _grn_io_header#version.); |
| 644 | max_nfiles = grn_io_compute_max_n_filescxx . . $ grn_io_compute_max_n_files(6b98de4443a54ff8).(segment_size, max_segment, |
| 645 | bs, file_size); |
| 646 | fis = GRN_MALLOCNcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_alloc.h:47:9`!(fileinfo, max_nfiles); |
| 647 | if (!fis) { |
| 648 | GRN_MUNMAPcxx . . $ `storage/mroonga/vendor/groonga/lib/io.c:97:10`!(ctx, &grn_gctx, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, &(fi.fmo), &fi, header, b); |
| 649 | grn_fileinfo_closecxx . . $ grn_fileinfo_close(91b895c7c0cdf7c3).(ctx, &fi); |
| 650 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 651 | } |
| 652 | grn_fileinfo_initcxx . . $ grn_fileinfo_init(f06d8a745bb74b52).(fis, max_nfiles); |
| 653 | grn_memcpycxx . . $ `storage/mroonga/vendor/groonga/include/groonga/portability.h:31:11`!(fis, &fi, sizeof(fileinfo)); |
| 654 | if ((io = GRN_MALLOCcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_alloc.h:38:9`!(sizeof(grn_io)))) { |
| 655 | grn_io_mapinfocxx . . $ grn_io_mapinfo# *maps = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 656 | if ((maps = GRN_CALLOCcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_alloc.h:39:9`!(sizeof(grn_io_mapinfo) * max_segment))) { |
| 657 | grn_strncpycxx . . $ `storage/mroonga/vendor/groonga/include/groonga/portability.h:108:10`!(io->path, PATH_MAX-1, path, PATH_MAXcxx . . $ `<external>/6347054901304145714/limits.h:13:9`!-1); |
| 658 | io->headercxx . . $ _grn_io#header. = header; |
| 659 | io->user_headercxx . . $ _grn_io#user_header. = (((bytecxx . . $ byte# *) header) + IO_HEADER_SIZEcxx . . $ `storage/mroonga/vendor/groonga/lib/io.c:64:9`!); |
| 660 | { |
| 661 | io->mapscxx . . $ _grn_io#maps. = maps; |
| 662 | io->basecxx . . $ _grn_io#base. = b; |
| 663 | io->base_segcxx . . $ _grn_io#base_seg. = bs; |
| 664 | io->modecxx . . $ _grn_io#mode. = mode; |
| 665 | io->fiscxx . . $ _grn_io#fis. = fis; |
| 666 | io->ainfocxx . . $ _grn_io#ainfo. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 667 | io->max_map_segcxx . . $ _grn_io#max_map_seg. = 0; |
| 668 | io->nmapscxx . . $ _grn_io#nmaps. = 0; |
| 669 | io->countcxx . . $ _grn_io#count. = 0; |
| 670 | io->flagscxx . . $ _grn_io#flags. = header->flagscxx . . $ _grn_io_header#flags.; |
| 671 | io->lockcxx . . $ _grn_io#lock. = &header->lockcxx . . $ _grn_io_header#lock.; |
| 672 | if (!array_initcxx . . $ array_init(2c16bfdb6acf067b).(ctx, io, io->headercxx . . $ _grn_io#header.->n_arrayscxx . . $ _grn_io_header#n_arrays.)) { |
| 673 | grn_io_registercxx . . $ grn_io_register(341fd28fcb683921).(ctx, io); |
| 674 | return io; |
| 675 | } |
| 676 | } |
| 677 | if (io->mapscxx . . $ _grn_io#maps.) { GRN_FREEcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_alloc.h:46:9`!(io->maps); } |
| 678 | } |
| 679 | GRN_FREEcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_alloc.h:46:9`!(io); |
| 680 | } |
| 681 | GRN_FREEcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_alloc.h:46:9`!(fis); |
| 682 | GRN_MUNMAPcxx . . $ `storage/mroonga/vendor/groonga/lib/io.c:97:10`!(ctx, &grn_gctx, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, &(fi.fmo), &fi, header, b); |
| 683 | } |
| 684 | grn_fileinfo_closecxx . . $ grn_fileinfo_close(91b895c7c0cdf7c3).(ctx, &fi); |
| 685 | } |
| 686 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 687 | } |
| 688 | |
| 689 | grn_rccxx . . $ grn_rc# |
| 690 | grn_io_closecxx . . $ grn_io_close(117c07c672382ce3).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_iocxx . . $ grn_io# *io) |
| 691 | { |
| 692 | uint32_tcxx . . $ uint32_t# max_nfiles; |
| 693 | |
| 694 | max_nfiles = grn_io_max_n_filescxx . . $ grn_io_max_n_files(ee95b3f473df551b).(io); |
| 695 | grn_io_unregistercxx . . $ grn_io_unregister(341fd28fcb683921).(ctx, io); |
| 696 | if (io->ainfocxx . . $ _grn_io#ainfo.) { GRN_FREEcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_alloc.h:46:9`!(io->ainfo); } |
| 697 | if (io->mapscxx . . $ _grn_io#maps.) { |
| 698 | int i; |
| 699 | uint32_tcxx . . $ uint32_t# max_segment; |
| 700 | uint32_tcxx . . $ uint32_t# segment_size; |
| 701 | unsigned long file_size; |
| 702 | uint32_tcxx . . $ uint32_t# segments_per_file; |
| 703 | |
| 704 | max_segment = grn_io_max_segmentcxx . . $ grn_io_max_segment(ee95b3f473df551b).(io); |
| 705 | segment_size = io->headercxx . . $ _grn_io#header.->segment_sizecxx . . $ _grn_io_header#segment_size.; |
| 706 | file_size = grn_io_compute_file_sizecxx . . $ grn_io_compute_file_size(1892545c1754497d).(io->headercxx . . $ _grn_io#header.->versioncxx . . $ _grn_io_header#version.); |
| 707 | segments_per_file = file_size / segment_size; |
| 708 | for (i = 0; (uintcxx . . $ uint#) i < max_segment; i++) { |
| 709 | grn_io_mapinfocxx . . $ grn_io_mapinfo# *mi; |
| 710 | mi = &(io->mapscxx . . $ _grn_io#maps.[i]); |
| 711 | if (mi->mapcxx . . $ $anonymous_type_75db8acbd456f2ab_3#map.) { |
| 712 | fileinfocxx . . $ fileinfo# *fi = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 713 | /* if (atomic_read(mi->nref)) { return STILL_IN_USE ; } */ |
| 714 | if (io->fiscxx . . $ _grn_io#fis.) { |
| 715 | uint32_tcxx . . $ uint32_t# bseg = i + io->base_segcxx . . $ _grn_io#base_seg.; |
| 716 | uint32_tcxx . . $ uint32_t# fno = bseg / segments_per_file; |
| 717 | fi = &io->fiscxx . . $ _grn_io#fis.[fno]; |
| 718 | } |
| 719 | GRN_MUNMAPcxx . . $ `storage/mroonga/vendor/groonga/lib/io.c:97:10`!(ctx, &grn_gctx, io, &mi->fmo, fi, mi->map, segment_size); |
| 720 | } |
| 721 | } |
| 722 | GRN_FREEcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_alloc.h:46:9`!(io->maps); |
| 723 | } |
| 724 | GRN_MUNMAPcxx . . $ `storage/mroonga/vendor/groonga/lib/io.c:97:10`!(ctx, &grn_gctx, io, (io->fis ? &io->fis->fmo : NULL), |
| 725 | io->fis, io->header, io->base); |
| 726 | if (io->fiscxx . . $ _grn_io#fis.) { |
| 727 | uintcxx . . $ uint# i; |
| 728 | for (i = 0; i < max_nfiles; i++) { |
| 729 | fileinfocxx . . $ fileinfo# *fi = &(io->fiscxx . . $ _grn_io#fis.[i]); |
| 730 | grn_fileinfo_closecxx . . $ grn_fileinfo_close(91b895c7c0cdf7c3).(ctx, fi); |
| 731 | } |
| 732 | GRN_FREEcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_alloc.h:46:9`!(io->fis); |
| 733 | } |
| 734 | GRN_FREEcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_alloc.h:46:9`!(io); |
| 735 | return GRN_SUCCESScxx . . $ GRN_SUCCESS.; |
| 736 | } |
| 737 | |
| 738 | uint32_tcxx . . $ uint32_t# |
| 739 | grn_io_base_segcxx . . $ grn_io_base_seg(ee95b3f473df551b).(grn_iocxx . . $ grn_io# *io) |
| 740 | { |
| 741 | return io->base_segcxx . . $ _grn_io#base_seg.; |
| 742 | } |
| 743 | |
| 744 | const char * |
| 745 | grn_io_pathcxx . . $ grn_io_path(53b2e212b3c13636).(grn_iocxx . . $ grn_io# *io) |
| 746 | { |
| 747 | return io->pathcxx . . $ _grn_io#path.; |
| 748 | } |
| 749 | |
| 750 | void * |
| 751 | grn_io_headercxx . . $ grn_io_header(611b9b393b7178f5).(grn_iocxx . . $ grn_io# *io) |
| 752 | { |
| 753 | return io->user_headercxx . . $ _grn_io#user_header.; |
| 754 | } |
| 755 | |
| 756 | grn_rccxx . . $ grn_rc# |
| 757 | grn_io_set_typecxx . . $ grn_io_set_type(d505e6e1d36b3afe).(grn_iocxx . . $ grn_io# *io, uint32_tcxx . . $ uint32_t# type) |
| 758 | { |
| 759 | if (!io || !io->headercxx . . $ _grn_io#header.) { |
| 760 | return GRN_INVALID_ARGUMENTcxx . . $ GRN_INVALID_ARGUMENT.; |
| 761 | } |
| 762 | io->headercxx . . $ _grn_io#header.->typecxx . . $ _grn_io_header#type. = type; |
| 763 | return GRN_SUCCESScxx . . $ GRN_SUCCESS.; |
| 764 | } |
| 765 | |
| 766 | uint32_tcxx . . $ uint32_t# |
| 767 | grn_io_get_typecxx . . $ grn_io_get_type(ee95b3f473df551b).(grn_iocxx . . $ grn_io# *io) |
| 768 | { |
| 769 | if (!io || !io->headercxx . . $ _grn_io#header.) { return GRN_VOIDcxx . . $ `storage/mroonga/vendor/groonga/include/groonga/groonga.h:358:9`!; } |
| 770 | return io->headercxx . . $ _grn_io#header.->typecxx . . $ _grn_io_header#type.; |
| 771 | } |
| 772 | |
| 773 | inline static void |
| 774 | gen_pathnamecxx . . $ gen_pathname(a1cf99d6bd92bbc4).(const char *path, char *buffer, int fno) |
| 775 | { |
| 776 | size_t len = strlencxx . . $ strlen(751346f8406fd082).(path); |
| 777 | grn_memcpycxx . . $ `storage/mroonga/vendor/groonga/include/groonga/portability.h:31:11`!(buffer, path, len); |
| 778 | if (fno) { |
| 779 | buffer[len] = '.'; |
| 780 | grn_itohcxx . . $ grn_itoh(8d45ad636653b6f2).(fno, buffer + len + 1, 3); |
| 781 | buffer[len + 4] = '\0'; |
| 782 | } else { |
| 783 | buffer[len] = '\0'; |
| 784 | } |
| 785 | } |
| 786 | |
| 787 | static uint32_tcxx . . $ uint32_t# |
| 788 | grn_io_n_filescxx . . $ grn_io_n_files(7752bae3ff5e951e).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_iocxx . . $ grn_io# *io) |
| 789 | { |
| 790 | unsigned long file_size; |
| 791 | file_size = grn_io_compute_file_sizecxx . . $ grn_io_compute_file_size(1892545c1754497d).(io->headercxx . . $ _grn_io#header.->versioncxx . . $ _grn_io_header#version.); |
| 792 | return ((io->headercxx . . $ _grn_io#header.->curr_sizecxx . . $ _grn_io_header#curr_size. + file_size - 1) / file_size); |
| 793 | } |
| 794 | |
| 795 | grn_rccxx . . $ grn_rc# |
| 796 | grn_io_sizecxx . . $ grn_io_size(cad0b01aa2d38ece).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_iocxx . . $ grn_io# *io, uint64_tcxx . . $ uint64_t# *size) |
| 797 | { |
| 798 | uint32_tcxx . . $ uint32_t# fno; |
| 799 | struct statcxx . . $ stat# s; |
| 800 | uint64_tcxx . . $ uint64_t# tsize = 0; |
| 801 | char buffer[PATH_MAXcxx . . $ `<external>/6347054901304145714/limits.h:13:9`!]; |
| 802 | uint32_tcxx . . $ uint32_t# n_files; |
| 803 | |
| 804 | n_files = grn_io_n_filescxx . . $ grn_io_n_files(7752bae3ff5e951e).(ctx, io); |
| 805 | for (fno = 0; fno < n_files; fno++) { |
| 806 | gen_pathnamecxx . . $ gen_pathname(a1cf99d6bd92bbc4).(io->pathcxx . . $ _grn_io#path., buffer, fno); |
| 807 | if (statcxx . . $ stat(a9cd1e23e96f423c).(buffer, &s)) { |
| 808 | SERRcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_ctx.h:332:9`!("failed to stat path to compute size: <%s>", |
| 809 | buffer); |
| 810 | } else { |
| 811 | tsize += s.st_sizecxx . . $ stat#st_size.; |
| 812 | } |
| 813 | } |
| 814 | *size = tsize; |
| 815 | return GRN_SUCCESScxx . . $ GRN_SUCCESS.; |
| 816 | } |
| 817 | |
| 818 | grn_rccxx . . $ grn_rc# |
| 819 | grn_io_remove_rawcxx . . $ grn_io_remove_raw(cae1c943be750b4c).(grn_ctxcxx . . $ grn_ctx# *ctx, const char *path) |
| 820 | { |
| 821 | grn_rccxx . . $ grn_rc# rc = GRN_SUCCESScxx . . $ GRN_SUCCESS.; |
| 822 | int fno; |
| 823 | char buffer[PATH_MAXcxx . . $ `<external>/6347054901304145714/limits.h:13:9`!]; |
| 824 | |
| 825 | if (grn_unlinkcxx . . $ `storage/mroonga/vendor/groonga/include/groonga/portability.h:85:10`!(path) != 0) { |
| 826 | ERRNO_ERRcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_ctx.h:403:9`!("[io][remove] failed to remove path: <%s>", |
| 827 | path); |
| 828 | return ctx->rccxx . . $ _grn_ctx#rc.; |
| 829 | } |
| 830 | GRN_LOGcxx . . $ `storage/mroonga/vendor/groonga/include/groonga/groonga.h:1112:9`!(ctx, GRN_LOG_INFO, "[io][remove] removed path: <%s>", path); |
| 831 | |
| 832 | for (fno = 1; ; fno++) { |
| 833 | struct statcxx . . $ stat# s; |
| 834 | gen_pathnamecxx . . $ gen_pathname(a1cf99d6bd92bbc4).(path, buffer, fno); |
| 835 | if (statcxx . . $ stat(a9cd1e23e96f423c).(buffer, &s) != 0) { |
| 836 | break; |
| 837 | } |
| 838 | if (grn_unlinkcxx . . $ `storage/mroonga/vendor/groonga/include/groonga/portability.h:85:10`!(buffer) == 0) { |
| 839 | GRN_LOGcxx . . $ `storage/mroonga/vendor/groonga/include/groonga/groonga.h:1112:9`!(ctx, GRN_LOG_INFO, |
| 840 | "[io][remove] removed numbered path: <%d>: <%s>", fno, buffer); |
| 841 | } else { |
| 842 | ERRNO_ERRcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_ctx.h:403:9`!("[io][remove] failed to remove numbered path: <%d>: <%s>", |
| 843 | fno, buffer); |
| 844 | rc = ctx->rccxx . . $ _grn_ctx#rc.; |
| 845 | } |
| 846 | } |
| 847 | return rc; |
| 848 | } |
| 849 | |
| 850 | grn_rccxx . . $ grn_rc# |
| 851 | grn_io_removecxx . . $ grn_io_remove(cae1c943be750b4c).(grn_ctxcxx . . $ grn_ctx# *ctx, const char *path) |
| 852 | { |
| 853 | struct statcxx . . $ stat# s; |
| 854 | |
| 855 | if (statcxx . . $ stat(a9cd1e23e96f423c).(path, &s) != 0) { |
| 856 | SERRcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_ctx.h:332:9`!("failed to stat: <%s>", path); |
| 857 | return ctx->rccxx . . $ _grn_ctx#rc.; |
| 858 | } |
| 859 | |
| 860 | return grn_io_remove_rawcxx . . $ grn_io_remove_raw(cae1c943be750b4c).(ctx, path); |
| 861 | } |
| 862 | |
| 863 | grn_rccxx . . $ grn_rc# |
| 864 | grn_io_remove_if_existcxx . . $ grn_io_remove_if_exist(cae1c943be750b4c).(grn_ctxcxx . . $ grn_ctx# *ctx, const char *path) |
| 865 | { |
| 866 | struct statcxx . . $ stat# s; |
| 867 | if (statcxx . . $ stat(a9cd1e23e96f423c).(path, &s) == 0) { |
| 868 | return grn_io_remove_rawcxx . . $ grn_io_remove_raw(cae1c943be750b4c).(ctx, path); |
| 869 | } |
| 870 | return GRN_SUCCESScxx . . $ GRN_SUCCESS.; |
| 871 | } |
| 872 | |
| 873 | grn_rccxx . . $ grn_rc# |
| 874 | grn_io_renamecxx . . $ grn_io_rename(acfed50c3cac5568).(grn_ctxcxx . . $ grn_ctx# *ctx, const char *old_name, const char *new_name) |
| 875 | { |
| 876 | struct statcxx . . $ stat# s; |
| 877 | if (statcxx . . $ stat(a9cd1e23e96f423c).(old_name, &s)) { |
| 878 | SERRcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_ctx.h:332:9`!("failed to stat path to be renamed: <%s>", old_name); |
| 879 | return ctx->rccxx . . $ _grn_ctx#rc.; |
| 880 | } else if (renamecxx . . $ rename(5ae29d726ae57f88).(old_name, new_name)) { |
| 881 | SERRcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_ctx.h:332:9`!("failed to rename path: <%s> -> <%s>", |
| 882 | old_name, new_name); |
| 883 | return ctx->rccxx . . $ _grn_ctx#rc.; |
| 884 | } else { |
| 885 | int fno; |
| 886 | char old_buffer[PATH_MAXcxx . . $ `<external>/6347054901304145714/limits.h:13:9`!]; |
| 887 | char new_buffer[PATH_MAXcxx . . $ `<external>/6347054901304145714/limits.h:13:9`!]; |
| 888 | for (fno = 1; ; fno++) { |
| 889 | gen_pathnamecxx . . $ gen_pathname(a1cf99d6bd92bbc4).(old_name, old_buffer, fno); |
| 890 | if (!statcxx . . $ stat(a9cd1e23e96f423c).(old_buffer, &s)) { |
| 891 | gen_pathnamecxx . . $ gen_pathname(a1cf99d6bd92bbc4).(new_name, new_buffer, fno); |
| 892 | if (renamecxx . . $ rename(5ae29d726ae57f88).(old_buffer, new_buffer)) { |
| 893 | SERRcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_ctx.h:332:9`!("failed to rename path: <%s> -> <%s>", |
| 894 | old_buffer, new_buffer); |
| 895 | } |
| 896 | } else { |
| 897 | SERRcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_ctx.h:332:9`!("failed to stat path to be renamed: <%s>", |
| 898 | old_buffer); |
| 899 | return ctx->rccxx . . $ _grn_ctx#rc.; |
| 900 | } |
| 901 | } |
| 902 | return GRN_SUCCESScxx . . $ GRN_SUCCESS.; |
| 903 | } |
| 904 | } |
| 905 | |
| 906 | typedef structcxx . . $ $anonymous_type_943e7849b6cc9839_0# { |
| 907 | grn_io_ja_eheadcxx . . $ grn_io_ja_ehead# headcxx . . $ $anonymous_type_943e7849b6cc9839_0#head.; |
| 908 | char bodycxx . . $ $anonymous_type_943e7849b6cc9839_0#body.[256]; |
| 909 | } ja_elementcxx . . $ ja_element#; |
| 910 | |
| 911 | grn_rccxx . . $ grn_rc# |
| 912 | grn_io_read_jacxx . . $ grn_io_read_ja(77e40c6d8fdca877).(grn_iocxx . . $ grn_io# *io, grn_ctxcxx . . $ grn_ctx# *ctx, grn_io_ja_einfocxx . . $ grn_io_ja_einfo# *einfo, uint32_tcxx . . $ uint32_t# epos, |
| 913 | uint32_tcxx . . $ uint32_t# key, uint32_tcxx . . $ uint32_t# segment, uint32_tcxx . . $ uint32_t# offset, void **value, |
| 914 | uint32_tcxx . . $ uint32_t# *value_len) |
| 915 | { |
| 916 | uint32_tcxx . . $ uint32_t# rest = 0, size = *value_len + sizeof(grn_io_ja_eheadcxx . . $ grn_io_ja_ehead#); |
| 917 | uint32_tcxx . . $ uint32_t# segment_size = io->headercxx . . $ _grn_io#header.->segment_sizecxx . . $ _grn_io_header#segment_size.; |
| 918 | unsigned long file_size = grn_io_compute_file_sizecxx . . $ grn_io_compute_file_size(1892545c1754497d).(io->headercxx . . $ _grn_io#header.->versioncxx . . $ _grn_io_header#version.); |
| 919 | uint32_tcxx . . $ uint32_t# segments_per_file = file_size / segment_size; |
| 920 | uint32_tcxx . . $ uint32_t# bseg = segment + io->base_segcxx . . $ _grn_io#base_seg.; |
| 921 | int fno = bseg / segments_per_file; |
| 922 | fileinfocxx . . $ fileinfo# *fi = &io->fiscxx . . $ _grn_io#fis.[fno]; |
| 923 | off_tcxx . . $ off_t# base = fno ? 0 : io->basecxx . . $ _grn_io#base. - (uint64_tcxx . . $ uint64_t#)segment_size * io->base_segcxx . . $ _grn_io#base_seg.; |
| 924 | off_tcxx . . $ off_t# pos = (uint64_tcxx . . $ uint64_t#)segment_size * (bseg % segments_per_file) + offset + base; |
| 925 | ja_elementcxx . . $ ja_element# *v = GRN_MALLOCcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_alloc.h:38:9`!(size); |
| 926 | if (!v) { |
| 927 | *value = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 928 | *value_len = 0; |
| 929 | return GRN_NO_MEMORY_AVAILABLEcxx . . $ GRN_NO_MEMORY_AVAILABLE.; |
| 930 | } |
| 931 | if ((unsigned long) (pos + size) > file_size) { |
| 932 | rest = pos + size - file_size; |
| 933 | size = file_size - pos; |
| 934 | } |
| 935 | if (!grn_fileinfo_openedcxx . . $ grn_fileinfo_opened(600504bf85ebe923).(fi)) { |
| 936 | char path[PATH_MAXcxx . . $ `<external>/6347054901304145714/limits.h:13:9`!]; |
| 937 | gen_pathnamecxx . . $ gen_pathname(a1cf99d6bd92bbc4).(io->pathcxx . . $ _grn_io#path., path, fno); |
| 938 | if (grn_fileinfo_opencxx . . $ grn_fileinfo_open(ac8f5bf2db69e073).(ctx, fi, path, O_RDWRcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:45:9`!|O_CREATcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:47:10`!)) { |
| 939 | *value = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 940 | *value_len = 0; |
| 941 | GRN_FREEcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_alloc.h:46:9`!(v); |
| 942 | return ctx->rccxx . . $ _grn_ctx#rc.; |
| 943 | } |
| 944 | } |
| 945 | if (grn_preadcxx . . $ grn_pread(4577714838bf4b55).(ctx, fi, v, size, pos)) { |
| 946 | *value = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 947 | *value_len = 0; |
| 948 | GRN_FREEcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_alloc.h:46:9`!(v); |
| 949 | return ctx->rccxx . . $ _grn_ctx#rc.; |
| 950 | } |
| 951 | if (einfo->poscxx . . $ _grn_io_ja_einfo#pos. != epos) { |
| 952 | GRN_LOGcxx . . $ `storage/mroonga/vendor/groonga/include/groonga/groonga.h:1112:9`!(ctx, GRN_LOG_WARNING, |
| 953 | "einfo pos changed %x => %x", einfo->pos, epos); |
| 954 | *value = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 955 | *value_len = 0; |
| 956 | GRN_FREEcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_alloc.h:46:9`!(v); |
| 957 | return GRN_FILE_CORRUPTcxx . . $ GRN_FILE_CORRUPT.; |
| 958 | } |
| 959 | if (einfo->sizecxx . . $ _grn_io_ja_einfo#size. != *value_len) { |
| 960 | GRN_LOGcxx . . $ `storage/mroonga/vendor/groonga/include/groonga/groonga.h:1112:9`!(ctx, GRN_LOG_WARNING, |
| 961 | "einfo size changed %d => %d", einfo->size, *value_len); |
| 962 | *value = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 963 | *value_len = 0; |
| 964 | GRN_FREEcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_alloc.h:46:9`!(v); |
| 965 | return GRN_FILE_CORRUPTcxx . . $ GRN_FILE_CORRUPT.; |
| 966 | } |
| 967 | if (v->headcxx . . $ $anonymous_type_943e7849b6cc9839_0#head..keycxx . . $ _grn_io_ja_ehead#key. != key) { |
| 968 | GRN_LOGcxx . . $ `storage/mroonga/vendor/groonga/include/groonga/groonga.h:1112:9`!(ctx, GRN_LOG_ERROR, |
| 969 | "ehead key unmatch %x => %x", key, v->head.key); |
| 970 | *value = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 971 | *value_len = 0; |
| 972 | GRN_FREEcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_alloc.h:46:9`!(v); |
| 973 | return GRN_INVALID_FORMATcxx . . $ GRN_INVALID_FORMAT.; |
| 974 | } |
| 975 | if (v->headcxx . . $ $anonymous_type_943e7849b6cc9839_0#head..sizecxx . . $ _grn_io_ja_ehead#size. != *value_len) { |
| 976 | GRN_LOGcxx . . $ `storage/mroonga/vendor/groonga/include/groonga/groonga.h:1112:9`!(ctx, GRN_LOG_ERROR, |
| 977 | "ehead size unmatch %d => %d", *value_len, v->head.size); |
| 978 | *value = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 979 | *value_len = 0; |
| 980 | GRN_FREEcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_alloc.h:46:9`!(v); |
| 981 | return GRN_INVALID_FORMATcxx . . $ GRN_INVALID_FORMAT.; |
| 982 | } |
| 983 | if (rest) { |
| 984 | bytecxx . . $ byte# *vr = (bytecxx . . $ byte# *)v + size; |
| 985 | do { |
| 986 | fi = &io->fiscxx . . $ _grn_io#fis.[++fno]; |
| 987 | if (!grn_fileinfo_openedcxx . . $ grn_fileinfo_opened(600504bf85ebe923).(fi)) { |
| 988 | char path[PATH_MAXcxx . . $ `<external>/6347054901304145714/limits.h:13:9`!]; |
| 989 | gen_pathnamecxx . . $ gen_pathname(a1cf99d6bd92bbc4).(io->pathcxx . . $ _grn_io#path., path, fno); |
| 990 | if (grn_fileinfo_opencxx . . $ grn_fileinfo_open(ac8f5bf2db69e073).(ctx, fi, path, O_RDWRcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:45:9`!|O_CREATcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:47:10`!)) { |
| 991 | *value = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 992 | *value_len = 0; |
| 993 | GRN_FREEcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_alloc.h:46:9`!(v); |
| 994 | return ctx->rccxx . . $ _grn_ctx#rc.; |
| 995 | } |
| 996 | } |
| 997 | size = rest > file_size ? file_size : rest; |
| 998 | if (grn_preadcxx . . $ grn_pread(4577714838bf4b55).(ctx, fi, vr, size, 0)) { |
| 999 | *value = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 1000 | *value_len = 0; |
| 1001 | GRN_FREEcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_alloc.h:46:9`!(v); |
| 1002 | return ctx->rccxx . . $ _grn_ctx#rc.; |
| 1003 | } |
| 1004 | vr += size; |
| 1005 | rest -= size; |
| 1006 | } while (rest); |
| 1007 | } |
| 1008 | *value = v->bodycxx . . $ $anonymous_type_943e7849b6cc9839_0#body.; |
| 1009 | return GRN_SUCCESScxx . . $ GRN_SUCCESS.; |
| 1010 | } |
| 1011 | |
| 1012 | grn_rccxx . . $ grn_rc# |
| 1013 | grn_io_write_jacxx . . $ grn_io_write_ja(83ed76a22e0380a9).(grn_iocxx . . $ grn_io# *io, grn_ctxcxx . . $ grn_ctx# *ctx, uint32_tcxx . . $ uint32_t# key, |
| 1014 | uint32_tcxx . . $ uint32_t# segment, uint32_tcxx . . $ uint32_t# offset, void *value, |
| 1015 | uint32_tcxx . . $ uint32_t# value_len) |
| 1016 | { |
| 1017 | grn_rccxx . . $ grn_rc# rc; |
| 1018 | uint32_tcxx . . $ uint32_t# rest = 0, size = value_len + sizeof(grn_io_ja_eheadcxx . . $ grn_io_ja_ehead#); |
| 1019 | uint32_tcxx . . $ uint32_t# segment_size = io->headercxx . . $ _grn_io#header.->segment_sizecxx . . $ _grn_io_header#segment_size.; |
| 1020 | unsigned long file_size = grn_io_compute_file_sizecxx . . $ grn_io_compute_file_size(1892545c1754497d).(io->headercxx . . $ _grn_io#header.->versioncxx . . $ _grn_io_header#version.); |
| 1021 | uint32_tcxx . . $ uint32_t# segments_per_file = file_size / segment_size; |
| 1022 | uint32_tcxx . . $ uint32_t# bseg = segment + io->base_segcxx . . $ _grn_io#base_seg.; |
| 1023 | int fno = bseg / segments_per_file; |
| 1024 | fileinfocxx . . $ fileinfo# *fi = &io->fiscxx . . $ _grn_io#fis.[fno]; |
| 1025 | off_tcxx . . $ off_t# base = fno ? 0 : io->basecxx . . $ _grn_io#base. - (uint64_tcxx . . $ uint64_t#)segment_size * io->base_segcxx . . $ _grn_io#base_seg.; |
| 1026 | off_tcxx . . $ off_t# pos = (uint64_tcxx . . $ uint64_t#)segment_size * (bseg % segments_per_file) + offset + base; |
| 1027 | if ((unsigned long) (pos + size) > file_size) { |
| 1028 | rest = pos + size - file_size; |
| 1029 | size = file_size - pos; |
| 1030 | } |
| 1031 | if (!grn_fileinfo_openedcxx . . $ grn_fileinfo_opened(600504bf85ebe923).(fi)) { |
| 1032 | char path[PATH_MAXcxx . . $ `<external>/6347054901304145714/limits.h:13:9`!]; |
| 1033 | gen_pathnamecxx . . $ gen_pathname(a1cf99d6bd92bbc4).(io->pathcxx . . $ _grn_io#path., path, fno); |
| 1034 | if ((rc = grn_fileinfo_opencxx . . $ grn_fileinfo_open(ac8f5bf2db69e073).(ctx, fi, path, O_RDWRcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:45:9`!|O_CREATcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:47:10`!))) { return rc; } |
| 1035 | } |
| 1036 | if (value_len <= 256) { |
| 1037 | ja_elementcxx . . $ ja_element# je; |
| 1038 | je.headcxx . . $ $anonymous_type_943e7849b6cc9839_0#head..sizecxx . . $ _grn_io_ja_ehead#size. = value_len; |
| 1039 | je.headcxx . . $ $anonymous_type_943e7849b6cc9839_0#head..keycxx . . $ _grn_io_ja_ehead#key. = key; |
| 1040 | grn_memcpycxx . . $ `storage/mroonga/vendor/groonga/include/groonga/portability.h:31:11`!(je.body, value, value_len); |
| 1041 | rc = grn_pwritecxx . . $ grn_pwrite(4577714838bf4b55).(ctx, fi, &je, size, pos); |
| 1042 | } else { |
| 1043 | grn_io_ja_eheadcxx . . $ grn_io_ja_ehead# eh; |
| 1044 | eh.sizecxx . . $ _grn_io_ja_ehead#size. = value_len; |
| 1045 | eh.keycxx . . $ _grn_io_ja_ehead#key. = key; |
| 1046 | if ((rc = grn_pwritecxx . . $ grn_pwrite(4577714838bf4b55).(ctx, fi, &eh, sizeof(grn_io_ja_eheadcxx . . $ grn_io_ja_ehead#), pos))) { |
| 1047 | return rc; |
| 1048 | } |
| 1049 | pos += sizeof(grn_io_ja_eheadcxx . . $ grn_io_ja_ehead#); |
| 1050 | rc = grn_pwritecxx . . $ grn_pwrite(4577714838bf4b55).(ctx, fi, value, size - sizeof(grn_io_ja_eheadcxx . . $ grn_io_ja_ehead#), pos); |
| 1051 | } |
| 1052 | if (rc) { return rc; } |
| 1053 | if (rest) { |
| 1054 | bytecxx . . $ byte# *vr = (bytecxx . . $ byte# *)value + size - sizeof(grn_io_ja_eheadcxx . . $ grn_io_ja_ehead#); |
| 1055 | do { |
| 1056 | fi = &io->fiscxx . . $ _grn_io#fis.[++fno]; |
| 1057 | if (!grn_fileinfo_openedcxx . . $ grn_fileinfo_opened(600504bf85ebe923).(fi)) { |
| 1058 | char path[PATH_MAXcxx . . $ `<external>/6347054901304145714/limits.h:13:9`!]; |
| 1059 | gen_pathnamecxx . . $ gen_pathname(a1cf99d6bd92bbc4).(io->pathcxx . . $ _grn_io#path., path, fno); |
| 1060 | if ((rc = grn_fileinfo_opencxx . . $ grn_fileinfo_open(ac8f5bf2db69e073).(ctx, fi, path, O_RDWRcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:45:9`!|O_CREATcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:47:10`!))) { |
| 1061 | return rc; |
| 1062 | } |
| 1063 | } |
| 1064 | size = rest > file_size ? file_size : rest; |
| 1065 | if ((rc = grn_pwritecxx . . $ grn_pwrite(4577714838bf4b55).(ctx, fi, vr, size, 0))) { return rc; } |
| 1066 | vr += size; |
| 1067 | rest -= size; |
| 1068 | } while (rest); |
| 1069 | } |
| 1070 | return rc; |
| 1071 | } |
| 1072 | |
| 1073 | grn_rccxx . . $ grn_rc# |
| 1074 | grn_io_write_ja_eheadcxx . . $ grn_io_write_ja_ehead(ba5be44a0ced10b1).(grn_iocxx . . $ grn_io# *io, grn_ctxcxx . . $ grn_ctx# *ctx, uint32_tcxx . . $ uint32_t# key, |
| 1075 | uint32_tcxx . . $ uint32_t# segment, uint32_tcxx . . $ uint32_t# offset, uint32_tcxx . . $ uint32_t# value_len) |
| 1076 | { |
| 1077 | grn_rccxx . . $ grn_rc# rc; |
| 1078 | uint32_tcxx . . $ uint32_t# segment_size = io->headercxx . . $ _grn_io#header.->segment_sizecxx . . $ _grn_io_header#segment_size.; |
| 1079 | unsigned long file_size = grn_io_compute_file_sizecxx . . $ grn_io_compute_file_size(1892545c1754497d).(io->headercxx . . $ _grn_io#header.->versioncxx . . $ _grn_io_header#version.); |
| 1080 | uint32_tcxx . . $ uint32_t# segments_per_file = file_size / segment_size; |
| 1081 | uint32_tcxx . . $ uint32_t# bseg = segment + io->base_segcxx . . $ _grn_io#base_seg.; |
| 1082 | int fno = bseg / segments_per_file; |
| 1083 | fileinfocxx . . $ fileinfo# *fi = &io->fiscxx . . $ _grn_io#fis.[fno]; |
| 1084 | off_tcxx . . $ off_t# base = fno ? 0 : io->basecxx . . $ _grn_io#base. - (uint64_tcxx . . $ uint64_t#)segment_size + io->base_segcxx . . $ _grn_io#base_seg.; |
| 1085 | off_tcxx . . $ off_t# pos = (uint64_tcxx . . $ uint64_t#)segment_size * (bseg % segments_per_file) + offset + base; |
| 1086 | if (!grn_fileinfo_openedcxx . . $ grn_fileinfo_opened(600504bf85ebe923).(fi)) { |
| 1087 | char path[PATH_MAXcxx . . $ `<external>/6347054901304145714/limits.h:13:9`!]; |
| 1088 | gen_pathnamecxx . . $ gen_pathname(a1cf99d6bd92bbc4).(io->pathcxx . . $ _grn_io#path., path, fno); |
| 1089 | if ((rc = grn_fileinfo_opencxx . . $ grn_fileinfo_open(ac8f5bf2db69e073).(ctx, fi, path, O_RDWRcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:45:9`!|O_CREATcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:47:10`!))) { return rc; } |
| 1090 | } |
| 1091 | { |
| 1092 | grn_io_ja_eheadcxx . . $ grn_io_ja_ehead# eh; |
| 1093 | eh.sizecxx . . $ _grn_io_ja_ehead#size. = value_len; |
| 1094 | eh.keycxx . . $ _grn_io_ja_ehead#key. = key; |
| 1095 | return grn_pwritecxx . . $ grn_pwrite(4577714838bf4b55).(ctx, fi, &eh, sizeof(grn_io_ja_eheadcxx . . $ grn_io_ja_ehead#), pos); |
| 1096 | } |
| 1097 | } |
| 1098 | |
| 1099 | void * |
| 1100 | grn_io_win_mapcxx . . $ grn_io_win_map(9825c1fa5dc4e0af).(grn_iocxx . . $ grn_io# *io, grn_ctxcxx . . $ grn_ctx# *ctx, grn_io_wincxx . . $ grn_io_win# *iw, uint32_tcxx . . $ uint32_t# segment, |
| 1101 | uint32_tcxx . . $ uint32_t# offset, uint32_tcxx . . $ uint32_t# size, grn_io_rw_modecxx . . $ grn_io_rw_mode# mode) |
| 1102 | { |
| 1103 | uint32_tcxx . . $ uint32_t# nseg, segment_size = io->headercxx . . $ _grn_io#header.->segment_sizecxx . . $ _grn_io_header#segment_size.; |
| 1104 | if (offset >= segment_size) { |
| 1105 | segment += offset / segment_size; |
| 1106 | offset = offset % segment_size; |
| 1107 | } |
| 1108 | nseg = (offset + size + segment_size - 1) / segment_size; |
| 1109 | if (!size || !ctx || segment + nseg > io->headercxx . . $ _grn_io#header.->max_segmentcxx . . $ _grn_io_header#max_segment.) { |
| 1110 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 1111 | } |
| 1112 | iw->ctxcxx . . $ $anonymous_type_75db8acbd456f2ab_2#ctx. = ctx; |
| 1113 | iw->diffcxx . . $ $anonymous_type_75db8acbd456f2ab_2#diff. = 0; |
| 1114 | iw->iocxx . . $ $anonymous_type_75db8acbd456f2ab_2#io. = io; |
| 1115 | iw->modecxx . . $ $anonymous_type_75db8acbd456f2ab_2#mode. = mode; |
| 1116 | iw->tiny_pcxx . . $ $anonymous_type_75db8acbd456f2ab_2#tiny_p. = 0; |
| 1117 | iw->segmentcxx . . $ $anonymous_type_75db8acbd456f2ab_2#segment. = segment; |
| 1118 | iw->offsetcxx . . $ $anonymous_type_75db8acbd456f2ab_2#offset. = offset; |
| 1119 | iw->nsegcxx . . $ $anonymous_type_75db8acbd456f2ab_2#nseg. = nseg; |
| 1120 | iw->sizecxx . . $ $anonymous_type_75db8acbd456f2ab_2#size. = size; |
| 1121 | if (nseg == 1) { |
| 1122 | bytecxx . . $ byte# *addr = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 1123 | GRN_IO_SEG_REFcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_io.h:169:9`!(io, segment, addr); |
| 1124 | if (!addr) { return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; } |
| 1125 | iw->cachedcxx . . $ $anonymous_type_75db8acbd456f2ab_2#cached. = 1; |
| 1126 | iw->addrcxx . . $ $anonymous_type_75db8acbd456f2ab_2#addr. = addr + offset; |
| 1127 | } else { |
| 1128 | if (!(iw->addrcxx . . $ $anonymous_type_75db8acbd456f2ab_2#addr. = GRN_MALLOCcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_alloc.h:38:9`!(size))) { return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; } |
| 1129 | iw->cachedcxx . . $ $anonymous_type_75db8acbd456f2ab_2#cached. = 0; |
| 1130 | switch (mode) { |
| 1131 | case grn_io_rdonlycxx . . $ grn_io_rdonly.: |
| 1132 | case grn_io_rdwrcxx . . $ grn_io_rdwr.: |
| 1133 | { |
| 1134 | bytecxx . . $ byte# *p, *q = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 1135 | uint32_tcxx . . $ uint32_t# s, r; |
| 1136 | for (p = iw->addrcxx . . $ $anonymous_type_75db8acbd456f2ab_2#addr., r = size; r; p += s, r -= s, segment++, offset = 0) { |
| 1137 | GRN_IO_SEG_REFcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_io.h:169:9`!(io, segment, q); |
| 1138 | if (!q) { |
| 1139 | GRN_FREEcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_alloc.h:46:9`!(iw->addr); |
| 1140 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 1141 | } |
| 1142 | s = (offset + r > segment_size) ? segment_size - offset : r; |
| 1143 | grn_memcpycxx . . $ `storage/mroonga/vendor/groonga/include/groonga/portability.h:31:11`!(p, q + offset, s); |
| 1144 | GRN_IO_SEG_UNREFcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_io.h:276:9`!(io, segment); |
| 1145 | } |
| 1146 | } |
| 1147 | break; |
| 1148 | case grn_io_wronlycxx . . $ grn_io_wronly.: |
| 1149 | break; |
| 1150 | default : |
| 1151 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 1152 | } |
| 1153 | } |
| 1154 | return iw->addrcxx . . $ $anonymous_type_75db8acbd456f2ab_2#addr.; |
| 1155 | } |
| 1156 | |
| 1157 | grn_rccxx . . $ grn_rc# |
| 1158 | grn_io_win_unmapcxx . . $ grn_io_win_unmap(6da7ae6a610e24ca).(grn_io_wincxx . . $ grn_io_win# *iw) |
| 1159 | { |
| 1160 | if (!iw || !iw->iocxx . . $ $anonymous_type_75db8acbd456f2ab_2#io. ||!iw->ctxcxx . . $ $anonymous_type_75db8acbd456f2ab_2#ctx.) { return GRN_INVALID_ARGUMENTcxx . . $ GRN_INVALID_ARGUMENT.; } |
| 1161 | if (iw->cachedcxx . . $ $anonymous_type_75db8acbd456f2ab_2#cached.) { |
| 1162 | if (!iw->tiny_pcxx . . $ $anonymous_type_75db8acbd456f2ab_2#tiny_p.) { GRN_IO_SEG_UNREFcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_io.h:276:9`!(iw->io, iw->segment); } |
| 1163 | return GRN_SUCCESScxx . . $ GRN_SUCCESS.; |
| 1164 | } |
| 1165 | { |
| 1166 | grn_iocxx . . $ grn_io# *io = iw->iocxx . . $ $anonymous_type_75db8acbd456f2ab_2#io.; |
| 1167 | grn_ctxcxx . . $ grn_ctx# *ctx = iw->ctxcxx . . $ $anonymous_type_75db8acbd456f2ab_2#ctx.; |
| 1168 | switch (iw->modecxx . . $ $anonymous_type_75db8acbd456f2ab_2#mode.) { |
| 1169 | case grn_io_rdonlycxx . . $ grn_io_rdonly.: |
| 1170 | if (!iw->addrcxx . . $ $anonymous_type_75db8acbd456f2ab_2#addr.) { return GRN_INVALID_ARGUMENTcxx . . $ GRN_INVALID_ARGUMENT.; } |
| 1171 | GRN_FREEcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_alloc.h:46:9`!(iw->addr); |
| 1172 | return GRN_SUCCESScxx . . $ GRN_SUCCESS.; |
| 1173 | case grn_io_rdwrcxx . . $ grn_io_rdwr.: |
| 1174 | case grn_io_wronlycxx . . $ grn_io_wronly.: |
| 1175 | { |
| 1176 | bytecxx . . $ byte# *p, *q = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 1177 | uint32_tcxx . . $ uint32_t# segment_size = io->headercxx . . $ _grn_io#header.->segment_sizecxx . . $ _grn_io_header#segment_size.; |
| 1178 | uint32_tcxx . . $ uint32_t# s, r, offset = iw->offsetcxx . . $ $anonymous_type_75db8acbd456f2ab_2#offset., segment = iw->segmentcxx . . $ $anonymous_type_75db8acbd456f2ab_2#segment.; |
| 1179 | for (p = iw->addrcxx . . $ $anonymous_type_75db8acbd456f2ab_2#addr., r = iw->sizecxx . . $ $anonymous_type_75db8acbd456f2ab_2#size.; r; |
| 1180 | p += s, r -= s, segment++, offset = 0) { |
| 1181 | GRN_IO_SEG_REFcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_io.h:169:9`!(io, segment, q); |
| 1182 | if (!q) { return GRN_NO_MEMORY_AVAILABLEcxx . . $ GRN_NO_MEMORY_AVAILABLE.; } |
| 1183 | s = (offset + r > segment_size) ? segment_size - offset : r; |
| 1184 | grn_memcpycxx . . $ `storage/mroonga/vendor/groonga/include/groonga/portability.h:31:11`!(q + offset, p, s); |
| 1185 | GRN_IO_SEG_UNREFcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_io.h:276:9`!(io, segment); |
| 1186 | } |
| 1187 | } |
| 1188 | GRN_FREEcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_alloc.h:46:9`!(iw->addr); |
| 1189 | return GRN_SUCCESScxx . . $ GRN_SUCCESS.; |
| 1190 | default : |
| 1191 | return GRN_INVALID_ARGUMENTcxx . . $ GRN_INVALID_ARGUMENT.; |
| 1192 | } |
| 1193 | } |
| 1194 | } |
| 1195 | |
| 1196 | #define DO_MAPcxx . . $ `storage/mroonga/vendor/groonga/lib/io.c:1196:9`!(io,fmo,fi,pos,size,segno,res) do {\ |
| 1197 | (res) = GRN_MMAPcxx . . $ `storage/mroonga/vendor/groonga/lib/io.c:110:11`!(ctx, &grn_gctx, (io), (fmo), (fi), (pos), (size));\ |
| 1198 | if ((res)) {\ |
| 1199 | uint32_t nmaps;\ |
| 1200 | if (io->max_map_seg < segno) { io->max_map_seg = segno; }\ |
| 1201 | GRN_ATOMIC_ADD_EXcxx . . $ `storage/mroonga/vendor/groonga/lib/grn.h:484:11`!(&io->nmaps, 1, nmaps);\ |
| 1202 | {\ |
| 1203 | uint64_t tail = io->base + (uint64_t)(size) * ((segno) + 1);\ |
| 1204 | if (tail > io->header->curr_size) { io->header->curr_size = tail; }\ |
| 1205 | }\ |
| 1206 | }\ |
| 1207 | } while (0) |
| 1208 | |
| 1209 | void |
| 1210 | grn_io_seg_map_cxx . . $ grn_io_seg_map_(ac1ae5c59b1408f9).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_iocxx . . $ grn_io# *io, uint32_tcxx . . $ uint32_t# segno, grn_io_mapinfocxx . . $ grn_io_mapinfo# *info) |
| 1211 | { |
| 1212 | uint32_tcxx . . $ uint32_t# segment_size = io->headercxx . . $ _grn_io#header.->segment_sizecxx . . $ _grn_io_header#segment_size.; |
| 1213 | if ((io->flagscxx . . $ _grn_io#flags. & GRN_IO_TEMPORARYcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_io.h:160:9`!)) { |
| 1214 | DO_MAPcxx . . $ `storage/mroonga/vendor/groonga/lib/io.c:1196:9`!(io, &info->fmo, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, 0, segment_size, segno, info->map); |
| 1215 | } else { |
| 1216 | unsigned long file_size = grn_io_compute_file_sizecxx . . $ grn_io_compute_file_size(1892545c1754497d).(io->headercxx . . $ _grn_io#header.->versioncxx . . $ _grn_io_header#version.); |
| 1217 | uint32_tcxx . . $ uint32_t# segments_per_file = file_size / segment_size; |
| 1218 | uint32_tcxx . . $ uint32_t# bseg = segno + io->base_segcxx . . $ _grn_io#base_seg.; |
| 1219 | uint32_tcxx . . $ uint32_t# fno = bseg / segments_per_file; |
| 1220 | off_tcxx . . $ off_t# base = fno ? 0 : io->basecxx . . $ _grn_io#base. - (uint64_tcxx . . $ uint64_t#)segment_size * io->base_segcxx . . $ _grn_io#base_seg.; |
| 1221 | off_tcxx . . $ off_t# pos = (uint64_tcxx . . $ uint64_t#)segment_size * (bseg % segments_per_file) + base; |
| 1222 | fileinfocxx . . $ fileinfo# *fi = &io->fiscxx . . $ _grn_io#fis.[fno]; |
| 1223 | if (!grn_fileinfo_openedcxx . . $ grn_fileinfo_opened(600504bf85ebe923).(fi)) { |
| 1224 | char path[PATH_MAXcxx . . $ `<external>/6347054901304145714/limits.h:13:9`!]; |
| 1225 | grn_boolcxx . . $ grn_bool# path_exist = GRN_TRUEcxx . . $ `storage/mroonga/vendor/groonga/include/groonga/groonga.h:44:9`!; |
| 1226 | gen_pathnamecxx . . $ gen_pathname(a1cf99d6bd92bbc4).(io->pathcxx . . $ _grn_io#path., path, fno); |
| 1227 | path_exist = grn_path_existcxx . . $ grn_path_exist(f8b331399af92601).(path); |
| 1228 | if (!grn_fileinfo_opencxx . . $ grn_fileinfo_open(ac8f5bf2db69e073).(ctx, fi, path, O_RDWRcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:45:9`!|O_CREATcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:47:10`!)) { |
| 1229 | DO_MAPcxx . . $ `storage/mroonga/vendor/groonga/lib/io.c:1196:9`!(io, &info->fmo, fi, pos, segment_size, segno, info->map); |
| 1230 | if (!info->mapcxx . . $ $anonymous_type_75db8acbd456f2ab_3#map. && !path_exist) { |
| 1231 | if (grn_unlinkcxx . . $ `storage/mroonga/vendor/groonga/include/groonga/portability.h:85:10`!(path) == 0) { |
| 1232 | GRN_LOGcxx . . $ `storage/mroonga/vendor/groonga/include/groonga/groonga.h:1112:9`!(ctx, GRN_LOG_INFO, |
| 1233 | "[io][map][error] memory mapping is failed and then " |
| 1234 | "removed created map file: <%s>", path); |
| 1235 | } else { |
| 1236 | ERRNO_ERRcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_ctx.h:403:9`!("[io][map][error] memory mapping is failed and then " |
| 1237 | "failed to remove created map file: <%s>", path); |
| 1238 | } |
| 1239 | } |
| 1240 | } |
| 1241 | } else { |
| 1242 | DO_MAPcxx . . $ `storage/mroonga/vendor/groonga/lib/io.c:1196:9`!(io, &info->fmo, fi, pos, segment_size, segno, info->map); |
| 1243 | } |
| 1244 | } |
| 1245 | } |
| 1246 | |
| 1247 | grn_rccxx . . $ grn_rc# |
| 1248 | grn_io_seg_expirecxx . . $ grn_io_seg_expire(e0580d1d0e28a8d4).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_iocxx . . $ grn_io# *io, uint32_tcxx . . $ uint32_t# segno, uint32_tcxx . . $ uint32_t# nretry) |
| 1249 | { |
| 1250 | uint32_tcxx . . $ uint32_t# retry, *pnref; |
| 1251 | grn_io_mapinfocxx . . $ grn_io_mapinfo# *info; |
| 1252 | if (!io->mapscxx . . $ _grn_io#maps. || segno >= io->headercxx . . $ _grn_io#header.->max_segmentcxx . . $ _grn_io_header#max_segment.) { return GRN_INVALID_ARGUMENTcxx . . $ GRN_INVALID_ARGUMENT.; } |
| 1253 | info = &io->mapscxx . . $ _grn_io#maps.[segno]; |
| 1254 | if (!info->mapcxx . . $ $anonymous_type_75db8acbd456f2ab_3#map.) { return GRN_INVALID_ARGUMENTcxx . . $ GRN_INVALID_ARGUMENT.; } |
| 1255 | pnref = &info->nrefcxx . . $ $anonymous_type_75db8acbd456f2ab_3#nref.; |
| 1256 | for (retry = 0;; retry++) { |
| 1257 | uint32_tcxx . . $ uint32_t# nref; |
| 1258 | GRN_ATOMIC_ADD_EXcxx . . $ `storage/mroonga/vendor/groonga/lib/grn.h:484:11`!(pnref, 1, nref); |
| 1259 | if (nref) { |
| 1260 | GRN_ATOMIC_ADD_EXcxx . . $ `storage/mroonga/vendor/groonga/lib/grn.h:484:11`!(pnref, -1, nref); |
| 1261 | if (retry >= GRN_IO_MAX_RETRYcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_io.h:155:9`!) { |
| 1262 | GRN_LOGcxx . . $ `storage/mroonga/vendor/groonga/include/groonga/groonga.h:1112:9`!(ctx, GRN_LOG_CRIT, |
| 1263 | "deadlock detected! in grn_io_seg_expire(%p, %u, %u)", |
| 1264 | io, segno, nref); |
| 1265 | return GRN_RESOURCE_DEADLOCK_AVOIDEDcxx . . $ GRN_RESOURCE_DEADLOCK_AVOIDED.; |
| 1266 | } |
| 1267 | } else { |
| 1268 | GRN_ATOMIC_ADD_EXcxx . . $ `storage/mroonga/vendor/groonga/lib/grn.h:484:11`!(pnref, GRN_IO_MAX_REFcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_io.h:156:9`!, nref); |
| 1269 | if (nref > 1) { |
| 1270 | GRN_ATOMIC_ADD_EXcxx . . $ `storage/mroonga/vendor/groonga/lib/grn.h:484:11`!(pnref, -(GRN_IO_MAX_REFcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_io.h:156:9`! + 1), nref); |
| 1271 | GRN_FUTEX_WAKEcxx . . $ `storage/mroonga/vendor/groonga/lib/grn.h:743:10`!(pnref); |
| 1272 | if (retry >= GRN_IO_MAX_RETRYcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_io.h:155:9`!) { |
| 1273 | GRN_LOGcxx . . $ `storage/mroonga/vendor/groonga/include/groonga/groonga.h:1112:9`!(ctx, GRN_LOG_CRIT, |
| 1274 | "deadlock detected!! in grn_io_seg_expire(%p, %u, %u)", |
| 1275 | io, segno, nref); |
| 1276 | return GRN_RESOURCE_DEADLOCK_AVOIDEDcxx . . $ GRN_RESOURCE_DEADLOCK_AVOIDED.; |
| 1277 | } |
| 1278 | } else { |
| 1279 | uint32_tcxx . . $ uint32_t# nmaps; |
| 1280 | fileinfocxx . . $ fileinfo# *fi = &(io->fiscxx . . $ _grn_io#fis.[segno]); |
| 1281 | GRN_MUNMAPcxx . . $ `storage/mroonga/vendor/groonga/lib/io.c:97:10`!(ctx, &grn_gctx, io, &info->fmo, fi, |
| 1282 | info->map, io->header->segment_size); |
| 1283 | info->mapcxx . . $ $anonymous_type_75db8acbd456f2ab_3#map. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 1284 | GRN_ATOMIC_ADD_EXcxx . . $ `storage/mroonga/vendor/groonga/lib/grn.h:484:11`!(pnref, -(GRN_IO_MAX_REFcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_io.h:156:9`! + 1), nref); |
| 1285 | GRN_ATOMIC_ADD_EXcxx . . $ `storage/mroonga/vendor/groonga/lib/grn.h:484:11`!(&io->nmaps, -1, nmaps); |
| 1286 | GRN_FUTEX_WAKEcxx . . $ `storage/mroonga/vendor/groonga/lib/grn.h:743:10`!(pnref); |
| 1287 | return GRN_SUCCESScxx . . $ GRN_SUCCESS.; |
| 1288 | } |
| 1289 | } |
| 1290 | if (retry >= nretry) { return GRN_RESOURCE_DEADLOCK_AVOIDEDcxx . . $ GRN_RESOURCE_DEADLOCK_AVOIDED.; } |
| 1291 | GRN_FUTEX_WAITcxx . . $ `storage/mroonga/vendor/groonga/lib/grn.h:742:10`!(pnref); |
| 1292 | } |
| 1293 | } |
| 1294 | |
| 1295 | uint32_tcxx . . $ uint32_t# |
| 1296 | grn_io_expirecxx . . $ grn_io_expire(2d2f0de1d0048aa2).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_iocxx . . $ grn_io# *io, int count_thresh, uint32_tcxx . . $ uint32_t# limit) |
| 1297 | { |
| 1298 | uint32_tcxx . . $ uint32_t# m, n = 0, ln = io->nmapscxx . . $ _grn_io#nmaps.; |
| 1299 | switch ((io->flagscxx . . $ _grn_io#flags. & (GRN_IO_EXPIRE_GTICKcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_io.h:158:9`!|GRN_IO_EXPIRE_SEGMENTcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_io.h:159:9`!))) { |
| 1300 | case GRN_IO_EXPIRE_GTICKcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_io.h:158:9`! : |
| 1301 | { |
| 1302 | uint32_tcxx . . $ uint32_t# nref, nmaps, *pnref = &io->nrefcxx . . $ _grn_io#nref.; |
| 1303 | GRN_ATOMIC_ADD_EXcxx . . $ `storage/mroonga/vendor/groonga/lib/grn.h:484:11`!(pnref, 1, nref); |
| 1304 | if (!nref && grn_gtickcxx . . $ grn_gtick. - io->countcxx . . $ _grn_io#count. > (uintcxx . . $ uint#) count_thresh) { |
| 1305 | { |
| 1306 | uint32_tcxx . . $ uint32_t# i = io->headercxx . . $ _grn_io#header.->n_arrayscxx . . $ _grn_io_header#n_arrays.; |
| 1307 | grn_io_array_speccxx . . $ grn_io_array_spec# *array_specs = (grn_io_array_speccxx . . $ grn_io_array_spec# *)io->user_headercxx . . $ _grn_io#user_header.; |
| 1308 | while (i--) { |
| 1309 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(io->ainfocxx . . $ _grn_io#ainfo.[i].addrscxx . . $ _grn_io_array_info#addrs., 0, |
| 1310 | sizeof(void *) * array_specs[i].max_n_segmentscxx . . $ _grn_io_array_spec#max_n_segments.); |
| 1311 | } |
| 1312 | } |
| 1313 | { |
| 1314 | uint32_tcxx . . $ uint32_t# fno; |
| 1315 | for (fno = 0; fno < io->max_map_segcxx . . $ _grn_io#max_map_seg.; fno++) { |
| 1316 | grn_io_mapinfocxx . . $ grn_io_mapinfo# *info = &(io->mapscxx . . $ _grn_io#maps.[fno]); |
| 1317 | if (info->mapcxx . . $ $anonymous_type_75db8acbd456f2ab_3#map.) { |
| 1318 | fileinfocxx . . $ fileinfo# *fi = &(io->fiscxx . . $ _grn_io#fis.[fno]); |
| 1319 | GRN_MUNMAPcxx . . $ `storage/mroonga/vendor/groonga/lib/io.c:97:10`!(ctx, &grn_gctx, io, &info->fmo, fi, |
| 1320 | info->map, io->header->segment_size); |
| 1321 | info->mapcxx . . $ $anonymous_type_75db8acbd456f2ab_3#map. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 1322 | info->nrefcxx . . $ $anonymous_type_75db8acbd456f2ab_3#nref. = 0; |
| 1323 | info->countcxx . . $ $anonymous_type_75db8acbd456f2ab_3#count. = grn_gtickcxx . . $ grn_gtick.; |
| 1324 | GRN_ATOMIC_ADD_EXcxx . . $ `storage/mroonga/vendor/groonga/lib/grn.h:484:11`!(&io->nmaps, -1, nmaps); |
| 1325 | n++; |
| 1326 | } |
| 1327 | } |
| 1328 | } |
| 1329 | } |
| 1330 | GRN_ATOMIC_ADD_EXcxx . . $ `storage/mroonga/vendor/groonga/lib/grn.h:484:11`!(pnref, -1, nref); |
| 1331 | } |
| 1332 | break; |
| 1333 | case GRN_IO_EXPIRE_SEGMENTcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_io.h:159:9`! : |
| 1334 | for (m = io->max_map_segcxx . . $ _grn_io#max_map_seg.; n < limit && m; m--) { |
| 1335 | if (!grn_io_seg_expirecxx . . $ grn_io_seg_expire(e0580d1d0e28a8d4).(ctx, io, m, 0)) { n++; } |
| 1336 | } |
| 1337 | break; |
| 1338 | case (GRN_IO_EXPIRE_GTICKcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_io.h:158:9`!|GRN_IO_EXPIRE_SEGMENTcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_io.h:159:9`!) : |
| 1339 | { |
| 1340 | grn_io_mapinfocxx . . $ grn_io_mapinfo# *info = io->mapscxx . . $ _grn_io#maps.; |
| 1341 | for (m = io->max_map_segcxx . . $ _grn_io#max_map_seg.; n < limit && m; info++, m--) { |
| 1342 | if (info->mapcxx . . $ $anonymous_type_75db8acbd456f2ab_3#map. && (grn_gtickcxx . . $ grn_gtick. - info->countcxx . . $ $anonymous_type_75db8acbd456f2ab_3#count.) > (uintcxx . . $ uint#) count_thresh) { |
| 1343 | uint32_tcxx . . $ uint32_t# nmaps, nref, *pnref = &info->nrefcxx . . $ $anonymous_type_75db8acbd456f2ab_3#nref.; |
| 1344 | GRN_ATOMIC_ADD_EXcxx . . $ `storage/mroonga/vendor/groonga/lib/grn.h:484:11`!(pnref, 1, nref); |
| 1345 | if (!nref && info->mapcxx . . $ $anonymous_type_75db8acbd456f2ab_3#map. && (grn_gtickcxx . . $ grn_gtick. - info->countcxx . . $ $anonymous_type_75db8acbd456f2ab_3#count.) > (uintcxx . . $ uint#) count_thresh) { |
| 1346 | GRN_MUNMAPcxx . . $ `storage/mroonga/vendor/groonga/lib/io.c:97:10`!(ctx, &grn_gctx, io, &info->fmo, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, |
| 1347 | info->map, io->header->segment_size); |
| 1348 | GRN_ATOMIC_ADD_EXcxx . . $ `storage/mroonga/vendor/groonga/lib/grn.h:484:11`!(&io->nmaps, -1, nmaps); |
| 1349 | info->mapcxx . . $ $anonymous_type_75db8acbd456f2ab_3#map. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 1350 | info->countcxx . . $ $anonymous_type_75db8acbd456f2ab_3#count. = grn_gtickcxx . . $ grn_gtick.; |
| 1351 | n++; |
| 1352 | } |
| 1353 | GRN_ATOMIC_ADD_EXcxx . . $ `storage/mroonga/vendor/groonga/lib/grn.h:484:11`!(pnref, -1, nref); |
| 1354 | } |
| 1355 | } |
| 1356 | } |
| 1357 | break; |
| 1358 | } |
| 1359 | if (n) { |
| 1360 | GRN_LOGcxx . . $ `storage/mroonga/vendor/groonga/include/groonga/groonga.h:1112:9`!(ctx, GRN_LOG_DEBUG, "<%p:%x> expired i=%p max=%d (%d/%d)", |
| 1361 | ctx, grn_gtick, io, io->max_map_seg, n, ln); |
| 1362 | } |
| 1363 | return n; |
| 1364 | } |
| 1365 | |
| 1366 | void * |
| 1367 | grn_io_anon_mapcxx . . $ grn_io_anon_map(9de643cca07c394).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_io_mapinfocxx . . $ grn_io_mapinfo# *mi, size_t length) |
| 1368 | { |
| 1369 | return (mi->mapcxx . . $ $anonymous_type_75db8acbd456f2ab_3#map. = GRN_MMAPcxx . . $ `storage/mroonga/vendor/groonga/lib/io.c:110:11`!(ctx, ctx, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, &mi->fmo, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, 0, length)); |
| 1370 | } |
| 1371 | |
| 1372 | void |
| 1373 | grn_io_anon_unmapcxx . . $ grn_io_anon_unmap(e34ce909368ead97).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_io_mapinfocxx . . $ grn_io_mapinfo# *mi, size_t length) |
| 1374 | { |
| 1375 | GRN_MUNMAPcxx . . $ `storage/mroonga/vendor/groonga/lib/io.c:97:10`!(ctx, ctx, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, &mi->fmo, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, mi->map, length); |
| 1376 | } |
| 1377 | |
| 1378 | grn_rccxx . . $ grn_rc# |
| 1379 | grn_io_lockcxx . . $ grn_io_lock(2c16bfdb6acf067b).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_iocxx . . $ grn_io# *io, int timeout) |
| 1380 | { |
| 1381 | static int _ncalls = 0, _ncolls = 0; |
| 1382 | uint32_tcxx . . $ uint32_t# count, count_log_border = 1000; |
| 1383 | uint32_tcxx . . $ uint32_t# rc_check_interval = 1000; |
| 1384 | _ncalls++; |
| 1385 | if (!io) { return GRN_INVALID_ARGUMENTcxx . . $ GRN_INVALID_ARGUMENT.; } |
| 1386 | for (count = 0;; count++) { |
| 1387 | uint32_tcxx . . $ uint32_t# lock; |
| 1388 | GRN_ATOMIC_ADD_EXcxx . . $ `storage/mroonga/vendor/groonga/lib/grn.h:484:11`!(io->lock, 1, lock); |
| 1389 | if (lock) { |
| 1390 | GRN_ATOMIC_ADD_EXcxx . . $ `storage/mroonga/vendor/groonga/lib/grn.h:484:11`!(io->lock, -1, lock); |
| 1391 | if (count == count_log_border) { |
| 1392 | GRN_LOGcxx . . $ `storage/mroonga/vendor/groonga/include/groonga/groonga.h:1112:9`!(ctx, GRN_LOG_NOTICE, |
| 1393 | "io(%s) collisions(%d/%d): lock failed %d times", |
| 1394 | io->path, _ncolls, _ncalls, count_log_border); |
| 1395 | } |
| 1396 | if (!timeout || (timeout > 0 && timeout == (int) count)) { |
| 1397 | GRN_LOGcxx . . $ `storage/mroonga/vendor/groonga/include/groonga/groonga.h:1112:9`!(ctx, GRN_LOG_WARNING, |
| 1398 | "[DB Locked] time out(%d): io(%s) collisions(%d/%d)", |
| 1399 | timeout, io->path, _ncolls, _ncalls); |
| 1400 | break; |
| 1401 | } |
| 1402 | if (!(++_ncolls % 1000000) && (_ncolls > _ncalls)) { |
| 1403 | if (_ncolls < 0 || _ncalls < 0) { |
| 1404 | _ncolls = 0; _ncalls = 0; |
| 1405 | } else { |
| 1406 | GRN_LOGcxx . . $ `storage/mroonga/vendor/groonga/include/groonga/groonga.h:1112:9`!(ctx, GRN_LOG_NOTICE, |
| 1407 | "io(%s) collisions(%d/%d)", io->path, _ncolls, _ncalls); |
| 1408 | } |
| 1409 | } |
| 1410 | if ((count % rc_check_interval) == 0) { |
| 1411 | if (ctx->rccxx . . $ _grn_ctx#rc. != GRN_SUCCESScxx . . $ GRN_SUCCESS.) { |
| 1412 | return ctx->rccxx . . $ _grn_ctx#rc.; |
| 1413 | } |
| 1414 | } |
| 1415 | grn_nanosleepcxx . . $ grn_nanosleep(2c44cd906ae4e829).(GRN_LOCK_WAIT_TIME_NANOSECONDcxx . . $ `build/storage/mroonga/vendor/groonga/config.h:35:9`!); |
| 1416 | continue; |
| 1417 | } |
| 1418 | return GRN_SUCCESScxx . . $ GRN_SUCCESS.; |
| 1419 | } |
| 1420 | ERRcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_ctx.h:143:9`!(GRN_RESOURCE_DEADLOCK_AVOIDED, "grn_io_lock failed"); |
| 1421 | return ctx->rccxx . . $ _grn_ctx#rc.; |
| 1422 | } |
| 1423 | |
| 1424 | void |
| 1425 | grn_io_unlockcxx . . $ grn_io_unlock(69bc83933b8864bc).(grn_iocxx . . $ grn_io# *io) |
| 1426 | { |
| 1427 | if (io) { |
| 1428 | uint32_tcxx . . $ uint32_t# lock; |
| 1429 | GRN_ATOMIC_ADD_EXcxx . . $ `storage/mroonga/vendor/groonga/lib/grn.h:484:11`!(io->lock, -1, lock); |
| 1430 | } |
| 1431 | } |
| 1432 | |
| 1433 | void |
| 1434 | grn_io_clear_lockcxx . . $ grn_io_clear_lock(69bc83933b8864bc).(grn_iocxx . . $ grn_io# *io) |
| 1435 | { |
| 1436 | if (io) { *io->lockcxx . . $ _grn_io#lock. = 0; } |
| 1437 | } |
| 1438 | |
| 1439 | uint32_tcxx . . $ uint32_t# |
| 1440 | grn_io_is_lockedcxx . . $ grn_io_is_locked(ee95b3f473df551b).(grn_iocxx . . $ grn_io# *io) |
| 1441 | { |
| 1442 | return io ? *io->lockcxx . . $ _grn_io#lock. : 0; |
| 1443 | } |
| 1444 | |
| 1445 | grn_rccxx . . $ grn_rc# |
| 1446 | grn_io_flushcxx . . $ grn_io_flush(117c07c672382ce3).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_iocxx . . $ grn_io# *io) |
| 1447 | { |
| 1448 | grn_rccxx . . $ grn_rc# rc = GRN_SUCCESScxx . . $ GRN_SUCCESS.; |
| 1449 | struct _grn_io_headercxx . . $ _grn_io_header# *header; |
| 1450 | uint32_tcxx . . $ uint32_t# aligned_header_size; |
| 1451 | |
| 1452 | if (io->pathcxx . . $ _grn_io#path.[0] == '\0') { |
| 1453 | return GRN_SUCCESScxx . . $ GRN_SUCCESS.; |
| 1454 | } |
| 1455 | |
| 1456 | header = io->headercxx . . $ _grn_io#header.; |
| 1457 | aligned_header_size = grn_io_compute_basecxx . . $ grn_io_compute_base(2141b656ce2cc063).(header->header_sizecxx . . $ _grn_io_header#header_size.); |
| 1458 | |
| 1459 | if (GRN_MSYNCcxx . . $ `storage/mroonga/vendor/groonga/lib/io.c:99:10`!(ctx, io->fis[0].fh, header, aligned_header_size) != 0) { |
| 1460 | return ctx->rccxx . . $ _grn_ctx#rc.; |
| 1461 | } |
| 1462 | |
| 1463 | if (io->mapscxx . . $ _grn_io#maps.) { |
| 1464 | uint32_tcxx . . $ uint32_t# i; |
| 1465 | uint32_tcxx . . $ uint32_t# max_mapped_segment; |
| 1466 | uint32_tcxx . . $ uint32_t# segment_size; |
| 1467 | |
| 1468 | max_mapped_segment = grn_io_max_segmentcxx . . $ grn_io_max_segment(ee95b3f473df551b).(io); |
| 1469 | segment_size = header->segment_sizecxx . . $ _grn_io_header#segment_size.; |
| 1470 | for (i = 0; i < max_mapped_segment; i++) { |
| 1471 | grn_io_mapinfocxx . . $ grn_io_mapinfo# *info = &(io->mapscxx . . $ _grn_io#maps.[i]); |
| 1472 | uint32_tcxx . . $ uint32_t# nth_file_info; |
| 1473 | uint32_tcxx . . $ uint32_t# *pnref; |
| 1474 | uint32_tcxx . . $ uint32_t# nref; |
| 1475 | int msync_result; |
| 1476 | |
| 1477 | if (!info) { |
| 1478 | continue; |
| 1479 | } |
| 1480 | |
| 1481 | pnref = &info->nrefcxx . . $ $anonymous_type_75db8acbd456f2ab_3#nref.; |
| 1482 | GRN_ATOMIC_ADD_EXcxx . . $ `storage/mroonga/vendor/groonga/lib/grn.h:484:11`!(pnref, 1, nref); |
| 1483 | if (nref != 0) { |
| 1484 | GRN_ATOMIC_ADD_EXcxx . . $ `storage/mroonga/vendor/groonga/lib/grn.h:484:11`!(pnref, -1, nref); |
| 1485 | continue; |
| 1486 | } |
| 1487 | |
| 1488 | if (!info->mapcxx . . $ $anonymous_type_75db8acbd456f2ab_3#map.) { |
| 1489 | GRN_ATOMIC_ADD_EXcxx . . $ `storage/mroonga/vendor/groonga/lib/grn.h:484:11`!(pnref, -1, nref); |
| 1490 | GRN_FUTEX_WAKEcxx . . $ `storage/mroonga/vendor/groonga/lib/grn.h:743:10`!(pnref); |
| 1491 | continue; |
| 1492 | } |
| 1493 | |
| 1494 | nth_file_info = grn_io_compute_nth_file_infocxx . . $ grn_io_compute_nth_file_info(edffd242529b3d8b).(io, i); |
| 1495 | msync_result = GRN_MSYNCcxx . . $ `storage/mroonga/vendor/groonga/lib/io.c:99:10`!(ctx, |
| 1496 | io->fis[nth_file_info].fh, |
| 1497 | info->map, |
| 1498 | segment_size); |
| 1499 | GRN_ATOMIC_ADD_EXcxx . . $ `storage/mroonga/vendor/groonga/lib/grn.h:484:11`!(pnref, -1, nref); |
| 1500 | GRN_FUTEX_WAKEcxx . . $ `storage/mroonga/vendor/groonga/lib/grn.h:743:10`!(pnref); |
| 1501 | |
| 1502 | if (msync_result != 0) { |
| 1503 | rc = ctx->rccxx . . $ _grn_ctx#rc.; |
| 1504 | break; |
| 1505 | } |
| 1506 | } |
| 1507 | } |
| 1508 | |
| 1509 | return rc; |
| 1510 | } |
| 1511 | |
| 1512 | grn_boolcxx . . $ grn_bool# |
| 1513 | grn_io_is_corruptcxx . . $ grn_io_is_corrupt(c28f33aee31d8406).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_iocxx . . $ grn_io# *io) |
| 1514 | { |
| 1515 | uint32_tcxx . . $ uint32_t# i; |
| 1516 | uint32_tcxx . . $ uint32_t# n_files; |
| 1517 | |
| 1518 | if (!io) { |
| 1519 | return GRN_FALSEcxx . . $ `storage/mroonga/vendor/groonga/include/groonga/groonga.h:45:9`!; |
| 1520 | } |
| 1521 | |
| 1522 | n_files = grn_io_n_filescxx . . $ grn_io_n_files(7752bae3ff5e951e).(ctx, io); |
| 1523 | for (i = 0; i < n_files; i++) { |
| 1524 | char path[PATH_MAXcxx . . $ `<external>/6347054901304145714/limits.h:13:9`!]; |
| 1525 | struct statcxx . . $ stat# s; |
| 1526 | gen_pathnamecxx . . $ gen_pathname(a1cf99d6bd92bbc4).(io->pathcxx . . $ _grn_io#path., path, i); |
| 1527 | if (statcxx . . $ stat(a9cd1e23e96f423c).(path, &s) != 0) { |
| 1528 | SERRcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_ctx.h:332:9`!("[io][corrupt] used path doesn't exist: <%s>", |
| 1529 | path); |
| 1530 | return GRN_TRUEcxx . . $ `storage/mroonga/vendor/groonga/include/groonga/groonga.h:44:9`!; |
| 1531 | } |
| 1532 | } |
| 1533 | |
| 1534 | return GRN_FALSEcxx . . $ `storage/mroonga/vendor/groonga/include/groonga/groonga.h:45:9`!; |
| 1535 | } |
| 1536 | |
| 1537 | size_t |
| 1538 | grn_io_get_disk_usagecxx . . $ grn_io_get_disk_usage(c4749d9481ec000d).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_iocxx . . $ grn_io# *io) |
| 1539 | { |
| 1540 | size_t usage = 0; |
| 1541 | uint32_tcxx . . $ uint32_t# i; |
| 1542 | uint32_tcxx . . $ uint32_t# n_files; |
| 1543 | |
| 1544 | if (!io) { |
| 1545 | return usage; |
| 1546 | } |
| 1547 | |
| 1548 | n_files = grn_io_n_filescxx . . $ grn_io_n_files(7752bae3ff5e951e).(ctx, io); |
| 1549 | for (i = 0; i < n_files; i++) { |
| 1550 | char path[PATH_MAXcxx . . $ `<external>/6347054901304145714/limits.h:13:9`!]; |
| 1551 | struct statcxx . . $ stat# s; |
| 1552 | gen_pathnamecxx . . $ gen_pathname(a1cf99d6bd92bbc4).(io->pathcxx . . $ _grn_io#path., path, i); |
| 1553 | if (statcxx . . $ stat(a9cd1e23e96f423c).(path, &s) != 0) { |
| 1554 | continue; |
| 1555 | } |
| 1556 | usage += s.st_sizecxx . . $ stat#st_size.; |
| 1557 | } |
| 1558 | |
| 1559 | return usage; |
| 1560 | } |
| 1561 | |
| 1562 | /** mmap abstraction **/ |
| 1563 | |
| 1564 | static size_t mmap_sizecxx . . $ mmap_size. = 0; |
| 1565 | |
| 1566 | #ifdef WIN32 |
| 1567 | |
| 1568 | inline static grn_rc |
| 1569 | grn_fileinfo_open_v1(grn_ctx *ctx, fileinfo *fi, const char *path, int flags) |
| 1570 | { |
| 1571 | CRITICAL_SECTION_INIT(fi->cs); |
| 1572 | return GRN_SUCCESS; |
| 1573 | } |
| 1574 | |
| 1575 | inline static void * |
| 1576 | grn_mmap_v1(grn_ctx *ctx, grn_ctx *owner_ctx, HANDLE *fmo, fileinfo *fi, |
| 1577 | off_t offset, size_t length) |
| 1578 | { |
| 1579 | void *res; |
| 1580 | if (!fi) { |
| 1581 | if (fmo) { |
| 1582 | *fmo = NULL; |
| 1583 | } |
| 1584 | /* TODO: Try to support VirtualAlloc() as anonymous mmap in POSIX. |
| 1585 | * If VirtualAlloc() provides better performance rather than malloc(), |
| 1586 | * we'll use it. |
| 1587 | */ |
| 1588 | return GRN_CALLOC(length); |
| 1589 | } |
| 1590 | /* CRITICAL_SECTION_ENTER(fi->cs); */ |
| 1591 | /* try to create fmo */ |
| 1592 | *fmo = CreateFileMapping(fi->fh, NULL, PAGE_READWRITE, 0, offset + length, NULL); |
| 1593 | if (!*fmo) { |
| 1594 | SERR("CreateFileMapping(%lu + %" GRN_FMT_SIZE ") failed " |
| 1595 | "<%" GRN_FMT_SIZE ">", |
| 1596 | (DWORD)offset, length, |
| 1597 | mmap_size); |
| 1598 | return NULL; |
| 1599 | } |
| 1600 | res = MapViewOfFile(*fmo, FILE_MAP_WRITE, 0, (DWORD)offset, (SIZE_T)length); |
| 1601 | if (!res) { |
| 1602 | SERR("MapViewOfFile(%lu,%" GRN_FMT_SIZE ") failed <%" GRN_FMT_SIZE ">", |
| 1603 | (DWORD)offset, length, mmap_size); |
| 1604 | return NULL; |
| 1605 | } |
| 1606 | /* CRITICAL_SECTION_LEAVE(fi->cs); */ |
| 1607 | mmap_size += length; |
| 1608 | return res; |
| 1609 | } |
| 1610 | |
| 1611 | inline static int |
| 1612 | grn_munmap_v1(grn_ctx *ctx, grn_ctx *owner_ctx, HANDLE *fmo, fileinfo *fi, |
| 1613 | void *start, size_t length) |
| 1614 | { |
| 1615 | int r = 0; |
| 1616 | |
| 1617 | if (!fi) { |
| 1618 | GRN_FREE(start); |
| 1619 | return r; |
| 1620 | } |
| 1621 | |
| 1622 | if (!fmo) { |
| 1623 | GRN_FREE(start); |
| 1624 | return r; |
| 1625 | } |
| 1626 | |
| 1627 | if (*fmo) { |
| 1628 | if (UnmapViewOfFile(start)) { |
| 1629 | mmap_size -= length; |
| 1630 | } else { |
| 1631 | SERR("UnmapViewOfFile(%p,%" GRN_FMT_SIZE ") failed <%" GRN_FMT_SIZE ">", |
| 1632 | start, length, mmap_size); |
| 1633 | r = -1; |
| 1634 | } |
| 1635 | if (!CloseHandle(*fmo)) { |
| 1636 | SERR("CloseHandle(%p,%" GRN_FMT_SIZE ") failed <%" GRN_FMT_SIZE ">", |
| 1637 | start, length, mmap_size); |
| 1638 | } |
| 1639 | *fmo = NULL; |
| 1640 | } else { |
| 1641 | GRN_FREE(start); |
| 1642 | } |
| 1643 | |
| 1644 | return r; |
| 1645 | } |
| 1646 | |
| 1647 | inline static grn_rc |
| 1648 | grn_fileinfo_open_v0(grn_ctx *ctx, fileinfo *fi, const char *path, int flags) |
| 1649 | { |
| 1650 | /* signature may be wrong.. */ |
| 1651 | fi->fmo = OpenFileMapping(FILE_MAP_ALL_ACCESS, FALSE, NULL); |
| 1652 | /* open failed */ |
| 1653 | if (fi->fmo == NULL) { |
| 1654 | // flock |
| 1655 | /* retry to open */ |
| 1656 | fi->fmo = OpenFileMapping(FILE_MAP_ALL_ACCESS, FALSE, NULL); |
| 1657 | /* failed again */ |
| 1658 | if (fi->fmo == NULL) { |
| 1659 | /* try to create fmo */ |
| 1660 | fi->fmo = CreateFileMapping(fi->fh, NULL, PAGE_READWRITE, 0, |
| 1661 | GRN_IO_FILE_SIZE_V0, NULL); |
| 1662 | } |
| 1663 | // funlock |
| 1664 | } |
| 1665 | if (fi->fmo != NULL) { |
| 1666 | if (GetLastError() != ERROR_ALREADY_EXISTS) { |
| 1667 | CRITICAL_SECTION_INIT(fi->cs); |
| 1668 | return GRN_SUCCESS; |
| 1669 | } else { |
| 1670 | GRN_LOG(ctx, GRN_LOG_ERROR, |
| 1671 | "fmo object already exists! handle=%p", fi->fh); |
| 1672 | CloseHandle(fi->fmo); |
| 1673 | } |
| 1674 | } else { |
| 1675 | GRN_LOG(ctx, GRN_LOG_ALERT, |
| 1676 | "failed to get FileMappingObject #%lu", GetLastError()); |
| 1677 | } |
| 1678 | CloseHandle(fi->fh); |
| 1679 | SERR("OpenFileMapping"); |
| 1680 | return ctx->rc; |
| 1681 | } |
| 1682 | |
| 1683 | inline static void * |
| 1684 | grn_mmap_v0(grn_ctx *ctx, grn_ctx *owner_ctx, fileinfo *fi, off_t offset, |
| 1685 | size_t length) |
| 1686 | { |
| 1687 | void *res; |
| 1688 | if (!fi) { return GRN_CALLOC(length); } |
| 1689 | /* file must be exceeded to GRN_IO_FILE_SIZE_V0 when FileMappingObject created. |
| 1690 | and, after fmo created, it's not allowed to expand the size of file. |
| 1691 | DWORD tail = (DWORD)(offset + length); |
| 1692 | DWORD filesize = GetFileSize(fi->fh, NULL); |
| 1693 | if (filesize < tail) { |
| 1694 | if (SetFilePointer(fi->fh, tail, NULL, FILE_BEGIN) != tail) { |
| 1695 | grn_log("SetFilePointer failed"); |
| 1696 | return NULL; |
| 1697 | } |
| 1698 | if (!SetEndOfFile(fi->fh)) { |
| 1699 | grn_log("SetEndOfFile failed"); |
| 1700 | return NULL; |
| 1701 | } |
| 1702 | filesize = tail; |
| 1703 | } |
| 1704 | */ |
| 1705 | res = MapViewOfFile(fi->fmo, FILE_MAP_WRITE, 0, (DWORD)offset, (SIZE_T)length); |
| 1706 | if (!res) { |
| 1707 | MERR("MapViewOfFile failed: <%" GRN_FMT_SIZE ">: %s", |
| 1708 | mmap_size, grn_current_error_message()); |
| 1709 | return NULL; |
| 1710 | } |
| 1711 | mmap_size += length; |
| 1712 | return res; |
| 1713 | } |
| 1714 | |
| 1715 | inline static int |
| 1716 | grn_munmap_v0(grn_ctx *ctx, grn_ctx *owner_ctx, fileinfo *fi, void *start, |
| 1717 | size_t length) |
| 1718 | { |
| 1719 | if (!fi) { |
| 1720 | GRN_FREE(start); |
| 1721 | return 0; |
| 1722 | } |
| 1723 | |
| 1724 | if (UnmapViewOfFile(start)) { |
| 1725 | mmap_size -= length; |
| 1726 | return 0; |
| 1727 | } else { |
| 1728 | SERR("UnmapViewOfFile(%p,%" GRN_FMT_SIZE ") failed <%" GRN_FMT_SIZE ">", |
| 1729 | start, length, mmap_size); |
| 1730 | return -1; |
| 1731 | } |
| 1732 | } |
| 1733 | |
| 1734 | inline static grn_rc |
| 1735 | grn_fileinfo_open_common(grn_ctx *ctx, fileinfo *fi, const char *path, int flags) |
| 1736 | { |
| 1737 | /* may be wrong if flags is just only O_RDWR */ |
| 1738 | if ((flags & O_CREAT)) { |
| 1739 | DWORD dwCreationDisposition; |
| 1740 | const char *flags_description; |
| 1741 | if (flags & O_EXCL) { |
| 1742 | dwCreationDisposition = CREATE_NEW; |
| 1743 | flags_description = "O_RDWR|O_CREAT|O_EXCL"; |
| 1744 | } else { |
| 1745 | dwCreationDisposition = OPEN_ALWAYS; |
| 1746 | flags_description = "O_RDWR|O_CREAT"; |
| 1747 | } |
| 1748 | fi->fh = CreateFile(path, GRN_IO_FILE_CREATE_MODE, |
| 1749 | FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, |
| 1750 | NULL, |
| 1751 | dwCreationDisposition, FILE_ATTRIBUTE_NORMAL, 0); |
| 1752 | if (fi->fh == INVALID_HANDLE_VALUE) { |
| 1753 | SERR("CreateFile(<%s>, <%s>) failed", |
| 1754 | path, flags_description); |
| 1755 | goto exit; |
| 1756 | } |
| 1757 | |
| 1758 | switch (dwCreationDisposition) { |
| 1759 | case CREATE_NEW : |
| 1760 | GRN_LOG(ctx, GRN_LOG_INFO, |
| 1761 | "[io][open] create new file: <%s>", path); |
| 1762 | break; |
| 1763 | case OPEN_ALWAYS : |
| 1764 | if (GetLastError() == ERROR_ALREADY_EXISTS) { |
| 1765 | GRN_LOG(ctx, GRN_LOG_INFO, |
| 1766 | "[io][open] open existing file because it exists: <%s>", path); |
| 1767 | } else { |
| 1768 | GRN_LOG(ctx, GRN_LOG_INFO, |
| 1769 | "[io][open] create new file because it doesn't exist: <%s>", |
| 1770 | path); |
| 1771 | } |
| 1772 | break; |
| 1773 | default : |
| 1774 | break; |
| 1775 | } |
| 1776 | |
| 1777 | if (grn_io_use_sparse) { |
| 1778 | FILE_SET_SPARSE_BUFFER buffer; |
| 1779 | buffer.SetSparse = TRUE; |
| 1780 | DWORD returned_bytes; |
| 1781 | if (!DeviceIoControl(fi->fh, |
| 1782 | FSCTL_SET_SPARSE, |
| 1783 | &buffer, |
| 1784 | sizeof(FILE_SET_SPARSE_BUFFER), |
| 1785 | NULL, |
| 1786 | 0, |
| 1787 | &returned_bytes, |
| 1788 | NULL)) { |
| 1789 | GRN_LOG(ctx, GRN_LOG_INFO, |
| 1790 | "Tried to make file sparse but failed: " |
| 1791 | "DeviceIoControl(FSCTL_SET_SPARSE): " |
| 1792 | "<%s>: <%s>", |
| 1793 | path, grn_current_error_message()); |
| 1794 | } |
| 1795 | } |
| 1796 | |
| 1797 | goto exit; |
| 1798 | } |
| 1799 | |
| 1800 | if ((flags & O_TRUNC)) { |
| 1801 | CloseHandle(fi->fh); |
| 1802 | /* unable to assign OPEN_ALWAYS and TRUNCATE_EXISTING at once */ |
| 1803 | fi->fh = CreateFile(path, GRN_IO_FILE_CREATE_MODE, |
| 1804 | FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, |
| 1805 | NULL, |
| 1806 | TRUNCATE_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); |
| 1807 | if (fi->fh == INVALID_HANDLE_VALUE) { |
| 1808 | SERR("CreateFile(<%s>, <O_RDWR|O_TRUNC>) failed", |
| 1809 | path); |
| 1810 | goto exit; |
| 1811 | } |
| 1812 | GRN_LOG(ctx, GRN_LOG_INFO, |
| 1813 | "[io][open] truncated: <%s>", path); |
| 1814 | goto exit; |
| 1815 | } |
| 1816 | /* O_RDWR only */ |
| 1817 | fi->fh = CreateFile(path, GRN_IO_FILE_CREATE_MODE, |
| 1818 | FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, |
| 1819 | NULL, |
| 1820 | OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); |
| 1821 | if (fi->fh == INVALID_HANDLE_VALUE) { |
| 1822 | SERR("CreateFile(<%s>, <O_RDWR>) failed", |
| 1823 | path); |
| 1824 | goto exit; |
| 1825 | } |
| 1826 | GRN_LOG(ctx, GRN_LOG_INFO, |
| 1827 | "[io][open] open existing file: <%s>", path); |
| 1828 | |
| 1829 | exit : |
| 1830 | return ctx->rc; |
| 1831 | } |
| 1832 | |
| 1833 | inline static grn_rc |
| 1834 | grn_fileinfo_open(grn_ctx *ctx, fileinfo *fi, const char *path, int flags) |
| 1835 | { |
| 1836 | grn_rc rc; |
| 1837 | struct _grn_io_header io_header; |
| 1838 | LARGE_INTEGER file_size; |
| 1839 | int version = grn_io_version_default; |
| 1840 | |
| 1841 | rc = grn_fileinfo_open_common(ctx, fi, path, flags); |
| 1842 | if (rc != GRN_SUCCESS) { |
| 1843 | if (fi->fh) { |
| 1844 | CloseHandle(fi->fh); |
| 1845 | fi->fh = INVALID_HANDLE_VALUE; |
| 1846 | } |
| 1847 | return rc; |
| 1848 | } |
| 1849 | |
| 1850 | if (GetFileSizeEx(fi->fh, &file_size) && file_size.QuadPart > 0) { |
| 1851 | DWORD header_size; |
| 1852 | DWORD read_bytes; |
| 1853 | header_size = sizeof(struct _grn_io_header); |
| 1854 | ReadFile(fi->fh, &io_header, header_size, &read_bytes, NULL); |
| 1855 | if (read_bytes == header_size) { |
| 1856 | version = io_header.version; |
| 1857 | } |
| 1858 | SetFilePointer(fi->fh, 0, NULL, FILE_BEGIN); |
| 1859 | } |
| 1860 | |
| 1861 | if (version == 0) { |
| 1862 | return grn_fileinfo_open_v0(ctx, fi, path, flags); |
| 1863 | } else { |
| 1864 | return grn_fileinfo_open_v1(ctx, fi, path, flags); |
| 1865 | } |
| 1866 | } |
| 1867 | |
| 1868 | inline static int |
| 1869 | grn_guess_io_version(grn_ctx *ctx, grn_io *io, fileinfo *fi) |
| 1870 | { |
| 1871 | if (io) { |
| 1872 | return io->header->version; |
| 1873 | } |
| 1874 | |
| 1875 | if (fi) { |
| 1876 | if (fi->fmo) { |
| 1877 | return 0; |
| 1878 | } else { |
| 1879 | return 1; |
| 1880 | } |
| 1881 | } |
| 1882 | |
| 1883 | return grn_io_version_default; |
| 1884 | } |
| 1885 | |
| 1886 | inline static void * |
| 1887 | grn_mmap(grn_ctx *ctx, grn_ctx *owner_ctx, grn_io *io, HANDLE *fmo, |
| 1888 | fileinfo *fi, off_t offset, size_t length) |
| 1889 | { |
| 1890 | int version; |
| 1891 | |
| 1892 | version = grn_guess_io_version(ctx, io, fi); |
| 1893 | |
| 1894 | if (version == 0) { |
| 1895 | return grn_mmap_v0(ctx, owner_ctx, fi, offset, length); |
| 1896 | } else { |
| 1897 | return grn_mmap_v1(ctx, owner_ctx, fmo, fi, offset, length); |
| 1898 | } |
| 1899 | } |
| 1900 | |
| 1901 | inline static int |
| 1902 | grn_munmap(grn_ctx *ctx, grn_ctx *owner_ctx, grn_io *io, |
| 1903 | HANDLE *fmo, fileinfo *fi, void *start, size_t length) |
| 1904 | { |
| 1905 | int version; |
| 1906 | |
| 1907 | version = grn_guess_io_version(ctx, io, fi); |
| 1908 | |
| 1909 | if (version == 0) { |
| 1910 | return grn_munmap_v0(ctx, owner_ctx, fi, start, length); |
| 1911 | } else { |
| 1912 | return grn_munmap_v1(ctx, owner_ctx, fmo, fi, start, length); |
| 1913 | } |
| 1914 | } |
| 1915 | |
| 1916 | inline static grn_rc |
| 1917 | grn_fileinfo_close(grn_ctx *ctx, fileinfo *fi) |
| 1918 | { |
| 1919 | if (fi->fmo != NULL) { |
| 1920 | CloseHandle(fi->fmo); |
| 1921 | fi->fmo = NULL; |
| 1922 | } |
| 1923 | if (fi->fh != INVALID_HANDLE_VALUE) { |
| 1924 | CloseHandle(fi->fh); |
| 1925 | CRITICAL_SECTION_FIN(fi->cs); |
| 1926 | fi->fh = INVALID_HANDLE_VALUE; |
| 1927 | } |
| 1928 | return GRN_SUCCESS; |
| 1929 | } |
| 1930 | |
| 1931 | inline static void |
| 1932 | grn_fileinfo_init(fileinfo *fis, int nfis) |
| 1933 | { |
| 1934 | for (; nfis--; fis++) { |
| 1935 | fis->fh = INVALID_HANDLE_VALUE; |
| 1936 | fis->fmo = NULL; |
| 1937 | } |
| 1938 | } |
| 1939 | |
| 1940 | inline static int |
| 1941 | grn_fileinfo_opened(fileinfo *fi) |
| 1942 | { |
| 1943 | return fi->fh != INVALID_HANDLE_VALUE; |
| 1944 | } |
| 1945 | |
| 1946 | inline static int |
| 1947 | grn_msync(grn_ctx *ctx, HANDLE handle, void *start, size_t length) |
| 1948 | { |
| 1949 | BOOL succeeded; |
| 1950 | SYSTEMTIME system_time; |
| 1951 | FILETIME file_time; |
| 1952 | |
| 1953 | succeeded = FlushViewOfFile(start, length); |
| 1954 | if (!succeeded) { |
| 1955 | SERR("FlushViewOfFile(<%p>, <%" GRN_FMT_SIZE ">) failed", |
| 1956 | start, length); |
| 1957 | return -1; |
| 1958 | } |
| 1959 | |
| 1960 | if (handle == INVALID_HANDLE_VALUE) { |
| 1961 | return 0; |
| 1962 | } |
| 1963 | |
| 1964 | GetSystemTime(&system_time); |
| 1965 | succeeded = SystemTimeToFileTime(&system_time, &file_time); |
| 1966 | if (!succeeded) { |
| 1967 | SERR("SystemTimeToFileTime(<%04u-%02u-%02uT%02u:%02u:%02u.%03u>) failed", |
| 1968 | system_time.wYear, |
| 1969 | system_time.wMonth, |
| 1970 | system_time.wDay, |
| 1971 | system_time.wHour, |
| 1972 | system_time.wMinute, |
| 1973 | system_time.wSecond, |
| 1974 | system_time.wMilliseconds); |
| 1975 | return -1; |
| 1976 | } |
| 1977 | |
| 1978 | succeeded = SetFileTime(handle, NULL, NULL, &file_time); |
| 1979 | if (!succeeded) { |
| 1980 | SERR("SetFileTime(<%p>, <%p>, <%" GRN_FMT_SIZE ">) failed", |
| 1981 | handle, start, length); |
| 1982 | return -1; |
| 1983 | } |
| 1984 | |
| 1985 | return 0; |
| 1986 | } |
| 1987 | |
| 1988 | inline static grn_rc |
| 1989 | grn_pread(grn_ctx *ctx, fileinfo *fi, void *buf, size_t count, off_t offset) |
| 1990 | { |
| 1991 | DWORD r, len; |
| 1992 | CRITICAL_SECTION_ENTER(fi->cs); |
| 1993 | r = SetFilePointer(fi->fh, offset, NULL, FILE_BEGIN); |
| 1994 | if (r == INVALID_SET_FILE_POINTER) { |
| 1995 | SERR("SetFilePointer"); |
| 1996 | } else { |
| 1997 | if (!ReadFile(fi->fh, buf, (DWORD)count, &len, NULL)) { |
| 1998 | SERR("ReadFile"); |
| 1999 | } else if (len != count) { |
| 2000 | /* todo : should retry ? */ |
| 2001 | ERR(GRN_INPUT_OUTPUT_ERROR, |
| 2002 | "ReadFile %" GRN_FMT_SIZE " != %lu", |
| 2003 | count, len); |
| 2004 | } |
| 2005 | } |
| 2006 | CRITICAL_SECTION_LEAVE(fi->cs); |
| 2007 | return ctx->rc; |
| 2008 | } |
| 2009 | |
| 2010 | inline static grn_rc |
| 2011 | grn_pwrite(grn_ctx *ctx, fileinfo *fi, void *buf, size_t count, off_t offset) |
| 2012 | { |
| 2013 | DWORD r, len; |
| 2014 | CRITICAL_SECTION_ENTER(fi->cs); |
| 2015 | r = SetFilePointer(fi->fh, offset, NULL, FILE_BEGIN); |
| 2016 | if (r == INVALID_SET_FILE_POINTER) { |
| 2017 | SERR("SetFilePointer"); |
| 2018 | } else { |
| 2019 | if (!WriteFile(fi->fh, buf, (DWORD)count, &len, NULL)) { |
| 2020 | SERR("WriteFile"); |
| 2021 | } else if (len != count) { |
| 2022 | /* todo : should retry ? */ |
| 2023 | ERR(GRN_INPUT_OUTPUT_ERROR, |
| 2024 | "WriteFile %" GRN_FMT_SIZE " != %lu", |
| 2025 | count, len); |
| 2026 | } |
| 2027 | } |
| 2028 | CRITICAL_SECTION_LEAVE(fi->cs); |
| 2029 | return ctx->rc; |
| 2030 | } |
| 2031 | |
| 2032 | #else /* WIN32 */ |
| 2033 | |
| 2034 | inline static grn_rccxx . . $ grn_rc# |
| 2035 | grn_fileinfo_opencxx . . $ grn_fileinfo_open(ac8f5bf2db69e073).(grn_ctxcxx . . $ grn_ctx# *ctx, fileinfocxx . . $ fileinfo# *fi, const char *path, int flags) |
| 2036 | { |
| 2037 | struct statcxx . . $ stat# st; |
| 2038 | grn_opencxx . . $ `storage/mroonga/vendor/groonga/include/groonga/portability.h:175:10`!(fi->fd, path, flags); |
| 2039 | if (fi->fdcxx . . $ _grn_io_fileinfo#fd. == -1) { |
| 2040 | ERRNO_ERRcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_ctx.h:403:9`!("failed to open file info path: <%s>", |
| 2041 | path); |
| 2042 | return ctx->rccxx . . $ _grn_ctx#rc.; |
| 2043 | } |
| 2044 | if (fstatcxx . . $ fstat(a43660ce2f600cb5).(fi->fdcxx . . $ _grn_io_fileinfo#fd., &st) == -1) { |
| 2045 | ERRNO_ERRcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_ctx.h:403:9`!("failed to stat file info path: <%s>", |
| 2046 | path); |
| 2047 | return ctx->rccxx . . $ _grn_ctx#rc.; |
| 2048 | } |
| 2049 | fi->devcxx . . $ _grn_io_fileinfo#dev. = st.st_devcxx . . $ stat#st_dev.; |
| 2050 | fi->inodecxx . . $ _grn_io_fileinfo#inode. = st.st_inocxx . . $ stat#st_ino.; |
| 2051 | return GRN_SUCCESScxx . . $ GRN_SUCCESS.; |
| 2052 | } |
| 2053 | |
| 2054 | inline static void |
| 2055 | grn_fileinfo_initcxx . . $ grn_fileinfo_init(f06d8a745bb74b52).(fileinfocxx . . $ fileinfo# *fis, int nfis) |
| 2056 | { |
| 2057 | for (; nfis--; fis++) { fis->fdcxx . . $ _grn_io_fileinfo#fd. = -1; } |
| 2058 | } |
| 2059 | |
| 2060 | inline static int |
| 2061 | grn_fileinfo_openedcxx . . $ grn_fileinfo_opened(600504bf85ebe923).(fileinfocxx . . $ fileinfo# *fi) |
| 2062 | { |
| 2063 | return fi->fdcxx . . $ _grn_io_fileinfo#fd. != -1; |
| 2064 | } |
| 2065 | |
| 2066 | inline static grn_rccxx . . $ grn_rc# |
| 2067 | grn_fileinfo_closecxx . . $ grn_fileinfo_close(91b895c7c0cdf7c3).(grn_ctxcxx . . $ grn_ctx# *ctx, fileinfocxx . . $ fileinfo# *fi) |
| 2068 | { |
| 2069 | if (fi->fdcxx . . $ _grn_io_fileinfo#fd. != -1) { |
| 2070 | if (grn_closecxx . . $ `storage/mroonga/vendor/groonga/include/groonga/portability.h:182:10`!(fi->fd) == -1) { |
| 2071 | SERRcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_ctx.h:332:9`!("close"); |
| 2072 | return ctx->rccxx . . $ _grn_ctx#rc.; |
| 2073 | } |
| 2074 | fi->fdcxx . . $ _grn_io_fileinfo#fd. = -1; |
| 2075 | } |
| 2076 | return GRN_SUCCESScxx . . $ GRN_SUCCESS.; |
| 2077 | } |
| 2078 | |
| 2079 | #if defined(MAP_ANONcxx . . $ `<external>/17226767460805440860/mman-linux.h:57:9`!) && !defined(MAP_ANONYMOUScxx . . $ `<external>/17226767460805440860/mman-linux.h:55:10`!) |
| 2080 | #define MAP_ANONYMOUS MAP_ANON |
| 2081 | #endif |
| 2082 | |
| 2083 | #include <sys/mman.h> |
| 2084 | |
| 2085 | inline static void * |
| 2086 | grn_mmapcxx . . $ grn_mmap(eae34eb82c337900).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_ctxcxx . . $ grn_ctx# *owner_ctx, grn_iocxx . . $ grn_io# *io, fileinfocxx . . $ fileinfo# *fi, |
| 2087 | off_tcxx . . $ off_t# offset, size_t length) |
| 2088 | { |
| 2089 | void *res; |
| 2090 | int fd, flags; |
| 2091 | if (fi) { |
| 2092 | struct statcxx . . $ stat# s; |
| 2093 | off_tcxx . . $ off_t# tail = offset + length; |
| 2094 | fd = fi->fdcxx . . $ _grn_io_fileinfo#fd.; |
| 2095 | if ((fstatcxx . . $ fstat(a43660ce2f600cb5).(fd, &s) == -1) || (s.st_sizecxx . . $ stat#st_size. < tail && ftruncatecxx . . $ ftruncate(bba9d6e9fb34fad7).(fd, tail) == -1)) { |
| 2096 | SERRcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_ctx.h:332:9`!("fstat"); |
| 2097 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 2098 | } |
| 2099 | flags = MAP_SHAREDcxx . . $ `<external>/17226767460805440860/mman-linux.h:42:9`!; |
| 2100 | } else { |
| 2101 | fd = -1; |
| 2102 | flags = MAP_PRIVATEcxx . . $ `<external>/17226767460805440860/mman-linux.h:43:9`!|MAP_ANONYMOUScxx . . $ `<external>/17226767460805440860/mman-linux.h:55:10`!; |
| 2103 | } |
| 2104 | res = mmapcxx . . $ mmap(ff06c1c904cdf0e2).(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, length, PROT_READcxx . . $ `<external>/17226767460805440860/mman-linux.h:32:9`!|PROT_WRITEcxx . . $ `<external>/17226767460805440860/mman-linux.h:33:9`!, flags, fd, offset); |
| 2105 | if (MAP_FAILEDcxx . . $ `<external>/6724834311684550606/mman.h:44:9`! == res) { |
| 2106 | MERRcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_ctx.h:145:9`!("mmap(%" GRN_FMT_LLUcxx . . $ `storage/mroonga/vendor/groonga/lib/grn.h:472:10`! ",%d,%" GRN_FMT_LLDcxx . . $ `storage/mroonga/vendor/groonga/lib/grn.h:471:10`! ")=%s <%" GRN_FMT_LLUcxx . . $ `storage/mroonga/vendor/groonga/lib/grn.h:472:10`! ">", |
| 2107 | (unsigned long long int)length, fd, (long long int)offset, |
| 2108 | strerror(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!), (unsigned long long int)mmap_size); |
| 2109 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 2110 | } |
| 2111 | mmap_sizecxx . . $ mmap_size. += length; |
| 2112 | return res; |
| 2113 | } |
| 2114 | |
| 2115 | #ifdef USE_FAIL_MALLOC |
| 2116 | inline static void * |
| 2117 | grn_fail_mmap(grn_ctx *ctx, grn_ctx *owner_ctx, grn_io *io, fileinfo *fi, |
| 2118 | off_t offset, size_t length, |
| 2119 | const char* file, int line, const char *func) |
| 2120 | { |
| 2121 | if (grn_fail_malloc_check(length, file, line, func)) { |
| 2122 | return grn_mmap(ctx, io, fi, offset, length); |
| 2123 | } else { |
| 2124 | MERR("fail_mmap(%" GRN_FMT_SIZE ",%d,%" GRN_FMT_LLU ") " |
| 2125 | "(%s:%d@%s) <%" GRN_FMT_SIZE ">", |
| 2126 | length, |
| 2127 | fi ? fi->fd : 0, |
| 2128 | (long long unsigned int)offset, |
| 2129 | file, |
| 2130 | line, |
| 2131 | func, |
| 2132 | mmap_size); |
| 2133 | return NULL; |
| 2134 | } |
| 2135 | } |
| 2136 | #endif /* USE_FAIL_MALLOC */ |
| 2137 | |
| 2138 | inline static int |
| 2139 | grn_msynccxx . . $ grn_msync(7850c81bf663d613).(grn_ctxcxx . . $ grn_ctx# *ctx, void *start, size_t length) |
| 2140 | { |
| 2141 | int r = msynccxx . . $ msync(e72f86de37bb8b46).(start, length, MS_SYNCcxx . . $ `<external>/17226767460805440860/mman-linux.h:83:9`!); |
| 2142 | if (r == -1) { SERRcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_ctx.h:332:9`!("msync"); } |
| 2143 | return r; |
| 2144 | } |
| 2145 | |
| 2146 | inline static int |
| 2147 | grn_munmapcxx . . $ grn_munmap(d6c6eff378d3be7).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_ctxcxx . . $ grn_ctx# *owner_ctx, grn_iocxx . . $ grn_io# *io, fileinfocxx . . $ fileinfo# *fi, |
| 2148 | void *start, size_t length) |
| 2149 | { |
| 2150 | int res; |
| 2151 | res = munmapcxx . . $ munmap(c0a5f96701d3f89).(start, length); |
| 2152 | if (res) { |
| 2153 | SERRcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_ctx.h:332:9`!("munmap(%p,%" GRN_FMT_LLUcxx . . $ `storage/mroonga/vendor/groonga/lib/grn.h:472:10`! ") failed <%" GRN_FMT_LLUcxx . . $ `storage/mroonga/vendor/groonga/lib/grn.h:472:10`! ">", |
| 2154 | start, |
| 2155 | (unsigned long long int)length, |
| 2156 | (unsigned long long int)mmap_size); |
| 2157 | } else { |
| 2158 | mmap_sizecxx . . $ mmap_size. -= length; |
| 2159 | } |
| 2160 | return res; |
| 2161 | } |
| 2162 | |
| 2163 | inline static grn_rccxx . . $ grn_rc# |
| 2164 | grn_preadcxx . . $ grn_pread(4577714838bf4b55).(grn_ctxcxx . . $ grn_ctx# *ctx, fileinfocxx . . $ fileinfo# *fi, void *buf, size_t count, off_tcxx . . $ off_t# offset) |
| 2165 | { |
| 2166 | ssize_tcxx . . $ ssize_t# r = preadcxx . . $ pread(b119fdc0c07358b4).(fi->fdcxx . . $ _grn_io_fileinfo#fd., buf, count, offset); |
| 2167 | if (r != (ssize_tcxx . . $ ssize_t#) count) { |
| 2168 | if (r == -1) { |
| 2169 | SERRcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_ctx.h:332:9`!("pread"); |
| 2170 | } else { |
| 2171 | /* todo : should retry ? */ |
| 2172 | ERRcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_ctx.h:143:9`!(GRN_INPUT_OUTPUT_ERROR, |
| 2173 | "pread returned %" GRN_FMT_LLDcxx . . $ `storage/mroonga/vendor/groonga/lib/grn.h:471:10`! " != %" GRN_FMT_LLUcxx . . $ `storage/mroonga/vendor/groonga/lib/grn.h:472:10`!, |
| 2174 | (long long int)r, (unsigned long long int)count); |
| 2175 | } |
| 2176 | return ctx->rccxx . . $ _grn_ctx#rc.; |
| 2177 | } |
| 2178 | return GRN_SUCCESScxx . . $ GRN_SUCCESS.; |
| 2179 | } |
| 2180 | |
| 2181 | inline static grn_rccxx . . $ grn_rc# |
| 2182 | grn_pwritecxx . . $ grn_pwrite(4577714838bf4b55).(grn_ctxcxx . . $ grn_ctx# *ctx, fileinfocxx . . $ fileinfo# *fi, void *buf, size_t count, off_tcxx . . $ off_t# offset) |
| 2183 | { |
| 2184 | ssize_tcxx . . $ ssize_t# r = pwritecxx . . $ pwrite(6a64eb0a75db039).(fi->fdcxx . . $ _grn_io_fileinfo#fd., buf, count, offset); |
| 2185 | if (r != (ssize_tcxx . . $ ssize_t#) count) { |
| 2186 | if (r == -1) { |
| 2187 | SERRcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_ctx.h:332:9`!("pwrite"); |
| 2188 | } else { |
| 2189 | /* todo : should retry ? */ |
| 2190 | ERRcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_ctx.h:143:9`!(GRN_INPUT_OUTPUT_ERROR, |
| 2191 | "pwrite returned %" GRN_FMT_LLDcxx . . $ `storage/mroonga/vendor/groonga/lib/grn.h:471:10`! " != %" GRN_FMT_LLUcxx . . $ `storage/mroonga/vendor/groonga/lib/grn.h:472:10`!, |
| 2192 | (long long int)r, (unsigned long long int)count); |
| 2193 | } |
| 2194 | return ctx->rccxx . . $ _grn_ctx#rc.; |
| 2195 | } |
| 2196 | return GRN_SUCCESScxx . . $ GRN_SUCCESS.; |
| 2197 | } |
| 2198 | |
| 2199 | #endif /* WIN32 */ |