1 #ifndef MTOOLS_DEVICE_H 2 #define MTOOLS_DEVICE_H 3 /* Copyright 2021 Alain Knaff. 4 * This file is part of mtools. 5 * 6 * Mtools is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation, either version 3 of the License, or 9 * (at your option) any later version. 10 * 11 * Mtools 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 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with Mtools. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 20 /* Functions needed to work with struct device */ 21 22 #include "llong.h" 23 24 /* Stuff related to particular device definitions are in devices.c 25 (note the plural) */ 26 27 #define SCSI_FLAG 0x001u 28 #define PRIV_FLAG 0x002u 29 #define NOLOCK_FLAG 0x004u 30 #define USE_XDF_FLAG 0x008u 31 #define MFORMAT_ONLY_FLAG 0x010u 32 #define VOLD_FLAG 0x020u 33 #define FLOPPYD_FLAG 0x040u 34 #define FILTER_FLAG 0x080u 35 #define SWAP_FLAG 0x100u 36 37 #define IS_SCSI(x) ((x) && ((x)->misc_flags & SCSI_FLAG)) 38 #define IS_PRIVILEGED(x) ((x) && ((x)->misc_flags & PRIV_FLAG)) 39 #define IS_NOLOCK(x) ((x) && ((x)->misc_flags & NOLOCK_FLAG)) 40 #define IS_MFORMAT_ONLY(x) ((x) && ((x)->misc_flags & MFORMAT_ONLY_FLAG)) 41 #define SHOULD_USE_VOLD(x) ((x)&& ((x)->misc_flags & VOLD_FLAG)) 42 #define SHOULD_USE_XDF(x) ((x)&& ((x)->misc_flags & USE_XDF_FLAG)) 43 #define DO_SWAP(x) ((x) && ((x)->misc_flags & SWAP_FLAG)) 44 45 typedef struct device { 46 const char *name; /* full path to device */ 47 48 char drive; /* the drive letter */ 49 int fat_bits; /* FAT encoding scheme */ 50 51 int mode; /* any special open() flags */ 52 unsigned int tracks; /* tracks */ 53 uint16_t heads; /* heads */ 54 uint16_t sectors; /* sectors */ 55 unsigned int hidden; /* number of hidden sectors. Used for 56 * mformatting partitioned devices */ 57 58 off_t offset; /* skip this many bytes */ 59 60 unsigned int partition; 61 62 unsigned int misc_flags; 63 64 /* Linux only stuff */ 65 uint8_t ssize; 66 unsigned int use_2m; 67 68 char *precmd; /* command to be executed before opening 69 * the drive */ 70 71 /* internal variables */ 72 int file_nr; /* used during parsing */ 73 unsigned int blocksize; /* size of disk block in bytes */ 74 75 unsigned int codepage; /* codepage for shortname encoding */ 76 77 const char *data_map; 78 79 uint32_t tot_sectors; /* Amount of total sectors, more 80 * precise than tracks (in case of 81 * partitions which may take up parts 82 * of a track) */ 83 84 uint16_t sector_size; /* Non-default sector size */ 85 86 const char *cfg_filename; /* used for debugging purposes */ 87 } device_t; 88 89 extern struct device *devices; 90 extern struct device const_devices[]; 91 extern const unsigned int nr_const_devices; 92 93 int lock_dev(int fd, int mode, struct device *dev); 94 95 void precmd(struct device *dev); 96 97 int check_if_sectors_fit(uint32_t tot_sectors, mt_off_t maxBytes, 98 uint32_t sectorSize, char *errmsg); 99 int chs_to_totsectors(struct device *dev, char *errmsg); 100 101 #endif 102