representaciÓn interna de ficheros

21
SISTEMA DE FICHEROS UNIX J. Santos 29 REPRESENTACIÓN INTERNA DE FICHEROS Inodos Existe un inodo para cada fichero del disco. Los inodos se encuentran: o En disco, en la lista de inodos. o En memoria, en la tabla de inodos, de estructura semejante al buffer cache. Detalles: El núcleo asigna inodos en llamadas del tipo open. Los inodos en memoria quedan libres cuando no hay ningún proceso que tenga abierto el fichero correspondiente al inodo. Funcionamiento análogo al buffer cache: algoritmos iget, iput (getblk, brelse). Inodo en disco PROPIETARIO GRUPO TIPO DE FICHERO PERMISOS DE ACCESO FECHAS: acceso, escritura, modificación inodo NÚMERO DE LINKS TAMAÑO DIRECCIONES DE DISCO Inodo en memoria COPIA INODO DISCO ESTADO NÚMERO DE DISPOSITIVO NÚMERO DE INODO PUNTEROS A COLAS HASH Y FREE LIST CONTADOR DE REFERENCIAS

Upload: buitruc

Post on 10-Jan-2017

234 views

Category:

Documents


4 download

TRANSCRIPT

Page 1: REPRESENTACIÓN INTERNA DE FICHEROS

SISTEMA DE FICHEROS UNIX J. Santos

29

REPRESENTACIÓN INTERNA DE FICHEROS

Inodos

• Existe un inodo para cada fichero del disco.

• Los inodos se encuentran:

o En disco, en la lista de inodos.

o En memoria, en la tabla de inodos, de estructura semejante al buffer cache.

Detalles:

• El núcleo asigna inodos en llamadas del tipo open.

• Los inodos en memoria quedan libres cuando no hay ningún proceso que tenga abierto el fichero correspondiente al inodo.

• Funcionamiento análogo al buffer cache: algoritmos iget, iput (getblk, brelse).

Inodo en disco

PROPIETARIO

GRUPO

TIPO DE FICHERO

PERMISOS DE ACCESO

FECHAS: acceso, escritura,

modificación inodo

NÚMERO DE LINKS

TAMAÑO

DIRECCIONES DE DISCO

Inodo en memoria

COPIA INODO DISCO

ESTADO

NÚMERO DE DISPOSITIVO

NÚMERO DE INODO

PUNTEROS A COLAS HASH

Y FREE LIST

CONTADOR DE

REFERENCIAS

Page 2: REPRESENTACIÓN INTERNA DE FICHEROS

SISTEMA DE FICHEROS UNIX J. Santos

30

Estructura de un fichero

• Cada fichero tiene asociado:

o Un inodo de la lista de inodos.

o Bloques del área de datos. Lo bloques del fichero figuran como información del inodo, con el siguiente esquema de acceso:

Detalles:

• Con bloques de 1K y direcciones de 4 bytes, el tamaño máximo resulta: 10K + 256K + 64M + 16G

• Acceso más lento a ficheros grandes.

Direcciones de disco en el inodo

[Tanenbaum, 2003]

Esquema de las principales estructuras del núcleo referentes al sistema de ficheros (Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7th Edition, Feb 6, 2005)

Page 3: REPRESENTACIÓN INTERNA DE FICHEROS

SISTEMA DE FICHEROS UNIX J. Santos

31

ALGORITMO bmap

Page 4: REPRESENTACIÓN INTERNA DE FICHEROS

SISTEMA DE FICHEROS UNIX J. Santos

32

ALGORITMO iget

Page 5: REPRESENTACIÓN INTERNA DE FICHEROS

SISTEMA DE FICHEROS UNIX J. Santos

33

ALGORITMO iput

Page 6: REPRESENTACIÓN INTERNA DE FICHEROS

SISTEMA DE FICHEROS UNIX J. Santos

34

Directorios

• Un directorio es un fichero cuyo contenido se interpreta como “entradas de directorio”.

• Formato de entradas de directorio:

En BSD:

Número inodo (4 bytes)

Longitud entrada (2 bytes)

Longitud nombre (2 bytes)

Nombre (terminado en '\0' hasta una longitud múltiplo de 4) (variable)

En System V:

Nombre (14 bytes)

Número inodo (2 bytes)

Page 7: REPRESENTACIÓN INTERNA DE FICHEROS

SISTEMA DE FICHEROS UNIX J. Santos

35

Ejemplo de pasos necesarios en la búsqueda del inodo de /usr/ast/correo

[Tanenbaum, 2003]

Page 8: REPRESENTACIÓN INTERNA DE FICHEROS

SISTEMA DE FICHEROS UNIX J. Santos

36

CREACIÓN DE FICHEROS. ASIGNACIÓN DE INODOS Y BLOQUES

SUPERBLOQUE

TAMAÑO SISTEMA DE FICHEROS

NÚMERO DE BLOQUES LIBRES

LISTA DE BLOQUES LIBRES

ÍNDICE SIGUIENTE BLOQUE LIBRE

TAMAÑO LISTA DE INODOS

NÚMERO DE INODOS LIBRES

LISTA DE INODOS LIBRES

ÍNDICE SIGUIENTE INODO LIBRE

FLAG OCUPADO/DISPONIBLE

LISTA INODOS LIBRES

LISTA BLOQUES LIBRES

FLAG SUPERBLOQUE MODIFICADO

Detalles:

• Al crear un fichero: se asigna inodo y bloques de datos.

• Cuando un fichero crece: se asignan datos.

