xref: /dflybsd-src/sbin/jscan/subs.c (revision 4a9a2afb7b2d86ea674d59e2680245a8c92fbd6a)
1ce5e5ac4SMatthew Dillon /*
2ce5e5ac4SMatthew Dillon  * Copyright (c) 2004,2005 The DragonFly Project.  All rights reserved.
3ce5e5ac4SMatthew Dillon  *
4ce5e5ac4SMatthew Dillon  * This code is derived from software contributed to The DragonFly Project
5ce5e5ac4SMatthew Dillon  * by Matthew Dillon <dillon@backplane.com>
6ce5e5ac4SMatthew Dillon  *
7ce5e5ac4SMatthew Dillon  * Redistribution and use in source and binary forms, with or without
8ce5e5ac4SMatthew Dillon  * modification, are permitted provided that the following conditions
9ce5e5ac4SMatthew Dillon  * are met:
10ce5e5ac4SMatthew Dillon  *
11ce5e5ac4SMatthew Dillon  * 1. Redistributions of source code must retain the above copyright
12ce5e5ac4SMatthew Dillon  *    notice, this list of conditions and the following disclaimer.
13ce5e5ac4SMatthew Dillon  * 2. Redistributions in binary form must reproduce the above copyright
14ce5e5ac4SMatthew Dillon  *    notice, this list of conditions and the following disclaimer in
15ce5e5ac4SMatthew Dillon  *    the documentation and/or other materials provided with the
16ce5e5ac4SMatthew Dillon  *    distribution.
17ce5e5ac4SMatthew Dillon  * 3. Neither the name of The DragonFly Project nor the names of its
18ce5e5ac4SMatthew Dillon  *    contributors may be used to endorse or promote products derived
19ce5e5ac4SMatthew Dillon  *    from this software without specific, prior written permission.
20ce5e5ac4SMatthew Dillon  *
21ce5e5ac4SMatthew Dillon  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22ce5e5ac4SMatthew Dillon  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23ce5e5ac4SMatthew Dillon  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24ce5e5ac4SMatthew Dillon  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
25ce5e5ac4SMatthew Dillon  * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26ce5e5ac4SMatthew Dillon  * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
27ce5e5ac4SMatthew Dillon  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28ce5e5ac4SMatthew Dillon  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29ce5e5ac4SMatthew Dillon  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30ce5e5ac4SMatthew Dillon  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31ce5e5ac4SMatthew Dillon  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32ce5e5ac4SMatthew Dillon  * SUCH DAMAGE.
33ce5e5ac4SMatthew Dillon  */
34ce5e5ac4SMatthew Dillon 
35ce5e5ac4SMatthew Dillon #include "jscan.h"
36ce5e5ac4SMatthew Dillon 
37ce5e5ac4SMatthew Dillon void
jf_warn(struct jfile * jf,const char * ctl,...)38ce5e5ac4SMatthew Dillon jf_warn(struct jfile *jf, const char *ctl, ...)
39ce5e5ac4SMatthew Dillon {
40ce5e5ac4SMatthew Dillon     va_list va;
41ce5e5ac4SMatthew Dillon 
42*a276dc6bSMatthew Dillon     fprintf(stderr, "@0x%016jx ", (uintmax_t)jf->jf_pos);
43ce5e5ac4SMatthew Dillon     va_start(va, ctl);
44ce5e5ac4SMatthew Dillon     vfprintf(stderr, ctl, va);
45ce5e5ac4SMatthew Dillon     va_end(va);
46ce5e5ac4SMatthew Dillon     fprintf(stderr, "\n");
47ce5e5ac4SMatthew Dillon }
48ce5e5ac4SMatthew Dillon 
49ce5e5ac4SMatthew Dillon const char *
type_to_name(int16_t rectype)50ce5e5ac4SMatthew Dillon type_to_name(int16_t rectype)
51ce5e5ac4SMatthew Dillon {
52ce5e5ac4SMatthew Dillon     const char *str;
53ce5e5ac4SMatthew Dillon 
54ce5e5ac4SMatthew Dillon     switch((u_int16_t)rectype & ~JMASK_LAST) {
55ce5e5ac4SMatthew Dillon     case JLEAF_PAD:
56ce5e5ac4SMatthew Dillon 	str = "PAD";
57ce5e5ac4SMatthew Dillon 	break;
58ce5e5ac4SMatthew Dillon     case JLEAF_ABORT:
59ce5e5ac4SMatthew Dillon 	str = "ABORT";
60ce5e5ac4SMatthew Dillon 	break;
61ce5e5ac4SMatthew Dillon     case JTYPE_ASSOCIATE:
62ce5e5ac4SMatthew Dillon 	str = "ASSOCIATE";
63ce5e5ac4SMatthew Dillon 	break;
64ce5e5ac4SMatthew Dillon     case JTYPE_DISASSOCIATE:
65ce5e5ac4SMatthew Dillon 	str = "DISASSOCIATE";
66ce5e5ac4SMatthew Dillon 	break;
67ce5e5ac4SMatthew Dillon     case JTYPE_UNDO:
68ce5e5ac4SMatthew Dillon 	str = "UNDO";
69ce5e5ac4SMatthew Dillon 	break;
7036456e49SMatthew Dillon     case JTYPE_REDO:
7136456e49SMatthew Dillon 	str = "REDO";
7236456e49SMatthew Dillon 	break;
73ce5e5ac4SMatthew Dillon     case JTYPE_AUDIT:
74ce5e5ac4SMatthew Dillon 	str = "AUDIT";
75ce5e5ac4SMatthew Dillon 	break;
76ce5e5ac4SMatthew Dillon     case JTYPE_SETATTR:
77ce5e5ac4SMatthew Dillon 	str = "SETATTR";
78ce5e5ac4SMatthew Dillon 	break;
79ce5e5ac4SMatthew Dillon     case JTYPE_WRITE:
80ce5e5ac4SMatthew Dillon 	str = "WRITE";
81ce5e5ac4SMatthew Dillon 	break;
82ce5e5ac4SMatthew Dillon     case JTYPE_PUTPAGES:
83ce5e5ac4SMatthew Dillon 	str = "PUTPAGES";
84ce5e5ac4SMatthew Dillon 	break;
85ce5e5ac4SMatthew Dillon     case JTYPE_SETACL:
86ce5e5ac4SMatthew Dillon 	str = "SETACL";
87ce5e5ac4SMatthew Dillon 	break;
88ce5e5ac4SMatthew Dillon     case JTYPE_SETEXTATTR:
89ce5e5ac4SMatthew Dillon 	str = "SETEXTATTR";
90ce5e5ac4SMatthew Dillon 	break;
91ce5e5ac4SMatthew Dillon     case JTYPE_CREATE:
92ce5e5ac4SMatthew Dillon 	str = "CREATE";
93ce5e5ac4SMatthew Dillon 	break;
94ce5e5ac4SMatthew Dillon     case JTYPE_MKNOD:
95ce5e5ac4SMatthew Dillon 	str = "MKNOD";
96ce5e5ac4SMatthew Dillon 	break;
97ce5e5ac4SMatthew Dillon     case JTYPE_LINK:
98ce5e5ac4SMatthew Dillon 	str = "LINK";
99ce5e5ac4SMatthew Dillon 	break;
100ce5e5ac4SMatthew Dillon     case JTYPE_SYMLINK:
101ce5e5ac4SMatthew Dillon 	str = "SYMLINK";
102ce5e5ac4SMatthew Dillon 	break;
103ce5e5ac4SMatthew Dillon     case JTYPE_WHITEOUT:
104ce5e5ac4SMatthew Dillon 	str = "WHITEOUT";
105ce5e5ac4SMatthew Dillon 	break;
106ce5e5ac4SMatthew Dillon     case JTYPE_REMOVE:
107ce5e5ac4SMatthew Dillon 	str = "REMOVE";
108ce5e5ac4SMatthew Dillon 	break;
109ce5e5ac4SMatthew Dillon     case JTYPE_MKDIR:
110ce5e5ac4SMatthew Dillon 	str = "MKDIR";
111ce5e5ac4SMatthew Dillon 	break;
112ce5e5ac4SMatthew Dillon     case JTYPE_RMDIR:
113ce5e5ac4SMatthew Dillon 	str = "RMDIR";
114ce5e5ac4SMatthew Dillon 	break;
115ce5e5ac4SMatthew Dillon     case JTYPE_RENAME:
116ce5e5ac4SMatthew Dillon 	str = "RENAME";
117ce5e5ac4SMatthew Dillon 	break;
118ce5e5ac4SMatthew Dillon     case JTYPE_VATTR:
119ce5e5ac4SMatthew Dillon 	str = "vattr";
120ce5e5ac4SMatthew Dillon 	break;
121ce5e5ac4SMatthew Dillon     case JTYPE_CRED:
122ce5e5ac4SMatthew Dillon 	str = "cred";
123ce5e5ac4SMatthew Dillon 	break;
124ce5e5ac4SMatthew Dillon     case JLEAF_FILEDATA:
125ce5e5ac4SMatthew Dillon 	str = "filedata";
126ce5e5ac4SMatthew Dillon 	break;
127ce5e5ac4SMatthew Dillon     case JLEAF_PATH1:
128ce5e5ac4SMatthew Dillon 	str = "path1";
129ce5e5ac4SMatthew Dillon 	break;
130ce5e5ac4SMatthew Dillon     case JLEAF_PATH2:
131ce5e5ac4SMatthew Dillon 	str = "path2";
132ce5e5ac4SMatthew Dillon 	break;
133ce5e5ac4SMatthew Dillon     case JLEAF_PATH3:
134ce5e5ac4SMatthew Dillon 	str = "path3";
135ce5e5ac4SMatthew Dillon 	break;
136ce5e5ac4SMatthew Dillon     case JLEAF_PATH4:
137ce5e5ac4SMatthew Dillon 	str = "path4";
138ce5e5ac4SMatthew Dillon 	break;
139ce5e5ac4SMatthew Dillon     case JLEAF_UID:
140ce5e5ac4SMatthew Dillon 	str = "uid";
141ce5e5ac4SMatthew Dillon 	break;
142ce5e5ac4SMatthew Dillon     case JLEAF_GID:
143ce5e5ac4SMatthew Dillon 	str = "gid";
144ce5e5ac4SMatthew Dillon 	break;
145712e03b0SMatthew Dillon     case JLEAF_VTYPE:
146712e03b0SMatthew Dillon 	str = "vtype";
147712e03b0SMatthew Dillon 	break;
148ce5e5ac4SMatthew Dillon     case JLEAF_MODES:
149ce5e5ac4SMatthew Dillon 	str = "modes";
150ce5e5ac4SMatthew Dillon 	break;
151ce5e5ac4SMatthew Dillon     case JLEAF_FFLAGS:
152ce5e5ac4SMatthew Dillon 	str = "fflags";
153ce5e5ac4SMatthew Dillon 	break;
154ce5e5ac4SMatthew Dillon     case JLEAF_PID:
155ce5e5ac4SMatthew Dillon 	str = "pid";
156ce5e5ac4SMatthew Dillon 	break;
157ce5e5ac4SMatthew Dillon     case JLEAF_PPID:
158ce5e5ac4SMatthew Dillon 	str = "ppid";
159ce5e5ac4SMatthew Dillon 	break;
160ce5e5ac4SMatthew Dillon     case JLEAF_COMM:
161ce5e5ac4SMatthew Dillon 	str = "comm";
162ce5e5ac4SMatthew Dillon 	break;
163ce5e5ac4SMatthew Dillon     case JLEAF_ATTRNAME:
164ce5e5ac4SMatthew Dillon 	str = "attrname";
165ce5e5ac4SMatthew Dillon 	break;
166ce5e5ac4SMatthew Dillon     case JLEAF_PATH_REF:
167ce5e5ac4SMatthew Dillon 	str = "path_ref";
168ce5e5ac4SMatthew Dillon 	break;
169ce5e5ac4SMatthew Dillon     case JLEAF_RESERVED_0F:
170ce5e5ac4SMatthew Dillon 	str = "?";
171ce5e5ac4SMatthew Dillon 	break;
172ce5e5ac4SMatthew Dillon     case JLEAF_SYMLINKDATA:
173ce5e5ac4SMatthew Dillon 	str = "symlinkdata";
174ce5e5ac4SMatthew Dillon 	break;
175ce5e5ac4SMatthew Dillon     case JLEAF_SEEKPOS:
176ce5e5ac4SMatthew Dillon 	str = "seekpos";
177ce5e5ac4SMatthew Dillon 	break;
178ce5e5ac4SMatthew Dillon     case JLEAF_INUM:
179ce5e5ac4SMatthew Dillon 	str = "inum";
180ce5e5ac4SMatthew Dillon 	break;
181ce5e5ac4SMatthew Dillon     case JLEAF_NLINK:
182ce5e5ac4SMatthew Dillon 	str = "nlink";
183ce5e5ac4SMatthew Dillon 	break;
184ce5e5ac4SMatthew Dillon     case JLEAF_FSID:
185ce5e5ac4SMatthew Dillon 	str = "fsid";
186ce5e5ac4SMatthew Dillon 	break;
187ce5e5ac4SMatthew Dillon     case JLEAF_SIZE:
188ce5e5ac4SMatthew Dillon 	str = "size";
189ce5e5ac4SMatthew Dillon 	break;
190ce5e5ac4SMatthew Dillon     case JLEAF_ATIME:
191ce5e5ac4SMatthew Dillon 	str = "atime";
192ce5e5ac4SMatthew Dillon 	break;
193ce5e5ac4SMatthew Dillon     case JLEAF_MTIME:
194ce5e5ac4SMatthew Dillon 	str = "mtime";
195ce5e5ac4SMatthew Dillon 	break;
196ce5e5ac4SMatthew Dillon     case JLEAF_CTIME:
197ce5e5ac4SMatthew Dillon 	str = "ctime";
198ce5e5ac4SMatthew Dillon 	break;
199ce5e5ac4SMatthew Dillon     case JLEAF_GEN:
200ce5e5ac4SMatthew Dillon 	str = "gen";
201ce5e5ac4SMatthew Dillon 	break;
202ce5e5ac4SMatthew Dillon     case JLEAF_FLAGS:
203ce5e5ac4SMatthew Dillon 	str = "flags";
204ce5e5ac4SMatthew Dillon 	break;
205ce5e5ac4SMatthew Dillon     case JLEAF_UDEV:
206ce5e5ac4SMatthew Dillon 	str = "udev";
207ce5e5ac4SMatthew Dillon 	break;
208ce5e5ac4SMatthew Dillon     case JLEAF_FILEREV:
209ce5e5ac4SMatthew Dillon 	str = "filerev";
210ce5e5ac4SMatthew Dillon 	break;
211ce5e5ac4SMatthew Dillon     default:
212ce5e5ac4SMatthew Dillon 	str = "?";
213ce5e5ac4SMatthew Dillon 	break;
214ce5e5ac4SMatthew Dillon     }
215ce5e5ac4SMatthew Dillon     return (str);
216ce5e5ac4SMatthew Dillon }
217ce5e5ac4SMatthew Dillon 
2189c118cb2SMatthew Dillon void
stringout(FILE * fp,char c,int exact)2199c118cb2SMatthew Dillon stringout(FILE *fp, char c, int exact)
2209c118cb2SMatthew Dillon {
221f5781ca3SMatthew Dillon     if ((c >= 'a' && c <= 'z') ||
222f5781ca3SMatthew Dillon 	(c >= 'A' && c <= 'Z') ||
223f5781ca3SMatthew Dillon 	(c >= '0' && c <= '9')
224f5781ca3SMatthew Dillon     ) {
225f5781ca3SMatthew Dillon 	putc(c, fp);
226f5781ca3SMatthew Dillon     } else if (isprint((unsigned char)c) && c != '\\' && c != '\"') {
2279c118cb2SMatthew Dillon 	putc(c, fp);
2289c118cb2SMatthew Dillon     } else if (exact == 0) {
2299c118cb2SMatthew Dillon 	putc('.', fp);
2309c118cb2SMatthew Dillon     } else if (c == 0) {
2319c118cb2SMatthew Dillon 	fprintf(fp, "\\0");
2329c118cb2SMatthew Dillon     } else if (c == '\n') {
2339c118cb2SMatthew Dillon 	fprintf(fp, "\\n");
2349c118cb2SMatthew Dillon     } else {
2359c118cb2SMatthew Dillon 	fprintf(fp, "\\x%02x", (int)(unsigned char)c);
2369c118cb2SMatthew Dillon     }
2379c118cb2SMatthew Dillon }
2389c118cb2SMatthew Dillon 
239712e03b0SMatthew Dillon void
jattr_reset(struct jattr * jattr)240712e03b0SMatthew Dillon jattr_reset(struct jattr *jattr)
241712e03b0SMatthew Dillon {
242712e03b0SMatthew Dillon     struct jattr *undo;
24336d6bdeeSMatthew Dillon     struct jattr_data *data;
244712e03b0SMatthew Dillon 
245712e03b0SMatthew Dillon     if (jattr->path1)
246712e03b0SMatthew Dillon 	free(jattr->path1);
247712e03b0SMatthew Dillon     if (jattr->path2)
248712e03b0SMatthew Dillon 	free(jattr->path2);
249712e03b0SMatthew Dillon     if (jattr->path3)
250712e03b0SMatthew Dillon 	free(jattr->path3);
251712e03b0SMatthew Dillon     if (jattr->path4)
252712e03b0SMatthew Dillon 	free(jattr->path4);
253712e03b0SMatthew Dillon     if (jattr->comm)
254712e03b0SMatthew Dillon 	free(jattr->comm);
255712e03b0SMatthew Dillon     if (jattr->attrname)
256712e03b0SMatthew Dillon 	free(jattr->attrname);
257712e03b0SMatthew Dillon     if (jattr->pathref)
258712e03b0SMatthew Dillon 	free(jattr->pathref);
259fa8f36ebSMatthew Dillon     if (jattr->symlinkdata)
260fa8f36ebSMatthew Dillon 	free(jattr->symlinkdata);
26136d6bdeeSMatthew Dillon     while ((data = jattr->data.next) != NULL) {
26236d6bdeeSMatthew Dillon 	jattr->data.next = data->next;
26336d6bdeeSMatthew Dillon 	free(data);
26436d6bdeeSMatthew Dillon     }
265712e03b0SMatthew Dillon     if ((undo = jattr->undo) != NULL)
266712e03b0SMatthew Dillon 	jattr_reset(jattr->undo);
267712e03b0SMatthew Dillon     bzero(jattr, sizeof(*jattr));
268712e03b0SMatthew Dillon     jattr->undo = undo;
269712e03b0SMatthew Dillon     jattr->uid = (uid_t)-1;
270712e03b0SMatthew Dillon     jattr->gid = (gid_t)-1;
271712e03b0SMatthew Dillon     jattr->size = (off_t)-1;
272712e03b0SMatthew Dillon     jattr->modes = -1;
273712e03b0SMatthew Dillon     jattr->flags = -1;
274712e03b0SMatthew Dillon     jattr->seekpos = -1;
275712e03b0SMatthew Dillon }
276712e03b0SMatthew Dillon 
277712e03b0SMatthew Dillon int64_t
buf_to_int64(const void * buf,int bytes)278712e03b0SMatthew Dillon buf_to_int64(const void *buf, int bytes)
279712e03b0SMatthew Dillon {
280712e03b0SMatthew Dillon     int64_t v;
281712e03b0SMatthew Dillon 
282712e03b0SMatthew Dillon     switch(bytes) {
283712e03b0SMatthew Dillon     case 1:
284712e03b0SMatthew Dillon 	v = (int64_t)*(const u_int8_t *)buf;
285712e03b0SMatthew Dillon 	break;
286712e03b0SMatthew Dillon     case 2:
287712e03b0SMatthew Dillon 	v = (int64_t)*(const u_int16_t *)buf;
288712e03b0SMatthew Dillon 	break;
289712e03b0SMatthew Dillon     case 4:
290712e03b0SMatthew Dillon 	v = (int64_t)*(const u_int32_t *)buf;
291712e03b0SMatthew Dillon 	break;
292712e03b0SMatthew Dillon     case 8:
293712e03b0SMatthew Dillon 	v = *(const int64_t *)buf;
294712e03b0SMatthew Dillon 	break;
295712e03b0SMatthew Dillon     default:
296712e03b0SMatthew Dillon 	v = 0;
297712e03b0SMatthew Dillon     }
298712e03b0SMatthew Dillon     return(v);
299712e03b0SMatthew Dillon }
300712e03b0SMatthew Dillon 
301712e03b0SMatthew Dillon char *
dupdatastr(const void * buf,int bytes)302712e03b0SMatthew Dillon dupdatastr(const void *buf, int bytes)
303712e03b0SMatthew Dillon {
304712e03b0SMatthew Dillon     char *res;
305712e03b0SMatthew Dillon 
306712e03b0SMatthew Dillon     res = malloc(bytes + 1);
307712e03b0SMatthew Dillon     bcopy(buf, res, bytes);
308712e03b0SMatthew Dillon     res[bytes] = 0;
309712e03b0SMatthew Dillon 
310712e03b0SMatthew Dillon     return(res);
311712e03b0SMatthew Dillon }
312712e03b0SMatthew Dillon 
313712e03b0SMatthew Dillon /*
314712e03b0SMatthew Dillon  * Similar to dupdatastr() but contains sanity checks.
315712e03b0SMatthew Dillon  */
316712e03b0SMatthew Dillon char *
dupdatapath(const void * buf,int bytes)317712e03b0SMatthew Dillon dupdatapath(const void *buf, int bytes)
318712e03b0SMatthew Dillon {
319712e03b0SMatthew Dillon     char *res;
320712e03b0SMatthew Dillon     char *scan;
321712e03b0SMatthew Dillon 
322712e03b0SMatthew Dillon     res = malloc(bytes + 1);
323712e03b0SMatthew Dillon     bcopy(buf, res, bytes);
324712e03b0SMatthew Dillon     res[bytes] = 0;
325712e03b0SMatthew Dillon 
326712e03b0SMatthew Dillon     if (res[0] == '/') {
327712e03b0SMatthew Dillon 	fprintf(stderr, "Bad path: %s\n", res);
328712e03b0SMatthew Dillon 	free(res);
329712e03b0SMatthew Dillon 	return(NULL);
330712e03b0SMatthew Dillon     }
331712e03b0SMatthew Dillon     scan = res;
332712e03b0SMatthew Dillon     for (;;) {
333712e03b0SMatthew Dillon 	if (scan[0] == '.' && scan[1] == '.' &&
334712e03b0SMatthew Dillon 	    (scan[2] == 0 || scan[2] == '/')
335712e03b0SMatthew Dillon 	) {
336712e03b0SMatthew Dillon 	    fprintf(stderr, "Bad path: %s\n", res);
337712e03b0SMatthew Dillon 	    free(res);
338712e03b0SMatthew Dillon 	    return(NULL);
339712e03b0SMatthew Dillon 	}
340712e03b0SMatthew Dillon 	if ((scan = strchr(scan, '/')) == NULL)
341712e03b0SMatthew Dillon 	    break;
342712e03b0SMatthew Dillon 	++scan;
343712e03b0SMatthew Dillon     }
344712e03b0SMatthew Dillon     return(res);
345712e03b0SMatthew Dillon }
346ce5e5ac4SMatthew Dillon 
347c2b2044aSMatthew Dillon void
get_transid_from_file(const char * path,int64_t * transid,int flags)348c2b2044aSMatthew Dillon get_transid_from_file(const char *path, int64_t *transid, int flags)
349c2b2044aSMatthew Dillon {
350c2b2044aSMatthew Dillon     int n;
351c2b2044aSMatthew Dillon     int fd;
352c2b2044aSMatthew Dillon     char buf[32];
353c2b2044aSMatthew Dillon 
354c2b2044aSMatthew Dillon     *transid = 0;
355c2b2044aSMatthew Dillon     if ((fd = open(path, O_RDONLY)) >= 0) {
356c2b2044aSMatthew Dillon 	n = read(fd, buf, sizeof(buf) - 1);
357c2b2044aSMatthew Dillon 	if (n >= 0)
358c2b2044aSMatthew Dillon 	    buf[n] = 0;
359c2b2044aSMatthew Dillon 	*transid = strtoull(buf, NULL, 16);
360c2b2044aSMatthew Dillon 	jmodes |= flags;
361c2b2044aSMatthew Dillon 	close(fd);
362c2b2044aSMatthew Dillon     }
363c2b2044aSMatthew Dillon }
364c2b2044aSMatthew Dillon 
365