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