Foros del Web » Soporte técnico » Windows »

Estructura de $BadClus en NTFS

Estas en el tema de Estructura de $BadClus en NTFS en el foro de Windows en Foros del Web. ¿Alguien conoce la estructura del archivo oculto $BadClus en el sistema de ficheros NTFS de Windows? Este archivo en mi disco duro tiene longitud 0 ...
  #1 (permalink)  
Antiguo 12/07/2008, 14:00
 
Fecha de Ingreso: junio-2008
Mensajes: 12
Antigüedad: 15 años, 10 meses
Puntos: 1
Estructura de $BadClus en NTFS

¿Alguien conoce la estructura del archivo oculto $BadClus en el sistema de ficheros NTFS de Windows?

Este archivo en mi disco duro tiene longitud 0 ya que no tengo sectores defectuosos y por tanto, no puedo saber su estructura.
En Google no sale nada de la estructura. Como mucho se dice que almacena la tabla de clusters defectuosos en cada partición del disco duro.

Me interesa saber la estructura de almacenamiento de las entradas para cada cluster, para hacer un programa de verificación de discos duros.

Última edición por wyxchari; 14/07/2008 a las 04:30
  #2 (permalink)  
Antiguo 14/07/2008, 03:57
 
Fecha de Ingreso: junio-2008
Mensajes: 12
Antigüedad: 15 años, 10 meses
Puntos: 1
Estructura de $BadClus en NTFS

Por fin encuentro algo:
http://www.cse.scu.edu/~tschwarz/COEN152_06/Lectures/NTFS.html
http://www.cse.scu.edu/~tschwarz/coen152_05/PPtPre/NTFSFS.ppt
http://data.linux-ntfs.org/ntfsdoc.pdf

Me pillo un pendrive (en mi caso de 1Gb) y lo formateo a FAT simple (tb llamado FAT16), ya que Windows no deja formatear unidades pequeñas a NTFS.

Ahora marco un cluster, el 24, como defectuoso (tranquilo que con un simple formato se borra la marca de defectuoso):
Luego en WinHex, abro la unidad del pendrive como disco lógico.
En Posición, Ir a registro FAT, meto cluster 24, escribo 2 bytes: F7 FF.
Pulso FAT2, voy al cluster 24 y meto igual: F7 FF.
Guardo cambios y cierro WinHex.

Convierto a NTFS desde el Símbolo del sistema:
convert u: /fs:ntfs

Abro de nuevo la unidad en WinHex y voilá, ya tengo una unidad ntfs con clusters defectuosos. Es lo que necesitaba para conocer la estructura de BadClus.

Veamos en FAT tenía el cluster 24 defectuoso que se corresponde con los sectores 1232-1263.
Ahora en NTFS tengo los clusters 154-157 defectuosos que se corresponden con los mismos sectores por supuesto y comprobado.

El archivo $BadClus:$Bad contiene los datos de los clusters defectuosos de todo el disco. Con un tamaño de 16Kb empieza en el sector 1232. Ok.

El archivo \$Bitmap contiene una representación de todos los clusters del disco a nivel de bit. Muestro el principio del archivo:
1EA8A000 FF FF FF FF FF FF FF FF 07 00 00 00 00 00 00 00 ÿÿÿÿÿÿÿÿ........
1EA8A010 00 00 00 3C 00 00 00 00 00 00 00 00 00 00 00 00 ...<............
Se observa que el byte 3C (00111100 en binario) debe corresponder con los 4 clusters 154-157 marcados como defectuosos. En este archivo un bit 0 indica disponible y un bit 1 indica no disponible. Si multiplicamos el desplazamiento del 3C que es 19 bytes, por 8 bit que tiene cada byte, sale 152, más los 2 bit 0 finales del 3C tenemos el cluster 154. Es decir, 3C = 00111100 y los bit en orden son los clusters 0-159, 0-158, 1-157, 1-156, 1-155, 1-154. 0- 153, 0-152. Vemos también que los clusters 1-64 estan ocupados (son los FF) y los 65-67 (es el 07).

