4040struct pstore_private {
4141 u64 id ;
4242 int (* erase )(u64 );
43+ ssize_t size ;
44+ char data [];
4345};
4446
45- #define pstore_get_inode ramfs_get_inode
47+ static int pstore_file_open (struct inode * inode , struct file * file )
48+ {
49+ file -> private_data = inode -> i_private ;
50+ return 0 ;
51+ }
52+
53+ static ssize_t pstore_file_read (struct file * file , char __user * userbuf ,
54+ size_t count , loff_t * ppos )
55+ {
56+ struct pstore_private * ps = file -> private_data ;
57+
58+ return simple_read_from_buffer (userbuf , count , ppos , ps -> data , ps -> size );
59+ }
60+
61+ static const struct file_operations pstore_file_operations = {
62+ .open = pstore_file_open ,
63+ .read = pstore_file_read ,
64+ .llseek = default_llseek ,
65+ };
4666
4767/*
4868 * When a file is unlinked from our file system we call the
@@ -63,44 +83,41 @@ static const struct inode_operations pstore_dir_inode_operations = {
6383 .unlink = pstore_unlink ,
6484};
6585
86+ static struct inode * pstore_get_inode (struct super_block * sb ,
87+ const struct inode * dir , int mode , dev_t dev )
88+ {
89+ struct inode * inode = new_inode (sb );
90+
91+ if (inode ) {
92+ inode -> i_ino = get_next_ino ();
93+ inode -> i_uid = inode -> i_gid = 0 ;
94+ inode -> i_mode = mode ;
95+ inode -> i_atime = inode -> i_mtime = inode -> i_ctime = CURRENT_TIME ;
96+ switch (mode & S_IFMT ) {
97+ case S_IFREG :
98+ inode -> i_fop = & pstore_file_operations ;
99+ break ;
100+ case S_IFDIR :
101+ inode -> i_op = & pstore_dir_inode_operations ;
102+ inode -> i_fop = & simple_dir_operations ;
103+ inc_nlink (inode );
104+ break ;
105+ }
106+ }
107+ return inode ;
108+ }
109+
66110static const struct super_operations pstore_ops = {
67111 .statfs = simple_statfs ,
68112 .drop_inode = generic_delete_inode ,
69113 .show_options = generic_show_options ,
70114};
71115
72116static struct super_block * pstore_sb ;
73- static struct vfsmount * pstore_mnt ;
74117
75118int pstore_is_mounted (void )
76119{
77- return pstore_mnt != NULL ;
78- }
79-
80- /*
81- * Set up a file structure as if we had opened this file and
82- * write our data to it.
83- */
84- static int pstore_writefile (struct inode * inode , struct dentry * dentry ,
85- char * data , size_t size )
86- {
87- struct file f ;
88- ssize_t n ;
89- mm_segment_t old_fs = get_fs ();
90-
91- memset (& f , '0' , sizeof f );
92- f .f_mapping = inode -> i_mapping ;
93- f .f_path .dentry = dentry ;
94- f .f_path .mnt = pstore_mnt ;
95- f .f_pos = 0 ;
96- f .f_op = inode -> i_fop ;
97- set_fs (KERNEL_DS );
98- n = do_sync_write (& f , data , size , & f .f_pos );
99- set_fs (old_fs );
100-
101- fsnotify_modify (& f );
102-
103- return n == size ;
120+ return pstore_sb != NULL ;
104121}
105122
106123/*
@@ -123,8 +140,7 @@ int pstore_mkfile(enum pstore_type_id type, char *psname, u64 id,
123140 inode = pstore_get_inode (pstore_sb , root -> d_inode , S_IFREG | 0444 , 0 );
124141 if (!inode )
125142 goto fail ;
126- inode -> i_uid = inode -> i_gid = 0 ;
127- private = kmalloc (sizeof * private , GFP_KERNEL );
143+ private = kmalloc (sizeof * private + size , GFP_KERNEL );
128144 if (!private )
129145 goto fail_alloc ;
130146 private -> id = id ;
@@ -152,28 +168,19 @@ int pstore_mkfile(enum pstore_type_id type, char *psname, u64 id,
152168 if (IS_ERR (dentry ))
153169 goto fail_lockedalloc ;
154170
155- d_add (dentry , inode );
156-
157- mutex_unlock (& root -> d_inode -> i_mutex );
158-
159- if (!pstore_writefile (inode , dentry , data , size ))
160- goto fail_write ;
171+ memcpy (private -> data , data , size );
172+ inode -> i_size = private -> size = size ;
161173
162174 inode -> i_private = private ;
163175
164176 if (time .tv_sec )
165177 inode -> i_mtime = inode -> i_ctime = time ;
166178
167- return 0 ;
179+ d_add ( dentry , inode ) ;
168180
169- fail_write :
170- kfree (private );
171- inode -> i_nlink -- ;
172- mutex_lock (& root -> d_inode -> i_mutex );
173- d_delete (dentry );
174- dput (dentry );
175181 mutex_unlock (& root -> d_inode -> i_mutex );
176- goto fail ;
182+
183+ return 0 ;
177184
178185fail_lockedalloc :
179186 mutex_unlock (& root -> d_inode -> i_mutex );
@@ -225,32 +232,21 @@ int pstore_fill_super(struct super_block *sb, void *data, int silent)
225232 return err ;
226233}
227234
228- static int pstore_get_sb (struct file_system_type * fs_type ,
229- int flags , const char * dev_name , void * data , struct vfsmount * mnt )
235+ static struct dentry * pstore_mount (struct file_system_type * fs_type ,
236+ int flags , const char * dev_name , void * data )
230237{
231- struct dentry * root ;
232-
233- root = mount_nodev (fs_type , flags , data , pstore_fill_super );
234- if (IS_ERR (root ))
235- return - ENOMEM ;
236-
237- mnt -> mnt_root = root ;
238- mnt -> mnt_sb = root -> d_sb ;
239- pstore_mnt = mnt ;
240-
241- return 0 ;
238+ return mount_single (fs_type , flags , data , pstore_fill_super );
242239}
243240
244241static void pstore_kill_sb (struct super_block * sb )
245242{
246243 kill_litter_super (sb );
247244 pstore_sb = NULL ;
248- pstore_mnt = NULL ;
249245}
250246
251247static struct file_system_type pstore_fs_type = {
252248 .name = "pstore" ,
253- .get_sb = pstore_get_sb ,
249+ .mount = pstore_mount ,
254250 .kill_sb = pstore_kill_sb ,
255251};
256252
0 commit comments