covertr@force.UUCP (Richard E. Covert) (08/29/89)
... I am writing a backup program and I need to ask the user for the size of his floppy. There are many ways of doing this. One method is for the user to enter the decimal number of bytes per floppy (from a table shown on the screen). another way is to ask the user to enter the number of tracks per disk, number of sectors per track, and number of sides per disk. I perfer the latter. But, how do I calculate the amount of usable space based on the number of sectors, tracks, and sides?? Some of the disk is used by the directory, and I heard that there are some unused sectors at the end. So, what is a good formula for determining the size of a floppy?? I am writing this program in Mark Williams C, so I would perfer C code, but a simple formula is enough. tia richard (gtephx!covertr) covert
root@yale.UUCP (Root Of All Evil) (08/30/89)
In article <4552164d.14a1f@force.UUCP> covertr@force.UUCP (Richard E. Covert) writes: > >... > >I am writing a backup program and I need to ask the user for the >size of his floppy. There are many ways of doing this. One method is for >the user to enter the decimal number of bytes per floppy (from a table >shown on the screen). another way is to ask the user to enter the number of >tracks per disk, number of sectors per track, and number of sides per disk. >I perfer the latter. This information is all available in the boot sector. You just need to know where to look for it. It's the same as for MS-DOS, so you can look in Norton's book on the IBM-PC to learn how disks are structured. > But, how do I calculate the amount of usable space based on the >number of sectors, tracks, and sides?? Some of the disk is used by the >directory, and I heard that there are some unused sectors at the end. >So, what is a good formula for determining the size of a floppy?? Why do you want to? The Gemdos call "Dfree" tells you how much space is left. It's only if you want to bypass Gemdos and write to the sectors directly through Bios calls that you need to worry about such things. ================================================== | Michael Fischer | | Arpanet: <fischer-michael@cs.yale.edu> | | Bitnet: <fischer-michael@yalecs.bitnet> | | UUCP: <fischer-michael@yale.UUCP> | ==================================================
woodside@ttidca.TTI.COM (George Woodside) (08/31/89)
In article <4552164d.14a1f@force.UUCP> covertr@force.UUCP (Richard E. Covert) writes: > >... > But, how do I calculate the amount of usable space based on the >number of sectors, tracks, and sides?? Some of the disk is used by the >directory, and I heard that there are some unused sectors at the end. >So, what is a good formula for determining the size of a floppy?? > > I am writing this program in Mark Williams C, so I would perfer >C code, but a simple formula is enough. > >tia > >richard (gtephx!covertr) covert While testing Turtle, I wrote a formatter that can do anything possible to a disk's format, including marking bad clusters. This fragment should answer your questions: (Default values, replaced by actuals from your user input) int tracks = 80; /* tracks */ int sectors = 9; /* sectors per track */ int sides = 2; /* sides on disk */ int dir_size = 7; /* directory size */ int fat_size = 5; /* FAT size */ int sectors; /* total sectors */ long space; /* total useable space */ sectors = tracks * sides * sectors; /* total sectors */ sectors -= (dir_size + fat_size + fat_size + 1); /* less overhead */ sectors -= 4; /* less what GEMDOS will miss */ sectors &= ~1; /* round off odd sectors */ sectors -= 2 * err_clust; /* less bad clusters */ space = (long)sectors * 512L; /* change to bytes */ i = space / 1000; /* compute thousands */ space = space % 1000; /* and remainder */ printf("Space available: %d,%03ld\n", i, space); /* log disk space */ Now, the total number of sectors on the disk is available in the disk's boot sector, so you can avoid some of the calculating here. The directory size is there, too, as a number of entries. Note that all boot sector integers are byte swapped. Directory size and FAT size are variables that GEMDOS recognizes, and can vary from disk to disk. The number of FATs is always 2, and GEMDOS can not get at the last two clusters. Clusters are two sectors to GEMDOS, no matter what the boot sector says. This code is from my formatter, so it gets the number of bad clusters from some code in the track formatting logic. To determine the number of bad clusters on a user floppy, the simplest (although it is not very fast) way is to use the system Dfree call (that takes into consideration all the variables above, and reports the number of free clusters on the disk). There is no other way to determine the bad clusters except to read the FAT and examine the entries yourself, on a disk by disk basis. If you do this, be advised that the first two entries in the FAT must be ignored, no matter whether they are marked or not. If you are attempting to set up a global parameter, rather than the specifics for a particular disk, you'll have to assume that all the user's disks are formatted the same (believe me, this causes nearly unlimited trouble!), and none have any bad clusters (still more trouble!). Entries in directories require 32 bytes each, so a significant number of them are available in the root directory (112 for standard seven sector directories). Subdirectories are created and expanded in clusters. Creating a sub-directory requires one entry in its parent, and one cluster for the subdirectory. There are two overhead entries in the subdirectory (. and ..) so the first cluster can contain 30 entries. If a 31st entry is made, either as a file or another sub-directory, another cluster is allocated. Since the overhead (. and ..) only occur once, each additional sub-directory cluster will hold 32 entries. Sub directories do not expand until they have to - if you put 29 entries into the first cluster, and add one, the 30th one fits, and the additional cluster is not allocated. Only when the 31st entry (in the first cluster, 33rd in any additional cluster) is allocated does the expansion occur. Then, you lose one cluster from the data pool. Sub-directories never free up clusters. Clear as mud, right? :^) -- *George R. Woodside - Citicorp/TTI - Santa Monica, CA *Path: ..!{philabs|csun|psivax}!ttidca!woodside
woodside@ttidca.TTI.COM (George Woodside) (09/01/89)
In article <5735@ttidca.TTI.COM> I wrote WRONG: > The number of FATs is >always 2, and GEMDOS can not get at the last two clusters. Clusters are two >sectors to GEMDOS, no matter what the boot sector says. It is the number of FATs, not the cluster size, that is always 2. GEMDOS ignores the number of FATs parameter in the boot sector, and always deals with the disk as if it had 2 copies of the FAT. Cluster size is properly supported, and can vary from disk to disk. 2 is the merely the default cluster size. -- *George R. Woodside - Citicorp/TTI - Santa Monica, CA *Path: ..!{philabs|csun|psivax}!ttidca!woodside
covertr@force.UUCP (Richard E. Covert) (09/01/89)
In article <5735@ttidca.TTI.COM>, woodside@ttidca.TTI.COM (George Woodside) writes: > While testing Turtle, I wrote a formatter that can do anything possible > to a disk's format, including marking bad clusters. This fragment should > answer your questions: > > Clear as mud, right? :^) > -- > *George R. Woodside - Citicorp/TTI - Santa Monica, CA > *Path: ..!{philabs|csun|psivax}!ttidca!woodside Thanks George, that is EXACTLY what I was looking for. My application is part of a series of support programs for the FOREM ST BBS package. I want to write some programs to ease the use of FOREM. One important program is backing up the DOWNLOAD FILE sections of Forem. I will consider your points about the floppies (i.e. checking for bad clusters etc). My initial plan was to ask the user (SYSOP) for the size of his pre-formatted floppies (# of sides, tracks, and sectors), and then use that value to bundle the individual files into floppy-disk sized groups. Then each group of files would be copied to a pre-formatted floppy. Now, you are suggesting that I read the size of the floppy before writing to it. That changes my program because I wouldn't be able to group the files into disk-sized groups, because the disk size wouldn't be known until the copy takes place. I could do a sort and group for each fresh floppy but that would increase the time to perform the backup. Ity might be an idea though. Just ask the user to insert a fresh pre-formatted floppy , read its size, and then find XX files that would fill the floppy. Hmmmm, might work... Well thanks for your ideas!! richard (gtephx!covertr) covert