Article View: comp.os.msdos.programmer
Article #1850Re: Unique file determination
From: Frank Whaley
Date: Fri, 10 Aug 1990 02:00
Date: Fri, 10 Aug 1990 02:00
84 lines
2589 bytes
2589 bytes
In article <1990Aug9.193919.2996@caen.engin.umich.edu>,
mrice@caen.engin.umich.edu (Michael Rice) writes:
>What I want to do is store some type of file indentifier for each file
>so when I get a new file I can create this identified and check it
>against the identifiers for my other files. If they match then I would
>know that file is a duplicate.
On Unix, the stat() function produces a unique device and inode number
for each file. Unfortunately, MS-DOS implementations of stat() typically
do not produce unique numbers. Some time back I posted a replacement
stat() function which used the "Parent Directory Cluster Number" and
"Entry Count In Directory" fields from the ffblk structure to produce
a unique inode number. This has worked well enough for me -- I haven't
received any bug reports about missing "File in use" messages since
the change.
The following code demonstrates fetching these magic numbers.
-----
#include <dir.h>
extern unsigned char _osmajor;
extern unsigned char _osminor;
/*
* devino - simulate fetching device and inode for MSDOS
*/
int
devino(filename, device, inode)
char *filename;
int *device;
long *inode;
{
int *ec; /* entry count in directory */
int *pc; /* parent dir cluster number */
int osver = (_osmajor * 10) + _osminor;
struct ffblk ff;
/* get information from directory entry */
if ( findfirst(filename, &ff, 0x17) != 0 )
{
return ( -1 );
}
ec = (int *)&ff.ff_reserved[13];
pc = (int *)&ff.ff_reserved[(osver >= 32) ? 15 : 19];
*device = ff.ff_reserved[(osver > 20) ? 0 : 1];
*inode = ((long)*pc << 16) + *ec;
return ( 0 );
}
#ifdef TEST
int
main(argc, argv)
int argc;
char *argv[];
{
int i;
int device;
long inode;
for ( i = 1; i < argc; i++ )
{
if ( devino(argv[i], &device, &inode) < 0 )
{
printf("%s: devino error\n", argv[i]);
}
else
{
printf("%s: %d %ld\n", argv[i], device, inode);
}
}
}
#endif
--
Frank Whaley
Senior Development Engineer
Quadratron Systems Incorporated
few@quad1.quad.com
uunet!ccicpg!quad1!few
Water separates the people of the world;
Wine unites them.
Technical Details
Message-ID:
<14320@gouda.quad.com>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rutgers!usc!srhqla!quad1!fewReferences:
<1990Aug9.193919.2996@caen.engin.umich.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rutgers!usc!srhqla!quad1!few From: few@quad1.quad.com (Frank Whaley) Newsgroups: comp.os.msdos.programmer Subject: Re: Unique file determination Keywords: Turbo C Checksums Message-ID: <14320@gouda.quad.com> Date: 10 Aug 90 02:00:35 GMT References: <1990Aug9.193919.2996@caen.engin.umich.edu> Organization: Quadratron Systems, Westlake Village, CA Lines: 84