Message ID | 20200423071224.500849-7-hch@lst.de |
---|---|
State | Not Applicable |
Delegated to: | David Miller |
Headers | show |
Series | [1/7] block: add a cdrom_device_info pointer to struct gendisk | expand |
On 2020/04/23 16:16, Christoph Hellwig wrote: > Instead just call the CD-ROM layer functionality directly, and turn the > hot mess in isofs_get_last_session into remotely readable code. > > Signed-off-by: Christoph Hellwig <hch@lst.de> > --- > fs/isofs/inode.c | 54 +++++++++++++++++++++++------------------------- > 1 file changed, 26 insertions(+), 28 deletions(-) > > diff --git a/fs/isofs/inode.c b/fs/isofs/inode.c > index 62c0462dc89f..fc48923a9b6c 100644 > --- a/fs/isofs/inode.c > +++ b/fs/isofs/inode.c > @@ -544,43 +544,41 @@ static int isofs_show_options(struct seq_file *m, struct dentry *root) > > static unsigned int isofs_get_last_session(struct super_block *sb, s32 session) > { > - struct cdrom_multisession ms_info; > - unsigned int vol_desc_start; > - struct block_device *bdev = sb->s_bdev; > - int i; > + struct cdrom_device_info *cdi = disk_to_cdi(sb->s_bdev->bd_disk); > + unsigned int vol_desc_start = 0; > > - vol_desc_start=0; > - ms_info.addr_format=CDROM_LBA; > if (session > 0) { > - struct cdrom_tocentry Te; > - Te.cdte_track=session; > - Te.cdte_format=CDROM_LBA; > - i = ioctl_by_bdev(bdev, CDROMREADTOCENTRY, (unsigned long) &Te); > - if (!i) { > + struct cdrom_tocentry te; > + > + if (!cdi) > + return -EINVAL; > + > + te.cdte_track = session; > + te.cdte_format = CDROM_LBA; > + if (cdrom_read_tocentry(cdi, &te) == 0) { > printk(KERN_DEBUG "ISOFS: Session %d start %d type %d\n", > - session, Te.cdte_addr.lba, > - Te.cdte_ctrl&CDROM_DATA_TRACK); > - if ((Te.cdte_ctrl&CDROM_DATA_TRACK) == 4) > - return Te.cdte_addr.lba; > + session, te.cdte_addr.lba, > + te.cdte_ctrl & CDROM_DATA_TRACK); > + if ((te.cdte_ctrl & CDROM_DATA_TRACK) == 4) > + return te.cdte_addr.lba; > } > > printk(KERN_ERR "ISOFS: Invalid session number or type of track\n"); > } > - i = ioctl_by_bdev(bdev, CDROMMULTISESSION, (unsigned long) &ms_info); > - if (session > 0) > - printk(KERN_ERR "ISOFS: Invalid session number\n"); > -#if 0 > - printk(KERN_DEBUG "isofs.inode: CDROMMULTISESSION: rc=%d\n",i); > - if (i==0) { > - printk(KERN_DEBUG "isofs.inode: XA disk: %s\n",ms_info.xa_flag?"yes":"no"); > - printk(KERN_DEBUG "isofs.inode: vol_desc_start = %d\n", ms_info.addr.lba); > - } > -#endif > - if (i==0) > + > + if (cdi) { > + struct cdrom_multisession ms_info; > + > + ms_info.addr_format = CDROM_LBA; > + if (cdrom_multisession(cdi, &ms_info) == 0) { > #if WE_OBEY_THE_WRITTEN_STANDARDS > - if (ms_info.xa_flag) /* necessary for a valid ms_info.addr */ > + /* necessary for a valid ms_info.addr */ > + if (ms_info.xa_flag) > #endif > - vol_desc_start=ms_info.addr.lba; > + vol_desc_start = ms_info.addr.lba; > + } > + } > + > return vol_desc_start; > } > > Looks OK to me. Reviewed-by: Damien Le Moal <damien.lemoal@wdc.com>
On Thu 23-04-20 09:12:23, Christoph Hellwig wrote: > Instead just call the CD-ROM layer functionality directly, and turn the > hot mess in isofs_get_last_session into remotely readable code. > > Signed-off-by: Christoph Hellwig <hch@lst.de> One comment below... > --- > fs/isofs/inode.c | 54 +++++++++++++++++++++++------------------------- > 1 file changed, 26 insertions(+), 28 deletions(-) > > diff --git a/fs/isofs/inode.c b/fs/isofs/inode.c > index 62c0462dc89f..fc48923a9b6c 100644 > --- a/fs/isofs/inode.c > +++ b/fs/isofs/inode.c > @@ -544,43 +544,41 @@ static int isofs_show_options(struct seq_file *m, struct dentry *root) > > static unsigned int isofs_get_last_session(struct super_block *sb, s32 session) > { > - struct cdrom_multisession ms_info; > - unsigned int vol_desc_start; > - struct block_device *bdev = sb->s_bdev; > - int i; > + struct cdrom_device_info *cdi = disk_to_cdi(sb->s_bdev->bd_disk); > + unsigned int vol_desc_start = 0; > > - vol_desc_start=0; > - ms_info.addr_format=CDROM_LBA; > if (session > 0) { > - struct cdrom_tocentry Te; > - Te.cdte_track=session; > - Te.cdte_format=CDROM_LBA; > - i = ioctl_by_bdev(bdev, CDROMREADTOCENTRY, (unsigned long) &Te); > - if (!i) { > + struct cdrom_tocentry te; > + > + if (!cdi) > + return -EINVAL; There's no error handling in the caller and this function actually returns unsigned int... So I believe you need to return 0 here to maintain previous behavior (however suspicious it may be)? Honza
On Thu, Apr 23, 2020 at 01:03:47PM +0200, Jan Kara wrote: > There's no error handling in the caller and this function actually returns > unsigned int... So I believe you need to return 0 here to maintain previous > behavior (however suspicious it may be)? Indeed, and I don't think it is suspicious at all - if we have no CDROM info we should assume session 0, which is the same as for non-CDROM devices. Fixed for the next version.
On Fri 24-04-20 08:52:53, Christoph Hellwig wrote: > On Thu, Apr 23, 2020 at 01:03:47PM +0200, Jan Kara wrote: > > There's no error handling in the caller and this function actually returns > > unsigned int... So I believe you need to return 0 here to maintain previous > > behavior (however suspicious it may be)? > > Indeed, and I don't think it is suspicious at all - if we have no CDROM > info we should assume session 0, which is the same as for non-CDROM > devices. Fixed for the next version. Right, I've realized that once I've checked UDF version and thought about it for a while... Honza
diff --git a/fs/isofs/inode.c b/fs/isofs/inode.c index 62c0462dc89f..fc48923a9b6c 100644 --- a/fs/isofs/inode.c +++ b/fs/isofs/inode.c @@ -544,43 +544,41 @@ static int isofs_show_options(struct seq_file *m, struct dentry *root) static unsigned int isofs_get_last_session(struct super_block *sb, s32 session) { - struct cdrom_multisession ms_info; - unsigned int vol_desc_start; - struct block_device *bdev = sb->s_bdev; - int i; + struct cdrom_device_info *cdi = disk_to_cdi(sb->s_bdev->bd_disk); + unsigned int vol_desc_start = 0; - vol_desc_start=0; - ms_info.addr_format=CDROM_LBA; if (session > 0) { - struct cdrom_tocentry Te; - Te.cdte_track=session; - Te.cdte_format=CDROM_LBA; - i = ioctl_by_bdev(bdev, CDROMREADTOCENTRY, (unsigned long) &Te); - if (!i) { + struct cdrom_tocentry te; + + if (!cdi) + return -EINVAL; + + te.cdte_track = session; + te.cdte_format = CDROM_LBA; + if (cdrom_read_tocentry(cdi, &te) == 0) { printk(KERN_DEBUG "ISOFS: Session %d start %d type %d\n", - session, Te.cdte_addr.lba, - Te.cdte_ctrl&CDROM_DATA_TRACK); - if ((Te.cdte_ctrl&CDROM_DATA_TRACK) == 4) - return Te.cdte_addr.lba; + session, te.cdte_addr.lba, + te.cdte_ctrl & CDROM_DATA_TRACK); + if ((te.cdte_ctrl & CDROM_DATA_TRACK) == 4) + return te.cdte_addr.lba; } printk(KERN_ERR "ISOFS: Invalid session number or type of track\n"); } - i = ioctl_by_bdev(bdev, CDROMMULTISESSION, (unsigned long) &ms_info); - if (session > 0) - printk(KERN_ERR "ISOFS: Invalid session number\n"); -#if 0 - printk(KERN_DEBUG "isofs.inode: CDROMMULTISESSION: rc=%d\n",i); - if (i==0) { - printk(KERN_DEBUG "isofs.inode: XA disk: %s\n",ms_info.xa_flag?"yes":"no"); - printk(KERN_DEBUG "isofs.inode: vol_desc_start = %d\n", ms_info.addr.lba); - } -#endif - if (i==0) + + if (cdi) { + struct cdrom_multisession ms_info; + + ms_info.addr_format = CDROM_LBA; + if (cdrom_multisession(cdi, &ms_info) == 0) { #if WE_OBEY_THE_WRITTEN_STANDARDS - if (ms_info.xa_flag) /* necessary for a valid ms_info.addr */ + /* necessary for a valid ms_info.addr */ + if (ms_info.xa_flag) #endif - vol_desc_start=ms_info.addr.lba; + vol_desc_start = ms_info.addr.lba; + } + } + return vol_desc_start; }
Instead just call the CD-ROM layer functionality directly, and turn the hot mess in isofs_get_last_session into remotely readable code. Signed-off-by: Christoph Hellwig <hch@lst.de> --- fs/isofs/inode.c | 54 +++++++++++++++++++++++------------------------- 1 file changed, 26 insertions(+), 28 deletions(-)