home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The UNIX CD Bookshelf
/
OREILLY_TUCB_UNIX_CD.iso
/
upt
/
examples
/
SOURCES
/
TAR
/
SPARSE.
< prev
next >
Wrap
Text File
|
1998-07-24
|
6KB
|
219 lines
--- create.c.orig Thu Mar 25 13:32:31 1993
+++ create.c Sat Apr 10 07:32:15 1993
@@ -380,7 +380,6 @@
header_moved = 0;
-#ifdef BSD42
if (f_sparse_files)
{
/*
@@ -392,10 +391,15 @@
* at least one of those records in the file is just
* a useless hole.
*/
+#ifdef BSD42
#ifdef hpux /* Nice of HPUX to gratuitiously change it, huh? - mib */
- if (hstat.st_size - (hstat.st_blocks * 1024) > 1024)
+ if (hstat.st_size - (hstat.st_blocks * 1024) > 1024
+#else
+ if (hstat.st_size - (hstat.st_blocks * RECORDSIZE) > RECORDSIZE
+#endif
+ || check_sparse(p))
#else
- if (hstat.st_size - (hstat.st_blocks * RECORDSIZE) > RECORDSIZE)
+ if (check_sparse(p))
#endif
{
int filesize = hstat.st_size;
@@ -464,9 +468,11 @@
}
}
+/*
#else
upperbound = SPARSE_IN_HDR - 1;
#endif
+*/
sizeleft = hstat.st_size;
/* Don't bother opening empty, world readable files. */
--- tar.c.orig Wed Mar 17 10:30:46 1993
+++ tar.c Sat Apr 10 07:30:59 1993
@@ -72,6 +72,9 @@
extern FILE *msg_file;
+int check_sparse();
+void add_sparse();
+void add_sparse_file();
int check_exclude ();
void add_exclude ();
void add_exclude_file ();
@@ -171,6 +174,9 @@
{"same-permissions", 0, &f_use_protection, 1},
+ {"sparse-list", 1, 0, 19},
+ {"sparse-file", 1, 0, 20},
+
{"sparse", 0, &f_sparse_files, 1},
{"tape-length", 1, 0, 'L'},
{"remove-files", 0, &f_remove_files, 1},
@@ -360,6 +366,15 @@
}
f_compressprog = optarg;
break;
+ case 19:
+ f_sparse_files++;
+ add_sparse_file(optarg);
+ break;
+
+ case 20:
+ f_sparse_files++;
+ add_sparse(optarg);
+ break;
case 'g': /* We are making a GNU dump; save
directories at the beginning of
@@ -736,6 +751,8 @@
--preserve-order list of names to extract is sorted to match archive\n\
--same-owner create extracted files with the same ownership \n\
-S, --sparse handle sparse files efficiently\n\
+--sparse-file FILE treat FILE as sparse (implicit -S as well)\n\
+--sparse-list FILE treat files listed in FILE as sparse (implicit -S)\n\
-T, --files-from F get names to extract or create from file F\n\
--null -T reads null-terminated names, disable -C\n\
--totals print total bytes written with --create\n\
@@ -1502,3 +1519,125 @@
}
return 0;
}
+
+char *s_buffer = 0;
+int size_s_buffer;
+int free_s_buffer;
+
+char **sparse = 0;
+int size_sparse = 0;
+int free_sparse = 0;
+
+char **re_sparse = 0;
+int size_re_sparse = 0;
+int free_re_sparse = 0;
+
+void
+add_sparse(name)
+char *name;
+{
+/* char *rname;*/
+/* char **tmp_ptr;*/
+ int size_buf;
+
+ un_quote_string(name);
+ size_buf = strlen(name);
+
+ if(s_buffer==0) {
+ s_buffer = (char *)ck_malloc(size_buf+1024);
+ free_s_buffer=1024;
+ } else if(free_s_buffer<=size_buf) {
+ char *old_s_buffer;
+ char **tmp_ptr;
+
+ old_s_buffer = s_buffer;
+ s_buffer = (char *)ck_realloc(s_buffer,size_s_buffer+1024);
+ free_s_buffer = 1024;
+ for(tmp_ptr=sparse;tmp_ptr<sparse+size_sparse;tmp_ptr++)
+ *tmp_ptr= s_buffer + ((*tmp_ptr) - old_s_buffer);
+ for(tmp_ptr=re_sparse;tmp_ptr<re_sparse+size_re_sparse;tmp_ptr++)
+ *tmp_ptr= s_buffer + ((*tmp_ptr) - old_s_buffer);
+ }
+
+ if(is_regex(name)) {
+ if(free_re_sparse==0) {
+ re_sparse= (char **)(re_sparse ?
+ ck_realloc(re_sparse,(size_re_sparse+32)*sizeof(char *)) :
+ ck_malloc(sizeof(char *)*32));
+ free_re_sparse+=32;
+ }
+ re_sparse[size_re_sparse]=s_buffer+size_s_buffer;
+ size_re_sparse++;
+ free_re_sparse--;
+ } else {
+ if(free_sparse==0) {
+ sparse=(char **)(sparse ?
+ ck_realloc(sparse,(size_sparse+32)*sizeof(char *)) :
+ ck_malloc(sizeof(char *)*32));
+ free_sparse+=32;
+ }
+ sparse[size_sparse]=s_buffer+size_s_buffer;
+ size_sparse++;
+ free_sparse--;
+ }
+ strcpy(s_buffer+size_s_buffer,name);
+ size_s_buffer+=size_buf+1;
+ free_s_buffer-=size_buf+1;
+}
+
+void
+add_sparse_file(file)
+char *file;
+{
+ FILE *fp;
+ char buf[1024];
+
+ if(strcmp(file, "-"))
+ fp=fopen(file,"r");
+ else
+ /* Let's hope the person knows what they're doing. */
+ /* Using -X - -T - -f - will get you *REALLY* strange
+ results. . . */
+ fp=stdin;
+
+ if(!fp) {
+ msg_perror("can't open %s",file);
+ exit(2);
+ }
+ while(fgets(buf,1024,fp)) {
+/* int size_buf;*/
+ char *end_str;
+
+ end_str=rindex(buf,'\n');
+ if(end_str)
+ *end_str='\0';
+ add_sparse(buf);
+
+ }
+ fclose(fp);
+}
+
+/* Returns non-zero if the file 'name' should be treated as sparse */
+int
+check_sparse(name)
+char *name;
+{
+ int n;
+ char *str;
+ extern char *strstr();
+
+ for(n=0;n<size_re_sparse;n++) {
+ if(fnmatch(re_sparse[n], name, FNM_LEADING_DIR) == 0)
+ return 1;
+ }
+ for(n=0;n<size_sparse;n++) {
+ /* Accept the output from strstr only if it is the last
+ part of the string. There is certainly a faster way to
+ do this. . . */
+ if( (str=strstr(name,sparse[n]))
+ && (str==name || str[-1]=='/')
+ && str[strlen(sparse[n])]=='\0')
+ return 1;
+ }
+ return 0;
+}
--- version.c.orig Thu Mar 25 13:35:25 1993
+++ version.c Sat Apr 10 16:07:54 1993
@@ -1 +1 @@
-char version_string[] = "GNU tar version 1.11.2";
+char version_string[] = "GNU tar version 1.11.2RTR";