Podemos utilizar el archivo \$Bitmap para marcar los clusters defectuosos simulando que están ocupados, poniendo a 1 los bits correspondientes. El problema es que con chkdsk u: saldrán errores de espacio no asignado y nos indicará que pongamos chkdsk u: /f para corregirlo restableciendo así estos bits a 0. Podemos ignorarlo y listo.

Estructura de una MFT record:
Cabecera MFT
Cabecera de atributo
Atributo STANDAR_INFORMATION
Cabecera de atributo
Atributo FILE_NAME
Cabecera de atributo
Atributo DATA
Espacio no usado

MFT Record Structure:
0x00-0x03: Magic Number: "FILE"
0x04-0x05: Offset to the update sequence.
0x06-0x07: Number of entries in fixup array
0x08-0x0f: $LogFile Sequence Number (LSN)
0x10-0x11: Sequence number
0x12-0x13: Hard link count
0x14-0x15: Offset to first attribute
0x16-0x17: Flags: 0x01: record in use, 0x02 directory.
0x18-0x1b: Used size of MFT entry
0x1c-0x1f: Allocated size of MFT entry.
0x20-0x27: File reference to the base FILE record
0x28-0x29: Next attribute ID
0x2a-0x2b: (XP) Align to 4B boundary
0x2c-0x2f: (XP) Number of this MFT record
0x30-0x100: Attributes and fixup value

Números reservados de las MFT record:
1 Master file table $MFT.
2 Master file table mirror $MftMirr.
3 Log file $LogFile.
4 Volume $Volume Attribute definitions $AttrDef.
5 The root folder “.”
6 Cluster bitmap $Bitmap
7 Boot sector $Boot (located at the beginning of partition)
8 Bad cluster file $BadClus
9 Security file $Secure
10 Upcase table $Upcase
11 NTFS extension file $Extend, that is used for future use.

MFT List of possible attributes:
Defined in $AttrDef entry of MFT, but default is:
0x10 STANDARD_INFORMATION
0x20 $ATTRIBUTE_LIST
0x30 $FILE_NAME0
0x40 (NT) $VOLUME_VERSION (2K) $OBJECT_ID
0x50 $SECURITY_DESCRIPTOR
0x60 $VOLUME_NAME
0x70 $VOLUME_INFORMATION
0x80 $DATA
0x90 $INDEX_ROOT
0xA0 $INDEX_ALLOCATION
0xB0 $BITMAP
0xC0 (NT) $SYMBOLIC_LINK, (2K) $REPARSE_POINT
0xD0 $EA_INFORMATION
0xE0 $EA
0xF0 NT$PROPERTY_SET
0x100 (2K) $LOGGED_UTILITY_STREAM

MFT Attribute Layout:
0x00 Attribute Type Identifier
0x04 Length of Attribute
0x08 non-resident flag
0x09 length of name
0x0a offset to name
0x0c flags
0x0e Attribute Identifier
0x10

Si es residente 0x08=0:
0x10 Size of content
0x14 Offset to content
0x16 Indexed flag
0x17 Padding
0x18

Si es no residente 0x08=1:
0x10 Starting Virtual Cluster Number of the runlist
0x18 Ending Virtual Cluster Number of the runlist
0x20 Offset to the runlist
0x22 Compression unit size
0x24 Unused
0x28 Allocated size of the attribute content
0x30 Actual size of attribute content
0x38 Initialized size of the attribute content
0x40

STANDAR Info Attribute:
0x00 C Time - File Creation
0x08 A Time - File Altered
0x10 M Time - MFT Changed
0x18 R Time - File Read
0x20 DOS File Permissions
0x24 Maximum Number of Versions
0x28 Version Number
0x2C Class Id
0x30 Owner Id 2K
0x34 Security Id 2K
0x38 Quota Charged 2K
0x40 Update Sequence Number (USN) 2K
0x48

