libfs.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801
  1. /*
  2. * fs/libfs.c
  3. * Library for filesystems writers.
  4. */
  5. #include <linux/module.h>
  6. #include <linux/pagemap.h>
  7. #include <linux/mount.h>
  8. #include <linux/vfs.h>
  9. #include <linux/mutex.h>
  10. #include <linux/exportfs.h>
  11. #include <asm/uaccess.h>
  12. int simple_getattr(struct vfsmount *mnt, struct dentry *dentry,
  13. struct kstat *stat)
  14. {
  15. struct inode *inode = dentry->d_inode;
  16. generic_fillattr(inode, stat);
  17. stat->blocks = inode->i_mapping->nrpages << (PAGE_CACHE_SHIFT - 9);
  18. return 0;
  19. }
  20. int simple_statfs(struct dentry *dentry, struct kstatfs *buf)
  21. {
  22. buf->f_type = dentry->d_sb->s_magic;
  23. buf->f_bsize = PAGE_CACHE_SIZE;
  24. buf->f_namelen = NAME_MAX;
  25. return 0;
  26. }
  27. /*
  28. * Retaining negative dentries for an in-memory filesystem just wastes
  29. * memory and lookup time: arrange for them to be deleted immediately.
  30. */
  31. static int simple_delete_dentry(struct dentry *dentry)
  32. {
  33. return 1;
  34. }
  35. /*
  36. * Lookup the data. This is trivial - if the dentry didn't already
  37. * exist, we know it is negative. Set d_op to delete negative dentries.
  38. */
  39. struct dentry *simple_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd)
  40. {
  41. static struct dentry_operations simple_dentry_operations = {
  42. .d_delete = simple_delete_dentry,
  43. };
  44. if (dentry->d_name.len > NAME_MAX)
  45. return ERR_PTR(-ENAMETOOLONG);
  46. dentry->d_op = &simple_dentry_operations;
  47. d_add(dentry, NULL);
  48. return NULL;
  49. }
  50. int simple_sync_file(struct file * file, struct dentry *dentry, int datasync)
  51. {
  52. return 0;
  53. }
  54. int dcache_dir_open(struct inode *inode, struct file *file)
  55. {
  56. static struct qstr cursor_name = {.len = 1, .name = "."};
  57. file->private_data = d_alloc(file->f_path.dentry, &cursor_name);
  58. return file->private_data ? 0 : -ENOMEM;
  59. }
  60. int dcache_dir_close(struct inode *inode, struct file *file)
  61. {
  62. dput(file->private_data);
  63. return 0;
  64. }
  65. loff_t dcache_dir_lseek(struct file *file, loff_t offset, int origin)
  66. {
  67. mutex_lock(&file->f_path.dentry->d_inode->i_mutex);
  68. switch (origin) {
  69. case 1:
  70. offset += file->f_pos;
  71. case 0:
  72. if (offset >= 0)
  73. break;
  74. default:
  75. mutex_unlock(&file->f_path.dentry->d_inode->i_mutex);
  76. return -EINVAL;
  77. }
  78. if (offset != file->f_pos) {
  79. file->f_pos = offset;
  80. if (file->f_pos >= 2) {
  81. struct list_head *p;
  82. struct dentry *cursor = file->private_data;
  83. loff_t n = file->f_pos - 2;
  84. spin_lock(&dcache_lock);
  85. list_del(&cursor->d_u.d_child);
  86. p = file->f_path.dentry->d_subdirs.next;
  87. while (n && p != &file->f_path.dentry->d_subdirs) {
  88. struct dentry *next;
  89. next = list_entry(p, struct dentry, d_u.d_child);
  90. if (!d_unhashed(next) && next->d_inode)
  91. n--;
  92. p = p->next;
  93. }
  94. list_add_tail(&cursor->d_u.d_child, p);
  95. spin_unlock(&dcache_lock);
  96. }
  97. }
  98. mutex_unlock(&file->f_path.dentry->d_inode->i_mutex);
  99. return offset;
  100. }
  101. /* Relationship between i_mode and the DT_xxx types */
  102. static inline unsigned char dt_type(struct inode *inode)
  103. {
  104. return (inode->i_mode >> 12) & 15;
  105. }
  106. /*
  107. * Directory is locked and all positive dentries in it are safe, since
  108. * for ramfs-type trees they can't go away without unlink() or rmdir(),
  109. * both impossible due to the lock on directory.
  110. */
  111. int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
  112. {
  113. struct dentry *dentry = filp->f_path.dentry;
  114. struct dentry *cursor = filp->private_data;
  115. struct list_head *p, *q = &cursor->d_u.d_child;
  116. ino_t ino;
  117. int i = filp->f_pos;
  118. switch (i) {
  119. case 0:
  120. ino = dentry->d_inode->i_ino;
  121. if (filldir(dirent, ".", 1, i, ino, DT_DIR) < 0)
  122. break;
  123. filp->f_pos++;
  124. i++;
  125. /* fallthrough */
  126. case 1:
  127. ino = parent_ino(dentry);
  128. if (filldir(dirent, "..", 2, i, ino, DT_DIR) < 0)
  129. break;
  130. filp->f_pos++;
  131. i++;
  132. /* fallthrough */
  133. default:
  134. spin_lock(&dcache_lock);
  135. if (filp->f_pos == 2)
  136. list_move(q, &dentry->d_subdirs);
  137. for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
  138. struct dentry *next;
  139. next = list_entry(p, struct dentry, d_u.d_child);
  140. if (d_unhashed(next) || !next->d_inode)
  141. continue;
  142. spin_unlock(&dcache_lock);
  143. if (filldir(dirent, next->d_name.name,
  144. next->d_name.len, filp->f_pos,
  145. next->d_inode->i_ino,
  146. dt_type(next->d_inode)) < 0)
  147. return 0;
  148. spin_lock(&dcache_lock);
  149. /* next is still alive */
  150. list_move(q, p);
  151. p = q;
  152. filp->f_pos++;
  153. }
  154. spin_unlock(&dcache_lock);
  155. }
  156. return 0;
  157. }
  158. ssize_t generic_read_dir(struct file *filp, char __user *buf, size_t siz, loff_t *ppos)
  159. {
  160. return -EISDIR;
  161. }
  162. const struct file_operations simple_dir_operations = {
  163. .open = dcache_dir_open,
  164. .release = dcache_dir_close,
  165. .llseek = dcache_dir_lseek,
  166. .read = generic_read_dir,
  167. .readdir = dcache_readdir,
  168. .fsync = simple_sync_file,
  169. };
  170. const struct inode_operations simple_dir_inode_operations = {
  171. .lookup = simple_lookup,
  172. };
  173. static const struct super_operations simple_super_operations = {
  174. .statfs = simple_statfs,
  175. };
  176. /*
  177. * Common helper for pseudo-filesystems (sockfs, pipefs, bdev - stuff that
  178. * will never be mountable)
  179. */
  180. int get_sb_pseudo(struct file_system_type *fs_type, char *name,
  181. const struct super_operations *ops, unsigned long magic,
  182. struct vfsmount *mnt)
  183. {
  184. struct super_block *s = sget(fs_type, NULL, set_anon_super, NULL);
  185. struct dentry *dentry;
  186. struct inode *root;
  187. struct qstr d_name = {.name = name, .len = strlen(name)};
  188. if (IS_ERR(s))
  189. return PTR_ERR(s);
  190. s->s_flags = MS_NOUSER;
  191. s->s_maxbytes = ~0ULL;
  192. s->s_blocksize = 1024;
  193. s->s_blocksize_bits = 10;
  194. s->s_magic = magic;
  195. s->s_op = ops ? ops : &simple_super_operations;
  196. s->s_time_gran = 1;
  197. root = new_inode(s);
  198. if (!root)
  199. goto Enomem;
  200. /*
  201. * since this is the first inode, make it number 1. New inodes created
  202. * after this must take care not to collide with it (by passing
  203. * max_reserved of 1 to iunique).
  204. */
  205. root->i_ino = 1;
  206. root->i_mode = S_IFDIR | S_IRUSR | S_IWUSR;
  207. root->i_uid = root->i_gid = 0;
  208. root->i_atime = root->i_mtime = root->i_ctime = CURRENT_TIME;
  209. dentry = d_alloc(NULL, &d_name);
  210. if (!dentry) {
  211. iput(root);
  212. goto Enomem;
  213. }
  214. dentry->d_sb = s;
  215. dentry->d_parent = dentry;
  216. d_instantiate(dentry, root);
  217. s->s_root = dentry;
  218. s->s_flags |= MS_ACTIVE;
  219. return simple_set_mnt(mnt, s);
  220. Enomem:
  221. up_write(&s->s_umount);
  222. deactivate_super(s);
  223. return -ENOMEM;
  224. }
  225. int simple_link(struct dentry *old_dentry, struct inode *dir, struct dentry *dentry)
  226. {
  227. struct inode *inode = old_dentry->d_inode;
  228. inode->i_ctime = dir->i_ctime = dir->i_mtime = CURRENT_TIME;
  229. inc_nlink(inode);
  230. atomic_inc(&inode->i_count);
  231. dget(dentry);
  232. d_instantiate(dentry, inode);
  233. return 0;
  234. }
  235. static inline int simple_positive(struct dentry *dentry)
  236. {
  237. return dentry->d_inode && !d_unhashed(dentry);
  238. }
  239. int simple_empty(struct dentry *dentry)
  240. {
  241. struct dentry *child;
  242. int ret = 0;
  243. spin_lock(&dcache_lock);
  244. list_for_each_entry(child, &dentry->d_subdirs, d_u.d_child)
  245. if (simple_positive(child))
  246. goto out;
  247. ret = 1;
  248. out:
  249. spin_unlock(&dcache_lock);
  250. return ret;
  251. }
  252. int simple_unlink(struct inode *dir, struct dentry *dentry)
  253. {
  254. struct inode *inode = dentry->d_inode;
  255. inode->i_ctime = dir->i_ctime = dir->i_mtime = CURRENT_TIME;
  256. drop_nlink(inode);
  257. dput(dentry);
  258. return 0;
  259. }
  260. int simple_rmdir(struct inode *dir, struct dentry *dentry)
  261. {
  262. if (!simple_empty(dentry))
  263. return -ENOTEMPTY;
  264. drop_nlink(dentry->d_inode);
  265. simple_unlink(dir, dentry);
  266. drop_nlink(dir);
  267. return 0;
  268. }
  269. int simple_rename(struct inode *old_dir, struct dentry *old_dentry,
  270. struct inode *new_dir, struct dentry *new_dentry)
  271. {
  272. struct inode *inode = old_dentry->d_inode;
  273. int they_are_dirs = S_ISDIR(old_dentry->d_inode->i_mode);
  274. if (!simple_empty(new_dentry))
  275. return -ENOTEMPTY;
  276. if (new_dentry->d_inode) {
  277. simple_unlink(new_dir, new_dentry);
  278. if (they_are_dirs)
  279. drop_nlink(old_dir);
  280. } else if (they_are_dirs) {
  281. drop_nlink(old_dir);
  282. inc_nlink(new_dir);
  283. }
  284. old_dir->i_ctime = old_dir->i_mtime = new_dir->i_ctime =
  285. new_dir->i_mtime = inode->i_ctime = CURRENT_TIME;
  286. return 0;
  287. }
  288. int simple_readpage(struct file *file, struct page *page)
  289. {
  290. clear_highpage(page);
  291. flush_dcache_page(page);
  292. SetPageUptodate(page);
  293. unlock_page(page);
  294. return 0;
  295. }
  296. int simple_prepare_write(struct file *file, struct page *page,
  297. unsigned from, unsigned to)
  298. {
  299. if (!PageUptodate(page)) {
  300. if (to - from != PAGE_CACHE_SIZE) {
  301. void *kaddr = kmap_atomic(page, KM_USER0);
  302. memset(kaddr, 0, from);
  303. memset(kaddr + to, 0, PAGE_CACHE_SIZE - to);
  304. flush_dcache_page(page);
  305. kunmap_atomic(kaddr, KM_USER0);
  306. }
  307. }
  308. return 0;
  309. }
  310. int simple_write_begin(struct file *file, struct address_space *mapping,
  311. loff_t pos, unsigned len, unsigned flags,
  312. struct page **pagep, void **fsdata)
  313. {
  314. struct page *page;
  315. pgoff_t index;
  316. unsigned from;
  317. index = pos >> PAGE_CACHE_SHIFT;
  318. from = pos & (PAGE_CACHE_SIZE - 1);
  319. page = __grab_cache_page(mapping, index);
  320. if (!page)
  321. return -ENOMEM;
  322. *pagep = page;
  323. return simple_prepare_write(file, page, from, from+len);
  324. }
  325. static int simple_commit_write(struct file *file, struct page *page,
  326. unsigned from, unsigned to)
  327. {
  328. struct inode *inode = page->mapping->host;
  329. loff_t pos = ((loff_t)page->index << PAGE_CACHE_SHIFT) + to;
  330. if (!PageUptodate(page))
  331. SetPageUptodate(page);
  332. /*
  333. * No need to use i_size_read() here, the i_size
  334. * cannot change under us because we hold the i_mutex.
  335. */
  336. if (pos > inode->i_size)
  337. i_size_write(inode, pos);
  338. set_page_dirty(page);
  339. return 0;
  340. }
  341. int simple_write_end(struct file *file, struct address_space *mapping,
  342. loff_t pos, unsigned len, unsigned copied,
  343. struct page *page, void *fsdata)
  344. {
  345. unsigned from = pos & (PAGE_CACHE_SIZE - 1);
  346. /* zero the stale part of the page if we did a short copy */
  347. if (copied < len) {
  348. void *kaddr = kmap_atomic(page, KM_USER0);
  349. memset(kaddr + from + copied, 0, len - copied);
  350. flush_dcache_page(page);
  351. kunmap_atomic(kaddr, KM_USER0);
  352. }
  353. simple_commit_write(file, page, from, from+copied);
  354. unlock_page(page);
  355. page_cache_release(page);
  356. return copied;
  357. }
  358. /*
  359. * the inodes created here are not hashed. If you use iunique to generate
  360. * unique inode values later for this filesystem, then you must take care
  361. * to pass it an appropriate max_reserved value to avoid collisions.
  362. */
  363. int simple_fill_super(struct super_block *s, int magic, struct tree_descr *files)
  364. {
  365. struct inode *inode;
  366. struct dentry *root;
  367. struct dentry *dentry;
  368. int i;
  369. s->s_blocksize = PAGE_CACHE_SIZE;
  370. s->s_blocksize_bits = PAGE_CACHE_SHIFT;
  371. s->s_magic = magic;
  372. s->s_op = &simple_super_operations;
  373. s->s_time_gran = 1;
  374. inode = new_inode(s);
  375. if (!inode)
  376. return -ENOMEM;
  377. /*
  378. * because the root inode is 1, the files array must not contain an
  379. * entry at index 1
  380. */
  381. inode->i_ino = 1;
  382. inode->i_mode = S_IFDIR | 0755;
  383. inode->i_uid = inode->i_gid = 0;
  384. inode->i_blocks = 0;
  385. inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
  386. inode->i_op = &simple_dir_inode_operations;
  387. inode->i_fop = &simple_dir_operations;
  388. inode->i_nlink = 2;
  389. root = d_alloc_root(inode);
  390. if (!root) {
  391. iput(inode);
  392. return -ENOMEM;
  393. }
  394. for (i = 0; !files->name || files->name[0]; i++, files++) {
  395. if (!files->name)
  396. continue;
  397. /* warn if it tries to conflict with the root inode */
  398. if (unlikely(i == 1))
  399. printk(KERN_WARNING "%s: %s passed in a files array"
  400. "with an index of 1!\n", __func__,
  401. s->s_type->name);
  402. dentry = d_alloc_name(root, files->name);
  403. if (!dentry)
  404. goto out;
  405. inode = new_inode(s);
  406. if (!inode)
  407. goto out;
  408. inode->i_mode = S_IFREG | files->mode;
  409. inode->i_uid = inode->i_gid = 0;
  410. inode->i_blocks = 0;
  411. inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
  412. inode->i_fop = files->ops;
  413. inode->i_ino = i;
  414. d_add(dentry, inode);
  415. }
  416. s->s_root = root;
  417. return 0;
  418. out:
  419. d_genocide(root);
  420. dput(root);
  421. return -ENOMEM;
  422. }
  423. static DEFINE_SPINLOCK(pin_fs_lock);
  424. int simple_pin_fs(struct file_system_type *type, struct vfsmount **mount, int *count)
  425. {
  426. struct vfsmount *mnt = NULL;
  427. spin_lock(&pin_fs_lock);
  428. if (unlikely(!*mount)) {
  429. spin_unlock(&pin_fs_lock);
  430. mnt = vfs_kern_mount(type, 0, type->name, NULL);
  431. if (IS_ERR(mnt))
  432. return PTR_ERR(mnt);
  433. spin_lock(&pin_fs_lock);
  434. if (!*mount)
  435. *mount = mnt;
  436. }
  437. mntget(*mount);
  438. ++*count;
  439. spin_unlock(&pin_fs_lock);
  440. mntput(mnt);
  441. return 0;
  442. }
  443. void simple_release_fs(struct vfsmount **mount, int *count)
  444. {
  445. struct vfsmount *mnt;
  446. spin_lock(&pin_fs_lock);
  447. mnt = *mount;
  448. if (!--*count)
  449. *mount = NULL;
  450. spin_unlock(&pin_fs_lock);
  451. mntput(mnt);
  452. }
  453. ssize_t simple_read_from_buffer(void __user *to, size_t count, loff_t *ppos,
  454. const void *from, size_t available)
  455. {
  456. loff_t pos = *ppos;
  457. if (pos < 0)
  458. return -EINVAL;
  459. if (pos >= available)
  460. return 0;
  461. if (count > available - pos)
  462. count = available - pos;
  463. if (copy_to_user(to, from + pos, count))
  464. return -EFAULT;
  465. *ppos = pos + count;
  466. return count;
  467. }
  468. /*
  469. * Transaction based IO.
  470. * The file expects a single write which triggers the transaction, and then
  471. * possibly a read which collects the result - which is stored in a
  472. * file-local buffer.
  473. */
  474. char *simple_transaction_get(struct file *file, const char __user *buf, size_t size)
  475. {
  476. struct simple_transaction_argresp *ar;
  477. static DEFINE_SPINLOCK(simple_transaction_lock);
  478. if (size > SIMPLE_TRANSACTION_LIMIT - 1)
  479. return ERR_PTR(-EFBIG);
  480. ar = (struct simple_transaction_argresp *)get_zeroed_page(GFP_KERNEL);
  481. if (!ar)
  482. return ERR_PTR(-ENOMEM);
  483. spin_lock(&simple_transaction_lock);
  484. /* only one write allowed per open */
  485. if (file->private_data) {
  486. spin_unlock(&simple_transaction_lock);
  487. free_page((unsigned long)ar);
  488. return ERR_PTR(-EBUSY);
  489. }
  490. file->private_data = ar;
  491. spin_unlock(&simple_transaction_lock);
  492. if (copy_from_user(ar->data, buf, size))
  493. return ERR_PTR(-EFAULT);
  494. return ar->data;
  495. }
  496. ssize_t simple_transaction_read(struct file *file, char __user *buf, size_t size, loff_t *pos)
  497. {
  498. struct simple_transaction_argresp *ar = file->private_data;
  499. if (!ar)
  500. return 0;
  501. return simple_read_from_buffer(buf, size, pos, ar->data, ar->size);
  502. }
  503. int simple_transaction_release(struct inode *inode, struct file *file)
  504. {
  505. free_page((unsigned long)file->private_data);
  506. return 0;
  507. }
  508. /* Simple attribute files */
  509. struct simple_attr {
  510. u64 (*get)(void *);
  511. void (*set)(void *, u64);
  512. char get_buf[24]; /* enough to store a u64 and "\n\0" */
  513. char set_buf[24];
  514. void *data;
  515. const char *fmt; /* format for read operation */
  516. struct mutex mutex; /* protects access to these buffers */
  517. };
  518. /* simple_attr_open is called by an actual attribute open file operation
  519. * to set the attribute specific access operations. */
  520. int simple_attr_open(struct inode *inode, struct file *file,
  521. u64 (*get)(void *), void (*set)(void *, u64),
  522. const char *fmt)
  523. {
  524. struct simple_attr *attr;
  525. attr = kmalloc(sizeof(*attr), GFP_KERNEL);
  526. if (!attr)
  527. return -ENOMEM;
  528. attr->get = get;
  529. attr->set = set;
  530. attr->data = inode->i_private;
  531. attr->fmt = fmt;
  532. mutex_init(&attr->mutex);
  533. file->private_data = attr;
  534. return nonseekable_open(inode, file);
  535. }
  536. int simple_attr_close(struct inode *inode, struct file *file)
  537. {
  538. kfree(file->private_data);
  539. return 0;
  540. }
  541. /* read from the buffer that is filled with the get function */
  542. ssize_t simple_attr_read(struct file *file, char __user *buf,
  543. size_t len, loff_t *ppos)
  544. {
  545. struct simple_attr *attr;
  546. size_t size;
  547. ssize_t ret;
  548. attr = file->private_data;
  549. if (!attr->get)
  550. return -EACCES;
  551. mutex_lock(&attr->mutex);
  552. if (*ppos) /* continued read */
  553. size = strlen(attr->get_buf);
  554. else /* first read */
  555. size = scnprintf(attr->get_buf, sizeof(attr->get_buf),
  556. attr->fmt,
  557. (unsigned long long)attr->get(attr->data));
  558. ret = simple_read_from_buffer(buf, len, ppos, attr->get_buf, size);
  559. mutex_unlock(&attr->mutex);
  560. return ret;
  561. }
  562. /* interpret the buffer as a number to call the set function with */
  563. ssize_t simple_attr_write(struct file *file, const char __user *buf,
  564. size_t len, loff_t *ppos)
  565. {
  566. struct simple_attr *attr;
  567. u64 val;
  568. size_t size;
  569. ssize_t ret;
  570. attr = file->private_data;
  571. if (!attr->set)
  572. return -EACCES;
  573. mutex_lock(&attr->mutex);
  574. ret = -EFAULT;
  575. size = min(sizeof(attr->set_buf) - 1, len);
  576. if (copy_from_user(attr->set_buf, buf, size))
  577. goto out;
  578. ret = len; /* claim we got the whole input */
  579. attr->set_buf[size] = '\0';
  580. val = simple_strtol(attr->set_buf, NULL, 0);
  581. attr->set(attr->data, val);
  582. out:
  583. mutex_unlock(&attr->mutex);
  584. return ret;
  585. }
  586. /*
  587. * This is what d_alloc_anon should have been. Once the exportfs
  588. * argument transition has been finished I will update d_alloc_anon
  589. * to this prototype and this wrapper will go away. --hch
  590. */
  591. static struct dentry *exportfs_d_alloc(struct inode *inode)
  592. {
  593. struct dentry *dentry;
  594. if (!inode)
  595. return NULL;
  596. if (IS_ERR(inode))
  597. return ERR_PTR(PTR_ERR(inode));
  598. dentry = d_alloc_anon(inode);
  599. if (!dentry) {
  600. iput(inode);
  601. dentry = ERR_PTR(-ENOMEM);
  602. }
  603. return dentry;
  604. }
  605. /**
  606. * generic_fh_to_dentry - generic helper for the fh_to_dentry export operation
  607. * @sb: filesystem to do the file handle conversion on
  608. * @fid: file handle to convert
  609. * @fh_len: length of the file handle in bytes
  610. * @fh_type: type of file handle
  611. * @get_inode: filesystem callback to retrieve inode
  612. *
  613. * This function decodes @fid as long as it has one of the well-known
  614. * Linux filehandle types and calls @get_inode on it to retrieve the
  615. * inode for the object specified in the file handle.
  616. */
  617. struct dentry *generic_fh_to_dentry(struct super_block *sb, struct fid *fid,
  618. int fh_len, int fh_type, struct inode *(*get_inode)
  619. (struct super_block *sb, u64 ino, u32 gen))
  620. {
  621. struct inode *inode = NULL;
  622. if (fh_len < 2)
  623. return NULL;
  624. switch (fh_type) {
  625. case FILEID_INO32_GEN:
  626. case FILEID_INO32_GEN_PARENT:
  627. inode = get_inode(sb, fid->i32.ino, fid->i32.gen);
  628. break;
  629. }
  630. return exportfs_d_alloc(inode);
  631. }
  632. EXPORT_SYMBOL_GPL(generic_fh_to_dentry);
  633. /**
  634. * generic_fh_to_dentry - generic helper for the fh_to_parent export operation
  635. * @sb: filesystem to do the file handle conversion on
  636. * @fid: file handle to convert
  637. * @fh_len: length of the file handle in bytes
  638. * @fh_type: type of file handle
  639. * @get_inode: filesystem callback to retrieve inode
  640. *
  641. * This function decodes @fid as long as it has one of the well-known
  642. * Linux filehandle types and calls @get_inode on it to retrieve the
  643. * inode for the _parent_ object specified in the file handle if it
  644. * is specified in the file handle, or NULL otherwise.
  645. */
  646. struct dentry *generic_fh_to_parent(struct super_block *sb, struct fid *fid,
  647. int fh_len, int fh_type, struct inode *(*get_inode)
  648. (struct super_block *sb, u64 ino, u32 gen))
  649. {
  650. struct inode *inode = NULL;
  651. if (fh_len <= 2)
  652. return NULL;
  653. switch (fh_type) {
  654. case FILEID_INO32_GEN_PARENT:
  655. inode = get_inode(sb, fid->i32.parent_ino,
  656. (fh_len > 3 ? fid->i32.parent_gen : 0));
  657. break;
  658. }
  659. return exportfs_d_alloc(inode);
  660. }
  661. EXPORT_SYMBOL_GPL(generic_fh_to_parent);
  662. EXPORT_SYMBOL(dcache_dir_close);
  663. EXPORT_SYMBOL(dcache_dir_lseek);
  664. EXPORT_SYMBOL(dcache_dir_open);
  665. EXPORT_SYMBOL(dcache_readdir);
  666. EXPORT_SYMBOL(generic_read_dir);
  667. EXPORT_SYMBOL(get_sb_pseudo);
  668. EXPORT_SYMBOL(simple_write_begin);
  669. EXPORT_SYMBOL(simple_write_end);
  670. EXPORT_SYMBOL(simple_dir_inode_operations);
  671. EXPORT_SYMBOL(simple_dir_operations);
  672. EXPORT_SYMBOL(simple_empty);
  673. EXPORT_SYMBOL(d_alloc_name);
  674. EXPORT_SYMBOL(simple_fill_super);
  675. EXPORT_SYMBOL(simple_getattr);
  676. EXPORT_SYMBOL(simple_link);
  677. EXPORT_SYMBOL(simple_lookup);
  678. EXPORT_SYMBOL(simple_pin_fs);
  679. EXPORT_SYMBOL(simple_prepare_write);
  680. EXPORT_SYMBOL(simple_readpage);
  681. EXPORT_SYMBOL(simple_release_fs);
  682. EXPORT_SYMBOL(simple_rename);
  683. EXPORT_SYMBOL(simple_rmdir);
  684. EXPORT_SYMBOL(simple_statfs);
  685. EXPORT_SYMBOL(simple_sync_file);
  686. EXPORT_SYMBOL(simple_unlink);
  687. EXPORT_SYMBOL(simple_read_from_buffer);
  688. EXPORT_SYMBOL(simple_transaction_get);
  689. EXPORT_SYMBOL(simple_transaction_read);
  690. EXPORT_SYMBOL(simple_transaction_release);
  691. EXPORT_SYMBOL_GPL(simple_attr_open);
  692. EXPORT_SYMBOL_GPL(simple_attr_close);
  693. EXPORT_SYMBOL_GPL(simple_attr_read);
  694. EXPORT_SYMBOL_GPL(simple_attr_write);