cdev.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771
  1. /*
  2. * Copyright (c) International Business Machines Corp., 2006
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
  12. * the GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17. *
  18. * Author: Artem Bityutskiy (Битюцкий Артём)
  19. */
  20. /*
  21. * This file includes implementation of UBI character device operations.
  22. *
  23. * There are two kinds of character devices in UBI: UBI character devices and
  24. * UBI volume character devices. UBI character devices allow users to
  25. * manipulate whole volumes: create, remove, and re-size them. Volume character
  26. * devices provide volume I/O capabilities.
  27. *
  28. * Major and minor numbers are assigned dynamically to both UBI and volume
  29. * character devices.
  30. *
  31. * Well, there is the third kind of character devices - the UBI control
  32. * character device, which allows to manipulate by UBI devices - create and
  33. * delete them. In other words, it is used for attaching and detaching MTD
  34. * devices.
  35. */
  36. #include <linux/module.h>
  37. #include <linux/stat.h>
  38. #include <linux/ioctl.h>
  39. #include <linux/capability.h>
  40. #include <mtd/ubi-user.h>
  41. #include <asm/uaccess.h>
  42. #include <asm/div64.h>
  43. #include "ubi.h"
  44. /**
  45. * get_exclusive - get exclusive access to an UBI volume.
  46. * @desc: volume descriptor
  47. *
  48. * This function changes UBI volume open mode to "exclusive". Returns previous
  49. * mode value (positive integer) in case of success and a negative error code
  50. * in case of failure.
  51. */
  52. static int get_exclusive(struct ubi_volume_desc *desc)
  53. {
  54. int users, err;
  55. struct ubi_volume *vol = desc->vol;
  56. spin_lock(&vol->ubi->volumes_lock);
  57. users = vol->readers + vol->writers + vol->exclusive;
  58. ubi_assert(users > 0);
  59. if (users > 1) {
  60. dbg_err("%d users for volume %d", users, vol->vol_id);
  61. err = -EBUSY;
  62. } else {
  63. vol->readers = vol->writers = 0;
  64. vol->exclusive = 1;
  65. err = desc->mode;
  66. desc->mode = UBI_EXCLUSIVE;
  67. }
  68. spin_unlock(&vol->ubi->volumes_lock);
  69. return err;
  70. }
  71. /**
  72. * revoke_exclusive - revoke exclusive mode.
  73. * @desc: volume descriptor
  74. * @mode: new mode to switch to
  75. */
  76. static void revoke_exclusive(struct ubi_volume_desc *desc, int mode)
  77. {
  78. struct ubi_volume *vol = desc->vol;
  79. spin_lock(&vol->ubi->volumes_lock);
  80. ubi_assert(vol->readers == 0 && vol->writers == 0);
  81. ubi_assert(vol->exclusive == 1 && desc->mode == UBI_EXCLUSIVE);
  82. vol->exclusive = 0;
  83. if (mode == UBI_READONLY)
  84. vol->readers = 1;
  85. else if (mode == UBI_READWRITE)
  86. vol->writers = 1;
  87. else
  88. vol->exclusive = 1;
  89. spin_unlock(&vol->ubi->volumes_lock);
  90. desc->mode = mode;
  91. }
  92. static int vol_cdev_open(struct inode *inode, struct file *file)
  93. {
  94. struct ubi_volume_desc *desc;
  95. int vol_id = iminor(inode) - 1, mode, ubi_num;
  96. ubi_num = ubi_major2num(imajor(inode));
  97. if (ubi_num < 0)
  98. return ubi_num;
  99. if (file->f_mode & FMODE_WRITE)
  100. mode = UBI_READWRITE;
  101. else
  102. mode = UBI_READONLY;
  103. dbg_msg("open volume %d, mode %d", vol_id, mode);
  104. desc = ubi_open_volume(ubi_num, vol_id, mode);
  105. if (IS_ERR(desc))
  106. return PTR_ERR(desc);
  107. file->private_data = desc;
  108. return 0;
  109. }
  110. static int vol_cdev_release(struct inode *inode, struct file *file)
  111. {
  112. struct ubi_volume_desc *desc = file->private_data;
  113. struct ubi_volume *vol = desc->vol;
  114. dbg_msg("release volume %d, mode %d", vol->vol_id, desc->mode);
  115. if (vol->updating) {
  116. ubi_warn("update of volume %d not finished, volume is damaged",
  117. vol->vol_id);
  118. vol->updating = 0;
  119. vfree(vol->upd_buf);
  120. }
  121. ubi_close_volume(desc);
  122. return 0;
  123. }
  124. static loff_t vol_cdev_llseek(struct file *file, loff_t offset, int origin)
  125. {
  126. struct ubi_volume_desc *desc = file->private_data;
  127. struct ubi_volume *vol = desc->vol;
  128. loff_t new_offset;
  129. if (vol->updating) {
  130. /* Update is in progress, seeking is prohibited */
  131. dbg_err("updating");
  132. return -EBUSY;
  133. }
  134. switch (origin) {
  135. case 0: /* SEEK_SET */
  136. new_offset = offset;
  137. break;
  138. case 1: /* SEEK_CUR */
  139. new_offset = file->f_pos + offset;
  140. break;
  141. case 2: /* SEEK_END */
  142. new_offset = vol->used_bytes + offset;
  143. break;
  144. default:
  145. return -EINVAL;
  146. }
  147. if (new_offset < 0 || new_offset > vol->used_bytes) {
  148. dbg_err("bad seek %lld", new_offset);
  149. return -EINVAL;
  150. }
  151. dbg_msg("seek volume %d, offset %lld, origin %d, new offset %lld",
  152. vol->vol_id, offset, origin, new_offset);
  153. file->f_pos = new_offset;
  154. return new_offset;
  155. }
  156. static ssize_t vol_cdev_read(struct file *file, __user char *buf, size_t count,
  157. loff_t *offp)
  158. {
  159. struct ubi_volume_desc *desc = file->private_data;
  160. struct ubi_volume *vol = desc->vol;
  161. struct ubi_device *ubi = vol->ubi;
  162. int err, lnum, off, len, tbuf_size;
  163. size_t count_save = count;
  164. void *tbuf;
  165. uint64_t tmp;
  166. dbg_msg("read %zd bytes from offset %lld of volume %d",
  167. count, *offp, vol->vol_id);
  168. if (vol->updating) {
  169. dbg_err("updating");
  170. return -EBUSY;
  171. }
  172. if (vol->upd_marker) {
  173. dbg_err("damaged volume, update marker is set");
  174. return -EBADF;
  175. }
  176. if (*offp == vol->used_bytes || count == 0)
  177. return 0;
  178. if (vol->corrupted)
  179. dbg_msg("read from corrupted volume %d", vol->vol_id);
  180. if (*offp + count > vol->used_bytes)
  181. count_save = count = vol->used_bytes - *offp;
  182. tbuf_size = vol->usable_leb_size;
  183. if (count < tbuf_size)
  184. tbuf_size = ALIGN(count, ubi->min_io_size);
  185. tbuf = vmalloc(tbuf_size);
  186. if (!tbuf)
  187. return -ENOMEM;
  188. len = count > tbuf_size ? tbuf_size : count;
  189. tmp = *offp;
  190. off = do_div(tmp, vol->usable_leb_size);
  191. lnum = tmp;
  192. do {
  193. cond_resched();
  194. if (off + len >= vol->usable_leb_size)
  195. len = vol->usable_leb_size - off;
  196. err = ubi_eba_read_leb(ubi, vol, lnum, tbuf, off, len, 0);
  197. if (err)
  198. break;
  199. off += len;
  200. if (off == vol->usable_leb_size) {
  201. lnum += 1;
  202. off -= vol->usable_leb_size;
  203. }
  204. count -= len;
  205. *offp += len;
  206. err = copy_to_user(buf, tbuf, len);
  207. if (err) {
  208. err = -EFAULT;
  209. break;
  210. }
  211. buf += len;
  212. len = count > tbuf_size ? tbuf_size : count;
  213. } while (count);
  214. vfree(tbuf);
  215. return err ? err : count_save - count;
  216. }
  217. #ifdef CONFIG_MTD_UBI_DEBUG_USERSPACE_IO
  218. /*
  219. * This function allows to directly write to dynamic UBI volumes, without
  220. * issuing the volume update operation. Available only as a debugging feature.
  221. * Very useful for testing UBI.
  222. */
  223. static ssize_t vol_cdev_direct_write(struct file *file, const char __user *buf,
  224. size_t count, loff_t *offp)
  225. {
  226. struct ubi_volume_desc *desc = file->private_data;
  227. struct ubi_volume *vol = desc->vol;
  228. struct ubi_device *ubi = vol->ubi;
  229. int lnum, off, len, tbuf_size, err = 0;
  230. size_t count_save = count;
  231. char *tbuf;
  232. uint64_t tmp;
  233. dbg_msg("requested: write %zd bytes to offset %lld of volume %u",
  234. count, *offp, vol->vol_id);
  235. if (vol->vol_type == UBI_STATIC_VOLUME)
  236. return -EROFS;
  237. tmp = *offp;
  238. off = do_div(tmp, vol->usable_leb_size);
  239. lnum = tmp;
  240. if (off % ubi->min_io_size) {
  241. dbg_err("unaligned position");
  242. return -EINVAL;
  243. }
  244. if (*offp + count > vol->used_bytes)
  245. count_save = count = vol->used_bytes - *offp;
  246. /* We can write only in fractions of the minimum I/O unit */
  247. if (count % ubi->min_io_size) {
  248. dbg_err("unaligned write length");
  249. return -EINVAL;
  250. }
  251. tbuf_size = vol->usable_leb_size;
  252. if (count < tbuf_size)
  253. tbuf_size = ALIGN(count, ubi->min_io_size);
  254. tbuf = vmalloc(tbuf_size);
  255. if (!tbuf)
  256. return -ENOMEM;
  257. len = count > tbuf_size ? tbuf_size : count;
  258. while (count) {
  259. cond_resched();
  260. if (off + len >= vol->usable_leb_size)
  261. len = vol->usable_leb_size - off;
  262. err = copy_from_user(tbuf, buf, len);
  263. if (err) {
  264. err = -EFAULT;
  265. break;
  266. }
  267. err = ubi_eba_write_leb(ubi, vol, lnum, tbuf, off, len,
  268. UBI_UNKNOWN);
  269. if (err)
  270. break;
  271. off += len;
  272. if (off == vol->usable_leb_size) {
  273. lnum += 1;
  274. off -= vol->usable_leb_size;
  275. }
  276. count -= len;
  277. *offp += len;
  278. buf += len;
  279. len = count > tbuf_size ? tbuf_size : count;
  280. }
  281. vfree(tbuf);
  282. return err ? err : count_save - count;
  283. }
  284. #else
  285. #define vol_cdev_direct_write(file, buf, count, offp) -EPERM
  286. #endif /* CONFIG_MTD_UBI_DEBUG_USERSPACE_IO */
  287. static ssize_t vol_cdev_write(struct file *file, const char __user *buf,
  288. size_t count, loff_t *offp)
  289. {
  290. int err = 0;
  291. struct ubi_volume_desc *desc = file->private_data;
  292. struct ubi_volume *vol = desc->vol;
  293. struct ubi_device *ubi = vol->ubi;
  294. if (!vol->updating)
  295. return vol_cdev_direct_write(file, buf, count, offp);
  296. err = ubi_more_update_data(ubi, vol->vol_id, buf, count);
  297. if (err < 0) {
  298. ubi_err("cannot write %zd bytes of update data, error %d",
  299. count, err);
  300. return err;
  301. }
  302. if (err) {
  303. /*
  304. * Update is finished, @err contains number of actually written
  305. * bytes now.
  306. */
  307. count = err;
  308. vol->updating = 0;
  309. err = ubi_check_volume(ubi, vol->vol_id);
  310. if (err < 0)
  311. return err;
  312. if (err) {
  313. ubi_warn("volume %d on UBI device %d is corrupted",
  314. vol->vol_id, ubi->ubi_num);
  315. vol->corrupted = 1;
  316. }
  317. vol->checked = 1;
  318. ubi_gluebi_updated(vol);
  319. revoke_exclusive(desc, UBI_READWRITE);
  320. }
  321. return count;
  322. }
  323. static int vol_cdev_ioctl(struct inode *inode, struct file *file,
  324. unsigned int cmd, unsigned long arg)
  325. {
  326. int err = 0;
  327. struct ubi_volume_desc *desc = file->private_data;
  328. struct ubi_volume *vol = desc->vol;
  329. struct ubi_device *ubi = vol->ubi;
  330. void __user *argp = (void __user *)arg;
  331. switch (cmd) {
  332. /* Volume update command */
  333. case UBI_IOCVOLUP:
  334. {
  335. int64_t bytes, rsvd_bytes;
  336. if (!capable(CAP_SYS_RESOURCE)) {
  337. err = -EPERM;
  338. break;
  339. }
  340. err = copy_from_user(&bytes, argp, sizeof(int64_t));
  341. if (err) {
  342. err = -EFAULT;
  343. break;
  344. }
  345. if (desc->mode == UBI_READONLY) {
  346. err = -EROFS;
  347. break;
  348. }
  349. rsvd_bytes = vol->reserved_pebs * (ubi->leb_size-vol->data_pad);
  350. if (bytes < 0 || bytes > rsvd_bytes) {
  351. err = -EINVAL;
  352. break;
  353. }
  354. err = get_exclusive(desc);
  355. if (err < 0)
  356. break;
  357. err = ubi_start_update(ubi, vol->vol_id, bytes);
  358. if (bytes == 0)
  359. revoke_exclusive(desc, UBI_READWRITE);
  360. break;
  361. }
  362. #ifdef CONFIG_MTD_UBI_DEBUG_USERSPACE_IO
  363. /* Logical eraseblock erasure command */
  364. case UBI_IOCEBER:
  365. {
  366. int32_t lnum;
  367. err = get_user(lnum, (__user int32_t *)argp);
  368. if (err) {
  369. err = -EFAULT;
  370. break;
  371. }
  372. if (desc->mode == UBI_READONLY) {
  373. err = -EROFS;
  374. break;
  375. }
  376. if (lnum < 0 || lnum >= vol->reserved_pebs) {
  377. err = -EINVAL;
  378. break;
  379. }
  380. if (vol->vol_type != UBI_DYNAMIC_VOLUME) {
  381. err = -EROFS;
  382. break;
  383. }
  384. dbg_msg("erase LEB %d:%d", vol->vol_id, lnum);
  385. err = ubi_eba_unmap_leb(ubi, vol, lnum);
  386. if (err)
  387. break;
  388. err = ubi_wl_flush(ubi);
  389. break;
  390. }
  391. #endif
  392. default:
  393. err = -ENOTTY;
  394. break;
  395. }
  396. return err;
  397. }
  398. /**
  399. * verify_mkvol_req - verify volume creation request.
  400. * @ubi: UBI device description object
  401. * @req: the request to check
  402. *
  403. * This function zero if the request is correct, and %-EINVAL if not.
  404. */
  405. static int verify_mkvol_req(const struct ubi_device *ubi,
  406. const struct ubi_mkvol_req *req)
  407. {
  408. int n, err = -EINVAL;
  409. if (req->bytes < 0 || req->alignment < 0 || req->vol_type < 0 ||
  410. req->name_len < 0)
  411. goto bad;
  412. if ((req->vol_id < 0 || req->vol_id >= ubi->vtbl_slots) &&
  413. req->vol_id != UBI_VOL_NUM_AUTO)
  414. goto bad;
  415. if (req->alignment == 0)
  416. goto bad;
  417. if (req->bytes == 0)
  418. goto bad;
  419. if (req->vol_type != UBI_DYNAMIC_VOLUME &&
  420. req->vol_type != UBI_STATIC_VOLUME)
  421. goto bad;
  422. if (req->alignment > ubi->leb_size)
  423. goto bad;
  424. n = req->alignment % ubi->min_io_size;
  425. if (req->alignment != 1 && n)
  426. goto bad;
  427. if (req->name_len > UBI_VOL_NAME_MAX) {
  428. err = -ENAMETOOLONG;
  429. goto bad;
  430. }
  431. return 0;
  432. bad:
  433. dbg_err("bad volume creation request");
  434. ubi_dbg_dump_mkvol_req(req);
  435. return err;
  436. }
  437. /**
  438. * verify_rsvol_req - verify volume re-size request.
  439. * @ubi: UBI device description object
  440. * @req: the request to check
  441. *
  442. * This function returns zero if the request is correct, and %-EINVAL if not.
  443. */
  444. static int verify_rsvol_req(const struct ubi_device *ubi,
  445. const struct ubi_rsvol_req *req)
  446. {
  447. if (req->bytes <= 0)
  448. return -EINVAL;
  449. if (req->vol_id < 0 || req->vol_id >= ubi->vtbl_slots)
  450. return -EINVAL;
  451. return 0;
  452. }
  453. static int ubi_cdev_ioctl(struct inode *inode, struct file *file,
  454. unsigned int cmd, unsigned long arg)
  455. {
  456. int err = 0;
  457. struct ubi_device *ubi;
  458. struct ubi_volume_desc *desc;
  459. void __user *argp = (void __user *)arg;
  460. if (!capable(CAP_SYS_RESOURCE))
  461. return -EPERM;
  462. ubi = ubi_get_by_major(imajor(inode));
  463. if (!ubi)
  464. return -ENODEV;
  465. switch (cmd) {
  466. /* Create volume command */
  467. case UBI_IOCMKVOL:
  468. {
  469. struct ubi_mkvol_req req;
  470. dbg_msg("create volume");
  471. err = copy_from_user(&req, argp, sizeof(struct ubi_mkvol_req));
  472. if (err) {
  473. err = -EFAULT;
  474. break;
  475. }
  476. err = verify_mkvol_req(ubi, &req);
  477. if (err)
  478. break;
  479. req.name[req.name_len] = '\0';
  480. mutex_lock(&ubi->volumes_mutex);
  481. err = ubi_create_volume(ubi, &req);
  482. mutex_unlock(&ubi->volumes_mutex);
  483. if (err)
  484. break;
  485. err = put_user(req.vol_id, (__user int32_t *)argp);
  486. if (err)
  487. err = -EFAULT;
  488. break;
  489. }
  490. /* Remove volume command */
  491. case UBI_IOCRMVOL:
  492. {
  493. int vol_id;
  494. dbg_msg("remove volume");
  495. err = get_user(vol_id, (__user int32_t *)argp);
  496. if (err) {
  497. err = -EFAULT;
  498. break;
  499. }
  500. desc = ubi_open_volume(ubi->ubi_num, vol_id, UBI_EXCLUSIVE);
  501. if (IS_ERR(desc)) {
  502. err = PTR_ERR(desc);
  503. break;
  504. }
  505. mutex_lock(&ubi->volumes_mutex);
  506. err = ubi_remove_volume(desc);
  507. mutex_unlock(&ubi->volumes_mutex);
  508. /*
  509. * The volume is deleted (unless an error occurred), and the
  510. * 'struct ubi_volume' object will be freed when
  511. * 'ubi_close_volume()' will call 'put_device()'.
  512. */
  513. ubi_close_volume(desc);
  514. break;
  515. }
  516. /* Re-size volume command */
  517. case UBI_IOCRSVOL:
  518. {
  519. int pebs;
  520. uint64_t tmp;
  521. struct ubi_rsvol_req req;
  522. dbg_msg("re-size volume");
  523. err = copy_from_user(&req, argp, sizeof(struct ubi_rsvol_req));
  524. if (err) {
  525. err = -EFAULT;
  526. break;
  527. }
  528. err = verify_rsvol_req(ubi, &req);
  529. if (err)
  530. break;
  531. desc = ubi_open_volume(ubi->ubi_num, req.vol_id, UBI_EXCLUSIVE);
  532. if (IS_ERR(desc)) {
  533. err = PTR_ERR(desc);
  534. break;
  535. }
  536. tmp = req.bytes;
  537. pebs = !!do_div(tmp, desc->vol->usable_leb_size);
  538. pebs += tmp;
  539. mutex_lock(&ubi->volumes_mutex);
  540. err = ubi_resize_volume(desc, pebs);
  541. mutex_unlock(&ubi->volumes_mutex);
  542. ubi_close_volume(desc);
  543. break;
  544. }
  545. default:
  546. err = -ENOTTY;
  547. break;
  548. }
  549. ubi_put_device(ubi);
  550. return err;
  551. }
  552. static int ctrl_cdev_ioctl(struct inode *inode, struct file *file,
  553. unsigned int cmd, unsigned long arg)
  554. {
  555. int err = 0;
  556. void __user *argp = (void __user *)arg;
  557. if (!capable(CAP_SYS_RESOURCE))
  558. return -EPERM;
  559. switch (cmd) {
  560. /* Attach an MTD device command */
  561. case UBI_IOCATT:
  562. {
  563. struct ubi_attach_req req;
  564. struct mtd_info *mtd;
  565. dbg_msg("attach MTD device");
  566. err = copy_from_user(&req, argp, sizeof(struct ubi_attach_req));
  567. if (err) {
  568. err = -EFAULT;
  569. break;
  570. }
  571. if (req.mtd_num < 0 ||
  572. (req.ubi_num < 0 && req.ubi_num != UBI_DEV_NUM_AUTO)) {
  573. err = -EINVAL;
  574. break;
  575. }
  576. mtd = get_mtd_device(NULL, req.mtd_num);
  577. if (IS_ERR(mtd)) {
  578. err = PTR_ERR(mtd);
  579. break;
  580. }
  581. /*
  582. * Note, further request verification is done by
  583. * 'ubi_attach_mtd_dev()'.
  584. */
  585. mutex_lock(&ubi_devices_mutex);
  586. err = ubi_attach_mtd_dev(mtd, req.ubi_num, req.vid_hdr_offset);
  587. mutex_unlock(&ubi_devices_mutex);
  588. if (err < 0)
  589. put_mtd_device(mtd);
  590. else
  591. /* @err contains UBI device number */
  592. err = put_user(err, (__user int32_t *)argp);
  593. break;
  594. }
  595. /* Detach an MTD device command */
  596. case UBI_IOCDET:
  597. {
  598. int ubi_num;
  599. dbg_msg("dettach MTD device");
  600. err = get_user(ubi_num, (__user int32_t *)argp);
  601. if (err) {
  602. err = -EFAULT;
  603. break;
  604. }
  605. mutex_lock(&ubi_devices_mutex);
  606. err = ubi_detach_mtd_dev(ubi_num, 0);
  607. mutex_unlock(&ubi_devices_mutex);
  608. break;
  609. }
  610. default:
  611. err = -ENOTTY;
  612. break;
  613. }
  614. return err;
  615. }
  616. /* UBI control character device operations */
  617. struct file_operations ubi_ctrl_cdev_operations = {
  618. .ioctl = ctrl_cdev_ioctl,
  619. .owner = THIS_MODULE,
  620. };
  621. /* UBI character device operations */
  622. struct file_operations ubi_cdev_operations = {
  623. .owner = THIS_MODULE,
  624. .ioctl = ubi_cdev_ioctl,
  625. .llseek = no_llseek,
  626. };
  627. /* UBI volume character device operations */
  628. struct file_operations ubi_vol_cdev_operations = {
  629. .owner = THIS_MODULE,
  630. .open = vol_cdev_open,
  631. .release = vol_cdev_release,
  632. .llseek = vol_cdev_llseek,
  633. .read = vol_cdev_read,
  634. .write = vol_cdev_write,
  635. .ioctl = vol_cdev_ioctl,
  636. };