$FILE_NAME attribute:
0x00 File Reference to parent directory
0x08 File creation time.
0x10 File modification time
0x18 MFT modification time
0x20 File access time.
0x28 Allocated size of file
0x30 Real size of file
0x38 Flags
0x3c Used by EAs and Reparse
0x40 Filename length in unicode characters
0x41 Filename namespace
0x42 File Name in Unicode

El archivo \$BadClus:
00000000 46 49 4C 45 30 00 03 00 6A 10 20 00 00 00 00 00 FILE0...j. .....
00000010 08 00 01 00 38 00 01 00 80 01 00 00 00 04 00 00 ....8...€.......
00000020 00 00 00 00 00 00 00 00 05 00 00 00 08 00 00 00 ................
00000030 02 00 00 00 00 00 00 00 10 00 00 00 60 00 00 00 ............`...
00000040 00 00 18 00 00 00 00 00 48 00 00 00 18 00 00 00 ........H.......
00000050 20 04 0F 95 42 E6 C8 01 20 04 0F 95 42 E6 C8 01 ..•BæÈ. ..•BæÈ.
00000060 20 04 0F 95 42 E6 C8 01 20 04 0F 95 42 E6 C8 01 ..•BæÈ. ..•BæÈ.
00000070 06 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000080 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 ................
00000090 00 00 00 00 00 00 00 00 30 00 00 00 70 00 00 00 ........0...p...
000000A0 00 00 18 00 00 00 03 00 52 00 00 00 18 00 01 00 ........R.......
000000B0 05 00 00 00 00 00 05 00 20 04 0F 95 42 E6 C8 01 ........ ..•BæÈ.
000000C0 20 04 0F 95 42 E6 C8 01 20 04 0F 95 42 E6 C8 01 ..•BæÈ. ..•BæÈ.
000000D0 20 04 0F 95 42 E6 C8 01 00 00 00 00 00 00 00 00 ..•BæÈ.........
000000E0 00 00 00 00 00 00 00 00 06 00 00 00 00 00 00 00 ................
000000F0 08 03 24 00 42 00 61 00 64 00 43 00 6C 00 75 00 ..$.B.a.d.C.l.u.
00000100 73 00 00 00 00 00 00 00 80 00 00 00 18 00 00 00 s.......€.......
00000110 00 00 18 00 00 00 02 00 00 00 00 00 18 00 00 00 ................
00000120 80 00 00 00 58 00 00 00 01 04 40 00 00 00 01 00 €...X.....@.....
00000130 00 00 00 00 00 00 00 00 FE D4 03 00 00 00 00 00 ........þÔ......
00000140 48 00 00 00 00 00 00 00 00 F0 4F 3D 00 00 00 00 H........ðO=....
00000150 00 F0 4F 3D 00 00 00 00 00 00 00 00 00 00 00 00 .ðO=............
00000160 24 00 42 00 61 00 64 00 02 9A 00 21 04 9A 00 03 $.B.a.d..š.!.š..
00000170 61 D4 03 00 00 00 00 00 FF FF FF FF 00 00 00 00 aÔ......ÿÿÿÿ....
00000180 80 00 00 00 18 00 00 00 00 00 18 00 00 00 02 00 €...............
00000190 00 00 00 00 18 00 00 00 80 00 00 00 58 00 00 00 ........€...X...
000001A0 01 04 40 00 00 00 01 00 00 00 00 00 00 00 00 00 ..@.............
000001B0 FE D4 03 00 00 00 00 00 48 00 00 00 00 00 00 00 þÔ......H.......
000001C0 00 F0 4F 3D 00 00 00 00 00 F0 4F 3D 00 00 00 00 .ðO=.....ðO=....
000001D0 00 00 00 00 00 00 00 00 24 00 42 00 61 00 64 00 ........$.B.a.d.
000001E0 02 9A 00 21 04 9A 00 03 61 D4 03 00 00 00 00 00 .š.!.š..aÔ......
000001F0 FF FF FF FF 00 00 00 00 00 00 00 00 00 00 02 00 ÿÿÿÿ............

Última edición por wyxchari; 15/07/2008 a las 13:06
  #3 (permalink)  
Antiguo 15/07/2008, 00:59
 
Fecha de Ingreso: junio-2008
Mensajes: 12
Antigüedad: 15 años, 10 meses
Puntos: 1
Estructura de $BadClus en NTFS

Analicemos. Muchas entradas parecen no tener utilidad.
Si alguna vez llegaste a entender la FAT y te pareció farragoso, el NTFS te va a dar hasta mareos. XDDD

MFT Record header:
00000000 46 49 4C 45 30 00 03 00 6A 10 20 00 00 00 00 00 FILE0...j. .....
00000010 08 00 01 00 38 00 01 00 80 01 00 00 00 04 00 00 ....8...€.......
00000020 00 00 00 00 00 00 00 00 05 00 00 00 08 00 00 00 ................
00000030 02 00 00 00 00 00 00 00
0x00-0x03: Magic Number: "FILE": 46 49 4C 45 <=================
Con esto vemos que se trata de una entrada MFT.
0x04-0x05: Offset to the update sequence: 30 00
0x06-0x07: Number of entries in fixup array: 03 00
0x08-0x0f: $LogFile Sequence Number (LSN): 6A 10 20 00 00 00 00 00
0x10-0x11: Sequence number: 08 00
0x12-0x13: Hard link count: 01 00
0x14-0x15: Offset to first attribute: 38 00 <========================
Este nos interesa ya que indica donde termina la MFT record header o cabecera y comienzan los atributos.
0x16-0x17: Flags: 0x01: record in use, 0x02 directory: 01 00
0x18-0x1b: Used size of MFT entry: 80 01 00 00 <====================
Indica donde termina la MFT record, 180h.
0x1c-0x1f: Allocated size of MFT entry: 00 04 00 00 <==================
Indica el espacio en disco que usa la MFT record. 400h, 1Kb o 2 sectores.
0x20-0x27: File reference to the base FILE record: 00 00 00 00 00 00 00 00
0x28-0x29: Next attribute ID: 05 00
0x2a-0x2b: (XP) Align to 4B boundary: 00 00
0x2c-0x2f: (XP) Number of this MFT record: 08 00 00 00 <================
Esto nos indica que se trata de una MFT record reservada, la BadClus.
0x30-0x100: Attributes and fixup value: 02 00 00 00 00 00 00 00

Cabecera atributo residente STANDAR:
00000030 XX XX XX XX XX XX XX XX 10 00 00 00 60 00 00 00 ............`...
00000040 00 00 18 00 00 00 00 00 48 00 00 00 18 00 00 00 ........H.......
0x00 Attribute Type Identifier: 10 00 00 00
El 10 indica que es el atributo STANDAR.
0x04 Length of Attribute: 60 00 00 00 <===========
Indica la longitud de este atributo y empieza el siguiente.
0x08 non-resident flag: 00 <=============
Indica que la información se guarda dentro del MFT y no en clusters externos. Los archivos menores de 900 bytes se guardan aquí.
Si es 01 indica que no es residente y se usan otros clusters para guardar la información.
0x09 length of name: 00
0x0a offset to name: 18 00 <============
Indica el comienzo de los datos del atributo.
0x0c flags: 00 00
0x0e Attribute Identifier: 00 00
0x10 Size of content: 48 00 00 00
0x14 Offset to content: 18 00
0x16 Indexed flag: 00
0x17 Padding: 00

