hppfs_kern.c 17 KB

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