hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/fs/hfsplus/inode.c
....@@ -187,11 +187,11 @@
187187 mode = be16_to_cpu(perms->mode);
188188
189189 i_uid_write(inode, be32_to_cpu(perms->owner));
190
- if (!i_uid_read(inode) && !mode)
190
+ if ((test_bit(HFSPLUS_SB_UID, &sbi->flags)) || (!i_uid_read(inode) && !mode))
191191 inode->i_uid = sbi->uid;
192192
193193 i_gid_write(inode, be32_to_cpu(perms->group));
194
- if (!i_gid_read(inode) && !mode)
194
+ if ((test_bit(HFSPLUS_SB_GID, &sbi->flags)) || (!i_gid_read(inode) && !mode))
195195 inode->i_gid = sbi->gid;
196196
197197 if (dir) {
....@@ -270,6 +270,26 @@
270270 return 0;
271271 }
272272
273
+int hfsplus_getattr(const struct path *path, struct kstat *stat,
274
+ u32 request_mask, unsigned int query_flags)
275
+{
276
+ struct inode *inode = d_inode(path->dentry);
277
+ struct hfsplus_inode_info *hip = HFSPLUS_I(inode);
278
+
279
+ if (inode->i_flags & S_APPEND)
280
+ stat->attributes |= STATX_ATTR_APPEND;
281
+ if (inode->i_flags & S_IMMUTABLE)
282
+ stat->attributes |= STATX_ATTR_IMMUTABLE;
283
+ if (hip->userflags & HFSPLUS_FLG_NODUMP)
284
+ stat->attributes |= STATX_ATTR_NODUMP;
285
+
286
+ stat->attributes_mask |= STATX_ATTR_APPEND | STATX_ATTR_IMMUTABLE |
287
+ STATX_ATTR_NODUMP;
288
+
289
+ generic_fillattr(inode, stat);
290
+ return 0;
291
+}
292
+
273293 int hfsplus_file_fsync(struct file *file, loff_t start, loff_t end,
274294 int datasync)
275295 {
....@@ -320,7 +340,7 @@
320340 }
321341
322342 if (!test_bit(HFSPLUS_SB_NOBARRIER, &sbi->flags))
323
- blkdev_issue_flush(inode->i_sb->s_bdev, GFP_KERNEL, NULL);
343
+ blkdev_issue_flush(inode->i_sb->s_bdev, GFP_KERNEL);
324344
325345 inode_unlock(inode);
326346
....@@ -329,6 +349,7 @@
329349
330350 static const struct inode_operations hfsplus_file_inode_operations = {
331351 .setattr = hfsplus_setattr,
352
+ .getattr = hfsplus_getattr,
332353 .listxattr = hfsplus_listxattr,
333354 };
334355
....@@ -476,16 +497,19 @@
476497 if (type == HFSPLUS_FOLDER) {
477498 struct hfsplus_cat_folder *folder = &entry.folder;
478499
479
- if (fd->entrylength < sizeof(struct hfsplus_cat_folder))
480
- /* panic? */;
500
+ if (fd->entrylength < sizeof(struct hfsplus_cat_folder)) {
501
+ pr_err("bad catalog folder entry\n");
502
+ res = -EIO;
503
+ goto out;
504
+ }
481505 hfs_bnode_read(fd->bnode, &entry, fd->entryoffset,
482506 sizeof(struct hfsplus_cat_folder));
483507 hfsplus_get_perms(inode, &folder->permissions, 1);
484508 set_nlink(inode, 1);
485509 inode->i_size = 2 + be32_to_cpu(folder->valence);
486
- inode->i_atime = timespec_to_timespec64(hfsp_mt2ut(folder->access_date));
487
- inode->i_mtime = timespec_to_timespec64(hfsp_mt2ut(folder->content_mod_date));
488
- inode->i_ctime = timespec_to_timespec64(hfsp_mt2ut(folder->attribute_mod_date));
510
+ inode->i_atime = hfsp_mt2ut(folder->access_date);
511
+ inode->i_mtime = hfsp_mt2ut(folder->content_mod_date);
512
+ inode->i_ctime = hfsp_mt2ut(folder->attribute_mod_date);
489513 HFSPLUS_I(inode)->create_date = folder->create_date;
490514 HFSPLUS_I(inode)->fs_blocks = 0;
491515 if (folder->flags & cpu_to_be16(HFSPLUS_HAS_FOLDER_COUNT)) {
....@@ -497,8 +521,11 @@
497521 } else if (type == HFSPLUS_FILE) {
498522 struct hfsplus_cat_file *file = &entry.file;
499523
500
- if (fd->entrylength < sizeof(struct hfsplus_cat_file))
501
- /* panic? */;
524
+ if (fd->entrylength < sizeof(struct hfsplus_cat_file)) {
525
+ pr_err("bad catalog file entry\n");
526
+ res = -EIO;
527
+ goto out;
528
+ }
502529 hfs_bnode_read(fd->bnode, &entry, fd->entryoffset,
503530 sizeof(struct hfsplus_cat_file));
504531
....@@ -521,14 +548,15 @@
521548 init_special_inode(inode, inode->i_mode,
522549 be32_to_cpu(file->permissions.dev));
523550 }
524
- inode->i_atime = timespec_to_timespec64(hfsp_mt2ut(file->access_date));
525
- inode->i_mtime = timespec_to_timespec64(hfsp_mt2ut(file->content_mod_date));
526
- inode->i_ctime = timespec_to_timespec64(hfsp_mt2ut(file->attribute_mod_date));
551
+ inode->i_atime = hfsp_mt2ut(file->access_date);
552
+ inode->i_mtime = hfsp_mt2ut(file->content_mod_date);
553
+ inode->i_ctime = hfsp_mt2ut(file->attribute_mod_date);
527554 HFSPLUS_I(inode)->create_date = file->create_date;
528555 } else {
529556 pr_err("bad catalog entry used to create inode\n");
530557 res = -EIO;
531558 }
559
+out:
532560 return res;
533561 }
534562
....@@ -537,6 +565,7 @@
537565 struct inode *main_inode = inode;
538566 struct hfs_find_data fd;
539567 hfsplus_cat_entry entry;
568
+ int res = 0;
540569
541570 if (HFSPLUS_IS_RSRC(inode))
542571 main_inode = HFSPLUS_I(inode)->rsrc_inode;
....@@ -555,8 +584,11 @@
555584 if (S_ISDIR(main_inode->i_mode)) {
556585 struct hfsplus_cat_folder *folder = &entry.folder;
557586
558
- if (fd.entrylength < sizeof(struct hfsplus_cat_folder))
559
- /* panic? */;
587
+ if (fd.entrylength < sizeof(struct hfsplus_cat_folder)) {
588
+ pr_err("bad catalog folder entry\n");
589
+ res = -EIO;
590
+ goto out;
591
+ }
560592 hfs_bnode_read(fd.bnode, &entry, fd.entryoffset,
561593 sizeof(struct hfsplus_cat_folder));
562594 /* simple node checks? */
....@@ -581,8 +613,11 @@
581613 } else {
582614 struct hfsplus_cat_file *file = &entry.file;
583615
584
- if (fd.entrylength < sizeof(struct hfsplus_cat_file))
585
- /* panic? */;
616
+ if (fd.entrylength < sizeof(struct hfsplus_cat_file)) {
617
+ pr_err("bad catalog file entry\n");
618
+ res = -EIO;
619
+ goto out;
620
+ }
586621 hfs_bnode_read(fd.bnode, &entry, fd.entryoffset,
587622 sizeof(struct hfsplus_cat_file));
588623 hfsplus_inode_write_fork(inode, &file->data_fork);
....@@ -603,5 +638,5 @@
603638 set_bit(HFSPLUS_I_CAT_DIRTY, &HFSPLUS_I(inode)->flags);
604639 out:
605640 hfs_find_exit(&fd);
606
- return 0;
641
+ return res;
607642 }