]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - libhandle/jdm.c
xfs: fix inobt magic number check
[thirdparty/xfsprogs-dev.git] / libhandle / jdm.c
1 /*
2 * Copyright (c) 1995, 2001-2002, 2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public License
7 * as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19 #include "platform_defs.h"
20 #include "xfs.h"
21 #include "handle.h"
22 #include "jdm.h"
23 #include "parent.h"
24
25 /* internal fshandle - typecast to a void for external use */
26 #define FSHANDLE_SZ 8
27 typedef struct fshandle {
28 char fsh_space[FSHANDLE_SZ];
29 } fshandle_t;
30
31 /* private file handle - for use by open_by_fshandle */
32 #define FILEHANDLE_SZ 24
33 #define FILEHANDLE_SZ_FOLLOWING 14
34 #define FILEHANDLE_SZ_PAD 2
35 typedef struct filehandle {
36 fshandle_t fh_fshandle; /* handle of fs containing this inode */
37 int16_t fh_sz_following; /* bytes in handle after this member */
38 char fh_pad[FILEHANDLE_SZ_PAD]; /* padding, must be zeroed */
39 uint32_t fh_gen; /* generation count */
40 xfs_ino_t fh_ino; /* 64 bit ino */
41 } filehandle_t;
42
43
44 static void
45 jdm_fill_filehandle( filehandle_t *handlep,
46 fshandle_t *fshandlep,
47 xfs_bstat_t *statp )
48 {
49 handlep->fh_fshandle = *fshandlep;
50 handlep->fh_sz_following = FILEHANDLE_SZ_FOLLOWING;
51 memset(handlep->fh_pad, 0, FILEHANDLE_SZ_PAD);
52 handlep->fh_gen = statp->bs_gen;
53 handlep->fh_ino = statp->bs_ino;
54 }
55
56 jdm_fshandle_t *
57 jdm_getfshandle( char *mntpnt )
58 {
59 fshandle_t *fshandlep;
60 size_t fshandlesz;
61 char resolved[MAXPATHLEN];
62
63 /* sanity checks */
64 ASSERT( sizeof( fshandle_t ) == FSHANDLE_SZ );
65 ASSERT( sizeof( filehandle_t ) == FILEHANDLE_SZ );
66 ASSERT( sizeof( filehandle_t )
67 -
68 offsetofmember( filehandle_t, fh_pad )
69 ==
70 FILEHANDLE_SZ_FOLLOWING );
71 ASSERT( sizeofmember( filehandle_t, fh_pad ) == FILEHANDLE_SZ_PAD );
72 ASSERT( FILEHANDLE_SZ_PAD == sizeof( int16_t ));
73
74 fshandlep = NULL; /* for lint */
75 fshandlesz = sizeof( *fshandlep );
76
77 if (!realpath( mntpnt, resolved ))
78 return NULL;
79
80 if (path_to_fshandle( resolved, ( void ** )&fshandlep, &fshandlesz ))
81 return NULL;
82
83 assert( fshandlesz == sizeof( *fshandlep ));
84
85 return ( jdm_fshandle_t * )fshandlep;
86 }
87
88
89 /* externally visible functions */
90
91 void
92 jdm_new_filehandle( jdm_filehandle_t **handlep,
93 size_t *hlen,
94 jdm_fshandle_t *fshandlep,
95 xfs_bstat_t *statp)
96 {
97 /* allocate and fill filehandle */
98 *hlen = sizeof(filehandle_t);
99 *handlep = (filehandle_t *) malloc(*hlen);
100
101 if (*handlep)
102 jdm_fill_filehandle(*handlep, (fshandle_t *) fshandlep, statp);
103 }
104
105 /* ARGSUSED */
106 void
107 jdm_delete_filehandle( jdm_filehandle_t *handlep, size_t hlen )
108 {
109 free(handlep);
110 }
111
112 intgen_t
113 jdm_open( jdm_fshandle_t *fshp, xfs_bstat_t *statp, intgen_t oflags )
114 {
115 fshandle_t *fshandlep = ( fshandle_t * )fshp;
116 filehandle_t filehandle;
117 intgen_t fd;
118
119 jdm_fill_filehandle( &filehandle, fshandlep, statp );
120 fd = open_by_fshandle( ( void * )&filehandle,
121 sizeof( filehandle ),
122 oflags );
123 return fd;
124 }
125
126 intgen_t
127 jdm_readlink( jdm_fshandle_t *fshp,
128 xfs_bstat_t *statp,
129 char *bufp, size_t bufsz )
130 {
131 fshandle_t *fshandlep = ( fshandle_t * )fshp;
132 filehandle_t filehandle;
133 intgen_t rval;
134
135 jdm_fill_filehandle( &filehandle, fshandlep, statp );
136 rval = readlink_by_handle( ( void * )&filehandle,
137 sizeof( filehandle ),
138 ( void * )bufp,
139 bufsz );
140 return rval;
141 }
142
143 int
144 jdm_attr_multi( jdm_fshandle_t *fshp,
145 xfs_bstat_t *statp,
146 char *bufp, int rtrvcnt, int flags)
147 {
148 fshandle_t *fshandlep = ( fshandle_t * )fshp;
149 filehandle_t filehandle;
150 int rval;
151
152 jdm_fill_filehandle( &filehandle, fshandlep, statp );
153 rval = attr_multi_by_handle ( ( void * )&filehandle,
154 sizeof( filehandle ),
155 (void *) bufp,
156 rtrvcnt, flags);
157 return rval;
158 }
159
160 int
161 jdm_attr_list( jdm_fshandle_t *fshp,
162 xfs_bstat_t *statp,
163 char *bufp, size_t bufsz, int flags,
164 struct attrlist_cursor *cursor)
165 {
166 fshandle_t *fshandlep = ( fshandle_t * )fshp;
167 filehandle_t filehandle;
168 int rval;
169
170 /* prevent needless EINVAL from the kernel */
171 if (bufsz > XFS_XATTR_LIST_MAX)
172 bufsz = XFS_XATTR_LIST_MAX;
173
174 jdm_fill_filehandle( &filehandle, fshandlep, statp );
175 rval = attr_list_by_handle (( void * )&filehandle,
176 sizeof( filehandle ),
177 bufp, bufsz, flags, cursor);
178 return rval;
179 }
180
181 int
182 jdm_parents( jdm_fshandle_t *fshp,
183 xfs_bstat_t *statp,
184 parent_t *bufp, size_t bufsz,
185 unsigned int *count)
186 {
187 errno = EOPNOTSUPP;
188 return -1;
189 }
190
191 int
192 jdm_parentpaths( jdm_fshandle_t *fshp,
193 xfs_bstat_t *statp,
194 parent_t *bufp, size_t bufsz,
195 unsigned int *count)
196 {
197 errno = EOPNOTSUPP;
198 return -1;
199 }