Atributo STANDAR:
00000050 20 04 0F 95 42 E6 C8 01 20 04 0F 95 42 E6 C8 01 ..•BæÈ. ..•BæÈ.
00000060 20 04 0F 95 42 E6 C8 01 20 04 0F 95 42 E6 C8 01 ..•BæÈ. ..•BæÈ.
00000070 06 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000080 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 ................
00000090 00 00 00 00 00 00 00 00
0x00 File Creation Time: 20 04 0F 95 42 E6 C8 01
0x08 File Alteration Time: 20 04 0F 95 42 E6 C8 01
0x10 MFT Change: 20 04 0F 95 42 E6 C8 01
0x18 File Read Time: 20 04 0F 95 42 E6 C8 01
0x20 DOS File Permissions: 06 00 00 00
0x24 Maximum number of versions: 00 00 00 00
0x28 Version number: 00 00 00 00
0x2C Class ID: 00 00 00 00
0x30 Owner Id 2K: 00 00 00 00
0x34 Security Id 2K: 00 01 00 00
0x38 Quota Charged 2K: 00 00 00 00 00 00 00 00
0x40 Update Sequence Number (USN) 2K: 00 00 00 00 00 00 00 00
0x48

Cabecera atributo residente FILE_NAME:
00000090 XX XX XX XX XX XX XX XX 30 00 00 00 70 00 00 00 ........0...p...
000000A0 00 00 18 00 00 00 03 00 52 00 00 00 18 00 01 00 ........R.......
0x00 Attribute Type Identifier: 30 00 00 00
Indica que el atributo es FILE_NAME.
0x04 Length of Attribute: 70 00 00 00 <============
Indica la longitud y donde comienza el siguiente atributo.
0x08 non-resident flag: 00
0x09 length of name: 00
0x0a offset to name: 18 00 <==========
Indica donde comienzan los datos.
0x0c flags: 00 00
0x0e Attribute Identifier: 03 00
0x10 Size of content: 52 00 00 00
0x14 Offset to content: 18 00
0x16 Indexed flag: 01
0x17 Padding: 00

