2 * linux/fs/hfs/file_hdr.c
4 * Copyright (C) 1995-1997 Paul H. Hargrove
5 * This file may be distributed under the terms of the GNU General Public License.
7 * This file contains the file_ops and inode_ops for the metadata
8 * files under the AppleDouble and Netatalk representations.
10 * The source code distributions of Netatalk, versions 1.3.3b2 and
11 * 1.4b2, were used as a specification of the location and format of
12 * files used by Netatalk's afpd. No code from Netatalk appears in
13 * hfs_fs. hfs_fs is not a work ``derived'' from Netatalk in the
14 * sense of intellectual property law.
16 * "XXX" in a comment is a note to myself to consider changing something.
18 * In function preconditions the term "valid" applied to a pointer to
19 * a structure means that the pointer is non-NULL and the structure it
20 * points to has all fields initialized to consistent values.
22 * XXX: Note the reason that there is not bmap() for AppleDouble
23 * header files is that dynamic nature of their structure make it
24 * very difficult to safely mmap them. Maybe in the distant future
25 * I'll get bored enough to implement it.
29 #include <linux/hfs_fs_sb.h>
30 #include <linux/hfs_fs_i.h>
31 #include <linux/hfs_fs.h>
34 #define PRODOSI_FTYPE_DIR 0x0F
35 #define PRODOSI_FTYPE_TEXT 0x04
36 #define PRODOSI_FTYPE_8BIT 0xFF
37 #define PRODOSI_FTYPE_16BIT 0xB3
39 #define PRODOSI_AUXTYPE_DIR 0x0200
41 /*================ Forward declarations ================*/
42 static loff_t hdr_llseek(struct file *, loff_t, int);
43 static hfs_rwret_t hdr_read(struct file *, char *, hfs_rwarg_t, loff_t *);
44 static hfs_rwret_t hdr_write(struct file *, const char *,
45 hfs_rwarg_t, loff_t *);
46 /*================ Global variables ================*/
48 struct file_operations hfs_hdr_operations = {
55 struct inode_operations hfs_hdr_inode_operations = {
56 setattr: hfs_notify_change_hdr,
59 const struct hfs_hdr_layout hfs_dbl_fil_hdr_layout = {
60 __constant_htonl(HFS_DBL_MAGIC), /* magic */
61 __constant_htonl(HFS_HDR_VERSION_2), /* version */
64 {HFS_HDR_FNAME, offsetof(struct hfs_dbl_hdr, real_name), ~0},
65 {HFS_HDR_DATES, offsetof(struct hfs_dbl_hdr, create_time), 16},
66 {HFS_HDR_FINFO, offsetof(struct hfs_dbl_hdr, finderinfo), 32},
67 {HFS_HDR_MACI, offsetof(struct hfs_dbl_hdr, fileinfo), 4},
68 {HFS_HDR_DID, offsetof(struct hfs_dbl_hdr, cnid), 4},
69 {HFS_HDR_RSRC, HFS_DBL_HDR_LEN, ~0}
72 (struct hfs_hdr_descr *)&hfs_dbl_fil_hdr_layout.descr[0],
73 (struct hfs_hdr_descr *)&hfs_dbl_fil_hdr_layout.descr[1],
74 (struct hfs_hdr_descr *)&hfs_dbl_fil_hdr_layout.descr[2],
75 (struct hfs_hdr_descr *)&hfs_dbl_fil_hdr_layout.descr[3],
76 (struct hfs_hdr_descr *)&hfs_dbl_fil_hdr_layout.descr[4],
77 (struct hfs_hdr_descr *)&hfs_dbl_fil_hdr_layout.descr[5]
81 const struct hfs_hdr_layout hfs_dbl_dir_hdr_layout = {
82 __constant_htonl(HFS_DBL_MAGIC), /* magic */
83 __constant_htonl(HFS_HDR_VERSION_2), /* version */
86 {HFS_HDR_FNAME, offsetof(struct hfs_dbl_hdr, real_name), ~0},
87 {HFS_HDR_DATES, offsetof(struct hfs_dbl_hdr, create_time), 16},
88 {HFS_HDR_FINFO, offsetof(struct hfs_dbl_hdr, finderinfo), 32},
89 {HFS_HDR_MACI, offsetof(struct hfs_dbl_hdr, fileinfo), 4},
90 {HFS_HDR_DID, offsetof(struct hfs_dbl_hdr, cnid), 4}
93 (struct hfs_hdr_descr *)&hfs_dbl_dir_hdr_layout.descr[0],
94 (struct hfs_hdr_descr *)&hfs_dbl_dir_hdr_layout.descr[1],
95 (struct hfs_hdr_descr *)&hfs_dbl_dir_hdr_layout.descr[2],
96 (struct hfs_hdr_descr *)&hfs_dbl_dir_hdr_layout.descr[3],
97 (struct hfs_hdr_descr *)&hfs_dbl_dir_hdr_layout.descr[4]
101 const struct hfs_hdr_layout hfs_nat2_hdr_layout = {
102 __constant_htonl(HFS_DBL_MAGIC), /* magic */
103 __constant_htonl(HFS_HDR_VERSION_2), /* version */
106 {HFS_HDR_FNAME, offsetof(struct hfs_dbl_hdr, real_name), ~0},
107 {HFS_HDR_COMNT, offsetof(struct hfs_dbl_hdr, comment), 0},
108 {HFS_HDR_DATES, offsetof(struct hfs_dbl_hdr, create_time), 16},
109 {HFS_HDR_FINFO, offsetof(struct hfs_dbl_hdr, finderinfo), 32},
110 {HFS_HDR_AFPI, offsetof(struct hfs_dbl_hdr, fileinfo), 4},
111 {HFS_HDR_DID, offsetof(struct hfs_dbl_hdr, cnid), 4},
112 {HFS_HDR_SNAME, offsetof(struct hfs_dbl_hdr, short_name), ~0},
113 {HFS_HDR_PRODOSI, offsetof(struct hfs_dbl_hdr, prodosi), 8},
114 {HFS_HDR_RSRC, HFS_NAT_HDR_LEN, ~0}
117 (struct hfs_hdr_descr *)&hfs_nat_hdr_layout.descr[0],
118 (struct hfs_hdr_descr *)&hfs_nat_hdr_layout.descr[1],
119 (struct hfs_hdr_descr *)&hfs_nat_hdr_layout.descr[2],
120 (struct hfs_hdr_descr *)&hfs_nat_hdr_layout.descr[3],
121 (struct hfs_hdr_descr *)&hfs_nat_hdr_layout.descr[4],
122 (struct hfs_hdr_descr *)&hfs_nat_hdr_layout.descr[5],
123 (struct hfs_hdr_descr *)&hfs_nat_hdr_layout.descr[6],
124 (struct hfs_hdr_descr *)&hfs_nat_hdr_layout.descr[7],
125 (struct hfs_hdr_descr *)&hfs_nat_hdr_layout.descr[8]
129 const struct hfs_hdr_layout hfs_nat_hdr_layout = {
130 __constant_htonl(HFS_DBL_MAGIC), /* magic */
131 __constant_htonl(HFS_HDR_VERSION_1), /* version */
134 {HFS_HDR_FNAME, offsetof(struct hfs_dbl_hdr, real_name), ~0},
135 {HFS_HDR_COMNT, offsetof(struct hfs_dbl_hdr, comment), 0},
136 {HFS_HDR_OLDI, offsetof(struct hfs_dbl_hdr, create_time), 16},
137 {HFS_HDR_FINFO, offsetof(struct hfs_dbl_hdr, finderinfo), 32},
138 {HFS_HDR_RSRC, HFS_NAT_HDR_LEN, ~0},
141 (struct hfs_hdr_descr *)&hfs_nat_hdr_layout.descr[0],
142 (struct hfs_hdr_descr *)&hfs_nat_hdr_layout.descr[1],
143 (struct hfs_hdr_descr *)&hfs_nat_hdr_layout.descr[2],
144 (struct hfs_hdr_descr *)&hfs_nat_hdr_layout.descr[3],
145 (struct hfs_hdr_descr *)&hfs_nat_hdr_layout.descr[4]
149 /*================ File-local variables ================*/
151 static const char fstype[16] =
152 {'M','a','c','i','n','t','o','s','h',' ',' ',' ',' ',' ',' ',' '};
154 /*================ File-local data types ================*/
159 hfs_byte_t filler[16];
161 hfs_byte_t descrs[12*HFS_HDR_MAX];
162 } __attribute__((packed));
164 /*================ File-local functions ================*/
169 static int dlength(const struct hfs_hdr_descr *descr,
170 const struct hfs_cat_entry *entry)
172 hfs_u32 length = descr->length;
174 /* handle auto-sized entries */
178 if (entry->type == HFS_CDR_FIL) {
179 length = entry->u.file.data_fork.lsize;
186 if (entry->type == HFS_CDR_FIL) {
187 length = entry->u.file.rsrc_fork.lsize;
194 length = entry->key.CName.Len;
208 static void hdr_build_meta(struct hdr_hdr *meta,
209 const struct hfs_hdr_layout *layout,
210 const struct hfs_cat_entry *entry)
212 const struct hfs_hdr_descr *descr;
216 hfs_put_nl(layout->magic, meta->magic);
217 hfs_put_nl(layout->version, meta->version);
218 if (layout->version == htonl(HFS_HDR_VERSION_1)) {
219 memcpy(meta->filler, fstype, 16);
221 memset(meta->filler, 0, 16);
223 hfs_put_hs(layout->entries, meta->entries);
224 memset(meta->descrs, 0, sizeof(meta->descrs));
225 for (lcv = 0, descr = layout->descr, ptr = meta->descrs;
226 lcv < layout->entries; ++lcv, ++descr, ptr += 12) {
227 hfs_put_hl(descr->id, ptr);
228 hfs_put_hl(descr->offset, ptr + 4);
229 hfs_put_hl(dlength(descr, entry), ptr + 8);
236 static struct hfs_hdr_layout *dup_layout(const struct hfs_hdr_layout *old)
238 struct hfs_hdr_layout *new;
242 memcpy(new, old, sizeof(*new));
243 for (lcv = 0; lcv < new->entries; ++lcv) {
244 new->order[lcv] = (struct hfs_hdr_descr *)
245 ((char *)(new->order[lcv]) +
246 ((char *)new - (char *)old));
255 static inline void init_layout(struct hfs_hdr_layout *layout,
256 const hfs_byte_t *descrs)
258 struct hfs_hdr_descr **base, **p, **q, *tmp;
259 int lcv, entries = layout->entries;
261 for (lcv = 0; lcv < entries; ++lcv, descrs += 12) {
262 layout->order[lcv] = &layout->descr[lcv];
263 layout->descr[lcv].id = hfs_get_hl(descrs);
264 layout->descr[lcv].offset = hfs_get_hl(descrs + 4);
265 layout->descr[lcv].length = hfs_get_hl(descrs + 8);
267 for (lcv = layout->entries; lcv < HFS_HDR_MAX; ++lcv) {
268 layout->order[lcv] = NULL;
269 layout->descr[lcv].id = 0;
270 layout->descr[lcv].offset = 0;
271 layout->descr[lcv].length = 0;
274 /* Sort the 'order' array using an insertion sort */
275 base = &layout->order[0];
276 for (p = (base+1); p < (base+entries); ++p) {
278 while ((*q)->offset < (*(q-1))->offset) {
282 if (q == base) break;
290 static inline void adjust_forks(struct hfs_cat_entry *entry,
291 const struct hfs_hdr_layout *layout)
295 for (lcv = 0; lcv < layout->entries; ++lcv) {
296 const struct hfs_hdr_descr *descr = &layout->descr[lcv];
298 if ((descr->id == HFS_HDR_DATA) &&
299 (descr->length != entry->u.file.data_fork.lsize)) {
300 entry->u.file.data_fork.lsize = descr->length;
301 hfs_extent_adj(&entry->u.file.data_fork);
302 } else if ((descr->id == HFS_HDR_RSRC) &&
303 (descr->length != entry->u.file.rsrc_fork.lsize)) {
304 entry->u.file.rsrc_fork.lsize = descr->length;
305 hfs_extent_adj(&entry->u.file.rsrc_fork);
313 static void get_dates(const struct hfs_cat_entry *entry,
314 const struct inode *inode, hfs_u32 dates[3])
316 dates[0] = hfs_m_to_htime(entry->create_date);
317 dates[1] = hfs_m_to_htime(entry->modify_date);
318 dates[2] = hfs_m_to_htime(entry->backup_date);
324 static void set_dates(struct hfs_cat_entry *entry, struct inode *inode,
325 const hfs_u32 *dates)
329 tmp = hfs_h_to_mtime(dates[0]);
330 if (entry->create_date != tmp) {
331 entry->create_date = tmp;
332 hfs_cat_mark_dirty(entry);
334 tmp = hfs_h_to_mtime(dates[1]);
335 if (entry->modify_date != tmp) {
336 entry->modify_date = tmp;
337 inode->i_ctime = inode->i_atime = inode->i_mtime =
338 hfs_h_to_utime(dates[1]);
339 hfs_cat_mark_dirty(entry);
341 tmp = hfs_h_to_mtime(dates[2]);
342 if (entry->backup_date != tmp) {
343 entry->backup_date = tmp;
344 hfs_cat_mark_dirty(entry);
348 loff_t hdr_llseek(struct file *file, loff_t offset, int origin)
354 offset += file->f_dentry->d_inode->i_size;
357 offset += file->f_pos;
360 if (offset>=0 && offset<file->f_dentry->d_inode->i_size) {
361 if (offset != file->f_pos) {
362 file->f_pos = offset;
364 file->f_version = ++event;
374 * This is the read field in the inode_operations structure for
375 * header files. The purpose is to transfer up to 'count' bytes
376 * from the file corresponding to 'inode', beginning at
377 * 'filp->offset' bytes into the file. The data is transferred to
378 * user-space at the address 'buf'. Returns the number of bytes
379 * successfully transferred.
381 /* XXX: what about the entry count changing on us? */
382 static hfs_rwret_t hdr_read(struct file * filp, char * buf,
383 hfs_rwarg_t count, loff_t *ppos)
385 struct inode *inode = filp->f_dentry->d_inode;
386 struct hfs_cat_entry *entry = HFS_I(inode)->entry;
387 const struct hfs_hdr_layout *layout;
388 off_t start, length, offset;
390 int left, lcv, read = 0;
392 if (!S_ISREG(inode->i_mode)) {
393 hfs_warn("hfs_hdr_read: mode = %07o\n",inode->i_mode);
397 if (HFS_I(inode)->layout) {
398 layout = HFS_I(inode)->layout;
400 layout = HFS_I(inode)->default_layout;
403 /* Adjust count to fit within the bounds of the file */
404 if (pos != (unsigned)pos || pos >= inode->i_size || count <= 0) {
406 } else if (count > inode->i_size - pos) {
407 count = inode->i_size - pos;
410 /* Handle the fixed-location portion */
411 length = sizeof(hfs_u32) + sizeof(hfs_u32) + 16 +
412 sizeof(hfs_u16) + layout->entries * (3 * sizeof(hfs_u32));
421 hdr_build_meta(&meta, layout, entry);
422 left -= copy_to_user(buf, ((char *)&meta) + pos, left);
432 /* Handle the actual data */
433 for (lcv = 0; count && (lcv < layout->entries); ++lcv) {
434 const struct hfs_hdr_descr *descr = layout->order[lcv];
435 struct hfs_fork *fork;
439 /* stop reading if we run out of descriptors early */
444 /* find start and length of this entry */
445 start = descr->offset;
446 length = dlength(descr, entry);
448 /* Skip to next entry if this one is empty or isn't needed */
449 if (!length || (pos >= start + length)) {
453 /* Pad with zeros to the start of this entry if needed */
459 clear_user(buf, left);
469 /* locate and/or construct the data for this entry */
474 fork = &entry->u.file.data_fork;
479 fork = &entry->u.file.rsrc_fork;
484 p = entry->key.CName.Name;
485 limit = entry->key.CName.Len;
490 get_dates(entry, inode, (hfs_u32 *)tmp);
491 if (descr->id == HFS_HDR_DATES) {
492 /* XXX: access date. hfsplus actually
494 memcpy(tmp + 12, tmp + 4, 4);
495 } else if ((entry->type == HFS_CDR_FIL) &&
496 (entry->u.file.flags & HFS_FIL_LOCK)) {
497 hfs_put_hl(HFS_AFP_RDONLY, tmp + 12);
499 hfs_put_nl(0, tmp + 12);
506 p = (char *)&entry->info;
511 /* XXX: this needs to do more mac->afp mappings */
513 if ((entry->type == HFS_CDR_FIL) &&
514 (entry->u.file.flags & HFS_FIL_LOCK)) {
515 hfs_put_hs(HFS_AFP_RDONLY, tmp + 2);
517 hfs_put_ns(0, tmp + 2);
523 case HFS_HDR_PRODOSI:
524 /* XXX: this needs to do mac->prodos translations */
527 hfs_put_ns(0, tmp); /* access */
528 hfs_put_ns(0, tmp); /* type */
529 hfs_put_nl(0, tmp); /* aux type */
537 if (entry->type == HFS_CDR_FIL) {
538 hfs_put_hs(entry->u.file.flags, tmp + 2);
540 hfs_put_ns(entry->u.dir.flags, tmp + 2);
547 /* if it's rootinfo, stick the next available did in
550 if (entry->cnid == htonl(HFS_ROOT_CNID)) {
551 struct hfs_mdb *mdb = entry->mdb;
552 const struct hfs_name *reserved =
553 HFS_SB(mdb->sys_mdb)->s_reserved2;
555 while (reserved->Len) {
556 if (hfs_streq(reserved->Name,
558 entry->key.CName.Name,
559 entry->key.CName.Len)) {
560 hfs_put_hl(mdb->next_id, tmp);
567 p = (char *) &entry->cnid;
576 /* limit the transfer to the available data
577 of to the stated length of the entry. */
578 if (length > limit) {
581 offset = pos - start;
582 left = length - offset;
590 /* transfer the data */
592 left -= copy_to_user(buf, p + offset, left);
594 left = hfs_do_read(inode, fork, offset, buf, left,
610 /* Pad the file out with zeros */
612 clear_user(buf, count);
619 inode->i_atime = CURRENT_TIME;
621 mark_inode_dirty(inode);
629 * This is the write() entry in the file_operations structure for
630 * header files. The purpose is to transfer up to 'count' bytes
631 * to the file corresponding to 'inode' beginning at offset
632 * '*ppos' from user-space at the address 'buf'.
633 * The return value is the number of bytes actually transferred.
635 static hfs_rwret_t hdr_write(struct file *filp, const char *buf,
636 hfs_rwarg_t count, loff_t *ppos)
638 struct inode *inode = filp->f_dentry->d_inode;
639 struct hfs_cat_entry *entry = HFS_I(inode)->entry;
640 struct hfs_hdr_layout *layout;
641 off_t start, length, offset;
642 int left, lcv, written = 0;
647 if (!S_ISREG(inode->i_mode)) {
648 hfs_warn("hfs_hdr_write: mode = %07o\n", inode->i_mode);
652 pos = (filp->f_flags & O_APPEND) ? inode->i_size : *ppos;
654 if (count <= 0 || pos != (unsigned)pos) {
658 if (!HFS_I(inode)->layout) {
659 HFS_I(inode)->layout = dup_layout(HFS_I(inode)->default_layout);
661 layout = HFS_I(inode)->layout;
663 /* Handle the 'magic', 'version', 'filler' and 'entries' fields */
664 length = sizeof(hfs_u32) + sizeof(hfs_u32) + 16 + sizeof(hfs_u16);
666 hdr_build_meta(&meta, layout, entry);
674 left -= copy_from_user(((char *)&meta) + pos, buf, left);
675 layout->magic = hfs_get_nl(meta.magic);
676 layout->version = hfs_get_nl(meta.version);
677 layout->entries = hfs_get_hs(meta.entries);
678 if (layout->entries > HFS_HDR_MAX) {
679 /* XXX: should allocate slots dynamically */
680 hfs_warn("hfs_hdr_write: TRUNCATING TO %d "
681 "DESCRIPTORS\n", HFS_HDR_MAX);
682 layout->entries = HFS_HDR_MAX;
694 /* We know for certain how many entries we have, so process them */
695 length += layout->entries * 3 * sizeof(hfs_u32);
698 hdr_build_meta(&meta, layout, entry);
706 left -= copy_from_user(((char *)&meta) + pos, buf, left);
707 init_layout(layout, meta.descrs);
714 /* Handle possible size changes for the forks */
715 if (entry->type == HFS_CDR_FIL) {
716 adjust_forks(entry, layout);
717 hfs_cat_mark_dirty(entry);
721 /* Handle the actual data */
722 for (lcv = 0; count && (lcv < layout->entries); ++lcv) {
723 struct hfs_hdr_descr *descr = layout->order[lcv];
724 struct hfs_fork *fork;
728 /* stop writing if we run out of descriptors early */
733 /* find start and length of this entry */
734 start = descr->offset;
735 if ((descr->id == HFS_HDR_DATA) ||
736 (descr->id == HFS_HDR_RSRC)) {
737 if (entry->type == HFS_CDR_FIL) {
738 length = 0x7fffffff - start;
743 length = dlength(descr, entry);
746 /* Trim length to avoid overlap with the next entry */
747 if (layout->order[lcv+1] &&
748 ((start + length) > layout->order[lcv+1]->offset)) {
749 length = layout->order[lcv+1]->offset - start;
752 /* Skip to next entry if this one is empty or isn't needed */
753 if (!length || (pos >= start + length)) {
757 /* Skip any padding that may exist between entries */
772 /* locate and/or construct the data for this entry */
778 /* Can't yet write to the data fork via a header file, since there is the
779 * possibility to write via the data file, and the only locking is at the
782 fork = &entry->u.file.data_fork;
790 fork = &entry->u.file.rsrc_fork;
796 get_dates(entry, inode, (hfs_u32 *)tmp);
797 if (descr->id == HFS_HDR_DATES) {
798 memcpy(tmp + 12, tmp + 4, 4);
799 } else if ((entry->type == HFS_CDR_FIL) &&
800 (entry->u.file.flags & HFS_FIL_LOCK)) {
801 hfs_put_hl(HFS_AFP_RDONLY, tmp + 12);
803 hfs_put_nl(0, tmp + 12);
810 p = (char *)&entry->info;
816 if ((entry->type == HFS_CDR_FIL) &&
817 (entry->u.file.flags & HFS_FIL_LOCK)) {
818 hfs_put_hs(HFS_AFP_RDONLY, tmp + 2);
820 hfs_put_ns(0, tmp + 2);
826 case HFS_HDR_PRODOSI:
827 /* XXX: this needs to do mac->prodos translations */
830 hfs_put_ns(0, tmp); /* access */
831 hfs_put_ns(0, tmp); /* type */
832 hfs_put_nl(0, tmp); /* aux type */
840 if (entry->type == HFS_CDR_FIL) {
841 hfs_put_hs(entry->u.file.flags, tmp + 2);
843 hfs_put_ns(entry->u.dir.flags, tmp + 2);
849 case HFS_HDR_FNAME: /* Can't rename a file this way */
850 case HFS_HDR_DID: /* can't specify a did this way */
855 /* limit the transfer to the available data
856 of to the stated length of the entry. */
857 if (length > limit) {
860 offset = pos - start;
861 left = length - offset;
869 /* transfer the data from user space */
871 left -= copy_from_user(p + offset, buf, left);
873 left = hfs_do_write(inode, fork, offset, buf, left);
876 /* process the data */
879 set_dates(entry, inode, (hfs_u32 *)tmp);
880 if (entry->type == HFS_CDR_FIL) {
881 hfs_u8 new_flags = entry->u.file.flags;
883 if (hfs_get_nl(tmp+12) & htonl(HFS_AFP_WRI)) {
884 new_flags |= HFS_FIL_LOCK;
886 new_flags &= ~HFS_FIL_LOCK;
889 if (new_flags != entry->u.file.flags) {
890 entry->u.file.flags = new_flags;
891 hfs_cat_mark_dirty(entry);
892 hfs_file_fix_mode(entry);
898 set_dates(entry, inode, (hfs_u32 *)tmp);
902 hfs_cat_mark_dirty(entry);
906 if (entry->type == HFS_CDR_DIR) {
907 hfs_u16 new_flags = hfs_get_ns(tmp + 2);
909 if (entry->u.dir.flags != new_flags) {
910 entry->u.dir.flags = new_flags;
911 hfs_cat_mark_dirty(entry);
914 hfs_u8 new_flags = tmp[3];
915 hfs_u8 changed = entry->u.file.flags^new_flags;
918 entry->u.file.flags = new_flags;
919 hfs_cat_mark_dirty(entry);
920 if (changed & HFS_FIL_LOCK) {
921 hfs_file_fix_mode(entry);
935 } else if (fork->lsize > descr->length) {
936 descr->length = fork->lsize;
940 case HFS_HDR_FNAME: /* Can't rename a file this way */
941 case HFS_HDR_DID: /* Can't specify a did this way */
942 case HFS_HDR_PRODOSI: /* not implemented yet */
943 case HFS_HDR_AFPI: /* ditto */
954 /* Skip any padding at the end */
963 if (pos > inode->i_size)
965 inode->i_mtime = inode->i_atime = CURRENT_TIME;
966 mark_inode_dirty(inode);
974 * This is the truncate field in the inode_operations structure for
975 * header files. The purpose is to allocate or release blocks as needed
976 * to satisfy a change in file length.
978 void hdr_truncate(struct inode *inode, size_t size)
980 struct hfs_cat_entry *entry = HFS_I(inode)->entry;
981 struct hfs_hdr_layout *layout;
984 inode->i_size = size;
985 if (!HFS_I(inode)->layout) {
986 HFS_I(inode)->layout = dup_layout(HFS_I(inode)->default_layout);
988 layout = HFS_I(inode)->layout;
990 last = layout->entries - 1;
991 for (lcv = 0; lcv <= last; ++lcv) {
992 struct hfs_hdr_descr *descr = layout->order[lcv];
993 struct hfs_fork *fork;
1000 if (descr->id == HFS_HDR_RSRC) {
1001 fork = &entry->u.file.rsrc_fork;
1003 /* Can't yet truncate the data fork via a header file, since there is the
1004 * possibility to truncate via the data file, and the only locking is at
1007 } else if (descr->id == HFS_HDR_DATA) {
1008 fork = &entry->u.file.data_fork;
1014 offset = descr->offset;
1016 if ((lcv != last) && ((offset + descr->length) <= size)) {
1020 if (offset < size) {
1021 descr->length = size - offset;
1025 if (fork->lsize != descr->length) {
1026 fork->lsize = descr->length;
1027 hfs_extent_adj(fork);
1028 hfs_cat_mark_dirty(entry);