]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - libhandle/jdm.c
e3ca789f74bb574df6c74677434b585f298611e2
[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 <xfs/libxfs.h>
20
21 /* attributes.h (purposefully) unavailable to xfsprogs, make do */
22 struct attrlist_cursor { __u32 opaque[4]; };
23
24 #include <xfs/handle.h>
25 #include <xfs/jdm.h>
26
27 /* internal fshandle - typecast to a void for external use */
28 #define FSHANDLE_SZ 8
29 typedef struct fshandle {
30 char fsh_space[FSHANDLE_SZ];
31 } fshandle_t;
32
33 /* private file handle - for use by open_by_fshandle */
34 #define FILEHANDLE_SZ 24
35 #define FILEHANDLE_SZ_FOLLOWING 14
36 #define FILEHANDLE_SZ_PAD 2
37 typedef struct filehandle {
38 fshandle_t fh_fshandle; /* handle of fs containing this inode */
39 int16_t fh_sz_following; /* bytes in handle after this member */
40 char fh_pad[FILEHANDLE_SZ_PAD]; /* padding, must be zeroed */
41 __uint32_t fh_gen; /* generation count */
42 xfs_ino_t fh_ino; /* 64 bit ino */
43 } filehandle_t;
44
45
46 static void
47 jdm_fill_filehandle( filehandle_t *handlep,
48 fshandle_t *fshandlep,
49 xfs_bstat_t *statp )
50 {
51 handlep->fh_fshandle = *fshandlep;
52 handlep->fh_sz_following = FILEHANDLE_SZ_FOLLOWING;
53 bzero(handlep->fh_pad, FILEHANDLE_SZ_PAD);
54 handlep->fh_gen = statp->bs_gen;
55 handlep->fh_ino = statp->bs_ino;
56 }
57
58 jdm_fshandle_t *
59 jdm_getfshandle( char *mntpnt )
60 {
61 fshandle_t *fshandlep;
62 size_t fshandlesz;
63 char resolved[MAXPATHLEN];
64
65 /* sanity checks */
66 ASSERT( sizeof( fshandle_t ) == FSHANDLE_SZ );
67 ASSERT( sizeof( filehandle_t ) == FILEHANDLE_SZ );
68 ASSERT( sizeof( filehandle_t )
69 -
70 offsetofmember( filehandle_t, fh_pad )
71 ==
72 FILEHANDLE_SZ_FOLLOWING );
73 ASSERT( sizeofmember( filehandle_t, fh_pad ) == FILEHANDLE_SZ_PAD );
74 ASSERT( FILEHANDLE_SZ_PAD == sizeof( int16_t ));
75
76 fshandlep = 0; /* for lint */
77 fshandlesz = sizeof( *fshandlep );
78
79 if (!realpath( mntpnt, resolved ))
80 return NULL;
81
82 if (path_to_fshandle( resolved, ( void ** )&fshandlep, &fshandlesz ))
83 return NULL;
84
85 assert( fshandlesz == sizeof( *fshandlep ));
86
87 return ( jdm_fshandle_t * )fshandlep;
88 }
89
90
91 /* externally visible functions */
92
93 void
94 jdm_new_filehandle( jdm_filehandle_t **handlep,
95 size_t *hlen,
96 jdm_fshandle_t *fshandlep,
97 xfs_bstat_t *statp)
98 {
99 /* allocate and fill filehandle */
100 *hlen = sizeof(filehandle_t);
101 *handlep = (filehandle_t *) malloc(*hlen);
102
103 if (*handlep)
104 jdm_fill_filehandle(*handlep, (fshandle_t *) fshandlep, statp);
105 }
106
107 /* ARGSUSED */
108 void
109 jdm_delete_filehandle( jdm_filehandle_t *handlep, size_t hlen )
110 {
111 free(handlep);
112 }
113
114 intgen_t
115 jdm_open( jdm_fshandle_t *fshp, xfs_bstat_t *statp, intgen_t oflags )
116 {
117 register fshandle_t *fshandlep = ( fshandle_t * )fshp;
118 filehandle_t filehandle;
119 intgen_t fd;
120
121 jdm_fill_filehandle( &filehandle, fshandlep, statp );
122 fd = open_by_fshandle( ( void * )&filehandle,
123 sizeof( filehandle ),
124 oflags );
125 return fd;
126 }
127
128 intgen_t
129 jdm_readlink( jdm_fshandle_t *fshp,
130 xfs_bstat_t *statp,
131 char *bufp, size_t bufsz )
132 {
133 register fshandle_t *fshandlep = ( fshandle_t * )fshp;
134 filehandle_t filehandle;
135 intgen_t rval;
136
137 jdm_fill_filehandle( &filehandle, fshandlep, statp );
138 rval = readlink_by_handle( ( void * )&filehandle,
139 sizeof( filehandle ),
140 ( void * )bufp,
141 bufsz );
142 return rval;
143 }
144
145 int
146 jdm_attr_multi( jdm_fshandle_t *fshp,
147 xfs_bstat_t *statp,
148 char *bufp, int rtrvcnt, int flags)
149 {
150 register fshandle_t *fshandlep = ( fshandle_t * )fshp;
151 filehandle_t filehandle;
152 int rval;
153
154 jdm_fill_filehandle( &filehandle, fshandlep, statp );
155 rval = attr_multi_by_handle ( ( void * )&filehandle,
156 sizeof( filehandle ),
157 (void *) bufp,
158 rtrvcnt, flags);
159 return rval;
160 }
161
162 int
163 jdm_attr_list( jdm_fshandle_t *fshp,
164 xfs_bstat_t *statp,
165 char *bufp, size_t bufsz, int flags,
166 struct attrlist_cursor *cursor)
167 {
168 register fshandle_t *fshandlep = ( fshandle_t * )fshp;
169 filehandle_t filehandle;
170 int rval;
171
172 jdm_fill_filehandle( &filehandle, fshandlep, statp );
173 rval = attr_list_by_handle (( void * )&filehandle,
174 sizeof( filehandle ),
175 bufp, bufsz, flags, cursor);
176 return rval;
177 }