Atributo FILE_NAME:
000000B0 05 00 00 00 00 00 05 00 20 04 0F 95 42 E6 C8 01 ........ ..•BæÈ.
000000C0 20 04 0F 95 42 E6 C8 01 20 04 0F 95 42 E6 C8 01 ..•BæÈ. ..•BæÈ.
000000D0 20 04 0F 95 42 E6 C8 01 00 00 00 00 00 00 00 00 ..•BæÈ.........
000000E0 00 00 00 00 00 00 00 00 06 00 00 00 00 00 00 00 ................
000000F0 08 03 24 00 42 00 61 00 64 00 43 00 6C 00 75 00 ..$.B.a.d.C.l.u.
00000100 73 00 00 00 00 00 00 00 XX XX XX XX XX XX XX XX s.......€.......
0x00 File reference to parent directory: 05 00 00 00 00 00 05 00
0x08 File creation time: 20 04 0F 95 42 E6 C8 01
0x10 File modification time: 20 04 0F 95 42 E6 C8 01
0x18 MFT modification time: 20 04 0F 95 42 E6 C8 01
0x20 File access time: 20 04 0F 95 42 E6 C8 01
0x28 Allocated size of file: 00 00 00 00 00 00 00 00
0x30 Real size of file: 00 00 00 00 00 00 00 00
0x38 Flags: 06 00 00 00
0x3c Used by EAs and Reparse: 00 00 00 00
0x40 Filename length in unicode characters: 08
0x41 Filename namespace: 03
0x42 File name in unicode: 24 00 42 00 61 00 64 00 43 00 6C 00 75 00 73 00 00 00 00 00 00 00

Cabecera atributo residente DATA 1º:
00000100 XX XX XX XX XX XX XX XX 80 00 00 00 18 00 00 00 s.......€.......
00000110 00 00 18 00 00 00 02 00 00 00 00 00 18 00 00 00 ................
0x00 Attribute Type Identifier: 80 00 00 00
Indica que el atributo es DATA.
0x04 Length of Attribute: 18 00 00 00 <============
Indica la longitud y donde comienza el siguiente atributo.
0x08 non-resident flag: 00
0x09 length of name: 00
0x0a offset to name: 18 00 <==========
Indica donde comienzan los datos.
0x0c flags: 00 00
0x0e Attribute Identifier: 02 00
0x10 Size of content: 00 00 00 00
0x14 Offset to content: 18 00
0x16 Indexed flag: 00
0x17 Padding: 00

