hppfs_kern.c 17 KB

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