* Copyright (c) 1989 The Regents of the University of California.
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
static char sccsid
[] = "@(#)create.c 5.1 (Berkeley) %G%";
extern int dflag
, xflag
, errno
, alphasort();
register ENTRY
*centry
, *level
;
struct dirent
*dp
, **dir_list
;
char *emalloc(), *rlink();
dir_cnt
= scandir(".", &dir_list
, NULL
, alphasort
);
if (dir_cnt
== -1 || xflag
&& stat(".", &sbuf
)) {
(void)fprintf(stderr
, "mtree: %s: %s\n", path
+ 2,
for (cnt
= 0; cnt
< dir_cnt
; ++cnt
) {
if (dp
->d_name
[0] == '.' &&
(!dp
->d_name
[1] || dp
->d_name
[1] == '.' && !dp
->d_name
[2]))
bcopy(dp
->d_name
, tail
, dp
->d_namlen
+ 1);
if (stat(dp
->d_name
, &sbuf
)) {
(void)fprintf(stderr
, "mtree: %s: %s\n",
path
+ 2, strerror(errno
));
if (dflag
&& !S_ISDIR(sbuf
.st_mode
))
centry
= (ENTRY
*)emalloc(sizeof(ENTRY
));
if (!(centry
->name
= strdup(dp
->d_name
)))
centry
->nlen
= dp
->d_namlen
;
switch(sbuf
.st_mode
&S_IFMT
) {
centry
->info
.type
= F_DIR
;
centry
->info
.type
= F_CHAR
;
centry
->info
.type
= F_BLOCK
;
centry
->info
.type
= F_FILE
;
centry
->info
.type
= F_LINK
;
centry
->info
.slink
= strdup(rlink(dp
->d_name
));
centry
->info
.type
= F_SOCK
;
(void)fprintf(stderr
, "mtree: unknown file type %s.\n",
centry
->info
.st_uid
= sbuf
.st_uid
;
centry
->info
.st_gid
= sbuf
.st_gid
;
centry
->info
.st_size
= sbuf
.st_size
;
centry
->info
.st_mode
= sbuf
.st_mode
&07777;
centry
->info
.st_nlink
= sbuf
.st_nlink
;
centry
->info
.st_uid
= sbuf
.st_uid
;
root
->parent
= root
->child
= NULL
;
centry
->parent
= level
->parent
;
level
= level
->next
= centry
;
if (!S_ISDIR(sbuf
.st_mode
) || xflag
&& device
!= sbuf
.st_dev
)
(void)fprintf(stderr
, "mtree: %s: %s\n", path
+ 2,
cwalk(level
, tail
+ dp
->d_namlen
);
(void)fprintf(stderr
, "mtree: ..: %s\n",
(void)printf("%s", level->nlen > 7 ? "\t" : "\t\t"); \
extern mode_t dmode
; /* default directory mode */
extern mode_t fmode
; /* default file mode */
uid_t uid
, gid
; /* default owner, group */
for (; level
; level
= level
->next
) {
for (cnt
= tabs
; cnt
--; )
(void)printf("%s", level
->name
);
if ((ip
= &level
->info
)->type
!= F_FILE
) {
(void)printf("type=%s", ftype(ip
->type
));
(void)printf("owner=%u", ip
->st_uid
);
(void)printf("group=%u", ip
->st_gid
);
if (ip
->st_mode
!= dmode
) {
(void)printf("mode=%o", ip
->st_mode
);
if (ip
->st_mode
!= fmode
) {
(void)printf("mode=%o", ip
->st_mode
);
(void)printf("nlink=%u", ip
->st_nlink
);
(void)printf("size=%ld", ip
->st_size
);
(void)printf(" link=%s", ip
->slink
);
pwalk(level
->child
, tabs
+ 1);
for (cnt
= tabs
; cnt
--; )
++dmodes
[ip
->st_mode
&0777];
++fmodes
[ip
->st_mode
&0777];
for (p
= uhead
;; p
= p
->next
)
p
= (ID
*)emalloc(sizeof(ID
));
} else if (p
->id
== ip
->st_uid
) {
for (p
= ghead
;; p
= p
->next
)
p
= (ID
*)emalloc(sizeof(ID
));
} else if (p
->id
== ip
->st_gid
) {
for (max
= 0, cnt
= 0777; cnt
; --cnt
)
(void)printf("/set dmode=%o\n", dmode
);
for (max
= 0, cnt
= 0777; cnt
; --cnt
)
(void)printf("/set fmode=%o\n", fmode
);
for (max
= 0, p
= uhead
; p
; p
= p
->next
)
(void)printf("/set owner=%u\n", uid
);
for (max
= 0, p
= ghead
; p
; p
= p
->next
)
(void)printf("/set group=%u\n", gid
);
(void)printf("/set nlink=1\n");
(void)printf("/set type=%s\n\n", dflag
? "dir" : "file");