1 #include <u.h>
2 #include <libc.h>
3 #include <bio.h>
4 #include <libsec.h>
5 #include <libproto.h>
6 #include <ctype.h>
7
8 #include "iso9660.h"
9
10 #include <grp.h>
11 #include <pwd.h>
12
13 typedef struct Xarg Xarg;
14 struct Xarg {
15 void (*enm)(char*,char*,XDir*,void*);
16 void (*warn)(char*,void*);
17 void *arg;
18 };
19
20 static long numericuid(char *user);
21 static long numericgid(char *gp);
22
23 void
dirtoxdir(XDir * xd,Dir * d)24 dirtoxdir(XDir *xd, Dir *d)
25 {
26 // char buf[NAMELEN+1];
27 memset(xd, 0, sizeof *xd);
28
29 xd->name = atom(d->name);
30 xd->uid = atom(d->uid);
31 xd->gid = atom(d->gid);
32 xd->uidno = numericuid(d->uid);
33 xd->gidno = numericgid(d->gid);
34 xd->mode = d->mode;
35 xd->atime = d->atime;
36 xd->mtime = d->mtime;
37 xd->ctime = 0;
38 xd->length = d->length;
39 if(xd->mode & CHLINK) {
40 xd->mode |= 0777;
41 xd->symlink = atom(d->symlink);
42 }
43 };
44
45 void
fdtruncate(int fd,ulong size)46 fdtruncate(int fd, ulong size)
47 {
48 ftruncate(fd, size);
49
50 return;
51 }
52
53 static long
numericuid(char * user)54 numericuid(char *user)
55 {
56 struct passwd *pass;
57 static int warned = 0;
58
59 if (! (pass = getpwnam(user))) {
60 if (!warned)
61 fprint(2, "Warning: getpwnam(3) failed for \"%s\"\n", user);
62 warned = 1;
63 return 0;
64 }
65
66 return pass->pw_uid;
67 }
68
69 static long
numericgid(char * gp)70 numericgid(char *gp)
71 {
72 struct group *gr;
73 static int warned = 0;
74
75 if (! (gr = getgrnam(gp))) {
76 if (!warned)
77 fprint(2, "Warning: getgrnam(3) failed for \"%s\"\n", gp);
78 warned = 1;
79 return 0;
80 }
81
82 return gr->gr_gid;
83 }
84