namei.c (846ae671ad368e344a2b141c0f19e1014b27a0dd) namei.c (b6a06cbbb5f7fd03589cff9178314af04c568826)
1/*
2 * fs/f2fs/namei.c
3 *
4 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 * http://www.samsung.com/
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as

--- 128 unchanged lines hidden (view full) ---

137 if (nid_free)
138 set_inode_flag(inode, FI_FREE_NID);
139 clear_nlink(inode);
140 unlock_new_inode(inode);
141 iput(inode);
142 return ERR_PTR(err);
143}
144
1/*
2 * fs/f2fs/namei.c
3 *
4 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 * http://www.samsung.com/
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as

--- 128 unchanged lines hidden (view full) ---

137 if (nid_free)
138 set_inode_flag(inode, FI_FREE_NID);
139 clear_nlink(inode);
140 unlock_new_inode(inode);
141 iput(inode);
142 return ERR_PTR(err);
143}
144
145static int is_multimedia_file(const unsigned char *s, const char *sub)
145static int is_extension_exist(const unsigned char *s, const char *sub)
146{
147 size_t slen = strlen(s);
148 size_t sublen = strlen(sub);
149 int i;
150
151 /*
152 * filename format of multimedia file should be defined as:
153 * "filename + '.' + extension + (optional: '.' + temp extension)".

--- 9 unchanged lines hidden (view full) ---

163 }
164
165 return 0;
166}
167
168/*
169 * Set multimedia files as cold files for hot/cold data separation
170 */
146{
147 size_t slen = strlen(s);
148 size_t sublen = strlen(sub);
149 int i;
150
151 /*
152 * filename format of multimedia file should be defined as:
153 * "filename + '.' + extension + (optional: '.' + temp extension)".

--- 9 unchanged lines hidden (view full) ---

163 }
164
165 return 0;
166}
167
168/*
169 * Set multimedia files as cold files for hot/cold data separation
170 */
171static inline void set_cold_files(struct f2fs_sb_info *sbi, struct inode *inode,
171static inline void set_file_temperature(struct f2fs_sb_info *sbi, struct inode *inode,
172 const unsigned char *name)
173{
174 __u8 (*extlist)[F2FS_EXTENSION_LEN] = sbi->raw_super->extension_list;
172 const unsigned char *name)
173{
174 __u8 (*extlist)[F2FS_EXTENSION_LEN] = sbi->raw_super->extension_list;
175 int i, count;
175 int i, cold_count, hot_count;
176
177 down_read(&sbi->sb_lock);
178
176
177 down_read(&sbi->sb_lock);
178
179 count = le32_to_cpu(sbi->raw_super->extension_count);
179 cold_count = le32_to_cpu(sbi->raw_super->extension_count);
180 hot_count = sbi->raw_super->hot_ext_count;
180
181
181 for (i = 0; i < count; i++) {
182 if (is_multimedia_file(name, extlist[i])) {
182 for (i = 0; i < cold_count + hot_count; i++) {
183 if (!is_extension_exist(name, extlist[i]))
184 continue;
185 if (i < cold_count)
183 file_set_cold(inode);
186 file_set_cold(inode);
184 break;
185 }
187 else
188 file_set_hot(inode);
189 break;
186 }
187
188 up_read(&sbi->sb_lock);
189}
190
190 }
191
192 up_read(&sbi->sb_lock);
193}
194
191int update_extension_list(struct f2fs_sb_info *sbi, const char *name, bool set)
195int update_extension_list(struct f2fs_sb_info *sbi, const char *name,
196 bool hot, bool set)
192{
193 __u8 (*extlist)[F2FS_EXTENSION_LEN] = sbi->raw_super->extension_list;
197{
198 __u8 (*extlist)[F2FS_EXTENSION_LEN] = sbi->raw_super->extension_list;
194 int count = le32_to_cpu(sbi->raw_super->extension_count);
199 int cold_count = le32_to_cpu(sbi->raw_super->extension_count);
200 int hot_count = sbi->raw_super->hot_ext_count;
201 int total_count = cold_count + hot_count;
202 int start, count;
195 int i;
196
203 int i;
204
197 for (i = 0; i < count; i++) {
205 if (set) {
206 if (total_count == F2FS_MAX_EXTENSION)
207 return -EINVAL;
208 } else {
209 if (!hot && !cold_count)
210 return -EINVAL;
211 if (hot && !hot_count)
212 return -EINVAL;
213 }
214
215 if (hot) {
216 start = cold_count;
217 count = total_count;
218 } else {
219 start = 0;
220 count = cold_count;
221 }
222
223 for (i = start; i < count; i++) {
198 if (strcmp(name, extlist[i]))
199 continue;
200
201 if (set)
202 return -EINVAL;
203
204 memcpy(extlist[i], extlist[i + 1],
224 if (strcmp(name, extlist[i]))
225 continue;
226
227 if (set)
228 return -EINVAL;
229
230 memcpy(extlist[i], extlist[i + 1],
205 F2FS_EXTENSION_LEN * (count - i - 1));
206 memset(extlist[count - 1], 0, F2FS_EXTENSION_LEN);
207 sbi->raw_super->extension_count = cpu_to_le32(count - 1);
231 F2FS_EXTENSION_LEN * (total_count - i - 1));
232 memset(extlist[total_count - 1], 0, F2FS_EXTENSION_LEN);
233 if (hot)
234 sbi->raw_super->hot_ext_count = hot_count - 1;
235 else
236 sbi->raw_super->extension_count =
237 cpu_to_le32(cold_count - 1);
208 return 0;
209 }
210
211 if (!set)
212 return -EINVAL;
213
238 return 0;
239 }
240
241 if (!set)
242 return -EINVAL;
243
214 if (count == F2FS_MAX_EXTENSION)
215 return -EINVAL;
244 if (hot) {
245 strncpy(extlist[count], name, strlen(name));
246 sbi->raw_super->hot_ext_count = hot_count + 1;
247 } else {
248 char buf[F2FS_MAX_EXTENSION][F2FS_EXTENSION_LEN];
216
249
217 strncpy(extlist[count], name, strlen(name));
218 sbi->raw_super->extension_count = cpu_to_le32(count + 1);
250 memcpy(buf, &extlist[cold_count],
251 F2FS_EXTENSION_LEN * hot_count);
252 memset(extlist[cold_count], 0, F2FS_EXTENSION_LEN);
253 strncpy(extlist[cold_count], name, strlen(name));
254 memcpy(&extlist[cold_count + 1], buf,
255 F2FS_EXTENSION_LEN * hot_count);
256 sbi->raw_super->extension_count = cpu_to_le32(cold_count + 1);
257 }
219 return 0;
220}
221
222static int f2fs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
223 bool excl)
224{
225 struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
226 struct inode *inode;

--- 7 unchanged lines hidden (view full) ---

234 if (err)
235 return err;
236
237 inode = f2fs_new_inode(dir, mode);
238 if (IS_ERR(inode))
239 return PTR_ERR(inode);
240
241 if (!test_opt(sbi, DISABLE_EXT_IDENTIFY))
258 return 0;
259}
260
261static int f2fs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
262 bool excl)
263{
264 struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
265 struct inode *inode;

--- 7 unchanged lines hidden (view full) ---

273 if (err)
274 return err;
275
276 inode = f2fs_new_inode(dir, mode);
277 if (IS_ERR(inode))
278 return PTR_ERR(inode);
279
280 if (!test_opt(sbi, DISABLE_EXT_IDENTIFY))
242 set_cold_files(sbi, inode, dentry->d_name.name);
281 set_file_temperature(sbi, inode, dentry->d_name.name);
243
244 inode->i_op = &f2fs_file_inode_operations;
245 inode->i_fop = &f2fs_file_operations;
246 inode->i_mapping->a_ops = &f2fs_dblock_aops;
247 ino = inode->i_ino;
248
249 f2fs_lock_op(sbi);
250 err = f2fs_add_link(dentry, inode);

--- 949 unchanged lines hidden ---
282
283 inode->i_op = &f2fs_file_inode_operations;
284 inode->i_fop = &f2fs_file_operations;
285 inode->i_mapping->a_ops = &f2fs_dblock_aops;
286 ino = inode->i_ino;
287
288 f2fs_lock_op(sbi);
289 err = f2fs_add_link(dentry, inode);

--- 949 unchanged lines hidden ---