/* Copyright (c) 1983 Regents of the University of California */
static char sccsid
[] = "@(#)utilities.c 3.5 (Berkeley) 83/01/16";
* Insure that all the components of a pathname exist.
start
= index(name
, '/');
for (cp
= start
; *cp
!= '\0'; cp
++) {
ep
= addentry(name
, ep
->e_ino
, NODE
);
* Change a name to a unique temporary name.
register struct entry
*ep
;
if (ep
->e_flags
& TMPNAME
)
badentry(ep
, "mktempname: called with TMPNAME");
strcpy(oldname
, myname(ep
));
ep
->e_name
[ep
->e_namlen
++] = TMPCHAR
;
ep
->e_name
[ep
->e_namlen
] = '\0';
renameit(oldname
, myname(ep
));
* Rename a file or directory.
if (rename(from
, to
) < 0) {
panic("Cannot rename %s to %s\n", from
, to
);
vprintf(stdout
, "rename %s to %s\n", from
, to
);
* Create a new node (directory).
badentry(np
, "newnode: not a node");
if (mkdir(cp
, 0777) < 0) {
panic("Cannot make node %s\n", cp
);
vprintf(stdout
, "Make node %s\n", cp
);
* Remove an old node (directory).
register struct entry
*ep
;
badentry(ep
, "removenode: not a node");
if (ep
->e_entries
!= NIL
)
badentry(ep
, "removenode: non-empty directory");
panic("Cannot remove node %s\n", cp
);
vprintf(stdout
, "Remove node %s\n", cp
);
register struct entry
*ep
;
badentry(ep
, "removeleaf: not a leaf");
panic("Cannot remove leaf %s\n", cp
);
vprintf(stdout
, "Remove leaf %s\n", cp
);
linkit(existing
, new, type
)
if (symlink(existing
, new) < 0) {
panic("Cannot create symbolic link %s->%s\n",
} else if (type
== HARDLINK
) {
if (link(existing
, new) < 0) {
panic("Cannot create hard link %s->%s\n",
panic("linkit: unknown type %d\n", type
);
vprintf(stdout
, "Create %s link %s->%s\n",
type
== SYMLINK
? "symbolic" : "hard", new, existing
);
* find lowest number file (above "start") that needs to be extracted
register struct entry
*ep
;
for ( ; start
< maxino
; start
++) {
if (ep
->e_flags
& (NEW
|EXTRACT
))
* find highest number file (below "start") that needs to be extracted
register struct entry
*ep
;
for ( ; start
> ROOTINO
; start
--) {
if (ep
->e_flags
& (NEW
|EXTRACT
))
* report on a badly formed entry
register struct entry
*ep
;
fprintf(stderr
, "bad entry: %s\n", msg
);
fprintf(stderr
, "name: %s\n", myname(ep
));
fprintf(stderr
, "parent name %s\n", myname(ep
->e_parent
));
if (ep
->e_sibling
!= NIL
)
fprintf(stderr
, "sibling name: %s\n", myname(ep
->e_sibling
));
if (ep
->e_entries
!= NIL
)
fprintf(stderr
, "next entry name: %s\n", myname(ep
->e_entries
));
fprintf(stderr
, "next link name: %s\n", myname(ep
->e_links
));
fprintf(stderr
, "next hashchain name: %s\n", myname(ep
->e_next
));
fprintf(stderr
, "entry type: %s\n",
ep
->e_type
== NODE
? "NODE" : "LEAF");
fprintf(stderr
, "inode number: %ld\n", ep
->e_ino
);
if (ep
->e_flags
& REMOVED
)
strcat(flagbuf
, "|REMOVED");
if (ep
->e_flags
& TMPNAME
)
strcat(flagbuf
, "|TMPNAME");
if (ep
->e_flags
& EXTRACT
)
strcat(flagbuf
, "|EXTRACT");
strcat(flagbuf
, "|KEEP");
panic("flags: %s\n", &flagbuf
[1]);
* canonicalize file names to always start with ``./''
canon(rawname
, canonname
)
char *rawname
, *canonname
;
if (strcmp(rawname
, ".") == 0 || strncmp(rawname
, "./", 2) == 0)
(void) strcpy(canonname
, "");
else if (rawname
[0] == '/')
(void) strcpy(canonname
, ".");
(void) strcpy(canonname
, "./");
(void) strcat(canonname
, rawname
);
len
= strlen(canonname
) - 1;
if (canonname
[len
] == '/')
fprintf(stderr
, "%s? ", question
);
fprintf(stderr
, "[yn] ");
while (c
!= '\n' && getchar() != '\n')
} while (c
!= 'y' && c
!= 'n');