hppfs_kern.c 17 KB

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