1 /* file.c - Additional file attributes */
3 /* Written 1993 by Werner Almesberger */
5 /* FAT32, VFAT, Atari format support, and various fixes additions May 1998
6 * by Roman Hodek <Roman.Hodek@informatik.uni-erlangen.de> */
15 #define _LINUX_STAT_H /* hack to avoid inclusion of <linux/stat.h> */
16 #define _LINUX_STRING_H_ /* hack to avoid inclusion of <linux/string.h>*/
17 #define _LINUX_FS_H /* hack to avoid inclusion of <linux/fs.h> */
19 //#include <linux/version.h>
20 //#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)
22 //# include <asm/types.h>
36 static void put_char(char **p
,unsigned char c
)
38 if ((c
>= ' ' && c
< 0x7f) || c
>= 0xa0) *(*p
)++ = c
;
41 *(*p
)++ = '0'+(c
>> 6);
42 *(*p
)++ = '0'+((c
>> 3) & 7);
43 *(*p
)++ = '0'+(c
& 7);
48 char *file_name(unsigned char *fixed
)
50 static char path
[MSDOS_NAME
*4+2];
55 for (i
= j
= 0; i
< 8; i
++)
56 if (fixed
[i
] != ' ') {
57 while (j
++ < i
) *p
++ = ' ';
58 put_char(&p
,fixed
[i
]);
60 if (strncmp(fixed
+8," ",3)) {
62 for (i
= j
= 0; i
< 3; i
++)
63 if (fixed
[i
+8] != ' ') {
64 while (j
++ < i
) *p
++ = ' ';
65 put_char(&p
,fixed
[i
+8]);
73 int file_cvt(unsigned char *name
,unsigned char *fixed
)
82 if (c
< ' ' || c
> 0x7e || strchr("*?<>|\"/",c
)) {
83 printf("Invalid character in name. Use \\ooo for special "
89 printf("Duplicate dots in name.\n");
92 while (size
--) *fixed
++ = ' ';
100 for (cnt
= 3; cnt
; cnt
--) {
101 if (*name
< '0' || *name
> '7') {
102 printf("Invalid octal character.\n");
108 printf("Expected three octal digits.\n");
113 if (islower(c
)) c
= toupper(c
);
120 if (*name
|| size
== 8) return 0;
122 while (size
--) *fixed
++ = ' ';
125 while (size
--) *fixed
++ = ' ';
130 void file_add(char *path
,FD_TYPE type
)
132 FDSC
**current
,*walk
;
133 char name
[MSDOS_NAME
];
137 if (*path
!= '/') die("%s: Absolute path required.",path
);
140 if ((here
= strchr(path
,'/'))) *here
= 0;
141 if (!file_cvt(path
,name
)) exit(2);
142 for (walk
= *current
; walk
; walk
= walk
->next
)
143 if (!here
&& (!strncmp(name
,walk
->name
,MSDOS_NAME
) || (type
==
144 fdt_undelete
&& !strncmp(name
+1,walk
->name
+1,MSDOS_NAME
-1))))
145 die("Ambiguous name: \"%s\"",path
);
146 else if (here
&& !strncmp(name
,walk
->name
,MSDOS_NAME
)) break;
148 walk
= alloc(sizeof(FDSC
));
149 strncpy(walk
->name
,name
,MSDOS_NAME
);
150 walk
->type
= here
? fdt_none
: type
;
152 walk
->next
= *current
;
155 current
= &walk
->first
;
163 FDSC
**file_cd(FDSC
**curr
,char *fixed
)
167 if (!curr
|| !*curr
) return NULL
;
168 for (walk
= curr
; *walk
; walk
= &(*walk
)->next
)
169 if (!strncmp((*walk
)->name
,fixed
,MSDOS_NAME
) && (*walk
)->first
)
170 return &(*walk
)->first
;
175 static FDSC
**file_find(FDSC
**dir
,char *fixed
)
177 if (!dir
|| !*dir
) return NULL
;
178 if (*(unsigned char *) fixed
== DELETED_FLAG
) {
180 if (!strncmp((*dir
)->name
+1,fixed
+1,MSDOS_NAME
-1) && !(*dir
)->first
)
187 if (!strncmp((*dir
)->name
,fixed
,MSDOS_NAME
) && !(*dir
)->first
)
195 FD_TYPE
file_type(FDSC
**curr
,char *fixed
)
199 if ((this = file_find(curr
,fixed
))) return (*this)->type
;
204 void file_modify(FDSC
**curr
,char *fixed
)
208 if (!(this = file_find(curr
,fixed
)))
209 die("Internal error: file_find failed");
210 switch ((*this)->type
) {
212 printf("Dropping %s\n",file_name(fixed
));
213 *(unsigned char *) fixed
= DELETED_FLAG
;
216 *fixed
= *(*this)->name
;
217 printf("Undeleting %s\n",file_name(fixed
));
220 die("Internal error: file_modify");
222 next
= (*this)->next
;
228 static void report_unused(FDSC
*this)
234 if (this->first
) report_unused(this->first
);
235 else if (this->type
!= fdt_none
)
236 printf("Warning: did not %s file %s\n",this->type
== fdt_drop
?
237 "drop" : "undelete",file_name(this->name
));
244 void file_unused(void)
246 report_unused(fp_root
);
249 /* Local Variables: */