Datos del DATA: vacío

Cabecera atributo no residente DATA 2º:
00000120 80 00 00 00 58 00 00 00 01 04 40 00 00 00 01 00 €...X.....@.....
00000130 00 00 00 00 00 00 00 00 FE D4 03 00 00 00 00 00 ........þÔ......
00000140 48 00 00 00 00 00 00 00 00 F0 4F 3D 00 00 00 00 H........ðO=....
00000150 00 F0 4F 3D 00 00 00 00 00 00 00 00 00 00 00 00 .ðO=............
0x00 Attribute Type Identifier: 80 00 00 00
Indica que el atributo es DATA.
0x04 Length of Attribute: 58 00 00 00 <============
Indica la longitud y donde comienza el siguiente atributo.
0x08 non-resident flag: 01 <===================================
Indica que los datos no estarán dentro del MFT sino en un fichero.
0x09 length of name: 04
0x0a offset to name: 40 00 <=============
Nombre del archivo.
Indica donde comienzan los datos.
0x0c flags: 00 00
0x0e Attribute Identifier: 01 00
0x10 Starting Virtual Cluster Number of the runlist: 00 00 00 00 00 00 00 00
0x18 Ending Virtual Cluster Number of the runlist: FE D4 03 00 00 00 00 00
0x20 Offset to the runlist: 48 00 <========
Tabla runlist.
0x22 Compression unit size: 00 00
0x24 Unused: 00 00 00 00
0x28 Allocated size of the attribute content: 00 F0 4F 3D 00 00 00 00
0x30 Actual size of attribute content: 00 F0 4F 3D 00 00 00 00
0x38 Initialized size of the attribute content: 00 00 00 00 00 00 00 00
0x40

Datos del DATA 2º:
00000160 24 00 42 00 61 00 64 00 02 9A 00 21 04 9A 00 03 $.B.a.d..š.!.š..
00000170 61 D4 03 00 00 00 00 00
Name: 24 00 42 00 61 00 64 00 $Bad
Runlist: 02 9A 00 21 04 9A 00 03 61 D4 03 00 00 00 00 00

Estructura de runlist:
Size of the Offset field
Size of the Length field
Length of the run
Offset to the starting LCN of the previous element

Decodificando runlist: hay 3 bloques sobre toda la unidad:
Bloque inicial: 02 9A 00:
02: 0 indica el tamaño del offset (0 bytes). 2 indica el tamaño de la longitud (2 bytes).
009Ah (154) clusters desde el cluster 0 al cluster 009Ah (154).
Bloque intermedio: 21 04 9A 00:
21: 2 indica el tamaño del offset (2 bytes). 1 indica el tamaño de la longitud (1 bytes).
4 clusters desde el 009Ah (154) al 009Dh (158).
Bloque final: 03 61 D4 03:
03: 0 indica el tamaño del offset (0 bytes). 3 indica el tamaño de la longitud (3 bytes).
03D461h clusters desde el cluster 009D (158) hasta el final de la unidad 03D4FEh.

00000170 XX XX XX XX XX XX XX XX FF FF FF FF XX XX XX XX aÔ......ÿÿÿÿ....
Los FF FF FF FF indican el final de la entrada BadClus.

Última edición por wyxchari; 15/07/2008 a las 09:50
  #4 (permalink)  
Antiguo 15/07/2008, 07:41
 
Fecha de Ingreso: junio-2008
Mensajes: 12
Antigüedad: 15 años, 10 meses
Puntos: 1
Estructura de $BadClus en NTFS

Me duele ya la cabeza.

Si se me jode un disco C: NTFS, no le marco sectores defectuosos, me compro otro disco.

El disco malo lo formateo a FAT32, marco los defectuosos y lo uso para grabar pelis. O después de marcar lo convierto a NTFS con convert u: /fs:ntfs.

Última edición por wyxchari; 18/07/2008 a las 06:26
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 07:46.