ide-proc.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695
  1. /*
  2. * Copyright (C) 1997-1998 Mark Lord
  3. * Copyright (C) 2003 Red Hat
  4. *
  5. * Some code was moved here from ide.c, see it for original copyrights.
  6. */
  7. /*
  8. * This is the /proc/ide/ filesystem implementation.
  9. *
  10. * Drive/Driver settings can be retrieved by reading the drive's
  11. * "settings" files. e.g. "cat /proc/ide0/hda/settings"
  12. * To write a new value "val" into a specific setting "name", use:
  13. * echo "name:val" >/proc/ide/ide0/hda/settings
  14. */
  15. #include <linux/module.h>
  16. #include <asm/uaccess.h>
  17. #include <linux/errno.h>
  18. #include <linux/proc_fs.h>
  19. #include <linux/stat.h>
  20. #include <linux/mm.h>
  21. #include <linux/pci.h>
  22. #include <linux/ctype.h>
  23. #include <linux/ide.h>
  24. #include <linux/seq_file.h>
  25. #include <asm/io.h>
  26. static struct proc_dir_entry *proc_ide_root;
  27. static int proc_ide_read_imodel
  28. (char *page, char **start, off_t off, int count, int *eof, void *data)
  29. {
  30. ide_hwif_t *hwif = (ide_hwif_t *) data;
  31. int len;
  32. const char *name;
  33. switch (hwif->chipset) {
  34. case ide_generic: name = "generic"; break;
  35. case ide_pci: name = "pci"; break;
  36. case ide_cmd640: name = "cmd640"; break;
  37. case ide_dtc2278: name = "dtc2278"; break;
  38. case ide_ali14xx: name = "ali14xx"; break;
  39. case ide_qd65xx: name = "qd65xx"; break;
  40. case ide_umc8672: name = "umc8672"; break;
  41. case ide_ht6560b: name = "ht6560b"; break;
  42. case ide_4drives: name = "4drives"; break;
  43. case ide_pmac: name = "mac-io"; break;
  44. case ide_au1xxx: name = "au1xxx"; break;
  45. case ide_palm3710: name = "palm3710"; break;
  46. case ide_acorn: name = "acorn"; break;
  47. default: name = "(unknown)"; break;
  48. }
  49. len = sprintf(page, "%s\n", name);
  50. PROC_IDE_READ_RETURN(page, start, off, count, eof, len);
  51. }
  52. static int proc_ide_read_mate
  53. (char *page, char **start, off_t off, int count, int *eof, void *data)
  54. {
  55. ide_hwif_t *hwif = (ide_hwif_t *) data;
  56. int len;
  57. if (hwif && hwif->mate)
  58. len = sprintf(page, "%s\n", hwif->mate->name);
  59. else
  60. len = sprintf(page, "(none)\n");
  61. PROC_IDE_READ_RETURN(page, start, off, count, eof, len);
  62. }
  63. static int proc_ide_read_channel
  64. (char *page, char **start, off_t off, int count, int *eof, void *data)
  65. {
  66. ide_hwif_t *hwif = (ide_hwif_t *) data;
  67. int len;
  68. page[0] = hwif->channel ? '1' : '0';
  69. page[1] = '\n';
  70. len = 2;
  71. PROC_IDE_READ_RETURN(page, start, off, count, eof, len);
  72. }
  73. static int proc_ide_read_identify
  74. (char *page, char **start, off_t off, int count, int *eof, void *data)
  75. {
  76. ide_drive_t *drive = (ide_drive_t *)data;
  77. int len = 0, i = 0;
  78. int err = 0;
  79. len = sprintf(page, "\n");
  80. if (drive) {
  81. __le16 *val = (__le16 *)page;
  82. err = taskfile_lib_get_identify(drive, page);
  83. if (!err) {
  84. char *out = (char *)page + SECTOR_SIZE;
  85. page = out;
  86. do {
  87. out += sprintf(out, "%04x%c",
  88. le16_to_cpup(val), (++i & 7) ? ' ' : '\n');
  89. val += 1;
  90. } while (i < SECTOR_SIZE / 2);
  91. len = out - page;
  92. }
  93. }
  94. PROC_IDE_READ_RETURN(page, start, off, count, eof, len);
  95. }
  96. /**
  97. * ide_find_setting - find a specific setting
  98. * @st: setting table pointer
  99. * @name: setting name
  100. *
  101. * Scan's the setting table for a matching entry and returns
  102. * this or NULL if no entry is found. The caller must hold the
  103. * setting semaphore
  104. */
  105. static
  106. const struct ide_proc_devset *ide_find_setting(const struct ide_proc_devset *st,
  107. char *name)
  108. {
  109. while (st->name) {
  110. if (strcmp(st->name, name) == 0)
  111. break;
  112. st++;
  113. }
  114. return st->name ? st : NULL;
  115. }
  116. /**
  117. * ide_read_setting - read an IDE setting
  118. * @drive: drive to read from
  119. * @setting: drive setting
  120. *
  121. * Read a drive setting and return the value. The caller
  122. * must hold the ide_setting_mtx when making this call.
  123. *
  124. * BUGS: the data return and error are the same return value
  125. * so an error -EINVAL and true return of the same value cannot
  126. * be told apart
  127. */
  128. static int ide_read_setting(ide_drive_t *drive,
  129. const struct ide_proc_devset *setting)
  130. {
  131. const struct ide_devset *ds = setting->setting;
  132. int val = -EINVAL;
  133. if (ds->get)
  134. val = ds->get(drive);
  135. return val;
  136. }
  137. /**
  138. * ide_write_setting - read an IDE setting
  139. * @drive: drive to read from
  140. * @setting: drive setting
  141. * @val: value
  142. *
  143. * Write a drive setting if it is possible. The caller
  144. * must hold the ide_setting_mtx when making this call.
  145. *
  146. * BUGS: the data return and error are the same return value
  147. * so an error -EINVAL and true return of the same value cannot
  148. * be told apart
  149. *
  150. * FIXME: This should be changed to enqueue a special request
  151. * to the driver to change settings, and then wait on a sema for completion.
  152. * The current scheme of polling is kludgy, though safe enough.
  153. */
  154. static int ide_write_setting(ide_drive_t *drive,
  155. const struct ide_proc_devset *setting, int val)
  156. {
  157. const struct ide_devset *ds = setting->setting;
  158. if (!capable(CAP_SYS_ADMIN))
  159. return -EACCES;
  160. if (!ds->set)
  161. return -EPERM;
  162. if ((ds->flags & DS_SYNC)
  163. && (val < setting->min || val > setting->max))
  164. return -EINVAL;
  165. return ide_devset_execute(drive, ds, val);
  166. }
  167. ide_devset_get(xfer_rate, current_speed);
  168. static int set_xfer_rate (ide_drive_t *drive, int arg)
  169. {
  170. struct ide_cmd cmd;
  171. if (arg < XFER_PIO_0 || arg > XFER_UDMA_6)
  172. return -EINVAL;
  173. memset(&cmd, 0, sizeof(cmd));
  174. cmd.tf.command = ATA_CMD_SET_FEATURES;
  175. cmd.tf.feature = SETFEATURES_XFER;
  176. cmd.tf.nsect = (u8)arg;
  177. cmd.valid.out.tf = IDE_VALID_FEATURE | IDE_VALID_NSECT;
  178. cmd.valid.in.tf = IDE_VALID_NSECT;
  179. cmd.tf_flags = IDE_TFLAG_SET_XFER;
  180. return ide_no_data_taskfile(drive, &cmd);
  181. }
  182. ide_devset_rw(current_speed, xfer_rate);
  183. ide_devset_rw_field(init_speed, init_speed);
  184. ide_devset_rw_flag(nice1, IDE_DFLAG_NICE1);
  185. ide_devset_rw_field(number, dn);
  186. static const struct ide_proc_devset ide_generic_settings[] = {
  187. IDE_PROC_DEVSET(current_speed, 0, 70),
  188. IDE_PROC_DEVSET(init_speed, 0, 70),
  189. IDE_PROC_DEVSET(io_32bit, 0, 1 + (SUPPORT_VLB_SYNC << 1)),
  190. IDE_PROC_DEVSET(keepsettings, 0, 1),
  191. IDE_PROC_DEVSET(nice1, 0, 1),
  192. IDE_PROC_DEVSET(number, 0, 3),
  193. IDE_PROC_DEVSET(pio_mode, 0, 255),
  194. IDE_PROC_DEVSET(unmaskirq, 0, 1),
  195. IDE_PROC_DEVSET(using_dma, 0, 1),
  196. { NULL },
  197. };
  198. static void proc_ide_settings_warn(void)
  199. {
  200. static int warned;
  201. if (warned)
  202. return;
  203. printk(KERN_WARNING "Warning: /proc/ide/hd?/settings interface is "
  204. "obsolete, and will be removed soon!\n");
  205. warned = 1;
  206. }
  207. static int proc_ide_read_settings
  208. (char *page, char **start, off_t off, int count, int *eof, void *data)
  209. {
  210. const struct ide_proc_devset *setting, *g, *d;
  211. const struct ide_devset *ds;
  212. ide_drive_t *drive = (ide_drive_t *) data;
  213. char *out = page;
  214. int len, rc, mul_factor, div_factor;
  215. proc_ide_settings_warn();
  216. mutex_lock(&ide_setting_mtx);
  217. g = ide_generic_settings;
  218. d = drive->settings;
  219. out += sprintf(out, "name\t\t\tvalue\t\tmin\t\tmax\t\tmode\n");
  220. out += sprintf(out, "----\t\t\t-----\t\t---\t\t---\t\t----\n");
  221. while (g->name || (d && d->name)) {
  222. /* read settings in the alphabetical order */
  223. if (g->name && d && d->name) {
  224. if (strcmp(d->name, g->name) < 0)
  225. setting = d++;
  226. else
  227. setting = g++;
  228. } else if (d && d->name) {
  229. setting = d++;
  230. } else
  231. setting = g++;
  232. mul_factor = setting->mulf ? setting->mulf(drive) : 1;
  233. div_factor = setting->divf ? setting->divf(drive) : 1;
  234. out += sprintf(out, "%-24s", setting->name);
  235. rc = ide_read_setting(drive, setting);
  236. if (rc >= 0)
  237. out += sprintf(out, "%-16d", rc * mul_factor / div_factor);
  238. else
  239. out += sprintf(out, "%-16s", "write-only");
  240. out += sprintf(out, "%-16d%-16d", (setting->min * mul_factor + div_factor - 1) / div_factor, setting->max * mul_factor / div_factor);
  241. ds = setting->setting;
  242. if (ds->get)
  243. out += sprintf(out, "r");
  244. if (ds->set)
  245. out += sprintf(out, "w");
  246. out += sprintf(out, "\n");
  247. }
  248. len = out - page;
  249. mutex_unlock(&ide_setting_mtx);
  250. PROC_IDE_READ_RETURN(page, start, off, count, eof, len);
  251. }
  252. #define MAX_LEN 30
  253. static int proc_ide_write_settings(struct file *file, const char __user *buffer,
  254. unsigned long count, void *data)
  255. {
  256. ide_drive_t *drive = (ide_drive_t *) data;
  257. char name[MAX_LEN + 1];
  258. int for_real = 0, mul_factor, div_factor;
  259. unsigned long n;
  260. const struct ide_proc_devset *setting;
  261. char *buf, *s;
  262. if (!capable(CAP_SYS_ADMIN))
  263. return -EACCES;
  264. proc_ide_settings_warn();
  265. if (count >= PAGE_SIZE)
  266. return -EINVAL;
  267. s = buf = (char *)__get_free_page(GFP_USER);
  268. if (!buf)
  269. return -ENOMEM;
  270. if (copy_from_user(buf, buffer, count)) {
  271. free_page((unsigned long)buf);
  272. return -EFAULT;
  273. }
  274. buf[count] = '\0';
  275. /*
  276. * Skip over leading whitespace
  277. */
  278. while (count && isspace(*s)) {
  279. --count;
  280. ++s;
  281. }
  282. /*
  283. * Do one full pass to verify all parameters,
  284. * then do another to actually write the new settings.
  285. */
  286. do {
  287. char *p = s;
  288. n = count;
  289. while (n > 0) {
  290. unsigned val;
  291. char *q = p;
  292. while (n > 0 && *p != ':') {
  293. --n;
  294. p++;
  295. }
  296. if (*p != ':')
  297. goto parse_error;
  298. if (p - q > MAX_LEN)
  299. goto parse_error;
  300. memcpy(name, q, p - q);
  301. name[p - q] = 0;
  302. if (n > 0) {
  303. --n;
  304. p++;
  305. } else
  306. goto parse_error;
  307. val = simple_strtoul(p, &q, 10);
  308. n -= q - p;
  309. p = q;
  310. if (n > 0 && !isspace(*p))
  311. goto parse_error;
  312. while (n > 0 && isspace(*p)) {
  313. --n;
  314. ++p;
  315. }
  316. mutex_lock(&ide_setting_mtx);
  317. /* generic settings first, then driver specific ones */
  318. setting = ide_find_setting(ide_generic_settings, name);
  319. if (!setting) {
  320. if (drive->settings)
  321. setting = ide_find_setting(drive->settings, name);
  322. if (!setting) {
  323. mutex_unlock(&ide_setting_mtx);
  324. goto parse_error;
  325. }
  326. }
  327. if (for_real) {
  328. mul_factor = setting->mulf ? setting->mulf(drive) : 1;
  329. div_factor = setting->divf ? setting->divf(drive) : 1;
  330. ide_write_setting(drive, setting, val * div_factor / mul_factor);
  331. }
  332. mutex_unlock(&ide_setting_mtx);
  333. }
  334. } while (!for_real++);
  335. free_page((unsigned long)buf);
  336. return count;
  337. parse_error:
  338. free_page((unsigned long)buf);
  339. printk("proc_ide_write_settings(): parse error\n");
  340. return -EINVAL;
  341. }
  342. int proc_ide_read_capacity
  343. (char *page, char **start, off_t off, int count, int *eof, void *data)
  344. {
  345. int len = sprintf(page, "%llu\n", (long long)0x7fffffff);
  346. PROC_IDE_READ_RETURN(page, start, off, count, eof, len);
  347. }
  348. EXPORT_SYMBOL_GPL(proc_ide_read_capacity);
  349. int proc_ide_read_geometry
  350. (char *page, char **start, off_t off, int count, int *eof, void *data)
  351. {
  352. ide_drive_t *drive = (ide_drive_t *) data;
  353. char *out = page;
  354. int len;
  355. out += sprintf(out, "physical %d/%d/%d\n",
  356. drive->cyl, drive->head, drive->sect);
  357. out += sprintf(out, "logical %d/%d/%d\n",
  358. drive->bios_cyl, drive->bios_head, drive->bios_sect);
  359. len = out - page;
  360. PROC_IDE_READ_RETURN(page, start, off, count, eof, len);
  361. }
  362. EXPORT_SYMBOL(proc_ide_read_geometry);
  363. static int proc_ide_read_dmodel
  364. (char *page, char **start, off_t off, int count, int *eof, void *data)
  365. {
  366. ide_drive_t *drive = (ide_drive_t *) data;
  367. char *m = (char *)&drive->id[ATA_ID_PROD];
  368. int len;
  369. len = sprintf(page, "%.40s\n", m[0] ? m : "(none)");
  370. PROC_IDE_READ_RETURN(page, start, off, count, eof, len);
  371. }
  372. static int proc_ide_read_driver
  373. (char *page, char **start, off_t off, int count, int *eof, void *data)
  374. {
  375. ide_drive_t *drive = (ide_drive_t *)data;
  376. struct device *dev = &drive->gendev;
  377. struct ide_driver *ide_drv;
  378. int len;
  379. if (dev->driver) {
  380. ide_drv = to_ide_driver(dev->driver);
  381. len = sprintf(page, "%s version %s\n",
  382. dev->driver->name, ide_drv->version);
  383. } else
  384. len = sprintf(page, "ide-default version 0.9.newide\n");
  385. PROC_IDE_READ_RETURN(page, start, off, count, eof, len);
  386. }
  387. static int ide_replace_subdriver(ide_drive_t *drive, const char *driver)
  388. {
  389. struct device *dev = &drive->gendev;
  390. int ret = 1;
  391. int err;
  392. device_release_driver(dev);
  393. /* FIXME: device can still be in use by previous driver */
  394. strlcpy(drive->driver_req, driver, sizeof(drive->driver_req));
  395. err = device_attach(dev);
  396. if (err < 0)
  397. printk(KERN_WARNING "IDE: %s: device_attach error: %d\n",
  398. __func__, err);
  399. drive->driver_req[0] = 0;
  400. if (dev->driver == NULL) {
  401. err = device_attach(dev);
  402. if (err < 0)
  403. printk(KERN_WARNING
  404. "IDE: %s: device_attach(2) error: %d\n",
  405. __func__, err);
  406. }
  407. if (dev->driver && !strcmp(dev->driver->name, driver))
  408. ret = 0;
  409. return ret;
  410. }
  411. static int proc_ide_write_driver
  412. (struct file *file, const char __user *buffer, unsigned long count, void *data)
  413. {
  414. ide_drive_t *drive = (ide_drive_t *) data;
  415. char name[32];
  416. if (!capable(CAP_SYS_ADMIN))
  417. return -EACCES;
  418. if (count > 31)
  419. count = 31;
  420. if (copy_from_user(name, buffer, count))
  421. return -EFAULT;
  422. name[count] = '\0';
  423. if (ide_replace_subdriver(drive, name))
  424. return -EINVAL;
  425. return count;
  426. }
  427. static int proc_ide_read_media
  428. (char *page, char **start, off_t off, int count, int *eof, void *data)
  429. {
  430. ide_drive_t *drive = (ide_drive_t *) data;
  431. const char *media;
  432. int len;
  433. switch (drive->media) {
  434. case ide_disk: media = "disk\n"; break;
  435. case ide_cdrom: media = "cdrom\n"; break;
  436. case ide_tape: media = "tape\n"; break;
  437. case ide_floppy: media = "floppy\n"; break;
  438. case ide_optical: media = "optical\n"; break;
  439. default: media = "UNKNOWN\n"; break;
  440. }
  441. strcpy(page, media);
  442. len = strlen(media);
  443. PROC_IDE_READ_RETURN(page, start, off, count, eof, len);
  444. }
  445. static ide_proc_entry_t generic_drive_entries[] = {
  446. { "driver", S_IFREG|S_IRUGO, proc_ide_read_driver,
  447. proc_ide_write_driver },
  448. { "identify", S_IFREG|S_IRUSR, proc_ide_read_identify, NULL },
  449. { "media", S_IFREG|S_IRUGO, proc_ide_read_media, NULL },
  450. { "model", S_IFREG|S_IRUGO, proc_ide_read_dmodel, NULL },
  451. { "settings", S_IFREG|S_IRUSR|S_IWUSR, proc_ide_read_settings,
  452. proc_ide_write_settings },
  453. { NULL, 0, NULL, NULL }
  454. };
  455. static void ide_add_proc_entries(struct proc_dir_entry *dir, ide_proc_entry_t *p, void *data)
  456. {
  457. struct proc_dir_entry *ent;
  458. if (!dir || !p)
  459. return;
  460. while (p->name != NULL) {
  461. ent = create_proc_entry(p->name, p->mode, dir);
  462. if (!ent) return;
  463. ent->data = data;
  464. ent->read_proc = p->read_proc;
  465. ent->write_proc = p->write_proc;
  466. p++;
  467. }
  468. }
  469. static void ide_remove_proc_entries(struct proc_dir_entry *dir, ide_proc_entry_t *p)
  470. {
  471. if (!dir || !p)
  472. return;
  473. while (p->name != NULL) {
  474. remove_proc_entry(p->name, dir);
  475. p++;
  476. }
  477. }
  478. void ide_proc_register_driver(ide_drive_t *drive, struct ide_driver *driver)
  479. {
  480. mutex_lock(&ide_setting_mtx);
  481. drive->settings = driver->proc_devsets(drive);
  482. mutex_unlock(&ide_setting_mtx);
  483. ide_add_proc_entries(drive->proc, driver->proc_entries(drive), drive);
  484. }
  485. EXPORT_SYMBOL(ide_proc_register_driver);
  486. /**
  487. * ide_proc_unregister_driver - remove driver specific data
  488. * @drive: drive
  489. * @driver: driver
  490. *
  491. * Clean up the driver specific /proc files and IDE settings
  492. * for a given drive.
  493. *
  494. * Takes ide_setting_mtx.
  495. */
  496. void ide_proc_unregister_driver(ide_drive_t *drive, struct ide_driver *driver)
  497. {
  498. ide_remove_proc_entries(drive->proc, driver->proc_entries(drive));
  499. mutex_lock(&ide_setting_mtx);
  500. /*
  501. * ide_setting_mtx protects both the settings list and the use
  502. * of settings (we cannot take a setting out that is being used).
  503. */
  504. drive->settings = NULL;
  505. mutex_unlock(&ide_setting_mtx);
  506. }
  507. EXPORT_SYMBOL(ide_proc_unregister_driver);
  508. void ide_proc_port_register_devices(ide_hwif_t *hwif)
  509. {
  510. struct proc_dir_entry *ent;
  511. struct proc_dir_entry *parent = hwif->proc;
  512. ide_drive_t *drive;
  513. char name[64];
  514. int i;
  515. ide_port_for_each_dev(i, drive, hwif) {
  516. if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0)
  517. continue;
  518. drive->proc = proc_mkdir(drive->name, parent);
  519. if (drive->proc)
  520. ide_add_proc_entries(drive->proc, generic_drive_entries, drive);
  521. sprintf(name, "ide%d/%s", (drive->name[2]-'a')/2, drive->name);
  522. ent = proc_symlink(drive->name, proc_ide_root, name);
  523. if (!ent) return;
  524. }
  525. }
  526. void ide_proc_unregister_device(ide_drive_t *drive)
  527. {
  528. if (drive->proc) {
  529. ide_remove_proc_entries(drive->proc, generic_drive_entries);
  530. remove_proc_entry(drive->name, proc_ide_root);
  531. remove_proc_entry(drive->name, drive->hwif->proc);
  532. drive->proc = NULL;
  533. }
  534. }
  535. static ide_proc_entry_t hwif_entries[] = {
  536. { "channel", S_IFREG|S_IRUGO, proc_ide_read_channel, NULL },
  537. { "mate", S_IFREG|S_IRUGO, proc_ide_read_mate, NULL },
  538. { "model", S_IFREG|S_IRUGO, proc_ide_read_imodel, NULL },
  539. { NULL, 0, NULL, NULL }
  540. };
  541. void ide_proc_register_port(ide_hwif_t *hwif)
  542. {
  543. if (!hwif->proc) {
  544. hwif->proc = proc_mkdir(hwif->name, proc_ide_root);
  545. if (!hwif->proc)
  546. return;
  547. ide_add_proc_entries(hwif->proc, hwif_entries, hwif);
  548. }
  549. }
  550. void ide_proc_unregister_port(ide_hwif_t *hwif)
  551. {
  552. if (hwif->proc) {
  553. ide_remove_proc_entries(hwif->proc, hwif_entries);
  554. remove_proc_entry(hwif->name, proc_ide_root);
  555. hwif->proc = NULL;
  556. }
  557. }
  558. static int proc_print_driver(struct device_driver *drv, void *data)
  559. {
  560. struct ide_driver *ide_drv = to_ide_driver(drv);
  561. struct seq_file *s = data;
  562. seq_printf(s, "%s version %s\n", drv->name, ide_drv->version);
  563. return 0;
  564. }
  565. static int ide_drivers_show(struct seq_file *s, void *p)
  566. {
  567. int err;
  568. err = bus_for_each_drv(&ide_bus_type, NULL, s, proc_print_driver);
  569. if (err < 0)
  570. printk(KERN_WARNING "IDE: %s: bus_for_each_drv error: %d\n",
  571. __func__, err);
  572. return 0;
  573. }
  574. static int ide_drivers_open(struct inode *inode, struct file *file)
  575. {
  576. return single_open(file, &ide_drivers_show, NULL);
  577. }
  578. static const struct file_operations ide_drivers_operations = {
  579. .owner = THIS_MODULE,
  580. .open = ide_drivers_open,
  581. .read = seq_read,
  582. .llseek = seq_lseek,
  583. .release = single_release,
  584. };
  585. void proc_ide_create(void)
  586. {
  587. proc_ide_root = proc_mkdir("ide", NULL);
  588. if (!proc_ide_root)
  589. return;
  590. proc_create("drivers", 0, proc_ide_root, &ide_drivers_operations);
  591. }
  592. void proc_ide_destroy(void)
  593. {
  594. remove_proc_entry("drivers", proc_ide_root);
  595. remove_proc_entry("ide", NULL);
  596. }