• La lista de inodos libres del SB es incompleta.

• La lista de bloques libres del SB es incompleta.

Page 9: REPRESENTACIÓN INTERNA DE FICHEROS

SISTEMA DE FICHEROS UNIX J. Santos

37

Page 10: REPRESENTACIÓN INTERNA DE FICHEROS

SISTEMA DE FICHEROS UNIX J. Santos

38

Dos ejemplos:

Asignación de un inodo de la lista del SB cuando ésta no está vacía.

Asignación cuando la lista del SB está vacía.

Page 11: REPRESENTACIÓN INTERNA DE FICHEROS

SISTEMA DE FICHEROS UNIX J. Santos

39

Dos ejemplos (con lista de SB llena):

Inodo liberado < inodo recordado

Inodo liberado > inodo recordado

Page 12: REPRESENTACIÓN INTERNA DE FICHEROS

SISTEMA DE FICHEROS UNIX J. Santos

40

Ejemplo de concurrencia:

Page 13: REPRESENTACIÓN INTERNA DE FICHEROS

SISTEMA DE FICHEROS UNIX J. Santos

41

Ejemplo de situación de la lista encadenada de bloques libres, partiendo de la lista de libres del SB:

Page 14: REPRESENTACIÓN INTERNA DE FICHEROS

SISTEMA DE FICHEROS UNIX J. Santos

42

Ejemplo de funcionamiento en la liberación y asignación de bloques libres:

Page 15: REPRESENTACIÓN INTERNA DE FICHEROS

SISTEMA DE FICHEROS UNIX J. Santos

43

LLAMADAS AL SISTEMA PARA EL MANEJO DE FICHEROS

int open (char *nombre, int modo, int permisos);

modo apertura: modo 0: lectura modo 1: escritura modo 2: lectura-escritura

O usando las constantes definidas en el cabecera <fcntl.h>

O_RDONLY sólo lectura O_RDWR lectura-escritura O_WRONLY sólo escritura O_APPEND añadir O_CREAT crear ...

Page 16: REPRESENTACIÓN INTERNA DE FICHEROS

SISTEMA DE FICHEROS UNIX J. Santos

44

int read (int df, char *buff, int n);

df – descriptor de fichero devuelto por open buff – dirección a donde se trasvasan los datos, en el espacio de usuario n – número de bytes a leer

Page 17: REPRESENTACIÓN INTERNA DE FICHEROS

SISTEMA DE FICHEROS UNIX J. Santos

45

Page 18: REPRESENTACIÓN INTERNA DE FICHEROS

SISTEMA DE FICHEROS UNIX J. Santos

46

Page 19: REPRESENTACIÓN INTERNA DE FICHEROS

SISTEMA DE FICHEROS UNIX J. Santos

47

DIFERENCIAS ENTRE EL SISTEMA DE FICHEROS SYSTEM V y BSD

• Estructura de directorios.

• Asignación de espacio mediante bloques y fragmentos.

• Introducción de Grupos de cilindros.

Estructura disco en BSD:

BOOT SUPERBLOQUE GRUPO

CILINDROS nº 1

GRUPO

CILINDROS nº 2 …

GRUPO

CILINDROS N

Estructura de cada Grupo de Cilindros:

COPIA SB

CABECERA

GC

LISTA DE INODOS

ÁREA DE DATOS

• Falta aquí figura de disco con GC

Organización del disco en grupos de cilindros [Márquez, 2004]

Page 20: REPRESENTACIÓN INTERNA DE FICHEROS

SISTEMA DE FICHEROS UNIX J. Santos

48

The Linux Ext2fs File System

Ext2fs uses a mechanism similar to that of BSD Fast File System (ffs) for locating data blocks belonging to a specific file

The main differences between ext2fs and ffs concern their disk allocation policies.

In ffs, the disk is allocated to files in blocks of 8Kb, with blocks being subdivided into fragments of 1Kb to store small files or partially filled blocks at the end of a file.

Ext2fs does not use fragments; it performs its allocations in smaller units:

The default block size on ext2fs is 1Kb, although 2Kb and 4Kb blocks are also supported.

Ext2fs uses allocation policies designed to place logically adjacent blocks of a file into physically adjacent blocks on disk, so that it can submit an I/O request for several disk blocks as a single operation.

Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7th Edition, Feb 6, 2005

Ext2fs Block-Allocation Policies

Page 21: REPRESENTACIÓN INTERNA DE FICHEROS

SISTEMA DE FICHEROS UNIX J. Santos

49

Bibliografía: [Batch, 1986] Bach, M.J., The Design of the UNIX Operating System, Prentice-Hall, 1986.

[Carretero y col., 2001] Carretero Pérez, J., de Miguel Anasagasti, P., García Carballeira, F., Pérez Costoya, F., Sistemas Operativos: Una Visión Aplicada, McGraw-Hill, 2001.

[Márquez, 2004] Márquez, F.M., UNIX. Programación Avanzada, Ra-Ma, 2004.

[Sánchez Prieto, 2005] Sánchez Prieto, S., Sistemas Operativos, Servicio Public. Univ. Alcalá, 2005.

[Silberschatz y col. 2005] Silberschatz, A., Galvin, P. and Gagne, G., Operating System Concepts – 7th Edition, Feb 6, 2005.

[Stallings 2005] Stallings, W. Operating Systems (5th Edition ), Prentice-Hall, 2005.

[Tanenbaum 2003] Tanenmaum, A., Sistemas Operativos Modernos, Prentice-Hall, 2003.