hppfs.c 17 KB

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