"Fossies" - the Fresh Open Source Software Archive

Member "ms-sys-2.7.0/src/partition_info.c" (20 Jun 2020, 3765 Bytes) of package /linux/privat/ms-sys-2.7.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "partition_info.c" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 2.4.1_vs_2.6.0.

    1 /******************************************************************
    2     Copyright (C) 2009  Henrik Carlqvist
    3 
    4     This program is free software; you can redistribute it and/or modify
    5     it under the terms of the GNU General Public License as published by
    6     the Free Software Foundation; either version 2 of the License, or
    7     (at your option) any later version.
    8 
    9     This program is distributed in the hope that it will be useful,
   10     but WITHOUT ANY WARRANTY; without even the implied warranty of
   11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   12     GNU General Public License for more details.
   13 
   14     You should have received a copy of the GNU General Public License
   15     along with this program; if not, write to the Free Software
   16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
   17 ******************************************************************/
   18 #include <stdio.h>
   19 
   20 #include "file.h"
   21 #include "fat16.h"
   22 #include "fat32.h"
   23 #include "exfat.h"
   24 #include "ntfs.h"
   25 #include "identify.h"
   26 #include "partition_info.h"
   27 
   28 int write_partition_number_of_heads(FILE *fp, int iHeads)
   29 {
   30    unsigned char aucBuf[2];
   31    unsigned short s = (iHeads < 0) ? partition_number_of_heads(fp) : (unsigned short)iHeads;
   32 
   33    if(!s)
   34       return 0;
   35    /* Converting a number like this is not necessary as long as we are on
   36       i386 compatible CPUs, however, the following code might make the program
   37       more portable... */
   38    aucBuf[0] = (unsigned char)(s & 0xff);
   39    aucBuf[1] = (unsigned char)((s & 0xff00) >> 8);
   40    return write_data(fp, 0x1a, aucBuf, 2);
   41 } /* write_partition_number_of_heads */
   42 
   43 #ifdef __OpenBSD__
   44 int write_partition_start_sector_number(FILE *fp, const char *szPath)
   45 #else
   46 int write_partition_start_sector_number(FILE *fp)
   47 #endif
   48 {
   49 #ifdef __OpenBSD__
   50    unsigned long l = partition_start_sector(fp, szPath);
   51 #else
   52    unsigned long l = partition_start_sector(fp);
   53 #endif
   54 
   55    if(!l)
   56       return 0;
   57    /* Converting a number like this is not necessary as long as we are on
   58       i386 compatible CPUs, however, the following code might make the program
   59       more portable... */
   60     if((is_fat_16_fs(fp)) || (is_fat_32_fs(fp)) || is_ntfs_fs(fp)) {
   61         unsigned char aucBuf[4];
   62         aucBuf[0] = (unsigned char)(l & 0xff);
   63         aucBuf[1] = (unsigned char)((l & 0xff00) >> 8);
   64         aucBuf[2] = (unsigned char)((l & 0xff0000) >> 16);
   65         aucBuf[3] = (unsigned char)((l & 0xff000000) >> 24);
   66         return write_data(fp, 0x1c, aucBuf, 4);
   67     }
   68     if(is_exfat_fs(fp)) {
   69         unsigned char aucBuf[8];
   70         aucBuf[0] = (unsigned char)(l & 0xff);
   71         aucBuf[1] = (unsigned char)((l & 0xff00) >> 8);
   72         aucBuf[2] = (unsigned char)((l & 0xff0000) >> 16);
   73         aucBuf[3] = (unsigned char)((l & 0xff000000) >> 24);
   74         aucBuf[4] = (unsigned char)((l & 0xff00000000) >> 32);
   75         aucBuf[5] = (unsigned char)((l & 0xff0000000000) >> 40);
   76         aucBuf[6] = (unsigned char)((l & 0xff000000000000) >> 48);
   77         aucBuf[7] = (unsigned char)((l & 0xff00000000000000) >> 56);
   78         return write_data(fp, 0x40, aucBuf, 8);
   79     } else {
   80         return 0;
   81     }
   82 } /* write_partition_start_sector_number */
   83 
   84 int write_partition_physical_disk_drive_id_fat16(FILE *fp)
   85 {
   86     unsigned char ucId = 0x80; /* C: */
   87     
   88     return write_data(fp, 0x24, &ucId, 1);
   89 } /* write_partition_physical_disk_drive_id_fat16 */
   90 
   91 int write_partition_physical_disk_drive_id_fat32(FILE *fp)
   92 {
   93    unsigned char ucId = 0x80; /* C: */
   94    
   95    return write_data(fp, 0x40, &ucId, 1);
   96 } /* write_partition_physical_disk_drive_id_fat32 */
   97 
   98 int write_partition_physical_disk_drive_id_exfat(FILE *fp)
   99 {
  100    unsigned char ucId = 0x80; /* C: */
  101    
  102    return write_data(fp, 0x6f, &ucId, 1);
  103 } /* write_partition_physical_disk_drive_id_exfat */