hppfs.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778
  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_dput;
  152. d_add(dentry, inode);
  153. return NULL;
  154. out_dput:
  155. dput(proc_dentry);
  156. out:
  157. return ERR_PTR(err);
  158. }
  159. static const struct inode_operations hppfs_file_iops = {
  160. };
  161. static ssize_t read_proc(struct file *file, char __user *buf, ssize_t count,
  162. loff_t *ppos, int is_user)
  163. {
  164. ssize_t (*read)(struct file *, char __user *, size_t, loff_t *);
  165. ssize_t n;
  166. read = file->f_path.dentry->d_inode->i_fop->read;
  167. if (!is_user)
  168. set_fs(KERNEL_DS);
  169. n = (*read)(file, buf, count, &file->f_pos);
  170. if (!is_user)
  171. set_fs(USER_DS);
  172. if (ppos)
  173. *ppos = file->f_pos;
  174. return n;
  175. }
  176. static ssize_t hppfs_read_file(int fd, char __user *buf, ssize_t count)
  177. {
  178. ssize_t n;
  179. int cur, err;
  180. char *new_buf;
  181. n = -ENOMEM;
  182. new_buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
  183. if (new_buf == NULL) {
  184. printk(KERN_ERR "hppfs_read_file : kmalloc failed\n");
  185. goto out;
  186. }
  187. n = 0;
  188. while (count > 0) {
  189. cur = min_t(ssize_t, count, PAGE_SIZE);
  190. err = os_read_file(fd, new_buf, cur);
  191. if (err < 0) {
  192. printk(KERN_ERR "hppfs_read : read failed, "
  193. "errno = %d\n", err);
  194. n = err;
  195. goto out_free;
  196. } else if (err == 0)
  197. break;
  198. if (copy_to_user(buf, new_buf, err)) {
  199. n = -EFAULT;
  200. goto out_free;
  201. }
  202. n += err;
  203. count -= err;
  204. }
  205. out_free:
  206. kfree(new_buf);
  207. out:
  208. return n;
  209. }
  210. static ssize_t hppfs_read(struct file *file, char __user *buf, size_t count,
  211. loff_t *ppos)
  212. {
  213. struct hppfs_private *hppfs = file->private_data;
  214. struct hppfs_data *data;
  215. loff_t off;
  216. int err;
  217. if (hppfs->contents != NULL) {
  218. int rem;
  219. if (*ppos >= hppfs->len)
  220. return 0;
  221. data = hppfs->contents;
  222. off = *ppos;
  223. while (off >= sizeof(data->contents)) {
  224. data = list_entry(data->list.next, struct hppfs_data,
  225. list);
  226. off -= sizeof(data->contents);
  227. }
  228. if (off + count > hppfs->len)
  229. count = hppfs->len - off;
  230. rem = copy_to_user(buf, &data->contents[off], count);
  231. *ppos += count - rem;
  232. if (rem > 0)
  233. return -EFAULT;
  234. } else if (hppfs->host_fd != -1) {
  235. err = os_seek_file(hppfs->host_fd, *ppos);
  236. if (err) {
  237. printk(KERN_ERR "hppfs_read : seek failed, "
  238. "errno = %d\n", err);
  239. return err;
  240. }
  241. err = hppfs_read_file(hppfs->host_fd, buf, count);
  242. if (err < 0) {
  243. printk(KERN_ERR "hppfs_read: read failed: %d\n", err);
  244. return err;
  245. }
  246. count = err;
  247. if (count > 0)
  248. *ppos += count;
  249. }
  250. else count = read_proc(hppfs->proc_file, buf, count, ppos, 1);
  251. return count;
  252. }
  253. static ssize_t hppfs_write(struct file *file, const char __user *buf,
  254. size_t len, loff_t *ppos)
  255. {
  256. struct hppfs_private *data = file->private_data;
  257. struct file *proc_file = data->proc_file;
  258. ssize_t (*write)(struct file *, const char __user *, size_t, loff_t *);
  259. write = proc_file->f_path.dentry->d_inode->i_fop->write;
  260. return (*write)(proc_file, buf, len, ppos);
  261. }
  262. static int open_host_sock(char *host_file, int *filter_out)
  263. {
  264. char *end;
  265. int fd;
  266. end = &host_file[strlen(host_file)];
  267. strcpy(end, "/rw");
  268. *filter_out = 1;
  269. fd = os_connect_socket(host_file);
  270. if (fd > 0)
  271. return fd;
  272. strcpy(end, "/r");
  273. *filter_out = 0;
  274. fd = os_connect_socket(host_file);
  275. return fd;
  276. }
  277. static void free_contents(struct hppfs_data *head)
  278. {
  279. struct hppfs_data *data;
  280. struct list_head *ele, *next;
  281. if (head == NULL)
  282. return;
  283. list_for_each_safe(ele, next, &head->list) {
  284. data = list_entry(ele, struct hppfs_data, list);
  285. kfree(data);
  286. }
  287. kfree(head);
  288. }
  289. static struct hppfs_data *hppfs_get_data(int fd, int filter,
  290. struct file *proc_file,
  291. struct file *hppfs_file,
  292. loff_t *size_out)
  293. {
  294. struct hppfs_data *data, *new, *head;
  295. int n, err;
  296. err = -ENOMEM;
  297. data = kmalloc(sizeof(*data), GFP_KERNEL);
  298. if (data == NULL) {
  299. printk(KERN_ERR "hppfs_get_data : head allocation failed\n");
  300. goto failed;
  301. }
  302. INIT_LIST_HEAD(&data->list);
  303. head = data;
  304. *size_out = 0;
  305. if (filter) {
  306. while ((n = read_proc(proc_file, data->contents,
  307. sizeof(data->contents), NULL, 0)) > 0)
  308. os_write_file(fd, data->contents, n);
  309. err = os_shutdown_socket(fd, 0, 1);
  310. if (err) {
  311. printk(KERN_ERR "hppfs_get_data : failed to shut down "
  312. "socket\n");
  313. goto failed_free;
  314. }
  315. }
  316. while (1) {
  317. n = os_read_file(fd, data->contents, sizeof(data->contents));
  318. if (n < 0) {
  319. err = n;
  320. printk(KERN_ERR "hppfs_get_data : read failed, "
  321. "errno = %d\n", err);
  322. goto failed_free;
  323. } else if (n == 0)
  324. break;
  325. *size_out += n;
  326. if (n < sizeof(data->contents))
  327. break;
  328. new = kmalloc(sizeof(*data), GFP_KERNEL);
  329. if (new == 0) {
  330. printk(KERN_ERR "hppfs_get_data : data allocation "
  331. "failed\n");
  332. err = -ENOMEM;
  333. goto failed_free;
  334. }
  335. INIT_LIST_HEAD(&new->list);
  336. list_add(&new->list, &data->list);
  337. data = new;
  338. }
  339. return head;
  340. failed_free:
  341. free_contents(head);
  342. failed:
  343. return ERR_PTR(err);
  344. }
  345. static struct hppfs_private *hppfs_data(void)
  346. {
  347. struct hppfs_private *data;
  348. data = kmalloc(sizeof(*data), GFP_KERNEL);
  349. if (data == NULL)
  350. return data;
  351. *data = ((struct hppfs_private ) { .host_fd = -1,
  352. .len = -1,
  353. .contents = NULL } );
  354. return data;
  355. }
  356. static int file_mode(int fmode)
  357. {
  358. if (fmode == (FMODE_READ | FMODE_WRITE))
  359. return O_RDWR;
  360. if (fmode == FMODE_READ)
  361. return O_RDONLY;
  362. if (fmode == FMODE_WRITE)
  363. return O_WRONLY;
  364. return 0;
  365. }
  366. static int hppfs_open(struct inode *inode, struct file *file)
  367. {
  368. const struct cred *cred = file->f_cred;
  369. struct hppfs_private *data;
  370. struct vfsmount *proc_mnt;
  371. struct dentry *proc_dentry;
  372. char *host_file;
  373. int err, fd, type, filter;
  374. err = -ENOMEM;
  375. data = hppfs_data();
  376. if (data == NULL)
  377. goto out;
  378. host_file = dentry_name(file->f_path.dentry, strlen("/rw"));
  379. if (host_file == NULL)
  380. goto out_free2;
  381. proc_dentry = HPPFS_I(inode)->proc_dentry;
  382. proc_mnt = inode->i_sb->s_fs_info;
  383. /* XXX This isn't closed anywhere */
  384. data->proc_file = dentry_open(dget(proc_dentry), mntget(proc_mnt),
  385. file_mode(file->f_mode), cred);
  386. err = PTR_ERR(data->proc_file);
  387. if (IS_ERR(data->proc_file))
  388. goto out_free1;
  389. type = os_file_type(host_file);
  390. if (type == OS_TYPE_FILE) {
  391. fd = os_open_file(host_file, of_read(OPENFLAGS()), 0);
  392. if (fd >= 0)
  393. data->host_fd = fd;
  394. else
  395. printk(KERN_ERR "hppfs_open : failed to open '%s', "
  396. "errno = %d\n", host_file, -fd);
  397. data->contents = NULL;
  398. } else if (type == OS_TYPE_DIR) {
  399. fd = open_host_sock(host_file, &filter);
  400. if (fd > 0) {
  401. data->contents = hppfs_get_data(fd, filter,
  402. data->proc_file,
  403. file, &data->len);
  404. if (!IS_ERR(data->contents))
  405. data->host_fd = fd;
  406. } else
  407. printk(KERN_ERR "hppfs_open : failed to open a socket "
  408. "in '%s', errno = %d\n", host_file, -fd);
  409. }
  410. kfree(host_file);
  411. file->private_data = data;
  412. return 0;
  413. out_free1:
  414. kfree(host_file);
  415. out_free2:
  416. free_contents(data->contents);
  417. kfree(data);
  418. out:
  419. return err;
  420. }
  421. static int hppfs_dir_open(struct inode *inode, struct file *file)
  422. {
  423. const struct cred *cred = file->f_cred;
  424. struct hppfs_private *data;
  425. struct vfsmount *proc_mnt;
  426. struct dentry *proc_dentry;
  427. int err;
  428. err = -ENOMEM;
  429. data = hppfs_data();
  430. if (data == NULL)
  431. goto out;
  432. proc_dentry = HPPFS_I(inode)->proc_dentry;
  433. proc_mnt = inode->i_sb->s_fs_info;
  434. data->proc_file = dentry_open(dget(proc_dentry), mntget(proc_mnt),
  435. file_mode(file->f_mode), cred);
  436. err = PTR_ERR(data->proc_file);
  437. if (IS_ERR(data->proc_file))
  438. goto out_free;
  439. file->private_data = data;
  440. return 0;
  441. out_free:
  442. kfree(data);
  443. out:
  444. return err;
  445. }
  446. static loff_t hppfs_llseek(struct file *file, loff_t off, int where)
  447. {
  448. struct hppfs_private *data = file->private_data;
  449. struct file *proc_file = data->proc_file;
  450. loff_t (*llseek)(struct file *, loff_t, int);
  451. loff_t ret;
  452. llseek = proc_file->f_path.dentry->d_inode->i_fop->llseek;
  453. if (llseek != NULL) {
  454. ret = (*llseek)(proc_file, off, where);
  455. if (ret < 0)
  456. return ret;
  457. }
  458. return default_llseek(file, off, where);
  459. }
  460. static const struct file_operations hppfs_file_fops = {
  461. .owner = NULL,
  462. .llseek = hppfs_llseek,
  463. .read = hppfs_read,
  464. .write = hppfs_write,
  465. .open = hppfs_open,
  466. };
  467. struct hppfs_dirent {
  468. void *vfs_dirent;
  469. filldir_t filldir;
  470. struct dentry *dentry;
  471. };
  472. static int hppfs_filldir(void *d, const char *name, int size,
  473. loff_t offset, u64 inode, unsigned int type)
  474. {
  475. struct hppfs_dirent *dirent = d;
  476. if (file_removed(dirent->dentry, name))
  477. return 0;
  478. return (*dirent->filldir)(dirent->vfs_dirent, name, size, offset,
  479. inode, type);
  480. }
  481. static int hppfs_readdir(struct file *file, void *ent, filldir_t filldir)
  482. {
  483. struct hppfs_private *data = file->private_data;
  484. struct file *proc_file = data->proc_file;
  485. int (*readdir)(struct file *, void *, filldir_t);
  486. struct hppfs_dirent dirent = ((struct hppfs_dirent)
  487. { .vfs_dirent = ent,
  488. .filldir = filldir,
  489. .dentry = file->f_path.dentry
  490. });
  491. int err;
  492. readdir = proc_file->f_path.dentry->d_inode->i_fop->readdir;
  493. proc_file->f_pos = file->f_pos;
  494. err = (*readdir)(proc_file, &dirent, hppfs_filldir);
  495. file->f_pos = proc_file->f_pos;
  496. return err;
  497. }
  498. static int hppfs_fsync(struct file *file, int datasync)
  499. {
  500. return 0;
  501. }
  502. static const struct file_operations hppfs_dir_fops = {
  503. .owner = NULL,
  504. .readdir = hppfs_readdir,
  505. .open = hppfs_dir_open,
  506. .fsync = hppfs_fsync,
  507. .llseek = default_llseek,
  508. };
  509. static int hppfs_statfs(struct dentry *dentry, struct kstatfs *sf)
  510. {
  511. sf->f_blocks = 0;
  512. sf->f_bfree = 0;
  513. sf->f_bavail = 0;
  514. sf->f_files = 0;
  515. sf->f_ffree = 0;
  516. sf->f_type = HPPFS_SUPER_MAGIC;
  517. return 0;
  518. }
  519. static struct inode *hppfs_alloc_inode(struct super_block *sb)
  520. {
  521. struct hppfs_inode_info *hi;
  522. hi = kmalloc(sizeof(*hi), GFP_KERNEL);
  523. if (!hi)
  524. return NULL;
  525. hi->proc_dentry = NULL;
  526. inode_init_once(&hi->vfs_inode);
  527. return &hi->vfs_inode;
  528. }
  529. void hppfs_evict_inode(struct inode *ino)
  530. {
  531. end_writeback(ino);
  532. dput(HPPFS_I(ino)->proc_dentry);
  533. mntput(ino->i_sb->s_fs_info);
  534. }
  535. static void hppfs_destroy_inode(struct inode *inode)
  536. {
  537. kfree(HPPFS_I(inode));
  538. }
  539. static const struct super_operations hppfs_sbops = {
  540. .alloc_inode = hppfs_alloc_inode,
  541. .destroy_inode = hppfs_destroy_inode,
  542. .evict_inode = hppfs_evict_inode,
  543. .statfs = hppfs_statfs,
  544. };
  545. static int hppfs_readlink(struct dentry *dentry, char __user *buffer,
  546. int buflen)
  547. {
  548. struct dentry *proc_dentry = HPPFS_I(dentry->d_inode)->proc_dentry;
  549. return proc_dentry->d_inode->i_op->readlink(proc_dentry, buffer,
  550. buflen);
  551. }
  552. static void *hppfs_follow_link(struct dentry *dentry, struct nameidata *nd)
  553. {
  554. struct dentry *proc_dentry = HPPFS_I(dentry->d_inode)->proc_dentry;
  555. return proc_dentry->d_inode->i_op->follow_link(proc_dentry, nd);
  556. }
  557. static void hppfs_put_link(struct dentry *dentry, struct nameidata *nd,
  558. void *cookie)
  559. {
  560. struct dentry *proc_dentry = HPPFS_I(dentry->d_inode)->proc_dentry;
  561. if (proc_dentry->d_inode->i_op->put_link)
  562. proc_dentry->d_inode->i_op->put_link(proc_dentry, nd, cookie);
  563. }
  564. static const struct inode_operations hppfs_dir_iops = {
  565. .lookup = hppfs_lookup,
  566. };
  567. static const struct inode_operations hppfs_link_iops = {
  568. .readlink = hppfs_readlink,
  569. .follow_link = hppfs_follow_link,
  570. .put_link = hppfs_put_link,
  571. };
  572. static struct inode *get_inode(struct super_block *sb, struct dentry *dentry)
  573. {
  574. struct inode *proc_ino = dentry->d_inode;
  575. struct inode *inode = new_inode(sb);
  576. if (!inode)
  577. return ERR_PTR(-ENOMEM);
  578. if (S_ISDIR(dentry->d_inode->i_mode)) {
  579. inode->i_op = &hppfs_dir_iops;
  580. inode->i_fop = &hppfs_dir_fops;
  581. } else if (S_ISLNK(dentry->d_inode->i_mode)) {
  582. inode->i_op = &hppfs_link_iops;
  583. inode->i_fop = &hppfs_file_fops;
  584. } else {
  585. inode->i_op = &hppfs_file_iops;
  586. inode->i_fop = &hppfs_file_fops;
  587. }
  588. HPPFS_I(inode)->proc_dentry = dget(dentry);
  589. inode->i_uid = proc_ino->i_uid;
  590. inode->i_gid = proc_ino->i_gid;
  591. inode->i_atime = proc_ino->i_atime;
  592. inode->i_mtime = proc_ino->i_mtime;
  593. inode->i_ctime = proc_ino->i_ctime;
  594. inode->i_ino = proc_ino->i_ino;
  595. inode->i_mode = proc_ino->i_mode;
  596. inode->i_nlink = proc_ino->i_nlink;
  597. inode->i_size = proc_ino->i_size;
  598. inode->i_blocks = proc_ino->i_blocks;
  599. return inode;
  600. }
  601. static int hppfs_fill_super(struct super_block *sb, void *d, int silent)
  602. {
  603. struct inode *root_inode;
  604. struct vfsmount *proc_mnt;
  605. int err = -ENOENT;
  606. proc_mnt = mntget(current->nsproxy->pid_ns->proc_mnt);
  607. if (IS_ERR(proc_mnt))
  608. goto out;
  609. sb->s_blocksize = 1024;
  610. sb->s_blocksize_bits = 10;
  611. sb->s_magic = HPPFS_SUPER_MAGIC;
  612. sb->s_op = &hppfs_sbops;
  613. sb->s_fs_info = proc_mnt;
  614. err = -ENOMEM;
  615. root_inode = get_inode(sb, proc_mnt->mnt_sb->s_root);
  616. if (!root_inode)
  617. goto out_mntput;
  618. sb->s_root = d_alloc_root(root_inode);
  619. if (!sb->s_root)
  620. goto out_iput;
  621. return 0;
  622. out_iput:
  623. iput(root_inode);
  624. out_mntput:
  625. mntput(proc_mnt);
  626. out:
  627. return(err);
  628. }
  629. static struct dentry *hppfs_read_super(struct file_system_type *type,
  630. int flags, const char *dev_name,
  631. void *data)
  632. {
  633. return mount_nodev(type, flags, data, hppfs_fill_super);
  634. }
  635. static struct file_system_type hppfs_type = {
  636. .owner = THIS_MODULE,
  637. .name = "hppfs",
  638. .mount = hppfs_read_super,
  639. .kill_sb = kill_anon_super,
  640. .fs_flags = 0,
  641. };
  642. static int __init init_hppfs(void)
  643. {
  644. return register_filesystem(&hppfs_type);
  645. }
  646. static void __exit exit_hppfs(void)
  647. {
  648. unregister_filesystem(&hppfs_type);
  649. }
  650. module_init(init_hppfs)
  651. module_exit(exit_hppfs)
  652. MODULE_LICENSE("GPL");