1 /**************************************************************************** 2 * drivers/bch/bch.h 3 * 4 * Licensed to the Apache Software Foundation (ASF) under one or more 5 * contributor license agreements. See the NOTICE file distributed with 6 * this work for additional information regarding copyright ownership. The 7 * ASF licenses this file to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance with the 9 * License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, software 14 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 15 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 16 * License for the specific language governing permissions and limitations 17 * under the License. 18 * 19 ****************************************************************************/ 20 21 #ifndef __DRIVERS_BCH_BCH_H 22 #define __DRIVERS_BCH_BCH_H 23 24 /**************************************************************************** 25 * Included Files 26 ****************************************************************************/ 27 28 #include <sys/types.h> 29 #include <stdint.h> 30 #include <stdbool.h> 31 #include <semaphore.h> 32 #include "fs/fs.h" 33 #include "disk.h" 34 #include "user_copy.h" 35 36 /**************************************************************************** 37 * Pre-processor Definitions 38 ****************************************************************************/ 39 40 #define bchlib_semgive(d) (void)sem_post(&(d)->sem) /* To match bchlib_semtake */ 41 #define MAX_OPENCNT (255) /* Limit of uint8_t */ 42 #define DIOC_GETPRIV (0x1000) 43 44 /**************************************************************************** 45 * Public Types 46 ****************************************************************************/ 47 48 struct bchlib_s 49 { 50 struct Vnode *vnode; /* I-node of the block driver */ 51 uint32_t sectsize; /* The size of one sector on the device */ 52 unsigned long long nsectors; /* Number of sectors supported by the device */ 53 unsigned long long sector; /* The current sector in the buffer */ 54 sem_t sem; /* For atomic accesses to this structure */ 55 uint8_t refs; /* Number of references */ 56 bool dirty; /* true: Data has been written to the buffer */ 57 bool readonly; /* true: Only read operations are supported */ 58 bool unlinked; /* true: The driver has been unlinked */ 59 uint8_t *buffer; /* One sector buffer */ 60 los_disk *disk; 61 unsigned long long sectstart; 62 }; 63 64 /**************************************************************************** 65 * Public Data 66 ****************************************************************************/ 67 68 #undef EXTERN 69 #if defined(__cplusplus) 70 #define EXTERN extern "C" 71 extern "C" { 72 #else 73 #define EXTERN extern 74 #endif 75 76 EXTERN const struct file_operations_vfs bch_fops; 77 78 /**************************************************************************** 79 * Public Function Prototypes 80 ****************************************************************************/ 81 82 EXTERN void bchlib_semtake(struct bchlib_s *bch); 83 EXTERN int bchlib_flushsector(struct bchlib_s *bch); 84 EXTERN int bchlib_readsector(struct bchlib_s *bch, unsigned long long sector); 85 EXTERN int bchlib_setup(const char *blkdev, bool readonly, void **handle); 86 EXTERN int bchlib_teardown(void *handle); 87 EXTERN ssize_t bchlib_read(void *handle, char *buffer, loff_t offset, size_t len); 88 EXTERN ssize_t bchlib_write(void *handle, const char *buffer, loff_t offset, size_t len); 89 90 #undef EXTERN 91 #if defined(__cplusplus) 92 } 93 #endif 94 95 #endif /* __DRIVERS_BCH_BCH_H */ 96