subrascasse

Sub Rascasse: an iPhone dive log for Subsurface cloud storage, with a pure-Swift git client (GPL-2.0)
git clone https://git.schurger.org/subrascasse.git
Log | Files | Refs | README | LICENSE

ioctl.h (2197B)


      1 /*
      2  * libdivecomputer
      3  *
      4  * Copyright (C) 2019 Jef Driesen
      5  *
      6  * This library is free software; you can redistribute it and/or
      7  * modify it under the terms of the GNU Lesser General Public
      8  * License as published by the Free Software Foundation; either
      9  * version 2.1 of the License, or (at your option) any later version.
     10  *
     11  * This library is distributed in the hope that it will be useful,
     12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     14  * Lesser General Public License for more details.
     15  *
     16  * You should have received a copy of the GNU Lesser General Public
     17  * License along with this library; if not, write to the Free Software
     18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
     19  * MA 02110-1301 USA
     20  */
     21 
     22 #ifndef DC_IOCTL_H
     23 #define DC_IOCTL_H
     24 
     25 #ifdef __cplusplus
     26 extern "C" {
     27 #endif /* __cplusplus */
     28 
     29 /*
     30  * Ioctl direction bits.
     31  *
     32  * Note: WRITE means the application is writing and the driver is
     33  * reading. READ means the application is reading and the driver is
     34  * writing.
     35  */
     36 #define DC_IOCTL_DIR_NONE  0u
     37 #define DC_IOCTL_DIR_READ  1u
     38 #define DC_IOCTL_DIR_WRITE 2u
     39 
     40 /*
     41  * Ioctl variable size bits.
     42  */
     43 #define DC_IOCTL_SIZE_VARIABLE 0
     44 
     45 /*
     46  * Helper macro to encode ioctl numbers.
     47  */
     48 #define DC_IOCTL_BASE(dir,type,nr,size) \
     49 	(((dir)  << 30) | \
     50 	 ((size) << 16) | \
     51 	 ((type) <<  8) | \
     52 	 ((nr)   <<  0))
     53 
     54 /*
     55  * Macros to encode ioctl numbers.
     56  */
     57 #define DC_IOCTL_IO(type,nr)        DC_IOCTL_BASE(DC_IOCTL_DIR_NONE, (type), (nr), 0)
     58 #define DC_IOCTL_IOR(type,nr,size)  DC_IOCTL_BASE(DC_IOCTL_DIR_READ, (type), (nr), (size))
     59 #define DC_IOCTL_IOW(type,nr,size)  DC_IOCTL_BASE(DC_IOCTL_DIR_WRITE, (type), (nr), (size))
     60 #define DC_IOCTL_IORW(type,nr,size) DC_IOCTL_BASE(DC_IOCTL_DIR_READ | DC_IOCTL_DIR_WRITE, (type), (nr), (size))
     61 
     62 /*
     63  * Macros to decode ioctl numbers.
     64  */
     65 #define DC_IOCTL_DIR(request)  (((request) >> 30) & 0x0003)
     66 #define DC_IOCTL_SIZE(request) (((request) >> 16) & 0x3FFF)
     67 #define DC_IOCTL_TYPE(request) (((request) >>  8) & 0x00FF)
     68 #define DC_IOCTL_NR(request)   (((request) >>  0) & 0x00FF)
     69 
     70 #ifdef __cplusplus
     71 }
     72 #endif /* __cplusplus */
     73 #endif /* DC_IOCTL_H */