Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

file: refactored the file layer so it only implements business logic #86

Merged
merged 16 commits into from
Jul 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion deps/crc32/crc32.c
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ crc_t crc_update(crc_t crc, const void *data, size_t data_len)
const uint32_t *d32 = (const uint32_t *)d;
while (data_len >= 8)
{
#if __BYTE_ORDER == __BIG_ENDIAN
#if defined(__BYTE_ORDER) && __BYTE_ORDER == __BIG_ENDIAN
crc_t d1 = *d32++ ^ le16toh(crc);
crc_t d2 = *d32++;
crc =
Expand Down
11 changes: 7 additions & 4 deletions include/chunkio/cio_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,8 @@ struct cio_file {
char *path; /* root path + stream */
char *map; /* map of data */
#ifdef _WIN32
void *h;
crc_t crc_be;
int map_synced;
HANDLE backing_file;
HANDLE backing_mapping;
#endif
/* cached addr */
char *st_content;
Expand All @@ -61,7 +60,7 @@ void cio_file_close(struct cio_chunk *ch, int delete);
int cio_file_write(struct cio_chunk *ch, const void *buf, size_t count);
int cio_file_write_metadata(struct cio_chunk *ch, char *buf, size_t size);
int cio_file_sync(struct cio_chunk *ch);
int cio_file_fs_size_change(struct cio_file *cf, size_t new_size);
int cio_file_resize(struct cio_file *cf, size_t new_size);
char *cio_file_hash(struct cio_file *cf);
void cio_file_hash_print(struct cio_file *cf);
void cio_file_calculate_checksum(struct cio_file *cf, crc_t *out);
Expand All @@ -77,5 +76,9 @@ int cio_file_up(struct cio_chunk *ch);
int cio_file_up_force(struct cio_chunk *ch);
int cio_file_lookup_user(char *user, void **result);
int cio_file_lookup_group(char *group, void **result);
int cio_file_update_size(struct cio_file *cf);

#define cio_file_report_runtime_error() { cio_file_native_report_runtime_error(); }
#define cio_file_report_os_error() { cio_file_native_report_os_error(); }

#endif
55 changes: 55 additions & 0 deletions include/chunkio/cio_file_native.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */

/* Chunk I/O
* =========
* Copyright 2018 Eduardo Silva <[email protected]>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef CIO_FILE_NATIVE_H
#define CIO_FILE_NATIVE_H

#include <chunkio/cio_file.h>



#ifdef _WIN32
#define cio_file_native_is_open(cf) (cf->backing_file != INVALID_HANDLE_VALUE)
#define cio_file_native_is_mapped(cf) (cf->backing_mapping != INVALID_HANDLE_VALUE)
#define cio_file_native_report_runtime_error() { cio_errno(); }
#define cio_file_native_report_os_error() { cio_winapi_error(); }
#else
#define cio_file_native_is_open(cf) (cf->fd != -1)
#define cio_file_native_is_mapped(cf) (cf->map != NULL)
#define cio_file_native_report_runtime_error() { cio_errno(); }
#define cio_file_native_report_os_error() { cio_errno(); }
#endif

int cio_file_native_apply_acl_and_settings(struct cio_ctx *ctx, struct cio_file *cf);
char *cio_file_native_compose_path(char *root_path, char *stream_name,
char *chunk_name);
int cio_file_native_unmap(struct cio_file *cf);
int cio_file_native_map(struct cio_file *cf, size_t map_size);
int cio_file_native_remap(struct cio_file *cf, size_t new_size);
int cio_file_native_lookup_user(char *user, void **result);
int cio_file_native_lookup_group(char *group, void **result);
int cio_file_native_get_size(struct cio_file *cf, size_t *file_size);
int cio_file_native_filename_check(char *name);
int cio_file_native_open(struct cio_file *cf);
int cio_file_native_close(struct cio_file *cf);
int cio_file_native_delete(struct cio_file *cf);
int cio_file_native_sync(struct cio_file *cf, int sync_mode);
int cio_file_native_resize(struct cio_file *cf, size_t new_size);

#endif
4 changes: 2 additions & 2 deletions include/chunkio/cio_file_st.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ static inline uint16_t cio_file_st_get_meta_len(char *map)
/* Set metadata length */
static inline void cio_file_st_set_meta_len(char *map, uint16_t len)
{
map[22] = (uint8_t) len >> 8;
map[23] = (uint8_t) len;
map[22] = (uint8_t) (len >> 8);
map[23] = (uint8_t) (len & 0xFF);
}

/* Return pointer to start point of metadata */
Expand Down
3 changes: 2 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
set(src
cio_os.c
cio_log.c
cio_file.c
cio_memfs.c
cio_chunk.c
cio_meta.c
Expand All @@ -27,7 +28,7 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
else()
set(src
${src}
cio_file.c
cio_file_unix.c
)
endif()

Expand Down
Loading