2 * libhfs - library for reading and writing Macintosh HFS volumes
3 * Copyright (C) 1996-1998 Robert Leslie
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20 * $Id: file.c,v 1.9 1998/11/02 22:08:59 rob Exp $
32 * DESCRIPTION: initialize file structure
34 void f_init(hfsfile *file, hfsvol *vol, long cnid, const char *name)
41 strcpy(file->name, name);
43 file->cat.cdrType = cdrFilRec;
44 file->cat.cdrResrv2 = 0;
46 file->cat.u.fil.filFlags = 0;
47 file->cat.u.fil.filTyp = 0;
49 file->cat.u.fil.filUsrWds.fdType = 0;
50 file->cat.u.fil.filUsrWds.fdCreator = 0;
51 file->cat.u.fil.filUsrWds.fdFlags = 0;
52 file->cat.u.fil.filUsrWds.fdLocation.v = 0;
53 file->cat.u.fil.filUsrWds.fdLocation.h = 0;
54 file->cat.u.fil.filUsrWds.fdFldr = 0;
56 file->cat.u.fil.filFlNum = cnid;
57 file->cat.u.fil.filStBlk = 0;
58 file->cat.u.fil.filLgLen = 0;
59 file->cat.u.fil.filPyLen = 0;
60 file->cat.u.fil.filRStBlk = 0;
61 file->cat.u.fil.filRLgLen = 0;
62 file->cat.u.fil.filRPyLen = 0;
63 file->cat.u.fil.filCrDat = 0;
64 file->cat.u.fil.filMdDat = 0;
65 file->cat.u.fil.filBkDat = 0;
67 file->cat.u.fil.filFndrInfo.fdIconID = 0;
68 for (i = 0; i < 4; ++i)
69 file->cat.u.fil.filFndrInfo.fdUnused[i] = 0;
70 file->cat.u.fil.filFndrInfo.fdComment = 0;
71 file->cat.u.fil.filFndrInfo.fdPutAway = 0;
73 file->cat.u.fil.filClpSize = 0;
75 for (i = 0; i < 3; ++i)
77 file->cat.u.fil.filExtRec[i].xdrStABN = 0;
78 file->cat.u.fil.filExtRec[i].xdrNumABlks = 0;
80 file->cat.u.fil.filRExtRec[i].xdrStABN = 0;
81 file->cat.u.fil.filRExtRec[i].xdrNumABlks = 0;
84 file->cat.u.fil.filResrv = 0;
86 f_selectfork(file, fkData);
95 * NAME: file->selectfork()
96 * DESCRIPTION: choose a fork for file operations
98 void f_selectfork(hfsfile *file, int fork)
102 memcpy(&file->ext, fork == fkData ?
103 &file->cat.u.fil.filExtRec : &file->cat.u.fil.filRExtRec,
111 * NAME: file->getptrs()
112 * DESCRIPTION: make pointers to the current fork's lengths and extents
114 void f_getptrs(hfsfile *file, ExtDataRec **extrec,
115 unsigned long **lglen, unsigned long **pylen)
117 if (file->fork == fkData)
120 *extrec = &file->cat.u.fil.filExtRec;
122 *lglen = &file->cat.u.fil.filLgLen;
124 *pylen = &file->cat.u.fil.filPyLen;
129 *extrec = &file->cat.u.fil.filRExtRec;
131 *lglen = &file->cat.u.fil.filRLgLen;
133 *pylen = &file->cat.u.fil.filRPyLen;
138 * NAME: file->doblock()
139 * DESCRIPTION: read or write a numbered block from a file
141 int f_doblock(hfsfile *file, unsigned long num, block *bp,
142 int (*func)(hfsvol *, unsigned int, unsigned int, block *))
149 abnum = num / file->vol->lpa;
150 blnum = num % file->vol->lpa;
152 /* locate the appropriate extent record */
160 f_getptrs(file, &extrec, NULL, NULL);
162 fabn = file->fabn = 0;
163 memcpy(&file->ext, extrec, sizeof(ExtDataRec));
172 for (i = 0; i < 3; ++i)
174 n = file->ext[i].xdrNumABlks;
177 return func(file->vol, file->ext[i].xdrStABN + abnum, blnum, bp);
183 if (v_extsearch(file, fabn, &file->ext, NULL) <= 0)