]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - libhandle/jdm.c
Merge whitespace changes over
[thirdparty/xfsprogs-dev.git] / libhandle / jdm.c
1 /*
2 * Copyright (c) 1995, 2001-2002 Silicon Graphics, Inc. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2.1 of the GNU Lesser General Public License
6 * as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 *
12 * Further, this software is distributed without any warranty that it is
13 * free of the rightful claim of any third person regarding infringement
14 * or the like. Any license provided herein, whether implied or
15 * otherwise, applies only to this software file. Patent licenses, if
16 * any, provided herein do not apply to combinations of this program with
17 * other software, or any other product whatsoever.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this program; if not, write the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307,
22 * USA.
23 *
24 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
25 * Mountain View, CA 94043, or:
26 *
27 * http://www.sgi.com
28 *
29 * For further information regarding this notice, see:
30 *
31 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
32 */
33
34 #include <libxfs.h>
35
36 /* attributes.h (purposefully) unavailable to xfsprogs, make do */
37 struct attrlist_cursor { __u32 opaque[4]; };
38
39 #include <handle.h>
40 #include <jdm.h>
41
42 /* internal fshandle - typecast to a void for external use */
43 #define FSHANDLE_SZ 8
44 typedef struct fshandle {
45 char fsh_space[FSHANDLE_SZ];
46 } fshandle_t;
47
48 /* private file handle - for use by open_by_handle */
49 #define FILEHANDLE_SZ 24
50 #define FILEHANDLE_SZ_FOLLOWING 14
51 #define FILEHANDLE_SZ_PAD 2
52 typedef struct filehandle {
53 fshandle_t fh_fshandle; /* handle of fs containing this inode */
54 int16_t fh_sz_following; /* bytes in handle after this member */
55 char fh_pad[FILEHANDLE_SZ_PAD]; /* padding, must be zeroed */
56 __uint32_t fh_gen; /* generation count */
57 xfs_ino_t fh_ino; /* 64 bit ino */
58 } filehandle_t;
59
60
61 static void
62 jdm_fill_filehandle( filehandle_t *handlep,
63 fshandle_t *fshandlep,
64 xfs_bstat_t *statp )
65 {
66 handlep->fh_fshandle = *fshandlep;
67 handlep->fh_sz_following = FILEHANDLE_SZ_FOLLOWING;
68 bzero(handlep->fh_pad, FILEHANDLE_SZ_PAD);
69 handlep->fh_gen = statp->bs_gen;
70 handlep->fh_ino = statp->bs_ino;
71 }
72
73 jdm_fshandle_t *
74 jdm_getfshandle( char *mntpnt )
75 {
76 fshandle_t *fshandlep;
77 size_t fshandlesz;
78 char resolved[MAXPATHLEN];
79
80 /* sanity checks */
81 ASSERT( sizeof( fshandle_t ) == FSHANDLE_SZ );
82 ASSERT( sizeof( filehandle_t ) == FILEHANDLE_SZ );
83 ASSERT( sizeof( filehandle_t )
84 -
85 offsetofmember( filehandle_t, fh_pad )
86 ==
87 FILEHANDLE_SZ_FOLLOWING );
88 ASSERT( sizeofmember( filehandle_t, fh_pad ) == FILEHANDLE_SZ_PAD );
89 ASSERT( FILEHANDLE_SZ_PAD == sizeof( int16_t ));
90
91 fshandlep = 0; /* for lint */
92 fshandlesz = sizeof( *fshandlep );
93
94 if (!realpath( mntpnt, resolved ))
95 return NULL;
96
97 if (path_to_fshandle( resolved, ( void ** )&fshandlep, &fshandlesz ))
98 return NULL;
99
100 assert( fshandlesz == sizeof( *fshandlep ));
101
102 return ( jdm_fshandle_t * )fshandlep;
103 }
104
105
106 /* externally visible functions */
107
108 void
109 jdm_new_filehandle( jdm_filehandle_t **handlep,
110 size_t *hlen,
111 jdm_fshandle_t *fshandlep,
112 xfs_bstat_t *statp)
113 {
114 /* allocate and fill filehandle */
115 *hlen = sizeof(filehandle_t);
116 *handlep = (filehandle_t *) malloc(*hlen);
117
118 if (*handlep)
119 jdm_fill_filehandle(*handlep, (fshandle_t *) fshandlep, statp);
120 }
121
122 /* ARGSUSED */
123 void
124 jdm_delete_filehandle( jdm_filehandle_t *handlep, size_t hlen )
125 {
126 free(handlep);
127 }
128
129 intgen_t
130 jdm_open( jdm_fshandle_t *fshp, xfs_bstat_t *statp, intgen_t oflags )
131 {
132 register fshandle_t *fshandlep = ( fshandle_t * )fshp;
133 filehandle_t filehandle;
134 intgen_t fd;
135
136 jdm_fill_filehandle( &filehandle, fshandlep, statp );
137 fd = open_by_handle( ( void * )&filehandle,
138 sizeof( filehandle ),
139 oflags );
140 return fd;
141 }
142
143 intgen_t
144 jdm_readlink( jdm_fshandle_t *fshp,
145 xfs_bstat_t *statp,
146 char *bufp, size_t bufsz )
147 {
148 register fshandle_t *fshandlep = ( fshandle_t * )fshp;
149 filehandle_t filehandle;
150 intgen_t rval;
151
152 jdm_fill_filehandle( &filehandle, fshandlep, statp );
153 rval = readlink_by_handle( ( void * )&filehandle,
154 sizeof( filehandle ),
155 ( void * )bufp,
156 bufsz );
157 return rval;
158 }
159
160 int
161 jdm_attr_multi( jdm_fshandle_t *fshp,
162 xfs_bstat_t *statp,
163 char *bufp, int rtrvcnt, int flags)
164 {
165 register fshandle_t *fshandlep = ( fshandle_t * )fshp;
166 filehandle_t filehandle;
167 int rval;
168
169 jdm_fill_filehandle( &filehandle, fshandlep, statp );
170 rval = attr_multi_by_handle ( ( void * )&filehandle,
171 sizeof( filehandle ),
172 (void *) bufp,
173 rtrvcnt, flags);
174 return rval;
175 }
176
177 int
178 jdm_attr_list( jdm_fshandle_t *fshp,
179 xfs_bstat_t *statp,
180 char *bufp, size_t bufsz, int flags,
181 struct attrlist_cursor *cursor)
182 {
183 register fshandle_t *fshandlep = ( fshandle_t * )fshp;
184 filehandle_t filehandle;
185 int rval;
186
187 jdm_fill_filehandle( &filehandle, fshandlep, statp );
188 rval = attr_list_by_handle (( void * )&filehandle,
189 sizeof( filehandle ),
190 bufp, bufsz, flags, cursor);
191 return rval;
192 }