]>
git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - libhandle/jdm.c
2 * Copyright (c) 1995, 2001-2002, 2005 Silicon Graphics, Inc.
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.
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.
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
19 #include "platform_defs.h"
25 /* internal fshandle - typecast to a void for external use */
27 typedef struct fshandle
{
28 char fsh_space
[FSHANDLE_SZ
];
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 */
45 jdm_fill_filehandle( filehandle_t
*handlep
,
46 fshandle_t
*fshandlep
,
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
;
57 jdm_getfshandle( char *mntpnt
)
59 fshandle_t
*fshandlep
;
61 char resolved
[MAXPATHLEN
];
64 ASSERT( sizeof( fshandle_t
) == FSHANDLE_SZ
);
65 ASSERT( sizeof( filehandle_t
) == FILEHANDLE_SZ
);
66 ASSERT( sizeof( filehandle_t
)
68 offsetofmember( filehandle_t
, fh_pad
)
70 FILEHANDLE_SZ_FOLLOWING
);
71 ASSERT( sizeofmember( filehandle_t
, fh_pad
) == FILEHANDLE_SZ_PAD
);
72 ASSERT( FILEHANDLE_SZ_PAD
== sizeof( int16_t ));
74 fshandlep
= NULL
; /* for lint */
75 fshandlesz
= sizeof( *fshandlep
);
77 if (!realpath( mntpnt
, resolved
))
80 if (path_to_fshandle( resolved
, ( void ** )&fshandlep
, &fshandlesz
))
83 assert( fshandlesz
== sizeof( *fshandlep
));
85 return ( jdm_fshandle_t
* )fshandlep
;
89 /* externally visible functions */
92 jdm_new_filehandle( jdm_filehandle_t
**handlep
,
94 jdm_fshandle_t
*fshandlep
,
97 /* allocate and fill filehandle */
98 *hlen
= sizeof(filehandle_t
);
99 *handlep
= (filehandle_t
*) malloc(*hlen
);
102 jdm_fill_filehandle(*handlep
, (fshandle_t
*) fshandlep
, statp
);
107 jdm_delete_filehandle( jdm_filehandle_t
*handlep
, size_t hlen
)
113 jdm_open( jdm_fshandle_t
*fshp
, xfs_bstat_t
*statp
, intgen_t oflags
)
115 fshandle_t
*fshandlep
= ( fshandle_t
* )fshp
;
116 filehandle_t filehandle
;
119 jdm_fill_filehandle( &filehandle
, fshandlep
, statp
);
120 fd
= open_by_fshandle( ( void * )&filehandle
,
121 sizeof( filehandle
),
127 jdm_readlink( jdm_fshandle_t
*fshp
,
129 char *bufp
, size_t bufsz
)
131 fshandle_t
*fshandlep
= ( fshandle_t
* )fshp
;
132 filehandle_t filehandle
;
135 jdm_fill_filehandle( &filehandle
, fshandlep
, statp
);
136 rval
= readlink_by_handle( ( void * )&filehandle
,
137 sizeof( filehandle
),
144 jdm_attr_multi( jdm_fshandle_t
*fshp
,
146 char *bufp
, int rtrvcnt
, int flags
)
148 fshandle_t
*fshandlep
= ( fshandle_t
* )fshp
;
149 filehandle_t filehandle
;
152 jdm_fill_filehandle( &filehandle
, fshandlep
, statp
);
153 rval
= attr_multi_by_handle ( ( void * )&filehandle
,
154 sizeof( filehandle
),
161 jdm_attr_list( jdm_fshandle_t
*fshp
,
163 char *bufp
, size_t bufsz
, int flags
,
164 struct attrlist_cursor
*cursor
)
166 fshandle_t
*fshandlep
= ( fshandle_t
* )fshp
;
167 filehandle_t filehandle
;
170 /* prevent needless EINVAL from the kernel */
171 if (bufsz
> XFS_XATTR_LIST_MAX
)
172 bufsz
= XFS_XATTR_LIST_MAX
;
174 jdm_fill_filehandle( &filehandle
, fshandlep
, statp
);
175 rval
= attr_list_by_handle (( void * )&filehandle
,
176 sizeof( filehandle
),
177 bufp
, bufsz
, flags
, cursor
);
182 jdm_parents( jdm_fshandle_t
*fshp
,
184 parent_t
*bufp
, size_t bufsz
,
192 jdm_parentpaths( jdm_fshandle_t
*fshp
,
194 parent_t
*bufp
, size_t bufsz
,