Commit 6d703a81 authored by Alexey Dobriyan's avatar Alexey Dobriyan Committed by David S. Miller

ide: convert to ->proc_fops

->read_proc, ->write_proc are going away, ->proc_fops should be used instead.

The only tricky place is IDENTIFY handling: if for some reason
taskfile_lib_get_identify() fails, buffer _is_ changed and at least
first byte is overwritten. Emulate old behaviour with returning
that first byte to userspace and reporting length=1 despite overall -E.
Signed-off-by: default avatarAlexey Dobriyan <adobriyan@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 76fbebfb
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/delay.h> #include <linux/delay.h>
#include <linux/timer.h> #include <linux/timer.h>
#include <linux/seq_file.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/interrupt.h> #include <linux/interrupt.h>
#include <linux/errno.h> #include <linux/errno.h>
...@@ -1389,19 +1390,30 @@ static sector_t ide_cdrom_capacity(ide_drive_t *drive) ...@@ -1389,19 +1390,30 @@ static sector_t ide_cdrom_capacity(ide_drive_t *drive)
return capacity * sectors_per_frame; return capacity * sectors_per_frame;
} }
static int proc_idecd_read_capacity(char *page, char **start, off_t off, static int idecd_capacity_proc_show(struct seq_file *m, void *v)
int count, int *eof, void *data)
{ {
ide_drive_t *drive = data; ide_drive_t *drive = m->private;
int len;
len = sprintf(page, "%llu\n", (long long)ide_cdrom_capacity(drive)); seq_printf(m, "%llu\n", (long long)ide_cdrom_capacity(drive));
PROC_IDE_READ_RETURN(page, start, off, count, eof, len); return 0;
}
static int idecd_capacity_proc_open(struct inode *inode, struct file *file)
{
return single_open(file, idecd_capacity_proc_show, PDE(inode)->data);
} }
static const struct file_operations idecd_capacity_proc_fops = {
.owner = THIS_MODULE,
.open = idecd_capacity_proc_open,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
};
static ide_proc_entry_t idecd_proc[] = { static ide_proc_entry_t idecd_proc[] = {
{ "capacity", S_IFREG|S_IRUGO, proc_idecd_read_capacity, NULL }, { "capacity", S_IFREG|S_IRUGO, &idecd_capacity_proc_fops },
{ NULL, 0, NULL, NULL } {}
}; };
static ide_proc_entry_t *ide_cd_proc_entries(ide_drive_t *drive) static ide_proc_entry_t *ide_cd_proc_entries(ide_drive_t *drive)
......
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/ide.h> #include <linux/ide.h>
#include <linux/seq_file.h>
#include "ide-disk.h" #include "ide-disk.h"
...@@ -37,77 +38,117 @@ static int get_smart_data(ide_drive_t *drive, u8 *buf, u8 sub_cmd) ...@@ -37,77 +38,117 @@ static int get_smart_data(ide_drive_t *drive, u8 *buf, u8 sub_cmd)
return ide_raw_taskfile(drive, &cmd, buf, 1); return ide_raw_taskfile(drive, &cmd, buf, 1);
} }
static int proc_idedisk_read_cache static int idedisk_cache_proc_show(struct seq_file *m, void *v)
(char *page, char **start, off_t off, int count, int *eof, void *data)
{ {
ide_drive_t *drive = (ide_drive_t *) data; ide_drive_t *drive = (ide_drive_t *) m->private;
char *out = page;
int len;
if (drive->dev_flags & IDE_DFLAG_ID_READ) if (drive->dev_flags & IDE_DFLAG_ID_READ)
len = sprintf(out, "%i\n", drive->id[ATA_ID_BUF_SIZE] / 2); seq_printf(m, "%i\n", drive->id[ATA_ID_BUF_SIZE] / 2);
else else
len = sprintf(out, "(none)\n"); seq_printf(m, "(none)\n");
return 0;
}
PROC_IDE_READ_RETURN(page, start, off, count, eof, len); static int idedisk_cache_proc_open(struct inode *inode, struct file *file)
{
return single_open(file, idedisk_cache_proc_show, PDE(inode)->data);
} }
static int proc_idedisk_read_capacity static const struct file_operations idedisk_cache_proc_fops = {
(char *page, char **start, off_t off, int count, int *eof, void *data) .owner = THIS_MODULE,
.open = idedisk_cache_proc_open,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
};
static int idedisk_capacity_proc_show(struct seq_file *m, void *v)
{ {
ide_drive_t*drive = (ide_drive_t *)data; ide_drive_t*drive = (ide_drive_t *)m->private;
int len;
len = sprintf(page, "%llu\n", (long long)ide_gd_capacity(drive)); seq_printf(m, "%llu\n", (long long)ide_gd_capacity(drive));
return 0;
}
PROC_IDE_READ_RETURN(page, start, off, count, eof, len); static int idedisk_capacity_proc_open(struct inode *inode, struct file *file)
{
return single_open(file, idedisk_capacity_proc_show, PDE(inode)->data);
} }
static int proc_idedisk_read_smart(char *page, char **start, off_t off, static const struct file_operations idedisk_capacity_proc_fops = {
int count, int *eof, void *data, u8 sub_cmd) .owner = THIS_MODULE,
.open = idedisk_capacity_proc_open,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
};
static int __idedisk_proc_show(struct seq_file *m, ide_drive_t *drive, u8 sub_cmd)
{ {
ide_drive_t *drive = (ide_drive_t *)data; u8 *buf;
int len = 0, i = 0;
buf = kmalloc(SECTOR_SIZE, GFP_KERNEL);
if (!buf)
return -ENOMEM;
(void)smart_enable(drive); (void)smart_enable(drive);
if (get_smart_data(drive, page, sub_cmd) == 0) { if (get_smart_data(drive, buf, sub_cmd) == 0) {
unsigned short *val = (unsigned short *) page; __le16 *val = (__le16 *)buf;
char *out = (char *)val + SECTOR_SIZE; int i;
page = out; for (i = 0; i < SECTOR_SIZE / 2; i++) {
do { seq_printf(m, "%04x%c", le16_to_cpu(val[i]),
out += sprintf(out, "%04x%c", le16_to_cpu(*val), (i % 8) == 7 ? '\n' : ' ');
(++i & 7) ? ' ' : '\n'); }
val += 1;
} while (i < SECTOR_SIZE / 2);
len = out - page;
} }
kfree(buf);
return 0;
}
PROC_IDE_READ_RETURN(page, start, off, count, eof, len); static int idedisk_sv_proc_show(struct seq_file *m, void *v)
{
return __idedisk_proc_show(m, m->private, ATA_SMART_READ_VALUES);
} }
static int proc_idedisk_read_sv static int idedisk_sv_proc_open(struct inode *inode, struct file *file)
(char *page, char **start, off_t off, int count, int *eof, void *data)
{ {
return proc_idedisk_read_smart(page, start, off, count, eof, data, return single_open(file, idedisk_sv_proc_show, PDE(inode)->data);
ATA_SMART_READ_VALUES);
} }
static int proc_idedisk_read_st static const struct file_operations idedisk_sv_proc_fops = {
(char *page, char **start, off_t off, int count, int *eof, void *data) .owner = THIS_MODULE,
.open = idedisk_sv_proc_open,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
};
static int idedisk_st_proc_show(struct seq_file *m, void *v)
{ {
return proc_idedisk_read_smart(page, start, off, count, eof, data, return __idedisk_proc_show(m, m->private, ATA_SMART_READ_THRESHOLDS);
ATA_SMART_READ_THRESHOLDS);
} }
static int idedisk_st_proc_open(struct inode *inode, struct file *file)
{
return single_open(file, idedisk_st_proc_show, PDE(inode)->data);
}
static const struct file_operations idedisk_st_proc_fops = {
.owner = THIS_MODULE,
.open = idedisk_st_proc_open,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
};
ide_proc_entry_t ide_disk_proc[] = { ide_proc_entry_t ide_disk_proc[] = {
{ "cache", S_IFREG|S_IRUGO, proc_idedisk_read_cache, NULL }, { "cache", S_IFREG|S_IRUGO, &idedisk_cache_proc_fops },
{ "capacity", S_IFREG|S_IRUGO, proc_idedisk_read_capacity, NULL }, { "capacity", S_IFREG|S_IRUGO, &idedisk_capacity_proc_fops },
{ "geometry", S_IFREG|S_IRUGO, proc_ide_read_geometry, NULL }, { "geometry", S_IFREG|S_IRUGO, &ide_geometry_proc_fops },
{ "smart_values", S_IFREG|S_IRUSR, proc_idedisk_read_sv, NULL }, { "smart_values", S_IFREG|S_IRUSR, &idedisk_sv_proc_fops },
{ "smart_thresholds", S_IFREG|S_IRUSR, proc_idedisk_read_st, NULL }, { "smart_thresholds", S_IFREG|S_IRUSR, &idedisk_st_proc_fops },
{ NULL, 0, NULL, NULL } {}
}; };
ide_devset_rw_field(bios_cyl, bios_cyl); ide_devset_rw_field(bios_cyl, bios_cyl);
......
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/ide.h> #include <linux/ide.h>
#include <linux/seq_file.h>
#include "ide-floppy.h" #include "ide-floppy.h"
static int proc_idefloppy_read_capacity(char *page, char **start, off_t off, static int idefloppy_capacity_proc_show(struct seq_file *m, void *v)
int count, int *eof, void *data)
{ {
ide_drive_t*drive = (ide_drive_t *)data; ide_drive_t*drive = (ide_drive_t *)m->private;
int len;
len = sprintf(page, "%llu\n", (long long)ide_gd_capacity(drive)); seq_printf(m, "%llu\n", (long long)ide_gd_capacity(drive));
PROC_IDE_READ_RETURN(page, start, off, count, eof, len); return 0;
} }
static int idefloppy_capacity_proc_open(struct inode *inode, struct file *file)
{
return single_open(file, idefloppy_capacity_proc_show, PDE(inode)->data);
}
static const struct file_operations idefloppy_capacity_proc_fops = {
.owner = THIS_MODULE,
.open = idefloppy_capacity_proc_open,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
};
ide_proc_entry_t ide_floppy_proc[] = { ide_proc_entry_t ide_floppy_proc[] = {
{ "capacity", S_IFREG|S_IRUGO, proc_idefloppy_read_capacity, NULL }, { "capacity", S_IFREG|S_IRUGO, &idefloppy_capacity_proc_fops },
{ "geometry", S_IFREG|S_IRUGO, proc_ide_read_geometry, NULL }, { "geometry", S_IFREG|S_IRUGO, &ide_geometry_proc_fops },
{ NULL, 0, NULL, NULL } {}
}; };
ide_devset_rw_field(bios_cyl, bios_cyl); ide_devset_rw_field(bios_cyl, bios_cyl);
......
This diff is collapsed.
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include <linux/major.h> #include <linux/major.h>
#include <linux/errno.h> #include <linux/errno.h>
#include <linux/genhd.h> #include <linux/genhd.h>
#include <linux/seq_file.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/pci.h> #include <linux/pci.h>
#include <linux/ide.h> #include <linux/ide.h>
...@@ -1816,22 +1817,32 @@ static void ide_tape_release(struct device *dev) ...@@ -1816,22 +1817,32 @@ static void ide_tape_release(struct device *dev)
} }
#ifdef CONFIG_IDE_PROC_FS #ifdef CONFIG_IDE_PROC_FS
static int proc_idetape_read_name static int idetape_name_proc_show(struct seq_file *m, void *v)
(char *page, char **start, off_t off, int count, int *eof, void *data)
{ {
ide_drive_t *drive = (ide_drive_t *) data; ide_drive_t *drive = (ide_drive_t *) m->private;
idetape_tape_t *tape = drive->driver_data; idetape_tape_t *tape = drive->driver_data;
char *out = page;
int len;
len = sprintf(out, "%s\n", tape->name); seq_printf(m, "%s\n", tape->name);
PROC_IDE_READ_RETURN(page, start, off, count, eof, len); return 0;
}
static int idetape_name_proc_open(struct inode *inode, struct file *file)
{
return single_open(file, idetape_name_proc_show, PDE(inode)->data);
} }
static const struct file_operations idetape_name_proc_fops = {
.owner = THIS_MODULE,
.open = idetape_name_proc_open,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
};
static ide_proc_entry_t idetape_proc[] = { static ide_proc_entry_t idetape_proc[] = {
{ "capacity", S_IFREG|S_IRUGO, proc_ide_read_capacity, NULL }, { "capacity", S_IFREG|S_IRUGO, &ide_capacity_proc_fops },
{ "name", S_IFREG|S_IRUGO, proc_idetape_read_name, NULL }, { "name", S_IFREG|S_IRUGO, &idetape_name_proc_fops },
{ NULL, 0, NULL, NULL } {}
}; };
static ide_proc_entry_t *ide_tape_proc_entries(ide_drive_t *drive) static ide_proc_entry_t *ide_tape_proc_entries(ide_drive_t *drive)
......
...@@ -919,8 +919,7 @@ __IDE_PROC_DEVSET(_name, _min, _max, NULL, NULL) ...@@ -919,8 +919,7 @@ __IDE_PROC_DEVSET(_name, _min, _max, NULL, NULL)
typedef struct { typedef struct {
const char *name; const char *name;
mode_t mode; mode_t mode;
read_proc_t *read_proc; const struct file_operations *proc_fops;
write_proc_t *write_proc;
} ide_proc_entry_t; } ide_proc_entry_t;
void proc_ide_create(void); void proc_ide_create(void);
...@@ -932,24 +931,8 @@ void ide_proc_unregister_port(ide_hwif_t *); ...@@ -932,24 +931,8 @@ void ide_proc_unregister_port(ide_hwif_t *);
void ide_proc_register_driver(ide_drive_t *, struct ide_driver *); void ide_proc_register_driver(ide_drive_t *, struct ide_driver *);
void ide_proc_unregister_driver(ide_drive_t *, struct ide_driver *); void ide_proc_unregister_driver(ide_drive_t *, struct ide_driver *);
read_proc_t proc_ide_read_capacity; extern const struct file_operations ide_capacity_proc_fops;
read_proc_t proc_ide_read_geometry; extern const struct file_operations ide_geometry_proc_fops;
/*
* Standard exit stuff:
*/
#define PROC_IDE_READ_RETURN(page,start,off,count,eof,len) \
{ \
len -= off; \
if (len < count) { \
*eof = 1; \
if (len <= 0) \
return 0; \
} else \
len = count; \
*start = page + off; \
return len; \
}
#else #else
static inline void proc_ide_create(void) { ; } static inline void proc_ide_create(void) { ; }
static inline void proc_ide_destroy(void) { ; } static inline void proc_ide_destroy(void) { ; }
...@@ -961,7 +944,6 @@ static inline void ide_proc_register_driver(ide_drive_t *drive, ...@@ -961,7 +944,6 @@ static inline void ide_proc_register_driver(ide_drive_t *drive,
struct ide_driver *driver) { ; } struct ide_driver *driver) { ; }
static inline void ide_proc_unregister_driver(ide_drive_t *drive, static inline void ide_proc_unregister_driver(ide_drive_t *drive,
struct ide_driver *driver) { ; } struct ide_driver *driver) { ; }
#define PROC_IDE_READ_RETURN(page,start,off,count,eof,len) return 0;
#endif #endif
enum { enum {
......
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