"Fossies" - the Fresh Open Source Software Archive

Member "ms-sys-2.7.0/src/ntfs.c" (26 Feb 2012, 2282 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 "ntfs.c" see the Fossies "Dox" file reference documentation.

    1 /******************************************************************
    2     Copyright (C) 2012  Pete Batard <pete@akeo.ie>
    3     Based on fat16.c Copyright (C) 2009  Henrik Carlqvist
    4 
    5     This program is free software; you can redistribute it and/or modify
    6     it under the terms of the GNU General Public License as published by
    7     the Free Software Foundation; either version 2 of the License, or
    8     (at your option) any later version.
    9 
   10     This program is distributed in the hope that it will be useful,
   11     but WITHOUT ANY WARRANTY; without even the implied warranty of
   12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   13     GNU General Public License for more details.
   14 
   15     You should have received a copy of the GNU General Public License
   16     along with this program; if not, write to the Free Software
   17     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
   18 ******************************************************************/
   19 
   20 #include <stdio.h>
   21 #include <string.h>
   22 
   23 #include "file.h"
   24 #include "ntfs.h"
   25 
   26 int is_ntfs_fs(FILE *fp)
   27 {
   28    unsigned char aucMagic[] = {'N','T','F','S',' ',' ',' ',' '};
   29 
   30    return contains_data(fp, 0x03, aucMagic, sizeof(aucMagic));
   31 } /* is_ntfs_fs */
   32 
   33 int is_ntfs_br(FILE *fp)
   34 {
   35    /* A "file" is probably some kind of NTFS boot record if it contains the
   36       magic chars 0x55, 0xAA at positions 0x1FE */
   37    unsigned char aucRef[] = {0x55, 0xAA};
   38    unsigned char aucMagic[] = {'N','T','F','S',' ',' ',' ',' '};
   39 
   40    if( ! contains_data(fp, 0x1FE, aucRef, sizeof(aucRef)))
   41       return 0;
   42    if( ! contains_data(fp, 0x03, aucMagic, sizeof(aucMagic)))
   43       return 0;
   44    return 1;
   45 } /* is_ntfs_br */
   46 
   47 int entire_ntfs_br_matches(FILE *fp)
   48 {
   49    #include "br_ntfs_0x0.h"
   50    #include "br_ntfs_0x54.h"
   51 
   52    return
   53       ( contains_data(fp, 0x0, br_ntfs_0x0, sizeof(br_ntfs_0x0)) &&
   54     /* BIOS Parameter Block might differ between systems */
   55     contains_data(fp, 0x54, br_ntfs_0x54, sizeof(br_ntfs_0x54)) );
   56 } /* entire_ntfs_br_matches */
   57 
   58 int write_ntfs_br(FILE *fp)
   59 {
   60    #include "br_ntfs_0x0.h"
   61    #include "br_ntfs_0x54.h"
   62 
   63    return
   64      ( write_data(fp, 0x0, br_ntfs_0x0, sizeof(br_ntfs_0x0)) &&
   65        /* BIOS Parameter Block should not be overwritten */
   66        write_data(fp, 0x54, br_ntfs_0x54, sizeof(br_ntfs_0x54)) );
   67 } /* write_ntsf_br */