util-linux/include/blkdev.h

62 lines
2.0 KiB
C
Raw Normal View History

#ifndef BLKDEV_H
#define BLKDEV_H
#include <sys/types.h>
#include <sys/ioctl.h>
#define DEFAULT_SECTOR_SIZE 512
mount: retry on ENOMEDIUM Due to a change in kernel behaviour when opening CDROM devices, we need to retry the open/mount call when ENOMEDIUM is returned. Explanation from Tejun Heo: Okay, the difference is from the addition of cdrom_get_media_event() call to both sr_drive_status() and ide_cdrom_drive_status(). Previously, the cdrom driver can't differentiate between tray closed w/ no media and tray open and always returned tray open, which triggers close and retry in the open logic which probably have delayed things enough to get the media recognized. Now the cdrom driver can discern between tray closed w/o media and device not ready for other reasons and returns -ENOMEDIUM on the former. This is all good and dandy but the problem seems that some drives report no media right after the tray is closed but it hasn't properly detected the media yet. It seems the only way to work around the problem is via sensible retries (e.g. try three times 5 secs apart) and I don't think we can add that type of retry logic into cdrom open path. Please note that the previous logic wasn't water proof. Some drives can take longer to recognize the media is there and could have failed the in-kernel retry too. Also, reading the media can take quite some time and during that period the drive reports media present but device not ready. The driver will retry the command (e.g. READ TOC for open) five times but all of them can fail w/ EMEDIUMTYPE. [kzak@redhat.com: - add CRDOM_NOMEDIUM_RETRIES to blkdev.h - add verbose message to mount.c] Signed-off-by: Matthias Koenig <mkoenig@suse.de> Signed-off-by: Karel Zak <kzak@redhat.com>
2008-06-09 09:38:25 -05:00
/* open() retries when errno is ENOMEDIUM */
#define CRDOM_NOMEDIUM_RETRIES 5
#if !defined(BLKROSET) && defined(__linux__)
#define BLKROSET _IO(0x12,93) /* set device read-only (0 = read-write) */
#define BLKROGET _IO(0x12,94) /* get read-only status (0 = read_write) */
#define BLKRRPART _IO(0x12,95) /* re-read partition table */
#define BLKGETSIZE _IO(0x12,96) /* return device size /512 (long *arg) */
#define BLKFLSBUF _IO(0x12,97) /* flush buffer cache */
#define BLKRASET _IO(0x12,98) /* set read ahead for block device */
#define BLKRAGET _IO(0x12,99) /* get current read ahead setting */
#define BLKFRASET _IO(0x12,100)/* set filesystem (mm/filemap.c) read-ahead */
#define BLKFRAGET _IO(0x12,101)/* get filesystem (mm/filemap.c) read-ahead */
#define BLKSECTSET _IO(0x12,102)/* set max sectors per request (ll_rw_blk.c) */
#define BLKSECTGET _IO(0x12,103)/* get max sectors per request (ll_rw_blk.c) */
#define BLKSSZGET _IO(0x12,104)/* get block device sector size */
/* ioctls introduced in 2.2.16, removed in 2.5.58 */
#define BLKELVGET _IOR(0x12,106,size_t) /* elevator get */
#define BLKELVSET _IOW(0x12,107,size_t) /* elevator set */
#define BLKBSZGET _IOR(0x12,112,size_t)
#define BLKBSZSET _IOW(0x12,113,size_t)
#define BLKGETSIZE64 _IOR(0x12,114,size_t) /* return device size in bytes (u64 *arg) */
#endif /* BLKROSET */
#ifndef HDIO_GETGEO
# ifdef __linux__
# define HDIO_GETGEO 0x0301
# endif
struct hd_geometry {
unsigned char heads;
unsigned char sectors;
unsigned short cylinders; /* truncated */
unsigned long start;
};
#endif
/* Determine size in bytes */
off_t blkdev_find_size (int fd);
/* get size in bytes */
int blkdev_get_size(int fd, unsigned long long *bytes);
/* get 512-byte sector count */
int blkdev_get_sectors(int fd, unsigned long long *sectors);
/* get hardware sector size */
int blkdev_get_sector_size(int fd, int *sector_size);
#endif /* BLKDEV_H */