dir.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705
  1. /*
  2. * Directory operations for Coda filesystem
  3. * Original version: (C) 1996 P. Braam and M. Callahan
  4. * Rewritten for Linux 2.1. (C) 1997 Carnegie Mellon University
  5. *
  6. * Carnegie Mellon encourages users to contribute improvements to
  7. * the Coda project. Contact Peter Braam (coda@cs.cmu.edu).
  8. */
  9. #include <linux/types.h>
  10. #include <linux/kernel.h>
  11. #include <linux/time.h>
  12. #include <linux/fs.h>
  13. #include <linux/file.h>
  14. #include <linux/stat.h>
  15. #include <linux/errno.h>
  16. #include <linux/string.h>
  17. #include <linux/smp_lock.h>
  18. #include <asm/uaccess.h>
  19. #include <linux/coda.h>
  20. #include <linux/coda_linux.h>
  21. #include <linux/coda_psdev.h>
  22. #include <linux/coda_fs_i.h>
  23. #include <linux/coda_cache.h>
  24. #include <linux/coda_proc.h>
  25. #include "coda_int.h"
  26. /* dir inode-ops */
  27. static int coda_create(struct inode *dir, struct dentry *new, int mode, struct nameidata *nd);
  28. static struct dentry *coda_lookup(struct inode *dir, struct dentry *target, struct nameidata *nd);
  29. static int coda_link(struct dentry *old_dentry, struct inode *dir_inode,
  30. struct dentry *entry);
  31. static int coda_unlink(struct inode *dir_inode, struct dentry *entry);
  32. static int coda_symlink(struct inode *dir_inode, struct dentry *entry,
  33. const char *symname);
  34. static int coda_mkdir(struct inode *dir_inode, struct dentry *entry, int mode);
  35. static int coda_rmdir(struct inode *dir_inode, struct dentry *entry);
  36. static int coda_rename(struct inode *old_inode, struct dentry *old_dentry,
  37. struct inode *new_inode, struct dentry *new_dentry);
  38. /* dir file-ops */
  39. static int coda_readdir(struct file *file, void *dirent, filldir_t filldir);
  40. /* dentry ops */
  41. static int coda_dentry_revalidate(struct dentry *de, struct nameidata *nd);
  42. static int coda_dentry_delete(struct dentry *);
  43. /* support routines */
  44. static int coda_venus_readdir(struct file *filp, filldir_t filldir,
  45. void *dirent, struct dentry *dir);
  46. /* same as fs/bad_inode.c */
  47. static int coda_return_EIO(void)
  48. {
  49. return -EIO;
  50. }
  51. #define CODA_EIO_ERROR ((void *) (coda_return_EIO))
  52. static struct dentry_operations coda_dentry_operations =
  53. {
  54. .d_revalidate = coda_dentry_revalidate,
  55. .d_delete = coda_dentry_delete,
  56. };
  57. const struct inode_operations coda_dir_inode_operations =
  58. {
  59. .create = coda_create,
  60. .lookup = coda_lookup,
  61. .link = coda_link,
  62. .unlink = coda_unlink,
  63. .symlink = coda_symlink,
  64. .mkdir = coda_mkdir,
  65. .rmdir = coda_rmdir,
  66. .mknod = CODA_EIO_ERROR,
  67. .rename = coda_rename,
  68. .permission = coda_permission,
  69. .getattr = coda_getattr,
  70. .setattr = coda_setattr,
  71. };
  72. const struct file_operations coda_dir_operations = {
  73. .llseek = generic_file_llseek,
  74. .read = generic_read_dir,
  75. .readdir = coda_readdir,
  76. .open = coda_open,
  77. .flush = coda_flush,
  78. .release = coda_release,
  79. .fsync = coda_fsync,
  80. };
  81. /* inode operations for directories */
  82. /* access routines: lookup, readlink, permission */
  83. static struct dentry *coda_lookup(struct inode *dir, struct dentry *entry, struct nameidata *nd)
  84. {
  85. struct inode *res_inode = NULL;
  86. struct CodaFid resfid = { { 0, } };
  87. int dropme = 0; /* to indicate entry should not be cached */
  88. int type = 0;
  89. int error = 0;
  90. const char *name = entry->d_name.name;
  91. size_t length = entry->d_name.len;
  92. if ( length > CODA_MAXNAMLEN ) {
  93. printk("name too long: lookup, %s (%*s)\n",
  94. coda_i2s(dir), (int)length, name);
  95. return ERR_PTR(-ENAMETOOLONG);
  96. }
  97. lock_kernel();
  98. /* control object, create inode on the fly */
  99. if (coda_isroot(dir) && coda_iscontrol(name, length)) {
  100. error = coda_cnode_makectl(&res_inode, dir->i_sb);
  101. dropme = 1;
  102. goto exit;
  103. }
  104. error = venus_lookup(dir->i_sb, coda_i2f(dir),
  105. (const char *)name, length, &type, &resfid);
  106. res_inode = NULL;
  107. if (!error) {
  108. if (type & CODA_NOCACHE) {
  109. type &= (~CODA_NOCACHE);
  110. dropme = 1;
  111. }
  112. error = coda_cnode_make(&res_inode, &resfid, dir->i_sb);
  113. if (error) {
  114. unlock_kernel();
  115. return ERR_PTR(error);
  116. }
  117. } else if (error != -ENOENT) {
  118. unlock_kernel();
  119. return ERR_PTR(error);
  120. }
  121. exit:
  122. entry->d_time = 0;
  123. entry->d_op = &coda_dentry_operations;
  124. d_add(entry, res_inode);
  125. if ( dropme ) {
  126. d_drop(entry);
  127. coda_flag_inode(res_inode, C_VATTR);
  128. }
  129. unlock_kernel();
  130. return NULL;
  131. }
  132. int coda_permission(struct inode *inode, int mask, struct nameidata *nd)
  133. {
  134. int error = 0;
  135. if (!mask)
  136. return 0;
  137. lock_kernel();
  138. coda_vfs_stat.permission++;
  139. if (coda_cache_check(inode, mask))
  140. goto out;
  141. error = venus_access(inode->i_sb, coda_i2f(inode), mask);
  142. if (!error)
  143. coda_cache_enter(inode, mask);
  144. out:
  145. unlock_kernel();
  146. return error;
  147. }
  148. static inline void coda_dir_changed(struct inode *dir, int link)
  149. {
  150. #ifdef REQUERY_VENUS_FOR_MTIME
  151. /* invalidate the directory cnode's attributes so we refetch the
  152. * attributes from venus next time the inode is referenced */
  153. coda_flag_inode(dir, C_VATTR);
  154. #else
  155. /* optimistically we can also act as if our nose bleeds. The
  156. * granularity of the mtime is coarse anyways so we might actually be
  157. * right most of the time. Note: we only do this for directories. */
  158. dir->i_mtime = dir->i_ctime = CURRENT_TIME_SEC;
  159. #endif
  160. if (link)
  161. dir->i_nlink += link;
  162. }
  163. /* creation routines: create, mknod, mkdir, link, symlink */
  164. static int coda_create(struct inode *dir, struct dentry *de, int mode, struct nameidata *nd)
  165. {
  166. int error=0;
  167. const char *name=de->d_name.name;
  168. int length=de->d_name.len;
  169. struct inode *inode;
  170. struct CodaFid newfid;
  171. struct coda_vattr attrs;
  172. lock_kernel();
  173. coda_vfs_stat.create++;
  174. if (coda_isroot(dir) && coda_iscontrol(name, length)) {
  175. unlock_kernel();
  176. return -EPERM;
  177. }
  178. error = venus_create(dir->i_sb, coda_i2f(dir), name, length,
  179. 0, mode, &newfid, &attrs);
  180. if ( error ) {
  181. unlock_kernel();
  182. d_drop(de);
  183. return error;
  184. }
  185. inode = coda_iget(dir->i_sb, &newfid, &attrs);
  186. if ( IS_ERR(inode) ) {
  187. unlock_kernel();
  188. d_drop(de);
  189. return PTR_ERR(inode);
  190. }
  191. /* invalidate the directory cnode's attributes */
  192. coda_dir_changed(dir, 0);
  193. unlock_kernel();
  194. d_instantiate(de, inode);
  195. return 0;
  196. }
  197. static int coda_mkdir(struct inode *dir, struct dentry *de, int mode)
  198. {
  199. struct inode *inode;
  200. struct coda_vattr attrs;
  201. const char *name = de->d_name.name;
  202. int len = de->d_name.len;
  203. int error;
  204. struct CodaFid newfid;
  205. lock_kernel();
  206. coda_vfs_stat.mkdir++;
  207. if (coda_isroot(dir) && coda_iscontrol(name, len)) {
  208. unlock_kernel();
  209. return -EPERM;
  210. }
  211. attrs.va_mode = mode;
  212. error = venus_mkdir(dir->i_sb, coda_i2f(dir),
  213. name, len, &newfid, &attrs);
  214. if ( error ) {
  215. unlock_kernel();
  216. d_drop(de);
  217. return error;
  218. }
  219. inode = coda_iget(dir->i_sb, &newfid, &attrs);
  220. if ( IS_ERR(inode) ) {
  221. unlock_kernel();
  222. d_drop(de);
  223. return PTR_ERR(inode);
  224. }
  225. /* invalidate the directory cnode's attributes */
  226. coda_dir_changed(dir, 1);
  227. unlock_kernel();
  228. d_instantiate(de, inode);
  229. return 0;
  230. }
  231. /* try to make de an entry in dir_inodde linked to source_de */
  232. static int coda_link(struct dentry *source_de, struct inode *dir_inode,
  233. struct dentry *de)
  234. {
  235. struct inode *inode = source_de->d_inode;
  236. const char * name = de->d_name.name;
  237. int len = de->d_name.len;
  238. int error;
  239. lock_kernel();
  240. coda_vfs_stat.link++;
  241. if (coda_isroot(dir_inode) && coda_iscontrol(name, len)) {
  242. unlock_kernel();
  243. return -EPERM;
  244. }
  245. error = venus_link(dir_inode->i_sb, coda_i2f(inode),
  246. coda_i2f(dir_inode), (const char *)name, len);
  247. if (error) {
  248. d_drop(de);
  249. goto out;
  250. }
  251. coda_dir_changed(dir_inode, 0);
  252. atomic_inc(&inode->i_count);
  253. d_instantiate(de, inode);
  254. inc_nlink(inode);
  255. out:
  256. unlock_kernel();
  257. return(error);
  258. }
  259. static int coda_symlink(struct inode *dir_inode, struct dentry *de,
  260. const char *symname)
  261. {
  262. const char *name = de->d_name.name;
  263. int len = de->d_name.len;
  264. int symlen;
  265. int error=0;
  266. lock_kernel();
  267. coda_vfs_stat.symlink++;
  268. if (coda_isroot(dir_inode) && coda_iscontrol(name, len)) {
  269. unlock_kernel();
  270. return -EPERM;
  271. }
  272. symlen = strlen(symname);
  273. if ( symlen > CODA_MAXPATHLEN ) {
  274. unlock_kernel();
  275. return -ENAMETOOLONG;
  276. }
  277. /*
  278. * This entry is now negative. Since we do not create
  279. * an inode for the entry we have to drop it.
  280. */
  281. d_drop(de);
  282. error = venus_symlink(dir_inode->i_sb, coda_i2f(dir_inode), name, len,
  283. symname, symlen);
  284. /* mtime is no good anymore */
  285. if ( !error )
  286. coda_dir_changed(dir_inode, 0);
  287. unlock_kernel();
  288. return error;
  289. }
  290. /* destruction routines: unlink, rmdir */
  291. int coda_unlink(struct inode *dir, struct dentry *de)
  292. {
  293. int error;
  294. const char *name = de->d_name.name;
  295. int len = de->d_name.len;
  296. lock_kernel();
  297. coda_vfs_stat.unlink++;
  298. error = venus_remove(dir->i_sb, coda_i2f(dir), name, len);
  299. if ( error ) {
  300. unlock_kernel();
  301. return error;
  302. }
  303. coda_dir_changed(dir, 0);
  304. drop_nlink(de->d_inode);
  305. unlock_kernel();
  306. return 0;
  307. }
  308. int coda_rmdir(struct inode *dir, struct dentry *de)
  309. {
  310. const char *name = de->d_name.name;
  311. int len = de->d_name.len;
  312. int error;
  313. lock_kernel();
  314. coda_vfs_stat.rmdir++;
  315. if (!d_unhashed(de)) {
  316. unlock_kernel();
  317. return -EBUSY;
  318. }
  319. error = venus_rmdir(dir->i_sb, coda_i2f(dir), name, len);
  320. if ( error ) {
  321. unlock_kernel();
  322. return error;
  323. }
  324. coda_dir_changed(dir, -1);
  325. drop_nlink(de->d_inode);
  326. d_delete(de);
  327. unlock_kernel();
  328. return 0;
  329. }
  330. /* rename */
  331. static int coda_rename(struct inode *old_dir, struct dentry *old_dentry,
  332. struct inode *new_dir, struct dentry *new_dentry)
  333. {
  334. const char *old_name = old_dentry->d_name.name;
  335. const char *new_name = new_dentry->d_name.name;
  336. int old_length = old_dentry->d_name.len;
  337. int new_length = new_dentry->d_name.len;
  338. int link_adjust = 0;
  339. int error;
  340. lock_kernel();
  341. coda_vfs_stat.rename++;
  342. error = venus_rename(old_dir->i_sb, coda_i2f(old_dir),
  343. coda_i2f(new_dir), old_length, new_length,
  344. (const char *) old_name, (const char *)new_name);
  345. if ( !error ) {
  346. if ( new_dentry->d_inode ) {
  347. if ( S_ISDIR(new_dentry->d_inode->i_mode) )
  348. link_adjust = 1;
  349. coda_dir_changed(old_dir, -link_adjust);
  350. coda_dir_changed(new_dir, link_adjust);
  351. coda_flag_inode(new_dentry->d_inode, C_VATTR);
  352. } else {
  353. coda_flag_inode(old_dir, C_VATTR);
  354. coda_flag_inode(new_dir, C_VATTR);
  355. }
  356. }
  357. unlock_kernel();
  358. return error;
  359. }
  360. /* file operations for directories */
  361. int coda_readdir(struct file *coda_file, void *dirent, filldir_t filldir)
  362. {
  363. struct dentry *coda_dentry = coda_file->f_path.dentry;
  364. struct coda_file_info *cfi;
  365. struct file *host_file;
  366. struct inode *host_inode;
  367. int ret;
  368. cfi = CODA_FTOC(coda_file);
  369. BUG_ON(!cfi || cfi->cfi_magic != CODA_MAGIC);
  370. host_file = cfi->cfi_container;
  371. coda_vfs_stat.readdir++;
  372. host_inode = host_file->f_path.dentry->d_inode;
  373. mutex_lock(&host_inode->i_mutex);
  374. host_file->f_pos = coda_file->f_pos;
  375. if (!host_file->f_op->readdir) {
  376. /* Venus: we must read Venus dirents from the file */
  377. ret = coda_venus_readdir(host_file, filldir, dirent, coda_dentry);
  378. } else {
  379. /* potemkin case: we were handed a directory inode. */
  380. /* Yuk, we can't call vfs_readdir because we are already
  381. * holding the inode semaphore. */
  382. ret = -ENOTDIR;
  383. if (!host_file->f_op || !host_file->f_op->readdir)
  384. goto out;
  385. ret = -ENOENT;
  386. if (!IS_DEADDIR(host_inode)) {
  387. ret = host_file->f_op->readdir(host_file, filldir, dirent);
  388. file_accessed(host_file);
  389. }
  390. }
  391. out:
  392. coda_file->f_pos = host_file->f_pos;
  393. mutex_unlock(&host_inode->i_mutex);
  394. return ret;
  395. }
  396. static inline unsigned int CDT2DT(unsigned char cdt)
  397. {
  398. unsigned int dt;
  399. switch(cdt) {
  400. case CDT_UNKNOWN: dt = DT_UNKNOWN; break;
  401. case CDT_FIFO: dt = DT_FIFO; break;
  402. case CDT_CHR: dt = DT_CHR; break;
  403. case CDT_DIR: dt = DT_DIR; break;
  404. case CDT_BLK: dt = DT_BLK; break;
  405. case CDT_REG: dt = DT_REG; break;
  406. case CDT_LNK: dt = DT_LNK; break;
  407. case CDT_SOCK: dt = DT_SOCK; break;
  408. case CDT_WHT: dt = DT_WHT; break;
  409. default: dt = DT_UNKNOWN; break;
  410. }
  411. return dt;
  412. }
  413. /* support routines */
  414. static int coda_venus_readdir(struct file *filp, filldir_t filldir,
  415. void *dirent, struct dentry *dir)
  416. {
  417. int result = 0; /* # of entries returned */
  418. struct venus_dirent *vdir;
  419. unsigned long vdir_size =
  420. (unsigned long)(&((struct venus_dirent *)0)->d_name);
  421. unsigned int type;
  422. struct qstr name;
  423. ino_t ino;
  424. int ret, i;
  425. vdir = kmalloc(sizeof(*vdir), GFP_KERNEL);
  426. if (!vdir) return -ENOMEM;
  427. i = filp->f_pos;
  428. switch(i) {
  429. case 0:
  430. ret = filldir(dirent, ".", 1, 0, dir->d_inode->i_ino, DT_DIR);
  431. if (ret < 0) break;
  432. result++;
  433. filp->f_pos++;
  434. /* fallthrough */
  435. case 1:
  436. ret = filldir(dirent, "..", 2, 1, dir->d_parent->d_inode->i_ino, DT_DIR);
  437. if (ret < 0) break;
  438. result++;
  439. filp->f_pos++;
  440. /* fallthrough */
  441. default:
  442. while (1) {
  443. /* read entries from the directory file */
  444. ret = kernel_read(filp, filp->f_pos - 2, (char *)vdir,
  445. sizeof(*vdir));
  446. if (ret < 0) {
  447. printk("coda_venus_readdir: read dir failed %d\n", ret);
  448. break;
  449. }
  450. if (ret == 0) break; /* end of directory file reached */
  451. /* catch truncated reads */
  452. if (ret < vdir_size || ret < vdir_size + vdir->d_namlen) {
  453. printk("coda_venus_readdir: short read: %ld\n",
  454. filp->f_path.dentry->d_inode->i_ino);
  455. ret = -EBADF;
  456. break;
  457. }
  458. /* validate whether the directory file actually makes sense */
  459. if (vdir->d_reclen < vdir_size + vdir->d_namlen) {
  460. printk("coda_venus_readdir: Invalid dir: %ld\n",
  461. filp->f_path.dentry->d_inode->i_ino);
  462. ret = -EBADF;
  463. break;
  464. }
  465. name.len = vdir->d_namlen;
  466. name.name = vdir->d_name;
  467. /* Make sure we skip '.' and '..', we already got those */
  468. if (name.name[0] == '.' && (name.len == 1 ||
  469. (vdir->d_name[1] == '.' && name.len == 2)))
  470. vdir->d_fileno = name.len = 0;
  471. /* skip null entries */
  472. if (vdir->d_fileno && name.len) {
  473. /* try to look up this entry in the dcache, that way
  474. * userspace doesn't have to worry about breaking
  475. * getcwd by having mismatched inode numbers for
  476. * internal volume mountpoints. */
  477. ino = find_inode_number(dir, &name);
  478. if (!ino) ino = vdir->d_fileno;
  479. type = CDT2DT(vdir->d_type);
  480. ret = filldir(dirent, name.name, name.len, filp->f_pos,
  481. ino, type);
  482. /* failure means no space for filling in this round */
  483. if (ret < 0) break;
  484. result++;
  485. }
  486. /* we'll always have progress because d_reclen is unsigned and
  487. * we've already established it is non-zero. */
  488. filp->f_pos += vdir->d_reclen;
  489. }
  490. }
  491. kfree(vdir);
  492. return result ? result : ret;
  493. }
  494. /* called when a cache lookup succeeds */
  495. static int coda_dentry_revalidate(struct dentry *de, struct nameidata *nd)
  496. {
  497. struct inode *inode = de->d_inode;
  498. struct coda_inode_info *cii;
  499. if (!inode)
  500. return 1;
  501. lock_kernel();
  502. if (coda_isroot(inode))
  503. goto out;
  504. if (is_bad_inode(inode))
  505. goto bad;
  506. cii = ITOC(de->d_inode);
  507. if (!(cii->c_flags & (C_PURGE | C_FLUSH)))
  508. goto out;
  509. shrink_dcache_parent(de);
  510. /* propagate for a flush */
  511. if (cii->c_flags & C_FLUSH)
  512. coda_flag_inode_children(inode, C_FLUSH);
  513. if (atomic_read(&de->d_count) > 1)
  514. /* pretend it's valid, but don't change the flags */
  515. goto out;
  516. /* clear the flags. */
  517. cii->c_flags &= ~(C_VATTR | C_PURGE | C_FLUSH);
  518. bad:
  519. unlock_kernel();
  520. return 0;
  521. out:
  522. unlock_kernel();
  523. return 1;
  524. }
  525. /*
  526. * This is the callback from dput() when d_count is going to 0.
  527. * We use this to unhash dentries with bad inodes.
  528. */
  529. static int coda_dentry_delete(struct dentry * dentry)
  530. {
  531. int flags;
  532. if (!dentry->d_inode)
  533. return 0;
  534. flags = (ITOC(dentry->d_inode)->c_flags) & C_PURGE;
  535. if (is_bad_inode(dentry->d_inode) || flags) {
  536. return 1;
  537. }
  538. return 0;
  539. }
  540. /*
  541. * This is called when we want to check if the inode has
  542. * changed on the server. Coda makes this easy since the
  543. * cache manager Venus issues a downcall to the kernel when this
  544. * happens
  545. */
  546. int coda_revalidate_inode(struct dentry *dentry)
  547. {
  548. struct coda_vattr attr;
  549. int error = 0;
  550. int old_mode;
  551. ino_t old_ino;
  552. struct inode *inode = dentry->d_inode;
  553. struct coda_inode_info *cii = ITOC(inode);
  554. lock_kernel();
  555. if ( !cii->c_flags )
  556. goto ok;
  557. if (cii->c_flags & (C_VATTR | C_PURGE | C_FLUSH)) {
  558. error = venus_getattr(inode->i_sb, &(cii->c_fid), &attr);
  559. if ( error )
  560. goto return_bad;
  561. /* this inode may be lost if:
  562. - it's ino changed
  563. - type changes must be permitted for repair and
  564. missing mount points.
  565. */
  566. old_mode = inode->i_mode;
  567. old_ino = inode->i_ino;
  568. coda_vattr_to_iattr(inode, &attr);
  569. if ((old_mode & S_IFMT) != (inode->i_mode & S_IFMT)) {
  570. printk("Coda: inode %ld, fid %s changed type!\n",
  571. inode->i_ino, coda_f2s(&(cii->c_fid)));
  572. }
  573. /* the following can happen when a local fid is replaced
  574. with a global one, here we lose and declare the inode bad */
  575. if (inode->i_ino != old_ino)
  576. goto return_bad;
  577. coda_flag_inode_children(inode, C_FLUSH);
  578. cii->c_flags &= ~(C_VATTR | C_PURGE | C_FLUSH);
  579. }
  580. ok:
  581. unlock_kernel();
  582. return 0;
  583. return_bad:
  584. unlock_kernel();
  585. return -EIO;
  586. }