/* Copyright (c) 1983 Regents of the University of California */
static char sccsid
[] = "@(#)utilities.c 3.4 (Berkeley) 83/02/28";
* Move the contents of a directory to a new directory.
register struct entry
*ep
;
strcpy(target
, myname(to
));
targetp
= &target
[strlen(target
)];
for (ep
= from
->e_entries
; ep
!= NIL
; ) {
strcpy(targetp
, ep
->e_name
);
if (ep
->e_flags
& TMPNAME
)
badentry(ep
, "movecontents: found TMPNAME");
renameit(myname(ep
), target
);
* Insure that all the components of a pathname exist.
start
= index(name
, '/');
return (lookupino(ROOTINO
));
for (cp
= start
; *cp
!= '\0'; cp
++) {
ep
= addentry(name
, (ino_t
)0, 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
);
ep
->e_flags
&= ~(TMPNAME
|TMPNODE
);
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
|CHANGE
))
* 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
|CHANGE
))
* report on a badly formed entry
register struct entry
*ep
;
fprintf(stderr
, "bad entry: %s\n", msg
);
fprintf(stderr
, "name: %s\n", myname(ep
));
if (ep
->e_newname
!= NULL
)
fprintf(stderr
, "new name: %s\n", ep
->e_newname
);
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
, "entry type: %s\n",
ep
->e_type
== NODE
? "NODE" : "LEAF");
fprintf(stderr
, "inode number: %ld\n", ep
->e_ino
);
if (ep
->e_flags
& REMOVE
)
strcat(flagbuf
, "|REMOVE");
if (ep
->e_flags
& REMOVED
)
strcat(flagbuf
, "|REMOVED");
if (ep
->e_flags
& RENAME
)
strcat(flagbuf
, "|RENAME");
if (ep
->e_flags
& TMPNAME
)
strcat(flagbuf
, "|TMPNAME");
if (ep
->e_flags
& TMPNODE
)
strcat(flagbuf
, "|TMPNODE");
if (ep
->e_flags
& EXTRACT
)
strcat(flagbuf
, "|EXTRACT");
if (ep
->e_flags
& RENUMBER
)
strcat(flagbuf
, "|RENUMBER");
if (ep
->e_flags
& CHANGE
)
strcat(flagbuf
, "|CHANGE");
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)
else if (rawname
[0] == '/')
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');