hppfs.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785
  1. /*
  2. * Copyright (C) 2002 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
  3. * Licensed under the GPL
  4. */
  5. #include <linux/ctype.h>
  6. #include <linux/dcache.h>
  7. #include <linux/file.h>
  8. #include <linux/fs.h>
  9. #include <linux/init.h>
  10. #include <linux/kernel.h>
  11. #include <linux/list.h>
  12. #include <linux/module.h>
  13. #include <linux/mount.h>
  14. #include <linux/slab.h>
  15. #include <linux/statfs.h>
  16. #include <linux/types.h>
  17. #include <linux/pid_namespace.h>
  18. #include <asm/uaccess.h>
  19. #include "os.h"
  20. static struct inode *get_inode(struct super_block *, struct dentry *);
  21. struct hppfs_data {
  22. struct list_head list;
  23. char contents[PAGE_SIZE - sizeof(struct list_head)];
  24. };
  25. struct hppfs_private {
  26. struct file *proc_file;
  27. int host_fd;
  28. loff_t len;
  29. struct hppfs_data *contents;
  30. };
  31. struct hppfs_inode_info {
  32. struct dentry *proc_dentry;
  33. struct inode vfs_inode;
  34. };
  35. static inline struct hppfs_inode_info *HPPFS_I(struct inode *inode)
  36. {
  37. return container_of(inode, struct hppfs_inode_info, vfs_inode);
  38. }
  39. #define HPPFS_SUPER_MAGIC 0xb00000ee
  40. static const struct super_operations hppfs_sbops;
  41. static int is_pid(struct dentry *dentry)
  42. {
  43. struct super_block *sb;
  44. int i;
  45. sb = dentry->d_sb;
  46. if (dentry->d_parent != sb->s_root)
  47. return 0;
  48. for (i = 0; i < dentry->d_name.len; i++) {
  49. if (!isdigit(dentry->d_name.name[i]))
  50. return 0;
  51. }
  52. return 1;
  53. }
  54. static char *dentry_name(struct dentry *dentry, int extra)
  55. {
  56. struct dentry *parent;
  57. char *root, *name;
  58. const char *seg_name;
  59. int len, seg_len;
  60. len = 0;
  61. parent = dentry;
  62. while (parent->d_parent != parent) {
  63. if (is_pid(parent))
  64. len += strlen("pid") + 1;
  65. else len += parent->d_name.len + 1;
  66. parent = parent->d_parent;
  67. }
  68. root = "proc";
  69. len += strlen(root);
  70. name = kmalloc(len + extra + 1, GFP_KERNEL);
  71. if (name == NULL)
  72. return NULL;
  73. name[len] = '\0';
  74. parent = dentry;
  75. while (parent->d_parent != parent) {
  76. if (is_pid(parent)) {
  77. seg_name = "pid";
  78. seg_len = strlen("pid");
  79. }
  80. else {
  81. seg_name = parent->d_name.name;
  82. seg_len = parent->d_name.len;
  83. }
  84. len -= seg_len + 1;
  85. name[len] = '/';
  86. strncpy(&name[len + 1], seg_name, seg_len);
  87. parent = parent->d_parent;
  88. }
  89. strncpy(name, root, strlen(root));
  90. return name;
  91. }
  92. static int file_removed(struct dentry *dentry, const char *file)
  93. {
  94. char *host_file;
  95. int extra, fd;
  96. extra = 0;
  97. if (file != NULL)
  98. extra += strlen(file) + 1;
  99. host_file = dentry_name(dentry, extra + strlen("/remove"));
  100. if (host_file == NULL) {
  101. printk(KERN_ERR "file_removed : allocation failed\n");
  102. return -ENOMEM;
  103. }
  104. if (file != NULL) {
  105. strcat(host_file, "/");
  106. strcat(host_file, file);
  107. }
  108. strcat(host_file, "/remove");
  109. fd = os_open_file(host_file, of_read(OPENFLAGS()), 0);
  110. kfree(host_file);
  111. if (fd > 0) {
  112. os_close_file(fd);
  113. return 1;
  114. }
  115. return 0;
  116. }
  117. static struct dentry *hppfs_lookup(struct inode *ino, struct dentry *dentry,
  118. struct nameidata *nd)
  119. {
  120. struct dentry *proc_dentry, *new, *parent;
  121. struct inode *inode;
  122. int err, deleted;
  123. deleted = file_removed(dentry, NULL);
  124. if (deleted < 0)
  125. return ERR_PTR(deleted);
  126. else if (deleted)
  127. return ERR_PTR(-ENOENT);
  128. err = -ENOMEM;
  129. parent = HPPFS_I(ino)->proc_dentry;
  130. mutex_lock(&parent->d_inode->i_mutex);
  131. proc_dentry = d_lookup(parent, &dentry->d_name);
  132. if (proc_dentry == NULL) {
  133. proc_dentry = d_alloc(parent, &dentry->d_name);
  134. if (proc_dentry == NULL) {
  135. mutex_unlock(&parent->d_inode->i_mutex);
  136. goto out;
  137. }
  138. new = (*parent->d_inode->i_op->lookup)(parent->d_inode,
  139. proc_dentry, NULL);
  140. if (new) {
  141. dput(proc_dentry);
  142. proc_dentry = new;
  143. }
  144. }
  145. mutex_unlock(&parent->d_inode->i_mutex);
  146. if (IS_ERR(proc_dentry))
  147. return proc_dentry;
  148. err = -ENOMEM;
  149. inode = get_inode(ino->i_sb, proc_dentry);
  150. if (!inode)
  151. goto out;
  152. d_add(dentry, inode);
  153. return NULL;
  154. out:
  155. return ERR_PTR(err);
  156. }
  157. static const struct inode_operations hppfs_file_iops = {
  158. };
  159. static ssize_t read_proc(struct file *file, char __user *buf, ssize_t count,
  160. loff_t *ppos, int is_user)
  161. {
  162. ssize_t (*read)(struct file *, char __user *, size_t, loff_t *);
  163. ssize_t n;
  164. read = file->f_path.dentry->d_inode->i_fop->read;
  165. if (!is_user)
  166. set_fs(KERNEL_DS);
  167. n = (*read)(file, buf, count, &file->f_pos);
  168. if (!is_user)
  169. set_fs(USER_DS);
  170. if (ppos)
  171. *ppos = file->f_pos;
  172. return n;
  173. }
  174. static ssize_t hppfs_read_file(int fd, char __user *buf, ssize_t count)
  175. {
  176. ssize_t n;
  177. int cur, err;
  178. char *new_buf;
  179. n = -ENOMEM;
  180. new_buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
  181. if (new_buf == NULL) {
  182. printk(KERN_ERR "hppfs_read_file : kmalloc failed\n");
  183. goto out;
  184. }
  185. n = 0;
  186. while (count > 0) {
  187. cur = min_t(ssize_t, count, PAGE_SIZE);
  188. err = os_read_file(fd, new_buf, cur);
  189. if (err < 0) {
  190. printk(KERN_ERR "hppfs_read : read failed, "
  191. "errno = %d\n", err);
  192. n = err;
  193. goto out_free;
  194. } else if (err == 0)
  195. break;
  196. if (copy_to_user(buf, new_buf, err)) {
  197. n = -EFAULT;
  198. goto out_free;
  199. }
  200. n += err;
  201. count -= err;
  202. }
  203. out_free:
  204. kfree(new_buf);
  205. out:
  206. return n;
  207. }
  208. static ssize_t hppfs_read(struct file *file, char __user *buf, size_t count,
  209. loff_t *ppos)
  210. {
  211. struct hppfs_private *hppfs = file->private_data;
  212. struct hppfs_data *data;
  213. loff_t off;
  214. int err;
  215. if (hppfs->contents != NULL) {
  216. int rem;
  217. if (*ppos >= hppfs->len)
  218. return 0;
  219. data = hppfs->contents;
  220. off = *ppos;
  221. while (off >= sizeof(data->contents)) {
  222. data = list_entry(data->list.next, struct hppfs_data,
  223. list);
  224. off -= sizeof(data->contents);
  225. }
  226. if (off + count > hppfs->len)
  227. count = hppfs->len - off;
  228. rem = copy_to_user(buf, &data->contents[off], count);
  229. *ppos += count - rem;
  230. if (rem > 0)
  231. return -EFAULT;
  232. } else if (hppfs->host_fd != -1) {
  233. err = os_seek_file(hppfs->host_fd, *ppos);
  234. if (err) {
  235. printk(KERN_ERR "hppfs_read : seek failed, "
  236. "errno = %d\n", err);
  237. return err;
  238. }
  239. err = hppfs_read_file(hppfs->host_fd, buf, count);
  240. if (err < 0) {
  241. printk(KERN_ERR "hppfs_read: read failed: %d\n", err);
  242. return err;
  243. }
  244. count = err;
  245. if (count > 0)
  246. *ppos += count;
  247. }
  248. else count = read_proc(hppfs->proc_file, buf, count, ppos, 1);
  249. return count;
  250. }
  251. static ssize_t hppfs_write(struct file *file, const char __user *buf,
  252. size_t len, loff_t *ppos)
  253. {
  254. struct hppfs_private *data = file->private_data;
  255. struct file *proc_file = data->proc_file;
  256. ssize_t (*write)(struct file *, const char __user *, size_t, loff_t *);
  257. write = proc_file->f_path.dentry->d_inode->i_fop->write;
  258. return (*write)(proc_file, buf, len, ppos);
  259. }
  260. static int open_host_sock(char *host_file, int *filter_out)
  261. {
  262. char *end;
  263. int fd;
  264. end = &host_file[strlen(host_file)];
  265. strcpy(end, "/rw");
  266. *filter_out = 1;
  267. fd = os_connect_socket(host_file);
  268. if (fd > 0)
  269. return fd;
  270. strcpy(end, "/r");
  271. *filter_out = 0;
  272. fd = os_connect_socket(host_file);
  273. return fd;
  274. }
  275. static void free_contents(struct hppfs_data *head)
  276. {
  277. struct hppfs_data *data;
  278. struct list_head *ele, *next;
  279. if (head == NULL)
  280. return;
  281. list_for_each_safe(ele, next, &head->list) {
  282. data = list_entry(ele, struct hppfs_data, list);
  283. kfree(data);
  284. }
  285. kfree(head);
  286. }
  287. static struct hppfs_data *hppfs_get_data(int fd, int filter,
  288. struct file *proc_file,
  289. struct file *hppfs_file,
  290. loff_t *size_out)
  291. {
  292. struct hppfs_data *data, *new, *head;
  293. int n, err;
  294. err = -ENOMEM;
  295. data = kmalloc(sizeof(*data), GFP_KERNEL);
  296. if (data == NULL) {
  297. printk(KERN_ERR "hppfs_get_data : head allocation failed\n");
  298. goto failed;
  299. }
  300. INIT_LIST_HEAD(&data->list);
  301. head = data;
  302. *size_out = 0;
  303. if (filter) {
  304. while ((n = read_proc(proc_file, data->contents,
  305. sizeof(data->contents), NULL, 0)) > 0)
  306. os_write_file(fd, data->contents, n);
  307. err = os_shutdown_socket(fd, 0, 1);
  308. if (err) {
  309. printk(KERN_ERR "hppfs_get_data : failed to shut down "
  310. "socket\n");
  311. goto failed_free;
  312. }
  313. }
  314. while (1) {
  315. n = os_read_file(fd, data->contents, sizeof(data->contents));
  316. if (n < 0) {
  317. err = n;
  318. printk(KERN_ERR "hppfs_get_data : read failed, "
  319. "errno = %d\n", err);
  320. goto failed_free;
  321. } else if (n == 0)
  322. break;
  323. *size_out += n;
  324. if (n < sizeof(data->contents))
  325. break;
  326. new = kmalloc(sizeof(*data), GFP_KERNEL);
  327. if (new == 0) {
  328. printk(KERN_ERR "hppfs_get_data : data allocation "
  329. "failed\n");
  330. err = -ENOMEM;
  331. goto failed_free;
  332. }
  333. INIT_LIST_HEAD(&new->list);
  334. list_add(&new->list, &data->list);
  335. data = new;
  336. }
  337. return head;
  338. failed_free:
  339. free_contents(head);
  340. failed:
  341. return ERR_PTR(err);
  342. }
  343. static struct hppfs_private *hppfs_data(void)
  344. {
  345. struct hppfs_private *data;
  346. data = kmalloc(sizeof(*data), GFP_KERNEL);
  347. if (data == NULL)
  348. return data;
  349. *data = ((struct hppfs_private ) { .host_fd = -1,
  350. .len = -1,
  351. .contents = NULL } );
  352. return data;
  353. }
  354. static int file_mode(int fmode)
  355. {
  356. if (fmode == (FMODE_READ | FMODE_WRITE))
  357. return O_RDWR;
  358. if (fmode == FMODE_READ)
  359. return O_RDONLY;
  360. if (fmode == FMODE_WRITE)
  361. return O_WRONLY;
  362. return 0;
  363. }
  364. static int hppfs_open(struct inode *inode, struct file *file)
  365. {
  366. const struct cred *cred = file->f_cred;
  367. struct hppfs_private *data;
  368. struct vfsmount *proc_mnt;
  369. struct dentry *proc_dentry;
  370. char *host_file;
  371. int err, fd, type, filter;
  372. err = -ENOMEM;
  373. data = hppfs_data();
  374. if (data == NULL)
  375. goto out;
  376. host_file = dentry_name(file->f_path.dentry, strlen("/rw"));
  377. if (host_file == NULL)
  378. goto out_free2;
  379. proc_dentry = HPPFS_I(inode)->proc_dentry;
  380. proc_mnt = inode->i_sb->s_fs_info;
  381. /* XXX This isn't closed anywhere */
  382. data->proc_file = dentry_open(dget(proc_dentry), mntget(proc_mnt),
  383. file_mode(file->f_mode), cred);
  384. err = PTR_ERR(data->proc_file);
  385. if (IS_ERR(data->proc_file))
  386. goto out_free1;
  387. type = os_file_type(host_file);
  388. if (type == OS_TYPE_FILE) {
  389. fd = os_open_file(host_file, of_read(OPENFLAGS()), 0);
  390. if (fd >= 0)
  391. data->host_fd = fd;
  392. else
  393. printk(KERN_ERR "hppfs_open : failed to open '%s', "
  394. "errno = %d\n", host_file, -fd);
  395. data->contents = NULL;
  396. } else if (type == OS_TYPE_DIR) {
  397. fd = open_host_sock(host_file, &filter);
  398. if (fd > 0) {
  399. data->contents = hppfs_get_data(fd, filter,
  400. data->proc_file,
  401. file, &data->len);
  402. if (!IS_ERR(data->contents))
  403. data->host_fd = fd;
  404. } else
  405. printk(KERN_ERR "hppfs_open : failed to open a socket "
  406. "in '%s', errno = %d\n", host_file, -fd);
  407. }
  408. kfree(host_file);
  409. file->private_data = data;
  410. return 0;
  411. out_free1:
  412. kfree(host_file);
  413. out_free2:
  414. free_contents(data->contents);
  415. kfree(data);
  416. out:
  417. return err;
  418. }
  419. static int hppfs_dir_open(struct inode *inode, struct file *file)
  420. {
  421. const struct cred *cred = file->f_cred;
  422. struct hppfs_private *data;
  423. struct vfsmount *proc_mnt;
  424. struct dentry *proc_dentry;
  425. int err;
  426. err = -ENOMEM;
  427. data = hppfs_data();
  428. if (data == NULL)
  429. goto out;
  430. proc_dentry = HPPFS_I(inode)->proc_dentry;
  431. proc_mnt = inode->i_sb->s_fs_info;
  432. data->proc_file = dentry_open(dget(proc_dentry), mntget(proc_mnt),
  433. file_mode(file->f_mode), cred);
  434. err = PTR_ERR(data->proc_file);
  435. if (IS_ERR(data->proc_file))
  436. goto out_free;
  437. file->private_data = data;
  438. return 0;
  439. out_free:
  440. kfree(data);
  441. out:
  442. return err;
  443. }
  444. static loff_t hppfs_llseek(struct file *file, loff_t off, int where)
  445. {
  446. struct hppfs_private *data = file->private_data;
  447. struct file *proc_file = data->proc_file;
  448. loff_t (*llseek)(struct file *, loff_t, int);
  449. loff_t ret;
  450. llseek = proc_file->f_path.dentry->d_inode->i_fop->llseek;
  451. if (llseek != NULL) {
  452. ret = (*llseek)(proc_file, off, where);
  453. if (ret < 0)
  454. return ret;
  455. }
  456. return default_llseek(file, off, where);
  457. }
  458. static const struct file_operations hppfs_file_fops = {
  459. .owner = NULL,
  460. .llseek = hppfs_llseek,
  461. .read = hppfs_read,
  462. .write = hppfs_write,
  463. .open = hppfs_open,
  464. };
  465. struct hppfs_dirent {
  466. void *vfs_dirent;
  467. filldir_t filldir;
  468. struct dentry *dentry;
  469. };
  470. static int hppfs_filldir(void *d, const char *name, int size,
  471. loff_t offset, u64 inode, unsigned int type)
  472. {
  473. struct hppfs_dirent *dirent = d;
  474. if (file_removed(dirent->dentry, name))
  475. return 0;
  476. return (*dirent->filldir)(dirent->vfs_dirent, name, size, offset,
  477. inode, type);
  478. }
  479. static int hppfs_readdir(struct file *file, void *ent, filldir_t filldir)
  480. {
  481. struct hppfs_private *data = file->private_data;
  482. struct file *proc_file = data->proc_file;
  483. int (*readdir)(struct file *, void *, filldir_t);
  484. struct hppfs_dirent dirent = ((struct hppfs_dirent)
  485. { .vfs_dirent = ent,
  486. .filldir = filldir,
  487. .dentry = file->f_path.dentry
  488. });
  489. int err;
  490. readdir = proc_file->f_path.dentry->d_inode->i_fop->readdir;
  491. proc_file->f_pos = file->f_pos;
  492. err = (*readdir)(proc_file, &dirent, hppfs_filldir);
  493. file->f_pos = proc_file->f_pos;
  494. return err;
  495. }
  496. static int hppfs_fsync(struct file *file, int datasync)
  497. {
  498. return 0;
  499. }
  500. static const struct file_operations hppfs_dir_fops = {
  501. .owner = NULL,
  502. .readdir = hppfs_readdir,
  503. .open = hppfs_dir_open,
  504. .fsync = hppfs_fsync,
  505. .llseek = default_llseek,
  506. };
  507. static int hppfs_statfs(struct dentry *dentry, struct kstatfs *sf)
  508. {
  509. sf->f_blocks = 0;
  510. sf->f_bfree = 0;
  511. sf->f_bavail = 0;
  512. sf->f_files = 0;
  513. sf->f_ffree = 0;
  514. sf->f_type = HPPFS_SUPER_MAGIC;
  515. return 0;
  516. }
  517. static struct inode *hppfs_alloc_inode(struct super_block *sb)
  518. {
  519. struct hppfs_inode_info *hi;
  520. hi = kmalloc(sizeof(*hi), GFP_KERNEL);
  521. if (!hi)
  522. return NULL;
  523. hi->proc_dentry = NULL;
  524. inode_init_once(&hi->vfs_inode);
  525. return &hi->vfs_inode;
  526. }
  527. void hppfs_evict_inode(struct inode *ino)
  528. {
  529. end_writeback(ino);
  530. dput(HPPFS_I(ino)->proc_dentry);
  531. mntput(ino->i_sb->s_fs_info);
  532. }
  533. static void hppfs_i_callback(struct rcu_head *head)
  534. {
  535. struct inode *inode = container_of(head, struct inode, i_rcu);
  536. INIT_LIST_HEAD(&inode->i_dentry);
  537. kfree(HPPFS_I(inode));
  538. }
  539. static void hppfs_destroy_inode(struct inode *inode)
  540. {
  541. call_rcu(&inode->i_rcu, hppfs_i_callback);
  542. }
  543. static const struct super_operations hppfs_sbops = {
  544. .alloc_inode = hppfs_alloc_inode,
  545. .destroy_inode = hppfs_destroy_inode,
  546. .evict_inode = hppfs_evict_inode,
  547. .statfs = hppfs_statfs,
  548. };
  549. static int hppfs_readlink(struct dentry *dentry, char __user *buffer,
  550. int buflen)
  551. {
  552. struct dentry *proc_dentry = HPPFS_I(dentry->d_inode)->proc_dentry;
  553. return proc_dentry->d_inode->i_op->readlink(proc_dentry, buffer,
  554. buflen);
  555. }
  556. static void *hppfs_follow_link(struct dentry *dentry, struct nameidata *nd)
  557. {
  558. struct dentry *proc_dentry = HPPFS_I(dentry->d_inode)->proc_dentry;
  559. return proc_dentry->d_inode->i_op->follow_link(proc_dentry, nd);
  560. }
  561. static void hppfs_put_link(struct dentry *dentry, struct nameidata *nd,
  562. void *cookie)
  563. {
  564. struct dentry *proc_dentry = HPPFS_I(dentry->d_inode)->proc_dentry;
  565. if (proc_dentry->d_inode->i_op->put_link)
  566. proc_dentry->d_inode->i_op->put_link(proc_dentry, nd, cookie);
  567. }
  568. static const struct inode_operations hppfs_dir_iops = {
  569. .lookup = hppfs_lookup,
  570. };
  571. static const struct inode_operations hppfs_link_iops = {
  572. .readlink = hppfs_readlink,
  573. .follow_link = hppfs_follow_link,
  574. .put_link = hppfs_put_link,
  575. };
  576. static struct inode *get_inode(struct super_block *sb, struct dentry *dentry)
  577. {
  578. struct inode *proc_ino = dentry->d_inode;
  579. struct inode *inode = new_inode(sb);
  580. if (!inode) {
  581. dput(dentry);
  582. return ERR_PTR(-ENOMEM);
  583. }
  584. if (S_ISDIR(dentry->d_inode->i_mode)) {
  585. inode->i_op = &hppfs_dir_iops;
  586. inode->i_fop = &hppfs_dir_fops;
  587. } else if (S_ISLNK(dentry->d_inode->i_mode)) {
  588. inode->i_op = &hppfs_link_iops;
  589. inode->i_fop = &hppfs_file_fops;
  590. } else {
  591. inode->i_op = &hppfs_file_iops;
  592. inode->i_fop = &hppfs_file_fops;
  593. }
  594. HPPFS_I(inode)->proc_dentry = dentry;
  595. inode->i_uid = proc_ino->i_uid;
  596. inode->i_gid = proc_ino->i_gid;
  597. inode->i_atime = proc_ino->i_atime;
  598. inode->i_mtime = proc_ino->i_mtime;
  599. inode->i_ctime = proc_ino->i_ctime;
  600. inode->i_ino = proc_ino->i_ino;
  601. inode->i_mode = proc_ino->i_mode;
  602. inode->i_nlink = proc_ino->i_nlink;
  603. inode->i_size = proc_ino->i_size;
  604. inode->i_blocks = proc_ino->i_blocks;
  605. return inode;
  606. }
  607. static int hppfs_fill_super(struct super_block *sb, void *d, int silent)
  608. {
  609. struct inode *root_inode;
  610. struct vfsmount *proc_mnt;
  611. int err = -ENOENT;
  612. proc_mnt = mntget(current->nsproxy->pid_ns->proc_mnt);
  613. if (IS_ERR(proc_mnt))
  614. goto out;
  615. sb->s_blocksize = 1024;
  616. sb->s_blocksize_bits = 10;
  617. sb->s_magic = HPPFS_SUPER_MAGIC;
  618. sb->s_op = &hppfs_sbops;
  619. sb->s_fs_info = proc_mnt;
  620. err = -ENOMEM;
  621. root_inode = get_inode(sb, dget(proc_mnt->mnt_sb->s_root));
  622. if (!root_inode)
  623. goto out_mntput;
  624. sb->s_root = d_alloc_root(root_inode);
  625. if (!sb->s_root)
  626. goto out_iput;
  627. return 0;
  628. out_iput:
  629. iput(root_inode);
  630. out_mntput:
  631. mntput(proc_mnt);
  632. out:
  633. return(err);
  634. }
  635. static struct dentry *hppfs_read_super(struct file_system_type *type,
  636. int flags, const char *dev_name,
  637. void *data)
  638. {
  639. return mount_nodev(type, flags, data, hppfs_fill_super);
  640. }
  641. static struct file_system_type hppfs_type = {
  642. .owner = THIS_MODULE,
  643. .name = "hppfs",
  644. .mount = hppfs_read_super,
  645. .kill_sb = kill_anon_super,
  646. .fs_flags = 0,
  647. };
  648. static int __init init_hppfs(void)
  649. {
  650. return register_filesystem(&hppfs_type);
  651. }
  652. static void __exit exit_hppfs(void)
  653. {
  654. unregister_filesystem(&hppfs_type);
  655. }
  656. module_init(init_hppfs)
  657. module_exit(exit_hppfs)
  658. MODULE_LICENSE("GPL");