diff --git a/fdasd/fdasd.c b/fdasd/fdasd.c index 806e026e..085d2beb 100644 --- a/fdasd/fdasd.c +++ b/fdasd/fdasd.c @@ -11,6 +11,7 @@ #include #include +#include "lib/dasd_base.h" #include "lib/dasd_sys.h" #include "lib/util_base.h" #include "lib/util_opt.h" @@ -1228,26 +1229,13 @@ static int fdasd_get_volser(fdasd_anchor_t *anc, char *volser) */ static void fdasd_reread_partition_table(fdasd_anchor_t *anc) { - char err_str[ERROR_STRING_SIZE]; - int fd; - if (!anc->silent) printf("rereading partition table...\n"); - fd = open(options.device, O_RDONLY); - if (fd < 0) { - snprintf(err_str, ERROR_STRING_SIZE, - "Could not open device '%s' " - "in read-only mode!\n", options.device); - fdasd_error(anc, unable_to_open_disk, err_str); - } - - if (ioctl(fd, BLKRRPART, NULL) != 0) { - close(fd); + if (dasd_reread_partition_table(options.device, 1) != 0) { fdasd_error(anc, unable_to_ioctl, "Error while rereading " "partition table.\nPlease reboot!"); } - close(fd); } /* @@ -2092,7 +2080,8 @@ static void fdasd_check_disk_access(fdasd_anchor_t *anc) { char err_str[ERROR_STRING_SIZE]; format1_label_t f1; - int fd, pos, ro; + int fd, pos; + bool ro; fd = open(options.device, O_RDONLY); if (fd == -1) { @@ -2125,7 +2114,9 @@ static void fdasd_check_disk_access(fdasd_anchor_t *anc) fdasd_error(anc, unable_to_seek_disk, err_str); } - if (ioctl(fd, BLKROGET, &ro) != 0) { + close(fd); + + if (dasd_is_ro(options.device, &ro) != 0) { snprintf(err_str, ERROR_STRING_SIZE, "Could not get read-only status for device '%s'.", options.device); @@ -2136,8 +2127,6 @@ static void fdasd_check_disk_access(fdasd_anchor_t *anc) "You will not be able to save any changes.\n\n", options.device); } - - close(fd); } /* @@ -2214,21 +2203,12 @@ static void fdasd_get_geometry(fdasd_anchor_t *anc) struct dasd_eckd_characteristics *characteristics; unsigned long long size_in_bytes; char err_str[ERROR_STRING_SIZE]; - dasd_information_t dasd_info; - int fd, blksize = 0; + dasd_information2_t dasd_info; + unsigned int blksize = 0; - fd = open(options.device, O_RDONLY); - if (fd < 0) { - snprintf(err_str, ERROR_STRING_SIZE, - "Could not open device '%s' " - "in read-only mode!\n", options.device); - fdasd_error(anc, unable_to_open_disk, err_str); - } - if (ioctl(fd, BLKGETSIZE64, &size_in_bytes) != 0) { - close(fd); + if (dasd_get_blocksize_in_bytes(options.device, &size_in_bytes) != 0) fdasd_error(anc, unable_to_ioctl, "Could not retrieve disk size."); - } /* * If anc->force_virtual is set, we do no real geometry detection. * anc->dev_type and anc->blksize have already been set via command @@ -2247,7 +2227,6 @@ static void fdasd_get_geometry(fdasd_anchor_t *anc) geo.start = 0; anc->label_pos = 2 * anc->blksize; anc->devno = 0; - close(fd); if (anc->verbose) { printf("The force option is active. " "The following geometry will be used:\n" @@ -2259,24 +2238,21 @@ static void fdasd_get_geometry(fdasd_anchor_t *anc) return; } - if (ioctl(fd, HDIO_GETGEO, &geo) != 0) { - close(fd); + if (dasd_get_geo(options.device, &geo) != 0) { fdasd_error(anc, unable_to_ioctl, "Could not retrieve disk geometry information."); } - if (ioctl(fd, BLKSSZGET, &blksize) != 0) { - close(fd); + if (dasd_get_blocksize(options.device, &blksize) != 0) { fdasd_error(anc, unable_to_ioctl, "Could not retrieve blocksize information."); } /* get disk type */ - if (ioctl(fd, BIODASDINFO, &dasd_info) != 0) { + if (dasd_get_info(options.device, &dasd_info) != 0) { if (anc->verbose) printf("BIODASDINFO ioctl failed," " use disk geometry only.\n"); /* verify that the geometry matches a 3390 DASD */ if (!fdasd_verify_geometry(DASD_3390_TYPE, blksize, &geo)) { - close(fd); fdasd_error(anc, wrong_disk_type, "Disk geometry does not match a DASD device" " of type 3390."); @@ -2356,8 +2332,6 @@ static void fdasd_get_geometry(fdasd_anchor_t *anc) anc->label_pos = dasd_info.label_block * blksize; anc->devno = dasd_info.devno; } - - close(fd); } /* diff --git a/fdasd/fdasd.h b/fdasd/fdasd.h index fc577236..2fd54fd1 100644 --- a/fdasd/fdasd.h +++ b/fdasd/fdasd.h @@ -14,125 +14,8 @@ * SECTION: Definitions needed for DASD-API (see dasd.h) * *****************************************************************************/ -#define DASD_IOCTL_LETTER 'D' - #define DASD_PARTN_BITS 2 -/* - * struct dasd_information_t - * represents any data about the device, which is visible to userspace. - * including foramt and featueres. - */ -typedef struct dasd_information_t { - unsigned int devno; /* S/390 devno */ - unsigned int real_devno; /* for aliases */ - unsigned int schid; /* S/390 subchannel identifier */ - unsigned int cu_type : 16; /* from SenseID */ - unsigned int cu_model : 8; /* from SenseID */ - unsigned int dev_type : 16; /* from SenseID */ - unsigned int dev_model : 8; /* from SenseID */ - unsigned int open_count; - unsigned int req_queue_len; - unsigned int chanq_len; /* length of chanq */ - char type[4]; /* from discipline.name, 'none' for */ - /* unknown */ - unsigned int status; /* current device level */ - unsigned int label_block; /* where to find the VOLSER */ - unsigned int FBA_layout; /* fixed block size (like AIXVOL) */ - unsigned int characteristics_size; - unsigned int confdata_size; - char characteristics[64]; /* from read_device_characteristics */ - char configuration_data[256]; /* from read_configuration_data */ -} dasd_information_t; - -struct dasd_eckd_characteristics { - unsigned short cu_type; - struct { - unsigned char support:2; - unsigned char async:1; - unsigned char reserved:1; - unsigned char cache_info:1; - unsigned char model:3; - } __attribute__ ((packed)) cu_model; - unsigned short dev_type; - unsigned char dev_model; - struct { - unsigned char mult_burst:1; - unsigned char RT_in_LR:1; - unsigned char reserved1:1; - unsigned char RD_IN_LR:1; - unsigned char reserved2:4; - unsigned char reserved3:8; - unsigned char defect_wr:1; - unsigned char XRC_supported:1; - unsigned char reserved4:1; - unsigned char striping:1; - unsigned char reserved5:4; - unsigned char cfw:1; - unsigned char reserved6:2; - unsigned char cache:1; - unsigned char dual_copy:1; - unsigned char dfw:1; - unsigned char reset_alleg:1; - unsigned char sense_down:1; - } __attribute__ ((packed)) facilities; - unsigned char dev_class; - unsigned char unit_type; - unsigned short no_cyl; - unsigned short trk_per_cyl; - unsigned char sec_per_trk; - unsigned char byte_per_track[3]; - unsigned short home_bytes; - unsigned char formula; - union { - struct { - unsigned char f1; - unsigned short f2; - unsigned short f3; - } __attribute__ ((packed)) f_0x01; - struct { - unsigned char f1; - unsigned char f2; - unsigned char f3; - unsigned char f4; - unsigned char f5; - } __attribute__ ((packed)) f_0x02; - } __attribute__ ((packed)) factors; - unsigned short first_alt_trk; - unsigned short no_alt_trk; - unsigned short first_dia_trk; - unsigned short no_dia_trk; - unsigned short first_sup_trk; - unsigned short no_sup_trk; - unsigned char MDR_ID; - unsigned char OBR_ID; - unsigned char director; - unsigned char rd_trk_set; - unsigned short max_rec_zero; - unsigned char reserved1; - unsigned char RWANY_in_LR; - unsigned char factor6; - unsigned char factor7; - unsigned char factor8; - unsigned char reserved2[3]; - unsigned char reserved3[6]; - unsigned int long_no_cyl; -} __attribute__ ((packed)); - -/* Get information on a dasd device (enhanced) */ -#define BIODASDINFO _IOR(DASD_IOCTL_LETTER,1,dasd_information_t) - -/***************************************************************************** - * SECTION: Further IOCTL Definitions (see fs.h and hdreq.h) * - *****************************************************************************/ -#define BLKROGET _IO(0x12,94) /* get read-only status (0 = read_write) */ -#define BLKRRPART _IO(0x12,95) /* re-read partition table */ -#define BLKSSZGET _IO(0x12,104)/* get block device sector size */ -#define BLKGETSIZE64 _IOR(0x12,114,size_t) /* device size in bytes (u64 *arg)*/ - -/* get device geometry */ -#define HDIO_GETGEO 0x0301 - /***************************************************************************** * SECTION: FDASD internal types * *****************************************************************************/