PageRenderTime 102ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/fs/libfs.c

https://gitlab.com/LiquidSmooth-Devices/android_kernel_htc_msm8974
C | 852 lines | 702 code | 136 blank | 14 comment | 99 complexity | c4838c6d67a2509c8b8b45fec41f5a1a MD5 | raw file
Possible License(s): GPL-2.0
  1. #include <linux/export.h>
  2. #include <linux/pagemap.h>
  3. #include <linux/slab.h>
  4. #include <linux/mount.h>
  5. #include <linux/vfs.h>
  6. #include <linux/quotaops.h>
  7. #include <linux/mutex.h>
  8. #include <linux/exportfs.h>
  9. #include <linux/writeback.h>
  10. #include <linux/buffer_head.h>
  11. #include <asm/uaccess.h>
  12. #include "internal.h"
  13. static inline int simple_positive(struct dentry *dentry)
  14. {
  15. return dentry->d_inode && !d_unhashed(dentry);
  16. }
  17. int simple_getattr(struct vfsmount *mnt, struct dentry *dentry,
  18. struct kstat *stat)
  19. {
  20. struct inode *inode = dentry->d_inode;
  21. generic_fillattr(inode, stat);
  22. stat->blocks = inode->i_mapping->nrpages << (PAGE_CACHE_SHIFT - 9);
  23. return 0;
  24. }
  25. int simple_statfs(struct dentry *dentry, struct kstatfs *buf)
  26. {
  27. buf->f_type = dentry->d_sb->s_magic;
  28. buf->f_bsize = PAGE_CACHE_SIZE;
  29. buf->f_namelen = NAME_MAX;
  30. return 0;
  31. }
  32. static int simple_delete_dentry(const struct dentry *dentry)
  33. {
  34. return 1;
  35. }
  36. struct dentry *simple_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd)
  37. {
  38. static const struct dentry_operations simple_dentry_operations = {
  39. .d_delete = simple_delete_dentry,
  40. };
  41. if (dentry->d_name.len > NAME_MAX)
  42. return ERR_PTR(-ENAMETOOLONG);
  43. d_set_d_op(dentry, &simple_dentry_operations);
  44. d_add(dentry, NULL);
  45. return NULL;
  46. }
  47. int dcache_dir_open(struct inode *inode, struct file *file)
  48. {
  49. static struct qstr cursor_name = {.len = 1, .name = "."};
  50. file->private_data = d_alloc(file->f_path.dentry, &cursor_name);
  51. return file->private_data ? 0 : -ENOMEM;
  52. }
  53. int dcache_dir_close(struct inode *inode, struct file *file)
  54. {
  55. dput(file->private_data);
  56. return 0;
  57. }
  58. loff_t dcache_dir_lseek(struct file *file, loff_t offset, int origin)
  59. {
  60. struct dentry *dentry = file->f_path.dentry;
  61. mutex_lock(&dentry->d_inode->i_mutex);
  62. switch (origin) {
  63. case 1:
  64. offset += file->f_pos;
  65. case 0:
  66. if (offset >= 0)
  67. break;
  68. default:
  69. mutex_unlock(&dentry->d_inode->i_mutex);
  70. return -EINVAL;
  71. }
  72. if (offset != file->f_pos) {
  73. file->f_pos = offset;
  74. if (file->f_pos >= 2) {
  75. struct list_head *p;
  76. struct dentry *cursor = file->private_data;
  77. loff_t n = file->f_pos - 2;
  78. spin_lock(&dentry->d_lock);
  79. list_del(&cursor->d_u.d_child);
  80. p = dentry->d_subdirs.next;
  81. while (n && p != &dentry->d_subdirs) {
  82. struct dentry *next;
  83. next = list_entry(p, struct dentry, d_u.d_child);
  84. spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
  85. if (simple_positive(next))
  86. n--;
  87. spin_unlock(&next->d_lock);
  88. p = p->next;
  89. }
  90. list_add_tail(&cursor->d_u.d_child, p);
  91. spin_unlock(&dentry->d_lock);
  92. }
  93. }
  94. mutex_unlock(&dentry->d_inode->i_mutex);
  95. return offset;
  96. }
  97. static inline unsigned char dt_type(struct inode *inode)
  98. {
  99. return (inode->i_mode >> 12) & 15;
  100. }
  101. int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
  102. {
  103. struct dentry *dentry = filp->f_path.dentry;
  104. struct dentry *cursor = filp->private_data;
  105. struct list_head *p, *q = &cursor->d_u.d_child;
  106. ino_t ino;
  107. int i = filp->f_pos;
  108. switch (i) {
  109. case 0:
  110. ino = dentry->d_inode->i_ino;
  111. if (filldir(dirent, ".", 1, i, ino, DT_DIR) < 0)
  112. break;
  113. filp->f_pos++;
  114. i++;
  115. case 1:
  116. ino = parent_ino(dentry);
  117. if (filldir(dirent, "..", 2, i, ino, DT_DIR) < 0)
  118. break;
  119. filp->f_pos++;
  120. i++;
  121. default:
  122. spin_lock(&dentry->d_lock);
  123. if (filp->f_pos == 2)
  124. list_move(q, &dentry->d_subdirs);
  125. for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
  126. struct dentry *next;
  127. next = list_entry(p, struct dentry, d_u.d_child);
  128. spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
  129. if (!simple_positive(next)) {
  130. spin_unlock(&next->d_lock);
  131. continue;
  132. }
  133. spin_unlock(&next->d_lock);
  134. spin_unlock(&dentry->d_lock);
  135. if (filldir(dirent, next->d_name.name,
  136. next->d_name.len, filp->f_pos,
  137. next->d_inode->i_ino,
  138. dt_type(next->d_inode)) < 0)
  139. return 0;
  140. spin_lock(&dentry->d_lock);
  141. spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
  142. list_move(q, p);
  143. spin_unlock(&next->d_lock);
  144. p = q;
  145. filp->f_pos++;
  146. }
  147. spin_unlock(&dentry->d_lock);
  148. }
  149. return 0;
  150. }
  151. ssize_t generic_read_dir(struct file *filp, char __user *buf, size_t siz, loff_t *ppos)
  152. {
  153. return -EISDIR;
  154. }
  155. const struct file_operations simple_dir_operations = {
  156. .open = dcache_dir_open,
  157. .release = dcache_dir_close,
  158. .llseek = dcache_dir_lseek,
  159. .read = generic_read_dir,
  160. .readdir = dcache_readdir,
  161. .fsync = noop_fsync,
  162. };
  163. const struct inode_operations simple_dir_inode_operations = {
  164. .lookup = simple_lookup,
  165. };
  166. static const struct super_operations simple_super_operations = {
  167. .statfs = simple_statfs,
  168. };
  169. struct dentry *mount_pseudo(struct file_system_type *fs_type, char *name,
  170. const struct super_operations *ops,
  171. const struct dentry_operations *dops, unsigned long magic)
  172. {
  173. struct super_block *s = sget(fs_type, NULL, set_anon_super, NULL);
  174. struct dentry *dentry;
  175. struct inode *root;
  176. struct qstr d_name = {.name = name, .len = strlen(name)};
  177. if (IS_ERR(s))
  178. return ERR_CAST(s);
  179. s->s_flags = MS_NOUSER;
  180. s->s_maxbytes = MAX_LFS_FILESIZE;
  181. s->s_blocksize = PAGE_SIZE;
  182. s->s_blocksize_bits = PAGE_SHIFT;
  183. s->s_magic = magic;
  184. s->s_op = ops ? ops : &simple_super_operations;
  185. s->s_time_gran = 1;
  186. root = new_inode(s);
  187. if (!root)
  188. goto Enomem;
  189. root->i_ino = 1;
  190. root->i_mode = S_IFDIR | S_IRUSR | S_IWUSR;
  191. root->i_atime = root->i_mtime = root->i_ctime = CURRENT_TIME;
  192. dentry = __d_alloc(s, &d_name);
  193. if (!dentry) {
  194. iput(root);
  195. goto Enomem;
  196. }
  197. d_instantiate(dentry, root);
  198. s->s_root = dentry;
  199. s->s_d_op = dops;
  200. s->s_flags |= MS_ACTIVE;
  201. return dget(s->s_root);
  202. Enomem:
  203. deactivate_locked_super(s);
  204. return ERR_PTR(-ENOMEM);
  205. }
  206. int simple_open(struct inode *inode, struct file *file)
  207. {
  208. if (inode->i_private)
  209. file->private_data = inode->i_private;
  210. return 0;
  211. }
  212. int simple_link(struct dentry *old_dentry, struct inode *dir, struct dentry *dentry)
  213. {
  214. struct inode *inode = old_dentry->d_inode;
  215. inode->i_ctime = dir->i_ctime = dir->i_mtime = CURRENT_TIME;
  216. inc_nlink(inode);
  217. ihold(inode);
  218. dget(dentry);
  219. d_instantiate(dentry, inode);
  220. return 0;
  221. }
  222. int simple_empty(struct dentry *dentry)
  223. {
  224. struct dentry *child;
  225. int ret = 0;
  226. spin_lock(&dentry->d_lock);
  227. list_for_each_entry(child, &dentry->d_subdirs, d_u.d_child) {
  228. spin_lock_nested(&child->d_lock, DENTRY_D_LOCK_NESTED);
  229. if (simple_positive(child)) {
  230. spin_unlock(&child->d_lock);
  231. goto out;
  232. }
  233. spin_unlock(&child->d_lock);
  234. }
  235. ret = 1;
  236. out:
  237. spin_unlock(&dentry->d_lock);
  238. return ret;
  239. }
  240. int simple_unlink(struct inode *dir, struct dentry *dentry)
  241. {
  242. struct inode *inode = dentry->d_inode;
  243. inode->i_ctime = dir->i_ctime = dir->i_mtime = CURRENT_TIME;
  244. drop_nlink(inode);
  245. dput(dentry);
  246. return 0;
  247. }
  248. int simple_rmdir(struct inode *dir, struct dentry *dentry)
  249. {
  250. if (!simple_empty(dentry))
  251. return -ENOTEMPTY;
  252. drop_nlink(dentry->d_inode);
  253. simple_unlink(dir, dentry);
  254. drop_nlink(dir);
  255. return 0;
  256. }
  257. int simple_rename(struct inode *old_dir, struct dentry *old_dentry,
  258. struct inode *new_dir, struct dentry *new_dentry)
  259. {
  260. struct inode *inode = old_dentry->d_inode;
  261. int they_are_dirs = S_ISDIR(old_dentry->d_inode->i_mode);
  262. if (!simple_empty(new_dentry))
  263. return -ENOTEMPTY;
  264. if (new_dentry->d_inode) {
  265. simple_unlink(new_dir, new_dentry);
  266. if (they_are_dirs) {
  267. drop_nlink(new_dentry->d_inode);
  268. drop_nlink(old_dir);
  269. }
  270. } else if (they_are_dirs) {
  271. drop_nlink(old_dir);
  272. inc_nlink(new_dir);
  273. }
  274. old_dir->i_ctime = old_dir->i_mtime = new_dir->i_ctime =
  275. new_dir->i_mtime = inode->i_ctime = CURRENT_TIME;
  276. return 0;
  277. }
  278. int simple_setattr(struct dentry *dentry, struct iattr *iattr)
  279. {
  280. struct inode *inode = dentry->d_inode;
  281. int error;
  282. WARN_ON_ONCE(inode->i_op->truncate);
  283. error = inode_change_ok(inode, iattr);
  284. if (error)
  285. return error;
  286. if (iattr->ia_valid & ATTR_SIZE)
  287. truncate_setsize(inode, iattr->ia_size);
  288. setattr_copy(inode, iattr);
  289. mark_inode_dirty(inode);
  290. return 0;
  291. }
  292. EXPORT_SYMBOL(simple_setattr);
  293. int simple_readpage(struct file *file, struct page *page)
  294. {
  295. clear_highpage(page);
  296. flush_dcache_page(page);
  297. SetPageUptodate(page);
  298. unlock_page(page);
  299. return 0;
  300. }
  301. int simple_write_begin(struct file *file, struct address_space *mapping,
  302. loff_t pos, unsigned len, unsigned flags,
  303. struct page **pagep, void **fsdata)
  304. {
  305. struct page *page;
  306. pgoff_t index;
  307. index = pos >> PAGE_CACHE_SHIFT;
  308. page = grab_cache_page_write_begin(mapping, index, flags);
  309. if (!page)
  310. return -ENOMEM;
  311. *pagep = page;
  312. if (!PageUptodate(page) && (len != PAGE_CACHE_SIZE)) {
  313. unsigned from = pos & (PAGE_CACHE_SIZE - 1);
  314. zero_user_segments(page, 0, from, from + len, PAGE_CACHE_SIZE);
  315. }
  316. return 0;
  317. }
  318. int simple_write_end(struct file *file, struct address_space *mapping,
  319. loff_t pos, unsigned len, unsigned copied,
  320. struct page *page, void *fsdata)
  321. {
  322. struct inode *inode = page->mapping->host;
  323. loff_t last_pos = pos + copied;
  324. if (copied < len) {
  325. unsigned from = pos & (PAGE_CACHE_SIZE - 1);
  326. zero_user(page, from + copied, len - copied);
  327. }
  328. if (!PageUptodate(page))
  329. SetPageUptodate(page);
  330. if (last_pos > inode->i_size)
  331. i_size_write(inode, last_pos);
  332. set_page_dirty(page);
  333. unlock_page(page);
  334. page_cache_release(page);
  335. return copied;
  336. }
  337. int simple_fill_super(struct super_block *s, unsigned long magic,
  338. struct tree_descr *files)
  339. {
  340. struct inode *inode;
  341. struct dentry *root;
  342. struct dentry *dentry;
  343. int i;
  344. s->s_blocksize = PAGE_CACHE_SIZE;
  345. s->s_blocksize_bits = PAGE_CACHE_SHIFT;
  346. s->s_magic = magic;
  347. s->s_op = &simple_super_operations;
  348. s->s_time_gran = 1;
  349. inode = new_inode(s);
  350. if (!inode)
  351. return -ENOMEM;
  352. inode->i_ino = 1;
  353. inode->i_mode = S_IFDIR | 0755;
  354. inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
  355. inode->i_op = &simple_dir_inode_operations;
  356. inode->i_fop = &simple_dir_operations;
  357. set_nlink(inode, 2);
  358. root = d_make_root(inode);
  359. if (!root)
  360. return -ENOMEM;
  361. for (i = 0; !files->name || files->name[0]; i++, files++) {
  362. if (!files->name)
  363. continue;
  364. if (unlikely(i == 1))
  365. printk(KERN_WARNING "%s: %s passed in a files array"
  366. "with an index of 1!\n", __func__,
  367. s->s_type->name);
  368. dentry = d_alloc_name(root, files->name);
  369. if (!dentry)
  370. goto out;
  371. inode = new_inode(s);
  372. if (!inode) {
  373. dput(dentry);
  374. goto out;
  375. }
  376. inode->i_mode = S_IFREG | files->mode;
  377. inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
  378. inode->i_fop = files->ops;
  379. inode->i_ino = i;
  380. d_add(dentry, inode);
  381. }
  382. s->s_root = root;
  383. return 0;
  384. out:
  385. d_genocide(root);
  386. shrink_dcache_parent(root);
  387. dput(root);
  388. return -ENOMEM;
  389. }
  390. static DEFINE_SPINLOCK(pin_fs_lock);
  391. int simple_pin_fs(struct file_system_type *type, struct vfsmount **mount, int *count)
  392. {
  393. struct vfsmount *mnt = NULL;
  394. spin_lock(&pin_fs_lock);
  395. if (unlikely(!*mount)) {
  396. spin_unlock(&pin_fs_lock);
  397. mnt = vfs_kern_mount(type, MS_KERNMOUNT, type->name, NULL);
  398. if (IS_ERR(mnt))
  399. return PTR_ERR(mnt);
  400. spin_lock(&pin_fs_lock);
  401. if (!*mount)
  402. *mount = mnt;
  403. }
  404. mntget(*mount);
  405. ++*count;
  406. spin_unlock(&pin_fs_lock);
  407. mntput(mnt);
  408. return 0;
  409. }
  410. void simple_release_fs(struct vfsmount **mount, int *count)
  411. {
  412. struct vfsmount *mnt;
  413. spin_lock(&pin_fs_lock);
  414. mnt = *mount;
  415. if (!--*count)
  416. *mount = NULL;
  417. spin_unlock(&pin_fs_lock);
  418. mntput(mnt);
  419. }
  420. ssize_t simple_read_from_buffer(void __user *to, size_t count, loff_t *ppos,
  421. const void *from, size_t available)
  422. {
  423. loff_t pos = *ppos;
  424. size_t ret;
  425. if (pos < 0)
  426. return -EINVAL;
  427. if (pos >= available || !count)
  428. return 0;
  429. if (count > available - pos)
  430. count = available - pos;
  431. ret = copy_to_user(to, from + pos, count);
  432. if (ret == count)
  433. return -EFAULT;
  434. count -= ret;
  435. *ppos = pos + count;
  436. return count;
  437. }
  438. /**
  439. * simple_write_to_buffer - copy data from user space to the buffer
  440. * @to: the buffer to write to
  441. * @available: the size of the buffer
  442. * @ppos: the current position in the buffer
  443. * @from: the user space buffer to read from
  444. * @count: the maximum number of bytes to read
  445. *
  446. * The simple_write_to_buffer() function reads up to @count bytes from the user
  447. * space address starting at @from into the buffer @to at offset @ppos.
  448. *
  449. * On success, the number of bytes written is returned and the offset @ppos is
  450. * advanced by this number, or negative value is returned on error.
  451. **/
  452. ssize_t simple_write_to_buffer(void *to, size_t available, loff_t *ppos,
  453. const void __user *from, size_t count)
  454. {
  455. loff_t pos = *ppos;
  456. size_t res;
  457. if (pos < 0)
  458. return -EINVAL;
  459. if (pos >= available || !count)
  460. return 0;
  461. if (count > available - pos)
  462. count = available - pos;
  463. res = copy_from_user(to + pos, from, count);
  464. if (res == count)
  465. return -EFAULT;
  466. count -= res;
  467. *ppos = pos + count;
  468. return count;
  469. }
  470. ssize_t memory_read_from_buffer(void *to, size_t count, loff_t *ppos,
  471. const void *from, size_t available)
  472. {
  473. loff_t pos = *ppos;
  474. if (pos < 0)
  475. return -EINVAL;
  476. if (pos >= available)
  477. return 0;
  478. if (count > available - pos)
  479. count = available - pos;
  480. memcpy(to, from + pos, count);
  481. *ppos = pos + count;
  482. return count;
  483. }
  484. void simple_transaction_set(struct file *file, size_t n)
  485. {
  486. struct simple_transaction_argresp *ar = file->private_data;
  487. BUG_ON(n > SIMPLE_TRANSACTION_LIMIT);
  488. smp_mb();
  489. ar->size = n;
  490. }
  491. char *simple_transaction_get(struct file *file, const char __user *buf, size_t size)
  492. {
  493. struct simple_transaction_argresp *ar;
  494. static DEFINE_SPINLOCK(simple_transaction_lock);
  495. if (size > SIMPLE_TRANSACTION_LIMIT - 1)
  496. return ERR_PTR(-EFBIG);
  497. ar = (struct simple_transaction_argresp *)get_zeroed_page(GFP_KERNEL);
  498. if (!ar)
  499. return ERR_PTR(-ENOMEM);
  500. spin_lock(&simple_transaction_lock);
  501. if (file->private_data) {
  502. spin_unlock(&simple_transaction_lock);
  503. free_page((unsigned long)ar);
  504. return ERR_PTR(-EBUSY);
  505. }
  506. file->private_data = ar;
  507. spin_unlock(&simple_transaction_lock);
  508. if (copy_from_user(ar->data, buf, size))
  509. return ERR_PTR(-EFAULT);
  510. return ar->data;
  511. }
  512. ssize_t simple_transaction_read(struct file *file, char __user *buf, size_t size, loff_t *pos)
  513. {
  514. struct simple_transaction_argresp *ar = file->private_data;
  515. if (!ar)
  516. return 0;
  517. return simple_read_from_buffer(buf, size, pos, ar->data, ar->size);
  518. }
  519. int simple_transaction_release(struct inode *inode, struct file *file)
  520. {
  521. free_page((unsigned long)file->private_data);
  522. return 0;
  523. }
  524. struct simple_attr {
  525. int (*get)(void *, u64 *);
  526. int (*set)(void *, u64);
  527. char get_buf[24];
  528. char set_buf[24];
  529. void *data;
  530. const char *fmt;
  531. struct mutex mutex;
  532. };
  533. int simple_attr_open(struct inode *inode, struct file *file,
  534. int (*get)(void *, u64 *), int (*set)(void *, u64),
  535. const char *fmt)
  536. {
  537. struct simple_attr *attr;
  538. attr = kmalloc(sizeof(*attr), GFP_KERNEL);
  539. if (!attr)
  540. return -ENOMEM;
  541. attr->get = get;
  542. attr->set = set;
  543. attr->data = inode->i_private;
  544. attr->fmt = fmt;
  545. mutex_init(&attr->mutex);
  546. file->private_data = attr;
  547. return nonseekable_open(inode, file);
  548. }
  549. int simple_attr_release(struct inode *inode, struct file *file)
  550. {
  551. kfree(file->private_data);
  552. return 0;
  553. }
  554. ssize_t simple_attr_read(struct file *file, char __user *buf,
  555. size_t len, loff_t *ppos)
  556. {
  557. struct simple_attr *attr;
  558. size_t size;
  559. ssize_t ret;
  560. attr = file->private_data;
  561. if (!attr->get)
  562. return -EACCES;
  563. ret = mutex_lock_interruptible(&attr->mutex);
  564. if (ret)
  565. return ret;
  566. if (*ppos) {
  567. size = strlen(attr->get_buf);
  568. } else {
  569. u64 val;
  570. ret = attr->get(attr->data, &val);
  571. if (ret)
  572. goto out;
  573. size = scnprintf(attr->get_buf, sizeof(attr->get_buf),
  574. attr->fmt, (unsigned long long)val);
  575. }
  576. ret = simple_read_from_buffer(buf, len, ppos, attr->get_buf, size);
  577. out:
  578. mutex_unlock(&attr->mutex);
  579. return ret;
  580. }
  581. ssize_t simple_attr_write(struct file *file, const char __user *buf,
  582. size_t len, loff_t *ppos)
  583. {
  584. struct simple_attr *attr;
  585. u64 val;
  586. size_t size;
  587. ssize_t ret;
  588. attr = file->private_data;
  589. if (!attr->set)
  590. return -EACCES;
  591. ret = mutex_lock_interruptible(&attr->mutex);
  592. if (ret)
  593. return ret;
  594. ret = -EFAULT;
  595. size = min(sizeof(attr->set_buf) - 1, len);
  596. if (copy_from_user(attr->set_buf, buf, size))
  597. goto out;
  598. attr->set_buf[size] = '\0';
  599. val = simple_strtoll(attr->set_buf, NULL, 0);
  600. ret = attr->set(attr->data, val);
  601. if (ret == 0)
  602. ret = len;
  603. out:
  604. mutex_unlock(&attr->mutex);
  605. return ret;
  606. }
  607. struct dentry *generic_fh_to_dentry(struct super_block *sb, struct fid *fid,
  608. int fh_len, int fh_type, struct inode *(*get_inode)
  609. (struct super_block *sb, u64 ino, u32 gen))
  610. {
  611. struct inode *inode = NULL;
  612. if (fh_len < 2)
  613. return NULL;
  614. switch (fh_type) {
  615. case FILEID_INO32_GEN:
  616. case FILEID_INO32_GEN_PARENT:
  617. inode = get_inode(sb, fid->i32.ino, fid->i32.gen);
  618. break;
  619. }
  620. return d_obtain_alias(inode);
  621. }
  622. EXPORT_SYMBOL_GPL(generic_fh_to_dentry);
  623. struct dentry *generic_fh_to_parent(struct super_block *sb, struct fid *fid,
  624. int fh_len, int fh_type, struct inode *(*get_inode)
  625. (struct super_block *sb, u64 ino, u32 gen))
  626. {
  627. struct inode *inode = NULL;
  628. if (fh_len <= 2)
  629. return NULL;
  630. switch (fh_type) {
  631. case FILEID_INO32_GEN_PARENT:
  632. inode = get_inode(sb, fid->i32.parent_ino,
  633. (fh_len > 3 ? fid->i32.parent_gen : 0));
  634. break;
  635. }
  636. return d_obtain_alias(inode);
  637. }
  638. EXPORT_SYMBOL_GPL(generic_fh_to_parent);
  639. int generic_file_fsync(struct file *file, loff_t start, loff_t end,
  640. int datasync)
  641. {
  642. struct inode *inode = file->f_mapping->host;
  643. int err;
  644. int ret;
  645. err = filemap_write_and_wait_range(inode->i_mapping, start, end);
  646. if (err)
  647. return err;
  648. mutex_lock(&inode->i_mutex);
  649. ret = sync_mapping_buffers(inode->i_mapping);
  650. if (!(inode->i_state & I_DIRTY))
  651. goto out;
  652. if (datasync && !(inode->i_state & I_DIRTY_DATASYNC))
  653. goto out;
  654. err = sync_inode_metadata(inode, 1);
  655. if (ret == 0)
  656. ret = err;
  657. out:
  658. mutex_unlock(&inode->i_mutex);
  659. return ret;
  660. }
  661. EXPORT_SYMBOL(generic_file_fsync);
  662. int generic_check_addressable(unsigned blocksize_bits, u64 num_blocks)
  663. {
  664. u64 last_fs_block = num_blocks - 1;
  665. u64 last_fs_page =
  666. last_fs_block >> (PAGE_CACHE_SHIFT - blocksize_bits);
  667. if (unlikely(num_blocks == 0))
  668. return 0;
  669. if ((blocksize_bits < 9) || (blocksize_bits > PAGE_CACHE_SHIFT))
  670. return -EINVAL;
  671. if ((last_fs_block > (sector_t)(~0ULL) >> (blocksize_bits - 9)) ||
  672. (last_fs_page > (pgoff_t)(~0ULL))) {
  673. return -EFBIG;
  674. }
  675. return 0;
  676. }
  677. EXPORT_SYMBOL(generic_check_addressable);
  678. int noop_fsync(struct file *file, loff_t start, loff_t end, int datasync)
  679. {
  680. return 0;
  681. }
  682. EXPORT_SYMBOL(dcache_dir_close);
  683. EXPORT_SYMBOL(dcache_dir_lseek);
  684. EXPORT_SYMBOL(dcache_dir_open);
  685. EXPORT_SYMBOL(dcache_readdir);
  686. EXPORT_SYMBOL(generic_read_dir);
  687. EXPORT_SYMBOL(mount_pseudo);
  688. EXPORT_SYMBOL(simple_write_begin);
  689. EXPORT_SYMBOL(simple_write_end);
  690. EXPORT_SYMBOL(simple_dir_inode_operations);
  691. EXPORT_SYMBOL(simple_dir_operations);
  692. EXPORT_SYMBOL(simple_empty);
  693. EXPORT_SYMBOL(simple_fill_super);
  694. EXPORT_SYMBOL(simple_getattr);
  695. EXPORT_SYMBOL(simple_open);
  696. EXPORT_SYMBOL(simple_link);
  697. EXPORT_SYMBOL(simple_lookup);
  698. EXPORT_SYMBOL(simple_pin_fs);
  699. EXPORT_SYMBOL(simple_readpage);
  700. EXPORT_SYMBOL(simple_release_fs);
  701. EXPORT_SYMBOL(simple_rename);
  702. EXPORT_SYMBOL(simple_rmdir);
  703. EXPORT_SYMBOL(simple_statfs);
  704. EXPORT_SYMBOL(noop_fsync);
  705. EXPORT_SYMBOL(simple_unlink);
  706. EXPORT_SYMBOL(simple_read_from_buffer);
  707. EXPORT_SYMBOL(simple_write_to_buffer);
  708. EXPORT_SYMBOL(memory_read_from_buffer);
  709. EXPORT_SYMBOL(simple_transaction_set);
  710. EXPORT_SYMBOL(simple_transaction_get);
  711. EXPORT_SYMBOL(simple_transaction_read);
  712. EXPORT_SYMBOL(simple_transaction_release);
  713. EXPORT_SYMBOL_GPL(simple_attr_open);
  714. EXPORT_SYMBOL_GPL(simple_attr_release);
  715. EXPORT_SYMBOL_GPL(simple_attr_read);
  716. EXPORT_SYMBOL_GPL(simple_attr_write);