hppfs.c 17 KB

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