From: hzatz@cco.caltech.edu (Harold R. Zatz) Subject: Re: Problems with extfs (a way to find the max file name length) Date: Sun, 2 Aug 1992 21:44:21 GMT
Actually, if all you're looking for is the maximum valid filename
length in a particular file system, why not just write a simple routine
that writes out a test file with an extremely large (>256) filename,
and then see how long a filename you can read back in?
This works on my regular and msdos partitions; I don't have an
extfs partition to check it for. It does also work on my Apollo DN-10000
at work, though.
================================Cut here===========================
#include <stdio.h>
#include <sys/errno.h>
int getfilenamelen() {
char name[1025];
register i;
FILE *file;
for( i = 0 ; i < 1024 ; i++) name[i] = 'a';
name[1024] = 0;
for( i = 0 ; i < 1023 ; i++) {
file = fopen( &(name[i]), "w" );
if (!file && errno != ENAMETOOLONG && errno != ENOENT ) {
perror( "getfilenamelen" );
return -1; /* Error return */
}
if (file) break;
}
fclose(file);
for( ; i < 1023 ; i++) {
file = fopen( &(name[i]), "r" );
if (!file) break;
fclose(file);
}
unlink( &(name[i]) );
return 1025-i;
}
main() {
printf("Filename len is %d\n", getfilenamelen());
exit(1);
}
===============================Cut here===========================
--Harold
-- "Twas brillig and the slithy toves I'm Harold R. Zatz, a.k.a. "H". Did gyre and gimble in the wabe; Internet: hzatz@graphics.cornell.edu All mimsy were the borogoves, USmail: 232 Linden Ave. Apt. #2 And the mome raths, outgrabe..." Ithaca, NY 14850