aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/9660/unix.c
blob: f060c104c7a4e8f2446b1b76498cf0fa443af756 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <u.h>
#include <libc.h>
#include <bio.h>
#include <libsec.h>
#include <disk.h>
#include <ctype.h>

#include "iso9660.h"

#include <grp.h>
#include <pwd.h>

typedef struct Xarg Xarg;
struct Xarg {
	void (*enm)(char*,char*,XDir*,void*);
	void (*warn)(char*,void*);
	void *arg;
};

static long numericuid(char *user);
static long numericgid(char *gp);

void
dirtoxdir(XDir *xd, Dir *d)
{
	//	char buf[NAMELEN+1];
	memset(xd, 0, sizeof *xd);

	xd->name = atom(d->name);
	xd->uid = atom(d->uid);
	xd->gid = atom(d->gid);
	xd->uidno = numericuid(d->uid);
	xd->gidno = numericgid(d->gid);
	xd->mode = d->mode;
	xd->atime = d->atime;
	xd->mtime = d->mtime;
	xd->ctime = 0;
	xd->length = d->length;
	if(xd->mode & CHLINK) {
		xd->mode |= 0777;
		//xd->symlink = atom(d->symlink);
		xd->symlink = atom("symlink");		// XXX: rsc
	}
}

void
fdtruncate(int fd, ulong size)
{
	ftruncate(fd, size);

	return;
}

static long
numericuid(char *user)
{
	struct passwd *pass;
	static int warned = 0;

	if (! (pass = getpwnam(user))) {
		if (!warned)
			fprint(2, "Warning: getpwnam(3) failed for \"%s\"\n", user);
		warned = 1;
		return 0;
	}

	return pass->pw_uid;
}

static long
numericgid(char *gp)
{
	struct group *gr;
	static int warned = 0;

	if (! (gr = getgrnam(gp))) {
		if (!warned)
			fprint(2, "Warning: getgrnam(3) failed for \"%s\"\n", gp);
		warned = 1;
		return 0;
	}

	return gr->gr_gid;
}