Commit 86d434de authored by Al Viro's avatar Al Viro

[PATCH] eliminate use of ->f_flags in block methods

store needed information in f_mode
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
parent aeb5d727
...@@ -1813,17 +1813,17 @@ static int floppy_open( struct inode *inode, struct file *filp ) ...@@ -1813,17 +1813,17 @@ static int floppy_open( struct inode *inode, struct file *filp )
if (p->ref && p->type != type) if (p->ref && p->type != type)
return -EBUSY; return -EBUSY;
if (p->ref == -1 || (p->ref && filp->f_flags & O_EXCL)) if (p->ref == -1 || (p->ref && filp->f_mode & FMODE_EXCL))
return -EBUSY; return -EBUSY;
if (filp->f_flags & O_EXCL) if (filp->f_mode & FMODE_EXCL)
p->ref = -1; p->ref = -1;
else else
p->ref++; p->ref++;
p->type = type; p->type = type;
if (filp->f_flags & O_NDELAY) if (filp->f_mode & FMODE_NDELAY)
return 0; return 0;
if (filp->f_mode & (FMODE_READ|FMODE_WRITE)) { if (filp->f_mode & (FMODE_READ|FMODE_WRITE)) {
......
...@@ -3453,7 +3453,7 @@ static int fd_getgeo(struct block_device *bdev, struct hd_geometry *geo) ...@@ -3453,7 +3453,7 @@ static int fd_getgeo(struct block_device *bdev, struct hd_geometry *geo)
static int fd_ioctl(struct inode *inode, struct file *filp, unsigned int cmd, static int fd_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
unsigned long param) unsigned long param)
{ {
#define FD_IOCTL_ALLOWED ((filp) && (filp)->private_data) #define FD_IOCTL_ALLOWED ((filp) && (filp)->f_mode & (FMODE_WRITE|FMODE_WRITE_IOCTL))
#define OUT(c,x) case c: outparam = (const char *) (x); break #define OUT(c,x) case c: outparam = (const char *) (x); break
#define IN(c,x,tag) case c: *(x) = inparam. tag ; return 0 #define IN(c,x,tag) case c: *(x) = inparam. tag ; return 0
...@@ -3690,7 +3690,6 @@ static int floppy_open(struct inode *inode, struct file *filp) ...@@ -3690,7 +3690,6 @@ static int floppy_open(struct inode *inode, struct file *filp)
int res = -EBUSY; int res = -EBUSY;
char *tmp; char *tmp;
filp->private_data = (void *)0;
mutex_lock(&open_lock); mutex_lock(&open_lock);
old_dev = UDRS->fd_device; old_dev = UDRS->fd_device;
if (opened_bdev[drive] && opened_bdev[drive] != inode->i_bdev) if (opened_bdev[drive] && opened_bdev[drive] != inode->i_bdev)
...@@ -3701,10 +3700,10 @@ static int floppy_open(struct inode *inode, struct file *filp) ...@@ -3701,10 +3700,10 @@ static int floppy_open(struct inode *inode, struct file *filp)
USETF(FD_VERIFY); USETF(FD_VERIFY);
} }
if (UDRS->fd_ref == -1 || (UDRS->fd_ref && (filp->f_flags & O_EXCL))) if (UDRS->fd_ref == -1 || (UDRS->fd_ref && (filp->f_mode & FMODE_EXCL)))
goto out2; goto out2;
if (filp->f_flags & O_EXCL) if (filp->f_mode & FMODE_EXCL)
UDRS->fd_ref = -1; UDRS->fd_ref = -1;
else else
UDRS->fd_ref++; UDRS->fd_ref++;
...@@ -3751,16 +3750,10 @@ static int floppy_open(struct inode *inode, struct file *filp) ...@@ -3751,16 +3750,10 @@ static int floppy_open(struct inode *inode, struct file *filp)
buffer_track = -1; buffer_track = -1;
} }
/* Allow ioctls if we have write-permissions even if read-only open.
* Needed so that programs such as fdrawcmd still can work on write
* protected disks */
if ((filp->f_mode & FMODE_WRITE) || !file_permission(filp, MAY_WRITE))
filp->private_data = (void *)8;
if (UFDCS->rawcmd == 1) if (UFDCS->rawcmd == 1)
UFDCS->rawcmd = 2; UFDCS->rawcmd = 2;
if (!(filp->f_flags & O_NDELAY)) { if (!(filp->f_mode & FMODE_NDELAY)) {
if (filp->f_mode & (FMODE_READ|FMODE_WRITE)) { if (filp->f_mode & (FMODE_READ|FMODE_WRITE)) {
UDRS->last_checked = 0; UDRS->last_checked = 0;
check_disk_change(inode->i_bdev); check_disk_change(inode->i_bdev);
......
...@@ -904,10 +904,10 @@ static int floppy_open(struct inode *inode, struct file *filp) ...@@ -904,10 +904,10 @@ static int floppy_open(struct inode *inode, struct file *filp)
swim3_action(fs, SETMFM); swim3_action(fs, SETMFM);
swim3_select(fs, RELAX); swim3_select(fs, RELAX);
} else if (fs->ref_count == -1 || filp->f_flags & O_EXCL) } else if (fs->ref_count == -1 || filp->f_mode & FMODE_EXCL)
return -EBUSY; return -EBUSY;
if (err == 0 && (filp->f_flags & O_NDELAY) == 0 if (err == 0 && (filp->f_mode & FMODE_NDELAY) == 0
&& (filp->f_mode & (FMODE_READ|FMODE_WRITE))) { && (filp->f_mode & (FMODE_READ|FMODE_WRITE))) {
check_disk_change(inode->i_bdev); check_disk_change(inode->i_bdev);
if (fs->ejected) if (fs->ejected)
...@@ -930,7 +930,7 @@ static int floppy_open(struct inode *inode, struct file *filp) ...@@ -930,7 +930,7 @@ static int floppy_open(struct inode *inode, struct file *filp)
return err; return err;
} }
if (filp->f_flags & O_EXCL) if (filp->f_mode & FMODE_EXCL)
fs->ref_count = -1; fs->ref_count = -1;
else else
++fs->ref_count; ++fs->ref_count;
......
...@@ -1691,7 +1691,7 @@ static int ub_bd_open(struct inode *inode, struct file *filp) ...@@ -1691,7 +1691,7 @@ static int ub_bd_open(struct inode *inode, struct file *filp)
* under some pretty murky conditions (a failure of READ CAPACITY). * under some pretty murky conditions (a failure of READ CAPACITY).
* We may need it one day. * We may need it one day.
*/ */
if (lun->removable && lun->changed && !(filp->f_flags & O_NDELAY)) { if (lun->removable && lun->changed && !(filp->f_mode & FMODE_NDELAY)) {
rc = -ENOMEDIUM; rc = -ENOMEDIUM;
goto err_open; goto err_open;
} }
......
...@@ -982,7 +982,7 @@ int cdrom_open(struct cdrom_device_info *cdi, struct inode *ip, struct file *fp) ...@@ -982,7 +982,7 @@ int cdrom_open(struct cdrom_device_info *cdi, struct inode *ip, struct file *fp)
/* if this was a O_NONBLOCK open and we should honor the flags, /* if this was a O_NONBLOCK open and we should honor the flags,
* do a quick open without drive/disc integrity checks. */ * do a quick open without drive/disc integrity checks. */
cdi->use_count++; cdi->use_count++;
if ((fp->f_flags & O_NONBLOCK) && (cdi->options & CDO_USE_FFLAGS)) { if ((fp->f_mode & FMODE_NDELAY) && (cdi->options & CDO_USE_FFLAGS)) {
ret = cdi->ops->open(cdi, 1); ret = cdi->ops->open(cdi, 1);
} else { } else {
ret = open_for_data(cdi); ret = open_for_data(cdi);
...@@ -1205,7 +1205,7 @@ int cdrom_release(struct cdrom_device_info *cdi, struct file *fp) ...@@ -1205,7 +1205,7 @@ int cdrom_release(struct cdrom_device_info *cdi, struct file *fp)
} }
opened_for_data = !(cdi->options & CDO_USE_FFLAGS) || opened_for_data = !(cdi->options & CDO_USE_FFLAGS) ||
!(fp && fp->f_flags & O_NONBLOCK); !(fp && fp->f_mode & FMODE_NDELAY);
/* /*
* flush cache on last write release * flush cache on last write release
......
...@@ -197,7 +197,7 @@ static int ide_gd_open(struct inode *inode, struct file *filp) ...@@ -197,7 +197,7 @@ static int ide_gd_open(struct inode *inode, struct file *filp)
* unreadable disk, so that we can get the format capacity * unreadable disk, so that we can get the format capacity
* of the drive or begin the format - Sam * of the drive or begin the format - Sam
*/ */
if (ret && (filp->f_flags & O_NDELAY) == 0) { if (ret && (filp->f_mode & FMODE_NDELAY) == 0) {
ret = -EIO; ret = -EIO;
goto out_put_idkp; goto out_put_idkp;
} }
......
...@@ -640,7 +640,7 @@ static int sd_open(struct inode *inode, struct file *filp) ...@@ -640,7 +640,7 @@ static int sd_open(struct inode *inode, struct file *filp)
*/ */
retval = -ENOMEDIUM; retval = -ENOMEDIUM;
if (sdev->removable && !sdkp->media_present && if (sdev->removable && !sdkp->media_present &&
!(filp->f_flags & O_NDELAY)) !(filp->f_mode & FMODE_NDELAY))
goto error_out; goto error_out;
/* /*
......
...@@ -1007,6 +1007,13 @@ static int do_open(struct block_device *bdev, struct file *file, int for_part) ...@@ -1007,6 +1007,13 @@ static int do_open(struct block_device *bdev, struct file *file, int for_part)
return ret; return ret;
} }
if (file->f_flags & O_NDELAY)
file->f_mode |= FMODE_NDELAY;
if (file->f_flags & O_EXCL)
file->f_mode |= FMODE_EXCL;
if ((file->f_flags & O_ACCMODE) == 3)
file->f_mode |= FMODE_WRITE_IOCTL;
ret = -ENXIO; ret = -ENXIO;
file->f_mapping = bdev->bd_inode->i_mapping; file->f_mapping = bdev->bd_inode->i_mapping;
......
...@@ -76,6 +76,10 @@ extern int dir_notify_enable; ...@@ -76,6 +76,10 @@ extern int dir_notify_enable;
behavior for cross-node execution/opening_for_writing of files */ behavior for cross-node execution/opening_for_writing of files */
#define FMODE_EXEC ((__force fmode_t)16) #define FMODE_EXEC ((__force fmode_t)16)
#define FMODE_NDELAY ((__force fmode_t)32)
#define FMODE_EXCL ((__force fmode_t)64)
#define FMODE_WRITE_IOCTL ((__force fmode_t)128)
#define RW_MASK 1 #define RW_MASK 1
#define RWA_MASK 2 #define RWA_MASK 2
#define READ 0 #define READ 0
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment