hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/fs/ext2/dir.c
....@@ -252,33 +252,10 @@
252252 return (char *)p - base;
253253 }
254254
255
-static unsigned char ext2_filetype_table[EXT2_FT_MAX] = {
256
- [EXT2_FT_UNKNOWN] = DT_UNKNOWN,
257
- [EXT2_FT_REG_FILE] = DT_REG,
258
- [EXT2_FT_DIR] = DT_DIR,
259
- [EXT2_FT_CHRDEV] = DT_CHR,
260
- [EXT2_FT_BLKDEV] = DT_BLK,
261
- [EXT2_FT_FIFO] = DT_FIFO,
262
- [EXT2_FT_SOCK] = DT_SOCK,
263
- [EXT2_FT_SYMLINK] = DT_LNK,
264
-};
265
-
266
-#define S_SHIFT 12
267
-static unsigned char ext2_type_by_mode[S_IFMT >> S_SHIFT] = {
268
- [S_IFREG >> S_SHIFT] = EXT2_FT_REG_FILE,
269
- [S_IFDIR >> S_SHIFT] = EXT2_FT_DIR,
270
- [S_IFCHR >> S_SHIFT] = EXT2_FT_CHRDEV,
271
- [S_IFBLK >> S_SHIFT] = EXT2_FT_BLKDEV,
272
- [S_IFIFO >> S_SHIFT] = EXT2_FT_FIFO,
273
- [S_IFSOCK >> S_SHIFT] = EXT2_FT_SOCK,
274
- [S_IFLNK >> S_SHIFT] = EXT2_FT_SYMLINK,
275
-};
276
-
277255 static inline void ext2_set_de_type(ext2_dirent *de, struct inode *inode)
278256 {
279
- umode_t mode = inode->i_mode;
280257 if (EXT2_HAS_INCOMPAT_FEATURE(inode->i_sb, EXT2_FEATURE_INCOMPAT_FILETYPE))
281
- de->file_type = ext2_type_by_mode[(mode & S_IFMT)>>S_SHIFT];
258
+ de->file_type = fs_umode_to_ftype(inode->i_mode);
282259 else
283260 de->file_type = 0;
284261 }
....@@ -293,14 +270,14 @@
293270 unsigned long n = pos >> PAGE_SHIFT;
294271 unsigned long npages = dir_pages(inode);
295272 unsigned chunk_mask = ~(ext2_chunk_size(inode)-1);
296
- unsigned char *types = NULL;
297273 bool need_revalidate = !inode_eq_iversion(inode, file->f_version);
274
+ bool has_filetype;
298275
299276 if (pos > inode->i_size - EXT2_DIR_REC_LEN(1))
300277 return 0;
301278
302
- if (EXT2_HAS_INCOMPAT_FEATURE(sb, EXT2_FEATURE_INCOMPAT_FILETYPE))
303
- types = ext2_filetype_table;
279
+ has_filetype =
280
+ EXT2_HAS_INCOMPAT_FEATURE(sb, EXT2_FEATURE_INCOMPAT_FILETYPE);
304281
305282 for ( ; n < npages; n++, offset = 0) {
306283 char *kaddr, *limit;
....@@ -335,8 +312,8 @@
335312 if (de->inode) {
336313 unsigned char d_type = DT_UNKNOWN;
337314
338
- if (types && de->file_type < EXT2_FT_MAX)
339
- d_type = types[de->file_type];
315
+ if (has_filetype)
316
+ d_type = fs_ftype_to_dtype(de->file_type);
340317
341318 if (!dir_emit(ctx, de->name, de->name_len,
342319 le32_to_cpu(de->inode),
....@@ -371,7 +348,6 @@
371348 struct page *page = NULL;
372349 struct ext2_inode_info *ei = EXT2_I(dir);
373350 ext2_dirent * de;
374
- int dir_has_error = 0;
375351
376352 if (npages == 0)
377353 goto out;
....@@ -385,25 +361,25 @@
385361 n = start;
386362 do {
387363 char *kaddr;
388
- page = ext2_get_page(dir, n, dir_has_error);
389
- if (!IS_ERR(page)) {
390
- kaddr = page_address(page);
391
- de = (ext2_dirent *) kaddr;
392
- kaddr += ext2_last_byte(dir, n) - reclen;
393
- while ((char *) de <= kaddr) {
394
- if (de->rec_len == 0) {
395
- ext2_error(dir->i_sb, __func__,
396
- "zero-length directory entry");
397
- ext2_put_page(page);
398
- goto out;
399
- }
400
- if (ext2_match (namelen, name, de))
401
- goto found;
402
- de = ext2_next_entry(de);
364
+ page = ext2_get_page(dir, n, 0);
365
+ if (IS_ERR(page))
366
+ return ERR_CAST(page);
367
+
368
+ kaddr = page_address(page);
369
+ de = (ext2_dirent *) kaddr;
370
+ kaddr += ext2_last_byte(dir, n) - reclen;
371
+ while ((char *) de <= kaddr) {
372
+ if (de->rec_len == 0) {
373
+ ext2_error(dir->i_sb, __func__,
374
+ "zero-length directory entry");
375
+ ext2_put_page(page);
376
+ goto out;
403377 }
404
- ext2_put_page(page);
405
- } else
406
- dir_has_error = 1;
378
+ if (ext2_match(namelen, name, de))
379
+ goto found;
380
+ de = ext2_next_entry(de);
381
+ }
382
+ ext2_put_page(page);
407383
408384 if (++n >= npages)
409385 n = 0;
....@@ -417,7 +393,7 @@
417393 }
418394 } while (n != start);
419395 out:
420
- return NULL;
396
+ return ERR_PTR(-ENOENT);
421397
422398 found:
423399 *res_page = page;
....@@ -437,18 +413,18 @@
437413 return de;
438414 }
439415
440
-ino_t ext2_inode_by_name(struct inode *dir, const struct qstr *child)
416
+int ext2_inode_by_name(struct inode *dir, const struct qstr *child, ino_t *ino)
441417 {
442
- ino_t res = 0;
443418 struct ext2_dir_entry_2 *de;
444419 struct page *page;
445420
446
- de = ext2_find_entry (dir, child, &page);
447
- if (de) {
448
- res = le32_to_cpu(de->inode);
449
- ext2_put_page(page);
450
- }
451
- return res;
421
+ de = ext2_find_entry(dir, child, &page);
422
+ if (IS_ERR(de))
423
+ return PTR_ERR(de);
424
+
425
+ *ino = le32_to_cpu(de->inode);
426
+ ext2_put_page(page);
427
+ return 0;
452428 }
453429
454430 static int ext2_prepare_chunk(struct page *page, loff_t pos, unsigned len)