Deleted Added
full compact
dirs.c (18406) dirs.c (21149)
1/*
2 * Copyright (c) 1983, 1993
3 * The Regents of the University of California. All rights reserved.
4 * (c) UNIX System Laboratories, Inc.
5 * All or some portions of this file are derived from material licensed
6 * to the University of California by American Telephone and Telegraph
7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8 * the permission of UNIX System Laboratories, Inc.

--- 90 unchanged lines hidden (view full) ---

99};
100
101/*
102 * Global variables for this file.
103 */
104static long seekpt;
105static FILE *df, *mf;
106static RST_DIR *dirp;
1/*
2 * Copyright (c) 1983, 1993
3 * The Regents of the University of California. All rights reserved.
4 * (c) UNIX System Laboratories, Inc.
5 * All or some portions of this file are derived from material licensed
6 * to the University of California by American Telephone and Telegraph
7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8 * the permission of UNIX System Laboratories, Inc.

--- 90 unchanged lines hidden (view full) ---

99};
100
101/*
102 * Global variables for this file.
103 */
104static long seekpt;
105static FILE *df, *mf;
106static RST_DIR *dirp;
107static char dirfile[32] = "#"; /* No file */
108static char modefile[32] = "#"; /* No file */
109static char dot[2] = "."; /* So it can be modified */
107static char dirfile[MAXPATHLEN] = "#"; /* No file */
108static char modefile[MAXPATHLEN] = "#"; /* No file */
109static char dot[2] = "."; /* So it can be modified */
110
111/*
112 * Format of old style directories.
113 */
114#define ODIRSIZ 14
115struct odirect {
116 u_short d_ino;
117 char d_name[ODIRSIZ];

--- 19 unchanged lines hidden (view full) ---

137void
138extractdirs(genmode)
139 int genmode;
140{
141 register int i;
142 register struct dinode *ip;
143 struct inotab *itp;
144 struct direct nulldir;
110
111/*
112 * Format of old style directories.
113 */
114#define ODIRSIZ 14
115struct odirect {
116 u_short d_ino;
117 char d_name[ODIRSIZ];

--- 19 unchanged lines hidden (view full) ---

137void
138extractdirs(genmode)
139 int genmode;
140{
141 register int i;
142 register struct dinode *ip;
143 struct inotab *itp;
144 struct direct nulldir;
145 int fd;
145
146 vprintf(stdout, "Extract directories from tape\n");
146
147 vprintf(stdout, "Extract directories from tape\n");
147 (void) sprintf(dirfile, "%s/rstdir%d", _PATH_TMP, dumpdate);
148 df = fopen(dirfile, "w");
149 if (df == NULL) {
148 (void) sprintf(dirfile, "%srstdir%d", _PATH_TMP, dumpdate);
149 if (command != 'r' && command != 'R') {
150 (void *) strcat(dirfile, "-XXXXXX");
151 fd = mkstemp(dirfile);
152 } else
153 fd = open(dirfile, O_RDWR|O_CREAT|O_EXCL, 0666);
154 if (fd == -1 || (df = fdopen(fd, "w")) == NULL) {
155 if (fd != -1)
156 close(fd);
150 fprintf(stderr,
151 "restore: %s - cannot create directory temporary\n",
152 dirfile);
153 fprintf(stderr, "fopen: %s\n", strerror(errno));
154 done(1);
155 }
156 if (genmode != 0) {
157 fprintf(stderr,
158 "restore: %s - cannot create directory temporary\n",
159 dirfile);
160 fprintf(stderr, "fopen: %s\n", strerror(errno));
161 done(1);
162 }
163 if (genmode != 0) {
157 (void) sprintf(modefile, "%s/rstmode%d", _PATH_TMP, dumpdate);
158 mf = fopen(modefile, "w");
159 if (mf == NULL) {
164 (void) sprintf(modefile, "%srstmode%d", _PATH_TMP, dumpdate);
165 if (command != 'r' && command != 'R') {
166 (void *) strcat(modefile, "-XXXXXX");
167 fd = mkstemp(modefile);
168 } else
169 fd = open(modefile, O_RDWR|O_CREAT|O_EXCL, 0666);
170 if (fd == -1 || (mf = fdopen(fd, "w")) == NULL) {
171 if (fd != -1)
172 close(fd);
160 fprintf(stderr,
161 "restore: %s - cannot create modefile \n",
162 modefile);
163 fprintf(stderr, "fopen: %s\n", strerror(errno));
164 done(1);
165 }
166 }
167 nulldir.d_ino = 0;

--- 66 unchanged lines hidden (view full) ---

234 * Pname is a dumped directory name.
235 */
236 if ((*todo)(pname, ino, NODE) == FAIL)
237 return;
238 /*
239 * begin search through the directory
240 * skipping over "." and ".."
241 */
173 fprintf(stderr,
174 "restore: %s - cannot create modefile \n",
175 modefile);
176 fprintf(stderr, "fopen: %s\n", strerror(errno));
177 done(1);
178 }
179 }
180 nulldir.d_ino = 0;

--- 66 unchanged lines hidden (view full) ---

247 * Pname is a dumped directory name.
248 */
249 if ((*todo)(pname, ino, NODE) == FAIL)
250 return;
251 /*
252 * begin search through the directory
253 * skipping over "." and ".."
254 */
242 (void) strncpy(locname, pname, MAXPATHLEN);
243 (void) strncat(locname, "/", MAXPATHLEN);
255 (void) strncpy(locname, pname, sizeof(locname) - 1);
256 locname[sizeof(locname) - 1] = '\0';
257 (void) strncat(locname, "/", sizeof(locname) - strlen(locname));
244 namelen = strlen(locname);
245 rst_seekdir(dirp, itp->t_seekpt, itp->t_seekpt);
246 dp = rst_readdir(dirp); /* "." */
247 if (dp != NULL && strcmp(dp->d_name, ".") == 0)
248 dp = rst_readdir(dirp); /* ".." */
249 else
250 fprintf(stderr, "Warning: `.' missing from directory %s\n",
251 pname);
252 if (dp != NULL && strcmp(dp->d_name, "..") == 0)
253 dp = rst_readdir(dirp); /* first real entry */
254 else
255 fprintf(stderr, "Warning: `..' missing from directory %s\n",
256 pname);
257 bpt = rst_telldir(dirp);
258 /*
259 * a zero inode signals end of directory
260 */
261 while (dp != NULL && dp->d_ino != 0) {
262 locname[namelen] = '\0';
258 namelen = strlen(locname);
259 rst_seekdir(dirp, itp->t_seekpt, itp->t_seekpt);
260 dp = rst_readdir(dirp); /* "." */
261 if (dp != NULL && strcmp(dp->d_name, ".") == 0)
262 dp = rst_readdir(dirp); /* ".." */
263 else
264 fprintf(stderr, "Warning: `.' missing from directory %s\n",
265 pname);
266 if (dp != NULL && strcmp(dp->d_name, "..") == 0)
267 dp = rst_readdir(dirp); /* first real entry */
268 else
269 fprintf(stderr, "Warning: `..' missing from directory %s\n",
270 pname);
271 bpt = rst_telldir(dirp);
272 /*
273 * a zero inode signals end of directory
274 */
275 while (dp != NULL && dp->d_ino != 0) {
276 locname[namelen] = '\0';
263 if (namelen + dp->d_namlen >= MAXPATHLEN) {
277 if (namelen + dp->d_namlen >= sizeof(locname)) {
264 fprintf(stderr, "%s%s: name exceeds %d char\n",
278 fprintf(stderr, "%s%s: name exceeds %d char\n",
265 locname, dp->d_name, MAXPATHLEN);
279 locname, dp->d_name, sizeof(locname) - 1);
266 } else {
267 (void) strncat(locname, dp->d_name, (int)dp->d_namlen);
268 treescan(locname, dp->d_ino, todo);
269 rst_seekdir(dirp, bpt, itp->t_seekpt);
270 }
271 dp = rst_readdir(dirp);
272 bpt = rst_telldir(dirp);
273 }

--- 306 unchanged lines hidden (view full) ---

580 int flags;
581{
582 FILE *mf;
583 struct modeinfo node;
584 struct entry *ep;
585 char *cp;
586
587 vprintf(stdout, "Set directory mode, owner, and times.\n");
280 } else {
281 (void) strncat(locname, dp->d_name, (int)dp->d_namlen);
282 treescan(locname, dp->d_ino, todo);
283 rst_seekdir(dirp, bpt, itp->t_seekpt);
284 }
285 dp = rst_readdir(dirp);
286 bpt = rst_telldir(dirp);
287 }

--- 306 unchanged lines hidden (view full) ---

594 int flags;
595{
596 FILE *mf;
597 struct modeinfo node;
598 struct entry *ep;
599 char *cp;
600
601 vprintf(stdout, "Set directory mode, owner, and times.\n");
588 (void) sprintf(modefile, "%s/rstmode%d", _PATH_TMP, dumpdate);
602 if (command == 'r' || command == 'R')
603 (void) sprintf(modefile, "%srstmode%d", _PATH_TMP, dumpdate);
604 if (modefile[0] == '#') {
605 panic("modefile not defined\n");
606 fprintf(stderr, "directory mode, owner, and times not set\n");
607 return;
608 }
589 mf = fopen(modefile, "r");
590 if (mf == NULL) {
591 fprintf(stderr, "fopen: %s\n", strerror(errno));
592 fprintf(stderr, "cannot open mode file %s\n", modefile);
593 fprintf(stderr, "directory mode, owner, and times not set\n");
594 return;
595 }
596 clearerr(mf);

--- 38 unchanged lines hidden (view full) ---

635{
636 register struct inotab *itp;
637 int ofile, dp, i, size;
638 char buf[BUFSIZ];
639
640 itp = inotablookup(ino);
641 if (itp == NULL)
642 panic("Cannot find directory inode %d named %s\n", ino, name);
609 mf = fopen(modefile, "r");
610 if (mf == NULL) {
611 fprintf(stderr, "fopen: %s\n", strerror(errno));
612 fprintf(stderr, "cannot open mode file %s\n", modefile);
613 fprintf(stderr, "directory mode, owner, and times not set\n");
614 return;
615 }
616 clearerr(mf);

--- 38 unchanged lines hidden (view full) ---

655{
656 register struct inotab *itp;
657 int ofile, dp, i, size;
658 char buf[BUFSIZ];
659
660 itp = inotablookup(ino);
661 if (itp == NULL)
662 panic("Cannot find directory inode %d named %s\n", ino, name);
643 if ((ofile = creat(name, 0666)) < 0) {
663 if ((ofile = open(name, O_WRONLY | O_CREAT | O_TRUNC, 0666)) < 0) {
644 fprintf(stderr, "%s: ", name);
645 (void) fflush(stderr);
646 fprintf(stderr, "cannot create file: %s\n", strerror(errno));
647 return (FAIL);
648 }
649 rst_seekdir(dirp, itp->t_seekpt, itp->t_seekpt);
650 dp = dup(dirp->dd_fd);
651 for (i = itp->t_size; i > 0; i -= BUFSIZ) {

--- 100 unchanged lines hidden ---
664 fprintf(stderr, "%s: ", name);
665 (void) fflush(stderr);
666 fprintf(stderr, "cannot create file: %s\n", strerror(errno));
667 return (FAIL);
668 }
669 rst_seekdir(dirp, itp->t_seekpt, itp->t_seekpt);
670 dp = dup(dirp->dd_fd);
671 for (i = itp->t_size; i > 0; i -= BUFSIZ) {

--- 100 unchanged lines hidden ---