]>
Commit | Line | Data |
---|---|---|
e9688c1d | 1 | /* |
da23017d NS |
2 | * Copyright (c) 1995, 2001-2002, 2005 Silicon Graphics, Inc. |
3 | * All Rights Reserved. | |
7c49c48b | 4 | * |
da23017d NS |
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 | |
7c49c48b DR |
7 | * as published by the Free Software Foundation. |
8 | * | |
da23017d NS |
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. | |
7c49c48b | 13 | * |
da23017d NS |
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 | |
e9688c1d NS |
17 | */ |
18 | ||
dcabd4e7 | 19 | #include "platform_defs.h" |
6b803e5a CH |
20 | #include "xfs.h" |
21 | #include "handle.h" | |
22 | #include "jdm.h" | |
23 | #include "parent.h" | |
e9688c1d NS |
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 | ||
a3cbe7cd | 31 | /* private file handle - for use by open_by_fshandle */ |
e9688c1d NS |
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 */ | |
14f8b681 | 39 | uint32_t fh_gen; /* generation count */ |
e9688c1d NS |
40 | xfs_ino_t fh_ino; /* 64 bit ino */ |
41 | } filehandle_t; | |
42 | ||
89184fbc | 43 | |
e9688c1d NS |
44 | static void |
45 | jdm_fill_filehandle( filehandle_t *handlep, | |
89184fbc | 46 | fshandle_t *fshandlep, |
e9688c1d NS |
47 | xfs_bstat_t *statp ) |
48 | { | |
49 | handlep->fh_fshandle = *fshandlep; | |
50 | handlep->fh_sz_following = FILEHANDLE_SZ_FOLLOWING; | |
dab9b8d6 | 51 | memset(handlep->fh_pad, 0, FILEHANDLE_SZ_PAD); |
e9688c1d NS |
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; | |
dfc130f3 | 61 | char resolved[MAXPATHLEN]; |
e9688c1d NS |
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 | ||
5e656dbb | 74 | fshandlep = NULL; /* for lint */ |
e9688c1d | 75 | fshandlesz = sizeof( *fshandlep ); |
dfc130f3 RC |
76 | |
77 | if (!realpath( mntpnt, resolved )) | |
78 | return NULL; | |
79 | ||
e9688c1d NS |
80 | if (path_to_fshandle( resolved, ( void ** )&fshandlep, &fshandlesz )) |
81 | return NULL; | |
dfc130f3 | 82 | |
e9688c1d | 83 | assert( fshandlesz == sizeof( *fshandlep )); |
dfc130f3 | 84 | |
e9688c1d NS |
85 | return ( jdm_fshandle_t * )fshandlep; |
86 | } | |
87 | ||
89184fbc AG |
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 | ||
e9688c1d NS |
112 | intgen_t |
113 | jdm_open( jdm_fshandle_t *fshp, xfs_bstat_t *statp, intgen_t oflags ) | |
114 | { | |
0c2a7d46 | 115 | fshandle_t *fshandlep = ( fshandle_t * )fshp; |
e9688c1d NS |
116 | filehandle_t filehandle; |
117 | intgen_t fd; | |
118 | ||
119 | jdm_fill_filehandle( &filehandle, fshandlep, statp ); | |
a3cbe7cd | 120 | fd = open_by_fshandle( ( void * )&filehandle, |
e9688c1d NS |
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 | { | |
0c2a7d46 | 131 | fshandle_t *fshandlep = ( fshandle_t * )fshp; |
e9688c1d NS |
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 | } | |
14290264 NS |
142 | |
143 | int | |
144 | jdm_attr_multi( jdm_fshandle_t *fshp, | |
145 | xfs_bstat_t *statp, | |
146 | char *bufp, int rtrvcnt, int flags) | |
147 | { | |
0c2a7d46 | 148 | fshandle_t *fshandlep = ( fshandle_t * )fshp; |
14290264 NS |
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 | { | |
0c2a7d46 | 166 | fshandle_t *fshandlep = ( fshandle_t * )fshp; |
14290264 NS |
167 | filehandle_t filehandle; |
168 | int rval; | |
169 | ||
aa23a327 | 170 | /* prevent needless EINVAL from the kernel */ |
54e724c0 JT |
171 | if (bufsz > XFS_XATTR_LIST_MAX) |
172 | bufsz = XFS_XATTR_LIST_MAX; | |
aa23a327 | 173 | |
14290264 NS |
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 | } | |
258b00ea TS |
180 | |
181 | int | |
60ac13e8 | 182 | jdm_parents( jdm_fshandle_t *fshp, |
258b00ea TS |
183 | xfs_bstat_t *statp, |
184 | parent_t *bufp, size_t bufsz, | |
60ac13e8 | 185 | unsigned int *count) |
258b00ea | 186 | { |
258b00ea TS |
187 | errno = EOPNOTSUPP; |
188 | return -1; | |
258b00ea TS |
189 | } |
190 | ||
191 | int | |
60ac13e8 | 192 | jdm_parentpaths( jdm_fshandle_t *fshp, |
258b00ea TS |
193 | xfs_bstat_t *statp, |
194 | parent_t *bufp, size_t bufsz, | |
60ac13e8 | 195 | unsigned int *count) |
258b00ea | 196 | { |
258b00ea TS |
197 | errno = EOPNOTSUPP; |
198 | return -1; | |
258b00ea | 199 | } |