]>
git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - libhandle/jdm.c
e3ca789f74bb574df6c74677434b585f298611e2
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 <xfs/libxfs.h>
21 /* attributes.h (purposefully) unavailable to xfsprogs, make do */
22 struct attrlist_cursor
{ __u32 opaque
[4]; };
24 #include <xfs/handle.h>
27 /* internal fshandle - typecast to a void for external use */
29 typedef struct fshandle
{
30 char fsh_space
[FSHANDLE_SZ
];
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 */
47 jdm_fill_filehandle( filehandle_t
*handlep
,
48 fshandle_t
*fshandlep
,
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
;
59 jdm_getfshandle( char *mntpnt
)
61 fshandle_t
*fshandlep
;
63 char resolved
[MAXPATHLEN
];
66 ASSERT( sizeof( fshandle_t
) == FSHANDLE_SZ
);
67 ASSERT( sizeof( filehandle_t
) == FILEHANDLE_SZ
);
68 ASSERT( sizeof( filehandle_t
)
70 offsetofmember( filehandle_t
, fh_pad
)
72 FILEHANDLE_SZ_FOLLOWING
);
73 ASSERT( sizeofmember( filehandle_t
, fh_pad
) == FILEHANDLE_SZ_PAD
);
74 ASSERT( FILEHANDLE_SZ_PAD
== sizeof( int16_t ));
76 fshandlep
= 0; /* for lint */
77 fshandlesz
= sizeof( *fshandlep
);
79 if (!realpath( mntpnt
, resolved
))
82 if (path_to_fshandle( resolved
, ( void ** )&fshandlep
, &fshandlesz
))
85 assert( fshandlesz
== sizeof( *fshandlep
));
87 return ( jdm_fshandle_t
* )fshandlep
;
91 /* externally visible functions */
94 jdm_new_filehandle( jdm_filehandle_t
**handlep
,
96 jdm_fshandle_t
*fshandlep
,
99 /* allocate and fill filehandle */
100 *hlen
= sizeof(filehandle_t
);
101 *handlep
= (filehandle_t
*) malloc(*hlen
);
104 jdm_fill_filehandle(*handlep
, (fshandle_t
*) fshandlep
, statp
);
109 jdm_delete_filehandle( jdm_filehandle_t
*handlep
, size_t hlen
)
115 jdm_open( jdm_fshandle_t
*fshp
, xfs_bstat_t
*statp
, intgen_t oflags
)
117 register fshandle_t
*fshandlep
= ( fshandle_t
* )fshp
;
118 filehandle_t filehandle
;
121 jdm_fill_filehandle( &filehandle
, fshandlep
, statp
);
122 fd
= open_by_fshandle( ( void * )&filehandle
,
123 sizeof( filehandle
),
129 jdm_readlink( jdm_fshandle_t
*fshp
,
131 char *bufp
, size_t bufsz
)
133 register fshandle_t
*fshandlep
= ( fshandle_t
* )fshp
;
134 filehandle_t filehandle
;
137 jdm_fill_filehandle( &filehandle
, fshandlep
, statp
);
138 rval
= readlink_by_handle( ( void * )&filehandle
,
139 sizeof( filehandle
),
146 jdm_attr_multi( jdm_fshandle_t
*fshp
,
148 char *bufp
, int rtrvcnt
, int flags
)
150 register fshandle_t
*fshandlep
= ( fshandle_t
* )fshp
;
151 filehandle_t filehandle
;
154 jdm_fill_filehandle( &filehandle
, fshandlep
, statp
);
155 rval
= attr_multi_by_handle ( ( void * )&filehandle
,
156 sizeof( filehandle
),
163 jdm_attr_list( jdm_fshandle_t
*fshp
,
165 char *bufp
, size_t bufsz
, int flags
,
166 struct attrlist_cursor
*cursor
)
168 register fshandle_t
*fshandlep
= ( fshandle_t
* )fshp
;
169 filehandle_t filehandle
;
172 jdm_fill_filehandle( &filehandle
, fshandlep
, statp
);
173 rval
= attr_list_by_handle (( void * )&filehandle
,
174 sizeof( filehandle
),
175 bufp
, bufsz
, flags
, cursor
);