hppfs_kern.c 17 KB

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