1/*
2 * hfsutils - tools for reading and writing Macintosh HFS volumes
3 * Copyright (C) 1996, 1997 Robert Leslie
4 *
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.
9 *
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.
14 *
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., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20# include <time.h>
21
22#ifdef APPLE_HYB
23#include "hybrid.h"
24
25/* don't need device locking for mkhybrid */
26#ifndef NODEVLOCKS
27#define NODEVLOCKS
28#endif /* NODEVLOCKS */
29
30#endif /* APPLE_HYB */
31
32# define HFS_BLOCKSZ	512
33# define HFS_MAX_FLEN	31
34# define HFS_MAX_VLEN	27
35
36typedef struct _hfsvol_  hfsvol;
37typedef struct _hfsfile_ hfsfile;
38typedef struct _hfsdir_  hfsdir;
39
40typedef struct {
41  char name[HFS_MAX_VLEN + 1];	/* name of volume */
42  int flags;			/* volume flags */
43  unsigned long totbytes;	/* total bytes on volume */
44  unsigned long freebytes;	/* free bytes on volume */
45  time_t crdate;		/* volume creation date */
46  time_t mddate;		/* last volume modification date */
47} hfsvolent;
48
49typedef struct {
50  char name[HFS_MAX_FLEN + 1];	/* catalog name */
51  int flags;			/* bit flags */
52  long cnid;			/* catalog node id (CNID) */
53  long parid;			/* CNID of parent directory */
54  time_t crdate;		/* date of creation */
55  time_t mddate;		/* date of last modification */
56  unsigned long dsize;		/* size of data fork */
57  unsigned long rsize;		/* size of resource fork */
58  char type[5];			/* file type code (plus null) */
59  char creator[5];		/* file creator code (plus null) */
60  short fdflags;		/* Macintosh Finder flags */
61} hfsdirent;
62
63# define HFS_ISDIR		0x01
64# define HFS_ISLOCKED		0x02
65
66# define HFS_CNID_ROOTPAR	1
67# define HFS_CNID_ROOTDIR	2
68# define HFS_CNID_EXT		3
69# define HFS_CNID_CAT		4
70# define HFS_CNID_BADALLOC	5
71
72# define HFS_FNDR_ISONDESK		(1 <<  0)
73# define HFS_FNDR_COLOR			0x0e
74# define HFS_FNDR_COLORRESERVED		(1 <<  4)
75# define HFS_FNDR_REQUIRESSWITCHLAUNCH	(1 <<  5)
76# define HFS_FNDR_ISSHARED		(1 <<  6)
77# define HFS_FNDR_HASNOINITS		(1 <<  7)
78# define HFS_FNDR_HASBEENINITED		(1 <<  8)
79# define HFS_FNDR_RESERVED		(1 <<  9)
80# define HFS_FNDR_HASCUSTOMICON		(1 << 10)
81# define HFS_FNDR_ISSTATIONERY		(1 << 11)
82# define HFS_FNDR_NAMELOCKED		(1 << 12)
83# define HFS_FNDR_HASBUNDLE		(1 << 13)
84# define HFS_FNDR_ISINVISIBLE		(1 << 14)
85# define HFS_FNDR_ISALIAS		(1 << 15)
86
87extern char *hfs_error;
88extern unsigned char hfs_charorder[];
89
90#ifdef APPLE_HYB
91hfsvol *hfs_mount(hce_mem *, int, int);
92#else
93hfsvol *hfs_mount(char *, int, int);
94#endif /* APPLE_HYB */
95
96int hfs_flush(hfsvol *);
97void hfs_flushall(void);
98#ifdef APPLE_HYB
99int hfs_umount(hfsvol *, long);
100#else
101int hfs_umount(hfsvol *);
102#endif /* APPLE_HYB */
103void hfs_umountall(void);
104hfsvol *hfs_getvol(char *);
105void hfs_setvol(hfsvol *);
106
107int hfs_vstat(hfsvol *, hfsvolent *);
108#ifdef APPLE_HYB
109int hfs_format(hce_mem *, int, char *);
110#else
111int hfs_format(char *, int, char *);
112#endif /* APPLE_HYB */
113
114int hfs_chdir(hfsvol *, char *);
115long hfs_getcwd(hfsvol *);
116int hfs_setcwd(hfsvol *, long);
117int hfs_dirinfo(hfsvol *, long *, char *);
118
119hfsdir *hfs_opendir(hfsvol *, char *);
120int hfs_readdir(hfsdir *, hfsdirent *);
121int hfs_closedir(hfsdir *);
122
123hfsfile *hfs_open(hfsvol *, char *);
124int hfs_setfork(hfsfile *, int);
125int hfs_getfork(hfsfile *);
126long hfs_read(hfsfile *, void *, unsigned long);
127long hfs_write(hfsfile *, void *, unsigned long);
128int hfs_truncate(hfsfile *, unsigned long);
129long hfs_lseek(hfsfile *, long, int);
130#ifdef APPLE_HYB
131int hfs_close(hfsfile *, long, long);
132#else
133int hfs_close(hfsfile *);
134#endif /* APPLE_HYB */
135
136int hfs_stat(hfsvol *, char *, hfsdirent *);
137int hfs_fstat(hfsfile *, hfsdirent *);
138int hfs_setattr(hfsvol *, char *, hfsdirent *);
139int hfs_fsetattr(hfsfile *, hfsdirent *);
140
141int hfs_mkdir(hfsvol *, char *);
142int hfs_rmdir(hfsvol *, char *);
143
144int hfs_create(hfsvol *, char *, char *, char *);
145int hfs_delete(hfsvol *, char *);
146
147int hfs_rename(hfsvol *, char *, char *);
148
149#ifdef APPLE_HYB
150unsigned short hfs_get_drAllocPtr(hfsfile *);
151int hfs_set_drAllocPtr(hfsfile *, unsigned short, int size);
152#endif /* APPLE_HYB */
153