PDA

View Full Version : Sendfile [EINVAL]


Arpeda
12-05-2004, 23:25
Ciao a tutti,
stavo provando la sendfile confrontando i tempi di trasferiemtno di un file rispetto alla copia "normale" (prima copia in un buffer e poi nel file di destinazione) ma la sendfile mi ritorna EINVAL. Questo è il codice incrimnato:

int main (int argc, char* argv[])
{
int read_fd;
int write_fd;
struct stat stat_buf;
off_t offset = 0;

/* Open the input file. */
read_fd = open (argv[1], O_RDONLY);
/* Stat the input file to obtain its size. */
fstat (read_fd, &stat_buf);
/* Open the ouput file for writing, with the same permissions as the
source file. */
write_fd = open (argv[2], O_WRONLY | O_CREAT, stat_buf.st_mode);
/* Blast the bytes from one file to the other. */
if (sendfile (write_fd, read_fd, &offset, stat_buf.st_size) < 0) {
if (errno == EBADF)
printf("EBADF\n");
if (errno == EAGAIN)
printf("EAGAIN\n");
if (errno == EINVAL)
printf("EINVAL\n");
if (errno == ENOMEM)
printf("ENOMEM\n");
if (errno == EIO)
printf("EIO\n");
if (errno == EFAULT)
printf("EFAULT\n");

perror("ERROR");
}
/* Close up. */
close (read_fd);
close (write_fd);

return 0;
}

L'esempio è preso da advanced linux programming ... avete qualche idea?
Ciao
Arpeda

ilsensine
13-05-2004, 08:09
kernel 2.6.3-gentoo-rc1

Mi sembra che nei kernel 2.6.x non sia più possibile utilizzare la sendfile tra due file, solo tra file e socket. Il tuo programma qui funziona (2.4).

Spostato in programmazione.

Arpeda
13-05-2004, 17:00
Grazie della risposta, ma sai anche il perchè di questo cambiamento? esiste una chiamata per copiare un file nel 2.6 come faceva la sendfile?

Ciao
Arpeda

ilsensine
13-05-2004, 17:17
Non sono sicuro, dicevo mi sembra. Può darsi che ci sia stato un cambiamento diverso, è passato tempo da quando l'ho letto.
Potresti provare su diversi tipi di file system?

ilsensine
13-05-2004, 17:20
Mumble...potrebbe anche essere legato alla modifica introdotta nel kernel 2.5.26:
http://marc.theaimsgroup.com/?l=linux-kernel&m=102686434527726&w=2
Prova su diversi file system, vediamo che succede.

Arpeda
13-05-2004, 17:23
io l'ho provato su reiserfs, ora chiedo anche ad alcuni miei amici che hanno ext3 e vediamo che succede ... il kernel che ho usato è 2.6.5-gentoo-r1

Ciao
Arpeda